Renames messages to feedback

main
Yasen Pramatarov 2025-02-16 10:18:26 +02:00
parent ef97dda39b
commit 3e9eb0d822
16 changed files with 52 additions and 52 deletions

View File

@ -168,7 +168,7 @@ class RateLimiter {
$message = "Cannot whitelist {$ip} - IP is currently blacklisted";
if ($userId) {
$this->log->insertLog($userId, "IP Whitelist: {$message}", 'system');
Messages::flash('ERROR', 'DEFAULT', $message);
Feedback::flash('ERROR', 'DEFAULT', $message);
}
return false;
}
@ -195,7 +195,7 @@ class RateLimiter {
} catch (Exception $e) {
if ($userId) {
$this->log->insertLog($userId, "IP Whitelist: Failed to add {$ip}: " . $e->getMessage(), 'system');
Messages::flash('ERROR', 'DEFAULT', "IP Whitelist: Failed to add {$ip}: " . $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', "IP Whitelist: Failed to add {$ip}: " . $e->getMessage());
}
return false;
}
@ -230,7 +230,7 @@ class RateLimiter {
} catch (Exception $e) {
if ($userId) {
$this->log->insertLog($userId, "IP Whitelist: Failed to remove {$ip}: " . $e->getMessage(), 'system');
Messages::flash('ERROR', 'DEFAULT', "IP Whitelist: Failed to remove {$ip}: " . $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', "IP Whitelist: Failed to remove {$ip}: " . $e->getMessage());
}
return false;
}
@ -243,7 +243,7 @@ class RateLimiter {
$message = "Cannot blacklist {$ip} - IP is currently whitelisted";
if ($userId) {
$this->log->insertLog($userId, "IP Blacklist: {$message}", 'system');
Messages::flash('ERROR', 'DEFAULT', $message);
Feedback::flash('ERROR', 'DEFAULT', $message);
}
return false;
}
@ -272,7 +272,7 @@ class RateLimiter {
} catch (Exception $e) {
if ($userId) {
$this->log->insertLog($userId, "IP Blacklist: Failed to add {$ip}: " . $e->getMessage(), 'system');
Messages::flash('ERROR', 'DEFAULT', "IP Blacklist: Failed to add {$ip}: " . $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', "IP Blacklist: Failed to add {$ip}: " . $e->getMessage());
}
return false;
}
@ -305,7 +305,7 @@ class RateLimiter {
} catch (Exception $e) {
if ($userId) {
$this->log->insertLog($userId, "IP Blacklist: Failed to remove {$ip}: " . $e->getMessage(), 'system');
Messages::flash('ERROR', 'DEFAULT', "IP Blacklist: Failed to remove {$ip}: " . $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', "IP Blacklist: Failed to remove {$ip}: " . $e->getMessage());
}
return false;
}
@ -340,7 +340,7 @@ class RateLimiter {
return true;
} catch (Exception $e) {
$this->log->insertLog(0, "Failed to cleanup expired entries: " . $e->getMessage(), 'system');
Messages::flash('ERROR', 'DEFAULT', "Failed to cleanup expired entries: " . $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', "Failed to cleanup expired entries: " . $e->getMessage());
return false;
}
}

View File

@ -52,7 +52,7 @@ function connectDB($config, $database = '', $dbFile = '', $platformId = '') {
// unknown database
} else {
$error = "Error: unknow database type \"{$config['db']['db_type']}\"";
Messages::flash('ERROR', 'DEFAULT', $error);
Feedback::flash('ERROR', 'DEFAULT', $error);
exit();
}

View File

@ -1,7 +1,7 @@
<?php
if (isset($messages) && is_array($messages)) {
foreach ($messages as $msg) {
echo Messages::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null, $msg['dismissible'] ?? false, $msg['small'] ?? false);
echo Feedback::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null, $msg['dismissible'] ?? false, $msg['small'] ?? false);
}
}

View File

@ -1,7 +1,7 @@
<?php
// Get any flash messages from previous request
$flash_messages = Messages::getFlash();
$flash_messages = Feedback::getFlash();
if (!empty($flash_messages)) {
$messages = array_merge($messages, array_map(function($flash) {
return [

View File

@ -49,7 +49,7 @@ function isCacheExpired($agentId) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate agent ID for POST operations
if ($agentId === false || $agentId === null) {
Messages::flash('ERROR', 'DEFAULT', 'Invalid agent ID format');
Feedback::flash('ERROR', 'DEFAULT', 'Invalid agent ID format');
echo json_encode(['status' => 'error', 'message' => 'Invalid agent ID format']);
exit;
}
@ -57,7 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Read and validate JSON data
$jsonData = file_get_contents("php://input");
if ($jsonData === false) {
Messages::flash('ERROR', 'DEFAULT', 'Failed to read input data');
Feedback::flash('ERROR', 'DEFAULT', 'Failed to read input data');
echo json_encode(['status' => 'error', 'message' => 'Failed to read input data']);
exit;
}
@ -72,7 +72,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
unset($_SESSION[$cacheKey]);
unset($_SESSION[$timeKey]);
Messages::flash('SUCCESS', 'DEFAULT', "Cache for agent {$agentId} is cleared.");
Feedback::flash('SUCCESS', 'DEFAULT', "Cache for agent {$agentId} is cleared.");
echo json_encode([
'status' => 'success',
'message' => "Cache for agent {$agentId} is cleared."
@ -86,14 +86,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_SESSION[$cacheKey] = $data;
$_SESSION[$timeKey] = time();
Messages::flash('SUCCESS', 'DEFAULT', "Cache for agent {$agentId} is stored.");
Feedback::flash('SUCCESS', 'DEFAULT', "Cache for agent {$agentId} is stored.");
echo json_encode([
'status' => 'success',
'message' => "Cache for agent {$agentId} is stored."
]);
}
else {
Messages::flash('ERROR', 'DEFAULT', 'Invalid data format');
Feedback::flash('ERROR', 'DEFAULT', 'Invalid data format');
echo json_encode(['status' => 'error', 'message' => 'Invalid data format']);
}
@ -119,7 +119,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate platform_id is set
if (!isset($platform_id)) {
Messages::flash('ERROR', 'DEFAULT', 'Platform ID is not set');
Feedback::flash('ERROR', 'DEFAULT', 'Platform ID is not set');
}
// Get host details for this platform

View File

@ -13,7 +13,7 @@ $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $pl
// if DB connection has error, display it and stop here
if ($response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $response['error']);
Feedback::flash('ERROR', 'DEFAULT', $response['error']);
// otherwise if DB connection is OK, go on
} else {

View File

@ -13,7 +13,7 @@ $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $pl
// if DB connection has error, display it and stop here
if ($response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $response['error']);
Feedback::flash('ERROR', 'DEFAULT', $response['error']);
// otherwise if DB connection is OK, go on
} else {

View File

@ -22,7 +22,7 @@ $isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
$isWritable = is_writable($config_file);
$configMessage = '';
if (!$isWritable) {
$configMessage = Messages::render('ERROR', 'DEFAULT', 'Config file is not writable', false);
$configMessage = Feedback::render('ERROR', 'DEFAULT', 'Config file is not writable', false);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
@ -41,7 +41,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (json_last_error() !== JSON_ERROR_NONE) {
$error = json_last_error_msg();
Messages::flash('ERROR', 'DEFAULT', 'Invalid JSON data received: ' . $error, true);
Feedback::flash('ERROR', 'DEFAULT', 'Invalid JSON data received: ' . $error, true);
echo json_encode([
'success' => false,
'message' => 'Invalid JSON data received: ' . $error
@ -52,14 +52,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Try to update config file
$result = $configObject->editConfigFile($postData, $config_file);
if ($result === true) {
$messageData = Messages::getMessageData('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
$messageData = Feedback::getMessageData('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
echo json_encode([
'success' => true,
'message' => 'Config file updated successfully',
'messageData' => $messageData
]);
} else {
$messageData = Messages::getMessageData('ERROR', 'DEFAULT', "Error updating config file: $result", true);
$messageData = Feedback::getMessageData('ERROR', 'DEFAULT', "Error updating config file: $result", true);
echo json_encode([
'success' => false,
'message' => "Error updating config file: $result",
@ -72,9 +72,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Handle non-AJAX POST
$result = $configObject->editConfigFile($_POST, $config_file);
if ($result === true) {
Messages::flash('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
Feedback::flash('NOTICE', 'DEFAULT', 'Config file updated successfully', true);
} else {
Messages::flash('ERROR', 'DEFAULT', "Error updating config file: $result", true);
Feedback::flash('ERROR', 'DEFAULT', "Error updating config file: $result", true);
}
header('Location: ' . htmlspecialchars($app_root) . '?page=config');

View File

@ -21,7 +21,7 @@ $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $pl
// if DB connection has error, display it and stop here
if ($response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $response['error']);
Feedback::flash('ERROR', 'DEFAULT', $response['error']);
// otherwise if DB connection is OK, go on
} else {

View File

@ -13,7 +13,7 @@ $hostObject = new Host($dbWeb);
// Connect to Jilo database for log data
$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
if ($response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $response['error']);
Feedback::flash('ERROR', 'DEFAULT', $response['error']);
} else {
$db = $response['db'];
}

View File

@ -55,14 +55,14 @@ try {
// Check if IP is blacklisted
if ($rateLimiter->isIpBlacklisted($user_IP)) {
throw new Exception(Messages::get('LOGIN', 'IP_BLACKLISTED')['message']);
throw new Exception(Feedback::get('LOGIN', 'IP_BLACKLISTED')['message']);
}
// Check rate limiting (but skip if IP is whitelisted)
if (!$rateLimiter->isIpWhitelisted($user_IP)) {
$attempts = $rateLimiter->getRecentAttempts($user_IP);
if ($attempts >= $rateLimiter->maxAttempts) {
throw new Exception(Messages::get('LOGIN', 'LOGIN_BLOCKED')['message']);
throw new Exception(Feedback::get('LOGIN', 'LOGIN_BLOCKED')['message']);
}
}
@ -97,15 +97,15 @@ try {
$logObject->insertLog($user_id, "Login: User \"$username\" logged in. IP: $user_IP", 'user');
// Set success message and redirect
Messages::flash('LOGIN', 'LOGIN_SUCCESS', null, true);
Feedback::flash('LOGIN', 'LOGIN_SUCCESS', null, true);
header('Location: ' . htmlspecialchars($app_root));
exit();
} else {
throw new Exception(Messages::get('LOGIN', 'LOGIN_FAILED')['message']);
throw new Exception(Feedback::get('LOGIN', 'LOGIN_FAILED')['message']);
}
} catch (Exception $e) {
// Log the failed attempt
Messages::flash('ERROR', 'DEFAULT', $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', $e->getMessage());
if (isset($username)) {
$user_id = $userObject->getUserId($username)[0]['id'] ?? 0;
$logObject->insertLog($user_id, "Login: Failed login attempt for user \"$username\". IP: $user_IP. Reason: {$e->getMessage()}", 'user');
@ -113,12 +113,12 @@ try {
}
}
} catch (Exception $e) {
Messages::flash('ERROR', 'DEFAULT', 'There was an unexpected error. Please try again.');
Feedback::flash('ERROR', 'DEFAULT', 'There was an unexpected error. Please try again.');
}
// Show configured login message if any
if (!empty($config['login_message'])) {
echo Messages::render('NOTICE', 'DEFAULT', $config['login_message'], false, false, false);
echo Feedback::render('NOTICE', 'DEFAULT', $config['login_message'], false, false, false);
}
// Get any new messages

View File

@ -13,7 +13,7 @@ $response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $pl
// if DB connection has error, display it and stop here
if ($response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $response['error']);
Feedback::flash('ERROR', 'DEFAULT', $response['error']);
// otherwise if DB connection is OK, go on
} else {

View File

@ -46,23 +46,23 @@ if ($config['registration_enabled'] == true) {
// redirect to login
if ($result === true) {
Messages::flash('NOTICE', 'DEFAULT', "Registration successful. You can log in now.");
Feedback::flash('NOTICE', 'DEFAULT', "Registration successful. You can log in now.");
header('Location: ' . htmlspecialchars($app_root));
exit();
// registration fail, redirect to login
} else {
Messages::flash('ERROR', 'DEFAULT', "Registration failed. $result");
Feedback::flash('ERROR', 'DEFAULT', "Registration failed. $result");
header('Location: ' . htmlspecialchars($app_root));
exit();
}
} else {
Messages::flash('ERROR', 'DEFAULT', $validator->getFirstError());
Feedback::flash('ERROR', 'DEFAULT', $validator->getFirstError());
header('Location: ' . htmlspecialchars($app_root . '?page=register'));
exit();
}
}
} catch (Exception $e) {
Messages::flash('ERROR', 'DEFAULT', $e->getMessage());
Feedback::flash('ERROR', 'DEFAULT', $e->getMessage());
}
// Get any new messages
@ -74,7 +74,7 @@ if ($config['registration_enabled'] == true) {
// registration disabled
} else {
echo Messages::render('NOTICE', 'DEFAULT', 'Registration is disabled', false);
echo Feedback::render('NOTICE', 'DEFAULT', 'Registration is disabled', false);
}
?>

View File

@ -49,9 +49,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if (!$rateLimiter->addToWhitelist($_POST['ip_address'], $is_network, $_POST['description'] ?? '', $currentUser, $user_id)) {
throw new Exception('Failed to add IP to whitelist');
}
Messages::flash('SECURITY', 'WHITELIST_ADD_SUCCESS');
Feedback::flash('SECURITY', 'WHITELIST_ADD_SUCCESS');
} else {
Messages::flash('SECURITY', 'WHITELIST_ADD_ERROR', $validator->getFirstError());
Feedback::flash('SECURITY', 'WHITELIST_ADD_ERROR', $validator->getFirstError());
}
break;
@ -71,9 +71,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if (!$rateLimiter->removeFromWhitelist($_POST['ip_address'], $currentUser, $user_id)) {
throw new Exception('Failed to remove IP from whitelist');
}
Messages::flash('SECURITY', 'WHITELIST_REMOVE_SUCCESS');
Feedback::flash('SECURITY', 'WHITELIST_REMOVE_SUCCESS');
} else {
Messages::flash('SECURITY', 'WHITELIST_REMOVE_ERROR', $validator->getFirstError());
Feedback::flash('SECURITY', 'WHITELIST_REMOVE_ERROR', $validator->getFirstError());
}
break;
@ -105,9 +105,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if (!$rateLimiter->addToBlacklist($_POST['ip_address'], $is_network, $_POST['reason'], $currentUser, $user_id, $expiry_hours)) {
throw new Exception('Failed to add IP to blacklist');
}
Messages::flash('SECURITY', 'BLACKLIST_ADD_SUCCESS');
Feedback::flash('SECURITY', 'BLACKLIST_ADD_SUCCESS');
} else {
Messages::flash('SECURITY', 'BLACKLIST_ADD_ERROR', $validator->getFirstError());
Feedback::flash('SECURITY', 'BLACKLIST_ADD_ERROR', $validator->getFirstError());
}
break;
@ -127,9 +127,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if (!$rateLimiter->removeFromBlacklist($_POST['ip_address'], $currentUser, $user_id)) {
throw new Exception('Failed to remove IP from blacklist');
}
Messages::flash('SECURITY', 'BLACKLIST_REMOVE_SUCCESS');
Feedback::flash('SECURITY', 'BLACKLIST_REMOVE_SUCCESS');
} else {
Messages::flash('SECURITY', 'BLACKLIST_REMOVE_ERROR', $validator->getFirstError());
Feedback::flash('SECURITY', 'BLACKLIST_REMOVE_ERROR', $validator->getFirstError());
}
break;
@ -137,7 +137,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
throw new Exception('Invalid action');
}
} catch (Exception $e) {
Messages::flash('SECURITY', 'ERROR', $e->getMessage());
Feedback::flash('SECURITY', 'ERROR', $e->getMessage());
}
// Redirect back to the appropriate section

View File

@ -47,7 +47,7 @@
<div class="col">
<?php if (isset($messages) && is_array($messages)): ?>
<?php foreach ($messages as $msg): ?>
<?= Messages::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null) ?>
<?= Feedback::render($msg['category'], $msg['key'], $msg['custom_message'] ?? null) ?>
<?php endforeach; ?>
<?php endif; ?>
</div>

View File

@ -123,7 +123,7 @@ try {
}
$dbWeb = $response['db'];
} catch (Exception $e) {
Messages::flash('ERROR', 'DEFAULT', getError('Error connecting to the database.', $e->getMessage()));
Feedback::flash('ERROR', 'DEFAULT', getError('Error connecting to the database.', $e->getMessage()));
include '../app/templates/page-header.php';
include '../app/includes/messages.php';
include '../app/includes/messages-show.php';
@ -175,7 +175,7 @@ if ($page == 'logout') {
$logObject->insertLog($user_id, "Logout: User \"$currentUser\" logged out. IP: $user_IP", 'user');
// Set success message
Messages::flash('LOGIN', 'LOGOUT_SUCCESS');
Feedback::flash('LOGIN', 'LOGOUT_SUCCESS');
include '../app/templates/page-header.php';
include '../app/templates/page-menu.php';
@ -207,7 +207,7 @@ if ($page == 'logout') {
$server_endpoint = '/health';
$server_status = $serverObject->getServerStatus($server_host, $server_port, $server_endpoint);
if (!$server_status) {
Messages::flash('ERROR', 'DEFAULT', 'The Jilo Server is not running. Some data may be old and incorrect.', false, true);
Feedback::flash('ERROR', 'DEFAULT', 'The Jilo Server is not running. Some data may be old and incorrect.', false, true);
}
}