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'),
(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
--

View File

@ -91,7 +91,6 @@ 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 {
@ -100,7 +99,6 @@ if (!empty($search)) {
'userID' => $item['user_id'],
'username' => $item['username'],
'time' => $item['time'],
'log level' => $item['level'],
'log message' => $item['message']
);
}
@ -115,8 +113,5 @@ $username = $userObject->getUserDetails($userId)[0]['username'];
// Get any new feedback messages
include dirname(__FILE__, 4) . '/app/helpers/feedback.php';
// Load plugin helpers
include PLUGIN_LOGS_PATH . 'helpers/logs_view_helper.php';
// Display messages list
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,
`user_id` INT(11) NOT NULL,
`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,
`message` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),

View File

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

View File

@ -75,14 +75,13 @@
<div class="mb-5">
<?php if (!empty($logs['records'])) { ?>
<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">
<tr>
<?php if ($scope === 'system') { ?>
<th>Username&nbsp;(id)</th>
<?php } ?>
<th style="white-space: nowrap;">Time</th>
<th style="white-space: nowrap;">Log level</th>
<th>Time</th>
<th>Log message</th>
</tr>
</thead>
@ -90,11 +89,10 @@
<?php foreach ($logs['records'] as $row) { ?>
<tr>
<?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 } ?>
<td style="white-space: nowrap;"><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 style="width: 100%; word-break: break-word;"><?= htmlspecialchars($row['log message']) ?></td>
<td><span class="text-muted"><?= date('d M Y H:i', strtotime($row['time'])) ?></span></td>
<td><?= htmlspecialchars($row['log message']) ?></td>
</tr>
<?php } ?>
</tbody>