2019-10-28 17:18:40 +02:00
|
|
|
#!/bin/sh
|
|
|
|
. /lib/functions/network.sh
|
|
|
|
|
2019-10-29 15:47:41 +02:00
|
|
|
p=$(uci get wifi-sentinel.@wifi-sentinel[0].packets)
|
|
|
|
if [ -z "$p" ]; then
|
|
|
|
PACKETS='3'
|
|
|
|
else
|
|
|
|
PACKETS="$p"
|
|
|
|
fi
|
|
|
|
|
|
|
|
p=$(uci get wifi-sentinel.@wifi-sentinel[0].interval)
|
|
|
|
if [ -z "$p" ]; then
|
|
|
|
INTERVAL='10'
|
|
|
|
else
|
|
|
|
INTERVAL="$p"
|
|
|
|
fi
|
|
|
|
|
|
|
|
p=$(uci get wifi-sentinel.@wifi-sentinel[0].network)
|
|
|
|
if [ -z "$p" ]; then
|
|
|
|
NETWORK='management'
|
|
|
|
else
|
|
|
|
NETWORK="$p"
|
|
|
|
fi
|
|
|
|
|
2019-10-28 17:18:40 +02:00
|
|
|
STATUS='unknown'
|
|
|
|
|
|
|
|
lightsoff()
|
|
|
|
{
|
|
|
|
if [ "$STATUS" != 'down' ]; then
|
|
|
|
/usr/bin/logger -t wifi-sentinel -p daemon.alert Shutting down wireless interfaces due to lack of connectivity to the gateway.
|
|
|
|
/sbin/wifi down
|
|
|
|
STATUS='down'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
lightson()
|
|
|
|
{
|
|
|
|
if [ "$STATUS" != 'up' ]; then
|
|
|
|
/usr/bin/logger -t wifi-sentinel -p daemon.notice Bringing up wireless interfaces. Gateway connectivity restored.
|
|
|
|
/sbin/wifi up
|
|
|
|
STATUS='up'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ping_check()
|
|
|
|
{
|
|
|
|
local target
|
|
|
|
network_get_gateway target $NETWORK
|
|
|
|
RET=`ping -c $PACKETS $target 2> /dev/null | awk '/packets received/ {print $4}'`
|
|
|
|
if [ "$RET" -eq "$PACKETS" ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
/usr/bin/logger -t wifi-sentinel -p daemon.info "Starting Wi-Fi Sentinel on the $NETWORK network with $PACKETS checks every $INTERVAL seconds."
|
|
|
|
|
|
|
|
while true ; do
|
2022-10-11 13:19:02 +03:00
|
|
|
if ping_check; then
|
2019-10-28 17:18:40 +02:00
|
|
|
lightson
|
|
|
|
else
|
|
|
|
lightsoff
|
|
|
|
fi
|
|
|
|
sleep $INTERVAL
|
|
|
|
done
|