1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- class SecurityLogger {
- public static function action($command, array $logReportData, $timestamp) {
- $message = "Unknown SecurityLogger action";
- switch($command) {
- case "login":
- $message = "User " . $logReportData['display_name'] . " (" . $logReportData['user_id'] . ")" .
- " logged in to " . DOMAIN;
- break;
- case "login-failed":
- $message = "Failed login on ".DOMAIN .
- " using username " . $logReportData['attempted_username'] .
- " from IP " . $logReportData['ip_address'];
- break;
- }
- $db = SqliteDatabase::getSingleton();
- $sql = "INSERT INTO security_logs (message, action, recordtime) VALUES (:message, :action, DATETIME('now'))";
- $preparedQuery = $db->prepare($sql);
- $preparedQuery->bindValue(':message', $message);
- $preparedQuery->bindValue(':action', $command);
- $preparedQuery->execute();
- }
- public function read() {
- $logs = array();
- $db = SqliteDatabase::getSingleton();
- $sql = "SELECT * FROM security_logs ORDER BY recordtime DESC";
- $return = $db->query($sql);
- while($row = $return->fetchArray(SQLITE3_ASSOC)) {
- $logs[] = $row;
- }
- return $logs;
- }
- }
|