123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?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;
- case "add-user":
- $message = "Admin ".$logReportData['admin_display_name']." (".$logReportData['admin_user_id'].
- ") added user ".$logReportData['user_added'];
- break;
- case "edit-user":
- $message = "Admin ".$logReportData['display_name']." (".$logReportData['user_id'].
- ") edited user ".$logReportData['username'] . "(".$logReportData['edited_user_id'].")";
- break;
- case "remove-user-domain":
- //TODO: send more descriptive names
- $message = "Admin ".$logReportData['admin_display_name']." (".$logReportData['admin_user_id'].
- ") removed access to account ".$logReportData['domain_removed']." from user ".$logReportData['user_removed'];
- break;
- case "add-user-domain":
- //TODO: send more descriptive names
- $message = "Admin ".$logReportData['admin_display_name']." (".$logReportData['admin_user_id'].
- ") added access to account ".$logReportData['domain_added']." for user ".$logReportData['user_added'];
- break;
- case "create-project":
- $message = "Admin ".$logReportData['display_name']." (".$logReportData['user_id'].
- ") created data project ".$logReportData['project_display_name'] . "(".$logReportData['project_folder'].") in region " . $logReportData['project_bucket'];
- break;
- case "edit-project":
- $message = "Admin ".$logReportData['display_name']." (".$logReportData['user_id'].
- ") edited data project ".$logReportData['project_display_name']." (".$logReportData['project_id'].")";
- break;
- case "add-project-domain":
- //TODO: send more descriptive names
- $message = "Admin ".$logReportData['admin_display_name']." (".$logReportData['admin_user_id'].
- ") added project ".$logReportData['project_added']." access to account ".$logReportData['domain_added'];
- break;
- case "remove-project-domain":
- //TODO: send more descriptive names
- $message = "Admin ".$logReportData['admin_display_name']." (".$logReportData['admin_user_id'].
- ") removed project ".$logReportData['project_removed']." access to account ".$logReportData['domain_removed'];
- break;
- case "create-account":
- $message = "Admin ".$logReportData['display_name']." (".$logReportData['user_id'].
- ") created account ".$logReportData['account_display_name'] . "(".$logReportData['subdomain'].")";
- break;
- case "edit-account":
- $message = "Admin ".$logReportData['display_name']." (".$logReportData['user_id'].
- ") edited account ".$logReportData['account_display_name'] . "(".$logReportData['client_id'].")";
- 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 LIMIT 0, 20";
- $return = $db->query($sql);
- while($row = $return->fetchArray(SQLITE3_ASSOC)) {
- $logs[] = $row;
- }
- return $logs;
- }
- public function readPage($pageOffset = 0, $pageSize = 5) {
- $db = SqliteDatabase::getSingleton();
- $sql = "SELECT * FROM security_logs ORDER BY recordtime DESC LIMIT ".$pageSize." OFFSET ".($pageOffset * $pageSize).";";
- $logs = $db->queryArray($sql);
- //var_dump($logs);
- return $logs;
- }
- }
|