Compare commits

..

No commits in common. "fd835dd05863007b409d4afa74862d60cb85f4ca" and "81b4187ae8f91e5ba5ef432d3671ff8796a21132" have entirely different histories.

6 changed files with 25 additions and 32 deletions

View File

@ -174,6 +174,22 @@ 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'), (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'); (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 -- Jilo
-- --

View File

@ -91,7 +91,6 @@ if (!empty($search)) {
$log_record = array( $log_record = array(
// assign title to the field in the array record // assign title to the field in the array record
'time' => $item['time'], 'time' => $item['time'],
'log level' => $item['level'],
'log message' => $item['message'] 'log message' => $item['message']
); );
} else { } else {
@ -100,7 +99,6 @@ if (!empty($search)) {
'userID' => $item['user_id'], 'userID' => $item['user_id'],
'username' => $item['username'], 'username' => $item['username'],
'time' => $item['time'], 'time' => $item['time'],
'log level' => $item['level'],
'log message' => $item['message'] 'log message' => $item['message']
); );
} }
@ -115,8 +113,5 @@ $username = $userObject->getUserDetails($userId)[0]['username'];
// Get any new feedback messages // Get any new feedback messages
include dirname(__FILE__, 4) . '/app/helpers/feedback.php'; include dirname(__FILE__, 4) . '/app/helpers/feedback.php';
// Load plugin helpers
include PLUGIN_LOGS_PATH . 'helpers/logs_view_helper.php';
// Display messages list // Display messages list
include PLUGIN_LOGS_PATH . 'views/logs.php'; include PLUGIN_LOGS_PATH . 'views/logs.php';

View File

@ -1,15 +0,0 @@
<?php
function getLogLevelClass($level) {
switch (strtolower($level)) {
case 'emergency': return 'text-danger fw-bold';
case 'alert': return 'text-danger';
case 'critical': return 'text-warning fw-bold';
case 'error': return 'text-warning';
case 'warning': return 'text-warning';
case 'notice': return 'text-primary';
case 'info': return 'text-info';
case 'debug': return 'text-muted';
default: return 'text-body'; // fallback normal text
}
}

View File

@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `log` (
`id` INT(11) NOT NULL AUTO_INCREMENT, `id` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` INT(11) NOT NULL, `user_id` INT(11) NOT NULL,
`time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`level` set('emergency','alert','critical','error','warning','notice','info','debug') NOT NULL DEFAULT 'info', `level` VARCHAR(10) NOT NULL DEFAULT 'info',
`scope` set('user','system') NOT NULL, `scope` set('user','system') NOT NULL,
`message` VARCHAR(255) NOT NULL, `message` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),

View File

@ -102,15 +102,14 @@ class Log {
$scope = $context['scope'] ?? 'system'; $scope = $context['scope'] ?? 'system';
try { try {
$sql = 'INSERT INTO log $sql = 'INSERT INTO log
(user_id, level, scope, message) (user_id, scope, message)
VALUES VALUES
(:user_id, :level, :scope, :message)'; (:user_id, :scope, :message)';
$query = $this->db->prepare($sql); $query = $this->db->prepare($sql);
$query->execute([ $query->execute([
':user_id' => $userId, ':user_id' => $userId,
':level' => $level,
':scope' => $scope, ':scope' => $scope,
':message' => $message, ':message' => "[$level] " . $message,
]); ]);
} catch (Exception $e) { } catch (Exception $e) {
// swallowing exceptions or here we could log to error log for testing // swallowing exceptions or here we could log to error log for testing

View File

@ -75,14 +75,13 @@
<div class="mb-5"> <div class="mb-5">
<?php if (!empty($logs['records'])) { ?> <?php if (!empty($logs['records'])) { ?>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover align-middle mb-0" style="width: 100%;"> <table class="table table-hover align-middle mb-0">
<thead class="table-light"> <thead class="table-light">
<tr> <tr>
<?php if ($scope === 'system') { ?> <?php if ($scope === 'system') { ?>
<th>Username&nbsp;(id)</th> <th>Username&nbsp;(id)</th>
<?php } ?> <?php } ?>
<th style="white-space: nowrap;">Time</th> <th>Time</th>
<th style="white-space: nowrap;">Log level</th>
<th>Log message</th> <th>Log message</th>
</tr> </tr>
</thead> </thead>
@ -90,11 +89,10 @@
<?php foreach ($logs['records'] as $row) { ?> <?php foreach ($logs['records'] as $row) { ?>
<tr> <tr>
<?php if ($scope === 'system') { ?> <?php if ($scope === 'system') { ?>
<td style="white-space: nowrap;"><?= $row['userID'] ? '<strong>' . htmlspecialchars($row['username'] . " ({$row['userID']})") . '</strong>' : '<span class="text-muted font-weight-normal small">SYSTEM</span>' ?></td> <td><?= $row['userID'] ? '<strong>' . htmlspecialchars($row['username'] . " ({$row['userID']})") . '</strong>' : '<span class="text-muted font-weight-normal small">SYSTEM</span>' ?></td>
<?php } ?> <?php } ?>
<td style="white-space: nowrap;"><span class="text-muted"><?= date('d M Y H:i', strtotime($row['time'])) ?></span></td> <td><span class="text-muted"><?= date('d M Y H:i', strtotime($row['time'])) ?></span></td>
<td style="white-space: nowrap;"><span class="<?= getLogLevelClass($row['log level']) ?>"><?= htmlspecialchars($row['log level']) ?></span></td> <td><?= htmlspecialchars($row['log message']) ?></td>
<td style="width: 100%; word-break: break-word;"><?= htmlspecialchars($row['log message']) ?></td>
</tr> </tr>
<?php } ?> <?php } ?>
</tbody> </tbody>