From 6fd750e4e12be790d93e5105f0011bfef7e2f853 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Mon, 31 Jul 2023 08:14:50 +1000 Subject: [PATCH] settings rewrite to JS --- front/maintenance.php | 6 ++++++ front/php/server/util.php | 9 ++++++++- front/php/templates/footer.php | 14 +++----------- front/php/templates/language/en_us.json | 3 ++- front/settings.php | 10 ++-------- pialert/initialise.py | 7 ++++--- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/front/maintenance.php b/front/maintenance.php index bce93eeb..8e68b274 100755 --- a/front/maintenance.php +++ b/front/maintenance.php @@ -164,6 +164,12 @@ $db->close();
">' .lang('Maintenance_new_version').''.'' .lang('Maintenance_current_version').'';?>
+
+
+
+ +
+
diff --git a/front/php/server/util.php b/front/php/server/util.php index 9337901e..de7df32e 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -297,6 +297,13 @@ function saveSettings() } elseif ($settingType == 'text.multiselect' || $settingType == 'subnets' || $settingType == 'list') { $temp = '['; + echo $settingType.'
'; + echo $settingKey.'
'; + echo json_encode($settingValue).'
'; + // echo json_decode($settingValue).'
'; + + // json_decode($settingValue) todo + if (count($setting) > 3 && is_array($settingValue) == true) { foreach ($settingValue as $val) { $temp .= "'" . encode_single_quotes($val) . "',"; @@ -323,7 +330,7 @@ function saveSettings() $txt = $txt."#-------------------IMPORTANT INFO-------------------#\n"; // open new file and write the new configuration - $newConfig = fopen($fullConfPath, "w") or die("Unable to open file!"); + $newConfig = fopen($fullConfPath.'_debug', "w") or die("Unable to open file!"); // todo fwrite($newConfig, $txt); fclose($newConfig); diff --git a/front/php/templates/footer.php b/front/php/templates/footer.php index 51211e5c..c7dd79c3 100755 --- a/front/php/templates/footer.php +++ b/front/php/templates/footer.php @@ -13,22 +13,14 @@ © - - - 2020 Puche (2022+ jokob-sk) | Built on: + 2020 Puche (2022+ jokob-sk) | : - + | Version: - release notes.", "Maintenance_current_version" : "You are up-to-date. Check out what I am working on.", + "Maintenance_built_on" : "Built on", "Maintenance_database_path" : "Database-Path", "Maintenance_database_size" : "Database-Size", "Maintenance_database_rows" : "Table (Rows)", diff --git a/front/settings.php b/front/settings.php index 5a7a5ee6..365cec67 100755 --- a/front/settings.php +++ b/front/settings.php @@ -439,14 +439,8 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { const temp = $(`#${set["Code_Name"]}`).is(':checked') ? 1 : 0; settingsArray.push([set["Group"], set["Code_Name"], set["Type"], temp]); - - } else if (set['Code_Name'] === 'SCAN_SUBNETS') { - const temps = []; - $('#SCAN_SUBNETS option').each(function (i, selected) { - temps.push($(selected).val()); - }); - settingsArray.push([set["Group"], set["Code_Name"], set["Type"], JSON.stringify(temps)]); - } else if (set['Type'] === 'list') { + + } else if (set['Type'] === 'list' || set['Type'] === 'subnets') { const temps = []; $(`#${set["Code_Name"]} option`).each(function (i, selected) { const vl = $(selected).val(); diff --git a/pialert/initialise.py b/pialert/initialise.py index 0783153e..ca161693 100755 --- a/pialert/initialise.py +++ b/pialert/initialise.py @@ -248,9 +248,6 @@ def importConfigs (db): sql.executemany ("""INSERT INTO Settings ("Code_Name", "Display_Name", "Description", "Type", "Options", "RegEx", "Value", "Group", "Events" ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""", conf.mySettingsSQLsafe) - # Used to determine the next import - conf.lastTimeImported = time.time() - # Is used to display a message in the UI when old (outdated) settings are loaded initOrSetParam(db, "Back_Settings_Imported",(round(time.time() * 1000),) ) @@ -259,6 +256,10 @@ def importConfigs (db): # update only the settings datasource update_api(db, False, ["settings"]) + + # Used to determine the next import + conf.lastTimeImported = time.time() + #TO DO this creates a circular reference between API and HELPER ! mylog('info', '[Config] Imported new config')