1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
#
|
2 |
#
|
3 |
# $Id: alcasar-migration-3.3.0_dbRadiusAttrs.sh 2664 2018-11-19 17:35:12Z tom.houdayer $
|
3 |
# $Id: alcasar-migration-3.3.0_dbRadiusAttrs.sh 2664 2018-11-19 17:35:12Z tom.houdayer $
|
4 |
#
|
4 |
#
|
5 |
# alcasar-migration-3.3.0_dbRadiusAttrs.sh
|
5 |
# alcasar-migration-3.3.0_dbRadiusAttrs.sh
|
6 |
# by Tom HOUDAYER
|
6 |
# by Tom HOUDAYER
|
7 |
#
|
7 |
#
|
8 |
# This script is distributed under the Gnu General Public License (GPL)
|
8 |
# This script is distributed under the Gnu General Public License (GPL)
|
9 |
#
|
9 |
#
|
10 |
# Migrate user database to ALCASAR 3.3.0
|
10 |
# Migrate user database to ALCASAR 3.3.0
|
11 |
# Changes:
|
11 |
# Changes:
|
12 |
# - Explode "Filter-Id" RADIUS attribute into "Alcasar-Filter", "Alcasar-Protocols-Filter", "Alcasar-Status-Page-Must-Stay-Open" and "Alcasar-Imputability-Warning"
|
12 |
# - Explode "Filter-Id" RADIUS attribute into "Alcasar-Filter", "Alcasar-Protocols-Filter", "Alcasar-Status-Page-Must-Stay-Open" and "Alcasar-Imputability-Warning"
|
13 |
# - Rename "ChilliSpot-*" RADIUS attribute to "CoovaChilli-*"
|
13 |
# - Rename "ChilliSpot-*" RADIUS attribute to "CoovaChilli-*"
|
14 |
# - Rename "Max-All-Session" RADIUS attribute to "Alcasar-Expire-After"
|
14 |
# - Rename "Max-All-Session" RADIUS attribute to "Alcasar-Expire-After"
|
15 |
|
15 |
|
16 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
16 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
17 |
DB_PASS=$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-)
|
17 |
DB_PASS=$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-)
|
18 |
|
18 |
|
19 |
DRY_RUN=false
|
19 |
DRY_RUN=false
|
20 |
|
20 |
|
21 |
if [ $# -eq 1 ] && [ "$1" == "--simulation" ]; then
|
21 |
if [ $# -eq 1 ] && [ "$1" == "--simulation" ]; then
|
22 |
DRY_RUN=true
|
22 |
DRY_RUN=true
|
23 |
fi
|
23 |
fi
|
24 |
|
24 |
|
25 |
db_query () {
|
25 |
db_query () {
|
26 |
if $DRY_RUN && [[ ! "$1" =~ ^'SELECT ' ]]; then
|
26 |
if $DRY_RUN && [[ ! "$1" =~ ^'SELECT ' ]]; then
|
27 |
echo "[SQL] request: \"$1\""
|
27 |
echo "[SQL] request: \"$1\""
|
28 |
else
|
28 |
else
|
29 |
mysql -u root -p"$DB_PASS" -D radius -e "$1" -Ns
|
29 |
mysql -u root -p"$DB_PASS" -D radius -e "$1" -Ns
|
30 |
[ $? -ne 0 ] && echo "[SQL] ERROR (\"$1\")"
|
30 |
[ $? -ne 0 ] && echo "[SQL] ERROR (\"$1\")"
|
31 |
fi
|
31 |
fi
|
32 |
}
|
32 |
}
|
33 |
|
33 |
|
34 |
for step in $(seq 1 2); do
|
34 |
for step in $(seq 1 2); do
|
35 |
if [ $step -eq 1 ]; then
|
35 |
if [ $step -eq 1 ]; then
|
36 |
tableNameCheck='radcheck'
|
36 |
tableNameCheck='radcheck'
|
37 |
tableNameReply='radreply'
|
37 |
tableNameReply='radreply'
|
38 |
loginName='username'
|
38 |
loginName='username'
|
39 |
else
|
39 |
else
|
40 |
tableNameCheck='radgroupcheck'
|
40 |
tableNameCheck='radgroupcheck'
|
41 |
tableNameReply='radgroupreply'
|
41 |
tableNameReply='radgroupreply'
|
42 |
loginName='groupname'
|
42 |
loginName='groupname'
|
43 |
fi
|
43 |
fi
|
44 |
|
44 |
|
45 |
# Explode "Filter-Id" RADIUS attribute into "Alcasar-Filter", "Alcasar-Protocols-Filter", "Alcasar-Status-Page-Must-Stay-Open" and "Alcasar-Imputability-Warning"
|
45 |
# Explode "Filter-Id" RADIUS attribute into "Alcasar-Filter", "Alcasar-Protocols-Filter", "Alcasar-Status-Page-Must-Stay-Open" and "Alcasar-Imputability-Warning"
|
46 |
db_res=$(db_query "SELECT $loginName, value FROM $tableNameReply WHERE attribute = 'Filter-Id';")
|
46 |
db_res=$(db_query "SELECT $loginName, value FROM $tableNameReply WHERE attribute = 'Filter-Id';")
|
47 |
if [ -n "$db_res" ]; then
|
47 |
if [ -n "$db_res" ]; then
|
48 |
echo "$(echo "$db_res" | wc -l) \"Filter-Id\" found in table \"$tableNameReply\"."
|
48 |
echo "$(echo "$db_res" | wc -l) \"Filter-Id\" found in table \"$tableNameReply\"."
|
49 |
while read -r line; do
|
49 |
while read -r line; do
|
50 |
login=$(echo "$line" | cut -f1)
|
50 |
login=$(echo "$line" | cut -f1)
|
51 |
filterId=$(echo "$line" | cut -f2)
|
51 |
filterId=$(echo "$line" | cut -f2)
|
52 |
echo " $login ($filterId)..."
|
52 |
echo " $login ($filterId)..."
|
53 |
|
53 |
|
54 |
if [ ${filterId:5:1} == '1' ]; then # Filter: HAVP_WL
|
54 |
if [ ${filterId:5:1} == '1' ]; then # Filter: HAVP_WL
|
55 |
filter='4'
|
55 |
filter='4'
|
56 |
elif [ ${filterId:6:1} == '1' ]; then # Filter: HAVP_BL
|
56 |
elif [ ${filterId:6:1} == '1' ]; then # Filter: HAVP_BL
|
57 |
filter='3'
|
57 |
filter='3'
|
58 |
elif [ ${filterId:7:1} == '1' ]; then # Filter: HAVP
|
58 |
elif [ ${filterId:7:1} == '1' ]; then # Filter: HAVP
|
59 |
filter='2'
|
59 |
filter='2'
|
60 |
else # Filter: NOT_FILTERED
|
60 |
else # Filter: NOT_FILTERED
|
61 |
filter=''
|
61 |
filter=''
|
62 |
fi
|
62 |
fi
|
63 |
[ ! -z "$filter" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Filter','$filter', '=');"
|
63 |
[ ! -z "$filter" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Filter','$filter', '=');"
|
64 |
|
64 |
|
65 |
if [ ${filterId:2:1} == '1' ]; then # FilterProto: PROFILE 3 (Custom)
|
65 |
if [ ${filterId:2:1} == '1' ]; then # FilterProto: PROFILE 3 (Custom)
|
66 |
filterProto='4';
|
66 |
filterProto='4';
|
67 |
elif [ ${filterId:1:1} == '1' ]; then # FilterProto: PROFILE 2 (WEB + Mail + Remote access)
|
67 |
elif [ ${filterId:1:1} == '1' ]; then # FilterProto: PROFILE 2 (WEB + Mail + Remote access)
|
68 |
filterProto='3';
|
68 |
filterProto='3';
|
69 |
elif [ ${filterId:0:1} == '1' ]; then # FilterProto: PROFILE 1 (WEB)
|
69 |
elif [ ${filterId:0:1} == '1' ]; then # FilterProto: PROFILE 1 (WEB)
|
70 |
filterProto='2';
|
70 |
filterProto='2';
|
71 |
else # FilterProto: PROFILE 0 (Not filtered)
|
71 |
else # FilterProto: PROFILE 0 (Not filtered)
|
72 |
filterProto='';
|
72 |
filterProto='';
|
73 |
fi
|
73 |
fi
|
74 |
[ ! -z "$filterProto" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Protocols-Filter','$filterProto', '=');"
|
74 |
[ ! -z "$filterProto" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Protocols-Filter','$filterProto', '=');"
|
75 |
|
75 |
|
76 |
if [ ${filterId:4:1} == '1' ]; then # status_open_required
|
76 |
if [ ${filterId:4:1} == '1' ]; then # status_open_required
|
77 |
statusOpenRequired='2';
|
77 |
statusOpenRequired='2';
|
78 |
else
|
78 |
else
|
79 |
statusOpenRequired='';
|
79 |
statusOpenRequired='';
|
80 |
fi
|
80 |
fi
|
81 |
[ ! -z "$statusOpenRequired" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Status-Page-Must-Stay-Open','$statusOpenRequired', '=');"
|
81 |
[ ! -z "$statusOpenRequired" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Status-Page-Must-Stay-Open','$statusOpenRequired', '=');"
|
82 |
|
82 |
|
83 |
if [ ${filterId:3:1} == '1' ]; then # imputability warning
|
83 |
if [ ${filterId:3:1} == '1' ]; then # imputability warning
|
84 |
imputabilityWarning='1';
|
84 |
imputabilityWarning='1';
|
85 |
else
|
85 |
else
|
86 |
imputabilityWarning='';
|
86 |
imputabilityWarning='';
|
87 |
fi
|
87 |
fi
|
88 |
[ ! -z "$imputabilityWarning" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Imputability-Warning','$imputabilityWarning', '=');"
|
88 |
[ ! -z "$imputabilityWarning" ] && db_query "INSERT INTO $tableNameReply ($loginName, attribute, value, op) VALUES ('$login','Alcasar-Imputability-Warning','$imputabilityWarning', '=');"
|
89 |
|
89 |
|
90 |
db_query "DELETE FROM $tableNameReply WHERE attribute = 'Filter-Id' AND $loginName = '$login';"
|
90 |
db_query "DELETE FROM $tableNameReply WHERE attribute = 'Filter-Id' AND $loginName = '$login';"
|
91 |
done <<< "$db_res"
|
91 |
done <<< "$db_res"
|
92 |
fi
|
92 |
fi
|
93 |
|
93 |
|
94 |
# Rename "ChilliSpot-*" RADIUS attribute to "CoovaChilli-*"
|
94 |
# Rename "ChilliSpot-*" RADIUS attribute to "CoovaChilli-*"
|
95 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Input-Octets' WHERE attribute = 'ChilliSpot-Max-Input-Octets';"
|
95 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Input-Octets' WHERE attribute = 'ChilliSpot-Max-Input-Octets';"
|
96 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Output-Octets' WHERE attribute = 'ChilliSpot-Max-Output-Octets';"
|
96 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Output-Octets' WHERE attribute = 'ChilliSpot-Max-Output-Octets';"
|
97 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Total-Octets' WHERE attribute = 'ChilliSpot-Max-Total-Octets';"
|
97 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Max-Total-Octets' WHERE attribute = 'ChilliSpot-Max-Total-Octets';"
|
98 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Bandwidth-Max-Up' WHERE attribute = 'ChilliSpot-Bandwidth-Max-Up';"
|
98 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Bandwidth-Max-Up' WHERE attribute = 'ChilliSpot-Bandwidth-Max-Up';"
|
99 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Bandwidth-Max-Down' WHERE attribute = 'ChilliSpot-Bandwidth-Max-Down';"
|
99 |
db_query "UPDATE $tableNameReply SET attribute = 'CoovaChilli-Bandwidth-Max-Down' WHERE attribute = 'ChilliSpot-Bandwidth-Max-Down';"
|
100 |
|
100 |
|
101 |
# Rename "Max-All-Session" RADIUS attribute to "Alcasar-Expire-After"
|
101 |
# Rename "Max-All-Session" RADIUS attribute to "Alcasar-Expire-After"
|
102 |
db_query "UPDATE $tableNameCheck SET attribute = 'Alcasar-Expire-After' WHERE attribute = 'Max-All-Session';"
|
102 |
db_query "UPDATE $tableNameCheck SET attribute = 'Alcasar-Expire-After' WHERE attribute = 'Max-All-Session';"
|
103 |
done
|
103 |
done
|
104 |
|
104 |
|