Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 307 → Rev 308

/scripts/alcasar-watchdog.sh
1,17 → 1,82
#/bin/sh
#!/bin/sh
# $Id$
# by rexy
# Ce script permet de déconnecter les usagers dont
# Ce script prévient les usagers de l'indisponibilité de l'accès Internet
# il déconnecte les usagers dont
# - les équipementis réseau ne répondent plus
# - les adresses MAC sont usurpées
# The aim of this script is to disconnect users whose
# This script tells users that Internet access is down
# it logs out users whose
# - PCs are quiet
# - MAC address are in used by other systems (usurped)
 
EXTIF="eth0"
INTIF="eth1"
PRIVATE_IP="192.168.182.1"
tmp_file="/tmp/watchdog.txt"
Network_Pb_Page="/var/www/html/redirect/index-network-pb.php"
IFS=$'\n'
 
# Fonction appelée si un Pb de connectivité Internet
# On fait pointer les usagers sur une page d'erreur
function ext_down_alert ()
{
case $EXT_DOWN in
"1")
logger "eth0 link down"
/bin/sed -i "s?diagnostic =.*?diagnostic = eth0 link down?g" $Network_Pb_Page
;;
"2")
logger "can't contact the default router"
/bin/sed -i "s?diagnostic =.*?diagnostic = can't contact the default router?g" $Network_Pb_Page
;;
"3")
logger "can't contact the Internet DNS"
/bin/sed -i "s?diagnostic =.*?diagnostic = can't contact the Internet DNS?g" $Network_Pb_Page
;;
esac
net_pb=`cat /etc/dnsmasq.d/alcasar-dnsmasq.conf|grep "address=/#/"|wc -l`
if [ $net_pb != "1" ]
then
rm -f /var/www/html/redirect/index.php
ln -s /var/www/html/redirect/index-network-pb.php /var/www/html/redirect/index.php
/bin/sed -i "s?^conf-dir=.*?address=\/#\/$PRIVATE_IP?g" /etc/dnsmasq.d/alcasar-dnsmasq.conf
/etc/init.d/dnsmasq restart
fi
}
 
# On teste la connectivité réseau
# On teste l'état d'EXTIF
EXT_DOWN="0"
if [ "`/usr/sbin/ethtool $EXTIF|grep Link|cut -d' ' -f3`" != "yes" ]
then
EXT_DOWN="1"
fi
# si EXTIF ok, on teste la connectivité vers le routeur par défaut (Box FAI)
if [ $EXT_DOWN -eq "0" ]
then
IP_GW=`/sbin/ip route list|grep ^default|cut -d" " -f3`
arp_reply=`/usr/sbin/arping -I$EXTIF -c1 $IP_GW|grep response|cut -d" " -f2`
if [ $arp_reply -eq "0" ]
then
EXT_DOWN="2"
fi
fi
# si routeur OK, on teste la connectivité vers les DNS externes
# + tard (EXT_DOWN=3)
# si Pb réseau, on avertit les usagers
if [ $EXT_DOWN != "0" ]
then
ext_down_alert
else
# sinon, on rebascule en mode normal
net_pb=`cat /etc/dnsmasq.d/alcasar-dnsmasq.conf|grep "address=/#/"|wc -l`
if [ $net_pb -eq "1" ]
then
/bin/sed -i "s?^address=\/#\/.*?conf-dir=/usr/local/etc/alcasar-dnsfilter-enabled?g" /etc/dnsmasq.d/alcasar-dnsmasq.conf
/etc/init.d/dnsmasq restart
fi
fi
# lecture du fichier contenant les adresses IP des stations muettes
if [ -e $tmp_file ]; then
cat $tmp_file | while read noresponse
50,3 → 115,4
fi
fi
done