diff --git a/ap.py b/ap.py index 02433d5..4785879 100644 --- a/ap.py +++ b/ap.py @@ -12089,7 +12089,7 @@ class Handler(BaseHTTPRequestHandler): for v_path in ('/data/version.json', os.path.join(BASE_DIR, 'version.json'), 'version.json'): try: with open(v_path, 'w', encoding='utf-8') as f: - json.dump(v_data, f, indent=2) + json.dump(v_data, f, indent=2, ensure_ascii=False) except Exception: pass with _update_lock: diff --git a/index.html b/index.html index 4e034d1..f068718 100644 --- a/index.html +++ b/index.html @@ -9393,6 +9393,204 @@ ${vpnBadgeTopo} if ($('nav')) $('nav').style.display = configured ? 'flex' : 'none'; if ($('dashboardTab')) $('dashboardTab').style.display = configured ? '' : 'none'; if ($('statsTab')) $('statsTab').style.display = configured ? '' : 'none'; + if ($('devicesTab')) $('devicesTab').style.display = configured ? '' : 'none'; + if ($('advancedTab')) $('advancedTab').style.display = configured ? '' : 'none'; + if ($('settingsTab')) $('settingsTab').style.display = configured ? '' : 'none'; + if ($('logsTab')) $('logsTab').style.display = configured ? '' : 'none'; + if ($('blockedTab')) $('blockedTab').style.display = configured ? '' : 'none'; + if ($('apControl')) { + $('apControl').style.display = configured ? '' : 'none'; + $('apControl').textContent = active ? t('btn_stop', 'Arrêter') : t('btn_start', 'Démarrer'); + $('apControl').style.background = active ? 'var(--red)' : 'var(--blue)'; + $('apControl').style.color = active ? 'white' : 'var(--blue-text, #071326)'; + } + if ($('apRestart')) { + $('apRestart').style.display = configured ? '' : 'none'; + $('apRestart').disabled = !active; + $('apRestart').style.opacity = active ? '1' : '0.4'; + $('apRestart').style.cursor = active ? 'pointer' : 'not-allowed'; + $('apRestart').title = active ? t('btn_restart', 'Redémarrer') : t('ap_stopped_no_restart', "L'AP est arrêtée (démarrage requis)"); + } + if ($('refresh')) $('refresh').style.display = configured ? '' : 'none'; + const updateInfo = (status && status.update) ? status.update : null; + if (updateInfo) lastUpdateData = updateInfo; + const updateAvailable = !!(updateInfo && updateInfo.available); + if ($('btnUpdateAvailable')) { + $('btnUpdateAvailable').style.display = (configured && updateAvailable) ? 'inline-flex' : 'none'; + } + } + + let lastUpdateData = null; + + function openUpdateModal() { + const modal = $('modalUpdateApp'); + if (!modal) return; + const u = lastUpdateData || (status && status.update) || {}; + const isAvail = !!u.available; + if ($('updateCurrentCommit')) $('updateCurrentCommit').textContent = u.current_commit || (u.current_commit_full ? u.current_commit_full.substring(0, 7) : '—'); + if ($('updateLatestCommit')) $('updateLatestCommit').textContent = u.latest_commit || (u.latest_commit_full ? u.latest_commit_full.substring(0, 7) : '—'); + if ($('updateCommitMsg')) $('updateCommitMsg').textContent = u.commit_msg || t('update_no_msg', 'Aucun message de commit'); + if ($('updateCommitAuthor')) $('updateCommitAuthor').textContent = u.author ? ('Par ' + u.author) : ''; + if ($('updateCommitDate')) { + let dStr = ''; + if (u.date) { + try { dStr = 'le ' + new Date(u.date).toLocaleString(); } catch (_) { dStr = 'le ' + u.date; } + } + $('updateCommitDate').textContent = dStr; + } + if ($('updateStatusAlert')) { + $('updateStatusAlert').style.background = isAvail ? 'rgba(16,185,129,0.1)' : 'rgba(56,189,248,0.1)'; + $('updateStatusAlert').style.borderColor = isAvail ? 'rgba(16,185,129,0.3)' : 'rgba(56,189,248,0.3)'; + } + if ($('updateStatusIcon')) { + $('updateStatusIcon').textContent = isAvail ? '🚀' : '✅'; + } + if ($('updateStatusTitle')) { + $('updateStatusTitle').textContent = isAvail ? t('update_new_version_found', 'Une nouvelle version de AP Manageur est prête !') : t('update_up_to_date', 'AP Manageur est à jour !'); + $('updateStatusTitle').style.color = isAvail ? '#10b981' : 'var(--blue)'; + } + if ($('updateStatusDesc')) { + $('updateStatusDesc').textContent = isAvail ? t('update_new_version_desc', "Une mise à jour plus récente de l'application est disponible sur le dépôt.") : t('update_up_to_date_desc', "Vous disposez déjà de la version la plus récente de l'application."); + } + if ($('updateDockerCmdSection')) { + $('updateDockerCmdSection').style.display = isAvail ? 'block' : 'none'; + } + + modal.classList.add('active'); + } + window.openUpdateModal = openUpdateModal; + + function closeUpdateModal() { + const modal = $('modalUpdateApp'); + if (modal) modal.classList.remove('active'); + } + window.closeUpdateModal = closeUpdateModal; + + async function copyUpdateCommand() { + const input = $('updateDockerCmd'); + const btnText = $('btnCopyUpdateCmdText'); + if (!input) return; + const cmd = input.value; + try { + if (navigator.clipboard && navigator.clipboard.writeText) { + await navigator.clipboard.writeText(cmd); + } else { + input.select(); + document.execCommand('copy'); + } + if (btnText) { + const original = btnText.textContent; + btnText.textContent = t('update_cmd_copied', '✓ Copié !'); + setTimeout(() => { if (btnText) btnText.textContent = original; }, 2000); + } + } catch (err) { + input.select(); + document.execCommand('copy'); + } + } + window.copyUpdateCommand = copyUpdateCommand; + + async function triggerManualUpdateCheck() { + const btn = $('btnCheckUpdateManual'); + if (btn) btn.disabled = true; + try { + const res = await apiFetch('/api/system/update?force=1', { cache: 'no-store' }); + if (res.ok) { + const u = await res.json(); + lastUpdateData = u; + if (status) status.update = u; + updateApButtons(); + openUpdateModal(); + } + } catch (e) { + console.warn('Erreur vérification mise à jour :', e); + } finally { + if (btn) btn.disabled = false; + } + } + window.triggerManualUpdateCheck = triggerManualUpdateCheck; + + async function toggleBlock(mac, blocked) { + return runAction(async () => { + try { + const response = await apiFetch('/api/clients/block', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ mac, blocked }) }); + const data = await response.json(); if (!response.ok) throw Error(data.error || 'Opération refusée'); + await load(); + } catch (e) { alert(tErr(e.message)) } + }); + } + + function render() { + updateApButtons(); + $('clientCount').textContent = status.max_clients > 0 ? `${clients.length} / ${status.max_clients}` : clients.length; + $('ssid').textContent = status.ssid || 'SSID inconnu'; + $('uptime').textContent = status.active ? uptime(status.uptime_seconds) : '—'; + $('settingsSsid').value = status.ssid || ''; + $('settingsPassword').value = status.password || ''; + $('settingsSecurity').value = status.security || 'wpa2'; + if ($('settingsMaxClients')) $('settingsMaxClients').value = status.max_clients !== undefined ? status.max_clients : 0; + const isBridge = status.mode === 'bridge'; + if ($('networkModeBadge')) { + $('networkModeBadge').textContent = isBridge ? t('badge_mode_bridge', 'Pont (DHCP Box)') : t('badge_mode_ap', 'AP (Routeur/NAT)'); + $('networkModeBadge').className = 'pill ' + (isBridge ? 'pill-blue' : 'pill-green'); + $('networkModeBadge').style.background = ''; + $('networkModeBadge').style.color = ''; + } + if ($('settingsModeAp') && $('settingsModeBridge')) { + if (isBridge) $('settingsModeBridge').checked = true; else $('settingsModeAp').checked = true; + if ($('settingsBridgeBlock')) $('settingsBridgeBlock').style.display = isBridge ? 'block' : 'none'; + } + const ethList = status.ethernet_interfaces || []; + const populateEth = (selId, cur) => { + const el = $(selId); if (!el) return; const val = el.value || cur; + el.innerHTML = ethList.length ? ethList.map(e => ``).join('') : ''; + if (val && ethList.includes(val)) el.value = val; else if (cur && ethList.includes(cur)) el.value = cur; + }; + populateEth('setupBridgeEth', status.bridge_eth); populateEth('settingsBridgeEth', status.bridge_eth); + $('settingsAutoconnect').checked = !!status.autoconnect; + $('updated').textContent = formatLastUpdated(); + $('state').innerHTML = status.active ? ' ' + t('status_active', 'Actif') : ' ' + t('status_inactive', 'Inactif'); + + const totalPages = Math.max(1, Math.ceil(clients.length / 10)); + if (clientsPage > totalPages) clientsPage = totalPages; if (clientsPage < 1) clientsPage = 1; + const pagedClients = clients.slice((clientsPage - 1) * 10, clientsPage * 10); + + $('clients').innerHTML = pagedClients.length ? pagedClients.map(c => { + const speedHtml = c.blocked + ? `● ${t('status_blocked', 'Bloqué')}` + : `↓ ${c.download_speed_str || formatSpeed(c.download_speed)}|↑ ${c.upload_speed_str || formatSpeed(c.upload_speed)}`; + const vpnHtml = c.vpn_routed + ? `🛡️ ${escapeHtml(c.vpn_profile_name)}${c.vpn_public_ip ? ` (${escapeHtml(c.vpn_public_ip)})` : ''}` + : (c.vpn_profile_name + ? (c.kill_switch + ? `🛡️ ${t('vpn_killswitch_chk', 'Kill-Switch')}` + : `⚠️ Direct`) + : `🌐 ${t('topo_direct_wan', 'Direct WAN (Box)')}`); + const ipLabel = c.ip || t('not_assigned', 'Non attribuée'); + const nameLabel = String(c.name || t('name_unknown', 'Nom non communiqué')).replace(/[&<>"']/g, ch => '' + ch.charCodeAt(0) + ';'); + return `