Subversion Repositories ALCASAR

Rev

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

Rev 2376 Rev 2394
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-watchdog.sh 2376 2017-08-16 18:46:50Z tom.houdayer $
2
# $Id: alcasar-watchdog.sh 2394 2017-08-27 13:28:59Z 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 103... Line 103...
103
		;;
103
		;;
104
	*)
104
	*)
105
		lan_test
105
		lan_test
106
		# We disconnect inactive users (its means that their 'status.php' tab has been closed --> their ip address isn't in $current_users_file)
106
		# We disconnect inactive users (its means that their 'status.php' tab has been closed --> their ip address isn't in $current_users_file)
107
		# process each equipment known by chilli to check if IP address is usurped (with arping)
107
		# process each equipment known by chilli to check if IP address is usurped (with arping)
108
		for system in `/usr/sbin/chilli_query list |grep -v "\.0\.0\.0"`
108
		for system in `/usr/sbin/chilli_query list | grep -v "0\.0\.0\.0"`
109
		do
109
		do
110
			active_ip=`echo $system |cut -d" " -f2`
110
			active_ip=`echo $system |cut -d" " -f2`
111
			active_session=`echo $system |cut -d" " -f5`
111
			active_session=`echo $system |cut -d" " -f5`
112
			active_mac=`echo $system | cut -d" " -f1`
112
			active_mac=`echo $system | cut -d" " -f1`
113
			active_user=`echo $system |cut -d" " -f6`
113
			active_user=`echo $system |cut -d" " -f6`
114
			#We disconnect inactive user here :
114
			# We disconnect inactive user here :
115
			#We check if this is not an auth @MAC and if he is still connected
115
			# We check if this is not an auth @MAC and if he is still connected
116
			if [ "$active_user" != "$active_mac" ] && [ $(expr $active_session) -eq 1 ]; then
116
			if [ "$active_user" != "$active_mac" ] && [ $(expr $active_session) -eq 1 ]; then
117
				if [ -e $current_users_file ]; then
117
				if [ -e $current_users_file ]; then
118
					# We check if user @IP is in 'current_users.txt'
118
					# We check if user @IP is in 'current_users.txt'
119
					cmp_user_ok=$(cat $current_users_file | grep "^$active_ip\$" -c)
119
					cmp_user_ok=$(cat $current_users_file | awk -F':' "\$1 == \"$active_ip\" {print \$2}")
120
					# If not we disconnect this user.
120
					# If not we disconnect this user.
121
					if [ $cmp_user_ok -eq 0 ]; then
121
					if [ -z "$cmp_user_ok" ]; then
122
						logger "alcasar-watchdog : $active_ip ($active_mac) can't be contact. We disconnects the user ($active_user)."
122
						logger "alcasar-watchdog : $active_ip ($active_mac) can't be contact. We disconnects the user ($active_user)."
123
						/usr/sbin/chilli_query logout $active_mac
123
						/usr/sbin/chilli_query logout $active_mac
124
					else
124
					elif [ "$cmp_user_ok" == "TEMP" ]; then
125
						# Remove the user's IP from 'current_users.txt'. Every user need to insert their @IP everytime to prove their connectivity.
125
						# Remove the user's IP from 'current_users.txt'. Every user need to insert their @IP everytime to prove their connectivity.
126
						sed -i "/^$active_ip\$/d" $current_users_file
126
						sed -i "/^$active_ip:$cmp_user_ok\$/d" $current_users_file
127
					fi
127
					fi
128
				else # "current_user.txt" does not exists. We disconnect every users.
128
				else # "current_user.txt" does not exists. We disconnect every users.
129
					logger "alcasar-watchdog : The file /var/tmp/havp/current_users.txt doen't' exist. We disconnects the user $active_user"
129
					logger "alcasar-watchdog : The file /var/tmp/havp/current_users.txt doen't' exist. We disconnects the user $active_user"
130
					/usr/sbin/chilli_query logout $active_mac
130
					/usr/sbin/chilli_query logout $active_mac
131
				fi
131
				fi