| @@ 277-294 (lines=18) @@ | ||
| 274 | $stmt->execute(); |
|
| 275 | } |
|
| 276 | ||
| 277 | public function addCertificate($userId, $commonName, $displayName, DateTime $validFrom, DateTime $validTo) |
|
| 278 | { |
|
| 279 | $this->addUser($userId); |
|
| 280 | $stmt = $this->db->prepare( |
|
| 281 | <<< 'SQL' |
|
| 282 | INSERT INTO certificates |
|
| 283 | (common_name, user_id, display_name, valid_from, valid_to) |
|
| 284 | VALUES |
|
| 285 | (:common_name, :user_id, :display_name, :valid_from, :valid_to) |
|
| 286 | SQL |
|
| 287 | ); |
|
| 288 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 289 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 290 | $stmt->bindValue(':display_name', $displayName, PDO::PARAM_STR); |
|
| 291 | $stmt->bindValue(':valid_from', $validFrom->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 292 | $stmt->bindValue(':valid_to', $validTo->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 293 | $stmt->execute(); |
|
| 294 | } |
|
| 295 | ||
| 296 | /** |
|
| 297 | * @return array |
|
| @@ 457-500 (lines=44) @@ | ||
| 454 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 455 | } |
|
| 456 | ||
| 457 | public function clientConnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt) |
|
| 458 | { |
|
| 459 | // this query is so complex, because we want to store the user_id in the |
|
| 460 | // log as well, not just the common_name... the user may delete the |
|
| 461 | // certificate, or the user account may be deleted... |
|
| 462 | $stmt = $this->db->prepare( |
|
| 463 | <<< 'SQL' |
|
| 464 | INSERT INTO connection_log |
|
| 465 | ( |
|
| 466 | user_id, |
|
| 467 | profile_id, |
|
| 468 | common_name, |
|
| 469 | ip4, |
|
| 470 | ip6, |
|
| 471 | connected_at |
|
| 472 | ) |
|
| 473 | VALUES |
|
| 474 | ( |
|
| 475 | ( |
|
| 476 | SELECT |
|
| 477 | u.user_id |
|
| 478 | FROM |
|
| 479 | users u, certificates c |
|
| 480 | WHERE |
|
| 481 | u.user_id = c.user_id |
|
| 482 | AND |
|
| 483 | c.common_name = :common_name |
|
| 484 | ), |
|
| 485 | :profile_id, |
|
| 486 | :common_name, |
|
| 487 | :ip4, |
|
| 488 | :ip6, |
|
| 489 | :connected_at |
|
| 490 | ) |
|
| 491 | SQL |
|
| 492 | ); |
|
| 493 | ||
| 494 | $stmt->bindValue(':profile_id', $profileId, PDO::PARAM_STR); |
|
| 495 | $stmt->bindValue(':common_name', $commonName, PDO::PARAM_STR); |
|
| 496 | $stmt->bindValue(':ip4', $ip4, PDO::PARAM_STR); |
|
| 497 | $stmt->bindValue(':ip6', $ip6, PDO::PARAM_STR); |
|
| 498 | $stmt->bindValue(':connected_at', $connectedAt->format('Y-m-d H:i:s'), PDO::PARAM_STR); |
|
| 499 | $stmt->execute(); |
|
| 500 | } |
|
| 501 | ||
| 502 | public function clientDisconnect($profileId, $commonName, $ip4, $ip6, DateTime $connectedAt, DateTime $disconnectedAt, $bytesTransferred) |
|
| 503 | { |
|