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)) {