From: Giorgio Ravera Date: Fri, 22 May 2026 15:20:14 +0000 (+0200) Subject: Minor fixes X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;h=95d4389768883c57a2649c0f54ecf97b953362cf;p=network-manager.git Minor fixes --- diff --git a/backend/routes/aliases.py b/backend/routes/aliases.py index 026282b..242d559 100644 --- a/backend/routes/aliases.py +++ b/backend/routes/aliases.py @@ -75,6 +75,9 @@ def api_get_aliases(request: Request): }) def api_get_alias(request: Request, alias_id: int): + # Inizializzazioni + start_ns = time.monotonic_ns() + try: alias = get_alias(alias_id) if not alias: # None or empty dict diff --git a/backend/routes/hosts.py b/backend/routes/hosts.py index 817e363..577f2fa 100644 --- a/backend/routes/hosts.py +++ b/backend/routes/hosts.py @@ -76,6 +76,9 @@ def api_get_hosts(request: Request): }) def api_get_host(request: Request, host_id: int): + # Inizializzazioni + start_ns = time.monotonic_ns() + try: host = get_host(host_id) if not host: # None or empty dict diff --git a/backend/utils.py b/backend/utils.py index ee4d46d..2377866 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -2,6 +2,8 @@ # Import standard modules import os +import platform +import subprocess # ----------------------------- # Load hash from file @@ -18,3 +20,40 @@ def load_hash(path: str): def normalize(value): return value.strip() if value and value.strip() else None +# ----------------------------- +# convert string to int (returns None if conversion fails) +# ----------------------------- +def to_int(v: str): + v = (v or "").strip() + if not v or v.lower() == "null": + return None + try: + return int(v) + except ValueError: + return None + +# ----------------------------- +# convert string to bool (returns None if conversion fails) +# ----------------------------- +def to_bool(v: str): + v = (v or "").strip().lower() + if v in ("true", "1", "yes", "y"): + return True + if v in ("false", "0", "no", "n"): + return False + return None + +# ----------------------------- +# check if host is active (ping) +# ----------------------------- +def is_host_active(ip: str, timeout: int = 1) -> bool: + try: + result = subprocess.run( + ["ping", "-c", "1", "-W", str(timeout), ip], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL + ) + return result.returncode == 0 + + except Exception: + return False diff --git a/frontend/js/aliases.js b/frontend/js/aliases.js index 5e7e360..aaeb124 100644 --- a/frontend/js/aliases.js +++ b/frontend/js/aliases.js @@ -290,12 +290,12 @@ async function editAlias(id) { document.getElementById("aliasTarget").value = data.target ?? ""; document.getElementById("aliasDescription").value = data.description ?? ""; document.getElementById("aliasSSL").checked = !!data.ssl_enabled; - if (data.visibility == 0) { - document.getElementById("aliasVisibilityLocal").checked = true; + if (data.visibility == 2) { + document.getElementById("aliasVisibilityAlias").checked = true; } else if (data.visibility == 1){ document.getElementById("aliasVisibilityGlobal").checked = true; } else { - document.getElementById("aliasVisibilityAlias").checked = true; + document.getElementById("aliasVisibilityLocal").checked = true; } } @@ -611,7 +611,7 @@ document.addEventListener("DOMContentLoaded", async () => { e.stopPropagation(); // evita che arrivi al listener globale resetSorting(sortState); clearSearch(); // svuota input e ricarica tabella (come definito nella tua funzione) - filterHosts(''); // ripristina tabella + filterAliases(''); // ripristina tabella } }); } @@ -628,7 +628,7 @@ document.addEventListener("DOMContentLoaded", async () => { e.preventDefault(); resetSorting(sortState); clearSearch(); - filterHosts(''); + filterAliases(''); } }); diff --git a/frontend/js/hosts.js b/frontend/js/hosts.js index 3f8e2d7..36e7c9e 100644 --- a/frontend/js/hosts.js +++ b/frontend/js/hosts.js @@ -302,12 +302,12 @@ async function editHost(id) { document.getElementById("hostMAC").value = data.mac ?? ""; document.getElementById("hostDescription").value = data.description ?? ""; document.getElementById("hostSSL").checked = !!data.ssl_enabled; - if (data.visibility == 0) { - document.getElementById("hostVisibilityLocal").checked = true; + if (data.visibility == 2) { + document.getElementById("hostVisibilityAlias").checked = true; } else if (data.visibility == 1){ document.getElementById("hostVisibilityGlobal").checked = true; } else { - document.getElementById("hostVisibilityAlias").checked = true; + document.getElementById("hostVisibilityLocal").checked = true; } }