From fa568f794e3d92cdfa26f10d25994744fe265804 Mon Sep 17 00:00:00 2001 From: tommal Date: Mon, 6 Jul 2026 16:48:49 +0200 Subject: [PATCH] Hide the passwords --- manager-solution/configurator_server.py | 55 ++++++++- manager-solution/dashboard/index.html | 157 ++++++++++++++++-------- 2 files changed, 161 insertions(+), 51 deletions(-) diff --git a/manager-solution/configurator_server.py b/manager-solution/configurator_server.py index 1692086..43e7fe0 100644 --- a/manager-solution/configurator_server.py +++ b/manager-solution/configurator_server.py @@ -15,6 +15,8 @@ DASHBOARD_DIR = ROOT_DIR / "dashboard" CONFIG_PATH = ROOT_DIR / "manager" / "config.json" MANAGER_DIR = ROOT_DIR / "manager" RECOVERY_COMMANDS_PATH = PROJECT_DIR / "docker-run-commands.sh" +MANAGER_CONTAINER_NAME = os.getenv("FIS_MANAGER_CONTAINER_NAME", "fis_manager") +MANAGER_RESTART_TIMEOUT_SECONDS = int(os.getenv("MANAGER_RESTART_TIMEOUT_SECONDS", "30")) sys.path.insert(0, str(MANAGER_DIR)) @@ -116,6 +118,45 @@ def write_recovery_commands_from_disk(): write_recovery_commands(json.load(handle)) +def restart_manager_container(): + try: + result = subprocess.run( + ["docker", "restart", MANAGER_CONTAINER_NAME], + check=True, + capture_output=True, + text=True, + timeout=MANAGER_RESTART_TIMEOUT_SECONDS, + ) + except FileNotFoundError: + return { + "attempted": True, + "ok": False, + "error": "Docker CLI not found; run manually: docker restart " + f"{MANAGER_CONTAINER_NAME}", + } + except subprocess.TimeoutExpired: + return { + "attempted": True, + "ok": False, + "error": f"Timed out restarting {MANAGER_CONTAINER_NAME}", + } + except subprocess.CalledProcessError as exc: + error = (exc.stderr or exc.stdout or str(exc)).strip() + return {"attempted": True, "ok": False, "error": error} + + return {"attempted": True, "ok": True, "output": result.stdout.strip()} + + +def read_compact_config_from_disk(): + if not CONFIG_PATH.exists(): + return None + try: + with CONFIG_PATH.open(encoding="utf-8") as handle: + return compact_config(json.load(handle)) + except (OSError, ValueError, json.JSONDecodeError): + return None + + def detect_lan_ip(): configured_ip = os.getenv("CONFIGURATOR_PUBLIC_IP") if configured_ip: @@ -212,6 +253,7 @@ class ConfiguratorHandler(SimpleHTTPRequestHandler): content_length = int(self.headers.get("Content-Length", "0")) payload = self.rfile.read(content_length) raw = json.loads(payload.decode("utf-8")) + previous_compact = read_compact_config_from_disk() normalized = normalize_config(raw) compact = compact_config(raw) CONFIG_PATH.write_text(json.dumps(compact, indent=2) + "\n", encoding="utf-8") @@ -223,7 +265,18 @@ class ConfiguratorHandler(SimpleHTTPRequestHandler): self._send_json({"ok": False, "error": f"Invalid JSON: {exc}"}, status=HTTPStatus.BAD_REQUEST) return - self._send_json({"ok": True, "config": compact, "normalized": normalized}) + manager_restart = {"attempted": False, "ok": True} + if compact != previous_compact: + manager_restart = restart_manager_container() + + self._send_json( + { + "ok": True, + "config": compact, + "normalized": normalized, + "manager_restart": manager_restart, + } + ) def log_message(self, format, *args): return diff --git a/manager-solution/dashboard/index.html b/manager-solution/dashboard/index.html index 5b8045d..89e07fa 100644 --- a/manager-solution/dashboard/index.html +++ b/manager-solution/dashboard/index.html @@ -6,58 +6,57 @@ Installazione Fiscality @@ -141,7 +174,6 @@
-

Configuratore installazione

Configura Fiscality senza modificare il JSON a mano.

Crea gli utenti aziendali, controlla porte e nomi dei container, salva in manager/config.json, poi esegui ./install.sh.

@@ -163,9 +195,12 @@
-
-

Valori predefiniti

-
+
+ +

Valori predefiniti

+ Mostra/nascondi +
+
@@ -195,7 +230,7 @@
-
+
@@ -211,7 +246,7 @@

Utente

-
+
@@ -222,21 +257,21 @@
- +
-
+
-
+
-
+
@@ -303,6 +338,26 @@ return message; } + function managerRestartMessage(result, savedMessage) { + const restart = result.manager_restart; + if (!restart?.attempted) { + return { + message: `${savedMessage} Nessuna modifica rilevata: restart non necessario.`, + kind: "ok" + }; + } + if (restart.ok) { + return { + message: `${savedMessage} Manager fis_manager riavviato.`, + kind: "ok" + }; + } + return { + message: `${savedMessage} Attenzione: restart di fis_manager non riuscito: ${restart.error || "errore sconosciuto"}`, + kind: "error" + }; + } + function stringify(value) { return JSON.stringify(value ?? {}, null, 2); } @@ -440,7 +495,8 @@ } renderDefaults(result.config); renderUsers(result.config); - setStatus("Configurazione salvata in manager/config.json.", "ok"); + const status = managerRestartMessage(result, "Configurazione salvata in manager/config.json."); + setStatus(status.message, status.kind); } catch (error) { setStatus(error.message, "error"); } @@ -458,9 +514,10 @@ if (!response.ok || !result.ok) { throw new Error(result.error || "Validazione non riuscita"); } - setStatus("Validazione completata e configurazione normalizzata salvata.", "ok"); renderDefaults(result.config); renderUsers(result.config); + const status = managerRestartMessage(result, "Validazione completata e configurazione normalizzata salvata."); + setStatus(status.message, status.kind); } catch (error) { setStatus(error.message, "error"); }