AP manageur V1.1 (Bêta)
This commit is contained in:
1 parent
a3c2cc93e8
commit
13d57a7b65
4 files changed
+44
-9
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ RUN apt-get update \
|
||||
&& apt full-upgrade -y && apt-get install -y --no-install-recommends \
|
||||
ca-certificates apache2 nano python3 python3-cryptography python3-dbus python3-paramiko tzdata \
|
||||
network-manager wpasupplicant hostapd dbus \
|
||||
iw iproute2 rfkill wireless-regdb \
|
||||
iw wireless-tools iproute2 rfkill wireless-regdb \
|
||||
dnsmasq-base iptables nftables procps kmod tcpdump \
|
||||
wireguard-tools openvpn ebtables curl conntrack rclone \
|
||||
&& a2enmod proxy proxy_http headers setenvif remoteip rewrite \
|
||||
|
||||
@@ -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()
|
||||
|
||||
+14
-1
@@ -205,6 +205,9 @@ managed=1
|
||||
[keyfile]
|
||||
unmanaged-devices=*;except:interface-name:${IFACE}
|
||||
|
||||
[connection]
|
||||
wifi.powersave=2
|
||||
|
||||
[device]
|
||||
wifi.scan-rand-mac-address=no
|
||||
|
||||
@@ -213,6 +216,13 @@ level=INFO
|
||||
domains=CORE,WIFI,IP4,DHCP4,DEVICE
|
||||
EOF
|
||||
|
||||
# Désactivation explicite de la veille Wi-Fi par défaut (écrase le réglage par défaut debian default-wifi-powersave-on.conf)
|
||||
mkdir -p /etc/NetworkManager/conf.d
|
||||
cat > /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf <<EOF
|
||||
[connection]
|
||||
wifi.powersave=2
|
||||
EOF
|
||||
|
||||
# Protection et vérification de la résolution DNS locale (/etc/resolv.conf)
|
||||
if [[ -f /etc/resolv.conf ]]; then
|
||||
if ! grep -Eq '^\s*nameserver\s+' /etc/resolv.conf 2>/dev/null; then
|
||||
@@ -310,7 +320,10 @@ sleep 1
|
||||
log "Domaine réglementaire : $(iw reg get 2>/dev/null | awk '/^country/{print $1,$2}' | tr '\n' ' ')"
|
||||
nmcli radio wifi on 2>/dev/null || true
|
||||
nmcli device set "$IFACE" managed yes 2>/dev/null || true
|
||||
log "NetworkManager opérationnel et configuré"
|
||||
# Désactivation active de la veille de la carte Wi-Fi (powersave off)
|
||||
iw dev "$IFACE" set power_save off 2>/dev/null || true
|
||||
command -v iwconfig >/dev/null 2>&1 && iwconfig "$IFACE" power off 2>/dev/null || true
|
||||
log "NetworkManager opérationnel et veille Wi-Fi désactivée sur $IFACE"
|
||||
|
||||
# 3. API Python (socket Unix, aucun port) + Apache (port AP_WEB_PORT) -----------
|
||||
log "Démarrage de l'API AP Manageur (Python)..."
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "V1.2 (Bêta)",
|
||||
"commit": "73f9bc2bcd7f357d7ad64bd53329df2ad522c884",
|
||||
"build_date": "2026-11-23T18:22:20Z"
|
||||
"commit": "a3c2cc93e861319933ba771792d8137d998d32bc",
|
||||
"build_date": "2026-11-23T19:17:26Z"
|
||||
}
|
||||
Reference in new issue
Block a user