-
Notifications
You must be signed in to change notification settings - Fork 907
/
kamdbctl.base
221 lines (180 loc) · 6.43 KB
/
kamdbctl.base
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
PATH=$PATH:/usr/local/sbin
# config vars
# name of the database to be used by Kamailio
DBNAME=${DBNAME:-kamailio}
# address of database server
DBHOST=${DBHOST:-localhost}
# user with full privileges over DBNAME database
DBRWUSER=${DBRWUSER:-kamailio}
# password user with full privileges over DBNAME database
DBRWPW=${DBRWPW:-kamailiorw}
# read-only user
DBROUSER=${DBROUSER:-kamailioro}
# password for read-only user
DBROPW=${DBROPW:-kamailioro}
# user name column
USERCOL=${USERCOL:-username}
# Describe what additional tables to install. Valid values for the variables
# below are yes/no/ask. With ask it will interactively ask the user for the
# answer, while yes/no allow for automated, unassisted installs.
INSTALL_EXTRA_TABLES=${INSTALL_EXTRA_TABLES:-ask}
INSTALL_PRESENCE_TABLES=${INSTALL_PRESENCE_TABLES:-ask}
INSTALL_DBUID_TABLES=${INSTALL_DBUID_TABLES:-ask}
# Used by dbtext and db_berkeley to define tables to be created, used by
# postgres to do the grants
STANDARD_TABLES=${STANDARD_TABLES:-version acc dbaliases domain domain_attrs
grp uri speed_dial lcr_gw lcr_rule lcr_rule_target pdt subscriber
location location_attrs re_grp trusted address missed_calls
usr_preferences aliases silo dialog dialog_vars dispatcher dialplan
acc_cdrs topos_d topos_t}
EXTRA_TABLES=${EXTRA_TABLES:-imc_members imc_rooms cpl sip_trace domainpolicy
carrierroute carrier_name domain_name carrierfailureroute userblacklist
globalblacklist htable purplemap uacreg pl_pipes mtree mtrees
sca_subscriptions mohqcalls mohqueues rtpproxy dr_gateways dr_rules
dr_gw_lists}
PRESENCE_TABLES=${PRESENCE_TABLES:-presentity active_watchers watchers xcap
pua rls_presentity rls_watchers}
DBUID_TABLES=${UID_TABLES:-uid_credentials uid_domain uid_domain_attrs
uid_global_attrs uid_uri uid_uri_attrs uid_user_attrs}
# SQL definitions
# If you change this definitions here, then you must change them
# in ../../lib/srdb1/schema/entities.xml too. They are used in this
# script and needed to be the same as in the database definitions.
# FIXME
FOREVER=${FOREVER:-2030-05-28 21:32:15}
# default location for config files
DEFAULT_CFG_DIR=/usr/local/etc/kamailio
# default location for data files
DEFAULT_DATA_DIR=/usr/local/share/kamailio
# Needed programs
MD5=${MD5:-md5sum}
AWK=${AWK:-awk}
GREP=${GREP:-grep}
SED=${SED:-sed}
# define what modules should be installed
STANDARD_MODULES=${STANDARD_MODULES:-standard acc lcr domain group
permissions registrar usrloc msilo alias_db uri_db speeddial
avpops auth_db pdt dialog dispatcher dialplan topos}
PRESENCE_MODULES=${PRESENCE_MODULES:-presence rls}
EXTRA_MODULES=${EXTRA_MODULES:-imc cpl siptrace domainpolicy carrierroute
drouting userblacklist htable purple uac pipelimit mtree sca mohqueue
rtpproxy}
DBUID_MODULES=${UID_MODULES:-uid_auth_db uid_avp_db uid_domain uid_gflags
uid_uri_db}
############################################################
# common functions
usage() {
COMMAND=`basename $0`
cat <<EOF
$0 $VERSION
usage: $COMMAND create <db name or db_path, optional> ...(creates a new database)
$COMMAND drop <db name or db_path, optional> .....(!entirely deletes tables!)
$COMMAND reinit <db name or db_path, optional> ...(!entirely deletes and than re-creates tables!)
$COMMAND backup <file> ...........................(dumps current database to file)
$COMMAND restore <file> ..........................(restores tables from a file)
$COMMAND copy <new_db> ...........................(creates a new db from an existing one)
$COMMAND migrate <old_db> <new_db> ...............(migrates DB from 1.2 to 1.3, not implemented yet!)
$COMMAND presence ................................(adds the presence related tables)
$COMMAND extra ...................................(adds the extra tables)
$COMMAND dbuid ...................................(adds the uid tables)
$COMMAND dbonly ..................................(creates empty database)
$COMMAND grant ...................................(grant privileges to database)
$COMMAND revoke ..................................(revoke privileges to database)
$COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
if you want to manipulate database as other database user than
root, want to change database name from default value "$DBNAME",
or want to use other values for users and password, edit the
"config vars" section of the command $COMMAND.
$COMMAND pframework create .......................(creates a sample provisioning framework file)
EOF
} #usage
# read realm
prompt_realm()
{
printf "Domain (realm) for the default user 'admin': "
read SIP_DOMAIN
echo
}
# calculate credentials for admin
credentials()
{
HA1=`echo -n "admin:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
if [ $? -ne 0 ] ; then
merr "HA1 calculation failed"
exit 1
fi
HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
if [ $? -ne 0 ] ; then
merr "HA1B calculation failed"
exit 1
fi
#PHPLIB_ID of users should be difficulty to guess for security reasons
NOW=`date`;
PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | $AWK '{ print $1 }'`
if [ $? -ne 0 ] ; then
merr "PHPLIB_ID calculation failed"
exit 1
fi
}
# FIXME use the definition from kamctl.base
mdbg() {
if [ "0$VERBOSE" -ne 0 ] ; then
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
else
echo "$1"
fi
fi
}
mwarn() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
else
echo "** WARNING: $1"
fi
}
minfo() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
else
echo "** INFO: $1"
fi
}
mecho() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
else
echo "$1"
fi
}
merr() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
else
echo "** ERROR: $1"
fi
}
# Get a y/n value from a variable. If the variable contains the keyword
# `ask', then interactively ask the user for an answer.
#
# Arguments:
# $1 - variable holding yes/no/ask
# $2 - question to print if value of variable is ask
#
# Return:
# On return $ANSWER will be available with y/n
#
get_answer ()
{
value=$1
question=$2
if [ "${value}" = "ask" ]; then
echo -n "$question"
read ANSWER
else
ANSWER=${value}
fi
ANSWER=${ANSWER:0:1}
ANSWER=${ANSWER/Y/y}
ANSWER=${ANSWER/N/n}
}