-
Notifications
You must be signed in to change notification settings - Fork 1
/
radius-nas
executable file
·144 lines (112 loc) · 2.35 KB
/
radius-nas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#! /bin/bash
. /etc/freeradius-bash-admin.conf
_value() {
local COLUMN="$1"
_mysql_silent "
SELECT
$COLUMN
FROM nas
WHERE shortname = '$SHORT_NAME';
"
}
_add() {
_prompt SHORT_NAME "Short name"
_prompt SECRET "Secret" $(_password_generator)
_prompt IP "IP address"
_prompt DESCRIPTION "Description"
_mysql "
INSERT
INTO nas (nasname, shortname, secret, description)
VALUES ('$IP','$SHORT_NAME','$SECRET', '$DESCRIPTION');
"
}
_show() {
local SHORT_NAME="$1"
if [ -z $SHORT_NAME ]; then
echo "Usage: radius-nas show <shortname> or <all>"
exit 1
fi
if [ "$SHORT_NAME" != 'all' ]; then
local WHERE="WHERE shortname = '$SHORT_NAME'"
fi
_mysql "
SELECT
shortname as Shortname,
secret AS Secret,
nasname AS 'IP address',
description AS Description
FROM nas
$WHERE
;
"
}
_update() {
local SHORT_NAME="$1"
if [ -z "$SHORT_NAME" ] ; then
echo "Usage: radius-nas update <shortname>"
exit 1
fi
_prompt SHORT_NAME_UPDATE "Short name" "$(_value shortname)"
_prompt SECRET "Secret" "$(_value secret)"
_prompt IP "IP address" "$(_value nasname)"
_prompt DESCRIPTION "Description" "$(_value description)"
_mysql "
UPDATE nas
SET
nasname = '$IP',
shortname = '$SHORT_NAME_UPDATE',
secret = '$SECRET',
description = '$DESCRIPTION'
WHERE shortname = '$SHORT_NAME';
"
_show "$SHORT_NAME_UPDATE"
}
_delete() {
local SHORT_NAME="$1"
if [ -z "$SHORT_NAME" ]; then
echo "Usage: radius-nas delete <shortname>"
exit 1
fi
_prompt_yes "Delete nas (shortname: '$SHORT_NAME')?"
_mysql "
DELETE
FROM nas
WHERE shortname = '$SHORT_NAME';
"
}
_usage() {
echo "Usage: radius-nas <options>
-> Manage the network access server (Access points).
Options:
add : Add a NAS.
show <shortname> or <all> : Show a NAS.
update <shortname> : Update a NAS.
delete <shortname> : Delete a NAS by shortname.
help : Show this help topic.
"
}
case "$1" in
add)
shift 1
_add $@
;;
show)
shift 1
_show $@
;;
update)
shift 1
_update $@
;;
delete)
shift 1
_delete $@
;;
help)
_usage
;;
*)
_usage
;;
esac
# vim: set ts=2 sw=2 sts=2 et :