| @@ 360-377 (lines=18) @@ | ||
| 357 | $stmt->execute(); |
|
| 358 | } |
|
| 359 | ||
| 360 | public function addCertificate($userId, $commonName, $displayName, DateTime $validFrom, DateTime $validTo) |
|
| 361 | { |
|
| 362 | $this->addUser($userId); |
|
| 363 | $stmt = $this->db->prepare( |
|
| 364 | <<< 'SQL' |
|
| 365 | INSERT INTO certificates |
|
| 366 | (common_name, user_id, display_name, valid_from, valid_to) |
|
| 367 | VALUES |
|
| 368 | (:common_name, :user_id, :display_name, :valid_from, :valid_to) |
|
| 369 | SQL |
|
| 370 | ); |
|
| 371 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 372 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 373 | $stmt->bindValue(':display_name', $displayName, PDO::PARAM_STR); |
|
| 374 | $stmt->bindValue(':valid_from', $validFrom->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 375 | $stmt->bindValue(':valid_to', $validTo->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 376 | $stmt->execute(); |
|
| 377 | } |
|
| 378 | ||
| 379 | /** |
|
| 380 | * @return array |
|
| @@ 540-583 (lines=44) @@ | ||
| 537 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 538 | } |
|
| 539 | ||
| 540 | public function clientConnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt) |
|
| 541 | { |
|
| 542 | // this query is so complex, because we want to store the user_id in the |
|
| 543 | // log as well, not just the common_name... the user may delete the |
|
| 544 | // certificate, or the user account may be deleted... |
|
| 545 | $stmt = $this->db->prepare( |
|
| 546 | <<< 'SQL' |
|
| 547 | INSERT INTO connection_log |
|
| 548 | ( |
|
| 549 | user_id, |
|
| 550 | profile_id, |
|
| 551 | common_name, |
|
| 552 | ip4, |
|
| 553 | ip6, |
|
| 554 | connected_at |
|
| 555 | ) |
|
| 556 | VALUES |
|
| 557 | ( |
|
| 558 | ( |
|
| 559 | SELECT |
|
| 560 | u.user_id |
|
| 561 | FROM |
|
| 562 | users u, certificates c |
|
| 563 | WHERE |
|
| 564 | u.user_id = c.user_id |
|
| 565 | AND |
|
| 566 | c.common_name = :common_name |
|
| 567 | ), |
|
| 568 | :profile_id, |
|
| 569 | :common_name, |
|
| 570 | :ip4, |
|
| 571 | :ip6, |
|
| 572 | :connected_at |
|
| 573 | ) |
|
| 574 | SQL |
|
| 575 | ); |
|
| 576 | ||
| 577 | $stmt->bindValue(':profile_id', $profileId, PDO::PARAM_STR); |
|
| 578 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 579 | $stmt->bindValue(':ip4', $ip4, PDO::PARAM_STR); |
|
| 580 | $stmt->bindValue(':ip6', $ip6, PDO::PARAM_STR); |
|
| 581 | $stmt->bindValue(':connected_at', $connectedAt->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 582 | $stmt->execute(); |
|
| 583 | } |
|
| 584 | ||
| 585 | public function clientDisconnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt, DateTime $disconnectedAt, $bytesTransferred) |
|
| 586 | { |
|