| Line 1... |
Line 1... |
| 1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
| 2 |
# $Id: alcasar-watchdog.sh 2967 2021-07-08 09:47:39Z rexy $
|
2 |
# $Id: alcasar-watchdog.sh 3008 2022-05-06 17:22:52Z 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 17... |
Line 17... |
| 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`
|
20 |
PRIVATE_IP=`echo $private_ip_mask |cut -d"/" -f1`
|
| 21 |
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
|
21 |
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
|
| - |
|
22 |
MULTIWAN=`grep ^MULTIWAN= $CONF_FILE|cut -d"=" -f2`
|
| 22 |
current_users_file="/tmp/current_users.txt" # file containing active users with their "status.php" tab open
|
23 |
current_users_file="/tmp/current_users.txt" # file containing active users with their "status.php" tab open
|
| 23 |
DIR_WEB="/var/www/html"
|
24 |
DIR_WEB="/var/www/html"
|
| 24 |
Index_Page="$DIR_WEB/index.php"
|
25 |
Index_Page="$DIR_WEB/index.php"
|
| 25 |
IPTABLES="/sbin/iptables"
|
26 |
IPTABLES="/sbin/iptables"
|
| 26 |
TUNIF="tun0" # listen device for chilli daemon
|
27 |
TUNIF="tun0" # listen device for chilli daemon
|
| Line 46... |
Line 47... |
| 46 |
echo "can't resolv DNS queries"
|
47 |
echo "can't resolv DNS queries"
|
| 47 |
/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't resolv DNS queries\";?g" $Index_Page
|
48 |
/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't resolv DNS queries\";?g" $Index_Page
|
| 48 |
;;
|
49 |
;;
|
| 49 |
esac
|
50 |
esac
|
| 50 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
51 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
| 51 |
if [ $net_pb = "0" ] # user alert (only the first time)
|
52 |
if [ $net_pb = "0" ] # if previously up
|
| 52 |
then
|
53 |
then
|
| 53 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = true;?g" $Index_Page
|
54 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = true;?g" $Index_Page
|
| 54 |
$IPTABLES -I PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
|
55 |
$IPTABLES -I PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
|
| 55 |
fi
|
56 |
fi
|
| 56 |
}
|
57 |
}
|
| Line 75... |
Line 76... |
| 75 |
then
|
76 |
then
|
| 76 |
GW_EXIST=`/sbin/ip route list|grep ^default|wc -l`
|
77 |
GW_EXIST=`/sbin/ip route list|grep ^default|wc -l`
|
| 77 |
if [ $GW_EXIST -eq "0" ] # no GW defined !
|
78 |
if [ $GW_EXIST -eq "0" ] # no GW defined !
|
| 78 |
then
|
79 |
then
|
| 79 |
systemctl restart network
|
80 |
systemctl restart network
|
| 80 |
else
|
81 |
else
|
| 81 |
IP_GW=`/sbin/ip route list|grep ^default|cut -d" " -f3`
|
82 |
if [ "$MULTIWAN" == "off" ] || [ "$MULTIWAN" == "Off" ]
|
| 82 |
arp_reply=`/usr/sbin/arping -I$EXTIF -c1 $IP_GW|grep response|cut -d" " -f2`
|
- |
|
| 83 |
if [ $arp_reply -eq "0" ]
|
- |
|
| 84 |
then
|
83 |
then
|
| - |
|
84 |
IP_GW=`/sbin/ip route list|grep ^default|cut -d" " -f3`
|
| - |
|
85 |
arp_reply=`/usr/sbin/arping -I$EXTIF -c1 $IP_GW|grep response|cut -d" " -f2`
|
| - |
|
86 |
if [ $arp_reply -eq "0" ]
|
| - |
|
87 |
then
|
| 85 |
LAN_DOWN="2"
|
88 |
LAN_DOWN="2"
|
| - |
|
89 |
fi
|
| 86 |
fi
|
90 |
fi
|
| 87 |
fi
|
91 |
fi
|
| 88 |
fi
|
92 |
fi
|
| 89 |
# DNS request testing (twice)
|
93 |
# DNS request testing (twice)
|
| 90 |
if [ $LAN_DOWN -eq "0" ]
|
94 |
if [ $LAN_DOWN -eq "0" ]
|
| Line 104... |
Line 108... |
| 104 |
lan_down_alert
|
108 |
lan_down_alert
|
| 105 |
# else switch in normal mode
|
109 |
# else switch in normal mode
|
| 106 |
else
|
110 |
else
|
| 107 |
echo "Internet access is OK for now"
|
111 |
echo "Internet access is OK for now"
|
| 108 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
112 |
net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
|
| 109 |
if [ $net_pb != "0" ]
|
113 |
if [ $net_pb != "0" ] # if already down
|
| 110 |
then
|
114 |
then
|
| 111 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = false;?g" $Index_Page
|
115 |
/bin/sed -i "s?^\$network_pb.*?\$network_pb = false;?g" $Index_Page
|
| 112 |
$IPTABLES -D PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
|
116 |
$IPTABLES -D PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
|
| 113 |
fi
|
117 |
fi
|
| 114 |
fi
|
118 |
fi
|