Line 1... |
Line 1... |
1 |
#!/bin/sh
|
1 |
#!/bin/sh
|
2 |
#
|
2 |
#
|
3 |
# $Id: alcasar-conup.sh 2841 2020-06-28 21:49:00Z rexy $
|
3 |
# $Id: alcasar-conup.sh 2883 2020-11-15 21:14:52Z 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 launched by coova after each successfull login
|
10 |
# Ce script est lancé par coova à chaque connexion d'usager (authentification réussi)
|
10 |
# Ce script est lancé par coova à chaque connexion d'usager (authentification réussi)
|
11 |
|
11 |
|
- |
|
12 |
|
12 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
13 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
13 |
|
14 |
|
14 |
if [ -z $FRAMED_IP_ADDRESS ]; then
|
15 |
if [ -z $FRAMED_IP_ADDRESS ]; then
|
15 |
exit 1
|
16 |
exit 1
|
16 |
fi
|
17 |
fi
|
17 |
|
18 |
|
18 |
# Add user to his IPSET
|
19 |
# Retrieve alcasar special radius attributes
|
19 |
|
- |
|
20 |
db_query_additionalGroups=''
|
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 "
|
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 \
|
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')) ) \
|
26 |
( 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;"
|
27 |
) 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)
|
28 |
db_res=$(mysql -u root -p$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-) -D radius -e "$db_query" -Ns)
|
29 |
|
29 |
|
30 |
filter=$(echo "$db_res" | awk '$1 == "Alcasar-Filter" { print $2 }')
|
30 |
filter=$(echo "$db_res" | awk '$1 == "Alcasar-Filter" { print $2 }')
|
31 |
filterProto=$(echo "$db_res" | awk '$1 == "Alcasar-Protocols-Filter" { print $2 }')
|
31 |
filterProto=$(echo "$db_res" | awk '$1 == "Alcasar-Protocols-Filter" { print $2 }')
|
32 |
statusOpenRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
|
32 |
statusPageRequired=$(echo "$db_res" | awk '$1 == "Alcasar-Status-Page-Must-Stay-Open" { print $2 }')
|
33 |
|
33 |
|
- |
|
34 |
|
- |
|
35 |
# Add user to his IPSET
|
34 |
if [ "$filter" == '4' ]; then # AV_WL
|
36 |
if [ "$filter" == '4' ]; then # AV_WL
|
35 |
set_filter="av_wl"
|
37 |
set_filter="av_wl"
|
36 |
elif [ "$filter" == '3' ]; then # AV_BL
|
38 |
elif [ "$filter" == '3' ]; then # AV_BL
|
37 |
set_filter="av_bl"
|
39 |
set_filter="av_bl"
|
38 |
elif [ "$filter" == '2' ]; then # AV
|
40 |
elif [ "$filter" == '2' ]; then # AV
|
Line 52... |
Line 54... |
52 |
fi
|
54 |
fi
|
53 |
|
55 |
|
54 |
ipset add $set_filter $FRAMED_IP_ADDRESS
|
56 |
ipset add $set_filter $FRAMED_IP_ADDRESS
|
55 |
ipset add $set_filterProto $FRAMED_IP_ADDRESS
|
57 |
ipset add $set_filterProto $FRAMED_IP_ADDRESS
|
56 |
|
58 |
|
- |
|
59 |
# If status page isn't required, add user_IP with flag PERM in /tmp/current_users.txt
|
57 |
# Add user IP permanently to current_users.txt if no status_open_required
|
60 |
if [ "$statusPageRequired" == '2' ]; then # Status page is not required
|
58 |
current_users_file="/tmp/current_users.txt"
|
61 |
if [ ! -e /tmp/current_users.txt ]; then
|
59 |
[ ! -e $current_users_file ] && touch $current_users_file && chown apache:apache $current_users_file
|
62 |
touch /tmp/current_users.txt && chown apache:apache /tmp/current_users.txt
|
60 |
if [ "$statusOpenRequired" == '2' ]; then # no status_open_required
|
- |
|
- |
|
63 |
fi
|
61 |
echo "$FRAMED_IP_ADDRESS:PERM" >> $current_users_file
|
64 |
echo "$FRAMED_IP_ADDRESS:PERM" >> /tmp/current_users.txt
|
62 |
fi
|
65 |
fi
|
63 |
|
66 |
|
- |
|
67 |
#############################
|
64 |
# Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
|
68 |
## Debug : show all the coova parse variables (+ $set_filter + $set_filterProto).
|
65 |
# see "/src/chilli.c" for the complete list of parse variables
|
69 |
## see "/src/chilli.c" for the complete list of parse variables
|
- |
|
70 |
#debug_file="/tmp/debug-conup.txt"
|
66 |
#echo "-----------------------------------------------" >> /tmp/debug-conup.txt
|
71 |
#echo "-----------------------------------------------" >> $debug_file
|
67 |
#echo `date` >> /tmp/debug-conup.txt
|
72 |
#echo `date` >> $debug_file
|
68 |
#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
|
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
|
69 |
#do
|
74 |
#do
|
- |
|
75 |
# echo -n "$i=" >> $debug_file
|
- |
|
76 |
# if [[ -v $i ]];
|
- |
|
77 |
# then
|
70 |
# echo "$i : ${!i}" >> /tmp/debug-conup.txt
|
78 |
# echo -n "${!i}; " >> $debug_file
|
- |
|
79 |
# else
|
- |
|
80 |
# echo -n "not defined; " >> $debug_file
|
- |
|
81 |
# fi
|
71 |
#done
|
82 |
#done
|
- |
|
83 |
#echo >> $debug_file
|
72 |
#echo "set_filter : $set_filter" >> /tmp/debug-conup.txt
|
84 |
#echo "set_filter : $set_filter" >> $debug_file
|
73 |
#echo "set_filterProto : $set_filterProto" >> /tmp/debug-conup.txt
|
85 |
#echo "set_filterProto : $set_filterProto" >> $debug_file
|
- |
|
86 |
#echo "statusPageRequired : $statusPageRequired" >> $debug_file
|
74 |
|
87 |
## END DEBUG
|
- |
|
88 |
#################################
|