Subversion Repositories ALCASAR

Rev

Rev 2841 | Rev 2884 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
872 richard 1
#!/bin/sh
2234 richard 2
#
3
# $Id: alcasar-conup.sh 2883 2020-11-15 21:14:52Z rexy $
4
#
872 richard 5
# alcasar-conup.sh
6
# by Rexy
7
# This script is distributed under the Gnu General Public License (GPL)
8
 
2184 richard 9
# This script is launched by coova after each successfull login
10
# Ce script est lancé par coova à chaque connexion d'usager (authentification réussi)
872 richard 11
 
2883 rexy 12
 
2501 tom.houday 13
PASSWD_FILE="/root/ALCASAR-passwords.txt"
14
 
2234 richard 15
if [ -z $FRAMED_IP_ADDRESS ]; then
16
	exit 1
2184 richard 17
fi
2069 richard 18
 
2883 rexy 19
# Retrieve alcasar special radius attributes 
2712 tom.houday 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 ( \
2883 rexy 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 \
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', 'Alcasar-Status-Page-Must-Stay-Open')) ORDER BY ug.priority ) UNION \
25
	$db_query_additionalGroups \
2883 rexy 26
	( SELECT attribute, value FROM radgroupreply WHERE groupname = 'default' AND (attribute IN ('Alcasar-Filter', 'Alcasar-Protocols-Filter', 'Alcasar-Status-Page-Must-Stay-Open')) ) \
2712 tom.houday 27
) attrs GROUP BY attribute;"
2501 tom.houday 28
db_res=$(mysql -u root -p$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-) -D radius -e "$db_query" -Ns)
2006 raphael.pi 29
 
2692 tom.houday 30
filter=$(echo "$db_res"             | awk '$1 == "Alcasar-Filter"                     { print $2 }')
31
filterProto=$(echo "$db_res"        | awk '$1 == "Alcasar-Protocols-Filter"           { print $2 }')
2883 rexy 32
statusPageRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
2501 tom.houday 33
 
2883 rexy 34
 
35
# Add user to his IPSET
2841 rexy 36
if [ "$filter" == '4' ]; then	# AV_WL
37
	set_filter="av_wl"
38
elif [ "$filter" == '3' ]; then	# AV_BL
39
	set_filter="av_bl"
40
elif [ "$filter" == '2' ]; then	# AV
41
	set_filter="av"
2501 tom.houday 42
else				# NOT_FILTERED
2234 richard 43
	set_filter="not_filtered"
2006 raphael.pi 44
fi
45
 
2501 tom.houday 46
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
47
	set_filterProto="proto_3";
48
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
49
	set_filterProto="proto_2";
50
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
51
	set_filterProto="proto_1";
2234 richard 52
else					# PROFILE 0 (Not filtered)
2501 tom.houday 53
	set_filterProto="proto_0";
2006 raphael.pi 54
fi
55
 
2501 tom.houday 56
ipset add $set_filter      $FRAMED_IP_ADDRESS
57
ipset add $set_filterProto $FRAMED_IP_ADDRESS
2184 richard 58
 
2883 rexy 59
# If status page isn't required, add user_IP with flag PERM in /tmp/current_users.txt
60
if [ "$statusPageRequired" == '2' ]; then	# Status page is not required
61
	if [ ! -e /tmp/current_users.txt ]; then
62
		touch /tmp/current_users.txt && chown apache:apache /tmp/current_users.txt
63
	fi
64
	echo "$FRAMED_IP_ADDRESS:PERM" >> /tmp/current_users.txt
2394 tom.houday 65
fi
66
 
2883 rexy 67
#############################
68
## Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
69
## see "/src/chilli.c" for the complete list of parse variables
70
#debug_file="/tmp/debug-conup.txt"
71
#echo "-----------------------------------------------" >> $debug_file
72
#echo `date` >> $debug_file
73
#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 74
#do
2883 rexy 75
#	echo -n "$i=" >> $debug_file
76
#	if [[ -v $i ]];
77
#	then
78
#		echo -n "${!i}; " >> $debug_file
79
#	else
80
#		echo -n "not defined; " >> $debug_file
81
#	fi
2184 richard 82
#done
2883 rexy 83
#echo >> $debug_file
84
#echo "set_filter : $set_filter" >> $debug_file
85
#echo "set_filterProto : $set_filterProto" >> $debug_file
86
#echo "statusPageRequired : $statusPageRequired" >> $debug_file
87
## END DEBUG
88
#################################