From b6451e6e76c01bc9397f4e67421cb53c3cb3f3d9 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Mon, 1 Jul 2024 21:07:51 +1000 Subject: [PATCH] =?UTF-8?q?=E2=96=B6=20Ad-hoc=20event=20bug=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/js/common.js | 3 ++- front/js/ui_components.js | 2 +- front/maintenance.php | 2 +- front/php/components/logs_defaults.json | 11 +++++++++++ front/php/server/util.php | 3 ++- front/php/server/utilNotification.php | 16 ++++++++++++++-- front/php/templates/timezone.php | 1 + front/settings.php | 3 ++- server/plugin.py | 8 +++----- 9 files changed, 37 insertions(+), 12 deletions(-) diff --git a/front/js/common.js b/front/js/common.js index 0236f793..be6f8684 100755 --- a/front/js/common.js +++ b/front/js/common.js @@ -945,7 +945,8 @@ function updateApi() { // value has to be in format event|param. e.g. run|ARPSCAN - action = `update_api|devices,appevents` + action = `${getGuid()}|update_api|devices,appevents` + $.ajax({ method: "POST", diff --git a/front/js/ui_components.js b/front/js/ui_components.js index 518bf587..b011777a 100755 --- a/front/js/ui_components.js +++ b/front/js/ui_components.js @@ -314,7 +314,7 @@ function getCellValue(row, index) { // -------------------------------------------------------- // Calls a backend function to add a front-end event (specified by the attributes 'data-myevent' and 'data-myparam-plugin' on the passed element) to an execution queue - function addToExecutionQueue(element) + function addToExecutionQueue_settingEvent(element) { // value has to be in format event|param. e.g. run|ARPSCAN diff --git a/front/maintenance.php b/front/maintenance.php index 77b163ae..8c53a259 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -624,7 +624,7 @@ function restartBackend() { $.ajax({ method: "POST", url: "php/server/util.php", - data: { function: "addToExecutionQueue", action: 'cron_restart_backend' }, + data: { function: "addToExecutionQueue", action: `${getGuid()}|cron_restart_backend` }, success: function(data, textStatus) { // showModalOk ('Result', data ); diff --git a/front/php/components/logs_defaults.json b/front/php/components/logs_defaults.json index ca1537b0..882ce209 100755 --- a/front/php/components/logs_defaults.json +++ b/front/php/components/logs_defaults.json @@ -37,6 +37,17 @@ "filePath": "/app/front/log/app.php_errors.log", "textAreaCssClass": "logs logs-small" }, + { + "buttons": [ + { + "labelStringCode": "Maint_PurgeLog", + "event": "logManage('execution_queue.log', 'cleanLog')" + } + ], + "fileName": "execution_queue.log", + "filePath": "/app/front/log/execution_queue.log", + "textAreaCssClass": "logs logs-small" + }, { "buttons": [ ], diff --git a/front/php/server/util.php b/front/php/server/util.php index 1c9ed559..7db787b4 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -225,6 +225,7 @@ function displayMessage($message, $logAlert = FALSE, $logConsole = TRUE, $logFil } + // ---------------------------------------------------------------------------------------- // Adds an action to perform into the execution_queue.log file function addToExecutionQueue($action) @@ -253,7 +254,7 @@ function cleanLog($logFile) $path = ""; - $allowedFiles = ['app.log', 'app_front.log', 'IP_changes.log', 'stdout.log', 'stderr.log', "pholus_lastrun.log", 'app.php_errors.log']; + $allowedFiles = ['app.log', 'app_front.log', 'IP_changes.log', 'stdout.log', 'stderr.log', "pholus_lastrun.log", 'app.php_errors.log', 'execution_queue.log']; if(in_array($logFile, $allowedFiles)) { diff --git a/front/php/server/utilNotification.php b/front/php/server/utilNotification.php index 69a63ece..5e61a860 100755 --- a/front/php/server/utilNotification.php +++ b/front/php/server/utilNotification.php @@ -3,7 +3,7 @@ require dirname(__FILE__).'/../templates/timezone.php'; - +// ---------------------------------------------------------------------------------------- // Check if the action parameter is set in the GET request if (isset($_GET['action'])) { // Collect GUID if provided @@ -46,6 +46,8 @@ if (isset($_GET['action'])) { } } +// ---------------------------------------------------------------------------------------- +// Generates a random GUID function generate_guid() { if (function_exists('com_create_guid') === true) { return trim(com_create_guid(), '{}'); @@ -54,8 +56,10 @@ function generate_guid() { mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535)); -} + } +// ---------------------------------------------------------------------------------------- +// Logs a notification in in-app notification system function write_notification($content, $level = "interrupt") { $NOTIFICATION_API_FILE = '/app/front/api/user_notifications.json'; @@ -87,6 +91,8 @@ function write_notification($content, $level = "interrupt") { file_put_contents($NOTIFICATION_API_FILE, json_encode($notifications)); } +// ---------------------------------------------------------------------------------------- +// Removes a notification based on GUID function remove_notification($guid) { $NOTIFICATION_API_FILE = '/app/front/api/user_notifications.json'; @@ -102,6 +108,8 @@ function remove_notification($guid) { file_put_contents($NOTIFICATION_API_FILE, json_encode(array_values($filtered_notifications))); } +// ---------------------------------------------------------------------------------------- +// Deletes all notifications function notifications_clear() { $NOTIFICATION_API_FILE = '/app/front/api/user_notifications.json'; @@ -109,6 +117,8 @@ function notifications_clear() { file_put_contents($NOTIFICATION_API_FILE, json_encode(array())); } +// ---------------------------------------------------------------------------------------- +// Mark a notification read based on GUID function mark_notification_as_read($guid) { $NOTIFICATION_API_FILE = '/app/front/api/user_notifications.json'; $max_attempts = 3; @@ -152,10 +162,12 @@ function mark_notification_as_read($guid) { echo "Failed to read notification file after $max_attempts attempts."; } +// ---------------------------------------------------------------------------------------- function notifications_mark_all_read() { mark_notification_as_read(null); } +// ---------------------------------------------------------------------------------------- function get_unread_notifications() { $NOTIFICATION_API_FILE = '/app/front/api/user_notifications.json'; diff --git a/front/php/templates/timezone.php b/front/php/templates/timezone.php index 26416572..b1412bd1 100755 --- a/front/php/templates/timezone.php +++ b/front/php/templates/timezone.php @@ -40,3 +40,4 @@ $timestamp = $date->format('Y-m-d_H-i-s'); // ################################### // ## TimeZone processing end // ################################### + diff --git a/front/settings.php b/front/settings.php index d3662d46..a12fbf8d 100755 --- a/front/settings.php +++ b/front/settings.php @@ -389,6 +389,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX // not initialized properly, reload if(isMetadata && val == "" ) { + console.warn(`Metadata setting value is empty: ${codeName}`); clearCache(); } @@ -604,7 +605,7 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX data-myparam="${codeName}" data-myparam-plugin="${prefix}" data-myevent="${event}" - onclick="addToExecutionQueue(this)" + onclick="addToExecutionQueue_settingEvent(this)" > diff --git a/server/plugin.py b/server/plugin.py index 1b02c3a7..c5ecfc1f 100755 --- a/server/plugin.py +++ b/server/plugin.py @@ -768,11 +768,9 @@ def check_and_run_user_event(db, all_plugins, pluginsState): # Split the line by '|', and take the third and fourth columns (indices 2 and 3) columns = line.strip().split('|')[2:4] - if len(columns) != 2: - remaining_lines.append(line) - continue - - event, param = columns + event, param = "", "" + if len(columns) == 2: + event, param = columns if event == 'test': show_events_completed = True