Browse code

- obsolete scripts and utilities removed closes SER-308

Jan Janak authored on 02/02/2008 13:21:09
Showing 1 changed files
1 1
deleted file mode 100755
... ...
@@ -1,936 +0,0 @@
1
-#!/bin/sh  
2
-#
3
-# $Id$
4
-#
5
-# sc: ser control; tool for maintaining ser's databases using UNIX sockets
6
-#
7
-# History:
8
-# -------
9
-# 2004-03-09 Derived from the original FIFO version (janakj)
10
-#
11
-
12
-# configuration for starting/stopping ser
13
-PID_FILE=/var/run/ser.pid
14
-SYSLOG=1 # 0=output to console, 1=output to syslog
15
-STARTOPTIONS= # for example -dddd
16
-DIR=`dirname $0`
17
-SERBIN=$DIR/ser
18
-
19
-# ser's UNIX domain socket
20
-if [ -z "$SER_UNIXSOCK" ]; then
21
-        SER_UNIXSOCK=/tmp/ser.sock
22
-fi
23
-
24
-# period in which stats are reprinted
25
-if [ -z "$WATCH_PERIOD" ] ; then
26
-	WATCH_PERIOD=2
27
-fi
28
-
29
-# SQL config
30
-if [ -z "$SQL_DB" ] ; then
31
-	SQL_DB=ser
32
-fi
33
-if [ -z "$SQL_HOST" ] ; then
34
-	SQL_HOST=localhost
35
-fi
36
-if [ -z "$SQL_USER" ] ; then
37
-	SQL_USER=ser
38
-fi
39
-
40
-# the read-only user for whom password may be stored here
41
-if [ -z "$RO_USER" ] ; then
42
-	RO_USER=serro
43
-fi
44
-if [ -z "$RO_PW" ] ; then
45
-	RO_PW=47serro11
46
-fi
47
-
48
-# binaries
49
-GENHA1='gen_ha1'
50
-SERUNIX='serunix'
51
-MYSQL='mysql'
52
-SER='sr'
53
-LAST_LINE='tail -1'
54
-
55
-# ACL name verification
56
-VERIFY_ACL=1
57
-ACL_GROUPS="local ld int voicemail free-pstn prepaid"
58
-
59
-VERSION='$Revision$'
60
-
61
-#### SQL names
62
-
63
-# Usr Loc Table
64
-if [ -z "$UL_TABLE" ] ; then
65
-	UL_TABLE=location
66
-fi
67
-USER_COLUMN=username
68
-CALLID_COLUMN=callid
69
-
70
-# subscriber table
71
-if [ -z "$SUB_TABLE" ] ; then
72
-	SUB_TABLE=subscriber
73
-fi
74
-REALM_COLUMN=domain
75
-HA1_COLUMN=HA1
76
-HA1B_COLUMN=HA1B
77
-PASSWORD_COLUMN=password
78
-RPID_COLUMN=rpid
79
-SUBSCRIBER_COLUMN='username'
80
-EMAIL_COLUMN=email_address
81
-SUB_CREATED_COLUMN=datetime_created
82
-SUB_MODIFIED_COLUMN=datetime_modified
83
-PHP_LIB_COLUMN=phplib_id
84
-
85
-# acl table
86
-if [ -z "$ACL_TABLE" ] ; then
87
-	ACL_TABLE=grp
88
-fi
89
-ACL_USER_COLUMN=username
90
-ACL_DOMAIN_COLUMN=domain
91
-ACL_GROUP_COLUMN=grp
92
-ACL_MODIFIED_COLUMN=last_modified
93
-ACL_DOMAIN_COLUMN=domain
94
-
95
-# aliases table
96
-if [ -z "$ALS_TABLE" ] ; then
97
-	ALS_TABLE=aliases
98
-fi
99
-A_USER_COLUMN=username
100
-A_CONTACT_COLUMN=contact
101
-A_EXPIRES_COLUMN=expires
102
-A_Q_COLUMN=q
103
-A_CALLID_COLUMN=callid
104
-A_CSEQ_COLUMN=cseq
105
-A_LAST_MODIFIED_COLUMN=last_modified
106
-
107
-# domain table
108
-DOMAIN_TABLE=domain
109
-
110
-# URI table
111
-if [ -z "$URI_TABLE" ] ; then
112
-	URI_TABLE=uri
113
-fi
114
-URIUSER_COLUMN=uri_user
115
-MODIFIED_COLUMN=last_modified
116
-
117
-UNIXSOCK_DBG=0
118
-
119
-EGREP="egrep"
120
-#===================================================================
121
-
122
-
123
-usage() {
124
-CMD=`basename $0`
125
-if [ "0$VERIFY_ACL" -eq 1 ] ; then
126
-	EXTRA_TEXT="ACL privileges are: $ACL_GROUPS"
127
-fi
128
-cat <<EOF
129
-$0 $VERSION
130
-parameter usage: 
131
-           * subscribers *
132
- add <username> <password> <email> .. add a new subscriber (*)
133
- passwd <username> <passwd> ......... change user's password (*)
134
- rm <username> ...................... delete a user (*)
135
- mail <username> .................... send an email to a user
136
- alias show [<alias>] ............... show aliases
137
- alias rm <alias> ................... remove an alias
138
- alias add <alias> <uri> ............ add an aliases 
139
- rpid add <username> <rpid> ......... add rpid for a user (*)
140
- rpid rm <username> ................. set rpid to NULL for a user (*)
141
- rpid show <username> ............... show rpid of a user
142
-
143
-           * access control lists *
144
- acl show [<username>] .............. show user membership
145
- acl grant <username> <group> ....... grant user membership (*)
146
- acl revoke <username> [<group>] .... grant user membership(s) (*)
147
-
148
-           * usrloc *
149
- ul show [<username>]................ show in-RAM online users
150
- ul rm <username> ................... delete user's UsrLoc entries
151
- ul add <username> <uri> ............ introduce a permanent UrLoc entry
152
- showdb [<username>] ................ show online users flushed in DB
153
-
154
-           * domains *
155
- domain show ........................ show list of served domains
156
- domain add <domainname> ............ add a new served domain
157
- domain rm <domainname> ............. remove a served domain
158
-
159
-           * control and diagnostics *
160
- moni ... show internal status        start .... start ser
161
- ps ..... show runnig processes       stop ..... stop ser
162
- unixsock ... send raw unixsock commands  restart .. restart ser
163
- ping <uri> .. ping a URI (OPTIONS)
164
- cisco_restart <uri> .. restart a Cisco phone (NOTIFY)
165
-
166
-
167
-   Commands labeled with (*) will prompt for a MySQL password.
168
-   If the variable PW is set, the password will not be prompted.
169
-
170
-     $EXTRA_TEXT
171
-EOF
172
-}
173
-
174
-
175
-# determine host name, typically for use in printing UAC
176
-# messages; we use today a simplistic but portable uname -n way --
177
-# no domain name is displayed ; unixsock_uac expands !! to host
178
-# address only for optional header fields; uname output without
179
-# domain is sufficient for informational header fields such as
180
-# From
181
-#
182
-get_my_host() {
183
-	uname -n
184
-}
185
-
186
-# calculate name and domain of current user
187
-set_user() {
188
-
189
-	SERUSER=`echo $1|awk -F @ '{print $1}'`
190
-	SERDOMAIN=`echo $1|awk -F @ '{print $2}'`
191
-
192
-	if [ -z "$SERDOMAIN" ] ; then
193
-		SERDOMAIN="$SIP_DOMAIN"
194
-	fi
195
-
196
-	if [ -z "$SERDOMAIN" ] ; then
197
-		echo "domain unknown: use usernames with domain or set default domain in SIP_DOMAIN"
198
-		exit 1
199
-	fi
200
-}
201
-
202
-
203
-# check the parameter if it is a valid SIP URI
204
-# quite simplified now -- it captures just very basic
205
-# errors
206
-check_uri() {
207
-	echo "$1" | $EGREP "^sip(s)?:([a-zA-Z0-9_]+@)?.*\..*" 
208
-}
209
-
210
-# check for alias duplicates
211
-check_alias() {
212
-		unixsock_cmd ul_show_contact "$ALS_TABLE" "$1" | grep 404 > /dev/null
213
-		if [ $? -ne 0 ]; then
214
-			echo error: overlap with an existing alias
215
-			exit 1
216
-		fi
217
-}
218
-
219
-
220
-#params: none
221
-# output: PW
222
-prompt_pw() {
223
-	if [ -z "$PW" ] ; then
224
-		savetty=`stty -g`
225
-		printf "MySql password: " > /dev/stderr
226
-		stty -echo
227
-    	read PW
228
-		stty $savetty
229
-    	echo
230
-	fi
231
-}
232
-
233
-print_status() {
234
-	echo $1 | grep "^[1-6][0-9][0-9]" > /dev/null
235
-	if [ "$?" -eq 0 ] ; then 
236
-		echo $1
237
-	else
238
-		echo "200 OK"
239
-	fi
240
-}
241
-
242
-# process output from unixsock server; if everything is ok
243
-# skip the first "ok" line and proceed to returned 
244
-# parameters
245
-filter_fl()
246
-{
247
-#	tail +2
248
-	
249
-	awk 'BEGIN {line=0;IGNORECASE=1;}
250
-		{line++}
251
-		line==1 && /^200/ { next }
252
-		{ print }'
253
-}
254
-
255
-unixsock_cmd()
256
-{
257
-	if [ "0${UNIXSOCK_DBG}" -eq 1 ] ; then
258
-		echo "entering unixsock_cmd $*"
259
-	fi
260
-	if [ "$#" -lt 1 ]; then
261
-		echo "ERROR: unixsock_cmd must take at least command name as parameter"
262
-		exit
263
-	fi
264
-
265
-	# construct the command now
266
-	CMD=":$1:\n";
267
-	shift
268
-	while [ -n "$1" ] ; do
269
-		CMD="${CMD}${1}\n"
270
-		shift
271
-	done
272
-	CMD="${CMD}\n"
273
-	
274
-	printf "$CMD" | $SERUNIX $SER_UNIXSOCK | filter_fl
275
-
276
-	if [ "0${UNIXSOCK_DBG}" -eq 1 ] ; then
277
-		printf "UNIXSOCK command was:\n$CMD"
278
-	fi
279
-}
280
-
281
-
282
-# $1=attempt number
283
-print_stats() {
284
-	echo "[cycle #: $1; if constant make sure server lives]"
285
-	unixsock_cmd version
286
-	unixsock_cmd uptime
287
-	echo Transaction Statistics
288
-	unixsock_cmd t_stats
289
-	echo Stateless Server Statistics
290
-	unixsock_cmd sl_stats
291
-	echo UsrLoc Stats
292
-	unixsock_cmd ul_stats
293
-}
294
-
295
-
296
-# input: sql query, optional mysql command-line params
297
-sql_query() {
298
-	# if password not yet queried, query it now
299
-	if [ -z "$PW" ] ; then
300
-		savetty=`stty -g`
301
-		printf "MySql password: " > /dev/stderr
302
-		stty -echo
303
-    	read PW >&2
304
-		stty $savetty
305
-    	echo >&2
306
-	fi
307
-	$MYSQL $2 -h $SQL_HOST -u $SQL_USER "-p$PW" -e "$1 ;" $SQL_DB
308
-}
309
-
310
-# input: sql query, optional mysql command-line params
311
-sql_ro_query() {
312
-	$MYSQL $2 -h $SQL_HOST -u $RO_USER "-p$RO_PW" \
313
-		-e "$1 ;" $SQL_DB
314
-}
315
-
316
-
317
-usrloc() {
318
-	if [ "$#" -lt 2 ] ; then
319
-		echo "usrloc: too few parameters"
320
-		exit 1
321
-	fi
322
-	if [ "$1" = "alias" ] ; then
323
-		USRLOC_TABLE="$ALS_TABLE"
324
-		CHECK_SUB=1
325
-	elif [ "$1" = "ul" ] ; then
326
-		USRLOC_TABLE="$UL_TABLE"
327
-		CHECK_SUB=0
328
-	else
329
-		echo "usrloc: unknown table name"
330
-		exit 1
331
-	fi
332
-	shift
333
-
334
-	case $1 in 
335
-		show)
336
-			if [ $# -eq 2 ] ; then
337
-				set_user $2
338
-				unixsock_cmd ul_show_contact $USRLOC_TABLE "$SERUSER@$SERDOMAIN"
339
-			elif [ $# -eq 1 ] ; then
340
-				printf "Dumping all contacts may take long: are you sure you want to proceed? [Y|N] " > /dev/stderr
341
-				read answer
342
-				if [ "$answer" = "y" -o "$answer" = "Y" ] ; then
343
-					unixsock_cmd ul_dump
344
-				fi
345
-			else
346
-				echo "wrong number of params for usrloc show"
347
-				usage
348
-				exit 1
349
-			fi
350
-			exit $?
351
-			;;
352
-		add)
353
-			if [ $# -ne 3 ] ; then
354
-				usage
355
-				exit 1
356
-			fi
357
-			shift
358
-			check_uri "$2"
359
-			set_user $1
360
-				
361
-			if [ "$?" -ne "0" ] ; then
362
-				echo "$2 is not a valid URI"
363
-				exit 1
364
-			fi
365
-
366
-			if [ "$CHECK_SUB" -ne 0 ] ; then
367
-				is_user 
368
-				if [ $? -eq 0 ] ; then
369
-					echo overlap of alias with an existing subscriber name
370
-					exit 1;
371
-				fi
372
-			fi
373
-
374
-			check_alias "$SERUSER@$SERDOMAIN"
375
-
376
-			# 128 means FL_PERSISTENT is on
377
-			unixsock_cmd ul_add "$USRLOC_TABLE" "$SERUSER@$SERDOMAIN" "$2" "0" "1.00" "0" "128"
378
-			exit $?
379
-			;;
380
-		rm)
381
-			if [ $# -ne 2 ] ; then
382
-                		usage
383
-                		exit 1
384
-            		fi
385
-
386
-			shift
387
-			set_user $1
388
-			unixsock_cmd ul_rm $USRLOC_TABLE "$SERUSER@$SERDOMAIN"
389
-
390
-            ;;
391
-
392
-		*)
393
-			usage
394
-			exit 1
395
-			;;
396
-	esac
397
-}
398
-
399
-rpid() {
400
-	if [ "$#" -lt 2 ] ; then
401
-		echo "rpid: too few parameters"
402
-		exit 1
403
-	fi
404
-        shift;
405
-
406
-	case $1 in
407
-		show)
408
-			if [ $# -eq 2 ] ; then
409
-				set_user $2
410
-				is_user 
411
-				if [ $? -ne 0 ] ; then
412
-					echo non-existent user
413
-					exit 1;
414
-				fi
415
-				CLAUSE=" WHERE $SUBSCRIBER_COLUMN='$SERUSER' AND $REALM_COLUMN='$SERDOMAIN' "
416
-			elif [ $# -ne 1 ] ; then
417
-				usage
418
-				exit 1
419
-			fi
420
-			QUERY="select $SUBSCRIBER_COLUMN, $RPID_COLUMN FROM $SUB_TABLE $CLAUSE ; "
421
-			sql_ro_query "$QUERY"
422
-			;;
423
-
424
-		add|rm)
425
-		        MODE=$1;
426
-
427
-			if [ "$MODE" == "add" ] ; then
428
-			    ARG_NUM=3;
429
-			else
430
-			    ARG_NUM=2;
431
-			fi
432
-			
433
-			if [ $# -lt $ARG_NUM ] ; then
434
-				usage
435
-				exit 1
436
-			fi
437
-
438
-			prompt_pw
439
-			set_user $2
440
-			is_user 
441
-			if [ $? -ne 0 ] ; then
442
-				echo non-existent user
443
-				exit 1
444
-			fi
445
-			shift 2
446
-
447
-			if [ "$MODE" = "add" ] ; then
448
-			        RPID_VAL="'$1'";
449
-			else
450
-			        RPID_VAL=NULL;
451
-			fi
452
-
453
-			QUERY="UPDATE $SUB_TABLE \
454
-                	SET $RPID_COLUMN=$RPID_VAL \
455
-                	WHERE $SUBSCRIBER_COLUMN='$SERUSER' AND $REALM_COLUMN='$SERDOMAIN';"
456
-				sql_query "$QUERY"
457
-				if [ $? -ne 0 ] ; then
458
-					echo "SQL Error"
459
-					exit 1
460
-				fi
461
-
462
-			$0 rpid show $SERUSER@$SERDOMAIN
463
-
464
-			;;
465
-
466
-		*)
467
-			usage
468
-			exit 1
469
-			;;
470
-	esac
471
-}
472
-
473
-domain() {
474
-	case $1 in
475
-		show)
476
-			# QUERY="select * FROM $DOMAIN_TABLE ; "
477
-			# sql_ro_query "$QUERY"
478
-			unixsock_cmd domain_dump
479
-			;;
480
-		add)
481
-			shift
482
-			if [ $# -ne 1 ] ; then
483
-				echo missing domain to be added
484
-				exit 1
485
-			fi
486
-			prompt_pw
487
-       		QUERY="insert into $DOMAIN_TABLE (domain) VALUES ('$1');"
488
-			sql_query "$QUERY"
489
-			if [ $? -ne 0 ] ; then
490
-				echo "SQL Error"
491
-				exit 1
492
-			fi
493
-			unixsock_cmd domain_reload
494
-			;;
495
-		rm)
496
-			shift
497
-			if [ $# -ne 1 ] ; then
498
-				echo missing domain to be removed
499
-				exit 1
500
-			fi
501
-			prompt_pw
502
-       		QUERY="delete from $DOMAIN_TABLE where domain='$1';"
503
-			sql_query "$QUERY"
504
-			if [ $? -ne 0 ] ; then
505
-				echo "SQL Error"
506
-				exit 1
507
-			fi
508
-			unixsock_cmd domain_reload
509
-			;;
510
-		*)
511
-			usage
512
-			exit 1
513
-	esac
514
-}
515
-
516
-acl() {
517
-	case $1 in
518
-		show)
519
-			if [ $# -eq 2 ] ; then
520
-				set_user $2
521
-				is_user 
522
-				if [ $? -ne 0 ] ; then
523
-					echo non-existent user
524
-					exit 1;
525
-				fi
526
-				CLAUSE=" WHERE $ACL_USER_COLUMN='$SERUSER' AND $ACL_DOMAIN_COLUMN='$SERDOMAIN' "
527
-			elif [ $# -ne 1 ] ; then
528
-				usage
529
-				exit 1
530
-			fi
531
-			QUERY="select * FROM $ACL_TABLE $CLAUSE ; "
532
-			sql_ro_query "$QUERY"
533
-
534
-			;;
535
-
536
-		grant)
537
-			if [ $# -lt 3 ] ; then
538
-				usage
539
-				exit 1
540
-			fi
541
-			prompt_pw
542
-			set_user $2
543
-			is_user 
544
-			if [ $? -ne 0 ] ; then
545
-				echo non-existent user
546
-				exit 1
547
-			fi
548
-			shift 2
549
-			while [ $# -gt 0 ] ; do
550
-
551
-				if [ $VERIFY_ACL -eq 1 ] ; then
552
-					found=0
553
-					for i in $ACL_GROUPS ; do
554
-						if [ "$1" = "$i" ] ; then
555
-							found=1
556
-							break
557
-						fi
558
-					done	
559
-					if [ $found -eq 0 ] ; then
560
-						echo "Invalid privilege: $1 ignored"
561
-						shift
562
-						continue
563
-					fi
564
-				fi
565
-
566
-        		QUERY="insert into $ACL_TABLE \
567
-                	($ACL_USER_COLUMN,$ACL_GROUP_COLUMN,$ACL_MODIFIED_COLUMN, $ACL_DOMAIN_COLUMN ) \
568
-                	values ('$SERUSER','$1', now(), '$SERDOMAIN' );"
569
-				sql_query "$QUERY"
570
-				if [ $? -ne 0 ] ; then
571
-					echo "SQL Error"
572
-					exit 1
573
-				fi
574
-				shift
575
-			done
576
-
577
-			$0 acl show $SERUSER@$SERDOMAIN
578
-
579
-			;;
580
-
581
-		revoke)
582
-			if [ $# -eq 3 ] ; then
583
-				CLAUSE=" and $ACL_GROUP_COLUMN='$3' "
584
-			elif [ $# -ne 2 ] ; then
585
-				usage
586
-				exit 1
587
-			fi	
588
-
589
-			set_user $2
590
-
591
-			QUERY="delete from $ACL_TABLE where \
592
-				$ACL_TABLE.$ACL_USER_COLUMN='$SERUSER' AND $ACL_DOMAIN_COLUMN='$SERDOMAIN' $CLAUSE"
593
-			sql_query "$QUERY"
594
-
595
-			$0 acl show $2
596
-
597
-			;;
598
-
599
-		*)
600
-			usage
601
-			exit 1
602
-			;;
603
-	esac
604
-}
605
-
606
-# params: user
607
-# output: false if exists, true otherwise
608
-is_user() {
609
-	QUERY="select count(*) from $SUB_TABLE \
610
-		where $SUBSCRIBER_COLUMN='$SERUSER' and $REALM_COLUMN='$SERDOMAIN';"
611
-	CNT=`sql_ro_query "$QUERY" | grep -v ERROR | $LAST_LINE`
612
-	if [ "0$CNT" -eq 0 ] ; then
613
-		false
614
-	else
615
-		true
616
-	fi
617
-
618
-}
619
-
620
-
621
-# params: user, password
622
-# output: HA1, HA1B
623
-credentials()
624
-{
625
-	set_user $1
626
-
627
-	HA1=`$GENHA1 $SERUSER $SERDOMAIN $2`
628
-	if [ $? -ne 0 ] ; then
629
-		echo "HA1 calculation failed"
630
-		exit 1
631
-	fi
632
-	HA1B=`$GENHA1 "$SERUSER@$SERDOMAIN" $SERDOMAIN $2`
633
-	if [ $? -ne 0 ] ; then
634
-		echo "HA1B calculation failed"
635
-		exit 1
636
-	fi
637
-}
638
-
639
-#================================================================
640
-
641
-# if the script calls itself ...
642
-export PW
643
-
644
-case $1 in
645
-
646
-	start)
647
-		echo
648
-		printf "Starting SER : "
649
-		if [ -r $PID_FILE ] ; then
650
-			echo "PID file exists! ($PID_FILE) already running?"
651
-			exit 1
652
-		else
653
-			if [ ! -x "$SERBIN" ] ; then
654
-				echo "SER binaries not found at $SERBIN; reconfigure SERBIN in $0"
655
-				exit 1
656
-			fi
657
-			if [ $SYSLOG = 1 ] ; then
658
-				$SERBIN -P $PID_FILE $STARTOPTIONS 1>/dev/null 2>/dev/null
659
-			else
660
-			 	$SERBIN -P $PID_FILE -E $STARTOPTIONS
661
-			fi
662
-			sleep 1
663
-			if [ ! -s $PID_FILE ] ; then
664
-				echo "PID file $PID_FILE does not exist -- SER start failed"
665
-				exit 1
666
-			fi
667
-			echo "started pid(`cat $PID_FILE`)"
668
-		fi
669
-		exit 0
670
-		;;
671
-
672
-	stop)
673
-		printf "Stopping SER : "
674
-		if [ -r $PID_FILE ] ; then
675
-			kill `cat $PID_FILE`
676
-			echo "stopped"
677
-		else
678
-			echo No PID file found! SER probably not running
679
-			exit 1
680
-		fi
681
-		exit 0
682
-		;;
683
-
684
-	restart)
685
-		$0 stop
686
-		if [ "$?" -ne 0 ] ; then
687
-			exit 1
688
-		fi
689
-		sleep 2
690
-		$0 start
691
-		exit 0
692
-		;;
693
-
694
-	passwd)
695
-		if [ $# -ne 3 ] ; then
696
-			usage
697
-			exit 1
698
-		fi
699
-		shift
700
-		credentials $1 $2
701
-		prompt_pw
702
-
703
-		is_user $1
704
-		if [ $? -ne 0 ] ; then
705
-			echo non-existent user
706
-			exit 1
707
-		fi
708
-		QUERY="update $SUB_TABLE \
709
-			set $HA1_COLUMN='$HA1', $HA1B_COLUMN='$HA1B', $PASSWORD_COLUMN='$2' \
710
-			, $SUB_MODIFIED_COLUMN=now() \
711
-			WHERE $SUBSCRIBER_COLUMN='$SERUSER' and $REALM_COLUMN='$SERDOMAIN';"
712
-		sql_query "$QUERY"
713
-		if [ $? -ne 0 ] ; then
714
-			echo "password change failed"
715
-		else
716
-			echo "password change succeeded"
717
-		fi
718
-		;;
719
-
720
-        add)
721
-		if [ $# -ne 4 ] ; then
722
-			usage
723
-			exit 1
724
-		fi
725
-		shift
726
-		credentials $1 $2
727
-		prompt_pw
728
-		is_user $1
729
-		if [ $? -eq 0 ] ; then
730
-           		echo user already exists
731
-           		exit 1
732
-		fi  
733
-		check_alias "$SERUSER@$SERDOMAIN"
734
-
735
-
736
-		QUERY="insert into $SUB_TABLE \
737
-				($SUBSCRIBER_COLUMN,$REALM_COLUMN,$HA1_COLUMN,\
738
-				$HA1B_COLUMN,$PASSWORD_COLUMN,$EMAIL_COLUMN, $SUB_CREATED_COLUMN,  \
739
-				$PHP_LIB_COLUMN ) \
740
-				values ('$SERUSER','$SERDOMAIN','$HA1','$HA1B','$2', '$3', now(), '$HA1' );";
741
-		sql_query "$QUERY"
742
-		if [ $? -ne 0 ] ; then
743
-			echo "introducing a new user to the database failed"
744
-		else
745
-			echo "new user added"
746
-		fi
747
-
748
-		QUERY="insert into $URI_TABLE \
749
-				($SUBSCRIBER_COLUMN,$REALM_COLUMN,$URIUSER_COLUMN,$MODIFIED_COLUMN) \
750
-				values ('$SERUSER','$SERDOMAIN','$SERUSER',now());";
751
-		sql_query "$QUERY"
752
-		if [ $? -ne 0 ] ; then
753
-			echo "introducing a new user into uri table failed"
754
-		else
755
-			echo "new user into uri table added"
756
-		fi
757
-		;;
758
-
759
-	monitor|console|moni|con)
760
-		attempt=0
761
-		if [ "$2" == "" ]; then
762
-		    loops=-1;
763
-		else
764
-		    loops=$2;
765
-		fi
766
-		clear
767
-		while [ $loops -ne $attempt ] ; do
768
-			attempt=$(($attempt + 1))
769
-			#clear
770
-			tput cup 0 0
771
-			print_stats $attempt
772
-			if [ $loops -ne $attempt ] ; then
773
-				sleep $WATCH_PERIOD
774
-			fi
775
-				
776
-		done
777
-		exit 0
778
-		;;
779
-
780
-	mail)
781
-		if [ $# -ne 2 ] ; then
782
-			usage
783
-			exit 1
784
-		fi
785
-		shift
786
-		set_user $1
787
-		QUERY="select $SUB_TABLE.$EMAIL_COLUMN from $SUB_TABLE where  \
788
-			$SUB_TABLE.$SUBSCRIBER_COLUMN='$SERUSER' and $SUB_TABLE.$REALM_COLUMN='$SERDOMAIN'"
789
-		EA=`sql_ro_query "$QUERY" "-B" | grep -v ERROR | $LAST_LINE`
790
-		if [ $? -ne 0 ] ; then
791
-			echo "MySql query failed"
792
-			exit 1
793
-		fi
794
-		echo "Write email to $1: $EA now ..."
795
-		mail -s "Message from $SERDOMAIN SIP admin" $EA
796
-		if [ $? -eq 0 ] ; then
797
-			echo message sent
798
-		else
799
-			echo sending message failed
800
-		fi
801
-		;;
802
-
803
-	alias|ul)
804
-		usrloc "$@"
805
-		;;
806
-
807
-        rpid)
808
-	        rpid "$@"
809
-		;;
810
-
811
-	online)
812
-		unixsock_cmd ul_dump |grep aor| awk '{print $3}' | sort | sort -mu
813
-		exit $?
814
-		;;
815
-
816
-
817
-	showdb|userdb)
818
-		if [ $# -ne 2 ] ; then
819
-			usage
820
-			exit 1
821
-		fi
822
-		shift
823
-		set_user $1
824
-		is_user
825
-		if [ $? -ne 0 ] ; then
826
-			echo non-existent user
827
-			exit 1;
828
-		fi
829
-
830
-		QUERY1="select $SUB_TABLE.$EMAIL_COLUMN from $SUB_TABLE where  \
831
-			$SUB_TABLE.$SUBSCRIBER_COLUMN='$SERUSER' and $SUB_TABLE.$REALM_COLUMN='$SERDOMAIN' "
832
-		QUERY2="select $UL_TABLE.* from $UL_TABLE where \
833
-			$UL_TABLE.$USER_COLUMN='$1' order by expires desc"
834
-		QUERY3="select $UL_TABLE.$USER_COLUMN, $SUB_TABLE.$EMAIL_COLUMN, $UL_TABLE.$CALLID_COLUMN \
835
-			from $SUB_TABLE, $UL_TABLE where  \
836
-			$SUB_TABLE.$SUBSCRIBER_COLUMN=$UL_TABLE.$USER_COLUMN  order by $UL_TABLE.$USER_COLUMN" 
837
-
838
-		if [ $# -eq 1 ] ; then
839
-			sql_ro_query "$QUERY1"
840
-			sql_ro_query "$QUERY2"
841
-		else
842
-			sql_ro_query "$QUERY3"
843
-		fi
844
-		echo "Note: Due to usage of cache, server's list " \
845
-			"may differ from DB list."
846
-		;;
847
-
848
-	rm)
849
-        	if [ $# -ne 2 ] ; then
850
-            		usage
851
-            		exit 1
852
-        	fi
853
-		shift 
854
-		prompt_pw 
855
-
856
-		set_user $1
857
-        	is_user 
858
-        	if [ $? -ne 0 ] ; then
859
-            		echo non-existent user
860
-            		exit 1
861
-        	fi
862
-
863
-		# begin with remove all user's privileges
864
-		$0 acl revoke $1  > /dev/null 2>&1
865
-
866
-		QUERY="delete from $URI_TABLE where $SUBSCRIBER_COLUMN='$SERUSER'"
867
-		sql_query "$QUERY"
868
-
869
-
870
-		# destroy the user now
871
-		QUERY="delete from $SUB_TABLE where $SUB_TABLE.$SUBSCRIBER_COLUMN='$SERUSER' and $SUB_TABLE.$REALM_COLUMN='$SERDOMAIN'"
872
-		sql_query "$QUERY"
873
-
874
-		# and also all his contacts
875
-		$0 ul rm $1   > /dev/null 2>&1
876
-		;;
877
-			
878
-	ps)
879
-		unixsock_cmd ps
880
-		;;
881
-
882
-	acl)
883
-		shift
884
-		acl "$@"
885
-		;;
886
-
887
-	domain)
888
-		shift
889
-		domain "$@"
890
-		;;
891
-
892
-	unixsock)
893
-		shift
894
-		unixsock_cmd "$@"
895
-		;;
896
-
897
-	ping)
898
-		# error handling is hacked -- filter_fl should not
899
-		# consume positive status -- that should be done by
900
-		# calling app
901
-		if [ "$#" -ne 2 ] ; then	
902
-			usage
903
-			exit 1
904
-		fi
905
-		myhost=`get_my_host`
906
-		RET=`unixsock_cmd t_uac_dlg OPTIONS "$2" "." \
907
-			"From: sip:daemon@$myhost" \
908
-			"To: <$2>" "Contact: <sip:daemon@!!>" "." "." \
909