Subversion Repositories ALCASAR

Rev

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

Rev 2394 Rev 2501
Line 1... Line 1...
1
#!/bin/sh
1
#!/bin/sh
2
#
2
#
3
# $Id: alcasar-condown.sh 2394 2017-08-27 13:28:59Z tom.houdayer $
3
# $Id: alcasar-condown.sh 2501 2018-02-28 00:34:14Z tom.houdayer $
4
#
4
#
5
# alcasar-condown.sh
5
# alcasar-condown.sh
6
# by Rexy
6
# by Rexy
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 launched by coova after each logout
9
# This script is launched 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"
-
 
13
 
12
if [ -z $FRAMED_IP_ADDRESS ]; then
14
if [ -z $FRAMED_IP_ADDRESS ]; then
13
	exit 1
15
	exit 1
14
fi
16
fi
15
 
17
 
-
 
18
# Remove user from his IPSET
-
 
19
 
16
# Remove user from his IPSET (depending on FILTER_ID)
20
db_query="SELECT attribute, value FROM (( SELECT attribute, value FROM radreply WHERE (attribute='Alcasar-Filter' OR attribute='Alcasar-Filter-Proto' OR attribute='Alcasar-Status-Open-Required') AND username='$USER_NAME') UNION ( SELECT attribute, value FROM radgroupreply gr LEFT JOIN radusergroup ug ON gr.groupname = ug.groupname WHERE (attribute='Alcasar-Filter' OR attribute='Alcasar-Filter-Proto' OR attribute='Alcasar-Status-Open-Required') AND username = '$USER_NAME' ORDER BY ug.priority)) attrs GROUP BY attribute;"
-
 
21
db_res=$(mysql -u root -p$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-) -D radius -e "$db_query" -Ns)
17
 
22
 
18
# FilterID Byte N°0 to 7
-
 
19
#  0: profile_1 (WEB)
-
 
20
#  1: profile_2 (WEB + Mail + Remote access)
23
filter=$(echo "$db_res"             | awk '$1 == "Alcasar-Filter"               { print $2 }')
21
#  2: profile_3 (Custom)
-
 
22
#  3: warn_user (if imputability report has been generated)
24
filterProto=$(echo "$db_res"        | awk '$1 == "Alcasar-Filter-Proto"         { print $2 }')
23
#  4: status_open_required (check user activity through status page)
25
statusOpenRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Open-Required" { print $2 }')
24
#  5: WL
-
 
25
#  6: BL
-
 
26
#  7: HAVP
-
 
27
 
26
 
28
if [ ${FILTER_ID:5:1} == '1' ]; then	# HAVP_WL
27
if [ "$filter" == '4' ]; then	# HAVP_WL
29
	set_filter="havp_wl"
28
	set_filter="havp_wl"
30
elif [ ${FILTER_ID:6:1} == '1' ]; then	# HAVP_BL
29
elif [ "$filter" == '3' ]; then	# HAVP_BL
31
	set_filter="havp_bl"
30
	set_filter="havp_bl"
32
elif [ ${FILTER_ID:7:1} == '1' ]; then	# HAVP
31
elif [ "$filter" == '2' ]; then	# HAVP
33
	set_filter="havp"
32
	set_filter="havp"
34
else					# NOT_FILTERED
33
else				# NOT_FILTERED
35
	set_filter="not_filtered"
34
	set_filter="not_filtered"
36
fi
35
fi
37
 
36
 
38
if [ ${FILTER_ID:2:1} == '1' ]; then	# PROFILE 3 (Custom)
37
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
39
	set_proto="proto_3";
38
	set_filterProto="proto_3";
40
elif [ ${FILTER_ID:1:1} == '1' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
39
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
41
	set_proto="proto_2";
40
	set_filterProto="proto_2";
42
elif [ ${FILTER_ID:0:1} == '1' ]; then	# PROFILE 1 (WEB)
41
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
43
	set_proto="proto_1";
42
	set_filterProto="proto_1";
44
else					# PROFILE 0 (Not filtered)
43
else					# PROFILE 0 (Not filtered)
45
	set_proto="proto_0";
44
	set_filterProto="proto_0";
46
fi
45
fi
47
 
46
 
48
ipset del $set_filter $FRAMED_IP_ADDRESS
47
ipset del $set_filter      $FRAMED_IP_ADDRESS
49
ipset del $set_proto $FRAMED_IP_ADDRESS
48
ipset del $set_filterProto $FRAMED_IP_ADDRESS
50
 
49
 
51
# Remove IP address from active users
50
# Remove IP address from active users
52
current_users_file="/var/tmp/havp/current_users.txt"
51
current_users_file="/var/tmp/havp/current_users.txt"
53
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
52
[ -e $current_users_file ] && sed -i "/^$FRAMED_IP_ADDRESS:/d" $current_users_file
54
 
53
 
55
# Debug : show all the coova parse variables (+ $set_filter + $set_proto).
54
# Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
56
# see "/src/chilli.c" for the complete list of parse variables
55
# see "/src/chilli.c" for the complete list of parse variables
57
#echo "-----------------------------------------------" >> /tmp/debug-condown.txt
56
#echo "-----------------------------------------------" >> /tmp/debug-condown.txt
58
#echo `date` >> /tmp/debug-condown.txt
57
#echo `date` >> /tmp/debug-condown.txt
59
#for i in LAYER3 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 WISPR-SESSION_TERMINATE_TIME CHILLISPOT_MAX_INPUT_OCTETS CHILLISPOT_MAX_OUTPUT_OCTETS CHILLISPOT_MAX_TOTAL_OCTETS INPUT_OCTETS OUTPUT_OCTETS SESSION_TIME IDLE_TIME LOCATION OLD_LOCATION TERMINATE_CAUSE
58
#for i in LAYER3 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 WISPR-SESSION_TERMINATE_TIME CHILLISPOT_MAX_INPUT_OCTETS CHILLISPOT_MAX_OUTPUT_OCTETS CHILLISPOT_MAX_TOTAL_OCTETS INPUT_OCTETS OUTPUT_OCTETS SESSION_TIME IDLE_TIME LOCATION OLD_LOCATION TERMINATE_CAUSE
60
#do
59
#do
61
#	echo "$i : ${!i}" >> /tmp/debug-condown.txt
60
#	echo "$i : ${!i}" >> /tmp/debug-condown.txt
62
#done
61
#done
63
#echo "set_filter : $set_filter" >> /tmp/debug-condown.txt
62
#echo "set_filter : $set_filter" >> /tmp/debug-condown.txt
64
#echo "set_proto : $set_proto" >> /tmp/debug-condown.txt
63
#echo "set_filterProto : $set_filterProto" >> /tmp/debug-condown.txt