90 lines
2.6 KiB
Bash
Executable file
90 lines
2.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# Watch the different broadcast networks and hide them if they
|
|
# are considered unusable.
|
|
# A new entry in wifi-iface sections of wireless config has been added
|
|
# test_connect can contain a shell command giving the state of the
|
|
# network:
|
|
# for a bridged wifi network (without IP on APs side), this could be:
|
|
# option 'test_connect' 'arping -I br-$(net) $(routeur_ip) -c 4'
|
|
# for wpa2 networks, test_connect can be ommited and connectivity
|
|
# to the radius serveur will be checked.
|
|
# In case of lack of connectivity, the corresponding SSID won't be
|
|
# broadcast anymore, preveting new clients from connecting.
|
|
# Currently, the scripts uses SIGHUP signal to hostapd process which
|
|
# ends up in loosing anyway all associated clients on the >>radio<<
|
|
# (hope this will be fixed)
|
|
|
|
CONF=/var/run/hostapd-phy0.conf
|
|
PID=/var/run/wifi-phy0.pid
|
|
CTRL=/var/run/hostapd-phy0
|
|
|
|
. /lib/functions.sh
|
|
|
|
# Numbered of changed statuses
|
|
changed=0
|
|
|
|
# $1 = interface
|
|
# $2 = variable name
|
|
hostapd_get_config() {
|
|
hostapd_cli -p$CTRL -i $1 get_config | sed "s/^$2=//; t; d"
|
|
}
|
|
|
|
# $1 = interface
|
|
# $2 = variable name
|
|
# $3 = value
|
|
hostapd_set_config() {
|
|
hostapd_cli -p$CTRL -i $1 set $2 $3
|
|
}
|
|
|
|
# $1 = ssid
|
|
# $2 = value ( 0 = Ok, 1 or 2 = hide)
|
|
set_ignore_broadcast_ssid() {
|
|
echo "changed $1's state to $2"
|
|
for iface in `ls $CTRL/`; do
|
|
[ "`hostapd_get_config $iface ssid`" = "$1" ] || continue
|
|
[ "`hostapd_get_config $iface ignore_broadcast_ssid`" != "$2" ] || continue
|
|
hostapd_set_config $iface ignore_broadcast_ssid $2
|
|
changed=$(($changed+1))
|
|
echo "changed"
|
|
done
|
|
}
|
|
|
|
check_ssid() {
|
|
local iface="$1"
|
|
config_get ssid $iface ssid default
|
|
config_get test_connect $iface test_connect
|
|
config_get disabled $iface disabled 0
|
|
[ $disabled -ne 0 ] && {
|
|
echo "$ssid: skipped (disabled)"
|
|
return
|
|
}
|
|
[ -z "$test_connect" ] && {
|
|
config_get server $iface server
|
|
[ -z "$server" ] && {
|
|
test_connect="true"
|
|
} || {
|
|
test_connect="ping -c 4 $server"
|
|
}
|
|
}
|
|
echo "$ssid: $test_connect ..."
|
|
$test_connect &> /dev/null
|
|
[ 0 -eq $? ] && set_ignore_broadcast_ssid "$ssid" 0 \
|
|
|| set_ignore_broadcast_ssid "$ssid" 1
|
|
|
|
}
|
|
|
|
# TODO: find out why this causes all clients to be disconnected on the radio
|
|
# maybe we should try reload the configuration using "hostapd_cli reconfigure"
|
|
# however we should figure out first what happened to that command
|
|
# (http://lists.shmoo.com/pipermail/hostap/2011-July/023520.html ?)
|
|
reload_hostapd() {
|
|
echo "reload config"
|
|
kill -1 `cat $PID`
|
|
}
|
|
|
|
config_load wireless
|
|
cp $CONF $CONF.bak
|
|
config_foreach check_ssid wifi-iface
|
|
|
|
exit $changed
|