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