AP manageur V1.1 (Bêta)
This commit is contained in:
1 parent
04c0a0c249
commit
ac34edf4c7
3 files changed
+90
-14
No files matched your search
@@ -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()
|
||||
|
||||
+26
-4
@@ -418,13 +418,35 @@ cleanup() {
|
||||
for _i in 1 2 3; do ip -4 rule del table "$tid" 2>/dev/null || break; done
|
||||
for _i in 1 2 3; do ip -6 rule del table "$tid" 2>/dev/null || break; done
|
||||
done
|
||||
# Arrêt propre de hostapd (mode pont) et détachement de l'interface Wi-Fi sans toucher au pont hôte
|
||||
# Arrêt complet et extinction du réseau Wi-Fi (AP/NAT et pont)
|
||||
log "Extinction du réseau Wi-Fi et déconnexion des clients..."
|
||||
if command -v nmcli >/dev/null 2>&1; then
|
||||
[[ -n "${IFACE:-}" ]] && nmcli device disconnect "$IFACE" 2>/dev/null || true
|
||||
for _con in $(nmcli -t -g NAME,DEVICE connection show --active 2>/dev/null | grep ":${IFACE:-}\$" | cut -d: -f1); do
|
||||
nmcli connection down "$_con" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
if [[ -f /run/ap-hostapd.pid ]]; then
|
||||
kill "$(cat /run/ap-hostapd.pid 2>/dev/null || true)" 2>/dev/null || true
|
||||
kill -15 "$(cat /run/ap-hostapd.pid 2>/dev/null || true)" 2>/dev/null || true
|
||||
sleep 0.1
|
||||
kill -9 "$(cat /run/ap-hostapd.pid 2>/dev/null || true)" 2>/dev/null || true
|
||||
rm -f /run/ap-hostapd.pid /run/ap-hostapd.conf 2>/dev/null || true
|
||||
fi
|
||||
pkill -f '/run/ap-hostapd.conf' 2>/dev/null || true
|
||||
[[ -n "${IFACE:-}" ]] && ip link set "$IFACE" nomaster 2>/dev/null || true
|
||||
pkill -9 hostapd 2>/dev/null || true
|
||||
pkill -9 -f 'ap-hostapd' 2>/dev/null || true
|
||||
rm -rf /run/hostapd 2>/dev/null || true
|
||||
if [[ -n "${IFACE:-}" ]]; then
|
||||
if command -v iw >/dev/null 2>&1; then
|
||||
for _sta in $(iw dev "$IFACE" station dump 2>/dev/null | awk '$1=="Station"{print $2}'); do
|
||||
iw dev "$IFACE" station del "$_sta" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
ip link set "$IFACE" nomaster 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
|
||||
# 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
|
||||
# Restauration uniquement d'un pont créé par APmanageur (/run/ap-created-bridge)
|
||||
|
||||
+23
-6
@@ -6634,7 +6634,7 @@
|
||||
style="background:var(--panel);padding:10px 12px;border-radius:8px;border:1px solid var(--line);margin-top:2px">
|
||||
<div style="display:flex;justify-content:space-between;font-size:12px;margin-bottom:6px">
|
||||
<span class="muted" data-i18n="modal_current_usage">Consommation actuelle :</span>
|
||||
<strong id="quotaUsageLabel">0 o / 10 Go (0%)</strong>
|
||||
<strong id="quotaUsageLabel">—</strong>
|
||||
</div>
|
||||
<div style="background:var(--line);height:8px;border-radius:4px;overflow:hidden">
|
||||
<div id="quotaUsageBar"
|
||||
@@ -10563,6 +10563,17 @@ ${vpnBadgeTopo}
|
||||
const remaining = Math.max(0, quotaBytes - usageBytes);
|
||||
const exceeded = (quotaBytes > 0 && usageBytes >= quotaBytes);
|
||||
|
||||
const quotaStr = quotaBytes > 0 ? formatBytes(quotaBytes) : t('modal_quota_unlimited', 'Illimité');
|
||||
if ($('quotaUsageLabel')) {
|
||||
$('quotaUsageLabel').textContent = quotaBytes > 0
|
||||
? `${usageStr} / ${quotaStr} (${pct}%)`
|
||||
: `${usageStr} (${t('modal_quota_unlimited', 'Illimité')})`;
|
||||
}
|
||||
|
||||
if ($('quotaExceededBadge')) {
|
||||
$('quotaExceededBadge').style.display = exceeded ? 'inline-flex' : 'none';
|
||||
}
|
||||
|
||||
if ($('quotaUsageBar')) {
|
||||
$('quotaUsageBar').style.width = `${pct}%`;
|
||||
$('quotaUsageBar').style.background = exceeded ? 'var(--red)' : (pct >= 85 ? '#f59e0b' : 'var(--blue)');
|
||||
@@ -10598,7 +10609,13 @@ ${vpnBadgeTopo}
|
||||
const d = await res.json();
|
||||
if (!res.ok) throw new Error(d.error || 'Erreur lors de la réinitialisation');
|
||||
|
||||
if (d.limits) currentLimitsDev.limits = d.limits;
|
||||
if (d.limits) {
|
||||
currentLimitsDev.limits = d.limits;
|
||||
} else if (currentLimitsDev.limits) {
|
||||
currentLimitsDev.limits.usage_bytes = 0;
|
||||
currentLimitsDev.limits.usage_bytes_str = '0 o';
|
||||
currentLimitsDev.limits.quota_exceeded = false;
|
||||
}
|
||||
updateQuotaPreview();
|
||||
const msg = $('deviceLimitsMsg');
|
||||
if (msg) {
|
||||
@@ -11580,10 +11597,10 @@ ${vpnBadgeTopo}
|
||||
const uT = isEn ? ' TB' : ' To';
|
||||
if (b === null || b === undefined || b <= 0) return '0' + uB;
|
||||
if (b < 1024) return Math.round(b) + uB;
|
||||
if (b < 1048576) return (b / 1024).toFixed(1) + uK;
|
||||
if (b < 1073741824) return (b / 1048576).toFixed(1) + uM;
|
||||
if (b < 1099511627776) return (b / 1073741824).toFixed(2) + uG;
|
||||
return (b / 1099511627776).toFixed(2) + uT;
|
||||
if (b < 1048576) return parseFloat((b / 1024).toFixed(1)) + uK;
|
||||
if (b < 1073741824) return parseFloat((b / 1048576).toFixed(1)) + uM;
|
||||
if (b < 1099511627776) return parseFloat((b / 1073741824).toFixed(2)) + uG;
|
||||
return parseFloat((b / 1099511627776).toFixed(2)) + uT;
|
||||
}
|
||||
|
||||
function renderTopClientsTable(topClients) {
|
||||
|
||||
Reference in new issue
Block a user