Subversion Repositories ALCASAR

Rev

Rev 2113 | Rev 2278 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2113 Rev 2250
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-watchdog.sh 2113 2017-01-08 22:43:26Z richard $
2
# $Id: alcasar-watchdog.sh 2250 2017-05-22 22:00:03Z tom.houdayer $
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=`echo "$private_ip_mask" |cut -d"/" -f1`		# @ip du portail (côté LAN)
21
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
21
PRIVATE_IP=${PRIVATE_IP:=192.168.182.1}
22
current_users_file="/var/tmp/havp/current_users.txt"	# file containing active users with their "status.php" tab open
22
current_users_file="/var/tmp/havp/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
27
OLDIFS=$IFS
27
OLDIFS=$IFS
28
IFS=$'\n'
28
IFS=$'\n'
29
 
29
 
30
function lan_down_alert ()
30
function lan_down_alert ()
31
# users are redirected on ALCASAR IP address if a LAN problem is detected
31
# users are redirected on ALCASAR IP address if a LAN problem is detected
Line 40... Line 40...
40
		logger "can't contact the default router"
40
		logger "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
	esac
44
	esac
45
	net_pb=`grep "network_pb = True;" $Index_Page|wc -l`
45
	net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
46
	if [ $net_pb = "0" ] # user alert (only the first time)	
46
	if [ $net_pb = "0" ] # user alert (only the first time)	
47
		then
47
		then
48
		/bin/sed -i "s?^\$network_pb.*?\$network_pb = True;?g" $Index_Page
48
		/bin/sed -i "s?^\$network_pb.*?\$network_pb = true;?g" $Index_Page
49
		$IPTABLES -I PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
49
		$IPTABLES -I PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
50
	fi
50
	fi
51
}
51
}
52
 
52
 
53
function lan_test ()
53
function lan_test ()
Line 80... Line 80...
80
		then
80
		then
81
			lan_down_alert
81
			lan_down_alert
82
	# else switch in normal mode
82
	# else switch in normal mode
83
	else
83
	else
84
		echo "Internet access is OK for now"
84
		echo "Internet access is OK for now"
85
		net_pb=`grep "network_pb = True;" $Index_Page|wc -l`
85
		net_pb=`grep "network_pb = true;" $Index_Page|wc -l`
86
		if [ $net_pb != "0" ]
86
		if [ $net_pb != "0" ]
87
			then
87
			then
88
			/bin/sed -i "s?^\$network_pb.*?\$network_pb = False;?g" $Index_Page
88
			/bin/sed -i "s?^\$network_pb.*?\$network_pb = false;?g" $Index_Page
89
			$IPTABLES -D PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
89
			$IPTABLES -D PREROUTING -t nat -i $TUNIF -p udp --dport domain -j REDIRECT --to-port 56
90
		fi
90
		fi
91
	fi
91
	fi
92
}
92
}
93
 
93