Browse code

- tables used by usrloc, aliases, subscribers and groups are not internally set if already defined from outside; usefull if we want to force different names for this tables

Bogdan-Andrei Iancu authored on 19/10/2003 17:54:33
Showing 1 changed files
... ...
@@ -66,12 +66,16 @@ VERSION='$Revision$'
66 66
 #### SQL names
67 67
 
68 68
 # Usr Loc Table
69
-USRLOC=location
69
+if [ -z "$UL_TABLE" ] ; then
70
+	UL_TABLE=location
71
+fi
70 72
 USER_COLUMN=username
71 73
 CALLID_COLUMN=callid
72 74
 
73 75
 # subscriber table
74
-TABLE=subscriber
76
+if [ -z "SUB_TABLE" ] ; then
77
+	SUB_TABLE=subscriber
78
+fi
75 79
 REALM_COLUMN=domain
76 80
 HA1_COLUMN=HA1
77 81
 HA1B_COLUMN=HA1B
... ...
@@ -83,14 +87,18 @@ SUB_MODIFIED_COLUMN=datetime_modified
83 87
 PHP_LIB_COLUMN=phplib_id
84 88
 
85 89
 # acl table
86
-ACL_TABLE=grp
90
+if [ -z "$ACL_TABLE" ] ; then
91
+	ACL_TABLE=grp
92
+fi
87 93
 ACL_USER_COLUMN=username
88 94
 ACL_GROUP_COLUMN=grp
89 95
 ACL_MODIFIED_COLUMN=last_modified
90 96
 ACL_DOMAIN_COLUMN=domain
91 97
 
92 98
 # aliases table
93
-A_TABLE=aliases
99
+if [ -z "$ALS_TABLE" ] ; then
100
+	ALS_TABLE=aliases
101
+fi
94 102
 A_USER_COLUMN=username
95 103
 A_CONTACT_COLUMN=contact
96 104
 A_EXPIRES_COLUMN=expires
... ...
@@ -319,9 +327,9 @@ usrloc() {
319 327
 		exit 1
320 328
 	fi
321 329
 	if [ "$1" = "alias" ] ; then
322
-		UL_TABLE="$A_TABLE"
330
+		USRLOC_TABLE="$ALS_TABLE"
323 331
 	elif [ "$1" = "ul" ] ; then
324
-		UL_TABLE="$USRLOC"
332
+		USRLOC_TABLE="$UL_TABLE"
325 333
 	else
326 334
 		echo "usrloc: unknown table name"
327 335
 		exit 1
... ...
@@ -331,7 +339,7 @@ usrloc() {
331 339
 	case $1 in 
332 340
 		show)
333 341
 			if [ $# -eq 2 ] ; then
334
-				fifo_cmd ul_show_contact $UL_TABLE $2
342
+				fifo_cmd ul_show_contact $USRLOC_TABLE $2
335 343
 			elif [ $# -eq 1 ] ; then
336 344
 				printf "Dumping all contacts may take long: are you sure you want to proceed? [Y|N] "
337 345
 				read answer
... ...
@@ -357,7 +365,7 @@ usrloc() {
357 365
 				exit 1
358 366
 			fi
359 367
 
360
-			fifo_cmd ul_add "$UL_TABLE" "$1" "$2" "$FOREVER_REL" "1.00" "0"
368
+			fifo_cmd ul_add "$USRLOC_TABLE" "$1" "$2" "$FOREVER_REL" "1.00" "0"
361 369
 			exit $?
362 370
 			;;
363 371
 		rm)
... ...
@@ -366,7 +374,7 @@ usrloc() {
366 374
                 exit 1
367 375
             fi
368 376
 			shift
369
-			fifo_cmd ul_rm $UL_TABLE $1
377
+			fifo_cmd ul_rm $USRLOC_TABLE $1
370 378
 
371 379
             ;;
372 380
 
... ...
@@ -467,7 +475,7 @@ acl() {
467 475
 # params: user
468 476
 # output: false if exists, true otherwise
469 477
 is_user() {
470
-	QUERY="select count(*) from $TABLE \
478
+	QUERY="select count(*) from $SUB_TABLE \
471 479
 		where $SUBSCRIBER_COLUMN='$1' and $REALM_COLUMN='$SIP_DOMAIN';"
472 480
 	CNT=`sql_ro_query "$QUERY" | grep -v ERROR | $LAST_LINE`
473 481
 	if [ "0$CNT" -eq 0 ] ; then
... ...
@@ -583,7 +591,7 @@ case $1 in
583 591
 			echo non-existent user
584 592
 			exit 1
585 593
 		fi
586
-		QUERY="update $TABLE \
594
+		QUERY="update $SUB_TABLE \
587 595
 			set $HA1_COLUMN='$HA1', $HA1B_COLUMN='$HA1B', $PASSWORD_COLUMN='$2' \
588 596
 			, $SUB_MODIFIED_COLUMN=now() \
589 597
 			WHERE $SUBSCRIBER_COLUMN='$1' and $REALM_COLUMN='$SIP_DOMAIN';"
... ...
@@ -612,7 +620,7 @@ case $1 in
612 620
             exit 1
613 621
         fi
614 622
 
615
-		QUERY="insert into $TABLE \
623
+		QUERY="insert into $SUB_TABLE \
616 624
 				($SUBSCRIBER_COLUMN,$REALM_COLUMN,$HA1_COLUMN,\
617 625
 				$HA1B_COLUMN,$PASSWORD_COLUMN,$EMAIL_COLUMN, $SUB_CREATED_COLUMN,  \
618 626
 				$PHP_LIB_COLUMN ) \
... ...
@@ -659,8 +667,8 @@ case $1 in
659 667
 			exit 1
660 668
 		fi
661 669
 		shift
662
-		QUERY="select $TABLE.$EMAIL_COLUMN from $TABLE where  \
663
-			$TABLE.$SUBSCRIBER_COLUMN='$1'"
670
+		QUERY="select $SUB_TABLE.$EMAIL_COLUMN from $SUB_TABLE where  \
671
+			$SUB_TABLE.$SUBSCRIBER_COLUMN='$1'"
664 672
 		EA=`sql_ro_query "$QUERY" "-B" | grep -v ERROR | $LAST_LINE`
665 673
 		if [ $? -ne 0 ] ; then
666 674
 			echo "MySql query failed"
... ...
@@ -700,13 +708,13 @@ case $1 in
700 708
 
701 709
 		shift
702 710
 
703
-		QUERY1="select $TABLE.$EMAIL_COLUMN from $TABLE where  \
704
-			$TABLE.$SUBSCRIBER_COLUMN='$1'"
705
-		QUERY2="select $USRLOC.* from $USRLOC where \
706
-			$USRLOC.$USER_COLUMN='$1' order by expires desc"
707
-		QUERY3="select $USRLOC.$USER_COLUMN, $TABLE.$EMAIL_COLUMN, $USRLOC.$CALLID_COLUMN \
708
-			from $TABLE, $USRLOC where  \
709
-			$TABLE.$SUBSCRIBER_COLUMN=$USRLOC.$USER_COLUMN  order by $USRLOC.$USER_COLUMN" 
711
+		QUERY1="select $SUB_TABLE.$EMAIL_COLUMN from $SUB_TABLE where  \
712
+			$SUB_TABLE.$SUBSCRIBER_COLUMN='$1'"
713
+		QUERY2="select $UL_TABLE.* from $UL_TABLE where \
714
+			$UL_TABLE.$USER_COLUMN='$1' order by expires desc"
715
+		QUERY3="select $UL_TABLE.$USER_COLUMN, $SUB_TABLE.$EMAIL_COLUMN, $UL_TABLE.$CALLID_COLUMN \
716
+			from $SUB_TABLE, $UL_TABLE where  \
717
+			$SUB_TABLE.$SUBSCRIBER_COLUMN=$UL_TABLE.$USER_COLUMN  order by $UL_TABLE.$USER_COLUMN" 
710 718
 
711 719
 		if [ $# -eq 1 ] ; then
712 720
 			sql_ro_query "$QUERY1"
... ...
@@ -737,7 +745,7 @@ case $1 in
737 745
 		$0 acl revoke $1  > /dev/null 2>&1
738 746
 
739 747
 		# destroy the user now
740
-        QUERY="delete from $TABLE where $TABLE.$SUBSCRIBER_COLUMN='$1'"
748
+        QUERY="delete from $SUB_TABLE where $SUB_TABLE.$SUBSCRIBER_COLUMN='$1'"
741 749
 		sql_query "$QUERY"
742 750
 
743 751
 		# and also all his contacts