🔀Guess types #738

This commit is contained in:
jokob-sk
2024-07-21 12:04:42 +10:00
parent 54b6b1d408
commit df40b5caf9
2 changed files with 54 additions and 2 deletions

View File

@@ -673,7 +673,9 @@
(!emptyArr.includes(nodeData.data.port )) ? port = nodeData.data.port : port = ""; (!emptyArr.includes(nodeData.data.port )) ? port = nodeData.data.port : port = "";
(port == "" || port == 0 ) ? portBckgIcon = `<i class="fa fa-wifi"></i>` : portBckgIcon = `<i class="fa fa-ethernet"></i>`; (port == "" || port == 0 || port == 'None' ) ? portBckgIcon = `<i class="fa fa-wifi"></i>` : portBckgIcon = `<i class="fa fa-ethernet"></i>`;
portHtml = (port == "" || port == 0 || port == 'None' ) ? "" : port
// Build HTML for individual nodes in the network diagram // Build HTML for individual nodes in the network diagram
deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ? deviceIcon = (!emptyArr.includes(nodeData.data.icon )) ?
@@ -682,7 +684,7 @@
</div>` : ""; </div>` : "";
devicePort = `<div class="netPort" devicePort = `<div class="netPort"
style="width:${emSize*sizeCoefficient}em;height:${emSize*sizeCoefficient}em"> style="width:${emSize*sizeCoefficient}em;height:${emSize*sizeCoefficient}em">
${port}</div> ${portHtml}</div>
<div class="portBckgIcon" <div class="portBckgIcon"
style="margin-left:-${emSize*sizeCoefficient}em;"> style="margin-left:-${emSize*sizeCoefficient}em;">
${portBckgIcon} ${portBckgIcon}

View File

@@ -431,6 +431,22 @@ def update_devices_data_from_scan (db):
if len(recordsToUpdate) > 0: if len(recordsToUpdate) > 0:
sql.executemany ("UPDATE Devices SET dev_Icon = ? WHERE dev_MAC = ? ", recordsToUpdate ) 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') mylog('debug','[Update Devices] Update devices end')
@@ -671,4 +687,38 @@ def guess_icon(vendor, mac, ip, name, default):
return result 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