Compare commits

...

2 Commits

Author SHA1 Message Date
Yasen Pramatarov 457c946946 Adds some user right restrictions 2025-04-27 15:48:07 +03:00
Yasen Pramatarov f84a337607 Fixes log plugin 2025-04-27 15:43:45 +03:00
5 changed files with 25 additions and 5 deletions

View File

@ -16,4 +16,12 @@ class NullLogger
* @return void
*/
public function insertLog($userId, string $message, ?string $type = null): void {}
/**
* PSR-3 log stub.
* @param string $level
* @param string $message
* @param array $context
*/
public function log(string $level, string $message, array $context = []): void {}
}

View File

@ -114,7 +114,8 @@ if (!$isAjax) {
* Handles GET requests to display templates.
*/
if ($userObject->hasRight($userId, 'view config file')) {
if ($userObject->hasRight($userId, 'superuser') ||
$userObject->hasRight($userId, 'view config file')) {
include '../app/templates/config.php';
} else {
$logObject->insertLog($userId, "Unauthorized: User \"$currentUser\" tried to access \"config\" page. IP: $user_IP", 'system');

View File

@ -17,7 +17,8 @@
<i class="fas fa-wrench me-2 text-secondary"></i>
<?= htmlspecialchars($config['site_name']) ?> app configuration
</h5>
<?php if ($userObject->hasRight($userId, 'edit config file')) { ?>
<?php if ($userObject->hasRight($userId, 'superuser') ||
$userObject->hasRight($userId, 'edit config file')) { ?>
<div>
<button type="button" class="btn btn-outline-primary btn-sm toggle-edit" <?= !$isWritable ? 'disabled' : '' ?>>
<i class="fas fa-edit me-2"></i>Edit

View File

@ -65,12 +65,15 @@
</a>
<div class="dropdown-menu dropdown-menu-right">
<h6 class="dropdown-header">system</h6>
<?php if ($userObject->hasRight($userId, 'view config file')) {?>
<?php if ($userObject->hasRight($userId, 'superuser') ||
$userObject->hasRight($userId, 'view config file')) {?>
<a class="dropdown-item" href="<?= htmlspecialchars($app_root) ?>?page=config">
<i class="fas fa-wrench"></i>Configuration
</a>
<?php } ?>
<?php if ($userObject->hasRight($userId, 'superuser') ||
$userObject->hasRight($userId, 'view config file') ||
$userObject->hasRight($userId, 'edit config file') ||
$userObject->hasRight($userId, 'edit whitelist') ||
$userObject->hasRight($userId, 'edit blacklist') ||
$userObject->hasRight($userId, 'edit ratelimiting')) { ?>

View File

@ -67,8 +67,8 @@ class Log {
$where_clauses = [];
// Base query with user join
$base_sql = 'SELECT l.*, u.username
FROM log l
$base_sql = 'SELECT l.*, u.username
FROM log l
LEFT JOIN user u ON l.user_id = u.id';
// Add scope condition
@ -119,4 +119,11 @@ class Log {
return $query->fetchAll(PDO::FETCH_ASSOC);
}
// PSR-3 style log method
public function log(string $level, string $message, array $context = []): void {
$userId = $context['user_id'] ?? null;
$scope = $context['scope'] ?? 'system';
$this->insertLog($userId, "[$level] " . $message, $scope);
}
}