From b45e82b2a0dd22ab4190b739b6466546359042f7 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Tue, 16 Jul 2024 20:27:15 +1000 Subject: [PATCH] =?UTF-8?q?=E2=9D=8C=20NEWDEV=5FLESS=5FNAME=5FCLEANUP=20+?= =?UTF-8?q?=20Internet=20ParentNode=20fix=20+=20=F0=9F=93=9ADocs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/php/templates/header.php | 8 ++--- front/plugins/README.md | 4 +-- front/plugins/__test/test.py | 6 ++-- front/plugins/newdev_template/config.json | 28 ----------------- front/settings.php | 20 ++++++------ server/device.py | 20 ++++++++++-- server/helper.py | 38 ++--------------------- 7 files changed, 40 insertions(+), 84 deletions(-) diff --git a/front/php/templates/header.php b/front/php/templates/header.php index c1b8647b..4c0e682d 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -341,7 +341,7 @@ if ($ENABLED_DARKMODE === True) { diff --git a/front/plugins/README.md b/front/plugins/README.md index 1d7064e7..17a0f58b 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -37,7 +37,7 @@ Device-detecting plugins insert values into the `CurrentScan` database table. T | `INTRSPD` | ♻ | Internet speed test | | Script | [internet_speedtest](/front/plugins/internet_speedtest/) | | `MAINT` | ⚙ | Maintenance of logs, etc. | | Script | [maintenance](/front/plugins/maintenance/) | | `MQTT` | ▶️ | MQTT for synching to Home Assistant | | Script | [_publisher_mqtt](/front/plugins/_publisher_mqtt/) | -| `NBTSCAN` | ♻ | NSLookup (NetBIOS-based) name resolution | | Script | [nbtscan_scan](/front/plugins/nbtscan_scan/) | +| `NBTSCAN` | ♻ | Nbtscan (NetBIOS-based) name resolution | | Script | [nbtscan_scan](/front/plugins/nbtscan_scan/) | | `NEWDEV` | ⚙ | New device template | Yes | Template | [newdev_template](/front/plugins/newdev_template/) | | `NMAP` | ♻ | Nmap port scanning & discovery | | Script | [nmap_scan](/front/plugins/nmap_scan/) | | `NMAPDEV` | 🔍 | Nmap dev scan on current network | | Script | [nmap_dev_scan](/front/plugins/nmap_dev_scan/) | @@ -80,7 +80,7 @@ Device-detecting plugins insert values into the `CurrentScan` database table. T Plugins can be enabled via Settings, and can be disabled as needed. -1. Research which plugin you'd like to use below and then load the required plugins in Settings via the `LOADED_PLUGINS` setting. +1. Research which plugin you'd like to use and load the required plugins in Settings via the `LOADED_PLUGINS` setting. 1. Save the changes and review the Settings of the newly loaded plugins. 1. Change the `_RUN` Setting to the recommended or custom value as per the documentation of the given setting - If using `schedule` on a `🔍 dev scanner` plugin, make sure the schedules are the same across all `🔍 dev scanner` plugins diff --git a/front/plugins/__test/test.py b/front/plugins/__test/test.py index fb2cc51a..69b2f9ca 100755 --- a/front/plugins/__test/test.py +++ b/front/plugins/__test/test.py @@ -60,11 +60,11 @@ def main(): print(subnets) for rgx in regexes: - mylog('debug', ["[cleanDeviceName] applying regex : " + rgx]) - mylog('debug', ["[cleanDeviceName] name before regex : " + str]) + mylog('trace', ["[cleanDeviceName] applying regex : " + rgx]) + mylog('trace', ["[cleanDeviceName] name before regex : " + str]) str = re.sub(rgx, "", str) - mylog('debug', ["[cleanDeviceName] name after regex : " + str]) + mylog('trace', ["[cleanDeviceName] name after regex : " + str]) mylog('debug', ["[cleanDeviceName] output: " + str]) diff --git a/front/plugins/newdev_template/config.json b/front/plugins/newdev_template/config.json index b29f78c4..1d2b0357 100755 --- a/front/plugins/newdev_template/config.json +++ b/front/plugins/newdev_template/config.json @@ -176,34 +176,6 @@ } ] }, - { - "function": "LESS_NAME_CLEANUP", - "type": { - "dataType": "boolean", - "elements": [ - { - "elementType": "input", - "elementOptions": [{ "type": "checkbox" }], - "transformers": [] - } - ] - }, - "default_value": 0, - "options": [], - "localized": ["name", "description"], - "name": [ - { - "language_code": "en_us", - "string": "Less Name Cleanup" - } - ], - "description": [ - { - "language_code": "en_us", - "string": "Check to start using the new code for cleaning device names. Removes all labels starting with underscore and removes network domain and search list." - } - ] - }, { "function": "NAME_CLEANUP_REGEX", "type": { diff --git a/front/settings.php b/front/settings.php index e1c2d920..7fbae9e4 100755 --- a/front/settings.php +++ b/front/settings.php @@ -114,21 +114,21 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX
-
+
">
-
+
">
-
+
">
@@ -285,12 +285,14 @@ $settingsJSON_DB = json_encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX overviewSections_html += `
-
- - - - ${getString("settings_"+section+"_label")} -
+ +
+ + + + ${getString("settings_"+section+"_label")} +
+
${overviewSectionsHtml[index]} diff --git a/server/device.py b/server/device.py index cff15651..3445920e 100755 --- a/server/device.py +++ b/server/device.py @@ -223,18 +223,32 @@ def create_new_devices (db): ) SELECT cur_MAC, - CASE WHEN LENGTH(TRIM(cur_Name)) > 0 THEN cur_Name ELSE '(unknown)' END, + CASE + WHEN LENGTH(TRIM(cur_Name)) > 0 THEN cur_Name ELSE '(unknown)' + END, cur_Vendor, cur_IP, ?, ?, cur_SyncHubNodeName, {sql_generateGuid}, - CASE WHEN LENGTH(TRIM(cur_NetworkNodeMAC)) > 0 THEN cur_NetworkNodeMAC ELSE '{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}' END, + CASE + WHEN LENGTH(TRIM(cur_NetworkNodeMAC)) > 0 + AND cur_MAC != 'Internet' + THEN cur_NetworkNodeMAC + ELSE + CASE + WHEN cur_MAC = 'Internet' + THEN 'null' + ELSE '{get_setting_value('NEWDEV_dev_Network_Node_MAC_ADDR')}' + END + END, cur_PORT, cur_NetworkSite, cur_SSID, - CASE WHEN LENGTH(TRIM(cur_Type)) > 0 THEN cur_Type ELSE '{get_setting_value('NEWDEV_dev_DeviceType')}' END, + CASE + WHEN LENGTH(TRIM(cur_Type)) > 0 THEN cur_Type ELSE '{get_setting_value('NEWDEV_dev_DeviceType')}' + END, {newDevDefaults} FROM CurrentScan WHERE 1=1 diff --git a/server/helper.py b/server/helper.py index 2866e599..53412ad0 100755 --- a/server/helper.py +++ b/server/helper.py @@ -727,38 +727,6 @@ def cleanDeviceName(str, match_IP): # add matching info if match_IP: str = str + " (IP match)" - - - if get_setting_value('NEWDEV_LESS_NAME_CLEANUP'): - mylog('debug', ["[Name cleanup] Using new cleanDeviceName(" + str + ")"]) - - # replace all labels starting with underscore - str = re.sub(r'^_[^\.]*\.', '', str) # leading label - str = re.sub(r'\._[^\.]*\.', '.', str) # nested label - - # get a stub resolver for access to resolv.conf configuration - resolv = dns.resolver.Resolver() - - # replace the local domain name - str = re.sub(r'\.' + resolv.domain.to_text() + r'$', '', str) - - # replace dns search list - for name in resolv.search: - str = re.sub(r'\.' + name.to_text() + r'$', '', str) - - # removing last part of e.g. Nest-Audio-ff77ff77ff77ff77ff77ff77ff77ff77 - str = re.sub(r'-[a-fA-F0-9]{32}', '', str) - - # Remove everything after '#' including the '#' - str = re.sub(r'#.*', '', str) - - # remove trailing dot - if str.endswith('.'): - str = str[:-1] - - # done - mylog('debug', ["[Name cleanup] cleanDeviceName = " + str]) - return str # Applying cleanup REGEXEs mylog('debug', ["[Name cleanup] Using old cleanDeviceName(" + str + ")"]) @@ -766,10 +734,10 @@ def cleanDeviceName(str, match_IP): regexes = get_setting_value('NEWDEV_NAME_CLEANUP_REGEX') for rgx in regexes: - mylog('debug', ["[cleanDeviceName] applying regex : " + rgx]) - mylog('debug', ["[cleanDeviceName] name before regex : " + str]) + mylog('trace', ["[cleanDeviceName] applying regex : " + rgx]) + mylog('trace', ["[cleanDeviceName] name before regex : " + str]) str = re.sub(rgx, "", str) - mylog('debug', ["[cleanDeviceName] name after regex : " + str]) + mylog('trace', ["[cleanDeviceName] name after regex : " + str]) str = re.sub(r'\.\b', '', str) # trailing dot after words str = re.sub(r'\.$', '', str) # trailing dot at the end of the string