diff --git a/front/plugins/README.md b/front/plugins/README.md index 84baba1e..b21428ee 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -102,10 +102,13 @@ More on specifics below. Currently, these data sources are supported (valid `data_source` value). -- Script (`script`) -- SQL query on the PiAlert database (`pialert-db-query`) -- Template (`template`) -- External SQLite database (`sqlite-db-query`) +| Name | `data_source` value | Needs to return a "table" | Overview (more details on this page below) | +|----------------------|----------------------|----------------------|----------------------| +| Script | `script` | no | Executes any linux command in the `CMD` setting. | +| Pialert DB query | `pialert-db-query` | yes | Executes a SQL query on the PiAlert database in the `CMD` setting. | +| Template | `template` | no | Used to generate internal settings, such a sdefault values. | +| External SQLite DB query | `sqlite-db-query` | yes | Executes a SQL query from the `CMD` setting on an external SQLite database mapped in the `DB_PATH` setting. | + > 🔎Example >```json @@ -113,6 +116,13 @@ Currently, these data sources are supported (valid `data_source` value). >``` Any of the above data sources have to return a "table" of the exact structure as outlined above. +You can show or hide the UI on the "Plugins" page and "Plugins" tab on devices via the `show_ui` property: + +> 🔎Example +>```json +> "show_ui": true, +> ``` + ### "data_source": "script" If the `data_source` is set to `script` the `CMD` setting (that you specify in the `settings` array section in the `config.json`) needs to contain an executable Linux command, that generates a `last_result.log` file. This file needs to be stored in the same folder as the plugin. @@ -208,17 +218,29 @@ Used to initialize internal settings. Check the `newdev_template` plugin for det ### "data_source": "sqlite-db-query" -You can execute a SQL query on an external database connected to the current PiALert database via a temporary `EXTERNAL.` prefix. The external SQLite database file has to be mapped in the container to the path specified in the `db_path` property: +You can execute a SQL query on an external database connected to the current PiALert database via a temporary `EXTERNAL.` prefix. The external SQLite database file has to be mapped in the container to the path specified in the `DB_PATH` setting: -```json - ... - "data_source": "sqlite-db-query", - "data_source_settings": - { - "db_path":"/etc/pihole/pihole-FTL.db" - }, - ... -``` +> 🔎Example +> +>```json +> ... +>{ +> "function": "DB_PATH", +> "type": "readonly", +> "default_value":"/etc/pihole/pihole-FTL.db", +> "options": [], +> "localized": ["name", "description"], +> "name" : [{ +> "language_code":"en_us", +> "string" : "DB Path" +> }], +> "description": [{ +> "language_code":"en_us", +> "string" : "Required setting for the sqlite-db-query plugin type. Is used to mount an external SQLite database and execute the SQL query stored in the CMD setting." +> }] +> } +> ... +>``` The actual SQL query you want to execute is then stored as a `CMD` setting, similar to the `pialert-db-query` plugin type. diff --git a/front/plugins/arp_scan/config.json b/front/plugins/arp_scan/config.json index b557f282..1be94439 100755 --- a/front/plugins/arp_scan/config.json +++ b/front/plugins/arp_scan/config.json @@ -13,6 +13,7 @@ "compare_use_quotes": true } ], + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name": [ diff --git a/front/plugins/dhcp_leases/config.json b/front/plugins/dhcp_leases/config.json index ca277a6d..f2a1ff66 100755 --- a/front/plugins/dhcp_leases/config.json +++ b/front/plugins/dhcp_leases/config.json @@ -12,6 +12,7 @@ "compare_use_quotes": true } ], + "show_ui": true, "localized": ["display_name", "description", "icon"], "mapped_to_table": "DHCP_Leases", "display_name" : [{ diff --git a/front/plugins/dhcp_servers/config.json b/front/plugins/dhcp_servers/config.json index ce9516ee..a8a66591 100755 --- a/front/plugins/dhcp_servers/config.json +++ b/front/plugins/dhcp_servers/config.json @@ -3,6 +3,7 @@ "unique_prefix": "DHCPSRVS", "enabled": true, "data_source": "script", + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name" : [{ "language_code":"en_us", diff --git a/front/plugins/known_template/config.json b/front/plugins/known_template/config.json index c7f9bddd..c42022d5 100755 --- a/front/plugins/known_template/config.json +++ b/front/plugins/known_template/config.json @@ -3,7 +3,8 @@ "template_type": "database-entry", "unique_prefix": "KNWN", "enabled": true, - "data_source": "template", + "data_source": "template", + "show_ui": false, "localized": ["display_name", "description", "icon"], "display_name": [{ "language_code": "en_us", diff --git a/front/plugins/newdev_template/config.json b/front/plugins/newdev_template/config.json index d44fbed5..e92a2b3d 100755 --- a/front/plugins/newdev_template/config.json +++ b/front/plugins/newdev_template/config.json @@ -4,6 +4,7 @@ "unique_prefix": "NEWDEV", "enabled": true, "data_source": "template", + "show_ui": false, "localized": ["display_name", "description", "icon"], "display_name": [{ "language_code": "en_us", diff --git a/front/plugins/nmap_services/config.json b/front/plugins/nmap_services/config.json index 75680cb8..66638791 100755 --- a/front/plugins/nmap_services/config.json +++ b/front/plugins/nmap_services/config.json @@ -12,6 +12,7 @@ "compare_use_quotes": true } ], + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name" : [{ "language_code":"en_us", diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index 3b60c080..11c86d51 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -3,10 +3,6 @@ "unique_prefix": "PIHOLE", "enabled": true, "data_source": "sqlite-db-query", - "data_source_settings": - { - "db_path":"/etc/pihole/pihole-FTL.db" - }, "mapped_to_table": "CurrentScan", "data_filters": [ { @@ -17,6 +13,7 @@ "compare_use_quotes": true } ], + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name": [ @@ -57,7 +54,7 @@ }], "description": [{ "language_code":"en_us", - "string" : "Specify when your PiHole device import from the PiHole databse will run. The typical setting would be schedule and then you specify a cron-like schedule in the PIHOLE_RUN_SCHDsetting. If enabled, you must map the pihole db into your container to the :/etc/pihole/pihole-FTL.db mount path." + "string" : "Specify when your PiHole device import from the PiHole databse will run. The typical setting would be schedule and then you specify a cron-like schedule in the PIHOLE_RUN_SCHDsetting. If enabled, you must map the pihole db into your container to the :/etc/pihole/pihole-FTL.db mount path as specified in the DB_PATH setting." }] }, { @@ -94,6 +91,21 @@ } ] }, + { + "function": "DB_PATH", + "type": "readonly", + "default_value":"/etc/pihole/pihole-FTL.db", + "options": [], + "localized": ["name", "description"], + "name" : [{ + "language_code":"en_us", + "string" : "DB Path" + }], + "description": [{ + "language_code":"en_us", + "string" : "Required setting for the sqlite-db-query plugin type. Is used to mount an external SQLite database and execute the SQL query stored in the CMD setting." + }] + }, { "function": "RUN_SCHD", "type": "text", diff --git a/front/plugins/set_password/config.json b/front/plugins/set_password/config.json index 6dc19893..ccd3ccd4 100755 --- a/front/plugins/set_password/config.json +++ b/front/plugins/set_password/config.json @@ -1,9 +1,10 @@ { - "code_name": "set_webui_password", + "code_name": "set_password", "template_type": "database-entry", "unique_prefix": "SETPWD", "enabled": true, "data_source": "script", + "show_ui": false, "localized": ["display_name", "description", "icon"], "display_name": [{ "language_code": "en_us", diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 9a3b4f09..ec7f69d9 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -12,6 +12,7 @@ "compare_use_quotes": true } ], + "show_ui": true, "localized": ["display_name", "description", "icon"], "mapped_to_table": "DHCP_Leases", "display_name" : [{ diff --git a/front/plugins/undiscoverables/config.json b/front/plugins/undiscoverables/config.json index 6b0a7163..6c4b30e2 100755 --- a/front/plugins/undiscoverables/config.json +++ b/front/plugins/undiscoverables/config.json @@ -4,7 +4,7 @@ "enabled": true, "data_source": "script", "mapped_to_table": "DHCP_Leases", - + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name": [ diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index a4449c4f..4b021456 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -3,6 +3,7 @@ "unique_prefix": "UNFIMP", "enabled": true, "data_source": "script", + "show_ui": true, "data_filters": [ { "compare_column" : "Object_PrimaryID", diff --git a/front/plugins/website_monitor/config.json b/front/plugins/website_monitor/config.json index c041d8f0..4ee74e2a 100755 --- a/front/plugins/website_monitor/config.json +++ b/front/plugins/website_monitor/config.json @@ -3,6 +3,7 @@ "unique_prefix": "WEBMON", "enabled": true, "data_source": "python-script", + "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name" : [{ "language_code": "en_us", diff --git a/front/pluginsCore.php b/front/pluginsCore.php index b5cc9757..b7ddddab 100755 --- a/front/pluginsCore.php +++ b/front/pluginsCore.php @@ -216,7 +216,7 @@ function generateTabs() // console.log(pluginObj) - if(pluginObj.data_source != "template") // hiding template-based plugins as they don't produce any output + if(pluginObj.show_ui) // hiding plugins where specified { $('#tabs-location').append( `
  • diff --git a/pialert/plugin.py b/pialert/plugin.py index 49ca8ec7..d22d53c9 100755 --- a/pialert/plugin.py +++ b/pialert/plugin.py @@ -32,8 +32,6 @@ def run_plugin_scripts(db, runType): shouldRun = True elif runType == "schedule": # run if overdue scheduled time - - # check schedules if any contains a unique plugin prefix matching the current plugin for schd in conf.mySchedules: if schd.service == prefix: @@ -250,8 +248,16 @@ def execute_plugin(db, plugin): # Execute command mylog('verbose', ['[Plugins] Executing: ', q]) + + # ------- necessary settings check -------- + set = get_plugin_setting(plugin, "DB_PATH") + + # handle missing "function":"DB_PATH" setting + if set == None: + mylog('none', ['[Plugins] Error: DB_PATH setting for plugin type sqlite-db-query missing.']) + return - fullSqlitePath = plugin['data_source_settings']['db_path'] + fullSqlitePath = set["value"] # try attaching the sqlite DB try: