diff --git a/ap.py b/ap.py index 2a02e64..133d8cd 100644 --- a/ap.py +++ b/ap.py @@ -7418,6 +7418,9 @@ def get_wifi_interface(): def start_capture(target_iface=None): global capture_running, capture_thread, capture_pcap_bytes, capture_iface_used, capture_started_at + st = status() + if not st.get('active'): + return False, "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames" with capture_lock: if capture_running: return True, f"Capture déjà en cours sur {capture_iface_used}" @@ -10667,9 +10670,6 @@ def _delete_s3(cfg, remote_filename): req.add_header('Authorization', auth_hdr) ctx = ssl.create_default_context() try: - with urllib.request.urlopen(req, context=ctx, timeout=30) as resp: - return True, f"Fichier {remote_filename} supprimé sur S3" - except Exception as e: return False, f"Erreur suppression S3 : {e}" def delete_remote_file(remote_filename, custom_cfg=None): @@ -13153,6 +13153,7 @@ class Handler(BaseHTTPRequestHandler): start_bridge_hostapd(db_ssid, db_pass, sec=db_sec, bridge_name=b_name, iface=wifi_if) mark_ap_started() elif action == 'stop': + stop_capture() stop_hostapd(wifi_if) teardown_bridge_dns_redirection(b_name, wifi_if) try: os.remove(UPTIME_FILE) @@ -13187,6 +13188,7 @@ class Handler(BaseHTTPRequestHandler): setup_ap_nat(wifi_if) mark_ap_started() elif action == 'stop': + stop_capture() if name: r = subprocess.run(['nmcli', 'connection', 'down', name], capture_output=True, text=True, timeout=5) if r.returncode and 'not an active connection' not in r.stderr.lower(): diff --git a/index.html b/index.html index c804bd8..e02188c 100644 --- a/index.html +++ b/index.html @@ -9803,6 +9803,16 @@ ${vpnBadgeTopo} if ($('btnUpdateAvailable')) { $('btnUpdateAvailable').style.display = (configured && updateAvailable) ? 'inline-flex' : 'none'; } + + if ($('startCaptureBtn')) { + const isWifiActive = !!(status && status.active); + if (!captureRunning) { + $('startCaptureBtn').disabled = !isWifiActive; + $('startCaptureBtn').style.opacity = isWifiActive ? '' : '0.45'; + $('startCaptureBtn').style.cursor = isWifiActive ? 'pointer' : 'not-allowed'; + $('startCaptureBtn').title = isWifiActive ? '' : t('adv_pcap_wifi_required', "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames"); + } + } } let lastUpdateData = null; @@ -11934,8 +11944,19 @@ ${vpnBadgeTopo} $('captureBufferSize').textContent = (capturePackets.length || buf) + ' ' + keptWord; $('capturePcapSize').textContent = formatBytes(pcapSz); if ($('captureDomainsCount')) $('captureDomainsCount').textContent = d.unique_domains_count !== undefined ? d.unique_domains_count : (d.domains ? d.domains.length : 0); - $('startCaptureBtn').style.display = captureRunning ? 'none' : ''; - $('stopCaptureBtn').style.display = captureRunning ? 'inline-flex' : 'none'; + const isWifiActive = !!(status && status.active); + const startBtn = $('startCaptureBtn'); + const stopBtn = $('stopCaptureBtn'); + if (startBtn) { + startBtn.style.display = captureRunning ? 'none' : ''; + startBtn.disabled = !isWifiActive; + startBtn.style.opacity = isWifiActive ? '' : '0.45'; + startBtn.style.cursor = isWifiActive ? 'pointer' : 'not-allowed'; + startBtn.title = isWifiActive ? '' : t('adv_pcap_wifi_required', "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames"); + } + if (stopBtn) { + stopBtn.style.display = captureRunning ? 'inline-flex' : 'none'; + } if ($('statDns')) $('statDns').textContent = captureStats.dns || 0; if ($('statIcmp')) $('statIcmp').textContent = captureStats.icmp || 0; if ($('statTcp')) $('statTcp').textContent = captureStats.tcp || 0; @@ -12295,11 +12316,28 @@ ${vpnBadgeTopo} $('statsRangeYear').onclick = () => setStatsRange('year'); $('startCaptureBtn').onclick = () => runAction(async () => { + if (!status || !status.active) { + alert(t('adv_pcap_wifi_required', "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames")); + return; + } captureStartTime = Date.now() / 1000; captureRunning = true; ensureCaptureTimer(); updateCaptureTimerDisplay(); - await apiFetch('/api/advanced/capture/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }); + try { + const res = await apiFetch('/api/advanced/capture/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }); + const data = await res.json(); + if (!res.ok || (data && !data.ok)) { + throw Error((data && data.message) || t('adv_pcap_wifi_required', "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames")); + } + } catch (err) { + captureRunning = false; + captureStartTime = null; + stopCaptureTimer(); + alert(tErr(err.message)); + await loadCaptureStatus(); + return; + } await loadCaptureStatus(); await loadCapturePackets(true); ensureCapturePolling(); diff --git a/lang/en-gb.js b/lang/en-gb.js index c6d64a4..22990e8 100644 --- a/lang/en-gb.js +++ b/lang/en-gb.js @@ -1462,5 +1462,6 @@ window.I18N['en-gb'] = { "confirm_restart_ap": "Are you sure you want to restart the Wi-Fi access point?\n\nAll connected devices will be temporarily disconnected.\nThis operation may take several minutes.", "confirm_save_settings_restart": "Modifying Wi-Fi settings will restart the access point.\n\nAll connected devices will be temporarily disconnected.\nThis operation may take several minutes.\n\nDo you want to continue?", "settings_restarting_warning": "Restarting: this operation may take several minutes…", - "settings_saved_restarted": "Settings saved and access point restarted successfully!" + "settings_saved_restarted": "Settings saved and access point restarted successfully!", + "adv_pcap_wifi_required": "Wi-Fi is turned off: start the access point to launch packet analysis" }; diff --git a/lang/en-us.js b/lang/en-us.js index 08198b9..82af408 100644 --- a/lang/en-us.js +++ b/lang/en-us.js @@ -1462,5 +1462,6 @@ window.I18N['en-us'] = { "confirm_restart_ap": "Are you sure you want to restart the Wi-Fi access point?\n\nAll connected devices will be temporarily disconnected.\nThis operation may take several minutes.", "confirm_save_settings_restart": "Modifying Wi-Fi settings will restart the access point.\n\nAll connected devices will be temporarily disconnected.\nThis operation may take several minutes.\n\nDo you want to continue?", "settings_restarting_warning": "Restarting: this operation may take several minutes…", - "settings_saved_restarted": "Settings saved and access point restarted successfully!" + "settings_saved_restarted": "Settings saved and access point restarted successfully!", + "adv_pcap_wifi_required": "Wi-Fi is turned off: start the access point to launch packet analysis" }; diff --git a/lang/fr.js b/lang/fr.js index ea99c34..f0a2ad7 100644 --- a/lang/fr.js +++ b/lang/fr.js @@ -1462,5 +1462,6 @@ window.I18N['fr'] = { "confirm_restart_ap": "Êtes-vous sûr de vouloir redémarrer le point d’accès Wi-Fi ?\n\nTous les appareils connectés seront temporairement déconnectés.\nCette opération peut prendre plusieurs minutes.", "confirm_save_settings_restart": "La modification des réglages Wi-Fi va redémarrer le point d’accès.\n\nTous les appareils connectés seront temporairement déconnectés.\nCette opération peut durer plusieurs minutes.\n\nSouhaitez-vous continuer ?", "settings_restarting_warning": "Redémarrage : cette opération peut durer plusieurs minutes…", - "settings_saved_restarted": "Réglages enregistrés et point d’accès redémarré avec succès !" + "settings_saved_restarted": "Réglages enregistrés et point d’accès redémarré avec succès !", + "adv_pcap_wifi_required": "Le Wi-Fi est coupé : démarrez le point d’accès pour lancer l’analyse des trames" };