3202 |
rexy |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# alcasar-migration_db-3.7.0.sh
|
|
|
4 |
# by Richard REY (Rexy)
|
|
|
5 |
#
|
|
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
|
|
7 |
#
|
|
|
8 |
# Migrate database structure to ALCASAR 3.7.0
|
|
|
9 |
# Changes:
|
|
|
10 |
# - Update radacct table
|
|
|
11 |
# - remove 'groupname', 'acctstartdelay', 'acctstopdelay' & 'xascendsessionsvrkey'
|
|
|
12 |
# - add 'acctupdatetime', 'acctinterval', 'framedipv6address', 'framedipv6prefix', 'framedinterfaceid', 'delegatedipv6prefix' & 'class'
|
|
|
13 |
# - change 'acctsessionid', 'acctuniqueid', 'nasportid', 'connectinfo start' & 'connectinfo stop'
|
|
|
14 |
# - KEY add: 'framedipv6address', 'framedipv6prefix', 'framedinterfaceid', 'delegatedipv6prefix', acctinterval & class
|
|
|
15 |
# - Update radpostauth table
|
|
|
16 |
# - add 'class'
|
|
|
17 |
# - KEY add: 'class' & 'username'
|
|
|
18 |
# - add nas table
|
|
|
19 |
|
|
|
20 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
|
|
21 |
DB_PASS=$(cat $PASSWD_FILE | grep ^db_root= | cut -d'=' -f2-)
|
|
|
22 |
|
|
|
23 |
DRY_RUN=false
|
|
|
24 |
|
|
|
25 |
if [ $# -eq 1 ] && [ "$1" == "--simulation" ]; then
|
|
|
26 |
DRY_RUN=true
|
|
|
27 |
fi
|
|
|
28 |
|
|
|
29 |
db_query () {
|
|
|
30 |
if $DRY_RUN && [[ ! "$1" =~ ^'SELECT ' ]]; then
|
|
|
31 |
echo "[SQL] request: \"$1\""
|
|
|
32 |
else
|
|
|
33 |
mysql -u root -p"$DB_PASS" -D radius -e "$1" -Ns
|
|
|
34 |
[ $? -ne 0 ] && echo "[SQL] ERROR (\"$1\")"
|
|
|
35 |
fi
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
# Update radacct table attributes
|
|
|
39 |
db_query "ALTER TABLE radacct DROP COLUMN IF EXISTS groupname, DROP COLUMN IF EXISTS acctstartdelay, DROP COLUMN IF EXISTS acctstopdelay, DROP COLUMN IF EXISTS xascendsessionsvrkey;"
|
|
|
40 |
|
|
|
41 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS acctupdatetime datetime DEFAULT NULL;"
|
|
|
42 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS acctinterval int(12) DEFAULT NULL;"
|
|
|
43 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS framedipv6address varchar(45) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
44 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS framedipv6prefix varchar(45) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
45 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS framedinterfaceid varchar(45) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
46 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS delegatedipv6prefix varchar(45) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
47 |
db_query "ALTER TABLE radacct ADD COLUMN IF NOT EXISTS class varchar(64) DEFAULT NULL;"
|
|
|
48 |
|
|
|
49 |
db_query "ALTER TABLE radacct MODIFY COLUMN acctsessionid varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
50 |
db_query "ALTER TABLE radacct MODIFY COLUMN acctuniqueid varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
51 |
db_query "ALTER TABLE radacct MODIFY COLUMN nasportid varchar(32) COLLATE utf8_bin NOT NULL DEFAULT '';"
|
|
|
52 |
db_query "ALTER TABLE radacct MODIFY COLUMN connectinfo_start varchar(128) COLLATE utf8_bin DEFAULT NULL;"
|
|
|
53 |
db_query "ALTER TABLE radacct MODIFY COLUMN connectinfo_stop varchar(128) COLLATE utf8_bin DEFAULT NULL;"
|
|
|
54 |
|
|
|
55 |
db_query "ALTER TABLE radacct ADD INDEX (framedipv6address);"
|
|
|
56 |
db_query "ALTER TABLE radacct ADD INDEX (framedipv6prefix);"
|
|
|
57 |
db_query "ALTER TABLE radacct ADD INDEX (framedinterfaceid);"
|
|
|
58 |
db_query "ALTER TABLE radacct ADD INDEX (delegatedipv6prefix);"
|
|
|
59 |
db_query "ALTER TABLE radacct ADD INDEX (acctinterval);"
|
|
|
60 |
db_query "ALTER TABLE radacct ADD INDEX (class);"
|
|
|
61 |
|
|
|
62 |
# update radpostauth table
|
|
|
63 |
db_query "ALTER TABLE radpostauth ADD COLUMN IF NOT EXISTS class varchar(64) DEFAULT NULL;"
|
|
|
64 |
db_query "ALTER TABLE radpostauth ADD INDEX (class);"
|
|
|
65 |
|
|
|
66 |
# add nas table
|
|
|
67 |
db_query "CREATE TABLE IF NOT EXISTS nas (
|
|
|
68 |
id int(10) NOT NULL AUTO_INCREMENT,
|
|
|
69 |
nasname varchar(128) NOT NULL,
|
|
|
70 |
shortname varchar(32),
|
|
|
71 |
type varchar(30) DEFAULT 'other',
|
|
|
72 |
ports int(5),
|
|
|
73 |
secret varchar(60) DEFAULT 'secret' NOT NULL,
|
|
|
74 |
server varchar(64),
|
|
|
75 |
community varchar(50),
|
|
|
76 |
description varchar(200) DEFAULT 'RADIUS Client',
|
|
|
77 |
PRIMARY KEY (id),
|
|
|
78 |
KEY nasname (nasname)
|
|
|
79 |
);"
|