From 4fbaccc0f24a8f9441f1873ba3c75da01edde781 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sat, 5 Aug 2023 06:52:23 +1000 Subject: [PATCH] Docs + flows work --- docs/README.md | 12 ++- front/flows.php | 0 front/php/server/util.php | 2 +- front/php/templates/language/en_us.json | 2 +- front/plugins/known_template/config.json | 102 ++++++++++++++++++++++- front/settings.php | 91 +++++++++++--------- pialert/flows.py | 0 pialert/plugin.py | 7 ++ 8 files changed, 168 insertions(+), 48 deletions(-) mode change 100644 => 100755 front/flows.php mode change 100644 => 100755 pialert/flows.py diff --git a/docs/README.md b/docs/README.md index 6b053269..45e64a69 100755 --- a/docs/README.md +++ b/docs/README.md @@ -21,8 +21,6 @@ There is also an in-app Help / FAQ section that should be answering frequently a #### 🔝 Popular/Suggested -- [API endpoints details](/docs/API.md) -- [Plugin system details and how to develop your own](/front/plugins/README.md) - [Network treemap configuration](/docs/NETWORK_TREE.md) - [Gmail as SMTP server for sending emails](/docs/SMTP_GMAIL.md) - [Subnets and VLANs configuration for arp-scan](/docs/SUBNETS.md) @@ -40,11 +38,17 @@ There is also an in-app Help / FAQ section that should be answering frequently a #### ♻ Misc -- [New Version notifications](/docs/VERSIONS.md) - [Version history (legacy)](/docs/VERSIONS_HISTORY.md) -- [Database structure](/docs/DATABASE.md) - [Reverse proxy (Nginx, Apache, SWAG)](/docs/REVERSE_PROXY.md) +#### 👩‍💻For Developers👨‍💻 + +- [APP code structure](/pialert/README.md) +- [Database structure](/docs/DATABASE.md) +- [API endpoints details](/docs/API.md) +- [Plugin system details and how to develop your own](/front/plugins/README.md) +- [New Version notifications](/docs/VERSIONS.md) + Feel free to suggest or submit new docs via a PR. ## 👨‍💻 Development priorities diff --git a/front/flows.php b/front/flows.php old mode 100644 new mode 100755 diff --git a/front/php/server/util.php b/front/php/server/util.php index b4ee1e3e..8d20e99f 100755 --- a/front/php/server/util.php +++ b/front/php/server/util.php @@ -312,7 +312,7 @@ function saveSettings() $temp = '['.$temp.']'; // wrap brackets $txt .= $settingKey . "=" . $temp . "\n"; - } elseif ($settingType == 'json') { + } elseif ($settingType == 'json' || substr($settingType, -9) === ".template") { $txt .= $settingKey . "=" . $settingValue . "\n"; } } diff --git a/front/php/templates/language/en_us.json b/front/php/templates/language/en_us.json index 7a14cbbd..b6587ca9 100755 --- a/front/php/templates/language/en_us.json +++ b/front/php/templates/language/en_us.json @@ -442,7 +442,7 @@ "INCLUDED_SECTIONS_name" : "Notify on", "INCLUDED_SECTIONS_description" : "Specifies which events trigger notifications. Remove the event type(s) you don not want to get notified on. This setting overrides device-specific settings in the UI. (CTRL + Click to select/deselect).", "SCAN_CYCLE_MINUTES_name" : "Scan cycle delay", - "SCAN_CYCLE_MINUTES_description" : "The delay between scans in minutes. If using arp-scan, the scan time itself depends on the number of IP addresses to check. This is influenced by the network mask set in the SCAN_SUBNETS setting at the top. Every IP takes a couple seconds to scan.", + "SCAN_CYCLE_MINUTES_description" : "The delay between scans in minutes. Only related to arp-scan, PiHole, DHCP_ACTIVE scans. If using arp-scan, the scan time itself depends on the number of IP addresses to check. This is influenced by the network mask set in the SCAN_SUBNETS setting at the top. Every IP takes a couple seconds to scan.", "DAYS_TO_KEEP_EVENTS_name" : "Delete events older than", "DAYS_TO_KEEP_EVENTS_description" : "This is a maintenance setting. This specifies the number of days worth of event entries that will be kept. All older events will be deleted periodically. Also applies on Plugin Events History.", "HRS_TO_KEEP_NEWDEV_name" : "Keep new devices for", diff --git a/front/plugins/known_template/config.json b/front/plugins/known_template/config.json index c7e3b9ae..0afb80dd 100755 --- a/front/plugins/known_template/config.json +++ b/front/plugins/known_template/config.json @@ -34,12 +34,106 @@ "name" : "dev_AlertEvents", "type" : "setting", "value" : "KNWN_dev_AlertEvents" + }, + { + "name" : "trigger_ids", + "type" : "array", + "value" : "trigger.Object_PrimaryID" + }, + { + "name" : "trigger_objects", + "type" : "array", + "value" : "trigger" } ], "settings":[ + { + "function": "flows", + "type": "json", + "maxLength": 50, + "default_value": [{ + "name":"apply_template", + "trigger": [ + { + "object_event": "new", + "object_filter": "" + } + ], + "steps": [ + { + "step_type":"wait", + "params": [ + { + "days": 3, + "hours": 0, + "minutes": 0, + "seconds": 0 + } + ] + }, + { + "step_type":"condition", + "params": [ + { + "left": { + "value": "triggers[0].object['dev_NewDevice']", + "use_quotes": true, + "js_template": "'{value}'.toString()" + }, + "operator": { + "value" : "==", + "data_type": "boolean" + }, + "right": { + "value": true, + "use_quotes": false, + "js_template": "'{value}'.toString()" + } + } + ] + }, + { + "step_type":"action", + "params": [ + { + "type": "plugin", + "params": + { + "unique_prefix": "KNWN", + "overrides":[ + { + "object_path": "settings.0", + "key":"function", + "value":"target_macs", + "target_property":"default_value", + "desired_value": "triggers.keys" + } + ] + } + + } + ] + } + ] + }], + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Flows" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "The flow." + } + ] + }, { "function": "target_macs", - "type": "list.readonly", + "type": "list.readonly", "maxLength": 50, "default_value": [], "options": [], @@ -74,9 +168,13 @@ }, { "function": "dev_Name", - "type": "readonly", + "type": "text.template", "maxLength": 50, "default_value": "(unknown)", + "value": { + "value":"(unknown)", + "override": true + }, "options": [], "localized": ["name", "description"], "name": [ diff --git a/front/settings.php b/front/settings.php index c60bb28c..5eb7fb1d 100755 --- a/front/settings.php +++ b/front/settings.php @@ -204,42 +204,34 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { // Render different input types based on the settings type let input = ""; - if (set['Type'] === 'text' || set['Type'] === 'string' || set['Type'] === 'date-time') { - input = ``; - } else if (set['Type'] === 'password') { - input = ``; - } else if (set['Type'] === 'readonly') { - input = ``; - } else if (set['Type'] === 'boolean' || set['Type'] === 'integer.checkbox') { + const setType = set['Type'].toLowerCase(); + + if (setType.startsWith('text') || setType.startsWith('string') || setType.startsWith('date-time') ) { + + if(setType.includes(".select")) + { + input = generateInputOptions(set, input, isMultiSelect = false) + + } else if(setType.includes(".multiselect")) + { + input = generateInputOptions(set, input, isMultiSelect = true) + } else{ + input = ``; + } + } else if (setType === 'integer') { + input = ``; + } else if (setType === 'password') { + input = ``; + } else if (setType === 'readonly') { + input = ``; + } else if (setType === 'boolean' || setType === 'integer.checkbox') { let checked = set['Value'] === 'True' || set['Value'] === '1' ? 'checked' : ''; - input = ``; - } else if (set['Type'] === 'integer') { - input = ``; - } else if (set['Type'] === 'text.select' || set['Type'] === 'integer.select') { - input = ``; + } else if (setType === 'integer.select') { - values = createArray(set['Value']); - options = createArray(set['Options']); - - options.forEach(option => { - let selected = values.includes(option) ? 'selected' : ''; - input += ``; - }); - - input += ''; - } else if (set['Type'] === 'text.multiselect') { - input = `'; - } else if (set['Type'] === 'subnets') { + input = generateInputOptions(set, input) + + } else if (setType === 'subnets') { input = `
@@ -253,7 +245,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
- `; options = createArray(set['Value']); @@ -264,7 +256,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { input += '
' + '
'; - } else if (set['Type'] === 'list') { + } else if (setType === 'list') { settingKeyOfLists.push(set['Code_Name']); @@ -278,8 +270,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
- `; let options = createArray(set['Value']); @@ -289,8 +280,8 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { input += '
' + `
`; - } else if (set['Type'] === 'json') { - input = ``; + } else if (setType === 'json') { + input = ``; } let eventsHtml = ""; @@ -327,6 +318,26 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { } + // + function generateInputOptions(set, input, isMultiSelect = false) + { + + multi = isMultiSelect ? "multiple" : ""; + input = `'; + + return input; + } + // todo fix function createArray(input) { // Empty array diff --git a/pialert/flows.py b/pialert/flows.py old mode 100644 new mode 100755 diff --git a/pialert/plugin.py b/pialert/plugin.py index a47be964..61017408 100755 --- a/pialert/plugin.py +++ b/pialert/plugin.py @@ -283,6 +283,7 @@ def plugin_param_from_glob_set(globalSetting): noConversion = ['text', 'string', 'integer', 'boolean', 'password', 'readonly', 'integer.select', 'text.select', 'integer.checkbox' ] arrayConversion = ['text.multiselect', 'list'] + jsonConversion = ['.template'] if setTyp in noConversion: return setVal @@ -290,6 +291,12 @@ def plugin_param_from_glob_set(globalSetting): if setTyp in arrayConversion: return flatten_array(setVal) + for item in jsonConversion: + if setTyp.endswith(item): + return json.dumps(setVal) + + + #------------------------------------------------------------------------------- # Gets the setting value def get_plugin_setting_value(plugin, function_key):