Subversion Repositories ALCASAR

Rev

Rev 2501 | Rev 2692 | 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 2505 2018-03-11 13:41:00Z tom.houdayer $
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
 
2501 tom.houday 12
PASSWD_FILE="/root/ALCASAR-passwords.txt"
13
 
2234 richard 14
if [ -z $FRAMED_IP_ADDRESS ]; then
15
	exit 1
2184 richard 16
fi
2069 richard 17
 
2501 tom.houday 18
# Add user to his IPSET
2006 raphael.pi 19
 
2505 tom.houday 20
db_query="SELECT attribute, value FROM (( SELECT attribute, value FROM radreply WHERE (attribute='Alcasar-Filter' OR attribute='Alcasar-Protocols-Filter' OR attribute='Alcasar-Status-Page-Must-Stay-Open') 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-Protocols-Filter' OR attribute='Alcasar-Status-Page-Must-Stay-Open') AND username = '$USER_NAME' ORDER BY ug.priority)) attrs GROUP BY attribute;"
2501 tom.houday 21
db_res=$(mysql -u root -p$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-) -D radius -e "$db_query" -Ns)
2006 raphael.pi 22
 
2501 tom.houday 23
filter=$(echo "$db_res"             | awk '$1 == "Alcasar-Filter"               { print $2 }')
2505 tom.houday 24
filterProto=$(echo "$db_res"        | awk '$1 == "Alcasar-Protocols-Filter"         { print $2 }')
25
statusOpenRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
2501 tom.houday 26
 
27
if [ "$filter" == '4' ]; then	# HAVP_WL
2249 tom.houday 28
	set_filter="havp_wl"
2501 tom.houday 29
elif [ "$filter" == '3' ]; then	# HAVP_BL
2234 richard 30
	set_filter="havp_bl"
2501 tom.houday 31
elif [ "$filter" == '2' ]; then	# HAVP
2249 tom.houday 32
	set_filter="havp"
2501 tom.houday 33
else				# NOT_FILTERED
2234 richard 34
	set_filter="not_filtered"
2006 raphael.pi 35
fi
36
 
2501 tom.houday 37
if [ "$filterProto" == '4' ]; then	# PROFILE 3 (Custom)
38
	set_filterProto="proto_3";
39
elif [ "$filterProto" == '3' ]; then	# PROFILE 2 (WEB + Mail + Remote access)
40
	set_filterProto="proto_2";
41
elif [ "$filterProto" == '2' ]; then	# PROFILE 1 (WEB)
42
	set_filterProto="proto_1";
2234 richard 43
else					# PROFILE 0 (Not filtered)
2501 tom.houday 44
	set_filterProto="proto_0";
2006 raphael.pi 45
fi
46
 
2501 tom.houday 47
ipset add $set_filter      $FRAMED_IP_ADDRESS
48
ipset add $set_filterProto $FRAMED_IP_ADDRESS
2184 richard 49
 
2394 tom.houday 50
# Add user IP permanently to current_users.txt if no status_open_required
51
current_users_file="/var/tmp/havp/current_users.txt"
52
[ ! -e $current_users_file ] && touch $current_users_file && chown apache:apache $current_users_file
2501 tom.houday 53
if [ "$statusOpenRequired" == '2' ]; then	# no status_open_required
2394 tom.houday 54
	echo "$FRAMED_IP_ADDRESS:PERM" >> $current_users_file
55
fi
56
 
2501 tom.houday 57
# Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
2184 richard 58
# see "/src/chilli.c" for the complete list of parse variables
59
#echo "-----------------------------------------------" >> /tmp/debug-conup.txt
60
#echo `date` >> /tmp/debug-conup.txt
61
#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
62
#do
63
#	echo "$i : ${!i}" >> /tmp/debug-conup.txt
64
#done
2234 richard 65
#echo "set_filter : $set_filter" >> /tmp/debug-conup.txt
2501 tom.houday 66
#echo "set_filterProto : $set_filterProto" >> /tmp/debug-conup.txt
2184 richard 67