})
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
})
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
# Import standard modules
import os
+import platform
+import subprocess
# -----------------------------
# Load hash from file
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
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;
}
}
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
}
});
}
e.preventDefault();
resetSorting(sortState);
clearSearch();
- filterHosts('');
+ filterAliases('');
}
});
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;
}
}