From df40b5caf9c3be44dcfa3d909d2d076e9f29fd83 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sun, 21 Jul 2024 12:04:42 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=80Guess=20types=20#738?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/network.php | 6 ++++-- server/device.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/front/network.php b/front/network.php index 88bcfa86..a85ac2d4 100755 --- a/front/network.php +++ b/front/network.php @@ -673,7 +673,9 @@ (!emptyArr.includes(nodeData.data.port )) ? port = nodeData.data.port : port = ""; - (port == "" || port == 0 ) ? portBckgIcon = `` : portBckgIcon = ``; + (port == "" || port == 0 || port == 'None' ) ? portBckgIcon = `` : portBckgIcon = ``; + + portHtml = (port == "" || port == 0 || port == 'None' ) ? "" : port // Build HTML for individual nodes in the network diagram deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ? @@ -682,7 +684,7 @@ ` : ""; devicePort = `
- ${port}
+ ${portHtml}
${portBckgIcon} diff --git a/server/device.py b/server/device.py index e2b24e5f..7851639a 100755 --- a/server/device.py +++ b/server/device.py @@ -431,6 +431,22 @@ def update_devices_data_from_scan (db): if len(recordsToUpdate) > 0: sql.executemany ("UPDATE Devices SET dev_Icon = ? WHERE dev_MAC = ? ", recordsToUpdate ) + + # Guess Type + recordsToUpdate = [] + query = """SELECT * FROM Devices + WHERE dev_DeviceType in ('', 'null') + OR dev_DeviceType IS NULL""" + default_type = get_setting_value('NEWDEV_dev_DeviceType') + + for device in sql.execute (query) : + # Conditional logic for dev_Icon guessing + dev_DeviceType = guess_type(device['dev_Vendor'], device['dev_MAC'], device['dev_LastIP'], device['dev_Name'], default_type) + + recordsToUpdate.append ([dev_DeviceType, device['dev_MAC']]) + + if len(recordsToUpdate) > 0: + sql.executemany ("UPDATE Devices SET dev_DeviceType = ? WHERE dev_MAC = ? ", recordsToUpdate ) mylog('debug','[Update Devices] Update devices end') @@ -671,4 +687,38 @@ def guess_icon(vendor, mac, ip, name, default): return result + +#------------------------------------------------------------------------------- +# Guess device type +def guess_type(vendor, mac, ip, name, default): + result = default + mac = mac.upper() + vendor = vendor.lower() + name = name.lower() + + # Guess icon based on vendor + if any(brand in vendor for brand in {"samsung", "motorola"}): + result = "Phone" + elif "cisco" in vendor: + result = "Router" + elif "lg" in vendor: + result = "TV" + elif "google" in vendor: + result = "Phone" + elif "ubiquiti" in vendor: + result = "Router" + + # Guess type based on MAC address patterns + elif mac == "INTERNET": + result = "Internet" + + # Guess type based on name + elif 'google' in name: + result = "Phone" + + # Guess type based on IP address ranges + elif ip == ("192.168.1.1"): + result = "Router" + + return result \ No newline at end of file