fix/feat: stabilizzazione dashboard in tempo reale e log dinamici
- Modificato app.py per leggere i parametri del RotatingFileHandler dal config.json, permettendo la regolazione dello spazio su disco senza toccare il codice. - Identificato e risolto il bug degli azzeramenti della tabella Lastheard (causato da un fallback continuo di Socket.IO a causa della mancata direttiva Upgrade nei reverse proxy)
This commit is contained in:
@@ -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.
|
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.
|
**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
|
#### 🛠️ Advanced Remote Control & Maintenance
|
||||||
* **Remote .INI Editor:** Edit daemon configuration files (e.g., MMDVMHost.ini) directly from the web interface without SSH access.
|
* **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.
|
* **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.
|
2. Configure your MQTT broker credentials.
|
||||||
3. Define your repeaters in `clients.json`.
|
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).*
|
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
|
#### 4. Running as a Service
|
||||||
To run the server continuously in production using Gunicorn:
|
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.
|
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.
|
**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
|
#### 🛠️ Controllo Remoto & Manutenzione Avanzata
|
||||||
* **Editor .INI Remoto:** Modifica i file di configurazione (es. MMDVMHost.ini) direttamente dal pannello web, senza bisogno di accessi SSH.
|
* **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.
|
* **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.
|
2. Inserisci le credenziali del broker MQTT.
|
||||||
3. Definisci i ripetitori nel file `clients.json`.
|
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).*
|
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)
|
#### 4. Esecuzione come Servizio (systemd)
|
||||||
Per eseguire il server in produzione in modo continuo e stabile con Gunicorn:
|
Per eseguire il server in produzione in modo continuo e stabile con Gunicorn:
|
||||||
|
|||||||
@@ -29,25 +29,15 @@ NXDN_IDS_PATH = os.path.join(BASE_DIR, 'nxdn.csv')
|
|||||||
CLIENTS_PATH = os.path.join(BASE_DIR, 'clients.json')
|
CLIENTS_PATH = os.path.join(BASE_DIR, 'clients.json')
|
||||||
LOG_FILE = os.path.join(BASE_DIR, 'fleet_console.log')
|
LOG_FILE = os.path.join(BASE_DIR, 'fleet_console.log')
|
||||||
|
|
||||||
# --- LOGGING CONFIGURATION ---
|
# --- CONFIG LOADER (INIZIALE PER IL LOGGING) ---
|
||||||
logging.basicConfig(
|
|
||||||
handlers=[
|
|
||||||
RotatingFileHandler(LOG_FILE, maxBytes=10000000, backupCount=3),
|
|
||||||
logging.StreamHandler()
|
|
||||||
],
|
|
||||||
level=logging.INFO,
|
|
||||||
format='[%(asctime)s] %(levelname)s - %(message)s',
|
|
||||||
datefmt='%Y-%m-%d %H:%M:%S'
|
|
||||||
)
|
|
||||||
logger = logging.getLogger("FleetHub")
|
|
||||||
logging.getLogger('werkzeug').setLevel(logging.ERROR)
|
|
||||||
|
|
||||||
# --- CONFIG ---
|
|
||||||
config_lock = threading.Lock()
|
config_lock = threading.Lock()
|
||||||
|
|
||||||
def read_config():
|
def read_config():
|
||||||
|
try:
|
||||||
with open(CONFIG_PATH, 'r') as f:
|
with open(CONFIG_PATH, 'r') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
|
except Exception:
|
||||||
|
return {}
|
||||||
|
|
||||||
def write_config(cfg):
|
def write_config(cfg):
|
||||||
tmp = CONFIG_PATH + '.tmp'
|
tmp = CONFIG_PATH + '.tmp'
|
||||||
@@ -63,6 +53,23 @@ def write_config(cfg):
|
|||||||
config = read_config()
|
config = read_config()
|
||||||
web_cfg = config.get('web', {})
|
web_cfg = config.get('web', {})
|
||||||
|
|
||||||
|
# --- LOGGING CONFIGURATION DINAMICA ---
|
||||||
|
log_max_mb = int(config.get('log_max_mb', 50))
|
||||||
|
log_backup_count = int(config.get('log_backup_count', 10))
|
||||||
|
max_bytes_val = log_max_mb * 1024 * 1024 if log_max_mb > 0 else 0
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
handlers=[
|
||||||
|
RotatingFileHandler(LOG_FILE, maxBytes=max_bytes_val, backupCount=log_backup_count),
|
||||||
|
logging.StreamHandler()
|
||||||
|
],
|
||||||
|
level=logging.INFO,
|
||||||
|
format='[%(asctime)s] %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
|
logger = logging.getLogger("FleetHub")
|
||||||
|
logging.getLogger('werkzeug').setLevel(logging.ERROR)
|
||||||
|
|
||||||
def get_secret_key():
|
def get_secret_key():
|
||||||
key = os.environ.get('FLEET_SECRET_KEY') or config.get('secret_key')
|
key = os.environ.get('FLEET_SECRET_KEY') or config.get('secret_key')
|
||||||
if not key or key == 'ari_fvg_secret_ultra_secure':
|
if not key or key == 'ari_fvg_secret_ultra_secure':
|
||||||
@@ -337,33 +344,27 @@ def on_message(client, userdata, msg):
|
|||||||
if cid not in node_versions:
|
if cid not in node_versions:
|
||||||
node_versions[cid] = {}
|
node_versions[cid] = {}
|
||||||
|
|
||||||
# 1. Cattura il Firmware MMDVM (es. "... description: MMDVM 20260424 19.2000 Mhz GitID #57e692a")
|
|
||||||
m_fw = re.search(r'description:\s*(MMDVM[^\n\r]+)', payload, re.IGNORECASE)
|
m_fw = re.search(r'description:\s*(MMDVM[^\n\r]+)', payload, re.IGNORECASE)
|
||||||
if m_fw:
|
if m_fw:
|
||||||
node_versions[cid]["Firmware MMDVM"] = m_fw.group(1).strip()
|
node_versions[cid]["Firmware MMDVM"] = m_fw.group(1).strip()
|
||||||
notify_update()
|
notify_update()
|
||||||
|
|
||||||
# 2. Cattura le versioni dei demoni Formato A (es. "YSFGateway-20260323 is starting")
|
|
||||||
m_sw1 = re.search(r'([A-Za-z0-9_]+)-([a-zA-Z0-9.\-]+)\s+is starting', payload, re.IGNORECASE)
|
m_sw1 = re.search(r'([A-Za-z0-9_]+)-([a-zA-Z0-9.\-]+)\s+is starting', payload, re.IGNORECASE)
|
||||||
if m_sw1:
|
if m_sw1:
|
||||||
prog = m_sw1.group(1)
|
prog = m_sw1.group(1)
|
||||||
node_versions[cid][prog] = m_sw1.group(2).strip()
|
node_versions[cid][prog] = m_sw1.group(2).strip()
|
||||||
node_versions[cid]["_last_prog"] = prog # Per il GitID della riga dopo
|
node_versions[cid]["_last_prog"] = prog
|
||||||
notify_update()
|
notify_update()
|
||||||
|
|
||||||
# 3. Cattura le versioni dei demoni Formato B (es. "MMDVMHost version 20250419 git #65ebb55")
|
|
||||||
m_sw2 = re.search(r'([A-Za-z0-9_]+)\s+version\s+([a-zA-Z0-9.\-\s#]+)', payload, re.IGNORECASE)
|
m_sw2 = re.search(r'([A-Za-z0-9_]+)\s+version\s+([a-zA-Z0-9.\-\s#]+)', payload, re.IGNORECASE)
|
||||||
if m_sw2:
|
if m_sw2:
|
||||||
prog = m_sw2.group(1)
|
prog = m_sw2.group(1)
|
||||||
# Ignoriamo i falsi positivi dei log (es. "protocol version", "firmware version")
|
|
||||||
if prog.lower() not in ['protocol', 'firmware', 'mmdvm firmware']:
|
if prog.lower() not in ['protocol', 'firmware', 'mmdvm firmware']:
|
||||||
# Puliamo un eventuale "is starting" finale, se presente
|
|
||||||
ver = m_sw2.group(2).replace("is starting", "").strip()
|
ver = m_sw2.group(2).replace("is starting", "").strip()
|
||||||
node_versions[cid][prog] = ver
|
node_versions[cid][prog] = ver
|
||||||
node_versions[cid]["_last_prog"] = prog
|
node_versions[cid]["_last_prog"] = prog
|
||||||
notify_update()
|
notify_update()
|
||||||
|
|
||||||
# 4. Cattura il GitID della riga successiva per i demoni di Formato A
|
|
||||||
m_git = re.search(r'Built .*?\(GitID #([0-9a-fA-F]+)\)', payload, re.IGNORECASE)
|
m_git = re.search(r'Built .*?\(GitID #([0-9a-fA-F]+)\)', payload, re.IGNORECASE)
|
||||||
if m_git:
|
if m_git:
|
||||||
git_id = m_git.group(1)
|
git_id = m_git.group(1)
|
||||||
@@ -426,23 +427,19 @@ def on_message(client, userdata, msg):
|
|||||||
"profiles": data.get("profiles", {"A": "PROFILE A", "B": "PROFILE B"}),
|
"profiles": data.get("profiles", {"A": "PROFILE A", "B": "PROFILE B"}),
|
||||||
"interval": data.get("update_interval")
|
"interval": data.get("update_interval")
|
||||||
}
|
}
|
||||||
# --- AGGIUNTA E PULIZIA: SALVA LE VERSIONI DEI BINARI ---
|
|
||||||
bin_versions = data.get("versions", {})
|
bin_versions = data.get("versions", {})
|
||||||
if bin_versions:
|
if bin_versions:
|
||||||
if cid not in node_versions:
|
if cid not in node_versions:
|
||||||
node_versions[cid] = {}
|
node_versions[cid] = {}
|
||||||
|
|
||||||
# Rimuove le vecchie versioni binarie che il nodo non trasmette più
|
|
||||||
# (proteggendo però il "Firmware MMDVM" e le chiavi interne che derivano dai log)
|
|
||||||
keys_to_remove = [k for k in node_versions[cid].keys()
|
keys_to_remove = [k for k in node_versions[cid].keys()
|
||||||
if k not in bin_versions and k not in ["Firmware MMDVM", "_last_prog"]]
|
if k not in bin_versions and k not in ["Firmware MMDVM", "_last_prog"]]
|
||||||
for k in keys_to_remove:
|
for k in keys_to_remove:
|
||||||
del node_versions[cid][k]
|
del node_versions[cid][k]
|
||||||
|
|
||||||
# Aggiorna o aggiunge le versioni attuali
|
|
||||||
for prog_name, prog_ver in bin_versions.items():
|
for prog_name, prog_ver in bin_versions.items():
|
||||||
node_versions[cid][prog_name] = prog_ver
|
node_versions[cid][prog_name] = prog_ver
|
||||||
# ----------------------------------------------
|
|
||||||
health_changed = device_health.get(cid) != new_health
|
health_changed = device_health.get(cid) != new_health
|
||||||
device_health[cid] = new_health
|
device_health[cid] = new_health
|
||||||
if health_changed:
|
if health_changed:
|
||||||
@@ -553,7 +550,6 @@ def on_message(client, userdata, msg):
|
|||||||
src = get_call(d.get('src_id'))
|
src = get_call(d.get('src_id'))
|
||||||
dst = str(d.get('dst_id'))
|
dst = str(d.get('dst_id'))
|
||||||
|
|
||||||
# Salviamo i campi estesi (source, mode) in RAM quando inizia il passaggio
|
|
||||||
active_calls[cid][sk] = {
|
active_calls[cid][sk] = {
|
||||||
'src': src,
|
'src': src,
|
||||||
'dst': dst,
|
'dst': dst,
|
||||||
@@ -568,10 +564,8 @@ def on_message(client, userdata, msg):
|
|||||||
notify_update()
|
notify_update()
|
||||||
|
|
||||||
elif act in ['end', 'lost']:
|
elif act in ['end', 'lost']:
|
||||||
# Ripeschiamo le info dalla RAM (incluso il source) che il pacchetto "end" ha omesso
|
|
||||||
info = active_calls[cid].get(sk, {'src': '---', 'dst': '---', 'slot': d.get('slot', 1), 'ext': '', 'source': '', 'mode': ''})
|
info = active_calls[cid].get(sk, {'src': '---', 'dst': '---', 'slot': d.get('slot', 1), 'ext': '', 'source': '', 'mode': ''})
|
||||||
|
|
||||||
# Iniettiamo a forza i dati nel dizionario prima di inviarlo al database SQLite
|
|
||||||
d.update({
|
d.update({
|
||||||
'src_id': info['src'],
|
'src_id': info['src'],
|
||||||
'dst_id': info['dst'],
|
'dst_id': info['dst'],
|
||||||
@@ -596,40 +590,31 @@ def on_message(client, userdata, msg):
|
|||||||
elif k == 'P25': src = get_call(p.get('src_id', '---'), 'DMR')
|
elif k == 'P25': src = get_call(p.get('src_id', '---'), 'DMR')
|
||||||
else: src = str(p.get('Callsign', p.get('src_callsign', p.get('src_info', p.get('src_id', '---')))))
|
else: src = str(p.get('Callsign', p.get('src_callsign', p.get('src_info', p.get('src_id', '---')))))
|
||||||
|
|
||||||
# --- NUOVA GESTIONE TARGET VS REF/SLOT ---
|
|
||||||
# 1. Peschiamo il target specifico (es. ID in NXDN o chiamata YSF)
|
|
||||||
raw_target = str(p.get('dst_callsign', p.get('dst_id', ''))).strip()
|
raw_target = str(p.get('dst_callsign', p.get('dst_id', ''))).strip()
|
||||||
|
|
||||||
# Nel D-STAR mostriamo sempre l'UR CALL (CQCQCQ o comandi), negli altri puliamo gli ALL/0 generici
|
|
||||||
if name == 'D-STAR':
|
if name == 'D-STAR':
|
||||||
target = raw_target if raw_target else "---"
|
target = raw_target if raw_target else "---"
|
||||||
else:
|
else:
|
||||||
target = raw_target if raw_target not in ['', '0', 'ALL'] else "---"
|
target = raw_target if raw_target not in ['', '0', 'ALL'] else "---"
|
||||||
# Selezioniamo il DG-ID per l'YSF
|
|
||||||
if name == 'YSF' and 'dg-id' in p:
|
if name == 'YSF' and 'dg-id' in p:
|
||||||
dg_id = str(p.get('dg-id')).strip()
|
dg_id = str(p.get('dg-id')).strip()
|
||||||
if dg_id:
|
if dg_id:
|
||||||
target = f"DG-ID {dg_id}" if target == "---" else f"{target} (DG {dg_id})"
|
target = f"DG-ID {dg_id}" if target == "---" else f"{target} (DG {dg_id})"
|
||||||
|
|
||||||
# 2. Peschiamo il Reflector / Stanza connessa dalla memoria del Gateway
|
|
||||||
mem_ref = last_seen_reflector.get(f"{cid}_{name}", "---")
|
mem_ref = last_seen_reflector.get(f"{cid}_{name}", "---")
|
||||||
pack_ref = str(p.get('reflector', '')).strip()
|
pack_ref = str(p.get('reflector', '')).strip()
|
||||||
|
|
||||||
# Diamo sempre priorità alla memoria di rete, ma usiamo il pacchetto come paracadute
|
|
||||||
ref_slot = mem_ref if mem_ref != "---" else (pack_ref if pack_ref else "---")
|
ref_slot = mem_ref if mem_ref != "---" else (pack_ref if pack_ref else "---")
|
||||||
|
|
||||||
active_calls[cid][k] = {'src': src, 'dst': target, 'slot': ref_slot, 'ext': str(p.get('src_ext', '')), 'source': str(p.get('source', '')), 'mode': str(p.get('mode', ''))}
|
active_calls[cid][k] = {'src': src, 'dst': target, 'slot': ref_slot, 'ext': str(p.get('src_ext', '')), 'source': str(p.get('source', '')), 'mode': str(p.get('mode', ''))}
|
||||||
|
|
||||||
# Aggiorniamo anche la stringa telemetrica visiva
|
|
||||||
target_str = target if target != "---" else "NET"
|
target_str = target if target != "---" else "NET"
|
||||||
client_telemetry[cid].update({"ts1":"","ts2":"","alt": f"{ico} {name}: {src} ➔ {target_str} ({ref_slot})"})
|
client_telemetry[cid].update({"ts1":"","ts2":"","alt": f"{ico} {name}: {src} ➔ {target_str} ({ref_slot})"})
|
||||||
notify_update()
|
notify_update()
|
||||||
|
|
||||||
elif act in ['end', 'lost']:
|
elif act in ['end', 'lost']:
|
||||||
# Estraiamo anche la variabile 'slot' memorizzata prima
|
|
||||||
info = active_calls[cid].get(k, {'src': '---', 'dst': '---', 'slot': '---', 'ext': '', 'source': '', 'mode': ''})
|
info = active_calls[cid].get(k, {'src': '---', 'dst': '---', 'slot': '---', 'ext': '', 'source': '', 'mode': ''})
|
||||||
|
|
||||||
# Forziamo l'inserimento dello slot nel dizionario 'p' che verrà salvato nel DB
|
|
||||||
p.update({'src_id': info['src'], 'dst_id': info['dst'], 'slot': info['slot'], 'src_ext': info['ext'], 'source': info['source'], 'mode': info['mode']})
|
p.update({'src_id': info['src'], 'dst_id': info['dst'], 'slot': info['slot'], 'src_ext': info['ext'], 'source': info['source'], 'mode': info['mode']})
|
||||||
|
|
||||||
save_to_sqlite(cid, p, protocol=name)
|
save_to_sqlite(cid, p, protocol=name)
|
||||||
@@ -639,16 +624,16 @@ def on_message(client, userdata, msg):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"MQTT MSG ERROR: {e}")
|
logger.error(f"MQTT MSG ERROR: {e}")
|
||||||
|
|
||||||
mqtt_id = config['mqtt'].get('client_id', 'flask_backend_generic')
|
mqtt_id = config.get('mqtt', {}).get('client_id', 'flask_backend_generic')
|
||||||
mqtt_backend = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION2, mqtt_id)
|
mqtt_backend = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION2, mqtt_id)
|
||||||
mqtt_backend.username_pw_set(config['mqtt']['user'], config['mqtt']['password'])
|
mqtt_backend.username_pw_set(config.get('mqtt', {}).get('user', ''), config.get('mqtt', {}).get('password', ''))
|
||||||
mqtt_backend.on_connect = on_connect
|
mqtt_backend.on_connect = on_connect
|
||||||
mqtt_backend.on_disconnect = on_disconnect
|
mqtt_backend.on_disconnect = on_disconnect
|
||||||
mqtt_backend.on_message = on_message
|
mqtt_backend.on_message = on_message
|
||||||
try:
|
try:
|
||||||
mqtt_backend.connect_async(config['mqtt']['broker'], config['mqtt']['port'])
|
mqtt_backend.connect_async(config.get('mqtt', {}).get('broker', 'localhost'), config.get('mqtt', {}).get('port', 1883))
|
||||||
mqtt_backend.loop_start()
|
mqtt_backend.loop_start()
|
||||||
logger.info(f"Avvio connessione MQTT asincrona verso {config['mqtt']['broker']}...")
|
logger.info(f"Avvio connessione MQTT asincrona verso {config.get('mqtt', {}).get('broker')}...")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Errore critico nell'inizializzazione MQTT: {e}")
|
logger.error(f"Errore critico nell'inizializzazione MQTT: {e}")
|
||||||
|
|
||||||
@@ -695,7 +680,6 @@ def get_logs():
|
|||||||
|
|
||||||
@app.route('/api/states', methods=['GET'])
|
@app.route('/api/states', methods=['GET'])
|
||||||
def get_states():
|
def get_states():
|
||||||
# Filtriamo le chiavi di servizio (come '_last_prog') per non mandarle all'interfaccia
|
|
||||||
clean_versions = {}
|
clean_versions = {}
|
||||||
for c, d in node_versions.items():
|
for c, d in node_versions.items():
|
||||||
clean_versions[c] = {k: v for k, v in d.items() if not k.startswith('_')}
|
clean_versions[c] = {k: v for k, v in d.items() if not k.startswith('_')}
|
||||||
@@ -1210,7 +1194,9 @@ def get_config_api():
|
|||||||
return jsonify({
|
return jsonify({
|
||||||
"update_schedule": cfg.get("update_schedule", "03:00"),
|
"update_schedule": cfg.get("update_schedule", "03:00"),
|
||||||
"url_dmr": cfg.get("id_urls", {}).get("dmr", ""),
|
"url_dmr": cfg.get("id_urls", {}).get("dmr", ""),
|
||||||
"url_nxdn": cfg.get("id_urls", {}).get("nxdn", "")
|
"url_nxdn": cfg.get("id_urls", {}).get("nxdn", ""),
|
||||||
|
"log_max_mb": cfg.get("log_max_mb", 50),
|
||||||
|
"log_backup_count": cfg.get("log_backup_count", 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@app.route('/api/config', methods=['POST'])
|
@app.route('/api/config', methods=['POST'])
|
||||||
@@ -1223,6 +1209,13 @@ def save_config_api():
|
|||||||
schedule = str(d.get("update_schedule", "03:00")).strip()
|
schedule = str(d.get("update_schedule", "03:00")).strip()
|
||||||
url_dmr = str(d.get("url_dmr", "")).strip()
|
url_dmr = str(d.get("url_dmr", "")).strip()
|
||||||
url_nxdn = str(d.get("url_nxdn", "")).strip()
|
url_nxdn = str(d.get("url_nxdn", "")).strip()
|
||||||
|
|
||||||
|
try:
|
||||||
|
log_max_mb = int(d.get("log_max_mb", 50))
|
||||||
|
log_backup_count = int(d.get("log_backup_count", 10))
|
||||||
|
except ValueError:
|
||||||
|
return err("Invalid log rotation settings")
|
||||||
|
|
||||||
if not TIME_RE.match(schedule):
|
if not TIME_RE.match(schedule):
|
||||||
return err("Invalid time (use HH:MM)")
|
return err("Invalid time (use HH:MM)")
|
||||||
for u in (url_dmr, url_nxdn):
|
for u in (url_dmr, url_nxdn):
|
||||||
@@ -1234,6 +1227,9 @@ def save_config_api():
|
|||||||
cfg.setdefault("id_urls", {})
|
cfg.setdefault("id_urls", {})
|
||||||
cfg["id_urls"]["dmr"] = url_dmr
|
cfg["id_urls"]["dmr"] = url_dmr
|
||||||
cfg["id_urls"]["nxdn"] = url_nxdn
|
cfg["id_urls"]["nxdn"] = url_nxdn
|
||||||
|
cfg["log_max_mb"] = log_max_mb
|
||||||
|
cfg["log_backup_count"] = log_backup_count
|
||||||
|
|
||||||
write_config(cfg)
|
write_config(cfg)
|
||||||
audit(auth['username'], '-', 'EDIT_SERVER_CONFIG')
|
audit(auth['username'], '-', 'EDIT_SERVER_CONFIG')
|
||||||
return jsonify({"success": True})
|
return jsonify({"success": True})
|
||||||
|
|||||||
+3
-1
@@ -37,5 +37,7 @@
|
|||||||
"id_urls": {
|
"id_urls": {
|
||||||
"dmr": "https://radioid.net/static/dmrid.dat",
|
"dmr": "https://radioid.net/static/dmrid.dat",
|
||||||
"nxdn": "https://radioid.net/static/nxdn.csv"
|
"nxdn": "https://radioid.net/static/nxdn.csv"
|
||||||
}
|
},
|
||||||
|
"log_max_mb": 50,
|
||||||
|
"log_backup_count": 10
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user