diff --git a/app.py b/app.py index dc5d207..9cd6fa3 100644 --- a/app.py +++ b/app.py @@ -257,6 +257,7 @@ last_seen_reflector = {} node_info = {} node_general = {} node_versions = {} +gateway_states = {} if os.path.exists(CACHE_FILE): try: @@ -313,7 +314,7 @@ def on_connect(client, userdata, flags, reason_code, properties=None): topics_list = config.get('mqtt', {}).get('topics', default_topics) subscribe_list = [(topic, 0) for topic in topics_list] - subscribe_list.append(("+/+/log", 0)) # Ascolto dinamico dei log + subscribe_list.append(("+/+/log", 0)) client.subscribe(subscribe_list) logger.info(f"Subscribed to {len(subscribe_list)} MQTT topics.") @@ -343,7 +344,6 @@ def on_message(client, userdata, msg): p0 = parts[0].lower().replace('-', '') p2 = parts[2].lower().replace('-', '') if len(parts) > 2 else "" - # --- LOG MANAGEMENT (ESTRAZIONE VERSIONI E GIT ID) --- if len(parts) >= 3 and parts[2].lower() == 'log': if cid not in node_versions: node_versions[cid] = {} @@ -523,6 +523,19 @@ def on_message(client, userdata, msg): elif "p25" in p0: proto = "P25" elif "dstar" in p0: proto = "D-STAR" + if cid not in gateway_states: + gateway_states[cid] = {} + + if 'status' in data: + gateway_states[cid][proto] = {"action": "status", "dest": data['status'].get('message', 'IDLE')} + notify_update() + elif 'link' in data: + l = data['link'] + g_dest = str(l.get('reflector') or l.get('talkgroup') or '---').strip() + g_action = l.get('action', '') + gateway_states[cid][proto] = {"action": g_action, "dest": g_dest} + notify_update() + m = "" if 'status' in data: m = data['status'].get('message', '') @@ -669,7 +682,6 @@ def add_security_headers(resp): def get_git_commit(): try: - # Legge i primi 7 caratteri dell'hash del commit corrente return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip() except Exception: return "sconosciuta" @@ -701,6 +713,35 @@ def get_states(): for c, d in node_versions.items(): clean_versions[c] = {k: v for k, v in d.items() if not k.startswith('_')} + # --- INIEZIONE DMR NETWORKS DA CONFIGURAZIONE (Versione 4.0) --- + enriched_gateway_states = dict(gateway_states) + + for cid, confs in device_configs.items(): + if 'dmrgateway' in confs: + dmr_conf = confs['dmrgateway'] + if isinstance(dmr_conf, dict) and 'raw_text' in dmr_conf: + raw = dmr_conf['raw_text'] + active_dmr_nets = [] + + # Cerca le sezioni [DMR Network 1] fino a [DMR Network 5] + for i in range(1, 6): + section_name = f"[DMR Network {i}]" + if section_name in raw: + # Estrai blocco della sezione + block = raw.split(section_name)[1].split('[')[0] + # Cerca Enabled=1 + if re.search(r'^Enabled\s*=\s*1', block, re.MULTILINE | re.IGNORECASE): + # Cerca Name= (es. Name=BM_2222) + m_name = re.search(r'^Name\s*=\s*(.+)', block, re.MULTILINE | re.IGNORECASE) + net_name = m_name.group(1).strip() if m_name else f"Net {i}" + active_dmr_nets.append(net_name) + + if active_dmr_nets: + if cid not in enriched_gateway_states: + enriched_gateway_states[cid] = {} + enriched_gateway_states[cid]['DMR_NETS'] = active_dmr_nets + # ---------------------------------------------------------------- + return jsonify({ "states": client_states, "telemetry": client_telemetry, @@ -709,7 +750,8 @@ def get_states(): "general": node_general, "last_seen": seen_ages(), "uptime": int(time.time() - START_TIME), - "versions": clean_versions + "versions": clean_versions, + "gateway_states": enriched_gateway_states }) @app.route('/api/stats') @@ -1294,19 +1336,10 @@ def check_server_update(): return err("Unauthorized", 403) try: - # Aggiorna le informazioni dal remote senza unire i file subprocess.run(['git', 'fetch'], timeout=10, cwd=BASE_DIR) - - # Confronta il commit locale con quello remoto local_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=BASE_DIR).decode('utf-8').strip() remote_hash = subprocess.check_output(['git', 'rev-parse', '@{u}'], cwd=BASE_DIR).decode('utf-8').strip() - update_available = local_hash != remote_hash - - # --- LOG DI DEBUG --- - logger.info(f"π Controllo OTA: Local={local_hash[:7]} | Remote={remote_hash[:7]} | Update={update_available}") - # -------------------- - return jsonify({"success": True, "update_available": update_available}) except Exception as e: logger.error(f"Errore controllo aggiornamenti server: {e}") @@ -1320,16 +1353,10 @@ def apply_server_update(): try: audit(auth['username'], 'SERVER', 'SERVER_OTA_UPDATE') - logger.warning(f"π Aggiornamento OTA del server avviato da {auth['username']}") - - # Esegue il pull subprocess.run(['git', 'pull', '--ff-only'], timeout=30, cwd=BASE_DIR, check=True) - - # Programma il riavvio (esce dal processo, systemd lo farΓ ripartire) def restart_server(): time.sleep(2) os._exit(1) - threading.Thread(target=restart_server, daemon=True).start() return jsonify({"success": True}) except subprocess.CalledProcessError as e: diff --git a/templates/index.html b/templates/index.html index fbe4973..3dd1c7c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -39,7 +39,24 @@ .theme-switch { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 6px 14px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.85rem; font-family: 'Inter', sans-serif; transition: all 0.2s; } .theme-switch:hover { color: var(--text-main); border-color: var(--text-main); } - .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; max-width: 1400px; margin: 30px auto; padding: 0 20px; } + /* FILTRI E CONTROLLI VIEW (Versione 4.0) */ + .filter-bar { background: var(--topbar-bg); border-radius: 12px; border: 1px solid var(--border-color); padding: 10px 20px; display: flex; gap: 15px; flex-wrap: wrap; align-items: center; justify-content: space-between; box-shadow: 0 4px 12px rgba(0,0,0,0.2); margin-bottom: 20px; } + .filter-pill { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 6px 14px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease; } + .filter-pill:hover { background: rgba(255,255,255,0.05); color: var(--text-main); } + .filter-pill.active { background: rgba(59, 130, 246, 0.15); color: var(--primary); border-color: var(--primary); } + + /* GRIGLIA E LISTA (Versione 4.0) */ + .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; max-width: 1400px; margin: 0 auto; padding: 0 20px; } + + .list-view { display: flex; flex-direction: column; gap: 10px; max-width: 1400px; margin: 0 auto; padding: 0 20px; } + .list-view .card { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 15px; gap: 15px; } + .list-view .card-header { border-bottom: none; padding-bottom: 0; margin-bottom: 0; flex: 1 1 200px; } + .list-view .health-bar { display: flex; flex-wrap: nowrap; margin-bottom: 0; flex: 1 1 auto; justify-content: center; } + .list-view .freq-bar { margin-bottom: 0; padding: 5px 10px; flex: 1 1 auto; } + .list-view .ts-container { flex-direction: row; margin-bottom: 0; flex: 1 1 250px; } + .list-view .terminal-log { display: none; } + .list-view .node-meta { margin-bottom: 0; text-align: left; } + .list-view .admin-dropdown { width: auto; flex: 0 0 auto; } .card { background: var(--card-bg) !important; border-radius: 12px; padding: 20px; border: 1px solid var(--border-color); border-top: 3px solid var(--border-color) !important; display: flex; flex-direction: column; box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important; filter: none !important; opacity: 1 !important; transition: all 0.3s ease; } @@ -52,24 +69,28 @@ .health-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 0.75rem; font-weight: 600; background: rgba(0,0,0,0.2); padding: 10px; border-radius: 8px; margin-bottom: 15px; border: 1px solid var(--border-color); font-family: 'JetBrains Mono', monospace; text-align: center; } .health-bar > span { background: rgba(255,255,255,0.03); padding: 6px; border-radius: 6px; } - .freq-bar { display: flex; justify-content: space-around; font-size: 0.8rem; font-weight: 800; background: rgba(0,0,0,0.2); padding: 8px 10px; border-radius: 8px; margin-bottom: 15px; border: 1px dashed var(--border-color); font-family: 'JetBrains Mono', monospace; } + .freq-bar { display: flex; justify-content: space-around; font-size: 0.8rem; font-weight: 800; background: rgba(0,0,0,0.2); padding: 8px 10px; border-radius: 8px; margin-bottom: 10px; border: 1px dashed var(--border-color); font-family: 'JetBrains Mono', monospace; } .freq-tx { color: #f87171; } .freq-rx { color: #4ade80; } .seen-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 0.7rem; font-family: 'JetBrains Mono', monospace; color: var(--text-muted); margin: -6px 0 12px 0; } .seen-item b { font-weight: 700; } .seen-item.ok b { color: var(--success); } .seen-item.warn, .seen-item.warn b { color: #f59e0b; font-weight: 700; } - .node-meta { font-size: 0.75rem; color: #8b949e; text-align: center; margin-bottom: 15px; line-height: 1.4; } + + .node-meta { font-size: 0.75rem; color: #8b949e; text-align: center; margin-bottom: 10px; line-height: 1.4; } .node-meta-item { display: block; } .type-badge { font-size: 0.65rem; padding: 4px 8px; border-radius: 6px; font-weight: 700; text-transform: uppercase; display: inline-block; margin-left: 0; vertical-align: middle; } .type-repeater { background: rgba(59, 130, 246, 0.15); color: var(--primary); border: 1px solid var(--primary); } .type-hotspot { background: rgba(139, 92, 246, 0.15); color: var(--accent); border: 1px solid var(--accent); } - .status-display { text-align: center; font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 700; padding: 8px; border-radius: 6px; background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); margin-bottom: 15px; color: var(--text-muted); } + .status-display { text-align: center; font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 700; padding: 8px; border-radius: 6px; background: rgba(0,0,0,0.2); border: 1px solid var(--border-color); margin-bottom: 10px; color: var(--text-muted); } .card.online .status-display { color: var(--success); border-color: rgba(16, 185, 129, 0.4); background: rgba(16, 185, 129, 0.1); } .status-offline { color: var(--danger) !important; border-color: rgba(239, 68, 68, 0.4) !important; } + /* GATEWAY BAR (Versione 4.0) */ + .gateway-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 15px; justify-content: center; } + .ts-container { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; } .dmr-info { font-size: 0.85rem; font-weight: 600; font-family: 'JetBrains Mono', monospace; padding: 8px 12px; border-radius: 6px; background: rgba(0,0,0,0.2) !important; border: 1px solid var(--border-color); border-left: 4px solid var(--border-color) !important; color: var(--text-muted) !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: all 0.3s; } @@ -110,52 +131,11 @@ input:disabled { opacity: 0.5; cursor: not-allowed; } option { background: var(--card-bg); color: var(--text-main); } - /* Stili per le Mini-Card (HOME) */ - .mini-card { - background: var(--card-bg); - border-radius: 10px; - border: 1px solid var(--border-color); - padding: 15px 10px; - display: flex; - flex-direction: column; - align-items: center; - justify-content: space-between; - text-align: center; - transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease; - cursor: pointer; - box-shadow: 0 4px 6px rgba(0,0,0,0.1); - height: 105px; - width: 160px; /* <--- AGGIUNGI QUESTA RIGA */ - overflow: hidden; - } - .mini-card:hover { - transform: translateY(-4px); - box-shadow: 0 8px 15px rgba(0,0,0,0.3); - } - .mini-card-content { - width: 100%; - overflow: hidden; - } - .mini-card-name { - font-weight: 800; - font-size: 0.95rem; - width: 100%; - display: block; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - .mini-card-status { - font-size: 0.65rem; - font-weight: 800; - padding: 4px 6px; - border-radius: 6px; - width: 100%; - display: block; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } + .mini-card { background: var(--card-bg); border-radius: 10px; border: 1px solid var(--border-color); padding: 15px 10px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.1); height: 105px; width: 160px; overflow: hidden; } + .mini-card:hover { transform: translateY(-4px); box-shadow: 0 8px 15px rgba(0,0,0,0.3); } + .mini-card-content { width: 100%; overflow: hidden; } + .mini-card-name { font-weight: 800; font-size: 0.95rem; width: 100%; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + .mini-card-status { font-size: 0.65rem; font-weight: 800; padding: 4px 6px; border-radius: 6px; width: 100%; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } @media (max-width: 768px) { #top-bar-container { top: 0; padding: 10px; margin-bottom: 15px; } @@ -169,14 +149,9 @@ .nav-tabs { position: fixed; bottom: 0; left: 0; width: 100%; background: var(--topbar-bg); border-top: 1px solid var(--border-color); margin: 0; padding: 10px 0; justify-content: space-around; z-index: 1000; flex-direction: row; gap: 0; padding-bottom: env(safe-area-inset-bottom, 10px); box-shadow: 0 -4px 15px rgba(0,0,0,0.3); } .nav-tab { font-size: 1rem; padding: 12px; flex: 1; text-align: center; border-radius: 0; } body { padding-bottom: 70px; } - - .table-container { background: transparent; border: none; box-shadow: none; margin: 0 10px 20px 10px; } - .table-container table, .table-container thead, .table-container tbody, .table-container th, .table-container td, .table-container tr { display: block; width: 100%; } - .table-container thead tr { position: absolute; top: -9999px; left: -9999px; } - .table-container tr { border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 15px; background: var(--card-bg); padding: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } - .table-container td { border: none; border-bottom: 1px solid rgba(255,255,255,0.05); position: relative; padding-left: 40%; text-align: left; font-size: 0.85rem; min-height: 35px; display: flex; align-items: center; } - .table-container td:before { position: absolute; top: 50%; transform: translateY(-50%); left: 10px; width: 35%; padding-right: 10px; white-space: nowrap; font-weight: bold; color: var(--text-muted); content: attr(data-label); font-family: 'Inter', sans-serif; font-size: 0.75rem; text-transform: uppercase; } - .table-container td:last-child { border-bottom: 0; } + + .filter-bar { flex-direction: column; } + .list-view .card { flex-direction: column; align-items: stretch; } } @@ -201,11 +176,30 @@