SecurityLogger.class.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class SecurityLogger {
  3. public static function action($command, array $logReportData, $timestamp) {
  4. $message = "Unknown SecurityLogger action";
  5. switch($command) {
  6. case "login":
  7. $message = "User " . $logReportData['display_name'] . " (" . $logReportData['user_id'] . ")" .
  8. " logged in to " . DOMAIN;
  9. break;
  10. case "login-failed":
  11. $message = "Failed login on ".DOMAIN .
  12. " using username " . $logReportData['attempted_username'] .
  13. " from IP " . $logReportData['ip_address'];
  14. break;
  15. }
  16. $db = SqliteDatabase::getSingleton();
  17. $sql = "INSERT INTO security_logs (message, action, recordtime) VALUES (:message, :action, DATETIME('now'))";
  18. $preparedQuery = $db->prepare($sql);
  19. $preparedQuery->bindValue(':message', $message);
  20. $preparedQuery->bindValue(':action', $command);
  21. $preparedQuery->execute();
  22. }
  23. public function read() {
  24. $logs = array();
  25. $db = SqliteDatabase::getSingleton();
  26. $sql = "SELECT * FROM security_logs ORDER BY recordtime DESC";
  27. $return = $db->query($sql);
  28. while($row = $return->fetchArray(SQLITE3_ASSOC)) {
  29. $logs[] = $row;
  30. }
  31. return $logs;
  32. }
  33. }