diff --git a/doc/database/main.sql b/doc/database/main.sql index bcd3bf5..c5c637e 100644 --- a/doc/database/main.sql +++ b/doc/database/main.sql @@ -174,22 +174,6 @@ INSERT INTO `security_ip_whitelist` (`id`, `ip_address`, `is_network`, `descript (4, '172.16.0.0/12', 1, 'Private network (Class B)', '2025-01-03 16:40:15', 'system'), (5, '192.168.0.0/16', 1, 'Private network (Class C)', '2025-01-03 16:40:15', 'system'); --- --- Logs --- - --- -------------------------------------------------------- -CREATE TABLE `log` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL, - `time` datetime NOT NULL DEFAULT current_timestamp(), - `scope` set('user','system') NOT NULL, - `message` varchar(255) NOT NULL, - PRIMARY KEY (`id`), - KEY `user_id` (`user_id`), - CONSTRAINT `log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; - -- -- Jilo -- diff --git a/plugins/logs/controllers/logs.php b/plugins/logs/controllers/logs.php index 309b10c..19df516 100644 --- a/plugins/logs/controllers/logs.php +++ b/plugins/logs/controllers/logs.php @@ -91,6 +91,7 @@ if (!empty($search)) { $log_record = array( // assign title to the field in the array record 'time' => $item['time'], + 'log level' => $item['level'], 'log message' => $item['message'] ); } else { @@ -99,6 +100,7 @@ if (!empty($search)) { 'userID' => $item['user_id'], 'username' => $item['username'], 'time' => $item['time'], + 'log level' => $item['level'], 'log message' => $item['message'] ); } diff --git a/plugins/logs/migrations/create_log_table.sql b/plugins/logs/migrations/create_log_table.sql index 68fc348..791f375 100644 --- a/plugins/logs/migrations/create_log_table.sql +++ b/plugins/logs/migrations/create_log_table.sql @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `log` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `user_id` INT(11) NOT NULL, `time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - `level` VARCHAR(10) NOT NULL DEFAULT 'info', + `level` set('emergency','alert','critical','error','warning','notice','info','debug') NOT NULL DEFAULT 'info', `scope` set('user','system') NOT NULL, `message` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`), diff --git a/plugins/logs/models/Log.php b/plugins/logs/models/Log.php index 4ad4486..fee10e2 100644 --- a/plugins/logs/models/Log.php +++ b/plugins/logs/models/Log.php @@ -102,14 +102,15 @@ class Log { $scope = $context['scope'] ?? 'system'; try { $sql = 'INSERT INTO log - (user_id, scope, message) + (user_id, level, scope, message) VALUES - (:user_id, :scope, :message)'; + (:user_id, :level, :scope, :message)'; $query = $this->db->prepare($sql); $query->execute([ ':user_id' => $userId, + ':level' => $level, ':scope' => $scope, - ':message' => "[$level] " . $message, + ':message' => $message, ]); } catch (Exception $e) { // swallowing exceptions or here we could log to error log for testing diff --git a/plugins/logs/views/logs.php b/plugins/logs/views/logs.php index 0f69e32..ad5848c 100644 --- a/plugins/logs/views/logs.php +++ b/plugins/logs/views/logs.php @@ -75,13 +75,14 @@
- +
- + + @@ -89,10 +90,11 @@ - + - - + + +
Username (id) TimeTimeLog level Log message
' . htmlspecialchars($row['username'] . " ({$row['userID']})") . '' : 'SYSTEM' ?>' . htmlspecialchars($row['username'] . " ({$row['userID']})") . '' : 'SYSTEM' ?>