]> git.giorgioravera.it Git - network-manager.git/commitdiff
Minor fixes
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Fri, 22 May 2026 15:20:14 +0000 (17:20 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Fri, 22 May 2026 15:20:14 +0000 (17:20 +0200)
backend/routes/aliases.py
backend/routes/hosts.py
backend/utils.py
frontend/js/aliases.js
frontend/js/hosts.js

index 026282b794949ba106ae27cd60e5cf941ee2273a..242d559ad6ae4967cded4fc2958fa532be009d61 100644 (file)
@@ -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
index 817e3639bb4a727ecd5978e6d1e821d30a2c0d80..577f2fad0c011f5082460c7269cc9dd3f1a08059 100644 (file)
@@ -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
index ee4d46dee0544c00283e3883afb4860125533105..2377866ebdd1e4493d8847e46bb4bd7b3c023d25 100644 (file)
@@ -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
index 5e7e3607ccd1c083bf4e0aa4b456a5e97a4610b2..aaeb1246a2b7de97ea826076ffcdfdbbed36736e 100644 (file)
@@ -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('');
         }
     });
 
index 3f8e2d7805b7798f8ee104ef1b54ed314cbd5353..36e7c9ecc9ad3f24a19b1f97573d6ab43d8e179e 100644 (file)
@@ -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;
     }
 }