Browse code

support for "who hang up" in accounting introduced

Jiri Kuthan authored on 05/04/2003 16:02:45
Showing 1 changed files
... ...
@@ -33,6 +33,8 @@ CMD="mysql -h $DBHOST -p -u "
33 33
 BACKUP_CMD="mysqldump -h $DBHOST -p -c -t -u "
34 34
 TABLE_TYPE="TYPE=MyISAM"
35 35
 SQL_USER="root"
36
+# user name column
37
+USERCOL="username"
36 38
 
37 39
 #################################################################
38 40
 
... ...
@@ -85,14 +87,29 @@ drop database $1;
85 87
 EOF
86 88
 } #ser_drop
87 89
 
88
-ser_create () # pars: <database name> <sql_user>
90
+ser_create () # pars: <database name> <sql_user> [<no_init_user>]
89 91
 {
90 92
 
91 93
 #test
92 94
 #cat > /tmp/sss <<EOF
93 95
 
94
-if [ $# -ne 2 ] ; then
95
-	echo "ser_create function takes two params"
96
+if [ $# -eq 2 ] ; then
97
+	# by default we create initial user
98
+	INITIAL_USER="INSERT INTO subscriber 
99
+		($USERCOL, password, first_name, last_name, phone, 
100
+		email_address, datetime_created, datetime_modified, confirmation, 
101
+		flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id, perms ) 
102
+		VALUES ( 'admin', 'heslo', 'Initial', 'Admin', '123', 
103
+		'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00', 
104
+		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '', 
105
+		'0239482f19d262f3953186a725a6f53b', 'iptel.org', 
106
+		'a84e8abaa7e83d1b45c75ab15b90c320', 
107
+		'65e397cda0aa8e3202ea22cbd350e4e9', 'admin' );"
108
+elif [ $# -eq 3 ] ; then
109
+	# if 3rd param set, don't create any initial user
110
+	INITIAL_USER=""
111
+else
112
+	echo "ser_create function takes two or three params"
96 113
 	exit 1
97 114
 fi
98 115
 
... ...
@@ -157,7 +174,9 @@ CREATE TABLE acc (
157 174
   from_uri varchar(128) NOT NULL default '',
158 175
   to_uri varchar(128) NOT NULL default '',
159 176
   sip_callid varchar(128) NOT NULL default '',
160
-  username varchar(64) NOT NULL default '',
177
+  $USERCOL varchar(64) NOT NULL default '',
178
+  fromtag varchar(128) NOT NULL default '',
179
+  totag varchar(128) NOT NULL default '',
161 180
   time datetime NOT NULL default '0000-00-00 00:00:00',
162 181
   timestamp timestamp(14) NOT NULL
163 182
 ) $TABLE_TYPE;
... ...
@@ -181,13 +200,12 @@ CREATE TABLE active_sessions (
181 200
 
182 201
 
183 202
 
184
-
185 203
 #
186 204
 # Table structure for table 'aliases' -- location-like table
187 205
 #
188 206
 
189 207
 CREATE TABLE aliases (
190
-  username varchar(50) NOT NULL default '',
208
+  $USERCOL varchar(50) NOT NULL default '',
191 209
   domain varchar(100) NOT NULL default '',
192 210
   contact varchar(255) NOT NULL default '',
193 211
   expires datetime default NULL,
... ...
@@ -197,7 +215,7 @@ CREATE TABLE aliases (
197 215
   last_modified timestamp(14) NOT NULL,
198 216
   replicate int(10) unsigned default NULL,
199 217
   state tinyint(1) unsigned default NULL,
200
-  PRIMARY KEY(username, domain, contact)
218
+  PRIMARY KEY($USERCOL, domain, contact)
201 219
 ) $TABLE_TYPE;
202 220
 
203 221
 
... ...
@@ -209,7 +227,7 @@ CREATE TABLE aliases (
209 227
 
210 228
 CREATE TABLE event (
211 229
   id int(10) unsigned NOT NULL auto_increment,
212
-  username varchar(50) NOT NULL default '',
230
+  $USERCOL varchar(50) NOT NULL default '',
213 231
   uri varchar(255) NOT NULL default '',
214 232
   description varchar(255) NOT NULL default '',
215 233
   PRIMARY KEY (id)
... ...
@@ -225,11 +243,11 @@ CREATE TABLE event (
225 243
 
226 244
 
227 245
 CREATE TABLE grp (
228
-  username varchar(50) NOT NULL default '',
246
+  $USERCOL varchar(50) NOT NULL default '',
229 247
   domain varchar(100) NOT NULL default '',
230 248
   grp varchar(50) NOT NULL default '',
231 249
   last_modified datetime NOT NULL default '0000-00-00 00:00:00',
232
-  PRIMARY KEY(username, domain, grp)
250
+  PRIMARY KEY($USERCOL, domain, grp)
233 251
 ) $TABLE_TYPE;
234 252
 
235 253
 
... ...
@@ -241,7 +259,7 @@ CREATE TABLE grp (
241 259
 
242 260
 
243 261
 CREATE TABLE location (
244
-  username varchar(50) NOT NULL default '',
262
+  $USERCOL varchar(50) NOT NULL default '',
245 263
   domain varchar(100) NOT NULL default '',
246 264
   contact varchar(255) NOT NULL default '',
247 265
   expires datetime default NULL,
... ...
@@ -251,7 +269,7 @@ CREATE TABLE location (
251 269
   last_modified timestamp(14) NOT NULL,
252 270
   replicate int(10) unsigned default NULL,
253 271
   state tinyint(1) unsigned default NULL,
254
-  PRIMARY KEY(username, domain, contact)
272
+  PRIMARY KEY($USERCOL, domain, contact)
255 273
 ) $TABLE_TYPE;
256 274
 
257 275
 
... ...
@@ -273,7 +291,9 @@ CREATE TABLE missed_calls (
273 291
   from_uri varchar(128) NOT NULL default '',
274 292
   to_uri varchar(128) NOT NULL default '',
275 293
   sip_callid varchar(128) NOT NULL default '',
276
-  username varchar(64) NOT NULL default '',
294
+  $USERCOL varchar(64) NOT NULL default '',
295
+  fromtag varchar(128) NOT NULL default '',
296
+  totag varchar(128) NOT NULL default '',
277 297
   time datetime NOT NULL default '0000-00-00 00:00:00',
278 298
   timestamp timestamp(14) NOT NULL
279 299
 ) $TABLE_TYPE;
... ...
@@ -289,7 +309,7 @@ CREATE TABLE missed_calls (
289 309
 
290 310
 CREATE TABLE pending (
291 311
   phplib_id varchar(32) NOT NULL default '',
292
-  username varchar(100) NOT NULL default '',
312
+  $USERCOL varchar(100) NOT NULL default '',
293 313
   password varchar(25) NOT NULL default '',
294 314
   first_name varchar(25) NOT NULL default '',
295 315
   last_name varchar(45) NOT NULL default '',
... ...
@@ -307,8 +327,8 @@ CREATE TABLE pending (
307 327
   perms varchar(32) default NULL,
308 328
   allow_find char(1) NOT NULL default '0',
309 329
   timezone varchar(128) default NULL,
310
-  PRIMARY KEY (username, domain),
311
-  KEY user_2 (username),
330
+  PRIMARY KEY ($USERCOL, domain),
331
+  KEY user_2 ($USERCOL),
312 332
   UNIQUE KEY phplib_id (phplib_id)
313 333
 ) $TABLE_TYPE;
314 334
 
... ...
@@ -322,7 +342,7 @@ CREATE TABLE pending (
322 342
 
323 343
 CREATE TABLE phonebook (
324 344
   id int(10) unsigned NOT NULL auto_increment,
325
-  username varchar(50) NOT NULL default '',
345
+  $USERCOL varchar(50) NOT NULL default '',
326 346
   fname varchar(32) NOT NULL default '',
327 347
   lname varchar(32) NOT NULL default '',
328 348
   sip_uri varchar(128) NOT NULL default '',
... ...
@@ -339,7 +359,7 @@ CREATE TABLE phonebook (
339 359
 
340 360
 
341 361
 CREATE TABLE reserved (
342
-  username char(100) NOT NULL default '',
362
+  $USERCOL char(100) NOT NULL default '',
343 363
   UNIQUE KEY user2(username)
344 364
 ) $TABLE_TYPE;
345 365
 
... ...
@@ -353,7 +373,7 @@ CREATE TABLE reserved (
353 373
 
354 374
 CREATE TABLE subscriber (
355 375
   phplib_id varchar(32) NOT NULL default '',
356
-  username varchar(100) NOT NULL default '',
376
+  $USERCOL varchar(100) NOT NULL default '',
357 377
   password varchar(25) NOT NULL default '',
358 378
   first_name varchar(25) NOT NULL default '',
359 379
   last_name varchar(45) NOT NULL default '',
... ...
@@ -372,8 +392,8 @@ CREATE TABLE subscriber (
372 392
   allow_find char(1) NOT NULL default '0',
373 393
   timezone varchar(128) default NULL,
374 394
   UNIQUE KEY phplib_id (phplib_id),
375
-  PRIMARY KEY (username, domain),
376
-  KEY user_2 (username)
395
+  PRIMARY KEY ($USERCOL, domain),
396
+  KEY user_2 ($USERCOL)
377 397
 ) $TABLE_TYPE;
378 398
 
379 399
 # hook-table for all posssible future config values
... ...
@@ -382,7 +402,7 @@ CREATE TABLE subscriber (
382 402
 CREATE TABLE config (
383 403
    attribute varchar(32) NOT NULL,
384 404
    value varchar(128) NOT NULL,
385
-   username varchar(100) NOT NULL default '',
405
+   $USERCOL varchar(100) NOT NULL default '',
386 406
    modified timestamp(14)
387 407
 ) $TABLE_TYPE;
388 408
 
... ...
@@ -415,11 +435,11 @@ CREATE TABLE domain (
415 435
 # Table structure for table 'uri' -- uri user parts users are allowed to use
416 436
 #
417 437
 CREATE TABLE uri (
418
-  username varchar(50) NOT NULL default '',
438
+  $USERCOL varchar(50) NOT NULL default '',
419 439
   domain varchar(50) NOT NULL default '',
420 440
   uri_user varchar(50) NOT NULL default '',
421 441
   last_modified datetime NOT NULL default '0000-00-00 00:00:00',
422
-  PRIMARY KEY (username, domain, uri_user)
442
+  PRIMARY KEY ($USERCOL, domain, uri_user)
423 443
 ) $TABLE_TYPE;
424 444
 
425 445
 #
... ...
@@ -482,14 +502,8 @@ CREATE TABLE server_monitoring_ul (
482 502
 # add an admin user "admin" with password==heslo, 
483 503
 # so that one can try it out on quick start
484 504
 
485
-INSERT INTO subscriber (username, password, first_name, last_name, phone, 
486
-	email_address, datetime_created, datetime_modified, confirmation, 
487
-	flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id, perms ) 
488
-	VALUES ( 'admin', 'heslo', 'Initial', 'Admin', '123', 
489
-	'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00', 
490
-	'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '', 
491
-	'0239482f19d262f3953186a725a6f53b', 'iptel.org', 
492
-	'a84e8abaa7e83d1b45c75ab15b90c320', '65e397cda0aa8e3202ea22cbd350e4e9', 'admin' );
505
+$INITIAL_USER
506
+
493 507
 
494 508
 
495 509
 EOF
... ...
@@ -499,7 +513,10 @@ EOF
499 513
 
500 514
 case $1 in
501 515
 	renew)
502
-		# backup, drop, restore (experimental)
516
+		# backup, drop, restore -- experimental; thought to
517
+		# deal with upgrade to new structures which include
518
+		# new tables or columns (troubles can appear if columns
519
+		# renamed); not tested too much yet
503 520
 		tmp_file=/tmp/ser_mysql.$$
504 521
 		ser_backup $DBNAME $SQL_USER > $tmp_file
505 522
 		ret=$?
... ...
@@ -512,7 +529,7 @@ case $1 in
512 529
 		if [ "$ret" -ne 0 ]; then
513 530
 			exit $ret
514 531
 		fi
515
-		ser_create $DBNAME $SQL_USER
532
+		ser_create $DBNAME $SQL_USER no_init_user
516 533
 		ret=$?
517 534
 		if [ "$ret" -ne 0 ]; then
518 535
 			exit $ret
... ...
@@ -536,7 +553,7 @@ case $1 in
536 553
 			rm $tmp_file
537 554
 			exit $ret
538 555
 		fi
539
-		ser_create $1 $SQL_USER
556
+		ser_create $1 $SQL_USER no_init_user
540 557
 		ret=$?
541 558
 		if [ "$ret" -ne 0 ]; then
542 559
 			rm $tmp_file