File: openserctl.sqlbase

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (317 lines) | stat: -rw-r--r-- 8,686 bytes parent folder | download
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/sh 
#
# $Id: openserctl.sqlbase,v 1.1 2006/07/04 17:49:59 miconda Exp $
#
# sc: openser control; tool for maintaining openser
#
#===================================================================

##### ----------------------------------------------- #####
### common variables and functions for SQL engines

if [ -z "$DBNAME" ] ; then
	DBNAME=openser
fi
if [ -z "$DBHOST" ] ; then
	DBHOST=localhost
fi
if [ -z "$DBRWUSER" ] ; then
	DBRWUSER=openser
fi

# the read-only user for whom password may be stored here
if [ -z "$DBROUSER" ] ; then
	DBROUSER=openserro
fi
if [ -z "$DBROPW" ] ; then
	DBROPW=openserro
fi

# full privileges SQL user
if [ -z "$DBROOTUSER" ]; then
	DBROOTUSER="root"
fi

##### ----------------------------------------------- #####
#### SQL names

# UsrLoc Table
if [ -z "$UL_TABLE" ] ; then
	UL_TABLE=location
fi
USER_COLUMN=username
DOMAIN_COLUMN=domain
CALLID_COLUMN=callid

# subscriber table
if [ -z "$SUB_TABLE" ] ; then
	SUB_TABLE=subscriber
fi
REALM_COLUMN=domain
HA1_COLUMN=HA1
HA1B_COLUMN=HA1B
PASSWORD_COLUMN=password
RPID_COLUMN=rpid
SUBSCRIBER_COLUMN='username'
EMAIL_COLUMN=email_address
SUB_CREATED_COLUMN=datetime_created
SUB_MODIFIED_COLUMN=datetime_modified
PHP_LIB_COLUMN=phplib_id

# acl table
if [ -z "$ACL_TABLE" ] ; then
	ACL_TABLE=grp
fi
ACL_USER_COLUMN=username
ACL_DOMAIN_COLUMN=domain
ACL_GROUP_COLUMN=grp
ACL_MODIFIED_COLUMN=last_modified

# aliases table
if [ -z "$ALS_TABLE" ] ; then
	ALS_TABLE=aliases
fi
A_USER_COLUMN=username
A_CONTACT_COLUMN=contact
A_EXPIRES_COLUMN=expires
A_Q_COLUMN=q
A_CALLID_COLUMN=callid
A_CSEQ_COLUMN=cseq
A_LAST_MODIFIED_COLUMN=last_modified

# domain table
if [ -z "$DOMAIN_TABLE" ] ; then
	DOMAIN_TABLE=domain
fi

# lcr tables
if [ -z "$LCR_TABLE" ] ; then
	LCR_TABLE=lcr
fi
if [ -z "$GW_TABLE" ] ; then
	GW_TABLE=gw
fi
if [ -z "$GW_GRP_TABLE" ] ; then
	GW_GRP_TABLE=gw_grp
fi

# URI table
if [ -z "$URI_TABLE" ] ; then
	URI_TABLE=uri
fi
URIUSER_COLUMN=uri_user
MODIFIED_COLUMN=last_modified

# dbaliases table
if [ -z "$DA_TABLE" ] ; then
	DA_TABLE=dbaliases
fi
DA_USER_COLUMN=username
DA_DOMAIN_COLUMN=domain
DA_ALIAS_USER_COLUMN=alias_username
DA_ALIAS_DOMAIN_COLUMN=alias_domain

# speeddial table
if [ -z "$SD_TABLE" ] ; then
	SD_TABLE=speed_dial
fi
SD_USER_COLUMN=username
SD_DOMAIN_COLUMN=domain
SD_SD_USER_COLUMN=sd_username
SD_SD_DOMAIN_COLUMN=sd_domain
SD_NEW_URI_COLUMN=new_uri
SD_DESC_COLUMN=description

# avp table
if [ -z "$AVP_TABLE" ] ; then
	AVP_TABLE=usr_preferences
fi

AVP_UUID_COLUMN=uuid
AVP_USER_COLUMN=username
AVP_DOMAIN_COLUMN=domain
AVP_ATTRIBUTE_COLUMN=attribute
AVP_VALUE_COLUMN=value
AVP_TYPE_COLUMN=type
AVP_MODIFIED_COLUMN=modified

##### ----------------------------------------------- #####
### ACL name verification
if [ -z "$VERIFY_ACL" ] ; then
	VERIFY_ACL=1
fi
if [ -z "$ACL_GROUPS" ] ; then
	ACL_GROUPS="local ld int voicemail free-pstn"
fi


#
##### ------------------------------------------------ #####
### usage functions
#
usage_acl() {
	echo
	mecho " -- command 'acl' - manage access control lists (acl)"
	echo
cat <<EOF
 acl show [<username>] .............. show user membership
 acl grant <username> <group> ....... grant user membership (*)
 acl revoke <username> [<group>] .... grant user membership(s) (*)
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_acl"


usage_alias_db() {
	echo
	mecho " -- command 'alias_db' - manage database aliases"
	echo
cat <<EOF
 alias_db show <alias> .............. show alias details
 alias_db list <sip-id> ............. list aliases for uri
 alias_db add <alias> <sip-id> ...... add an alias (*)
 alias_db rm <alias> ................ remove an alias (*)
 alias_db help ...................... help message
    - <alias> must be an AoR (username@domain)"
    - <sip-id> must be an AoR (username@domain)"
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_alias_db"

usage_avp() {
	echo
	mecho " -- command 'avp' - manage AVPs"
	echo
cat <<EOF
 avp list [-T table] [-u <sip-id|uuid>]
     [-a attribute] [-v value] [-t type] ... list AVPs
 avp add [-T table] <sip-id|uuid>
     <attribute> <type> <value> ............ add AVP (*)
 avp rm [-T table]  [-u <sip-id|uuid>]
     [-a attribute] [-v value] [-t type] ... remove AVP (*)
 avp help .................................. help message
    - -T - table name
    - -u - SIP id or unique id
    - -a - AVP name
    - -v - AVP value
    - -t - AVP name and type (0 (str:str), 1 (str:int),
                              2 (int:str), 3 (int:int))
    - <sip-id> must be an AoR (username@domain)
    - <uuid> must be a string but not AoR
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_avp"

usage_db_ops() {
	echo
	mecho " -- command 'db' - database operations"
	echo
cat <<EOF
 db exec <query> ..................... execute SQL query
 db show <table> ..................... display table content
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops"

usage_lcr() {
	echo
	mecho " -- command 'lcr' - manage least cost routes (lcr)"
	echo
cat <<EOF
           * lcr *
   * IP addresses must be entered in dotted quad format e.g. 1.2.3.4 *
   * <uri_scheme> and <transport> must be entered in integer or text,*
   * e.g. transport '2' is identical to transport 'tcp'.             *
   *   scheme: 1=sip, 2=sips;   transport: 1=udp, 2=tcp, 3=tls       *
   * Examples:  lcr addgw_grp usa 1                                  *
   *            lcr addgw level3 1.2.3.4 5080 sip tcp 1              *
   *            lcr addroute +1 % 1 1                                *
 lcr show ....................................................................
           ............. show routes, gateways and groups
 lcr reload ..................................................................
           ............. reload lcr gateways
 lcr addgw_grp <grp_name> ....................................................
           .............. add gateway group, autocreate grp_id
 lcr addgw_grp <grp_name> <grp_id> ...........................................
           ............... add gateway group with grp_id
 lcr rmgw_grp  <grp_id> ......................................................
           ............... delete the gw_grp
 lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> ...............
           ............... add a gateway
 lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <prefix> ......
           ............... add a gateway with prefix
 lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <prefix> <strip>
           ............... add a gateway with prefix and strip
 lcr rmgw  <gw_name> .........................................................
           ............... delete a gateway
 lcr addroute <prefix> <from> <grp_id> <prio> ................................
           .............. add a route
 lcr rmroute  <prefix> <from> <grp_id> <prio> ................................
           .............. delete a route
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_lcr"


usage_rpid() {
	echo
	mecho " -- command 'rpid' - manage Remote-Party-ID (RPID)"
	echo
cat <<EOF
 rpid add <username> <rpid> ......... add rpid for a user (*)
 rpid rm <username> ................. set rpid to NULL for a user (*)
 rpid show <username> ............... show rpid of a user
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_rpid"

usage_speeddial() {
	echo
	mecho " -- command 'speeddial' - manage speed dials (short numbers)"
	echo
cat <<EOF
 speeddial show <speeddial-id> ....... show speeddial details
 speeddial list <sip-id> ............. list speeddial for uri
 speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ... 
           ........................... add a speedial (*)
 speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*)
 speeddial help ...................... help message
    - <speeddial-id>, <sd-id> must be an AoR (username@domain)
    - <sip-id> must be an AoR (username@domain)
    - <new-uri> must be a SIP AoR (sip:username@domain)
    - <desc> a description for speeddial
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_speeddial"

usage_subscriber() {
	echo
	mecho " -- command 'add|mail|passwd|rm' - manage subscribers"
	echo
cat <<EOF
 add <username> <password> <email> .. add a new subscriber (*)
 passwd <username> <passwd> ......... change user's password (*)
 rm <username> ...................... delete a user (*)
 mail <username> .................... send an email to a user
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_subscriber"

#params: none
# output: DBRWPW
prompt_pw() {
	if [ -z "$DBRWPW" ] ; then
		savetty=`stty -g`
		if [ -z "$1" ] ; then
			printf "Password: " > /dev/stderr
		else
			printf "$1: " > /dev/stderr
		fi
		stty -echo
    	read DBRWPW
		stty $savetty
    	echo
	fi
}