Subversion Repositories ALCASAR

Rev

Rev 2956 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1294 richard 1
#!/bin/sh
2234 richard 2
#
3
# $Id: alcasar-condown.sh 2965 2021-07-04 22:15:08Z rexy $
4
#
2068 richard 5
# alcasar-condown.sh
2956 rexy 6
# by Rexy & Pierre RIVAULT
1294 richard 7
# This script is distributed under the Gnu General Public License (GPL)
8
 
2886 rexy 9
# This script is started by coova after each logout
2184 richard 10
# Ce script est lancé par coova à chaque déconnexion d'usager
1294 richard 11
 
2965 rexy 12
CONF_FILE="/usr/local/etc/alcasar.conf"
2501 tom.houday 13
PASSWD_FILE="/root/ALCASAR-passwords.txt"
2886 rexy 14
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
15
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`
2501 tom.houday 16
 
2234 richard 17
if [ -z $FRAMED_IP_ADDRESS ]; then
18
	exit 1
2184 richard 19
fi
1294 richard 20
 
2886 rexy 21
# Retrieve 2 alcasar special radius attributes (search order : default group, then user's group, then user)
2712 tom.houday 22
db_query="SELECT attribute, value FROM ( \
2886 rexy 23
 	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) UNION \
2712 tom.houday 24
	( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ORDER BY ug.priority ) UNION \
2883 rexy 25
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) \
2712 tom.houday 26
) attrs GROUP BY attribute;"
2886 rexy 27
db_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)
2006 raphael.pi 28
 
2712 tom.houday 29
filter=$(echo "$db_res"      | awk '$1 == "Alcasar-Filter"           { print $2 }')
30
filterProto=$(echo "$db_res" | awk '$1 == "Alcasar-Protocols-Filter" { print $2 }')
2501 tom.houday 31
 
2841 rexy 32
if [ "$filter" == '4' ]; then	# AV_WL
33
	set_filter="av_wl"
34
elif [ "$filter" == '3' ]; then	# AV_BL
35
	set_filter="av_bl"
36
elif [ "$filter" == '2' ]; then	# AV
37
	set_filter="av"
2501 tom.houday 38
else				# NOT_FILTERED
2234 richard 39
	set_filter="not_filtered"
2006 raphael.pi 40
fi
41
 
2501 tom.houday 42
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
43
	set_filterProto="proto_3";
44
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
45
	set_filterProto="proto_2";
46
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
47
	set_filterProto="proto_1";
2234 richard 48
else					# PROFILE 0 (Not filtered)
2501 tom.houday 49
	set_filterProto="proto_0";
2006 raphael.pi 50
fi
51
 
2886 rexy 52
# Remove user from his IPSET
2501 tom.houday 53
ipset del $set_filter      $FRAMED_IP_ADDRESS
54
ipset del $set_filterProto $FRAMED_IP_ADDRESS
2184 richard 55
 
2896 rexy 56
# Remove IP address from active users list
2841 rexy 57
current_users_file="/tmp/current_users.txt"
2394 tom.houday 58
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
2376 tom.houday 59
 
2956 rexy 60
# Remove user_IP from ipset of load balancing
61
nb_gw=`grep ^WAN $CONF_FILE | wc -l`
62
for (( i = 0 ; i <= $nb_gw ; i++ ));do
63
	gw="gw$i"
64
	ipset test $gw $FRAMED_IP_ADDRESS 1>/dev/null 2>&1
65
	if [ $? -eq 0 ];then
66
		ipset del $gw $FRAMED_IP_ADDRESS
67
		break
68
	fi
69
done
70
 
2883 rexy 71
#############################
2886 rexy 72
## Debug : show all the coova parse variables (+ ALCASAR-Filter + ALCASAR-Protocols-Filter).
2883 rexy 73
## see "/src/chilli.c" for the complete list of parse variables
74
#debug_file="/tmp/debug-condown.txt"
75
#echo "-----------------------------------------------" >> $debug_file
76
#echo `date` >> $debug_file
77
#for i in DEV NET MASK ADDR USER_NAME NAS_IP_ADDRESS SERVICE_TYPE FRAMED_IP_ADDRESS FILTER_ID STATE CLASS CUI SESSION_TIMEOUT IDLE_TIMEOUT CALLING_STATION_ID CALLED_STATION_ID NAS_ID NAS_PORT_TYPE ACCT_SESSION_ID ACCT_INTERIM_INTERVAL WISPR_LOCATION_ID WISPR_LOCATION_NAME WISPR_BANDWIDTH_MAX_UP WISPR_BANDWIDTH_MAX_DOWN COOVACHILLI_MAX_INPUT_OCTETS COOVACHILLI_MAX_OUTPUT_OCTETS COOVACHILLI_MAX_TOTAL_OCTETS INPUT_OCTETS OUTPUT_OCTETS INPUT_PACKETS OUTPUT_PACKETS SESSION_TIME IDLE_TIME LOCATION OLD_LOCATION TERMINATE_CAUSE
2184 richard 78
#do
2883 rexy 79
#	echo -n "$i=" >> $debug_file
80
#	if [[ -v $i ]];
81
#	then
82
#		echo -n "${!i}; " >> $debug_file
83
#	else
84
#		echo -n "not defined; " >> $debug_file
85
#	fi
2184 richard 86
#done
2883 rexy 87
#echo >> $debug_file
2886 rexy 88
#echo "ALCASAR-Filter : $set_filter" >> $debug_file
89
#echo "ALCASAR-Protocols-Filter : $set_filterProto" >> $debug_file
2883 rexy 90
## END Debug
91
#################################