2088 |
raphael.pi |
1 |
#!/bin/sh
|
2234 |
richard |
2 |
#
|
|
|
3 |
# $Id: alcasar-macup.sh 2274 2017-06-06 06:12:50Z richard $
|
|
|
4 |
#
|
|
|
5 |
# Le script 'macup' est appelé par coovachilli lorsqu'il attribut une @IP à une @MAC.
|
2274 |
richard |
6 |
# Il permet d'affecter le bon ipset aux @MAC authorisées
|
2088 |
raphael.pi |
7 |
|
2234 |
richard |
8 |
if [ -z $CALLING_STATION_ID ]; then
|
|
|
9 |
exit 1
|
|
|
10 |
fi
|
2088 |
raphael.pi |
11 |
|
|
|
12 |
chilli_current_mac=$(chilli_query list | grep $CALLING_STATION_ID)
|
|
|
13 |
is_connected=$(echo $chilli_current_mac | cut -d' ' -f5)
|
|
|
14 |
current_mac=$(echo $chilli_current_mac | cut -d' ' -f1)
|
|
|
15 |
current_name=$(echo $chilli_current_mac | cut -d' ' -f6)
|
|
|
16 |
current_ip=$(echo $chilli_current_mac | cut -d' ' -f2)
|
|
|
17 |
|
2094 |
raphael.pi |
18 |
|
2274 |
richard |
19 |
if [ $is_connected == "1" ] && [ $current_mac == $current_name ]; then # only for authenticated MAC
|
2094 |
raphael.pi |
20 |
#Lecture du filter-id dans la DB radius afin de placer l'équipement réseau dans le bon ipset
|
|
|
21 |
#Un équipement autorisé "à chaud" sera placé dans l'ipset 'not_filtered' + pas de filtrage de protocole (proto_0)
|
|
|
22 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
2234 |
richard |
23 |
QUERY="SELECT value FROM radreply WHERE attribute='Filter-Id' AND username='$current_mac';"
|
|
|
24 |
FILTER_ID=$(mysql -D radius -u root -p$(cat $PASSWD_FILE | grep "root /" | rev | cut -d' ' -f1 | rev) -e "$QUERY" -Ns)
|
2094 |
raphael.pi |
25 |
|
2234 |
richard |
26 |
# FilterID Byte N°0 to 7
|
|
|
27 |
# 0: profile_1 (WEB)
|
|
|
28 |
# 1: profile_2 (WEB + Mail + Remote access)
|
|
|
29 |
# 2: profile_3 (Custom)
|
|
|
30 |
# 3: warn_user (if imputability report has been generated)
|
|
|
31 |
# 5: WL
|
|
|
32 |
# 6: BL
|
|
|
33 |
# 7: HAVP
|
2094 |
raphael.pi |
34 |
|
2249 |
tom.houday |
35 |
if [ ${FILTER_ID:5:1} == '1' ]; then # HAVP_WL
|
|
|
36 |
set_filter="havp_wl"
|
2234 |
richard |
37 |
elif [ ${FILTER_ID:6:1} == '1' ]; then # HAVP_BL
|
|
|
38 |
set_filter="havp_bl"
|
2249 |
tom.houday |
39 |
elif [ ${FILTER_ID:7:1} == '1' ]; then # HAVP
|
|
|
40 |
set_filter="havp"
|
2234 |
richard |
41 |
else # NOT_FILTERED
|
|
|
42 |
set_filter="not_filtered"
|
2094 |
raphael.pi |
43 |
fi
|
|
|
44 |
|
2249 |
tom.houday |
45 |
if [ ${FILTER_ID:2:1} == '1' ]; then # PROFILE 3 (Custom)
|
|
|
46 |
set_proto="proto_3";
|
2234 |
richard |
47 |
elif [ ${FILTER_ID:1:1} == '1' ]; then # PROFILE 2 (WEB + Mail + Remote access)
|
|
|
48 |
set_proto="proto_2";
|
2249 |
tom.houday |
49 |
elif [ ${FILTER_ID:0:1} == '1' ]; then # PROFILE 1 (WEB)
|
|
|
50 |
set_proto="proto_1";
|
2234 |
richard |
51 |
else # PROFILE 0 (Not filtered)
|
|
|
52 |
set_proto="proto_0";
|
2094 |
raphael.pi |
53 |
fi
|
|
|
54 |
|
2234 |
richard |
55 |
ipset add $set_filter $current_ip
|
2094 |
raphael.pi |
56 |
ipset add $set_proto $current_ip
|
2088 |
raphael.pi |
57 |
fi
|