| Line 1... |
Line 1... |
| 1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
| 2 |
# $Id: alcasar-watchdog.sh 2841 2020-06-28 21:49:00Z rexy $
|
2 |
# $Id: alcasar-watchdog.sh 2864 2020-10-18 09:06:17Z rexy $
|
| 3 |
|
3 |
|
| 4 |
# alcasar-watchdog.sh
|
4 |
# alcasar-watchdog.sh
|
| 5 |
# by Rexy
|
5 |
# by Rexy
|
| 6 |
# This script is distributed under the Gnu General Public License (GPL)
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
| 7 |
# - Ce script prévient les usagers de l'indisponibilité de l'accès Internet
|
7 |
# - Ce script prévient les usagers de l'indisponibilité de l'accès Internet
|
| Line 15... |
Line 15... |
| 15 |
CONF_FILE="/usr/local/etc/alcasar.conf"
|
15 |
CONF_FILE="/usr/local/etc/alcasar.conf"
|
| 16 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
16 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
| 17 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
17 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
| 18 |
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
18 |
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
| 19 |
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
|
19 |
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
|
| 20 |
PRIVATE_IP=`echo "$private_ip_mask" |cut -d"/" -f1` # @ip du portail (côté LAN)
|
20 |
PRIVATE_IP="192.168.182.1"
|
| 21 |
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
|
21 |
PRIVATE_IP="192.168.182.1"
|
| 22 |
current_users_file="/tmp/current_users.txt" # file containing active users with their "status.php" tab open
|
22 |
current_users_file="/tmp/current_users.txt" # file containing active users with their "status.php" tab open
|
| 23 |
DIR_WEB="/var/www/html"
|
23 |
DIR_WEB="/var/www/html"
|
| 24 |
Index_Page="$DIR_WEB/index.php"
|
24 |
Index_Page="$DIR_WEB/index.php"
|
| 25 |
IPTABLES="/sbin/iptables"
|
25 |
IPTABLES="/sbin/iptables"
|
| 26 |
TUNIF="tun0" # listen device for chilli daemon
|
26 |
TUNIF="tun0" # listen device for chilli daemon
|
| Line 39... |
Line 39... |
| 39 |
"2")
|
39 |
"2")
|
| 40 |
logger -t alcasar-watchdog "can't contact the default router"
|
40 |
logger -t alcasar-watchdog "can't contact the default router"
|
| 41 |
echo "can't contact the default router"
|
41 |
echo "can't contact the default router"
|
| 42 |
/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't contact the default router\";?g" $Index_Page
|
42 |
/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't contact the default router\";?g" $Index_Page
|
| 43 |
;;
|
43 |
;;
|
| - |
|
44 |
"3")
|
| - |
|
45 |
logger -t alcasar-watchdog "can't resolv DNS queries"
|
| - |
|
46 |
echo "can't resolv DNS queries"
|
| - |
|
47 |
/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't resolv DNS queries\";?g" $Index_Page
|
| - |
|
48 |
;;
|
| 44 |
esac
|
49 |
esac
|
| 45 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
50 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
| 46 |
if [ $net_pb = "0" ] # user alert (only the first time)
|
51 |
if [ $net_pb = "0" ] # user alert (only the first time)
|
| 47 |
then
|
52 |
then
|
| 48 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = true;?g" $Index_Page
|
53 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = true;?g" $Index_Page
|
| Line 79... |
Line 84... |
| 79 |
then
|
84 |
then
|
| 80 |
LAN_DOWN="2"
|
85 |
LAN_DOWN="2"
|
| 81 |
fi
|
86 |
fi
|
| 82 |
fi
|
87 |
fi
|
| 83 |
fi
|
88 |
fi
|
| - |
|
89 |
# DNS request testing
|
| - |
|
90 |
if [ $LAN_DOWN -eq "0" ]
|
| - |
|
91 |
then
|
| - |
|
92 |
dns_reply=`/usr/bin/host -W1 free.fr|grep SERVFAIL|wc -l`
|
| - |
|
93 |
if [ $dns_reply -eq "1" ]
|
| - |
|
94 |
then
|
| - |
|
95 |
LAN_DOWN="3"
|
| - |
|
96 |
fi
|
| - |
|
97 |
fi
|
| 84 |
# if LAN pb detected, users are warned
|
98 |
# if LAN pb detected, users are warned
|
| 85 |
if [ $LAN_DOWN != "0" ]
|
99 |
if [ $LAN_DOWN != "0" ]
|
| 86 |
then
|
100 |
then
|
| 87 |
lan_down_alert
|
101 |
lan_down_alert
|
| 88 |
# else switch in normal mode
|
102 |
# else switch in normal mode
|