Subversion Repositories ALCASAR

Rev

Rev 1469 | Rev 1474 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 1469 Rev 1472
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-watchdog.sh 1469 2014-10-30 21:58:47Z richard $
2
# $Id: alcasar-watchdog.sh 1472 2014-11-03 17:56:00Z richard $
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 21... Line 21...
21
PRIVATE_IP=`echo "$private_ip_mask" |cut -d"/" -f1`      # @ip du portail (côté LAN)
21
PRIVATE_IP=`echo "$private_ip_mask" |cut -d"/" -f1`      # @ip du portail (côté LAN)
22
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
22
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
23
tmp_file="/tmp/watchdog.txt"
23
tmp_file="/tmp/watchdog.txt"
24
DIR_WEB="/var/www/html"
24
DIR_WEB="/var/www/html"
25
Index_Page="$DIR_WEB/index.php"
25
Index_Page="$DIR_WEB/index.php"
-
 
26
IPTABLES="/sbin/iptables"
-
 
27
TUNIF="tun0"						# listen device for chilli daemon
26
OLDIFS=$IFS
28
OLDIFS=$IFS
27
IFS=$'\n'
29
IFS=$'\n'
28
 
30
 
29
function lan_down_alert ()
31
function lan_down_alert ()
30
# users are redirected on ALCASAR IP address if a LAN problem is detected
32
# users are redirected on ALCASAR IP address if a LAN problem is detected
Line 39... Line 41...
39
		logger "can't contact the default router"
41
		logger "can't contact the default router"
40
		echo "can't contact the default router"
42
		echo "can't contact the default router"
41
		/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't contact the default router\";?g" $Index_Page
43
		/bin/sed -i "s?diagnostic =.*?diagnostic = \"can't contact the default router\";?g" $Index_Page
42
		;;
44
		;;
43
	esac
45
	esac
44
	net_pb=`cat /etc/dnsmasq.conf|grep "address=/#/"|wc -l`
46
	net_pb=`grep "network_pb = True;" $Index_Page|wc -l`
45
	if [ $net_pb = "0" ] # user alert
47
	if [ $net_pb = "0" ] # user alert (only the first time)	
46
		then
48
		then
47
		/bin/sed -i "s?^\$network_pb.*?\$network_pb = True;?g" $Index_Page
49
		/bin/sed -i "s?^\$network_pb.*?\$network_pb = True;?g" $Index_Page
48
		/bin/sed -i "s?^conf-dir=.*?address=\/#\/$PRIVATE_IP?g" /etc/dnsmasq-blacklist.conf
50
		$IPTABLES -I PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
49
		/bin/sed -i "1i\address=\/#\/$PRIVATE_IP" /etc/dnsmasq.conf
-
 
50
		/etc/init.d/dnsmasq restart
-
 
51
	fi
51
	fi
52
}
52
}
53
 
53
 
54
function lan_test ()
54
function lan_test ()
55
# LAN connectiivity testing
55
# LAN connectiivity testing
Line 60... Line 60...
60
		echo "ALCASAR watchdog is already running"
60
		echo "ALCASAR watchdog is already running"
61
		exit 0
61
		exit 0
62
	fi
62
	fi
63
	# EXTIF testing
63
	# EXTIF testing
64
	LAN_DOWN="0"
64
	LAN_DOWN="0"
65
	if [ "`/usr/sbin/ethtool $EXTIF|grep Link|cut -d' ' -f3`" != "yes" ] && [ "`/sbin/mii-tool $EXTIF | grep -i link | awk '{print $NF}'`" != "ok" ]
65
	if [ `/sbin/ip link | grep $EXTIF|grep "NO-CARRIER" | wc -l` -eq "1" ]
66
		then
66
		then
67
		LAN_DOWN="1"
67
		LAN_DOWN="1"
68
	fi
68
	fi
69
	# Default GW testing
69
	# Default GW testing
70
	if [ $LAN_DOWN -eq "0" ]
70
	if [ $LAN_DOWN -eq "0" ]
Line 81... Line 81...
81
		then
81
		then
82
			lan_down_alert
82
			lan_down_alert
83
	# else switch in normal mode
83
	# else switch in normal mode
84
	else
84
	else
85
		echo "Internet access is OK for now"
85
		echo "Internet access is OK for now"
86
		net_pb=`cat /etc/dnsmasq.conf|grep "address=/#/"|wc -l`
86
		net_pb=`grep "network_pb = True;" $Index_Page|wc -l`
87
		if [ $net_pb != "0" ]
87
		if [ $net_pb != "0" ]
88
			then
88
			then
89
			/bin/sed -i "s?^\$network_pb.*?\$network_pb = False;?g" $Index_Page
89
			/bin/sed -i "s?^\$network_pb.*?\$network_pb = False;?g" $Index_Page
90
			/bin/sed -i "s?^address=\/#\/.*?conf-dir=/usr/local/share/dnsmasq-bl-enabled?g" /etc/dnsmasq-blacklist.conf
90
			$IPTABLES -D PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
91
			/bin/sed -i "/^address=/d" /etc/dnsmasq.conf
-
 
92
			/etc/init.d/dnsmasq restart
-
 
93
		fi
91
		fi
94
	fi
92
	fi
95
}
93
}
96
 
94
 
97
usage="Usage: alcasar-watchdog.sh {-lt --lan_test}"
95
usage="Usage: alcasar-watchdog.sh {-lt --lan_test}"