APmanageur Wi-Fi V1.0

This commit is contained in:
yoannmultigaming committed 2026-11-22 22:53:10 +01:00
1 parent 2effae81b2
commit 4ab701ee58
3 files changed
+201 -3

No files matched your search

+1 -1
View File
@@ -12089,7 +12089,7 @@ class Handler(BaseHTTPRequestHandler):
for v_path in ('/data/version.json', os.path.join(BASE_DIR, 'version.json'), 'version.json'): for v_path in ('/data/version.json', os.path.join(BASE_DIR, 'version.json'), 'version.json'):
try: try:
with open(v_path, 'w', encoding='utf-8') as f: 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: except Exception:
pass pass
with _update_lock: with _update_lock:
+198
View File
@@ -9393,6 +9393,204 @@ ${vpnBadgeTopo}
if ($('nav')) $('nav').style.display = configured ? 'flex' : 'none'; if ($('nav')) $('nav').style.display = configured ? 'flex' : 'none';
if ($('dashboardTab')) $('dashboardTab').style.display = configured ? '' : 'none'; if ($('dashboardTab')) $('dashboardTab').style.display = configured ? '' : 'none';
if ($('statsTab')) $('statsTab').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 => `<option value="${e}">${e}</option>`).join('') : '<option value="">Auto-détection</option>';
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 ? '<i class="dot"></i> ' + t('status_active', 'Actif') : '<i class="dot" style="background:var(--red)"></i> ' + 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
? `<span class="signal-faible">● ${t('status_blocked', 'Bloqué')}</span>`
: `<span style="font-family:monospace;font-size:13px;white-space:nowrap"><span style="color:var(--blue);font-weight:700" title="Débit descendant">↓ ${c.download_speed_str || formatSpeed(c.download_speed)}</span><span style="color:var(--muted);margin:0 5px">|</span><span style="color:var(--green);font-weight:700" title="Débit montant">↑ ${c.upload_speed_str || formatSpeed(c.upload_speed)}</span></span>`;
const vpnHtml = c.vpn_routed
? `<span class="pill pill-green" style="font-size:11px;font-weight:600;display:inline-flex;align-items:center;gap:4px" title="Trafic chiffré via ${escapeHtml(c.vpn_profile_name)}">🛡️ ${escapeHtml(c.vpn_profile_name)}${c.vpn_public_ip ? ` <span style="font-family:monospace;font-size:10px;opacity:.9">(${escapeHtml(c.vpn_public_ip)})</span>` : ''}</span>`
: (c.vpn_profile_name
? (c.kill_switch
? `<span class="pill" style="background:rgba(255,107,107,.15);color:var(--red);font-size:11px;font-weight:600">🛡️ ${t('vpn_killswitch_chk', 'Kill-Switch')}</span>`
: `<span class="pill" style="background:rgba(246,173,85,.15);color:#f6ad55;font-size:11px">⚠️ Direct</span>`)
: `<span class="muted" style="font-size:12px;display:inline-flex;align-items:center;gap:4px">🌐 ${t('topo_direct_wan', 'Direct WAN (Box)')}</span>`);
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 `<tr><td><div class="client"><div class="avatar">${String(c.name || '?')[0].toUpperCase()}</div><strong>${nameLabel}</strong></div></td><td>${ipLabel}</td><td>${c.mac || '—'}</td><td>${vpnHtml}</td><td>${signalQuality(c.signal_dbm, c)}</td><td>${speedHtml}</td></tr>`;
}).join('') : `<tr><td colspan="6" class="empty">${t('no_clients', 'Aucun client connecté')}</td></tr>`;
renderPagination('clientsPagination', clientsPage, clients.length, 'changeClientsPage', 10);
qr();
}
window.changeClientsPage = (p) => { clientsPage = p; render(); };
let isLoadInProgress = false;
let loadFailureCount = 0;
async function load() {
if (isLoadInProgress) return;
isLoadInProgress = true;
try {
let [a, b] = await Promise.all([apiFetch('/api/status', { cache: 'no-store', timeout: 10000 }), apiFetch('/api/clients', { cache: 'no-store', timeout: 10000 })]);
if (!a.ok || !b.ok) {
const response = !a.ok ? a : b; let detail = 'HTTP ' + response.status;
try { const body = await response.json(); detail = body.error || detail; } catch (_) { }
throw Error(detail);
}
const nextStatus = await a.json(); const nextClients = await b.json();
const signature = nextClients.map(client => client.mac).sort().join('|'); const signature = nextClients.map(client => client.mac).sort().join('|');
const changed = previousClientSignature !== null && signature !== previousClientSignature; const changed = previousClientSignature !== null && signature !== previousClientSignature;
status = nextStatus; clients = nextClients; previousClientSignature = signature; status = nextStatus; clients = nextClients; previousClientSignature = signature;
+2 -2
View File
@@ -1,5 +1,5 @@
{ {
"version": "V1.1 (Béta)", "version": "V1.1 (Béta)",
"commit": "6f353a5ff5725279cc59812972ee5a34f15f1013", "commit": "2effae81b20306eaa2f9bfa3e1d54c3243c64161",
"build_date": "2026-11-22T21:30:00Z" "build_date": "2026-11-22T21:30:36Z"
} }