AP manageur V1.1 (Bêta)
This commit is contained in:
1 parent
ac34edf4c7
commit
92d8cf9bd2
3 files changed
+24
-12
No files matched your search
@@ -4198,8 +4198,6 @@ def shutdown_wifi(iface=None):
|
|||||||
except Exception: pass
|
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, 'nomaster'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', wifi_if, 'down'], 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
|
except Exception: pass
|
||||||
|
|
||||||
atexit.register(shutdown_wifi)
|
atexit.register(shutdown_wifi)
|
||||||
@@ -4220,10 +4218,12 @@ def ensure_nm_manages_wifi(iface=None, force=False):
|
|||||||
|
|
||||||
stop_hostapd(iface)
|
stop_hostapd(iface)
|
||||||
ensure_wpa_supplicant_running()
|
ensure_wpa_supplicant_running()
|
||||||
|
try:
|
||||||
subprocess.run(['rfkill', 'unblock', 'wifi'], capture_output=True, timeout=2)
|
subprocess.run(['rfkill', 'unblock', 'wifi'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'nomaster'], capture_output=True, timeout=2)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'nomaster'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['nmcli', 'device', 'set', iface, 'managed', 'yes'], capture_output=True, timeout=2)
|
subprocess.run(['nmcli', 'device', 'set', iface, 'managed', 'yes'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['nmcli', 'radio', 'wifi', 'on'], capture_output=True, timeout=2)
|
subprocess.run(['nmcli', 'radio', 'wifi', 'on'], capture_output=True, timeout=2)
|
||||||
|
except Exception: pass
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
st = command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1)
|
st = command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1)
|
||||||
if st and not st.startswith('10'):
|
if st and not st.startswith('10'):
|
||||||
@@ -4244,32 +4244,36 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
|
|||||||
stop_hostapd(iface)
|
stop_hostapd(iface)
|
||||||
was_managed = not (command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1) or '').startswith('10')
|
was_managed = not (command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1) or '').startswith('10')
|
||||||
if was_managed:
|
if was_managed:
|
||||||
|
try:
|
||||||
subprocess.run(['nmcli', '--wait', '2', 'device', 'disconnect', iface], capture_output=True, timeout=2)
|
subprocess.run(['nmcli', '--wait', '2', 'device', 'disconnect', iface], capture_output=True, timeout=2)
|
||||||
subprocess.run(['nmcli', 'device', 'set', iface, 'managed', 'no'], capture_output=True, timeout=2)
|
subprocess.run(['nmcli', 'device', 'set', iface, 'managed', 'no'], capture_output=True, timeout=2)
|
||||||
|
except Exception: pass
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
st = command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1)
|
st = command('nmcli', '-t', '-g', 'GENERAL.STATE', 'device', 'show', iface, timeout=1)
|
||||||
if not st or st.startswith('10'): # 10 = unmanaged
|
if not st or st.startswith('10'): # 10 = unmanaged
|
||||||
break
|
break
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
# Arrêter wpa_supplicant afin qu'il ne bloque jamais les trames EAPOL de hostapd
|
# Arrêter wpa_supplicant afin qu'il ne bloque jamais les trames EAPOL de hostapd
|
||||||
|
try:
|
||||||
subprocess.run(['pkill', '-x', 'wpa_supplicant'], capture_output=True, timeout=2)
|
subprocess.run(['pkill', '-x', 'wpa_supplicant'], capture_output=True, timeout=2)
|
||||||
|
except Exception: pass
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
if subprocess.run(['pgrep', '-x', 'wpa_supplicant'], capture_output=True, timeout=1).returncode != 0:
|
if subprocess.run(['pgrep', '-x', 'wpa_supplicant'], capture_output=True, timeout=1).returncode != 0:
|
||||||
break
|
break
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
country = os.environ.get('AP_COUNTRY', 'FR').strip().upper() or 'FR'
|
country = os.environ.get('AP_COUNTRY', 'FR').strip().upper() or 'FR'
|
||||||
|
try:
|
||||||
subprocess.run(['rfkill', 'unblock', 'wifi'], capture_output=True, timeout=2)
|
subprocess.run(['rfkill', 'unblock', 'wifi'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['iw', 'reg', 'set', country], capture_output=True, timeout=2)
|
subprocess.run(['iw', 'reg', 'set', country], capture_output=True, timeout=2)
|
||||||
# Cycle rapide DOWN -> managed -> UP -> DOWN pour vider l'ancien BSS/table de clés du firmware
|
except Exception: pass
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'down'], capture_output=True, timeout=2)
|
|
||||||
subprocess.run(['ip', 'addr', 'flush', 'dev', iface], capture_output=True, timeout=2)
|
# Libération et préparation propre de l'interface pour hostapd
|
||||||
|
try:
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'nomaster'], capture_output=True, timeout=2)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'nomaster'], capture_output=True, timeout=2)
|
||||||
subprocess.run(['iw', 'dev', iface, 'set', 'type', 'managed'], capture_output=True, timeout=2)
|
subprocess.run(['ip', 'addr', 'flush', 'dev', iface], capture_output=True, timeout=2)
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'up'], capture_output=True, timeout=2)
|
|
||||||
time.sleep(0.1)
|
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'down'], capture_output=True, timeout=2)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'down'], capture_output=True, timeout=2)
|
||||||
time.sleep(0.1)
|
except Exception: pass
|
||||||
|
|
||||||
band = (AP_BAND or 'bg').strip().lower()
|
band = (AP_BAND or 'bg').strip().lower()
|
||||||
hw_mode = 'a' if band == 'a' else 'g'
|
hw_mode = 'a' if band == 'a' else 'g'
|
||||||
@@ -4338,6 +4342,7 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
|
|||||||
os.remove(ctrl_sock)
|
os.remove(ctrl_sock)
|
||||||
except OSError: pass
|
except OSError: pass
|
||||||
|
|
||||||
|
try:
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
[hostapd_bin, '-B', '-P', HOSTAPD_PID_FILE, '-f', HOSTAPD_LOG_FILE, HOSTAPD_CONF_FILE],
|
[hostapd_bin, '-B', '-P', HOSTAPD_PID_FILE, '-f', HOSTAPD_LOG_FILE, HOSTAPD_CONF_FILE],
|
||||||
capture_output=True, text=True, timeout=5
|
capture_output=True, text=True, timeout=5
|
||||||
@@ -4353,6 +4358,8 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return False, err or 'hostapd a refusé de démarrer'
|
return False, err or 'hostapd a refusé de démarrer'
|
||||||
|
except Exception as e:
|
||||||
|
return False, f"Impossible d'exécuter hostapd: {e}"
|
||||||
|
|
||||||
for i_attempt in range(20):
|
for i_attempt in range(20):
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@@ -4367,14 +4374,18 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
|
|||||||
has_master = os.path.exists(f'/sys/class/net/{iface}/master')
|
has_master = os.path.exists(f'/sys/class/net/{iface}/master')
|
||||||
if 'AP-ENABLED' in log_txt:
|
if 'AP-ENABLED' in log_txt:
|
||||||
if not has_master:
|
if not has_master:
|
||||||
|
try:
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
||||||
|
except Exception: pass
|
||||||
disable_wifi_powersave(iface)
|
disable_wifi_powersave(iface)
|
||||||
return True, ''
|
return True, ''
|
||||||
if i_attempt % 3 == 0:
|
if i_attempt % 3 == 0:
|
||||||
iw_out = command('iw', 'dev', iface, 'info', timeout=0.8) or ''
|
iw_out = command('iw', 'dev', iface, 'info', timeout=0.8) or ''
|
||||||
if 'type AP' in iw_out:
|
if 'type AP' in iw_out:
|
||||||
if not has_master:
|
if not has_master:
|
||||||
|
try:
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
||||||
|
except Exception: pass
|
||||||
disable_wifi_powersave(iface)
|
disable_wifi_powersave(iface)
|
||||||
return True, ''
|
return True, ''
|
||||||
|
|
||||||
@@ -4382,7 +4393,9 @@ def start_bridge_hostapd(ssid, password, sec='wpa2', bridge_name='br0', iface=No
|
|||||||
iw_out = command('iw', 'dev', iface, 'info', timeout=0.8) or ''
|
iw_out = command('iw', 'dev', iface, 'info', timeout=0.8) or ''
|
||||||
if 'type AP' in iw_out:
|
if 'type AP' in iw_out:
|
||||||
if not os.path.exists(f'/sys/class/net/{iface}/master'):
|
if not os.path.exists(f'/sys/class/net/{iface}/master'):
|
||||||
|
try:
|
||||||
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
subprocess.run(['ip', 'link', 'set', 'dev', iface, 'master', bridge_name], capture_output=True, timeout=1)
|
||||||
|
except Exception: pass
|
||||||
disable_wifi_powersave(iface)
|
disable_wifi_powersave(iface)
|
||||||
return True, ''
|
return True, ''
|
||||||
return False, 'hostapd démarré mais interface non passée en mode AP'
|
return False, 'hostapd démarré mais interface non passée en mode AP'
|
||||||
|
|||||||
@@ -443,9 +443,6 @@ cleanup() {
|
|||||||
fi
|
fi
|
||||||
ip link set "$IFACE" nomaster 2>/dev/null || true
|
ip link set "$IFACE" nomaster 2>/dev/null || true
|
||||||
ip link set "$IFACE" down 2>/dev/null || true
|
ip link set "$IFACE" down 2>/dev/null || true
|
||||||
if command -v iw >/dev/null 2>&1; then
|
|
||||||
iw dev "$IFACE" set type managed 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# Suppression du fichier d'uptime lors de l'arrêt du conteneur
|
# Suppression du fichier d'uptime lors de l'arrêt du conteneur
|
||||||
rm -f "${AP_UPTIME_FILE:-/data/uptime}" /app/ap-dashboard-uptime 2>/dev/null || true
|
rm -f "${AP_UPTIME_FILE:-/data/uptime}" /app/ap-dashboard-uptime 2>/dev/null || true
|
||||||
|
|||||||
@@ -6617,6 +6617,8 @@
|
|||||||
<!-- Raccourcis de quotas -->
|
<!-- Raccourcis de quotas -->
|
||||||
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
|
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
|
||||||
<span class="muted" style="font-size:11px" data-i18n="modal_presets">Préréglages :</span>
|
<span class="muted" style="font-size:11px" data-i18n="modal_presets">Préréglages :</span>
|
||||||
|
<button type="button" class="secondary" style="padding:2px 7px;font-size:11px;border-radius:6px"
|
||||||
|
onclick="setQuotaPreset(500, 'MB')">500 Mo</button>
|
||||||
<button type="button" class="secondary" style="padding:2px 7px;font-size:11px;border-radius:6px"
|
<button type="button" class="secondary" style="padding:2px 7px;font-size:11px;border-radius:6px"
|
||||||
onclick="setQuotaPreset(1, 'GB')" data-i18n="modal_quota_preset_1">1 Go</button>
|
onclick="setQuotaPreset(1, 'GB')" data-i18n="modal_quota_preset_1">1 Go</button>
|
||||||
<button type="button" class="secondary" style="padding:2px 7px;font-size:11px;border-radius:6px"
|
<button type="button" class="secondary" style="padding:2px 7px;font-size:11px;border-radius:6px"
|
||||||
|
|||||||
Reference in new issue
Block a user