Browse code

Added functions to calculate credentials of initial user admin according to $SIP_DOMAIN and prompts for it, if not set.

If acked by all participants we/i could backport it to stable.

Nils Ohlmeier authored on 31/07/2003 03:28:38
Showing 1 changed files
... ...
@@ -38,6 +38,8 @@ TABLE_TYPE="TYPE=MyISAM"
38 38
 # user name column
39 39
 USERCOL="username"
40 40
 
41
+GENHA1='gen_ha1'
42
+
41 43
 #################################################################
42 44
 
43 45
 
... ...
@@ -135,9 +137,37 @@ drop database $1;
135 137
 EOF
136 138
 } #ser_drop
137 139
 
140
+# read realm
141
+prompt_realm() 
142
+{
143
+	printf "Doamin (realm) for the default user 'admin': "
144
+	read SIP_DOMAIN
145
+	echo
146
+}
147
+
148
+# calculate credentials for admin
149
+credentials()
150
+{
151
+	HA1=`$GENHA1 admin $SIP_DOMAIN heslo`
152
+	if [ $? -ne 0 ] ; then
153
+		echo "HA1 calculation failed"
154
+		exit 1
155
+	fi
156
+	HA1B=`$GENHA1 "admin@$SIP_DOMAIN" $SIP_DOMAIN heslo`
157
+	if [ $? -ne 0 ] ; then
158
+		echo "HA1B calculation failed"
159
+		exit 1
160
+	fi
161
+
162
+}
163
+
138 164
 ser_create () # pars: <database name> [<no_init_user>]
139 165
 {
140 166
 if [ $# -eq 1 ] ; then
167
+	if [ -z "$SIP_DOMAIN" ] ; then
168
+		prompt_realm
169
+	fi
170
+	credentials
141 171
 	# by default we create initial user
142 172
 	INITIAL_USER="INSERT INTO subscriber 
143 173
 		($USERCOL, password, first_name, last_name, phone, 
... ...
@@ -146,8 +176,7 @@ if [ $# -eq 1 ] ; then
146 176
 		VALUES ( 'admin', 'heslo', 'Initial', 'Admin', '123', 
147 177
 		'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00', 
148 178
 		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '', 
149
-		'0239482f19d262f3953186a725a6f53b', 'iptel.org', 
150
-		'a84e8abaa7e83d1b45c75ab15b90c320', 
179
+		'$HA1', '$SIP_DOMAIN', '$HA1B',
151 180
 		'65e397cda0aa8e3202ea22cbd350e4e9', 'admin' );"
152 181
 elif [ $# -eq 2 ] ; then
153 182
 	# if 3rd param set, don't create any initial user