Compare commits

...
2 Commits
3 changed files with 33 additions and 15 deletions
+12 -3
View File
@@ -226,6 +226,9 @@ def service_control():
d = json_body() d = json_body()
cid = str(d.get('clientId', '')).strip().lower() cid = str(d.get('clientId', '')).strip().lower()
if not check_node_allowed(auth['allowed_nodes'], cid):
return err("Permesso negato per questo nodo", 403)
action = str(d.get('action', '')).strip().lower() action = str(d.get('action', '')).strip().lower()
service = str(d.get('service', '')).strip() service = str(d.get('service', '')).strip()
if not CID_RE.match(cid): if not CID_RE.match(cid):
@@ -323,6 +326,8 @@ def get_config_file(cid, service):
if not auth or auth['role'] != 'admin': if not auth or auth['role'] != 'admin':
return err("Non autorizzato", 403) return err("Non autorizzato", 403)
cid = cid.lower() cid = cid.lower()
if not check_node_allowed(auth['allowed_nodes'], cid):
return err("Permesso negato per questo nodo", 403)
service = service.lower() service = service.lower()
if not CID_RE.match(cid) or not SERVICE_RE.match(service): if not CID_RE.match(cid) or not SERVICE_RE.match(service):
return err("Parametri non validi") return err("Parametri non validi")
@@ -339,6 +344,9 @@ def save_config_file():
d = json_body() d = json_body()
cid = str(d.get('clientId', '')).strip().lower() cid = str(d.get('clientId', '')).strip().lower()
if not check_node_allowed(auth['allowed_nodes'], cid):
return err("Permesso negato per questo nodo", 403)
service = str(d.get('service', '')).strip().lower() service = str(d.get('service', '')).strip().lower()
new_config = d.get('config_data') new_config = d.get('config_data')
if not CID_RE.match(cid) or not SERVICE_RE.match(service): if not CID_RE.match(cid) or not SERVICE_RE.match(service):
@@ -367,9 +375,10 @@ def get_server_update_status():
if not auth or auth['role'] != 'admin': if not auth or auth['role'] != 'admin':
return err("Non autorizzato", 403) return err("Non autorizzato", 403)
# Eseguiamo il controllo sincrono (ci mette max 1-2 secondi) ogni ora force_check = request.args.get('force') == '1'
# In questo modo il frontend riceve subito il risultato VERO, non quello della cache precedente
if time.time() - LAST_GITEA_CHECK_TIME > 3600: # Eseguiamo il controllo sincrono se è passata 1 ora OPPURE se forzato dal client
if force_check or (time.time() - LAST_GITEA_CHECK_TIME > 3600):
try: try:
subprocess.run(['git', 'fetch'], timeout=10, cwd=BASE_DIR) 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() local_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=BASE_DIR).decode('utf-8').strip()
+19 -10
View File
@@ -112,7 +112,7 @@ function openNodeFocus(clientId) {
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
let canControl = isAuthenticated && (role === 'admin' || allowedList.includes('all') || allowedList.includes(clientId.toLowerCase())); let canControl = isAuthenticated && (allowedList.includes('all') || allowedList.includes(clientId.toLowerCase()));
const modesCard = document.getElementById('focus-modes-card'); const modesCard = document.getElementById('focus-modes-card');
if (modesCard) { if (modesCard) {
@@ -290,7 +290,7 @@ function sendTgCommand(clientId, comando) {
async function fetchNodeConfigForModes(clientId) { async function fetchNodeConfigForModes(clientId) {
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
let canControl = isAuthenticated && (role === 'admin' || allowedList.includes('all') || allowedList.includes(clientId.toLowerCase())); let canControl = isAuthenticated && (allowedList.includes('all') || allowedList.includes(clientId.toLowerCase()));
const modesCard = document.getElementById('focus-modes-card'); const modesCard = document.getElementById('focus-modes-card');
if (!canControl) { if (!canControl) {
if (modesCard) modesCard.style.display = 'none'; if (modesCard) modesCard.style.display = 'none';
@@ -349,7 +349,7 @@ async function fetchNodeConfigForModes(clientId) {
function renderModeToggles(clientId, statusMsg = "") { function renderModeToggles(clientId, statusMsg = "") {
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
let canControl = isAuthenticated && (role === 'admin' || allowedList.includes('all') || allowedList.includes(clientId.toLowerCase())); let canControl = isAuthenticated && (allowedList.includes('all') || allowedList.includes(clientId.toLowerCase()));
const modesCard = document.getElementById('focus-modes-card'); const modesCard = document.getElementById('focus-modes-card');
if (modesCard) { if (modesCard) {
@@ -530,7 +530,7 @@ async function initUI() {
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
if (isAuthenticated) { if (isAuthenticated) {
const hasAllNodes = role === 'admin' || allowedList.includes('all'); const hasAllNodes = allowedList.includes('all');
const canOverride = hasAllNodes; const canOverride = hasAllNodes;
let actionBtns = ''; let actionBtns = '';
@@ -554,8 +554,8 @@ async function initUI() {
} }
grid.innerHTML = clients.map(c => { grid.innerHTML = clients.map(c => {
let canControl = isAuthenticated && (role === 'admin' || allowedList.includes('all') || allowedList.includes(c.id.toLowerCase())); let canControl = isAuthenticated && (allowedList.includes('all') || allowedList.includes(c.id.toLowerCase()));
let showReboot = (role === 'admin'); let showReboot = (role === 'admin' && canControl);
return ` return `
<div class="card" id="card-${c.id}" data-status="offline" data-gateways="" data-loc="" data-has-warn="false"> <div class="card" id="card-${c.id}" data-status="offline" data-gateways="" data-loc="" data-has-warn="false">
@@ -765,8 +765,8 @@ async function refreshStates() {
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
let canControl = isAuthenticated && (role === 'admin' || allowedList.includes('all') || allowedList.includes(c.id.toLowerCase())); let canControl = isAuthenticated && (allowedList.includes('all') || allowedList.includes(c.id.toLowerCase()));
let showReboot = (role === 'admin'); let showReboot = (role === 'admin' && canControl);
let isTx = false; let isTx = false;
let activeModeColor = "var(--primary)"; let activeModeColor = "var(--primary)";
@@ -1385,9 +1385,18 @@ async function checkPushStatus() {
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; } 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() { async function checkServerUpdate(force = false) {
if (!isAuthenticated || me.role !== 'admin') return; if (!isAuthenticated || me.role !== 'admin') return;
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); } try {
const url = force ? '/api/server_update/check?force=1' : '/api/server_update/check';
const res = await fetch(url);
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() {
+2 -2
View File
@@ -232,7 +232,7 @@ async function saveSettings() {
function triggerGlobalEmergency() { function triggerGlobalEmergency() {
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
const hasAll = role === 'admin' || allowedList.includes('all'); const hasAll = allowedList.includes('all');
let uniqueProfiles = {}; let uniqueProfiles = {};
for (const id in globalHealthData) { for (const id in globalHealthData) {
@@ -259,7 +259,7 @@ function sendGlobalAction(action) {
document.getElementById('override-modal').style.display = 'none'; document.getElementById('override-modal').style.display = 'none';
const role = me.role || ''; const role = me.role || '';
const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean); const allowedList = String(me.allowed_nodes || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
const hasAll = role === 'admin' || allowedList.includes('all'); const hasAll = allowedList.includes('all');
const confirmMsg = hasAll const confirmMsg = hasAll
? t('promptOvrConfirm') ? t('promptOvrConfirm')