Subversion Repositories ALCASAR

Rev

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

Rev 2884 Rev 2886
Line 1... Line 1...
1
#!/bin/sh
1
#!/bin/sh
2
#
2
#
3
# $Id: alcasar-conup.sh 2884 2020-11-16 22:12:53Z rexy $
3
# $Id: alcasar-conup.sh 2886 2020-11-23 22:50:01Z rexy $
4
#
4
#
5
# alcasar-conup.sh
5
# alcasar-conup.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 successfull login
9
# This script is started by coova after each successfull login
10
# Ce script est lancé par coova à chaque connexion d'usager (authentification réussi)
10
# Ce script est démarré par coova à chaque connexion d'usager (authentification réussi)
11
 
11
 
12
 
12
 
13
PASSWD_FILE="/root/ALCASAR-passwords.txt"
13
PASSWD_FILE="/root/ALCASAR-passwords.txt"
-
 
14
DB_USER=`cat $PASSWD_FILE|grep ^db_user=|cut -d'=' -f2`
-
 
15
DB_PASSWORD=`cat $PASSWD_FILE|grep ^db_password=|cut -d'=' -f2`
14
 
16
 
15
if [ -z $FRAMED_IP_ADDRESS ]; then
17
if [ -z $FRAMED_IP_ADDRESS ]; then
16
	exit 1
18
	exit 1
17
fi
19
fi
18
 
20
 
19
# Retrieve alcasar special radius attributes 
21
# Retrieve 3 alcasar special radius attributes (search order : default group, then user's group, then user)
20
db_query_additionalGroups=''
-
 
21
[ -n "$FILTER_ID" ] && db_query_additionalGroups="( SELECT attribute, value FROM radgroupreply WHERE groupname = '$FILTER_ID' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) UNION "
-
 
22
db_query="SELECT attribute, value FROM ( \
22
db_query="SELECT attribute, value FROM ( \
23
	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) UNION \
23
 	( SELECT attribute, value FROM radreply WHERE username = '$USER_NAME' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) UNION \
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', 'Alcasar-Status-Page-Must-Stay-Open')) ORDER BY ug.priority ) UNION \
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', 'Alcasar-Status-Page-Must-Stay-Open')) ORDER BY ug.priority ) UNION \
25
	$db_query_additionalGroups \
-
 
26
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) \
25
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) \
27
) attrs GROUP BY attribute;"
26
) attrs GROUP BY attribute;"
28
db_res=$(mysql -u root -p$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-) -D radius -e "$db_query" -Ns)
27
db_res=$(mysql -u$DB_USER -p$DB_PASSWORD -D radius -e "$db_query" -Ns)
29
 
28
 
30
filter=$(echo "$db_res"             | awk '$1 == "Alcasar-Filter"                     { print $2 }')
29
filter=$(echo "$db_res"             | awk '$1 == "Alcasar-Filter"                     { print $2 }')
31
filterProto=$(echo "$db_res"        | awk '$1 == "Alcasar-Protocols-Filter"           { print $2 }')
30
filterProto=$(echo "$db_res"        | awk '$1 == "Alcasar-Protocols-Filter"           { print $2 }')
32
statusPageRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
31
statusPageRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
33
 
32
 
Line 51... Line 50...
51
	set_filterProto="proto_1";
50
	set_filterProto="proto_1";
52
else					# PROFILE 0 (Not filtered)
51
else					# PROFILE 0 (Not filtered)
53
	set_filterProto="proto_0";
52
	set_filterProto="proto_0";
54
fi
53
fi
55
 
54
 
-
 
55
# Add user to his IPSET
56
ipset add $set_filter      $FRAMED_IP_ADDRESS
56
ipset add $set_filter      $FRAMED_IP_ADDRESS
57
ipset add $set_filterProto $FRAMED_IP_ADDRESS
57
ipset add $set_filterProto $FRAMED_IP_ADDRESS
58
 
58
 
-
 
59
# If status page isn't required :
59
# If status page isn't required, add user_IP with flag PERM in /tmp/current_users.txt
60
#	-add user_IP with flag PERM in /tmp/current_users.txt (watchdog remove these @IP at midnight)
-
 
61
#	if the user has the "Expiration" attribute, add its @MAC as an authenticated user (with the same user's attributes)
60
if [ "$statusPageRequired" == '2' ]; then	# Status page is not required
62
if [ "$statusPageRequired" == '2' ]; then	# Status page is not required
61
	current_users_file="/tmp/current_users.txt"
63
	current_users_file="/tmp/current_users.txt"
62
	if [ ! -e $current_users_file ]; then
64
	if [ ! -e $current_users_file ]; then
63
		touch $current_users_file && chown root:apache $current_users_file && chmod 660 $current_users_file
65
		touch $current_users_file && chown root:apache $current_users_file && chmod 660 $current_users_file
64
    fi
66
    fi
65
	echo "$FRAMED_IP_ADDRESS:PERM" >> $current_users_file
67
	echo "$FRAMED_IP_ADDRESS:PERM" >> $current_users_file
66
fi
68
fi
67
 
69
 
68
#############################
70
#############################
69
## Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
71
## Debug : show all the coova parse variables (+ ALCASAR-Filter + ALCASAR-Protocols-Filter + Alcasar-Status-Page-Must-Stay-Open).
70
## see "/src/chilli.c" for the complete list of parse variables
72
## see "/src/chilli.c" for the complete list of parse variables
71
#debug_file="/tmp/debug-conup.txt"
73
#debug_file="/tmp/debug-conup.txt"
72
#echo "-----------------------------------------------" >> $debug_file
74
#echo "-----------------------------------------------" >> $debug_file
73
#echo `date` >> $debug_file
75
#echo `date` >> $debug_file
74
#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
Line 80... Line 82...
80
#	else
82
#	else
81
#		echo -n "not defined; " >> $debug_file
83
#		echo -n "not defined; " >> $debug_file
82
#	fi
84
#	fi
83
#done
85
#done
84
#echo >> $debug_file
86
#echo >> $debug_file
85
#echo "set_filter : $set_filter" >> $debug_file
87
#echo "ALCASAR-Filter : $set_filter" >> $debug_file
86
#echo "set_filterProto : $set_filterProto" >> $debug_file
88
#echo "ALCASAR-Protocols-Filter : $set_filterProto" >> $debug_file
87
#echo "statusPageRequired : $statusPageRequired" >> $debug_file
89
#echo "Alcasar-Status-Page-Must-Stay-Open : $statusPageRequired" >> $debug_file
88
## END DEBUG
90
## END DEBUG
89
#################################
91
#################################