AP manageur V1.1 (Bêta)

This commit is contained in:
yoannmultigaming committed 2026-11-26 02:37:38 +01:00
1 parent 04c0a0c249
commit ac34edf4c7
3 files changed
+90 -14

No files matched your search

+41 -4
View File
@@ -58,6 +58,10 @@ def remove_uptime_file():
atexit.register(remove_uptime_file)
def _sig_handler(signum, frame):
try:
if 'shutdown_wifi' in globals():
shutdown_wifi()
except Exception: pass
try:
if 'disconnect_all_vpn_profiles' in globals():
disconnect_all_vpn_profiles('SIGTERM')
@@ -2045,10 +2049,10 @@ def format_speed(bps):
def format_bytes(b):
if not b or b <= 0: return "0 o"
if b < 1024: return f"{int(b)} o"
if b < 1048576: return f"{b/1024:.1f} Ko"
if b < 1073741824: return f"{b/1048576:.2f} Mo"
if b < 1099511627776: return f"{b/1073741824:.2f} Go"
return f"{b/1099511627776:.2f} To"
if b < 1048576: return f"{b/1024:.1f}".rstrip('0').rstrip('.') + " Ko"
if b < 1073741824: return f"{b/1048576:.2f}".rstrip('0').rstrip('.') + " Mo"
if b < 1099511627776: return f"{b/1073741824:.2f}".rstrip('0').rstrip('.') + " Go"
return f"{b/1099511627776:.2f}".rstrip('0').rstrip('.') + " To"
def get_top_clients(active_items=None, range_type='day'):
active_map = {}
@@ -4167,6 +4171,39 @@ def stop_hostapd(iface=None):
except OSError: pass
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'nomaster'], capture_output=True, timeout=2)
def shutdown_wifi(iface=None):
"""Coupe complètement le réseau Wi-Fi lors de l'arrêt du conteneur (hostapd, NM, et interface down)."""
wifi_if = iface or INTERFACE or detect_wifi_interface()
try:
stop_hostapd(wifi_if)
except Exception: pass
try:
nmcli_bin = find_bin('nmcli')
if nmcli_bin and wifi_if:
try:
name = connection_name()
if name:
subprocess.run([nmcli_bin, 'connection', 'down', name], capture_output=True, timeout=2)
except Exception: pass
subprocess.run([nmcli_bin, 'device', 'disconnect', wifi_if], capture_output=True, timeout=2)
except Exception: pass
try:
if wifi_if:
iw_bin = find_bin('iw')
if iw_bin:
try:
dump = command('iw', 'dev', wifi_if, 'station', 'dump')
for m in re.finditer(r'^Station ([0-9a-f:]{17})', dump, re.I | re.M):
subprocess.run([iw_bin, 'dev', wifi_if, 'station', 'del', m.group(1)], capture_output=True, timeout=1)
except Exception: pass
subprocess.run(['ip', 'link', 'set', 'dev', wifi_if, 'nomaster'], capture_output=True, timeout=2)
subprocess.run(['ip', 'link', 'set', 'dev', wifi_if, 'down'], capture_output=True, timeout=2)
if iw_bin:
subprocess.run([iw_bin, 'dev', wifi_if, 'set', 'type', 'managed'], capture_output=True, timeout=2)
except Exception: pass
atexit.register(shutdown_wifi)
def ensure_nm_manages_wifi(iface=None, force=False):
"""Rend le contrôle de l'interface Wi-Fi à NetworkManager (pour le mode AP/NAT) et attend qu'elle soit prête."""
iface = iface or get_wifi_interface()