From 2e0cb923db51640791a9cd64f9b56d5e985b0b06 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 29 Jan 2023 14:13:31 +1100 Subject: [PATCH 1/6] Column settings preserved after restart --- back/pialert.py | 2 ++ front/devices.php | 21 +++++++++++++++------ front/php/templates/language/en_us.php | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index e0f8fb04..f1dedb0a 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -3234,6 +3234,8 @@ def isNewVersion(): buildTimestamp = int(f.read().strip()) f.close() + data = "" + try: url = requests.get("https://api.github.com/repos/jokob-sk/Pi.Alert/releases") text = url.text diff --git a/front/devices.php b/front/devices.php index 67af8d2f..ed0d08c0 100755 --- a/front/devices.php +++ b/front/devices.php @@ -204,14 +204,26 @@ // ----------------------------------------------------------------------------- function main () { + // get from cookie if available (need to use decodeURI as saved as part of URI in PHP) + cookieColumnsVisibleStr = decodeURI(getCookie("Front_Devices_Columns_Visible")).replaceAll('%2C',',') + + defaultValue = cookieColumnsVisibleStr == "" ? columnsStr : cookieColumnsVisibleStr; + // get visible columns - $.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue='+columnsStr+'¶meter=Front_Devices_Columns_Visible&skipcache', function(data) { + $.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue='+defaultValue+'¶meter=Front_Devices_Columns_Visible&skipcache', function(data) { + // save which columns are in the Devices page visible tableColumnVisible = numberArrayFromString(data); + // get from cookie if available (need to use decodeURI as saved as part of URI in PHP) + cookieColumnsOrderStr = decodeURI(getCookie("Front_Devices_Columns_Order")).replaceAll('%2C',',') + + defaultValue = cookieColumnsOrderStr == "" ? columnsStr : cookieColumnsOrderStr; + // get the custom order specified by the user - $.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue='+columnsStr+'¶meter=Front_Devices_Columns_Order&skipcache', function(data) { + $.get('php/server/parameters.php?action=get&expireMinutes=525600&defaultValue='+defaultValue+'¶meter=Front_Devices_Columns_Order&skipcache', function(data) { + // save the columns order in the Devices page tableColumnOrder = numberArrayFromString(data); //initialize the table headers in the correct order @@ -243,8 +255,6 @@ function main () { } $('#tableDevices tr').html(html); - - // get parameter value $.get('php/server/parameters.php?action=get&defaultValue=50¶meter='+ parTableRows, function(data) { @@ -282,14 +292,13 @@ function main () { // ----------------------------------------------------------------------------- var tableColumnHide = []; +// mapping the default order to the user specified one function mapIndx(oldIndex) { for(i=0;i 'Scan device', 'DevDetail_EveandAl_AlertAllEvents' => 'Alert All Events', 'DevDetail_EveandAl_AlertDown' => 'Alert Down', -'DevDetail_EveandAl_Skip' => 'Skip repeated notifications during', +'DevDetail_EveandAl_Skip' => 'Skip repeated notifications for', 'DevDetail_EveandAl_NewDevice' => 'New Device', 'DevDetail_EveandAl_Archived' => 'Archived', 'DevDetail_EveandAl_RandomMAC' => 'Random MAC', @@ -638,7 +638,7 @@ the arp-scan will take hours to complete instead of seconds. 'NMAP_ACTIVE_name' => 'Cycle run', 'NMAP_ACTIVE_description' => 'If enabled this will execute a scan on a newly found device. For a scheduled or one-off scan, check the NMAP_RUN setting.', 'NMAP_TIMEOUT_name' => 'Run timeout', -'NMAP_TIMEOUT_description' => 'Maximum time to wait for an Nmap scan to finish on any device.', +'NMAP_TIMEOUT_description' => 'Maximum time in seconds to wait for an Nmap scan to finish on any device.', 'NMAP_RUN_name' => 'Scheduled run', 'NMAP_RUN_description' => 'Enable a regular Nmap scan on your network on all devices. The scheduling settings can be found below. If you select once Nmap is run only once on start for the time specified in NMAP_TIMEOUT setting.', 'NMAP_RUN_SCHD_name' => 'Schedule', From e98a538f5314e342cc1426634dc9e7bf6cdedcaa Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 29 Jan 2023 14:42:43 +1100 Subject: [PATCH 2/6] API 0.3 --- back/pialert.py | 8 +++++--- docs/API.md | 1 + front/php/templates/language/en_us.php | 7 ++++++- front/settings.php | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index f1dedb0a..1745dd7b 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -289,7 +289,7 @@ def importConfig (): # Nmap global NMAP_ACTIVE, NMAP_TIMEOUT, NMAP_RUN, NMAP_RUN_SCHD, NMAP_ARGS # API - global ENABLE_API, API_RUN, API_RUN_SCHD, API_RUN_INTERVAL + global ENABLE_API, API_RUN, API_RUN_SCHD, API_RUN_INTERVAL, API_CUSTOM_SQL mySettings = [] # reset settings # get config file @@ -391,8 +391,9 @@ def importConfig (): # API ENABLE_API = ccd('ENABLE_API', True , c_d, 'Enable API', 'boolean', '', 'API') API_RUN = ccd('API_RUN', 'schedule' , c_d, 'API execution', 'selecttext', "['none', 'interval', 'schedule']", 'API') - API_RUN_SCHD = ccd('API_RUN_SCHD', '*/3 * * * *' , c_d, 'API schedule', 'text', '', 'API') + API_RUN_SCHD = ccd('API_RUN_SCHD', '*/3 * * * *' , c_d, 'API schedule', 'text', '', 'API') API_RUN_INTERVAL = ccd('API_RUN_INTERVAL', 10 , c_d, 'API update interval', 'integer', '', 'API') + API_CUSTOM_SQL = ccd('API_CUSTOM_SQL', 'SELECT * FROM Devices WHERE dev_PresentLastScan = 0' , c_d, 'Custom endpoint', 'text', '', 'API') # Insert settings into the DB sql.execute ("DELETE FROM Settings") @@ -2968,7 +2969,8 @@ def update_api(isNotification = False): ["devices", sql_devices_all], ["nmap_scan", sql_nmap_scan_all], ["pholus_scan", sql_pholus_scan_all], - ["events_pending_alert", sql_events_pending_alert] + ["events_pending_alert", sql_events_pending_alert], + ["custom_endpoint", API_CUSTOM_SQL] ] # Save selected database tables diff --git a/docs/API.md b/docs/API.md index 41125fbb..6d58be3c 100755 --- a/docs/API.md +++ b/docs/API.md @@ -29,6 +29,7 @@ You can access the following files: | `table_nmap_scan.json` | The current state of the discovered ports by the regular NMAP scans. | | `table_pholus_scan.json` | The latest state of the [pholus](https://github.com/jokob-sk/Pi.Alert/tree/main/pholus) (A multicast DNS and DNS Service Discovery Security Assessment Tool) scan results. | | `table_events_pending_alert.json` | The list of the unprocessed (pending) notification events. | + | `table_custom_endpoint.json` | A custom endpoint generated by the SQL query specified by the `API_CUSTOM_SQL` setting. | Current/latest state of the aforementioned files depends on your settings. diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index 54c61e7b..9aa0e13d 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -654,8 +654,13 @@ the arp-scan will take hours to complete instead of seconds. 'API_RUN_description' => 'Scheduling settings to specify when the API endpoints should be updated. If set to schedule then endpoints will be updated on a specified cron-like schedule specified by the API_RUN_SCHD setting. Otherwise if set to interval endpoints will be updated every N seconds specified by the API_RUN_INTERVAL setting.', 'API_RUN_SCHD_name' => 'Schedule', 'API_RUN_SCHD_description' => 'Depends on the API_RUN settings to be set to schedule. Make sure you enter the schedule in the correct cron-like format (e.g. validate at crontab.guru).', -'API_RUN_INTERVAL_name' => 'API update interval', +'API_RUN_INTERVAL_name' => 'Update interval', 'API_RUN_INTERVAL_description' => 'Depends on the API_RUN settings to be set to interval. The minimum cycle is 5 seconds.', +'API_CUSTOM_SQL_name' => 'Custom endpoint', +'API_CUSTOM_SQL_description' => 'You can specify a custom SQL query which will generate a JSON file then exposed via the table_custom_endpoint.json file endpoint.', + + + ); ?> diff --git a/front/settings.php b/front/settings.php index 5af3938b..bd3078d8 100755 --- a/front/settings.php +++ b/front/settings.php @@ -285,7 +285,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {