Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e0e77790 | ||
|
|
1bb1c2cc99 | ||
|
|
5fabe68944 |
+12
-16
@@ -360,28 +360,24 @@ def save_config_file():
|
|||||||
|
|
||||||
# --- AGGIORNAMENTO SERVER OTA ---
|
# --- AGGIORNAMENTO SERVER OTA ---
|
||||||
|
|
||||||
def background_gitea_check():
|
@api_bp.route('/api/server_update/check', methods=['GET'])
|
||||||
global GLOBAL_SERVER_UPDATE_AVAILABLE, LAST_GITEA_CHECK_TIME
|
|
||||||
try:
|
|
||||||
subprocess.run(['git', 'fetch'], timeout=10, cwd=BASE_DIR)
|
|
||||||
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()
|
|
||||||
GLOBAL_SERVER_UPDATE_AVAILABLE = (local_hash != remote_hash)
|
|
||||||
LAST_GITEA_CHECK_TIME = time.time()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Errore controllo Gitea in background: {e}")
|
|
||||||
|
|
||||||
@api_bp.route('/api/server_update/status', methods=['GET'])
|
|
||||||
def get_server_update_status():
|
def get_server_update_status():
|
||||||
global LAST_GITEA_CHECK_TIME
|
global LAST_GITEA_CHECK_TIME, GLOBAL_SERVER_UPDATE_AVAILABLE
|
||||||
auth = get_auth()
|
auth = get_auth()
|
||||||
if not auth or auth['role'] != 'admin':
|
if not auth or auth['role'] != 'admin':
|
||||||
return err("Non autorizzato", 403)
|
return err("Non autorizzato", 403)
|
||||||
|
|
||||||
# Se è passata più di un'ora (3600 secondi) dall'ultimo controllo, avvia il thread
|
# Eseguiamo il controllo sincrono (ci mette max 1-2 secondi) ogni ora
|
||||||
|
# In questo modo il frontend riceve subito il risultato VERO, non quello della cache precedente
|
||||||
if time.time() - LAST_GITEA_CHECK_TIME > 3600:
|
if time.time() - LAST_GITEA_CHECK_TIME > 3600:
|
||||||
import threading
|
try:
|
||||||
threading.Thread(target=background_gitea_check, daemon=True).start()
|
subprocess.run(['git', 'fetch'], timeout=10, cwd=BASE_DIR)
|
||||||
|
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()
|
||||||
|
GLOBAL_SERVER_UPDATE_AVAILABLE = (local_hash != remote_hash)
|
||||||
|
LAST_GITEA_CHECK_TIME = time.time()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Errore controllo Gitea: {e}")
|
||||||
|
|
||||||
return jsonify({"success": True, "update_available": GLOBAL_SERVER_UPDATE_AVAILABLE})
|
return jsonify({"success": True, "update_available": GLOBAL_SERVER_UPDATE_AVAILABLE})
|
||||||
|
|
||||||
|
|||||||
+18
-12
@@ -789,7 +789,22 @@ async function refreshStates() {
|
|||||||
cardDiv.dataset.status = isOnline ? 'online' : 'offline';
|
cardDiv.dataset.status = isOnline ? 'online' : 'offline';
|
||||||
renderSeen(c, data, isOnline);
|
renderSeen(c, data, isOnline);
|
||||||
|
|
||||||
const warns = (data.warnings && data.warnings[c.id.toLowerCase()]) || [];
|
let warns = (data.warnings && data.warnings[c.id.toLowerCase()]) ? [...data.warnings[c.id.toLowerCase()]] : [];
|
||||||
|
|
||||||
|
let hasOfflineService = false;
|
||||||
|
if (healthObj && healthObj.processes) {
|
||||||
|
for (const [svcName, svcStatus] of Object.entries(healthObj.processes)) {
|
||||||
|
let s = svcStatus.toLowerCase();
|
||||||
|
if (s !== 'online' && s !== 'standby') {
|
||||||
|
hasOfflineService = true;
|
||||||
|
warns.push(`SVC KO: ${svcName.toUpperCase()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!latestStatesData.warnings) latestStatesData.warnings = {};
|
||||||
|
latestStatesData.warnings[c.id.toLowerCase()] = warns;
|
||||||
|
|
||||||
cardDiv.dataset.hasWarn = (warns.length > 0) ? 'true' : 'false';
|
cardDiv.dataset.hasWarn = (warns.length > 0) ? 'true' : 'false';
|
||||||
const diagDiv = document.getElementById(`diag-warn-${c.id}`);
|
const diagDiv = document.getElementById(`diag-warn-${c.id}`);
|
||||||
if (diagDiv) {
|
if (diagDiv) {
|
||||||
@@ -936,16 +951,7 @@ async function refreshStates() {
|
|||||||
if (healthContainer) healthContainer.style.display = 'none';
|
if (healthContainer) healthContainer.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logica tollerante per i Gateway in standby (spenti dalla UI)
|
// Logica tollerante per i Gateway in standby (hasOfflineService calcolato in alto)
|
||||||
let hasOfflineService = false;
|
|
||||||
if (healthObj && healthObj.processes) {
|
|
||||||
for (const [svcName, svcStatus] of Object.entries(healthObj.processes)) {
|
|
||||||
let s = svcStatus.toLowerCase();
|
|
||||||
if (s !== 'online' && s !== 'standby') {
|
|
||||||
hasOfflineService = true; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const warnBadge = document.getElementById(`svc-warn-${c.id}`); const btnSvc = document.getElementById(`btn-svc-${c.id}`);
|
const warnBadge = document.getElementById(`svc-warn-${c.id}`); const btnSvc = document.getElementById(`btn-svc-${c.id}`);
|
||||||
if (warnBadge) warnBadge.style.display = hasOfflineService ? 'block' : 'none';
|
if (warnBadge) warnBadge.style.display = hasOfflineService ? 'block' : 'none';
|
||||||
if (btnSvc) { if (hasOfflineService) { btnSvc.style.borderColor = 'var(--danger)'; btnSvc.style.color = 'var(--danger)'; } else { btnSvc.style.borderColor = 'var(--text-main)'; btnSvc.style.color = 'var(--text-main)'; } }
|
if (btnSvc) { if (hasOfflineService) { btnSvc.style.borderColor = 'var(--danger)'; btnSvc.style.color = 'var(--danger)'; } else { btnSvc.style.borderColor = 'var(--text-main)'; btnSvc.style.color = 'var(--text-main)'; } }
|
||||||
@@ -1372,7 +1378,7 @@ function urlB64ToUint8Array(base64String) { const padding = '='.repeat((4 - base
|
|||||||
|
|
||||||
async function checkServerUpdate() {
|
async function checkServerUpdate() {
|
||||||
if (!isAuthenticated || me.role !== 'admin') return;
|
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(e); }
|
try { const res = await fetch('/api/server_update/check'); if (!res.ok) return; 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(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmServerUpdate() {
|
function confirmServerUpdate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user