Subversion Repositories ALCASAR

Rev

Rev 2896 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2896 Rev 2956
1
#!/bin/sh
1
#!/bin/sh
2
#
2
#
3
# $Id: alcasar-condown.sh 2896 2020-12-10 23:29:21Z rexy $
3
# $Id: alcasar-condown.sh 2956 2021-05-24 19:57:17Z rexy $
4
#
4
#
5
# alcasar-condown.sh
5
# alcasar-condown.sh
6
# by Rexy
6
# by Rexy & Pierre RIVAULT
7
# This script is distributed under the Gnu General Public License (GPL)
7
# This script is distributed under the Gnu General Public License (GPL)
8
 
8
 
9
# This script is started by coova after each logout
9
# This script is started by coova after each logout
10
# Ce script est lancé par coova à chaque déconnexion d'usager
10
# Ce script est lancé par coova à chaque déconnexion d'usager
11
 
11
 
12
PASSWD_FILE="/root/ALCASAR-passwords.txt"
12
PASSWD_FILE="/root/ALCASAR-passwords.txt"
13
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
13
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
14
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`
14
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`
15
 
15
 
16
if [ -z $FRAMED_IP_ADDRESS ]; then
16
if [ -z $FRAMED_IP_ADDRESS ]; then
17
	exit 1
17
	exit 1
18
fi
18
fi
19
 
19
 
20
# Retrieve 2 alcasar special radius attributes (search order : default group, then user's group, then user)
20
# Retrieve 2 alcasar special radius attributes (search order : default group, then user's group, then user)
21
db_query="SELECT attribute, value FROM ( \
21
db_query="SELECT attribute, value FROM ( \
22
 	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) UNION \
22
 	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) UNION \
23
	( 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 \
23
	( 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 \
24
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) \
24
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter')) ) \
25
) attrs GROUP BY attribute;"
25
) attrs GROUP BY attribute;"
26
db_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)
26
db_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)
27
 
27
 
28
filter=$(echo "$db_res"      | awk '$1 == "Alcasar-Filter"           { print $2 }')
28
filter=$(echo "$db_res"      | awk '$1 == "Alcasar-Filter"           { print $2 }')
29
filterProto=$(echo "$db_res" | awk '$1 == "Alcasar-Protocols-Filter" { print $2 }')
29
filterProto=$(echo "$db_res" | awk '$1 == "Alcasar-Protocols-Filter" { print $2 }')
30
 
30
 
31
if [ "$filter" == '4' ]; then	# AV_WL
31
if [ "$filter" == '4' ]; then	# AV_WL
32
	set_filter="av_wl"
32
	set_filter="av_wl"
33
elif [ "$filter" == '3' ]; then	# AV_BL
33
elif [ "$filter" == '3' ]; then	# AV_BL
34
	set_filter="av_bl"
34
	set_filter="av_bl"
35
elif [ "$filter" == '2' ]; then	# AV
35
elif [ "$filter" == '2' ]; then	# AV
36
	set_filter="av"
36
	set_filter="av"
37
else				# NOT_FILTERED
37
else				# NOT_FILTERED
38
	set_filter="not_filtered"
38
	set_filter="not_filtered"
39
fi
39
fi
40
 
40
 
41
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
41
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
42
	set_filterProto="proto_3";
42
	set_filterProto="proto_3";
43
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
43
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
44
	set_filterProto="proto_2";
44
	set_filterProto="proto_2";
45
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
45
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
46
	set_filterProto="proto_1";
46
	set_filterProto="proto_1";
47
else					# PROFILE 0 (Not filtered)
47
else					# PROFILE 0 (Not filtered)
48
	set_filterProto="proto_0";
48
	set_filterProto="proto_0";
49
fi
49
fi
50
 
50
 
51
# Remove user from his IPSET
51
# Remove user from his IPSET
52
ipset del $set_filter      $FRAMED_IP_ADDRESS
52
ipset del $set_filter      $FRAMED_IP_ADDRESS
53
ipset del $set_filterProto $FRAMED_IP_ADDRESS
53
ipset del $set_filterProto $FRAMED_IP_ADDRESS
54
 
54
 
55
# Remove IP address from active users list
55
# Remove IP address from active users list
56
current_users_file="/tmp/current_users.txt"
56
current_users_file="/tmp/current_users.txt"
57
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
57
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
58
 
58
 
-
 
59
# Remove user_IP from ipset of load balancing
-
 
60
nb_gw=`grep ^WAN $CONF_FILE | wc -l`
-
 
61
for (( i = 0 ; i <= $nb_gw ; i++ ));do
-
 
62
	gw="gw$i"
-
 
63
	ipset test $gw $FRAMED_IP_ADDRESS 1>/dev/null 2>&1
-
 
64
	if [ $? -eq 0 ];then
-
 
65
		ipset del $gw $FRAMED_IP_ADDRESS
-
 
66
		break
-
 
67
	fi
-
 
68
done
-
 
69
 
59
#############################
70
#############################
60
## Debug : show all the coova parse variables (+ ALCASAR-Filter + ALCASAR-Protocols-Filter).
71
## Debug : show all the coova parse variables (+ ALCASAR-Filter + ALCASAR-Protocols-Filter).
61
## see "/src/chilli.c" for the complete list of parse variables
72
## see "/src/chilli.c" for the complete list of parse variables
62
#debug_file="/tmp/debug-condown.txt"
73
#debug_file="/tmp/debug-condown.txt"
63
#echo "-----------------------------------------------" >> $debug_file
74
#echo "-----------------------------------------------" >> $debug_file
64
#echo `date` >> $debug_file
75
#echo `date` >> $debug_file
65
#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
76
#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
66
#do
77
#do
67
#	echo -n "$i=" >> $debug_file
78
#	echo -n "$i=" >> $debug_file
68
#	if [[ -v $i ]];
79
#	if [[ -v $i ]];
69
#	then
80
#	then
70
#		echo -n "${!i}; " >> $debug_file
81
#		echo -n "${!i}; " >> $debug_file
71
#	else
82
#	else
72
#		echo -n "not defined; " >> $debug_file
83
#		echo -n "not defined; " >> $debug_file
73
#	fi
84
#	fi
74
#done
85
#done
75
#echo >> $debug_file
86
#echo >> $debug_file
76
#echo "ALCASAR-Filter : $set_filter" >> $debug_file
87
#echo "ALCASAR-Filter : $set_filter" >> $debug_file
77
#echo "ALCASAR-Protocols-Filter : $set_filterProto" >> $debug_file
88
#echo "ALCASAR-Protocols-Filter : $set_filterProto" >> $debug_file
78
## END Debug
89
## END Debug
79
#################################
90
#################################
80
 
91
 
81
 
92
 
82

Generated by GNU Enscript 1.6.6.
93

Generated by GNU Enscript 1.6.6.
83
 
94
 
84
 
95
 
85
 
96