55 lines
1.5 KiB
Bash
Executable File
55 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Konfiguration
|
|
LOG_FILE="/var/log/nm-captive.log"
|
|
|
|
# Log-Funktion
|
|
log() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
|
}
|
|
|
|
check_captive_portal() {
|
|
# Teste mit Google's Connectivity Check (sollte 204 zurückgeben)
|
|
local url="http://connectivitycheck.gstatic.com/generate_204"
|
|
local http_code=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "$url")
|
|
|
|
if [ $? -ne 0 ]; then
|
|
log "Network error - captive portal likely"
|
|
return 1
|
|
fi
|
|
|
|
if [ "$http_code" = "204" ]; then
|
|
log "Connectivity check passed (204) - no captive portal"
|
|
return 0
|
|
else
|
|
log "Connectivity check failed (HTTP $http_code) - captive portal detected"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
log "=== Dispatch triggered: $1 $2 ==="
|
|
|
|
if [[ "$1" == wl* ]] && [ "$2" = "up" ]; then
|
|
sleep 3
|
|
|
|
if ! check_captive_portal; then
|
|
log "CAPTIVE PORTAL DETECTED! Opening browser..."
|
|
|
|
# Finde Benutzer und starte Firefox
|
|
local_user=$(who | grep "(:0)" | awk '{print $1}' | head -n1)
|
|
if [ -n "$local_user" ]; then
|
|
export DISPLAY=:0
|
|
export XAUTHORITY=/home/$local_user/.Xauthority
|
|
|
|
# Starte Firefox im Hintergrund
|
|
sudo -u $local_user env DISPLAY=:0 XAUTHORITY=/home/$local_user/.Xauthority \
|
|
firefox --new-window "http://captive.apple.com" &
|
|
log "Firefox started for user $local_user"
|
|
fi
|
|
else
|
|
log "No captive portal detected"
|
|
fi
|
|
fi
|
|
|
|
log "=== Completed ==="
|