BE: linting fixes 2

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2025-11-22 20:43:36 +11:00
parent 5c14b34a8b
commit ebeb7a07af
63 changed files with 124 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
#
# -------------------------------------------------------------------------------
# NetAlertX v2.70 / 2021-02-01

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import json
import time
import threading

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import base64

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import base64

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sys

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
import os
import sqlite3

View File

@@ -136,23 +136,6 @@ def ensure_views(sql) -> bool:
"""CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac;"""
)
sql.execute(""" CREATE VIEW IF NOT EXISTS LatestEventsPerMAC AS
WITH RankedEvents AS (
SELECT
e.*,
ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num
FROM Events AS e
)
SELECT
e.*,
d.*,
c.*
FROM RankedEvents AS e
LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac
INNER JOIN CurrentScan AS c ON e.eve_MAC = c.cur_MAC
WHERE e.row_num = 1;
""")
# handling the Convert_Events_to_Sessions / Sessions screens
sql.execute("""DROP VIEW IF EXISTS Convert_Events_to_Sessions;""")
sql.execute("""CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC,

View File

@@ -624,6 +624,11 @@ def extract_ip_addresses(text):
# Helper function to determine if a MAC address is random
def is_random_mac(mac):
"""Determine if a MAC address is random, respecting user-defined prefixes not to mark as random."""
# Validate input
if not mac or len(mac) < 2:
return False
# Check if second character matches "2", "6", "A", "E" (case insensitive)
is_random = mac[1].upper() in ["2", "6", "A", "E"]
@@ -631,7 +636,7 @@ def is_random_mac(mac):
if is_random:
not_random_prefixes = get_setting_value("UI_NOT_RANDOM_MAC")
for prefix in not_random_prefixes:
if mac.startswith(prefix):
if mac.upper().startswith(prefix.upper()):
is_random = False
break
return is_random

View File

@@ -10,7 +10,7 @@ import re
# Register NetAlertX libraries
import conf
from const import fullConfPath, fullConfFolder, default_tz
from helper import getBuildTimeStampAndVersion, fixPermissions, collect_lang_strings, updateSubnets, generate_random_string
from helper import getBuildTimeStampAndVersion, collect_lang_strings, updateSubnets, generate_random_string
from utils.datetime_utils import timeNowDB
from app_state import updateState
from logger import mylog
@@ -680,10 +680,11 @@ def importConfigs(pm, db, all_plugins):
ccd('VERSION', new_version , c_d, '_KEEP_', '_KEEP_', '_KEEP_', '_KEEP_', None, "_KEEP_", None, None, True)
write_notification(f'[Upgrade]: App upgraded from <code>{prev_version}</code> to \
<code>{new_version}</ code> 🚀 Please clear the cache: \
<ol> <li>Click OK below</li> <li>Clear the browser cache (shift + \
browser refresh button)</li> <li> Clear app cache with the <i class="fa-solid fa-rotate"></i> \
(reload) button in the header</li><li>Go to Settings and click Save</li> </ol>\
<code>{new_version}</code> 🚀 Please clear the cache: \
<ol> <li>Click OK below</li> \
<li>Clear the browser cache (shift + browser refresh button)</li> \
<li> Clear app cache with the <i class="fa-solid fa-rotate"></i> (reload) button in the header</li>\
<li>Go to Settings and click Save</li> </ol>\
Check out new features and what has changed in the \
<a href="https://github.com/jokob-sk/NetAlertX/releases" target="_blank">📓 release notes</a>.',
'interrupt',
@@ -804,8 +805,6 @@ def renameSettings(config_file):
str(config_file) + "_temp", str(config_file)
) # Convert config_file to a string
# ensure correct ownership
fixPermissions()
else:
mylog(
"debug", "[Config] No old setting names found in the file. No changes made."

View File

@@ -1,4 +1,4 @@
# !/usr/bin/env python
#!/usr/bin/env python
# from datetime import datetime
from dateutil import parser