Compare commits
31
Commits
v2.0.0
...
dad1a656fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dad1a656fe | ||
|
|
b33d495474 | ||
|
|
38f7efce6b | ||
|
|
24c81c1abb | ||
|
|
126ad8cdaf | ||
|
|
2f0abdc9bf | ||
|
|
a1449eedfb | ||
|
|
2fa1b476c4 | ||
|
|
8ce2ed243d | ||
|
|
8ee2958b8e | ||
|
|
298478e36d | ||
|
|
502244dff4 | ||
|
|
c5dcacefd1 | ||
|
|
cae5c4ea83 | ||
|
|
445cc5e97d | ||
|
|
c502da2dfb | ||
|
|
3b45c14ded | ||
|
|
255066eefa | ||
|
|
74d7910fec | ||
|
|
bcb885c878 | ||
|
|
3f59b905c7 | ||
|
|
869b09f8a9 | ||
|
|
bdfc4043f8 | ||
|
|
caf77819a2 | ||
|
|
47e51e10f0 | ||
|
|
d56d3d6b5b | ||
|
|
cd2960d00b | ||
|
|
95b5dd4cbc | ||
|
|
74d7c41b93 | ||
|
|
cf4dd93c06 | ||
|
|
9fb0b01f30 |
@@ -37,6 +37,27 @@ The server acts as the brain of the network:
|
||||
Please note that **Web Push Notifications** and the **Service Worker** require a secure connection to function. For security reasons, modern browsers only enable these features over **HTTPS**. If you are accessing the console via HTTP (outside of `localhost`), the "Push" button and notification registration will not work. We recommend using a reverse proxy (like Nginx, Caddy, or Traefik) with an SSL certificate.
|
||||
**Pro Tip:** You can use Let's Encrypt to get a free SSL certificate for your domain.
|
||||
|
||||
### ⚠️ Reverse Proxy & WebSocket Configuration
|
||||
If you expose the Fleet Console through a reverse proxy like **Apache** on a public IP (HTTPS), standard HTTP proxying will drop Socket.IO real-time connections, causing the dashboard's tables to randomly clear or flash.
|
||||
You must enable the WebSocket tunnel in Apache:
|
||||
```bash
|
||||
sudo a2enmod proxy_wstunnel rewrite headers
|
||||
```
|
||||
And insert the **Rewrite** rules *before* the `ProxyPass` directives inside your `<VirtualHost *:443>` block:
|
||||
```apache
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://127.0.0.1:9000/$1 [P,L]
|
||||
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
|
||||
RewriteRule /(.*) http://127.0.0.1:9000/$1 [P,L]
|
||||
|
||||
ProxyPass /socket.io/ ws://127.0.0.1:9000/socket.io/
|
||||
ProxyPassReverse /socket.io/ ws://127.0.0.1:9000/socket.io/
|
||||
|
||||
ProxyPass / http://127.0.0.1:9000/
|
||||
ProxyPassReverse / http://127.0.0.1:9000/
|
||||
```
|
||||
|
||||
#### 🛠️ Advanced Remote Control & Maintenance
|
||||
* **Remote .INI Editor:** Edit daemon configuration files (e.g., MMDVMHost.ini) directly from the web interface without SSH access.
|
||||
* **Service Management:** Start, Stop, or Restart remote system daemons with a single click.
|
||||
@@ -82,6 +103,7 @@ pip install -r requirements.txt
|
||||
2. Configure your MQTT broker credentials.
|
||||
3. Define your repeaters in `clients.json`.
|
||||
4. Generate VAPID keys at [vapidkeys.com](https://vapidkeys.com/) and add them to `config.json` to enable Web Push notifications. *(Note: Push notifications require HTTPS).*
|
||||
5. Configure dynamic log rotation sizes (`log_max_mb` and `log_backup_count`) directly in `config.json` to manage disk space.
|
||||
|
||||
#### 4. Running as a Service
|
||||
To run the server continuously in production using Gunicorn:
|
||||
@@ -126,6 +148,27 @@ Il server agisce da cervello della rete:
|
||||
Si prega di notare che le **Notifiche Web Push** e il **Service Worker** richiedono una connessione sicura per funzionare. Per motivi di sicurezza, i browser moderni abilitano queste funzionalità solo su **HTTPS**. Se accedi alla console via HTTP (al di fuori di `localhost`), il tasto "Push" e la registrazione delle notifiche non saranno attivi. Si consiglia l'uso di un reverse proxy (come Nginx, Caddy o Traefik) con certificato SSL.
|
||||
**Suggerimento:** Puoi usare Let's Encrypt per ottenere un certificato SSL gratuito per il tuo dominio.
|
||||
|
||||
### ⚠️ Configurazione Reverse Proxy & WebSocket
|
||||
Se esponi la Fleet Console tramite un reverse proxy come **Apache** su IP pubblico (HTTPS), il proxy HTTP standard farà cadere continuamente la connessione in tempo reale di Socket.IO, causando fastidiosi "azzeramenti" o lampeggiamenti della dashboard.
|
||||
Devi abilitare il tunnel WebSocket in Apache:
|
||||
```bash
|
||||
sudo a2enmod proxy_wstunnel rewrite headers
|
||||
```
|
||||
E inserire le regole di **Rewrite** *prima* del `ProxyPass` all'interno del tuo blocco `<VirtualHost *:443>`:
|
||||
```apache
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP:Upgrade} =websocket [NC]
|
||||
RewriteRule /(.*) ws://127.0.0.1:9000/$1 [P,L]
|
||||
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
|
||||
RewriteRule /(.*) http://127.0.0.1:9000/$1 [P,L]
|
||||
|
||||
ProxyPass /socket.io/ ws://127.0.0.1:9000/socket.io/
|
||||
ProxyPassReverse /socket.io/ ws://127.0.0.1:9000/socket.io/
|
||||
|
||||
ProxyPass / http://127.0.0.1:9000/
|
||||
ProxyPassReverse / http://127.0.0.1:9000/
|
||||
```
|
||||
|
||||
#### 🛠️ Controllo Remoto & Manutenzione Avanzata
|
||||
* **Editor .INI Remoto:** Modifica i file di configurazione (es. MMDVMHost.ini) direttamente dal pannello web, senza bisogno di accessi SSH.
|
||||
* **Gestione Demoni:** Avvia, arresta o riavvia i servizi di sistema remoti con un clic.
|
||||
@@ -171,6 +214,7 @@ pip install -r requirements.txt
|
||||
2. Inserisci le credenziali del broker MQTT.
|
||||
3. Definisci i ripetitori nel file `clients.json`.
|
||||
4. Genera le chiavi VAPID su [vapidkeys.com](https://vapidkeys.com/) e inseriscile in `config.json` per attivare le notifiche Push. *(Attenzione: le notifiche Push richiedono obbligatoriamente un certificato HTTPS).*
|
||||
5. Configura le dimensioni della rotazione dei log (`log_max_mb` e `log_backup_count`) direttamente nel `config.json` per gestire lo spazio su disco.
|
||||
|
||||
#### 4. Esecuzione come Servizio (systemd)
|
||||
Per eseguire il server in produzione in modo continuo e stabile con Gunicorn:
|
||||
|
||||
+3
-1
@@ -37,5 +37,7 @@
|
||||
"id_urls": {
|
||||
"dmr": "https://radioid.net/static/dmrid.dat",
|
||||
"nxdn": "https://radioid.net/static/nxdn.csv"
|
||||
}
|
||||
},
|
||||
"log_max_mb": 50,
|
||||
"log_backup_count": 10
|
||||
}
|
||||
|
||||
+261
-48
@@ -28,10 +28,25 @@
|
||||
body { font-family: 'Inter', sans-serif; background: var(--bg-gradient); margin: 0; padding: 0; color: var(--text-main); min-height: 100vh; }
|
||||
|
||||
/* Barra superiore squadrata e tecnica */
|
||||
#top-bar-container { position: sticky; top: 15px; z-index: 100; padding: 0 20px; display: flex; justify-content: center; }
|
||||
#top-bar-container {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
padding: 15px 20px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background: var(--bg-gradient);
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
#top-bar { background: var(--topbar-bg); padding: 12px 30px; display: flex; justify-content: space-between; align-items: center; border-radius: 6px; border: 1px solid var(--border-color); width: 100%; max-width: 1400px; }
|
||||
.title-brand { font-size: 1.2rem; font-weight: 800; letter-spacing: 2px; color: var(--text-main); font-family: 'JetBrains Mono', monospace; }
|
||||
|
||||
/* --- Navigation Tabs --- */
|
||||
.nav-tabs { display: flex; gap: 15px; margin-left: 30px; flex: 1; }
|
||||
.nav-tab { background: transparent; border: none; color: var(--text-muted); font-size: 0.95rem; font-weight: 800; cursor: pointer; padding: 6px 12px; border-bottom: 3px solid transparent; transition: all 0.2s ease; font-family: 'JetBrains Mono', monospace; letter-spacing: 1px; }
|
||||
.nav-tab:hover { color: var(--text-main); }
|
||||
.nav-tab.active { color: var(--primary); border-bottom: 3px solid var(--primary); }
|
||||
|
||||
.theme-switch { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 6px 14px; border-radius: 4px; cursor: pointer; font-weight: 600; font-size: 0.85rem; font-family: 'JetBrains Mono', monospace; }
|
||||
.theme-switch:hover { color: var(--text-main); border-color: var(--text-main); }
|
||||
|
||||
@@ -137,6 +152,7 @@
|
||||
#top-bar-container { top: 10px; padding: 0 10px; }
|
||||
#top-bar { flex-direction: column; padding: 15px; gap: 12px; border-radius: 8px; }
|
||||
.title-brand { font-size: 1.1rem; text-align: center; width: 100%; }
|
||||
.nav-tabs { margin-left: 0; width: 100%; justify-content: center; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; margin-bottom: 10px; }
|
||||
#top-bar > div { width: 100%; flex-wrap: wrap; justify-content: center; gap: 8px !important; }
|
||||
#auth-container { width: 100%; justify-content: center; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border-color); }
|
||||
#auth-container > span { width: 100%; text-align: center; margin-bottom: 8px; font-family: 'JetBrains Mono', monospace; }
|
||||
@@ -153,6 +169,13 @@
|
||||
<div id="top-bar-container">
|
||||
<div id="top-bar">
|
||||
<div class="title-brand">FLEET CONTROL CONSOLE</div>
|
||||
|
||||
<!-- Menu a schede -->
|
||||
<div class="nav-tabs">
|
||||
<button class="nav-tab active" onclick="switchView('home')" id="tab-home">HOME</button>
|
||||
<button class="nav-tab" onclick="switchView('nodes')" id="tab-nodes">NODES</button>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; align-items: center; gap: 12px;">
|
||||
<span id="mqtt-badge" class="mqtt-badge mqtt-offline">MQTT: CHECKING...</span>
|
||||
<button class="theme-switch" id="lang-btn" onclick="toggleLang()" data-i18n-title="ttLang">🇮🇹 ITA</button>
|
||||
@@ -162,13 +185,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================= VISTA NODI ================= -->
|
||||
<div id="view-nodes" style="display: none;">
|
||||
<div class="grid" id="client-grid"></div>
|
||||
</div>
|
||||
|
||||
<!-- ================= VISTA HOME ================= -->
|
||||
<div id="view-home">
|
||||
<div style="max-width: 1400px; margin: 0 auto 15px auto; padding: 0 20px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;">
|
||||
<h3 style="margin: 0; font-weight: 800; display: flex; align-items: center; gap: 10px; color: var(--text-main);">
|
||||
<span style="font-size: 1.5rem;">📊</span> <span data-i18n="statTitle">DAILY STATISTICS</span>
|
||||
</h3>
|
||||
<select id="stat-node-filter" onchange="refreshStats()" style="background: var(--card-bg); border: 1px solid var(--border-color); color: var(--text-main); padding: 8px 15px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-weight: bold; cursor: pointer; outline: none;">
|
||||
<select id="stat-node-filter" onchange="refreshStats(); refreshLogs();" style="background: var(--card-bg); border: 1px solid var(--border-color); color: var(--text-main); padding: 8px 15px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; font-weight: bold; cursor: pointer; outline: none;">
|
||||
<option value="all">🌐 ALL NODES</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -208,17 +236,21 @@
|
||||
<th data-i18n="thTime">Time</th>
|
||||
<th data-i18n="thRep">Repeater</th>
|
||||
<th data-i18n="thMode">Mode</th>
|
||||
<th style="text-align: center;">Slot</th>
|
||||
<th style="text-align: center;">YSF Mode</th>
|
||||
<th style="text-align: center;">Source</th>
|
||||
<th style="text-align: center;">REF / SLOT</th>
|
||||
<th data-i18n="thCall">Callsign</th>
|
||||
<th>Target / TG</th>
|
||||
<th data-i18n="thDur">Duration</th>
|
||||
<th>BER</th>
|
||||
<th>RSSI</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="log-body"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div style="text-align: center; padding: 25px; color: var(--text-muted); font-size: 0.85rem; font-weight: 600; display: flex; justify-content: center; align-items: center; gap: 15px; flex-wrap: wrap;">
|
||||
@@ -234,10 +266,11 @@
|
||||
<span>GitHub Mirror</span>
|
||||
</a>
|
||||
<span style="opacity: 0.5;">|</span>
|
||||
<span style="font-family: 'JetBrains Mono', monospace; color: var(--accent);">Rev: {{ git_commit }}</span>
|
||||
<span style="opacity: 0.5;">|</span>
|
||||
<span id="last-update">Sync: --:--</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<div id="login-modal" class="modal-overlay">
|
||||
<div class="modal-content" style="width:90%; max-width:400px;">
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid var(--border-color); padding-bottom:15px; margin-bottom:20px;">
|
||||
@@ -390,6 +423,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- NUOVO MODALE VERSIONI -->
|
||||
<div id="versions-modal" class="modal-overlay">
|
||||
<div class="modal-content" style="width:90%; max-width:450px;">
|
||||
<div style="display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid var(--border-color); padding-bottom:15px; margin-bottom:15px;">
|
||||
<h2 style="margin:0; color:var(--primary);">ℹ️ <span data-i18n="modVersions">Software & Firmware</span></h2>
|
||||
<button onclick="closeVersionsModal()" style="background:none; border:none; font-size:1.5rem; cursor:pointer; color:var(--danger);">✖</button>
|
||||
</div>
|
||||
<div id="versions-list" style="background: #010409; padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; line-height: 1.8; color: var(--text-main);">
|
||||
<!-- Dati iniettati via JS -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.min.js"></script>
|
||||
|
||||
<script>
|
||||
@@ -421,8 +467,8 @@
|
||||
ttReqCfg: "Request immediate data update", ttGlobal: "Force profile switch on network", ttAdmin: "User and system management", ttPass: "Change your password", ttLogout: "Log out",
|
||||
ttProfA: "Switch to Profile A", ttProfB: "Switch to Profile B", ttTgOn: "Enable Telegram notifications", ttTgOff: "Disable Telegram notifications", ttSvc: "Manage system daemons", ttFile: "Edit .ini configuration files", ttHat: "Send physical reset to modem", ttBoot: "Reboot node operating system",
|
||||
ttSwitchTo: "Switch to profile: ", ttSvcStart: "Start service", ttSvcRestart: "Restart service", ttSvcEdit: "Edit configuration", ttSvcStop: "Stop service", ttLang: "Change language",
|
||||
statTopTG: "🎯 TOP TALKGROUPS", statTopCall: "🗣️ TOP CALLSIGNS", statLoading: "Loading...", statAvgDur: "⏱️ AVERAGE DURATION", statTodayTx: "📡 TRANSITS TODAY", statNoData: "No data",
|
||||
statTitle: "DAILY STATISTICS", statAllNodes: "ALL NODES"
|
||||
statTopTG: "🎯 TOP TALKGROUPS", statTopCall: "🗣️ TOP CALLSIGNS", statLoading: "Loading...", statAvgDur: "⏱️ AVERAGE DURATION", statTodayTx: "📡 TRANSITI TODAY", statNoData: "No data",
|
||||
statTitle: "DAILY STATISTICS", statAllNodes: "ALL NODES", modVersions: "Software & Firmware"
|
||||
},
|
||||
it: {
|
||||
lastTransits: "Ultimi ascolti", loginTitle: "🔒 Login di Sistema",
|
||||
@@ -451,7 +497,7 @@
|
||||
ttProfA: "Passa al Profilo A", ttProfB: "Passa al Profilo B", ttTgOn: "Abilita notifiche Telegram", ttTgOff: "Disabilita notifiche Telegram", ttSvc: "Gestisci demoni di sistema", ttFile: "Modifica file .ini da remoto", ttHat: "Reset fisico scheda modem", ttBoot: "Riavvia sistema operativo",
|
||||
ttSwitchTo: "Passa al profilo: ", ttSvcStart: "Avvia servizio", ttSvcRestart: "Riavvia servizio", ttSvcEdit: "Modifica configurazione", ttSvcStop: "Ferma servizio", ttLang: "Cambia lingua",
|
||||
statTopTG: "🎯 TOP TALKGROUPS", statTopCall: "🗣️ TOP CALLSIGNS", statLoading: "Caricamento...", statAvgDur: "⏱️ DURATA MEDIA", statTodayTx: "📡 TRANSITI OGGI", statNoData: "Nessun dato",
|
||||
statTitle: "STATISTICHE GIORNALIERE", statAllNodes: "TUTTA LA RETE"
|
||||
statTitle: "STATISTICHE GIORNALIERE", statAllNodes: "TUTTA LA RETE", modVersions: "Software & Firmware"
|
||||
}
|
||||
};
|
||||
let currentLang = localStorage.getItem('lang') || 'en';
|
||||
@@ -474,13 +520,29 @@
|
||||
}
|
||||
|
||||
// --- HELPER DI SICUREZZA ---
|
||||
// esc(): escape HTML per tutto ciò che arriva da MQTT / database / utenti prima di finire in innerHTML
|
||||
function esc(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); }
|
||||
// q(): letterale JS sicuro da usare dentro onclick="...": onclick="fn(${q(valore)})"
|
||||
function q(s) { return esc(JSON.stringify(String(s ?? ''))); }
|
||||
const HANG_TIME_MS = 180000; // tempo massimo in cui la card resta "accesa" dopo l'ultimo TX
|
||||
const HANG_TIME_MS = 180000;
|
||||
|
||||
// --- DIAGNOSTICA: "ultimo messaggio ricevuto" per nodo (MMDVM / gateway / agent) ---
|
||||
// --- GESTIONE SCHEDE (TABS) ---
|
||||
function switchView(viewName) {
|
||||
document.getElementById('view-home').style.display = 'none';
|
||||
document.getElementById('view-nodes').style.display = 'none';
|
||||
document.getElementById('tab-home').classList.remove('active');
|
||||
document.getElementById('tab-nodes').classList.remove('active');
|
||||
|
||||
document.getElementById(`view-${viewName}`).style.display = 'block';
|
||||
document.getElementById(`tab-${viewName}`).classList.add('active');
|
||||
|
||||
localStorage.setItem('fleetDefaultView', viewName);
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const savedView = localStorage.getItem('fleetDefaultView') || 'home';
|
||||
switchView(savedView);
|
||||
});
|
||||
|
||||
// --- DIAGNOSTICA ---
|
||||
function fmtAge(sec) {
|
||||
sec = Math.max(0, Math.round(sec));
|
||||
if (sec < 60) return sec + 's';
|
||||
@@ -501,8 +563,6 @@
|
||||
const upSec = data.uptime || 0;
|
||||
let html = '';
|
||||
|
||||
// MMDVM: pubblica eventi (TX, cambio modo), quindi su un nodo tranquillo l'età può crescere senza problemi.
|
||||
// Si segnala solo il caso "mai ricevuto nulla" con nodo online e server attivo da un po'.
|
||||
const warnM = ages.mmdvm === undefined && isOnline && upSec > 600;
|
||||
const tipM = it ? `Ultimo evento dal topic mmdvm/${c.id}/json (TX, cambio modo...). Su un nodo tranquillo può passare molto tempo.`
|
||||
: `Last event from topic mmdvm/${c.id}/json (TX, mode change...). It can be a long time on a quiet node.`;
|
||||
@@ -510,13 +570,10 @@
|
||||
: `No MMDVM event received since the server started (${fmtAge(upSec)}): check that MMDVMHost is connected to the broker.`;
|
||||
html += seenItem('MMDVM', ages.mmdvm, warnM ? tipMW : tipM, warnM);
|
||||
|
||||
// Gateway: solo se il nodo ne ha mai pubblicati
|
||||
if (ages.gateway !== undefined) {
|
||||
html += seenItem('GW', ages.gateway, it ? 'Ultimo evento dai gateway (DMR/NXDN/YSF/P25/D-Star)' : 'Last event from the gateways (DMR/NXDN/YSF/P25/D-Star)', false);
|
||||
}
|
||||
|
||||
// Agent: heartbeat periodico, se tace a lungo con nodo "online" qualcosa non va
|
||||
// Soglia in base all'intervallo di telemetria dichiarato dall'agente (default 60 s): 3 intervalli, minimo 180 s
|
||||
const hObj = (data.health && data.health[c.id.toLowerCase()]) || {};
|
||||
const iv = Number(hObj.interval) > 0 ? Number(hObj.interval) : 60;
|
||||
const warnA = isOnline && (ages.health === undefined ? upSec > Math.max(300, iv * 5) : ages.health > Math.max(180, iv * 3));
|
||||
@@ -531,10 +588,11 @@
|
||||
|
||||
// --- GLOBAL VARIABLES ---
|
||||
let clients = [];
|
||||
let me = { logged_in: false, user: '', role: '', allowed_nodes: '' }; // stato reale della sessione (da /api/me)
|
||||
let me = { logged_in: false, user: '', role: '', allowed_nodes: '' };
|
||||
let isAuthenticated = false;
|
||||
let usersCache = {};
|
||||
let globalHealthData = {};
|
||||
let globalVersionsData = {}; // NUOVA VARIABILE VERSIONI
|
||||
let editingUserId = null;
|
||||
let currentResetHatId = null;
|
||||
let confirmActionCallback = null;
|
||||
@@ -595,8 +653,7 @@
|
||||
}
|
||||
|
||||
function confirmReboot(id) { sendCommand(id, 'REBOOT', `🔄 ${t('titleBoot')}`, `${t('confBoot')}<b>${id.toUpperCase()}</b>?`, "var(--danger)"); }
|
||||
function confirmUpdateAgent(id) { sendCommand(id, 'UPDATE_AGENT', `⬇️ UPDATE OTA`, `Confermi l'aggiornamento dello script tramite git pull sul nodo <b>${id.toUpperCase()}</b>?`, "#2563eb");
|
||||
}
|
||||
function confirmUpdateAgent(id) { sendCommand(id, 'UPDATE_AGENT', `⬇️ UPDATE OTA`, `Confermi l'aggiornamento dello script tramite git pull sul nodo <b>${id.toUpperCase()}</b>?`, "#2563eb"); }
|
||||
|
||||
function confirmHatReset(id) {
|
||||
currentResetHatId = id;
|
||||
@@ -647,7 +704,6 @@
|
||||
|
||||
const response = await fetch('/api/clients');
|
||||
clients = await response.json();
|
||||
// Gli id nodo finiscono in id HTML e onclick: accettiamo solo caratteri sicuri
|
||||
clients = clients.filter(c => /^[A-Za-z0-9_\-]+$/.test(String(c.id)));
|
||||
|
||||
const statSelect = document.getElementById('stat-node-filter');
|
||||
@@ -664,6 +720,7 @@
|
||||
|
||||
if (isAuthenticated) {
|
||||
let adminBtn = role === 'admin' ? `
|
||||
<button id="server-update-btn" onclick="confirmServerUpdate()" class="auth-btn" style="background:var(--danger); color:white !important; display:none; border: 2px solid white; animation: pulse-red 1.5s infinite;" title="Aggiornamento Server Disponibile">🔄 UPDATE SERVER</button>
|
||||
<button onclick="sendGlobalUpdate()" class="auth-btn" style="background:#f59e0b; color:white;" data-i18n-title="ttReqCfg" title="${t('ttReqCfg')}">${t('btnReqCfg')}</button>
|
||||
<button onclick="triggerGlobalEmergency()" class="auth-btn" style="background:#ef4444; color:white;" data-i18n-title="ttGlobal" title="${t('ttGlobal')}">${t('btnGlobal')}</button>
|
||||
<button onclick="openAdmin()" class="auth-btn" style="background:var(--accent); color:white;" data-i18n-title="ttAdmin" title="${t('ttAdmin')}">${t('btnAdmin')}</button>` : '';
|
||||
@@ -686,6 +743,7 @@
|
||||
<span class="client-name" title="${esc(c.name)}">${esc(c.name)}</span>
|
||||
<div style="display: flex; align-items: center;">
|
||||
<span class="badge-id">ID: ${c.id.toUpperCase()}</span>
|
||||
<span class="badge-id" id="agent-badge-${c.id}" style="display: none; margin-left: 6px; color: #38bdf8; border-color: rgba(56, 189, 248, 0.4); background: rgba(56, 189, 248, 0.1);" title="Versione Node Agent"></span>
|
||||
<div id="type-badge-${c.id}" class="type-badge" style="display: none;"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -702,6 +760,7 @@
|
||||
<span>🌡️ <span id="temp-${c.id}">--</span>°C</span>
|
||||
<span>🧠 <span id="ram-${c.id}">--</span>%</span>
|
||||
<span>💾 <span id="disk-${c.id}">--</span>%</span>
|
||||
<span title="System Uptime">⏱️ <span id="up-${c.id}">--</span></span>
|
||||
</div>
|
||||
<div class="seen-bar" id="seen-${c.id}" style="display: none;"></div>
|
||||
|
||||
@@ -729,13 +788,14 @@
|
||||
` : ''}
|
||||
${showReboot ? `
|
||||
<div style="width: 100%; display: flex; gap: 8px;">
|
||||
<button class="btn-cmd" style="background: var(--primary); padding: 8px 4px;" title="Mostra Versioni Software" onclick="openVersionsModal('${c.id}')">ℹ️ INFO</button>
|
||||
<button id="btn-svc-${c.id}" class="btn-cmd" style="background: #334155; padding: 8px 4px;" title="${t('ttSvc')}" onclick="openServicesModal('${c.id}')">${t('btnSvc')}</button>
|
||||
<button class="btn-cmd" style="background: #8e44ad; padding: 8px 4px;" title="${t('ttFile')}" onclick="openConfigsModal('${c.id}')">${t('btnFile')}</button>
|
||||
<button class="btn-cmd" style="background: #ea580c; padding: 8px 4px;" title="${t('ttHat')}" onclick="confirmHatReset('${c.id}')">${t('btnHat')}</button>
|
||||
<button class="btn-cmd" style="background: var(--danger); padding: 8px 4px;" title="${t('ttBoot')}" onclick="confirmReboot('${c.id}')">${t('btnBoot')}</button>
|
||||
</div>
|
||||
<div style="width: 100%; display: flex; gap: 8px;">
|
||||
<button class="btn-cmd" style="background: #2563eb; padding: 8px 4px;" title="Scarica l'ultima versione da Gitea" onclick="confirmUpdateAgent('${c.id}')">⬇️ UPDATE OTA</button>
|
||||
<button id="btn-ota-${c.id}" class="btn-cmd" style="background: #2563eb; padding: 8px 4px;" title="Scarica l'ultima versione da Gitea" onclick="confirmUpdateAgent('${c.id}')">⬇️ UPDATE OTA</button>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>`;
|
||||
@@ -764,21 +824,23 @@
|
||||
async function refreshStates() {
|
||||
try {
|
||||
const res = await fetch('/api/states'); const data = await res.json();
|
||||
|
||||
// AGGIORNAMENTO DATI VERSIONI GLOBALI
|
||||
globalVersionsData = data.versions || {};
|
||||
|
||||
clients.forEach(c => {
|
||||
const statusDiv = document.getElementById(`status-${c.id}`); const cardDiv = document.getElementById(`card-${c.id}`);
|
||||
if (!statusDiv || !cardDiv) return;
|
||||
|
||||
// 1. PRIMA CALCOLIAMO SE È ONLINE
|
||||
let stateValue = data.states[c.id.toLowerCase()] || data.states[c.id] || "OFFLINE";
|
||||
stateValue = String(stateValue).trim().toUpperCase(); statusDiv.innerText = stateValue;
|
||||
const isOnline = !stateValue.includes("OFF") && stateValue !== "";
|
||||
renderSeen(c, data, isOnline);
|
||||
|
||||
// 2. POI AGGIORNIAMO NOME E ID DINAMICI
|
||||
let genObj = data.general && data.general[c.id.toLowerCase()];
|
||||
const nameSpan = cardDiv.querySelector('.client-name');
|
||||
const idBadge = cardDiv.querySelector('.badge-id');
|
||||
const typeBadge = document.getElementById(`type-badge-${c.id}`); // <--- Peschiamo il nostro nuovo badge
|
||||
const typeBadge = document.getElementById(`type-badge-${c.id}`);
|
||||
|
||||
if (genObj && isOnline) {
|
||||
nameSpan.innerText = genObj.callsign;
|
||||
@@ -787,7 +849,6 @@
|
||||
idBadge.style.color = "#ffffff";
|
||||
idBadge.style.borderColor = "var(--primary)";
|
||||
|
||||
// --- LOGICA BADGE HOTSPOT/REPEATER ---
|
||||
if (typeBadge && genObj.duplex !== undefined) {
|
||||
typeBadge.style.display = 'inline-block';
|
||||
if (genObj.duplex === "1") {
|
||||
@@ -805,10 +866,9 @@
|
||||
idBadge.style.color = "var(--text-muted)";
|
||||
idBadge.style.borderColor = "var(--border-color)";
|
||||
|
||||
if (typeBadge) typeBadge.style.display = 'none'; // Nascondilo se il nodo va offline
|
||||
if (typeBadge) typeBadge.style.display = 'none';
|
||||
}
|
||||
|
||||
// 3. TELEMETRIA E STATO (PULITO DAI DUPLICATI)
|
||||
let telemetryObj = data.telemetry[c.id.toLowerCase()] || data.telemetry[c.id] || { ts1: "...", ts2: "...", alt: "", idle: true };
|
||||
if (typeof telemetryObj === 'string') telemetryObj = { ts1: telemetryObj, ts2: "...", alt: "", idle: true };
|
||||
|
||||
@@ -835,22 +895,17 @@
|
||||
if (altDiv) altDiv.style.display = "none";
|
||||
if (tsContainer) tsContainer.style.display = "flex";
|
||||
|
||||
let netObj = data.networks && data.networks[c.id.toLowerCase()] ? data.networks[c.id.toLowerCase()] : {ts1: "", ts2: ""};
|
||||
activeModeColor = "var(--primary)";
|
||||
|
||||
if (ts1Div && ts2Div) {
|
||||
// --- LOGICA DUPLEX / SIMPLEX ---
|
||||
let isSimplex = (genObj && genObj.duplex === "0");
|
||||
|
||||
// Nascondiamo il div del TS1 se il nodo è Simplex
|
||||
ts1Div.style.display = isSimplex ? 'none' : 'block';
|
||||
|
||||
[ts1Div, ts2Div].forEach((div, idx) => {
|
||||
// Se è simplex, saltiamo del tutto l'aggiornamento grafico del TS1
|
||||
if (isSimplex && idx === 0) return;
|
||||
|
||||
const val = String((idx === 0 ? telemetryObj.ts1 : telemetryObj.ts2) ?? ''); const netName = idx === 0 ? netObj.ts1 : netObj.ts2;
|
||||
const fullLabel = netName ? `TS${idx + 1} [${netName}]` : `TS${idx + 1}`;
|
||||
const val = String((idx === 0 ? telemetryObj.ts1 : telemetryObj.ts2) ?? '');
|
||||
const fullLabel = `TS${idx + 1}`;
|
||||
div.innerText = `${fullLabel}: ${val}`;
|
||||
div.style.setProperty('--pulse-color', activeModeColor);
|
||||
|
||||
@@ -895,6 +950,15 @@
|
||||
let tempVal = healthObj.temp; tempSpan.innerText = tempVal; tempSpan.style.color = tempVal < 55 ? 'var(--success)' : (tempVal < 70 ? '#f59e0b' : 'var(--danger)');
|
||||
ramSpan.innerText = healthObj.ram; let d = healthObj.disk; diskSpan.innerText = d; diskSpan.style.color = d < 85 ? 'inherit' : (d < 95 ? '#f59e0b' : 'var(--danger)');
|
||||
|
||||
let upSpan = document.getElementById(`up-${c.id}`);
|
||||
if (upSpan && healthObj.uptime) {
|
||||
upSpan.innerText = fmtAge(healthObj.uptime);
|
||||
}
|
||||
let agentBadge = document.getElementById(`agent-badge-${c.id}`);
|
||||
if (agentBadge && healthObj.agent_version) {
|
||||
agentBadge.innerText = `Agent v${healthObj.agent_version}`;
|
||||
agentBadge.style.display = 'inline-block';
|
||||
}
|
||||
const profBtnsDiv = document.getElementById(`prof-btns-${c.id}`);
|
||||
const profKeys = JSON.stringify(healthObj.profiles || {});
|
||||
|
||||
@@ -917,7 +981,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
} else { if (healthContainer) healthContainer.style.display = 'none'; }
|
||||
} else {
|
||||
if (healthContainer) healthContainer.style.display = 'none';
|
||||
let agentBadge = document.getElementById(`agent-badge-${c.id}`);
|
||||
if (agentBadge) agentBadge.style.display = 'none';
|
||||
}
|
||||
|
||||
globalHealthData[c.id.toLowerCase()] = healthObj;
|
||||
|
||||
@@ -933,18 +1001,26 @@
|
||||
else { btnSvc.style.background = '#334155'; btnSvc.classList.remove('blink'); btnSvc.innerHTML = t('btnSvc'); }
|
||||
}
|
||||
|
||||
let btnOta = document.getElementById(`btn-ota-${c.id}`);
|
||||
if (btnOta) {
|
||||
if (healthObj && healthObj.agent_update_available) {
|
||||
btnOta.style.background = 'var(--danger)';
|
||||
btnOta.style.animation = 'pulse-red 1.5s infinite';
|
||||
} else {
|
||||
btnOta.style.background = '#2563eb';
|
||||
btnOta.style.animation = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnline) {
|
||||
cardDiv.classList.add('online'); statusDiv.classList.remove('status-offline'); cardDiv.style.opacity = "1"; cardDiv.style.filter = "none";
|
||||
|
||||
// --- INIZIO LOGICA SMART HANG-TIME ---
|
||||
if (isTx) cardDiv.dataset.lastTx = Date.now(); // Memorizza quando è avvenuto l'ultimo TX
|
||||
if (isTx) cardDiv.dataset.lastTx = Date.now();
|
||||
let timeSinceTx = Date.now() - (parseInt(cardDiv.dataset.lastTx) || 0);
|
||||
|
||||
// Accendi se in TX, OPPURE se in Hang Time (ma spegni a forza dopo HANG_TIME_MS di inattività)
|
||||
let showActiveColor = isTx || (!isIdle && timeSinceTx < HANG_TIME_MS);
|
||||
|
||||
cardDiv.style.setProperty('border-top-color', showActiveColor ? activeModeColor : "var(--border-color)", 'important');
|
||||
// --- FINE LOGICA ---
|
||||
if(isTx) {
|
||||
let shadowRGB = '59, 130, 246';
|
||||
if (activeModeColor === '#10b981') shadowRGB = '16, 185, 129';
|
||||
@@ -970,17 +1046,93 @@
|
||||
const time = row[0] ? row[0].split(' ')[1] : "--:--";
|
||||
const clientId = row[1]; const protocol = row[2] || "DMR"; let source = row[3] || "---"; const target = row[4] || "---";
|
||||
const rawSlot = row[5]; const source_ext = row[8];
|
||||
const rawRssi = row[9];
|
||||
const sourceConn = row[10];
|
||||
const ysfMode = row[11];
|
||||
|
||||
let sourceHtml = esc(source);
|
||||
if (source_ext && source_ext.trim() !== "") { sourceHtml += ` <span style="font-size:0.8em; color:#94a3b8; font-family:'JetBrains Mono', monospace;">/${esc(source_ext)}</span>`; }
|
||||
|
||||
const slotDisplay = protocol === "DMR" ? `TS${rawSlot}` : "--";
|
||||
let slotDisplay = "---";
|
||||
if (rawSlot && String(rawSlot).trim() !== "" && rawSlot !== "undefined") {
|
||||
if (protocol === "DMR" && !String(rawSlot).toUpperCase().startsWith("TS")) {
|
||||
slotDisplay = `TS${rawSlot}`;
|
||||
} else {
|
||||
slotDisplay = rawSlot;
|
||||
}
|
||||
}
|
||||
let protoColor = "#3b82f6"; if (protocol === "NXDN") protoColor = "#10b981"; else if (protocol === "YSF") protoColor = "#8b5cf6"; else if (protocol === "D-STAR") protoColor = "#06b6d4"; else if (protocol === "P25") protoColor = "#f59e0b";
|
||||
|
||||
// Formatta il Source (RF o NET)
|
||||
let sourceBadge = "---";
|
||||
if (sourceConn) {
|
||||
if (sourceConn.toLowerCase() === 'rf') sourceBadge = '<span style="color:#f87171; font-weight:800;">RF</span>';
|
||||
else if (sourceConn.toLowerCase() === 'network') sourceBadge = '<span style="color:#38bdf8; font-weight:800;">NET</span>';
|
||||
else sourceBadge = `<span style="font-weight:800; color:var(--text-muted);">${esc(sourceConn).toUpperCase()}</span>`;
|
||||
}
|
||||
|
||||
// Formatta l'YSF Mode
|
||||
let modeDisplay = "---";
|
||||
if (ysfMode && ysfMode.trim() !== "") {
|
||||
modeDisplay = `<span style="font-size:0.7rem; color:#a78bfa; border: 1px solid #a78bfa; padding: 2px 4px; border-radius: 4px;">${esc(ysfMode).toUpperCase()}</span>`;
|
||||
}
|
||||
|
||||
// Formatta l'RSSI con S-Meter grafico a segmenti
|
||||
let rssiDisplay = '---';
|
||||
if (rawRssi && rawRssi !== 0) {
|
||||
// Calcolo livello S-Meter (Standard VHF/UHF: S9 = -93 dBm, 6dB per punto S)
|
||||
let sLabel = "S0";
|
||||
if (rawRssi >= -93) {
|
||||
let over = Math.round((rawRssi + 93) / 10) * 10;
|
||||
sLabel = over > 0 ? `S9<sup style="color: var(--danger); font-weight: 800;">+${over}</sup>` : "S9";
|
||||
} else {
|
||||
let sUnits = Math.floor((rawRssi + 141) / 6) + 1;
|
||||
sLabel = `S${Math.max(1, Math.min(9, sUnits))}`;
|
||||
}
|
||||
|
||||
// Calcolo segmenti accesi (9 segmenti totali)
|
||||
let activeSegs = 1;
|
||||
if (rawRssi >= -53) activeSegs = 9;
|
||||
else if (rawRssi >= -63) activeSegs = 8;
|
||||
else if (rawRssi >= -73) activeSegs = 7;
|
||||
else if (rawRssi >= -83) activeSegs = 6;
|
||||
else if (rawRssi >= -93) activeSegs = 5; // S9
|
||||
else if (rawRssi >= -105) activeSegs = 4;
|
||||
else if (rawRssi >= -117) activeSegs = 3;
|
||||
else if (rawRssi >= -129) activeSegs = 2;
|
||||
|
||||
// Generazione barre HTML
|
||||
let barsHtml = '';
|
||||
const heights = [4, 5, 6, 7, 8, 10, 12, 14, 14];
|
||||
for (let i = 0; i < 9; i++) {
|
||||
let color = "rgba(255,255,255,0.1)"; // Spento
|
||||
if (i < activeSegs) {
|
||||
if (i < 5) color = "var(--success)"; // Verde
|
||||
else if (i < 7) color = "#f59e0b"; // Giallo
|
||||
else color = "var(--danger)"; // Rosso
|
||||
}
|
||||
barsHtml += `<div style="width: 4px; height: ${heights[i]}px; background: ${color}; border-radius: 1px;"></div>`;
|
||||
}
|
||||
|
||||
rssiDisplay = `
|
||||
<div style="display: flex; align-items: center; gap: 10px;" title="${esc(rawRssi)} dBm">
|
||||
<div style="min-width: 40px; text-align: right; font-weight: bold; font-family: 'Inter', sans-serif;">${sLabel}</div>
|
||||
<div style="display: flex; align-items: flex-end; gap: 2px; height: 14px;">
|
||||
${barsHtml}
|
||||
</div>
|
||||
<span style="font-size: 0.85em; color: var(--text-muted); min-width: 7ch; text-align: right;">${esc(rawRssi)} dBm</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
if (source.includes("🌐")) {
|
||||
if (!networkLogs[clientId]) networkLogs[clientId] = "";
|
||||
networkLogs[clientId] += `<div style="border-bottom:1px solid rgba(255,255,255,0.1); padding:4px 0;"><span style="color:#64748b;">[${esc(time)}]</span> <span style="color:${protoColor}; font-weight:bold;">[${esc(protocol)}]</span> <span style="color:#cbd5e1;">${esc(source.replace("🌐", "").trim())}</span></div>`;
|
||||
} else {
|
||||
tableHTML += `<tr><td>${esc(time)}</td><td><b style="color:var(--text-main);">${esc(String(clientId).toUpperCase())}</b></td><td><span style="background:${protoColor}; color:white; padding:3px 8px; border-radius:8px; font-size:0.7rem; font-weight:800;">${esc(protocol)}</span></td><td style="font-family:'JetBrains Mono', monospace; font-weight:bold; text-align:center;">${esc(slotDisplay)}</td><td style="color:var(--accent); font-weight:800;">${sourceHtml}</td><td style="font-family:'JetBrains Mono', monospace;">${esc(target.trim())}</td><td>${esc(row[6])}s</td><td>${esc(row[7])}%</td></tr>`;
|
||||
// FILTRO TENDINA: Controlla il nodo selezionato prima di aggiungere la riga
|
||||
const selectedFilter = document.getElementById('stat-node-filter').value;
|
||||
if (selectedFilter === 'all' || String(clientId).toLowerCase() === selectedFilter) {
|
||||
tableHTML += `<tr><td>${esc(time)}</td><td><b style="color:var(--text-main);">${esc(String(clientId).toUpperCase())}</b></td><td><span style="background:${protoColor}; color:white; padding:3px 8px; border-radius:8px; font-size:0.7rem; font-weight:800;">${esc(protocol)}</span></td><td style="text-align:center;">${modeDisplay}</td><td style="text-align:center; font-family:'JetBrains Mono', monospace;">${sourceBadge}</td><td style="font-family:'JetBrains Mono', monospace; font-weight:bold; text-align:center;">${esc(slotDisplay)}</td><td style="color:var(--accent); font-weight:800;">${sourceHtml}</td><td style="font-family:'JetBrains Mono', monospace;">${esc(target.trim())}</td><td>${esc(row[6])}s</td><td>${esc(row[7])}%</td><td style="font-family:'JetBrains Mono', monospace;">${rssiDisplay}</td></tr>`;
|
||||
}
|
||||
}
|
||||
});
|
||||
tbody.innerHTML = tableHTML;
|
||||
@@ -1046,7 +1198,6 @@
|
||||
// --- SETTINGS ---
|
||||
function triggerGlobalEmergency() {
|
||||
let uniqueProfiles = {};
|
||||
// Raccoglie tutti i profili unici trovati nei nodi online
|
||||
for (const id in globalHealthData) {
|
||||
if (globalHealthData[id] && globalHealthData[id].profiles) {
|
||||
for (const [k, v] of Object.entries(globalHealthData[id].profiles)) {
|
||||
@@ -1102,10 +1253,19 @@
|
||||
}
|
||||
|
||||
// --- SERVICES & CONFIGS ---
|
||||
function fileLabel(stem, names) {
|
||||
const key = String(stem).toLowerCase();
|
||||
const full = (names || []).find(n => String(n).replace(/\.[^.]*$/, '').toLowerCase() === key);
|
||||
if (full) {
|
||||
const m = String(full).match(/^(.*?)(\.[^.]*)?$/);
|
||||
return String(m[1]).toUpperCase() + (m[2] || '');
|
||||
}
|
||||
return String(stem).toUpperCase() + '.ini';
|
||||
}
|
||||
function openConfigsModal(clientId) {
|
||||
const data = globalHealthData[clientId.toLowerCase()]; const listDiv = document.getElementById('configs-list'); let listaFile = data ? (data.config_files || data.files || []) : [];
|
||||
const data = globalHealthData[clientId.toLowerCase()]; const listDiv = document.getElementById('configs-list'); let listaFile = data ? (data.config_files || data.files || []) : []; const fileNames = (data && data.file_names) || [];
|
||||
if (listaFile.length === 0) listDiv.innerHTML = `<div style="text-align:center; padding:20px;"><p style="color:var(--text-muted); margin-bottom:15px;">${t('waitData')}</p><button onclick="sendGlobalUpdate(); closeConfigsModal();" class="btn-cmd" style="background:var(--accent);">${t('forceUpdate')}</button></div>`;
|
||||
else listDiv.innerHTML = listaFile.map(f => `<div style="display:flex; justify-content:space-between; align-items:center; padding:12px; background:rgba(128,128,128,0.1); border-radius:12px; border:1px solid var(--border-color); margin-bottom:8px;"><span style="font-family:'JetBrains Mono',monospace; font-weight:bold;">${esc(String(f).toUpperCase())}.ini</span><button onclick="closeConfigsModal(); openEditorModal(${q(clientId)}, ${q(f)})" class="btn-cmd" style="background:#8e44ad; max-width:120px;">${t('btnEdit')}</button></div>`).join('');
|
||||
else listDiv.innerHTML = listaFile.map(f => `<div style="display:flex; justify-content:space-between; align-items:center; padding:12px; background:rgba(128,128,128,0.1); border-radius:12px; border:1px solid var(--border-color); margin-bottom:8px;"><span style="font-family:'JetBrains Mono',monospace; font-weight:bold;">${esc(fileLabel(f, fileNames))}</span><button onclick="closeConfigsModal(); openEditorModal(${q(clientId)}, ${q(f)})" class="btn-cmd" style="background:#8e44ad; max-width:120px;">${t('btnEdit')}</button></div>`).join('');
|
||||
document.getElementById('configs-modal').style.display = 'flex';
|
||||
}
|
||||
function closeConfigsModal() { document.getElementById('configs-modal').style.display = 'none'; }
|
||||
@@ -1161,10 +1321,32 @@
|
||||
});
|
||||
}
|
||||
|
||||
// --- NUOVE FUNZIONI PER POP-UP VERSIONI ---
|
||||
function openVersionsModal(clientId) {
|
||||
const versions = globalVersionsData[clientId.toLowerCase()];
|
||||
const listDiv = document.getElementById('versions-list');
|
||||
|
||||
if (!versions || Object.keys(versions).length === 0) {
|
||||
listDiv.innerHTML = "<span style='color: var(--text-muted);'>Nessun dato ancora ricevuto. Usa il tasto 🔄 RESTART sui servizi del nodo per forzare l'invio del log di avvio.</span>";
|
||||
} else {
|
||||
let html = "";
|
||||
for (const [software, version] of Object.entries(versions)) {
|
||||
html += `<div><strong style="color: var(--primary); display: inline-block; width: 140px;">${esc(software)}:</strong> <span style="color: var(--success); font-weight: bold;">${esc(version)}</span></div>`;
|
||||
}
|
||||
listDiv.innerHTML = html;
|
||||
}
|
||||
|
||||
document.getElementById('versions-modal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeVersionsModal() {
|
||||
document.getElementById('versions-modal').style.display = 'none';
|
||||
}
|
||||
|
||||
// --- PUSH NOTIFICATIONS ---
|
||||
async function subscribeToPush() {
|
||||
if (!('serviceWorker' in navigator) || !('PushManager' in window)) { customAlert("Error", "Push notifications are not supported by this browser.", true); return; }
|
||||
if (!me.logged_in) { openLoginModal(); return; } // le notifiche si attivano solo da loggati
|
||||
if (!me.logged_in) { openLoginModal(); return; }
|
||||
const permission = await Notification.requestPermission();
|
||||
if (permission !== 'granted') { customAlert("Error", "Push notifications permission denied.", true); return; }
|
||||
try {
|
||||
@@ -1181,11 +1363,42 @@
|
||||
}
|
||||
function urlB64ToUint8Array(base64String) { const padding = '='.repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/'); const rawData = window.atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) outputArray[i] = rawData.charCodeAt(i); return outputArray; }
|
||||
|
||||
async function checkServerUpdate() {
|
||||
if (!isAuthenticated || me.role !== 'admin') return;
|
||||
try {
|
||||
const res = await fetch('/api/server_update/check');
|
||||
const data = await res.json();
|
||||
const btn = document.getElementById('server-update-btn');
|
||||
if (btn) {
|
||||
btn.style.display = data.update_available ? 'inline-block' : 'none';
|
||||
}
|
||||
} catch (e) { console.error("Errore check update server:", e); }
|
||||
}
|
||||
|
||||
function confirmServerUpdate() {
|
||||
customConfirm("🔄 UPDATE SERVER", "Vuoi scaricare l'ultima versione del server da Gitea/GitHub e riavviare il servizio backend?", "var(--danger)", async () => {
|
||||
try {
|
||||
const res = await fetch('/api/server_update/apply', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
customAlert("✅ SUCCESS", "Aggiornamento in corso. La pagina si ricaricherà a breve.");
|
||||
setTimeout(() => location.reload(), 5000); // Ricarica dopo 5 secondi
|
||||
} else {
|
||||
customAlert("❌ ERRORE", esc(data.error), true);
|
||||
}
|
||||
} catch (e) { console.error(e); customAlert("❌ ERRORE", "Errore di rete.", true); }
|
||||
});
|
||||
}
|
||||
|
||||
// Controlla gli aggiornamenti ogni ora
|
||||
setInterval(checkServerUpdate, 3600000);
|
||||
// Effettua un controllo 5 secondi dopo l'avvio della UI
|
||||
setTimeout(checkServerUpdate, 5000);
|
||||
|
||||
initUI();
|
||||
checkPushStatus();
|
||||
|
||||
// --- AGGIORNAMENTI PERIODICI ---
|
||||
// Fallback se il WebSocket non è disponibile + spegne l'hang time scaduto anche senza nuovi eventi
|
||||
setInterval(refreshStates, 15000);
|
||||
setInterval(() => { refreshLogs(); refreshStats(); }, 60000);
|
||||
|
||||
@@ -1201,8 +1414,8 @@
|
||||
if (badge) { if (data.connected) { badge.innerText = "MQTT: ONLINE"; badge.className = "mqtt-badge mqtt-online"; } else { badge.innerText = "MQTT: OFFLINE"; badge.className = "mqtt-badge mqtt-offline"; } }
|
||||
});
|
||||
socket.on('connect', () => { refreshStates(); refreshLogs(); refreshStats(); });
|
||||
socket.on('dati_aggiornati', refreshStatesSoon); // stato nodi / telemetria
|
||||
socket.on('log_aggiornato', refreshLogsSoon); // nuovi ascolti -> lastheard + statistiche
|
||||
socket.on('dati_aggiornati', refreshStatesSoon);
|
||||
socket.on('log_aggiornato', refreshLogsSoon);
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user