AP manageur V1.1 (Bêta)

This commit is contained in:
yoannmultigaming committed 2026-11-23 20:40:55 +01:00
1 parent a3c2cc93e8
commit 13d57a7b65
4 files changed
+44 -9

No files matched your search

+27 -5
View File
@@ -3,7 +3,7 @@
# VERSION DU LOGICIEL AP MANAGEUR
# Modifiez cette variable pour changer la version dans toute l'application :
# ==============================================================================
APP_VERSION = 'V1.2 (Bêta)'
APP_VERSION = 'V1.1 (Bêta)'
# ==============================================================================
import base64, copy, hashlib, hmac, json, os, re, secrets, socket, sqlite3, subprocess, threading, time, urllib.parse, urllib.request, urllib.error, socketserver, shutil, datetime, atexit, signal, struct, smtplib, ssl, ipaddress, queue, http.client, io, zipfile, tempfile
@@ -2387,8 +2387,19 @@ def save_connection(name):
try: open(CONNECTION_FILE, 'w', encoding='utf8').write(name)
except OSError: pass
def disable_wifi_powersave(iface=None):
"""Désactive activement la veille (power management / powersave) de la carte Wi-Fi pour éviter les latences et déconnexions."""
target_iface = iface or INTERFACE
if not target_iface:
return
try:
subprocess.run(['iw', 'dev', target_iface, 'set', 'power_save', 'off'], capture_output=True, timeout=3)
subprocess.run(['iwconfig', target_iface, 'power', 'off'], capture_output=True, timeout=3)
except Exception:
pass
def apply_radio_defaults():
"""Applique bande/canal/CCMP à la connexion AP déjà créée (sans avoir à ré-enregistrer les réglages)."""
"""Applique bande/canal/CCMP/powersave à la connexion AP déjà créée (sans avoir à ré-enregistrer les réglages)."""
if is_bridge_mode(): return
name = connection_name()
if not name: return
@@ -2396,13 +2407,17 @@ def apply_radio_defaults():
band = command('nmcli','-t','-g','802-11-wireless.band','connection','show',name)
chan = command('nmcli','-t','-g','802-11-wireless.channel','connection','show',name)
key = command('nmcli','-t','-g','802-11-wireless-security.key-mgmt','connection','show',name)
if band == AP_BAND and chan == str(eff_channel): return
args = ['nmcli','connection','modify',name,'802-11-wireless.band',AP_BAND,'802-11-wireless.channel',str(eff_channel)]
psave = command('nmcli','-t','-g','802-11-wireless.powersave','connection','show',name)
if band == AP_BAND and chan == str(eff_channel) and psave == '2':
disable_wifi_powersave()
return
args = ['nmcli','connection','modify',name,'802-11-wireless.band',AP_BAND,'802-11-wireless.channel',str(eff_channel),'802-11-wireless.powersave','2']
if key in ('wpa-psk','sae'): args += ['802-11-wireless-security.pairwise','ccmp','802-11-wireless-security.group','ccmp']
r = subprocess.run(args, text=True, capture_output=True)
print(f"[ap-api] Radio {name} : bande={AP_BAND} canal={eff_channel}{' (auto)' if is_auto_channel() else ''} -> {'OK' if not r.returncode else r.stderr.strip()}", flush=True)
print(f"[ap-api] Radio {name} : bande={AP_BAND} canal={eff_channel}{' (auto)' if is_auto_channel() else ''} powersave=2 -> {'OK' if not r.returncode else r.stderr.strip()}", flush=True)
if not r.returncode and command('nmcli','-t','-g','GENERAL.STATE','device','show',INTERFACE).startswith('100'):
subprocess.run(['nmcli','connection','up',name], text=True, capture_output=True)
disable_wifi_powersave()
def security(value):
values = {'wpa1':('wpa-psk','wpa','optional'), 'wpa2':('wpa-psk','rsn','optional'), 'wpa3':('sae',None,'required')}
@@ -4094,6 +4109,7 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
try: log_txt = open(HOSTAPD_LOG_FILE, encoding='utf-8', errors='replace').read()
except OSError: pass
if is_hostapd_running() and 'type AP' in iw_out and os.path.exists(f'/sys/class/net/{iface}/master') and 'AP-DISABLED' not in log_txt:
disable_wifi_powersave(iface)
return True, ''
return False, 'Interface AP instable après initialisation initiale'
if is_hostapd_running():
@@ -4101,6 +4117,7 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
if 'type AP' in iw_out:
if not os.path.exists(f'/sys/class/net/{iface}/master'):
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True)
disable_wifi_powersave(iface)
return True, ''
return False, 'hostapd démarré mais interface non passée en mode AP'
err = ''
@@ -6489,6 +6506,7 @@ def configure_ap(data, initial=False, caller_ip=None, start_now=True, silent=Fal
modify_args = [
'nmcli', 'connection', 'modify', name,
'802-11-wireless.mode', 'ap',
'802-11-wireless.powersave', '2',
'802-11-wireless-security.key-mgmt', key,
'802-11-wireless-security.psk', password,
'802-11-wireless-security.pmf', pmf,
@@ -6513,6 +6531,7 @@ def configure_ap(data, initial=False, caller_ip=None, start_now=True, silent=Fal
r = subprocess.run(['nmcli', 'connection', 'up', name], text=True, capture_output=True)
if r.returncode:
raise RuntimeError(r.stderr.strip() or 'Impossible de démarrer le point d’accès')
disable_wifi_powersave(INTERFACE)
setup_ap_nat(INTERFACE)
mark_ap_started()
else:
@@ -6634,6 +6653,7 @@ def restore_ap_from_db(force_start=False):
if r.returncode != 0:
print(f"[ap-api] Erreur démarrage automatique '{target_name}' : {r.stderr.strip()}", flush=True)
return False
disable_wifi_powersave(INTERFACE)
setup_ap_nat(INTERFACE)
mark_ap_started()
else:
@@ -12896,6 +12916,7 @@ class Handler(BaseHTTPRequestHandler):
subprocess.run(['nmcli', 'connection', 'down', name], capture_output=True, text=True)
r = subprocess.run(['nmcli', 'connection', 'up', name], capture_output=True, text=True)
if r.returncode: raise RuntimeError(r.stderr.strip())
disable_wifi_powersave(INTERFACE)
setup_ap_nat(INTERFACE)
mark_ap_started()
elif action == 'stop':
@@ -13369,6 +13390,7 @@ if __name__ == '__main__':
# Restaurer le profil Wi-Fi (SSID, mot de passe, sécurité, mode, démarrage automatique) depuis la BDD SQLite
restore_ap_from_db()
apply_radio_defaults()
disable_wifi_powersave()
try: sync_client_bandwidth_and_quotas(force=True)
except Exception: pass
threading.Thread(target=arp_listener, daemon=True).start()