From 3e9eb0d82259887dc985571b1584bdc1f2f0cdad Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sun, 16 Feb 2025 10:18:26 +0200 Subject: [PATCH] Renames messages to feedback --- app/classes/ratelimiter.php | 14 +++++++------- app/includes/database.php | 2 +- app/includes/messages-show.php | 2 +- app/includes/messages.php | 2 +- app/pages/agents.php | 12 ++++++------ app/pages/components.php | 2 +- app/pages/conferences.php | 2 +- app/pages/config.php | 12 ++++++------ app/pages/dashboard.php | 2 +- app/pages/graphs.php | 2 +- app/pages/login.php | 14 +++++++------- app/pages/participants.php | 2 +- app/pages/register.php | 10 +++++----- app/pages/security.php | 18 +++++++++--------- app/templates/page-header.php | 2 +- public_html/index.php | 6 +++--- 16 files changed, 52 insertions(+), 52 deletions(-) diff --git a/app/classes/ratelimiter.php b/app/classes/ratelimiter.php index a3e3b85..3f2ec28 100644 --- a/app/classes/ratelimiter.php +++ b/app/classes/ratelimiter.php @@ -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; } } diff --git a/app/includes/database.php b/app/includes/database.php index 1789c32..436d1dc 100644 --- a/app/includes/database.php +++ b/app/includes/database.php @@ -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(); } diff --git a/app/includes/messages-show.php b/app/includes/messages-show.php index 7ff8f6f..f9020d3 100644 --- a/app/includes/messages-show.php +++ b/app/includes/messages-show.php @@ -1,7 +1,7 @@ '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 diff --git a/app/pages/components.php b/app/pages/components.php index 64d3edd..8d15be9 100644 --- a/app/pages/components.php +++ b/app/pages/components.php @@ -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 { diff --git a/app/pages/conferences.php b/app/pages/conferences.php index 9108bc0..6998770 100644 --- a/app/pages/conferences.php +++ b/app/pages/conferences.php @@ -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 { diff --git a/app/pages/config.php b/app/pages/config.php index 993bfce..ed20a63 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -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'); diff --git a/app/pages/dashboard.php b/app/pages/dashboard.php index 48a6a9f..25a7594 100644 --- a/app/pages/dashboard.php +++ b/app/pages/dashboard.php @@ -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 { diff --git a/app/pages/graphs.php b/app/pages/graphs.php index 6b41ad7..cd2f264 100644 --- a/app/pages/graphs.php +++ b/app/pages/graphs.php @@ -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']; } diff --git a/app/pages/login.php b/app/pages/login.php index 84c2987..dc24171 100644 --- a/app/pages/login.php +++ b/app/pages/login.php @@ -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 diff --git a/app/pages/participants.php b/app/pages/participants.php index fa89401..1beee5e 100644 --- a/app/pages/participants.php +++ b/app/pages/participants.php @@ -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 { diff --git a/app/pages/register.php b/app/pages/register.php index 14be54e..28805dc 100644 --- a/app/pages/register.php +++ b/app/pages/register.php @@ -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); } ?> diff --git a/app/pages/security.php b/app/pages/security.php index b9ee0bd..60d8d0c 100644 --- a/app/pages/security.php +++ b/app/pages/security.php @@ -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 diff --git a/app/templates/page-header.php b/app/templates/page-header.php index 912d47d..9ea9435 100644 --- a/app/templates/page-header.php +++ b/app/templates/page-header.php @@ -47,7 +47,7 @@
- +
diff --git a/public_html/index.php b/public_html/index.php index cb2715e..65b362f 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -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); } }