Rev 247 | Rev 309 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log
Rev 247 | Rev 308 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 |
|
1 | #!/bin/sh |
2 | # $Id: alcasar-watchdog.sh |
2 | # $Id: alcasar-watchdog.sh 308 2010-10-25 22:17:29Z richard $ |
3 | # by rexy |
3 | # by rexy |
- | 4 | # Ce script prévient les usagers de l'indisponibilité de l'accès Internet |
|
4 | # |
5 | # il déconnecte les usagers dont |
5 | # - les équipementis réseau ne répondent plus |
6 | # - les équipementis réseau ne répondent plus |
6 | # - les adresses MAC sont usurpées |
7 | # - les adresses MAC sont usurpées |
7 | # |
8 | # This script tells users that Internet access is down |
- | 9 | # it logs out users whose |
|
8 | # - PCs are quiet |
10 | # - PCs are quiet |
9 | # - MAC address are in used by other systems (usurped) |
11 | # - MAC address are in used by other systems (usurped) |
10 | 12 | ||
- | 13 | EXTIF="eth0" |
|
11 | INTIF="eth1" |
14 | INTIF="eth1" |
12 | PRIVATE_IP="192.168.182.1" |
15 | PRIVATE_IP="192.168.182.1" |
13 | tmp_file="/tmp/watchdog.txt" |
16 | tmp_file="/tmp/watchdog.txt" |
- | 17 | Network_Pb_Page="/var/www/html/redirect/index-network-pb.php" |
|
14 | IFS=$'\n' |
18 | IFS=$'\n' |
- | 19 | ||
- | 20 | # Fonction appelée si un Pb de connectivité Internet |
|
- | 21 | # On fait pointer les usagers sur une page d'erreur |
|
- | 22 | function ext_down_alert () |
|
- | 23 | { |
|
- | 24 | case $EXT_DOWN in |
|
- | 25 | "1") |
|
- | 26 | logger "eth0 link down" |
|
- | 27 | /bin/sed -i "s?diagnostic =.*?diagnostic = eth0 link down?g" $Network_Pb_Page |
|
- | 28 | ;; |
|
- | 29 | "2") |
|
- | 30 | logger "can't contact the default router" |
|
- | 31 | /bin/sed -i "s?diagnostic =.*?diagnostic = can't contact the default router?g" $Network_Pb_Page |
|
- | 32 | ;; |
|
- | 33 | "3") |
|
- | 34 | logger "can't contact the Internet DNS" |
|
- | 35 | /bin/sed -i "s?diagnostic =.*?diagnostic = can't contact the Internet DNS?g" $Network_Pb_Page |
|
- | 36 | ;; |
|
- | 37 | esac |
|
- | 38 | net_pb=`cat /etc/dnsmasq.d/alcasar-dnsmasq.conf|grep "address=/#/"|wc -l` |
|
- | 39 | if [ $net_pb != "1" ] |
|
- | 40 | then |
|
- | 41 | rm -f /var/www/html/redirect/index.php |
|
- | 42 | ln -s /var/www/html/redirect/index-network-pb.php /var/www/html/redirect/index.php |
|
- | 43 | /bin/sed -i "s?^conf-dir=.*?address=\/#\/$PRIVATE_IP?g" /etc/dnsmasq.d/alcasar-dnsmasq.conf |
|
- | 44 | /etc/init.d/dnsmasq restart |
|
- | 45 | fi |
|
- | 46 | } |
|
- | 47 | ||
- | 48 | # On teste la connectivité réseau |
|
- | 49 | # On teste l'état d'EXTIF |
|
- | 50 | EXT_DOWN="0" |
|
- | 51 | if [ "`/usr/sbin/ethtool $EXTIF|grep Link|cut -d' ' -f3`" != "yes" ] |
|
- | 52 | then |
|
- | 53 | EXT_DOWN="1" |
|
- | 54 | fi |
|
- | 55 | # si EXTIF ok, on teste la connectivité vers le routeur par défaut (Box FAI) |
|
- | 56 | if [ $EXT_DOWN -eq "0" ] |
|
- | 57 | then |
|
- | 58 | IP_GW=`/sbin/ip route list|grep ^default|cut -d" " -f3` |
|
- | 59 | arp_reply=`/usr/sbin/arping -I$EXTIF -c1 $IP_GW|grep response|cut -d" " -f2` |
|
- | 60 | if [ $arp_reply -eq "0" ] |
|
- | 61 | then |
|
- | 62 | EXT_DOWN="2" |
|
- | 63 | fi |
|
- | 64 | fi |
|
- | 65 | # si routeur OK, on teste la connectivité vers les DNS externes |
|
- | 66 | # + tard (EXT_DOWN=3) |
|
- | 67 | # si Pb réseau, on avertit les usagers |
|
- | 68 | if [ $EXT_DOWN != "0" ] |
|
- | 69 | then |
|
- | 70 | ext_down_alert |
|
- | 71 | else |
|
- | 72 | # sinon, on rebascule en mode normal |
|
- | 73 | net_pb=`cat /etc/dnsmasq.d/alcasar-dnsmasq.conf|grep "address=/#/"|wc -l` |
|
- | 74 | if [ $net_pb -eq "1" ] |
|
- | 75 | then |
|
- | 76 | /bin/sed -i "s?^address=\/#\/.*?conf-dir=/usr/local/etc/alcasar-dnsfilter-enabled?g" /etc/dnsmasq.d/alcasar-dnsmasq.conf |
|
- | 77 | /etc/init.d/dnsmasq restart |
|
- | 78 | fi |
|
- | 79 | fi |
|
15 | # lecture du fichier contenant les adresses IP des stations muettes |
80 | # lecture du fichier contenant les adresses IP des stations muettes |
16 | if [ -e $tmp_file ]; then |
81 | if [ -e $tmp_file ]; then |
17 | cat $tmp_file | while read noresponse |
82 | cat $tmp_file | while read noresponse |
18 | do |
83 | do |
19 | noresponse_ip=`echo $noresponse | cut -d" " -f1` |
84 | noresponse_ip=`echo $noresponse | cut -d" " -f1` |
Line 48... | Line 113... | ||
48 | logger "alcasar-watchdog : $active_ip est usurpée ($active_mac). On déconnecte." |
113 | logger "alcasar-watchdog : $active_ip est usurpée ($active_mac). On déconnecte." |
49 | /usr/sbin/chilli_query logout $active_mac |
114 | /usr/sbin/chilli_query logout $active_mac |
50 | fi |
115 | fi |
51 | fi |
116 | fi |
52 | done |
117 | done |
- | 118 |