Browse code

- reinstall functonality fixed (only for mysql) - serweb tables moved away from the openser tables - replaced gen_ha1 with md5sum

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@788 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 07/04/2006 14:03:54
Showing 2 changed files
... ...
@@ -20,6 +20,9 @@
20 20
 #             tables to domain (janakj)
21 21
 # 2003-04-14  reinstall introduced (jiri)
22 22
 # 2004-07-05  new definition of table silo (dcm)
23
+# 2006-04-07  removed gen_ha1 dependency - use md5sum;
24
+#             separated the serweb from openser tables;
25
+#             fixed the reinstall functionality (bogdan)
23 26
 
24 27
 PATH=$PATH:/usr/local/sbin
25 28
 
... ...
@@ -78,10 +81,6 @@ fi
78 78
 if [ -z "$USERCOL" ]; then
79 79
 	USERCOL="username"
80 80
 fi
81
-# path to gen_ha1 tool
82
-if [ -z "$GENHA1" ]; then
83
-	GENHA1='openser_gen_ha1'
84
-fi
85 81
 
86 82
 FOREVER="2020-05-28 21:32:15"
87 83
 
... ...
@@ -101,9 +100,11 @@ usage: $COMMAND create
101 101
        $COMMAND drop   (!!entirely deletes tables)
102 102
        $COMMAND reinit (!!entirely deletes and than re-creates tables
103 103
        $COMMAND backup (dumps current database to stdout)
104
-	   $COMMAND restore <file> (restores tables from a file)
104
+       $COMMAND restore <file> (restores tables from a file)
105 105
        $COMMAND copy <new_db> (creates a new db from an existing one)
106
-       $COMMAND reinstall (updates to a new SER database)
106
+       $COMMAND reinstall (updates to a new OpenSER database)
107
+       $COMMAND serweb (adds the SERWEB specific tables)
108
+       $COMMAND reinit (drops ans install OpenSER database)
107 109
 
108 110
        if you want to manipulate database as other MySql user than
109 111
        root, want to change database name from default value "$DBNAME",
... ...
@@ -132,10 +133,10 @@ sql_query()
132 132
 }
133 133
 
134 134
 # dump all rows
135
-ser_dump()  # pars: <database name>
135
+openser_dump()  # pars: <database name>
136 136
 {
137 137
 	if [ $# -ne 1 ] ; then
138
-		echo "ser_dump function takes one param"
138
+		echo "openser_dump function takes one param"
139 139
 		exit 1
140 140
 	fi
141 141
 	$DUMP_CMD "-p$PW" $1
... ...
@@ -143,50 +144,53 @@ ser_dump()  # pars: <database name>
143 143
 
144 144
 
145 145
 # copy a database to database_bak
146
-ser_backup() # par: <database name>
146
+openser_backup() # par: <database name>
147 147
 {
148 148
 	if [ $# -ne 1 ] ; then
149
-		echo  "ser_backup function takes one param"
149
+		echo  "openser_backup function takes one param"
150 150
 		exit 1
151 151
 	fi
152 152
 	BU=/tmp/mysql_bup.$$
153 153
 	$BACKUP_CMD "-p$PW" $1 > $BU
154 154
 	if [ "$?" -ne 0 ] ; then
155
-		echo "ser backup dump failed"
155
+		echo "openser_backup dump failed"
156 156
 		exit 1
157 157
 	fi
158 158
 	sql_query <<EOF
159 159
 	create database $1_bak;
160 160
 EOF
161 161
 
162
-	ser_restore $1_bak $BU
162
+	openser_restore $1_bak $BU
163 163
 	if [ "$?" -ne 0 ]; then
164
-		echo "ser backup/restore failed"
164
+		echo "openser backup/restore failed"
165 165
 		rm $BU
166 166
 		exit 1
167 167
 	fi
168 168
 }
169 169
 
170
-ser_restore() #pars: <database name> <filename>
170
+
171
+openser_restore() #pars: <database name> <filename>
171 172
 {
172 173
 if [ $# -ne 2 ] ; then
173
-	echo "ser_restore function takes two params"
174
+	echo "openser_restore function takes two params"
174 175
 	exit 1
175 176
 fi
176 177
 sql_query $1 < $2
177 178
 }
178 179
 
179
-ser_drop()  # pars: <database name>
180
+
181
+openser_drop()  # pars: <database name>
180 182
 {
181 183
 if [ $# -ne 1 ] ; then
182
-	echo "ser_drop function takes two params"
184
+	echo "openser_drop function takes two params"
183 185
 	exit 1
184 186
 fi
185 187
 
186 188
 sql_query << EOF
187 189
 drop database $1;
188 190
 EOF
189
-} #ser_drop
191
+}
192
+
190 193
 
191 194
 # read realm
192 195
 prompt_realm()
... ...
@@ -196,30 +200,32 @@ prompt_realm()
196 196
 	echo
197 197
 }
198 198
 
199
+
199 200
 # calculate credentials for admin
200 201
 credentials()
201 202
 {
202
-	HA1=`$GENHA1 admin $SIP_DOMAIN $DEFAULT_PW`
203
+	HA1=`echo -n "admin:$SIP_DOMAIN:$DEFAULT_PW" | md5sum | awk '{ print $1 }'`
203 204
 	if [ $? -ne 0 ] ; then
204 205
 		echo "HA1 calculation failed"
205 206
 		exit 1
206 207
 	fi
207
-	HA1B=`$GENHA1 "admin@$SIP_DOMAIN" $SIP_DOMAIN $DEFAULT_PW`
208
+	HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DEFAULT_PW" | md5sum | awk '{ print $1 }'`
208 209
 	if [ $? -ne 0 ] ; then
209 210
 		echo "HA1B calculation failed"
210 211
 		exit 1
211 212
 	fi
212 213
 
213
-  #PHPLIB_ID of users should be difficulty to guess for security reasons
214
-  NOW=`date`;
215
-  PHPLIB_ID=`$GENHA1 "$RANDOM" "$NOW" $SIP_DOMAIN`
214
+	#PHPLIB_ID of users should be difficulty to guess for security reasons
215
+	NOW=`date`;
216
+	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | md5sum | awk '{ print $1 }'`
216 217
 	if [ $? -ne 0 ] ; then
217
-    echo "PHPLIB_ID calculation failed"
218
+		echo "PHPLIB_ID calculation failed"
218 219
 		exit 1
219 220
 	fi
220 221
 }
221 222
 
222
-ser_create () # pars: <database name> [<no_init_user>]
223
+
224
+openser_create () # pars: <database name> [<no_init_user>]
223 225
 {
224 226
 if [ $# -eq 1 ] ; then
225 227
 	if [ -z "$SIP_DOMAIN" ] ; then
... ...
@@ -230,23 +236,17 @@ if [ $# -eq 1 ] ; then
230 230
 	INITIAL_USER="INSERT INTO subscriber
231 231
 		($USERCOL, password, first_name, last_name, phone,
232 232
 		email_address, datetime_created, datetime_modified, confirmation,
233
-    flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
233
+		flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
234 234
 		VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
235 235
 		'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00',
236 236
 		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
237 237
 		'$HA1', '$SIP_DOMAIN', '$HA1B',
238
-    '$PHPLIB_ID' );
239
-
240
-    INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
241
-    VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
242
-
243
-    INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
244
-    VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
238
+		'$PHPLIB_ID' );"
245 239
 elif [ $# -eq 2 ] ; then
246 240
 	# if 3rd param set, don't create any initial user
247 241
 	INITIAL_USER=""
248 242
 else
249
-	echo "ser_create function takes one or two params"
243
+	echo "openser_create function takes one or two params"
250 244
 	exit 1
251 245
 fi
252 246
 
... ...
@@ -277,29 +277,17 @@ CREATE TABLE version (
277 277
 #
278 278
 
279 279
 INSERT INTO version VALUES ( 'subscriber', '5');
280
-INSERT INTO version VALUES ( 'reserved', '1');
281
-INSERT INTO version VALUES ( 'phonebook', '1');
282
-INSERT INTO version VALUES ( 'pending', '4');
283 280
 INSERT INTO version VALUES ( 'missed_calls', '2');
284 281
 INSERT INTO version VALUES ( 'location', '1003');
285 282
 INSERT INTO version VALUES ( 'aliases', '1003');
286 283
 INSERT INTO version VALUES ( 'grp', '2');
287 284
 INSERT INTO version VALUES ( 're_grp', '1');
288
-INSERT INTO version VALUES ( 'event', '1');
289
-INSERT INTO version VALUES ( 'active_sessions', '1');
290 285
 INSERT INTO version VALUES ( 'acc', '2');
291
-INSERT INTO version VALUES ( 'config', '1');
292 286
 INSERT INTO version VALUES ( 'silo', '4');
293
-INSERT INTO version VALUES ( 'realm', '1');
294 287
 INSERT INTO version VALUES ( 'domain', '1');
295 288
 INSERT INTO version VALUES ( 'uri', '1');
296
-INSERT INTO version VALUES ( 'server_monitoring', '1');
297
-INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
298 289
 INSERT INTO version VALUES ( 'trusted', '3');
299 290
 INSERT INTO version VALUES ( 'usr_preferences', '2');
300
-INSERT INTO version VALUES ( 'usr_preferences_types', '1');
301
-INSERT INTO version VALUES ( 'admin_privileges', '1');
302
-INSERT INTO version VALUES ( 'calls_forwarding', '1');
303 291
 INSERT INTO version VALUES ( 'speed_dial', '2');
304 292
 INSERT INTO version VALUES ( 'dbaliases', '1');
305 293
 INSERT INTO version VALUES ( 'gw', '3');
... ...
@@ -307,14 +295,43 @@ INSERT INTO version VALUES ( 'gw_grp', '1');
307 307
 INSERT INTO version VALUES ( 'lcr', '2');
308 308
 INSERT INTO version VALUES ( 'sip_trace', '1');
309 309
 
310
+
311
+
310 312
 #
311
-# Table structure for table 'acc' -- accounted calls
313
+# Table structure for table 'subscriber' -- user database
312 314
 #
315
+CREATE TABLE subscriber (
316
+  phplib_id varchar(32) NOT NULL default '',
317
+  $USERCOL varchar(64) NOT NULL default '',
318
+  domain varchar(128) NOT NULL default '',
319
+  password varchar(25) NOT NULL default '',
320
+  first_name varchar(25) NOT NULL default '',
321
+  last_name varchar(45) NOT NULL default '',
322
+  phone varchar(15) NOT NULL default '',
323
+  email_address varchar(50) NOT NULL default '',
324
+  datetime_created datetime NOT NULL default '0000-00-00 00:00:00',
325
+  datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
326
+  confirmation varchar(64) NOT NULL default '',
327
+  flag char(1) NOT NULL default 'o',
328
+  sendnotification varchar(50) NOT NULL default '',
329
+  greeting varchar(50) NOT NULL default '',
330
+  ha1 varchar(128) NOT NULL default '',
331
+  ha1b varchar(128) NOT NULL default '',
332
+  allow_find char(1) NOT NULL default '0',
333
+  timezone varchar(128) default NULL,
334
+  rpid varchar(128) default NULL,
335
+  domn int(10) default NULL,
336
+  uuid varchar(64) default NULL,
337
+  UNIQUE KEY phplib_id (phplib_id),
338
+  PRIMARY KEY ($USERCOL, domain),
339
+  KEY user_2 ($USERCOL)
340
+) $TABLE_TYPE;
313 341
 
314 342
 
343
+#
344
+# Table structure for table 'acc' -- accounted calls
345
+#
315 346
 CREATE TABLE acc (
316
-  caller_UUID varchar(64) NOT NULL default '',
317
-  callee_UUID varchar(64) NOT NULL default '',
318 347
   sip_from varchar(128) NOT NULL default '',
319 348
   sip_to varchar(128) NOT NULL default '',
320 349
   sip_status varchar(128) NOT NULL default '',
... ...
@@ -330,8 +347,6 @@ CREATE TABLE acc (
330 330
   totag varchar(128) NOT NULL default '',
331 331
   time datetime NOT NULL default '0000-00-00 00:00:00',
332 332
   timestamp timestamp(14) NOT NULL,
333
-  caller_deleted char(1) NOT NULL default '0',
334
-  callee_deleted char(1) NOT NULL default '0',
335 333
   src_leg varchar(128) default NULL,
336 334
   dst_leg varchar(128) default NULL,
337 335
   INDEX acc_user ($USERCOL, domain),
... ...
@@ -339,29 +354,58 @@ CREATE TABLE acc (
339 339
 ) $TABLE_TYPE;
340 340
 
341 341
 
342
-
343
-
344 342
 #
345
-# Table structure for table 'active_sessions' -- web stuff
343
+# Table structure for table 'missed_calls' -- acc-like table
344
+# for keeping track of missed calls
346 345
 #
346
+CREATE TABLE missed_calls (
347
+  sip_from varchar(128) NOT NULL default '',
348
+  sip_to varchar(128) NOT NULL default '',
349
+  sip_status varchar(128) NOT NULL default '',
350
+  sip_method varchar(16) NOT NULL default '',
351
+  i_uri varchar(128) NOT NULL default '',
352
+  o_uri varchar(128) NOT NULL default '',
353
+  from_uri varchar(128) NOT NULL default '',
354
+  to_uri varchar(128) NOT NULL default '',
355
+  sip_callid varchar(128) NOT NULL default '',
356
+  $USERCOL varchar(64) NOT NULL default '',
357
+  domain varchar(128) NOT NULL default '',
358
+  fromtag varchar(128) NOT NULL default '',
359
+  totag varchar(128) NOT NULL default '',
360
+  time datetime NOT NULL default '0000-00-00 00:00:00',
361
+  timestamp timestamp(14) NOT NULL,
362
+  src_leg varchar(128) default NULL,
363
+  dst_leg varchar(128) default NULL,
364
+  INDEX mc_user ($USERCOL, domain)
365
+) $TABLE_TYPE;
347 366
 
348 367
 
349
-CREATE TABLE active_sessions (
350
-  sid varchar(32) NOT NULL default '',
351
-  name varchar(32) NOT NULL default '',
352
-  val text,
353
-  changed varchar(14) NOT NULL default '',
354
-  PRIMARY KEY  (name,sid),
355
-  KEY changed (changed)
368
+#
369
+# Table structure for table 'location' -- that is persistent UsrLoc
370
+#
371
+CREATE TABLE location (
372
+  $USERCOL varchar(64) NOT NULL default '',
373
+  domain varchar(128) NOT NULL default '',
374
+  contact varchar(255) NOT NULL default '',
375
+  received varchar(255) default NULL,
376
+  path varchar(255) default NULL,
377
+  expires datetime NOT NULL default '$DEFAULT_LOCATION_EXPIRES',
378
+  q float(10,2) NOT NULL default '$DEFAULT_Q',
379
+  callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
380
+  cseq int(11) NOT NULL default '$DEFAULT_CSEQ',
381
+  last_modified timestamp(14) NOT NULL,
382
+  flags int(11) NOT NULL default '0',
383
+  user_agent varchar(255) NOT NULL default '',
384
+  socket varchar(128) default NULL,
385
+  methods int(11) default NULL,
386
+  PRIMARY KEY($USERCOL, domain, contact)
356 387
 ) $TABLE_TYPE;
357 388
 
358 389
 
359
-
360 390
 #
361 391
 # Table structure for table 'aliases' -- location-like table
362 392
 # (aliases_contact index makes lookup of missed calls much faster)
363 393
 #
364
-
365 394
 CREATE TABLE aliases (
366 395
   $USERCOL varchar(64) NOT NULL default '',
367 396
   domain varchar(128) NOT NULL default '',
... ...
@@ -385,7 +429,6 @@ CREATE TABLE aliases (
385 385
 #
386 386
 # DB aliases
387 387
 #
388
-
389 388
 CREATE TABLE dbaliases (
390 389
   alias_username varchar(64) NOT NULL default '',
391 390
   alias_domain varchar(128) NOT NULL default '',
... ...
@@ -400,8 +443,6 @@ CREATE TABLE dbaliases (
400 400
 # Table structure for table 'grp' -- group membership
401 401
 # table; used primarily for ACLs
402 402
 #
403
-
404
-
405 403
 CREATE TABLE grp (
406 404
   $USERCOL varchar(64) NOT NULL default '',
407 405
   domain varchar(128) NOT NULL default '',
... ...
@@ -415,8 +456,6 @@ CREATE TABLE grp (
415 415
 # Table structure for table 're_grp' -- group membership
416 416
 # based on regular expressions
417 417
 #
418
-
419
-
420 418
 CREATE TABLE re_grp (
421 419
   reg_exp varchar(128) NOT NULL default '',
422 420
   group_id int(11) NOT NULL default '0',
... ...
@@ -425,145 +464,8 @@ CREATE TABLE re_grp (
425 425
 
426 426
 
427 427
 #
428
-# Table structure for table 'location' -- that is persistent UsrLoc
429
-#
430
-CREATE TABLE location (
431
-  $USERCOL varchar(64) NOT NULL default '',
432
-  domain varchar(128) NOT NULL default '',
433
-  contact varchar(255) NOT NULL default '',
434
-  received varchar(255) default NULL,
435
-  path varchar(255) default NULL,
436
-  expires datetime NOT NULL default '$DEFAULT_LOCATION_EXPIRES',
437
-  q float(10,2) NOT NULL default '$DEFAULT_Q',
438
-  callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
439
-  cseq int(11) NOT NULL default '$DEFAULT_CSEQ',
440
-  last_modified timestamp(14) NOT NULL,
441
-  flags int(11) NOT NULL default '0',
442
-  user_agent varchar(255) NOT NULL default '',
443
-  socket varchar(128) default NULL,
444
-  methods int(11) default NULL,
445
-  PRIMARY KEY($USERCOL, domain, contact)
446
-) $TABLE_TYPE;
447
-
448
-
449
-
450
-
451
-#
452
-# Table structure for table 'missed_calls' -- acc-like table
453
-# for keeping track of missed calls
454
-#
455
-
456
-
457
-CREATE TABLE missed_calls (
458
-  sip_from varchar(128) NOT NULL default '',
459
-  sip_to varchar(128) NOT NULL default '',
460
-  sip_status varchar(128) NOT NULL default '',
461
-  sip_method varchar(16) NOT NULL default '',
462
-  i_uri varchar(128) NOT NULL default '',
463
-  o_uri varchar(128) NOT NULL default '',
464
-  from_uri varchar(128) NOT NULL default '',
465
-  to_uri varchar(128) NOT NULL default '',
466
-  sip_callid varchar(128) NOT NULL default '',
467
-  $USERCOL varchar(64) NOT NULL default '',
468
-  domain varchar(128) NOT NULL default '',
469
-  fromtag varchar(128) NOT NULL default '',
470
-  totag varchar(128) NOT NULL default '',
471
-  time datetime NOT NULL default '0000-00-00 00:00:00',
472
-  timestamp timestamp(14) NOT NULL,
473
-  src_leg varchar(128) default NULL,
474
-  dst_leg varchar(128) default NULL,
475
-  INDEX mc_user ($USERCOL, domain)
476
-) $TABLE_TYPE;
477
-
478
-
479
-
480
-
481
-#
482
-# Table structure for table 'pending' -- unconfirmed subscribtion
483
-# requests
484
-#
485
-
486
-
487
-CREATE TABLE pending (
488
-  phplib_id varchar(32) NOT NULL default '',
489
-  $USERCOL varchar(64) NOT NULL default '',
490
-  domain varchar(128) NOT NULL default '',
491
-  password varchar(25) NOT NULL default '',
492
-  first_name varchar(25) NOT NULL default '',
493
-  last_name varchar(45) NOT NULL default '',
494
-  phone varchar(15) NOT NULL default '',
495
-  email_address varchar(50) NOT NULL default '',
496
-  datetime_created datetime NOT NULL default '0000-00-00 00:00:00',
497
-  datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
498
-  confirmation varchar(64) NOT NULL default '',
499
-  flag char(1) NOT NULL default 'o',
500
-  sendnotification varchar(50) NOT NULL default '',
501
-  greeting varchar(50) NOT NULL default '',
502
-  ha1 varchar(128) NOT NULL default '',
503
-  ha1b varchar(128) NOT NULL default '',
504
-  allow_find char(1) NOT NULL default '0',
505
-  timezone varchar(128) default NULL,
506
-  rpid varchar(128) default NULL,
507
-  domn int(10) default NULL,
508
-  uuid varchar(64) default NULL,
509
-  PRIMARY KEY ($USERCOL, domain),
510
-  KEY user_2 ($USERCOL),
511
-  UNIQUE KEY phplib_id (phplib_id)
512
-) $TABLE_TYPE;
513
-
514
-
515
-
516
-
517
-#
518
-# Table structure for table 'phonebook' -- user's phonebook
519
-#
520
-
521
-
522
-CREATE TABLE phonebook (
523
-  id int(10) unsigned NOT NULL auto_increment,
524
-  $USERCOL varchar(64) NOT NULL default '',
525
-  domain varchar(128) NOT NULL default '',
526
-  fname varchar(32) NOT NULL default '',
527
-  lname varchar(32) NOT NULL default '',
528
-  sip_uri varchar(128) NOT NULL default '',
529
-  PRIMARY KEY  (id)
530
-) $TABLE_TYPE;
531
-
532
-
533
-#
534
-# Table structure for table 'subscriber' -- user database
535
-#
536
-
537
-
538
-CREATE TABLE subscriber (
539
-  phplib_id varchar(32) NOT NULL default '',
540
-  $USERCOL varchar(64) NOT NULL default '',
541
-  domain varchar(128) NOT NULL default '',
542
-  password varchar(25) NOT NULL default '',
543
-  first_name varchar(25) NOT NULL default '',
544
-  last_name varchar(45) NOT NULL default '',
545
-  phone varchar(15) NOT NULL default '',
546
-  email_address varchar(50) NOT NULL default '',
547
-  datetime_created datetime NOT NULL default '0000-00-00 00:00:00',
548
-  datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
549
-  confirmation varchar(64) NOT NULL default '',
550
-  flag char(1) NOT NULL default 'o',
551
-  sendnotification varchar(50) NOT NULL default '',
552
-  greeting varchar(50) NOT NULL default '',
553
-  ha1 varchar(128) NOT NULL default '',
554
-  ha1b varchar(128) NOT NULL default '',
555
-  allow_find char(1) NOT NULL default '0',
556
-  timezone varchar(128) default NULL,
557
-  rpid varchar(128) default NULL,
558
-  domn int(10) default NULL,
559
-  uuid varchar(64) default NULL,
560
-  UNIQUE KEY phplib_id (phplib_id),
561
-  PRIMARY KEY ($USERCOL, domain),
562
-  KEY user_2 ($USERCOL)
563
-) $TABLE_TYPE;
564
-
565 428
 # "instant" message silo
566
-
429
+#
567 430
 CREATE TABLE silo(
568 431
     mid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
569 432
     src_addr VARCHAR(255) NOT NULL DEFAULT "",
... ...
@@ -578,10 +480,10 @@ CREATE TABLE silo(
578 578
     body BLOB NOT NULL DEFAULT ""
579 579
 ) $TABLE_TYPE;
580 580
 
581
+
581 582
 #
582 583
 # Table structure for table 'domain' -- domains proxy is responsible for
583 584
 #
584
-
585 585
 CREATE TABLE domain (
586 586
   domain varchar(128) NOT NULL default '',
587 587
   last_modified datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -600,25 +502,10 @@ CREATE TABLE uri (
600 600
   PRIMARY KEY ($USERCOL, domain, uri_user)
601 601
 ) $TABLE_TYPE;
602 602
 
603
-#
604
-# Table structure for table 'server_monitoring'
605
-#
606
-
607
-
608
-DROP TABLE IF EXISTS server_monitoring;
609
-CREATE TABLE server_monitoring (
610
-  time datetime NOT NULL default '0000-00-00 00:00:00',
611
-  id int(10) unsigned NOT NULL default '0',
612
-  param varchar(32) NOT NULL default '',
613
-  value int(10) NOT NULL default '0',
614
-  increment int(10) NOT NULL default '0',
615
-  PRIMARY KEY  (id,param)
616
-) $TABLE_TYPE;
617 603
 
618 604
 #
619 605
 # Table structure for table 'usr_preferences'
620 606
 #
621
-
622 607
 DROP TABLE IF EXISTS usr_preferences;
623 608
 CREATE TABLE usr_preferences (
624 609
   uuid varchar(64) NOT NULL default '',
... ...
@@ -635,22 +522,8 @@ CREATE TABLE usr_preferences (
635 635
 
636 636
 
637 637
 #
638
-# Table structure for table 'usr_preferences_type'
639
-#
640
-
641
-DROP TABLE IF EXISTS usr_preferences_types;
642
-CREATE TABLE usr_preferences_types (
643
-  att_name varchar(32) NOT NULL default '',
644
-  att_rich_type varchar(32) NOT NULL default 'string',
645
-  att_raw_type int NOT NULL default '2',
646
-  att_type_spec text,
647
-  default_value varchar(100) NOT NULL default '',
648
-  PRIMARY KEY  (att_name)
649
-) $TABLE_TYPE;
650
-
651
-
652
-#
653 638
 # Table structure for table trusted
639
+#
654 640
 CREATE TABLE trusted (
655 641
   src_ip varchar(39) NOT NULL,
656 642
   proto varchar(4) NOT NULL,
... ...
@@ -661,43 +534,8 @@ CREATE TABLE trusted (
661 661
 
662 662
 
663 663
 #
664
-# Table structure for table 'server_monitoring_agg'
665
-#
666
-DROP TABLE IF EXISTS server_monitoring_agg;
667
-CREATE TABLE server_monitoring_agg (
668
-  param varchar(32) NOT NULL default '',
669
-  s_value int(10) NOT NULL default '0',
670
-  s_increment int(10) NOT NULL default '0',
671
-  last_aggregated_increment int(10) NOT NULL default '0',
672
-  av float NOT NULL default '0',
673
-  mv int(10) NOT NULL default '0',
674
-  ad float NOT NULL default '0',
675
-  lv int(10) NOT NULL default '0',
676
-  min_val int(10) NOT NULL default '0',
677
-  max_val int(10) NOT NULL default '0',
678
-  min_inc int(10) NOT NULL default '0',
679
-  max_inc int(10) NOT NULL default '0',
680
-  lastupdate datetime NOT NULL default '0000-00-00 00:00:00',
681
-  PRIMARY KEY  (param)
682
-) $TABLE_TYPE;
683
-
684
-#
685
-# Table structure for table 'admin_privileges' -- multidomain serweb ACL control
686
-#
687
-
688
-CREATE TABLE admin_privileges (
689
-  $USERCOL varchar(64) NOT NULL default '',
690
-  domain varchar(128) NOT NULL default '',
691
-  priv_name varchar(64) NOT NULL default '',
692
-  priv_value varchar(64) NOT NULL default '',
693
-  PRIMARY KEY  ($USERCOL,priv_name,priv_value,domain)
694
-) $TABLE_TYPE;
695
-
696
-
697
-#
698 664
 # Table structure for table 'speed_dial'
699 665
 #
700
-
701 666
 CREATE TABLE speed_dial (
702 667
   uuid varchar(64) NOT NULL default '',
703 668
   $USERCOL varchar(64) NOT NULL default '',
... ...
@@ -715,7 +553,6 @@ CREATE TABLE speed_dial (
715 715
 #
716 716
 # Table structure for table 'gw'
717 717
 #
718
-
719 718
 CREATE TABLE gw (
720 719
   gw_name VARCHAR(128) NOT NULL,
721 720
   grp_id INT UNSIGNED NOT NULL,
... ...
@@ -733,7 +570,6 @@ CREATE TABLE gw (
733 733
 #
734 734
 # Table structure for table 'gw_grp'
735 735
 #
736
-
737 736
 CREATE TABLE gw_grp (
738 737
   grp_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
739 738
   grp_name VARCHAR(64) NOT NULL
... ...
@@ -743,7 +579,6 @@ CREATE TABLE gw_grp (
743 743
 #
744 744
 # Table structure for table 'lcr'
745 745
 #
746
-
747 746
 CREATE TABLE lcr (
748 747
   prefix varchar(16) NOT NULL,
749 748
   from_uri varchar(128) DEFAULT NULL,
... ...
@@ -754,10 +589,10 @@ CREATE TABLE lcr (
754 754
   KEY (grp_id)
755 755
 ) $TABLE_TYPE;
756 756
 
757
+
757 758
 #
758 759
 # Table structure for table 'siptrace'
759 760
 #
760
-
761 761
 CREATE TABLE sip_trace (
762 762
   id bigint(20) NOT NULL auto_increment,
763 763
   date datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -779,13 +614,173 @@ CREATE TABLE sip_trace (
779 779
 
780 780
 # add an admin user "admin" with password==$DEFAULT_PW,
781 781
 # so that one can try it out on quick start
782
-
783 782
 $INITIAL_USER
783
+EOF
784
+
785
+echo -n "Install SERWEB tables ?(y/n):"
786
+read INPUT
787
+if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
788
+then
789
+	serweb_create $1 $2
790
+fi
791
+} # openser_create
784 792
 
785 793
 
794
+serweb_create () # pars: <database name>
795
+{
796
+if [ $# -eq 1 ] ; then
797
+	if [ -z "$SIP_DOMAIN" ] ; then
798
+		prompt_realm
799
+	fi
800
+	INITIAL_INSERT="
801
+		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
802
+		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
803
+		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
804
+		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
805
+elif [ $# -eq 2 ] ; then
806
+	# if 3rd param set, don't do any initial insert
807
+	INITIAL_INSERT=""
808
+else
809
+	echo "serweb_create function takes one or two params"
810
+	exit 1
811
+fi
812
+
813
+echo "creating serweb tables into $1 ..."
814
+
815
+sql_query <<EOF
816
+use $1;
817
+
818
+INSERT INTO version VALUES ( 'phonebook', '1');
819
+INSERT INTO version VALUES ( 'pending', '4');
820
+INSERT INTO version VALUES ( 'active_sessions', '1');
821
+INSERT INTO version VALUES ( 'server_monitoring', '1');
822
+INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
823
+INSERT INTO version VALUES ( 'usr_preferences_types', '1');
824
+INSERT INTO version VALUES ( 'admin_privileges', '1');
825
+
826
+
827
+#
828
+# Table structure for table 'active_sessions' -- web stuff
829
+#
830
+CREATE TABLE active_sessions (
831
+  sid varchar(32) NOT NULL default '',
832
+  name varchar(32) NOT NULL default '',
833
+  val text,
834
+  changed varchar(14) NOT NULL default '',
835
+  PRIMARY KEY  (name,sid),
836
+  KEY changed (changed)
837
+) $TABLE_TYPE;
838
+
839
+
840
+#
841
+# Table structure for table 'pending' -- unconfirmed subscribtion
842
+# requests
843
+#
844
+CREATE TABLE pending (
845
+  phplib_id varchar(32) NOT NULL default '',
846
+  $USERCOL varchar(64) NOT NULL default '',
847
+  domain varchar(128) NOT NULL default '',
848
+  password varchar(25) NOT NULL default '',
849
+  first_name varchar(25) NOT NULL default '',
850
+  last_name varchar(45) NOT NULL default '',
851
+  phone varchar(15) NOT NULL default '',
852
+  email_address varchar(50) NOT NULL default '',
853
+  datetime_created datetime NOT NULL default '0000-00-00 00:00:00',
854
+  datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
855
+  confirmation varchar(64) NOT NULL default '',
856
+  flag char(1) NOT NULL default 'o',
857
+  sendnotification varchar(50) NOT NULL default '',
858
+  greeting varchar(50) NOT NULL default '',
859
+  ha1 varchar(128) NOT NULL default '',
860
+  ha1b varchar(128) NOT NULL default '',
861
+  allow_find char(1) NOT NULL default '0',
862
+  timezone varchar(128) default NULL,
863
+  rpid varchar(128) default NULL,
864
+  domn int(10) default NULL,
865
+  uuid varchar(64) default NULL,
866
+  PRIMARY KEY ($USERCOL, domain),
867
+  KEY user_2 ($USERCOL),
868
+  UNIQUE KEY phplib_id (phplib_id)
869
+) $TABLE_TYPE;
870
+
871
+
872
+#
873
+# Table structure for table 'phonebook' -- user's phonebook
874
+#
875
+CREATE TABLE phonebook (
876
+  id int(10) unsigned NOT NULL auto_increment,
877
+  $USERCOL varchar(64) NOT NULL default '',
878
+  domain varchar(128) NOT NULL default '',
879
+  fname varchar(32) NOT NULL default '',
880
+  lname varchar(32) NOT NULL default '',
881
+  sip_uri varchar(128) NOT NULL default '',
882
+  PRIMARY KEY  (id)
883
+) $TABLE_TYPE;
884
+
885
+
886
+#
887
+# Table structure for table 'server_monitoring'
888
+#
889
+CREATE TABLE server_monitoring (
890
+  time datetime NOT NULL default '0000-00-00 00:00:00',
891
+  id int(10) unsigned NOT NULL default '0',
892
+  param varchar(32) NOT NULL default '',
893
+  value int(10) NOT NULL default '0',
894
+  increment int(10) NOT NULL default '0',
895
+  PRIMARY KEY  (id,param)
896
+) $TABLE_TYPE;
897
+
898
+
899
+#
900
+# Table structure for table 'usr_preferences_type'
901
+#
902
+CREATE TABLE usr_preferences_types (
903
+  att_name varchar(32) NOT NULL default '',
904
+  att_rich_type varchar(32) NOT NULL default 'string',
905
+  att_raw_type int NOT NULL default '2',
906
+  att_type_spec text,
907
+  default_value varchar(100) NOT NULL default '',
908
+  PRIMARY KEY  (att_name)
909
+) $TABLE_TYPE;
910
+
911
+
912
+#
913
+# Table structure for table 'server_monitoring_agg'
914
+#
915
+CREATE TABLE server_monitoring_agg (
916
+  param varchar(32) NOT NULL default '',
917
+  s_value int(10) NOT NULL default '0',
918
+  s_increment int(10) NOT NULL default '0',
919
+  last_aggregated_increment int(10) NOT NULL default '0',
920
+  av float NOT NULL default '0',
921
+  mv int(10) NOT NULL default '0',
922
+  ad float NOT NULL default '0',
923
+  lv int(10) NOT NULL default '0',
924
+  min_val int(10) NOT NULL default '0',
925
+  max_val int(10) NOT NULL default '0',
926
+  min_inc int(10) NOT NULL default '0',
927
+  max_inc int(10) NOT NULL default '0',
928
+  lastupdate datetime NOT NULL default '0000-00-00 00:00:00',
929
+  PRIMARY KEY  (param)
930
+) $TABLE_TYPE;
931
+
932
+
933
+#
934
+# Table structure for table 'admin_privileges' 
935
+# for multidomain serweb ACL control
936
+#
937
+CREATE TABLE admin_privileges (
938
+  $USERCOL varchar(64) NOT NULL default '',
939
+  domain varchar(128) NOT NULL default '',
940
+  priv_name varchar(64) NOT NULL default '',
941
+  priv_value varchar(64) NOT NULL default '',
942
+  PRIMARY KEY  ($USERCOL,priv_name,priv_value,domain)
943
+) $TABLE_TYPE;
944
+$INITIAL_INSERT
786 945
 EOF
787 946
 
788
-} # ser_create
947
+}  # end serweb_create
948
+
789 949
 
790 950
 
791 951
 export PW
... ...
@@ -793,30 +788,29 @@ if [ "$#" -ne 0 ] && [ "$PW" = "" ]; then
793 793
 	prompt_pw
794 794
 fi
795 795
 
796
+
796 797
 case $1 in
797 798
 	reinstall)
798
-
799 799
 		#1 create a backup database (named *_bak)
800 800
 		echo "creating backup database"
801
-		ser_backup $DBNAME
801
+		openser_backup $DBNAME
802 802
 		if [ "$?" -ne 0 ] ; then
803
-			echo "reinstall: ser_backup failed"
803
+			echo "reinstall: creating backup db failed"
804 804
 			exit 1
805 805
 		fi
806 806
 		#2 dump original database and change names in it
807 807
 		echo "dumping table content ($DBNAME)"
808
-		tmp_file=/tmp/ser_mysql.$$
809
-		ser_dump $DBNAME  > $tmp_file
808
+		tmp_file=/tmp/openser_mysql.$$
809
+		openser_dump "$DBNAME --ignore-table=$DBNAME.version" > $tmp_file
810 810
 		if [ "$?" -ne 0 ] ; then
811 811
 			echo "reinstall: dumping original db failed"
812 812
 			exit 1
813 813
 		fi
814
-		sed "s/[uU][sS][eE][rR]_[iI][dD]/user/g" $tmp_file |
815
-			sed "s/[uU][sS][eE][rR]\($\|[^a-zA-Z]\)/$USERCOL\1/g" |
816
-			sed "s/[rR][eE][aA][lL][mM]/domain/g"> ${tmp_file}.2
814
+		sed "s/[sS][rR][cC]\($\|[^_]\)/src_leg\1/g" $tmp_file |
815
+			sed "s/[dD][sS][tT]\($\|[^_]\)/dst_leg\1/g"> ${tmp_file}.2
817 816
 		#3 drop original database
818 817
 		echo "dropping table ($DBNAME)"
819
-		ser_drop $DBNAME
818
+		openser_drop $DBNAME
820 819
 		if [ "$?" -ne 0 ] ; then
821 820
 			echo "reinstall: dropping table failed"
822 821
 			rm $tmp_file*
... ...
@@ -824,7 +818,7 @@ case $1 in
824 824
 		fi
825 825
 		#4 change names in table definition and restore
826 826
 		echo "creating new structures"
827
-		ser_create $DBNAME no_init_user
827
+		openser_create $DBNAME no_init_user
828 828
 		if [ "$?" -ne 0 ] ; then
829 829
 			echo "reinstall: creating new table failed"
830 830
 			rm $tmp_file*
... ...
@@ -832,37 +826,14 @@ case $1 in
832 832
 		fi
833 833
 		#5 restoring table content
834 834
 		echo "restoring table content"
835
-
836
-		# Recreate perms column here so that subsequent
837
-		# restore succeeds
838
-
839
-    sql_query $DBNAME << EOF
840
-    ALTER TABLE subscriber ADD perms VARCHAR(32)  AFTER ha1b;
841
-    ALTER TABLE pending ADD perms VARCHAR(32)  AFTER ha1b;
842
-EOF
843
-
844
-
845
-		ser_restore $DBNAME ${tmp_file}.2
835
+		openser_restore $DBNAME ${tmp_file}.2
846 836
 		if [ "$?" -ne 0 ] ; then
847 837
 			echo "reinstall: restoring table failed"
848 838
 			rm $tmp_file*
849 839
 			exit 1
850 840
 		fi
851
-
852
-
853
-    sql_query $DBNAME << EOF
854
-
855
-    # Move perms from subscriber to admin_privileges
856
-    INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value) SELECT $USERCOL, domain, 'is_admin', '1' FROM subscriber WHERE perms='admin';
857
-
858
-		# Drop perms column here
859
-    ALTER TABLE subscriber DROP perms;
860
-    ALTER TABLE pending DROP perms;
861
-
862
-EOF
863
-
864
-#XX
865
-#		rm $tmp_file*
841
+		# done
842
+		rm -f $tmp_file*
866 843
 		exit 0
867 844
 		;;
868 845
 	copy)
... ...
@@ -872,27 +843,29 @@ EOF
872 872
 			usage
873 873
 			exit 1
874 874
 		fi
875
-		tmp_file=/tmp/ser_mysql.$$
876
-		ser_dump $DBNAME  > $tmp_file
875
+		tmp_file=/tmp/openser_mysql.$$
876
+		openser_dump $DBNAME > $tmp_file
877 877
 		ret=$?
878 878
 		if [ "$ret" -ne 0 ]; then
879
+			echo "copy: dumping original db failed"
879 880
 			rm $tmp_file
880 881
 			exit $ret
881 882
 		fi
882
-		ser_create $1 no_init_user
883
+		openser_create $1 no_init_user
883 884
 		ret=$?
884 885
 		if [ "$ret" -ne 0 ]; then
886
+			echo "copy: creating new db failed"
885 887
 			rm $tmp_file
886 888
 			exit $ret
887 889
 		fi
888
-		ser_restore $1 $tmp_file
890
+		openser_restore $1 $tmp_file
889 891
 		ret=$?
890
-		rm $tmp_file
892
+		rm -f $tmp_file
891 893
 		exit $ret
892 894
 		;;
893 895
 	backup)
894 896
 		# backup current database
895
-		ser_dump $DBNAME
897
+		openser_dump $DBNAME
896 898
 		exit $?
897 899
 		;;
898 900
 	restore)
... ...
@@ -902,7 +875,7 @@ EOF
902 902
 			usage
903 903
 			exit 1
904 904
 		fi
905
-		ser_restore $DBNAME $1
905
+		openser_restore $DBNAME $1
906 906
 		exit $?
907 907
 		;;
908 908
 	create)
... ...
@@ -911,22 +884,26 @@ EOF
911 911
 		if [ $# -eq 1 ] ; then
912 912
 			DBNAME="$1"
913 913
 		fi
914
-		ser_create $DBNAME
914
+		openser_create $DBNAME
915
+		exit $?
916
+		;;
917
+	serweb)
918
+		serweb_create $DBNAME
915 919
 		exit $?
916 920
 		;;
917 921
 	drop)
918
-		# delete ser database
919
-		ser_drop $DBNAME
922
+		# delete openser database
923
+		openser_drop $DBNAME
920 924
 		exit $?
921 925
 		;;
922 926
 	reinit)
923 927
 		# delete database and create a new one
924
-		ser_drop $DBNAME
928
+		openser_drop $DBNAME
925 929
 		ret=$?
926 930
 		if [ "$ret" -ne 0 ]; then
927 931
 			exit $ret
928 932
 		fi
929
-		ser_create $DBNAME
933
+		openser_create $DBNAME
930 934
 		exit $?
931 935
 		;;
932 936
 	*)
... ...
@@ -26,6 +26,8 @@
26 26
 #     indexes are doubled
27 27
 #  -  msilo: blob replaced by text, is this fine?
28 28
 #  -  datetime types not sure
29
+# 2006-04-07  removed gen_ha1 dependency - use md5sum;
30
+#             separated the serweb from openser tables (bogdan)
29 31
 
30 32
 PATH=$PATH:/usr/local/sbin
31 33
 
... ...
@@ -90,10 +92,6 @@ fi
90 90
 if [ -z "$USERCOL" ]; then
91 91
 	USERCOL="username"
92 92
 fi
93
-# path to gen_ha1 tool
94
-if [ -z "$GENHA1" ]; then
95
-	GENHA1='/usr/sbin/openser_gen_ha1'
96
-fi
97 93
 
98 94
 DUMMY_DATE="2000-01-01 00:00:01"
99 95
 FOREVER="2020-05-28 21:32:15"
... ...
@@ -119,7 +117,9 @@ usage: $COMMAND create
119 119
        $COMMAND backup (dumps current database to stdout)
120 120
        $COMMAND restore <file> (restores tables from a file)
121 121
        $COMMAND copy <new_db> (creates a new db from an existing one)
122
-       $COMMAND reinstall (updates to a new SER database)
122
+       $COMMAND reinstall (updates to a new OpenSER database)
123
+       $COMMAND serweb (adds the SERWEB specific tables)
124
+       $COMMAND reinit (drops ans install OpenSER database)
123 125
 
124 126
        if you want to manipulate database as other postgresql user than
125 127
        "postgres", want to change database name from default value "$DBNAME",
... ...
@@ -145,17 +145,14 @@ EOF
145 145
 # execute sql command
146 146
 sql_query()
147 147
 {
148
-	# uncomment next line for psql debugging
149
-	# echo $CMD "$@"
150
-
151 148
 	$CMD "$@"
152 149
 }
153 150
 
154 151
 # dump all rows
155
-ser_dump()  # pars: <database name>
152
+openser_dump()  # pars: <database name>
156 153
 {
157 154
 	if [ $# -ne 1 ] ; then
158
-		echo "ser_dump function takes one param"
155
+		echo "openser_dump function takes one param"
159 156
 		exit 1
160 157
 	fi
161 158
 	$DUMP_CMD "-p$PW" $1
... ...
@@ -163,10 +160,10 @@ ser_dump()  # pars: <database name>
163 163
 
164 164
 
165 165
 # copy a database to database_bak
166
-ser_backup() # par: <database name>
166
+openser_backup() # par: <database name>
167 167
 {
168 168
 	if [ $# -ne 1 ] ; then
169
-		echo  "ser_backup function takes one param"
169
+		echo  "openser_backup function takes one param"
170 170
 		exit 1
171 171
 	fi
172 172
 	BU=/tmp/mysql_bup.$$
... ...
@@ -179,7 +176,7 @@ ser_backup() # par: <database name>
179 179
 	create database $1_bak;
180 180
 EOF
181 181
 
182
-	ser_restore $1_bak $BU
182
+	openser_restore $1_bak $BU
183 183
 	if [ "$?" -ne 0 ]; then
184 184
 		echo "ser backup/restore failed"
185 185
 		rm $BU
... ...
@@ -187,19 +184,20 @@ EOF
187 187
 	fi
188 188
 }
189 189
 
190
-ser_restore() #pars: <database name> <filename>
190
+openser_restore() #pars: <database name> <filename>
191 191
 {
192 192
 if [ $# -ne 2 ] ; then
193
-	echo "ser_restore function takes two params"
193
+	echo "openser_restore function takes two params"
194 194
 	exit 1
195 195
 fi
196 196
 sql_query $1 < $2
197 197
 }
198 198
 
199
-ser_drop()  # pars: <database name>
199
+
200
+openser_drop()  # pars: <database name>
200 201
 {
201 202
 	if [ $# -ne 1 ] ; then
202
-		echo "ser_drop function takes two params"
203
+		echo "openser_drop function takes two params"
203 204
 		exit 1
204 205
 	fi
205 206
 
... ...
@@ -211,7 +209,7 @@ ser_drop()  # pars: <database name>
211 211
 	drop database $1;
212 212
 	$DROP_USER
213 213
 EOF
214
-} #ser_drop
214
+} #openser_drop
215 215
 
216 216
 # read realm
217 217
 prompt_realm()
... ...
@@ -224,27 +222,28 @@ prompt_realm()
224 224
 # calculate credentials for admin
225 225
 credentials()
226 226
 {
227
-	HA1=`$GENHA1 admin $SIP_DOMAIN $DEFAULT_PW`
227
+	HA1=`echo -n "admin:$SIP_DOMAIN:$DEFAULT_PW" | md5sum | awk '{ print $1 }'`
228 228
 	if [ $? -ne 0 ] ; then
229 229
 		echo "HA1 calculation failed"
230 230
 		exit 1
231 231
 	fi
232
-	HA1B=`$GENHA1 "admin@$SIP_DOMAIN" $SIP_DOMAIN $DEFAULT_PW`
232
+	HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DEFAULT_PW" | md5sum | awk '{ print $1 }'`
233 233
 	if [ $? -ne 0 ] ; then
234 234
 		echo "HA1B calculation failed"
235 235
 		exit 1
236 236
 	fi
237 237
 
238
-  #PHPLIB_ID of users should be difficulty to guess for security reasons
239
-  NOW=`date`;
240
-  PHPLIB_ID=`$GENHA1 "$RANDOM" "$NOW" $SIP_DOMAIN`
238
+	#PHPLIB_ID of users should be difficulty to guess for security reasons
239
+	NOW=`date`;
240
+	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | md5sum | awk '{ print $1 }'`
241
+	PHPLIB_ID=`$GENHA1 "$RANDOM" "$NOW" $SIP_DOMAIN`
241 242
 	if [ $? -ne 0 ] ; then
242
-    echo "PHPLIB_ID calculation failed"
243
+		echo "PHPLIB_ID calculation failed"
243 244
 		exit 1
244 245
 	fi
245 246
 }
246 247
 
247
-ser_create () # pars: <database name> [<no_init_user>]
248
+openser_create () # pars: <database name> [<no_init_user>]
248 249
 {
249 250
 if [ $# -eq 1 ] ; then
250 251
 	if [ -z "$SIP_DOMAIN" ] ; then
... ...
@@ -255,23 +254,23 @@ if [ $# -eq 1 ] ; then
255 255
 	INITIAL_USER="INSERT INTO subscriber
256 256
 		($USERCOL, password, first_name, last_name, phone,
257 257
 		email_address, datetime_created, datetime_modified, confirmation,
258
-    flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
258
+		flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
259 259
 		VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
260 260
 		'root@localhost', '2002-09-04 19:37:45', '$DUMMY_DATE',
261 261
 		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
262 262
 		'$HA1', '$SIP_DOMAIN', '$HA1B',
263
-    '$PHPLIB_ID' );
263
+		'$PHPLIB_ID' );
264 264
 
265
-    INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
266
-    VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
265
+		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
266
+		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
267 267
 
268
-    INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
269
-    VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
268
+		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
269
+		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
270 270
 elif [ $# -eq 2 ] ; then
271 271
 	# if 3rd param set, don't create any initial user
272 272
 	INITIAL_USER=""
273 273
 else
274
-	echo "ser_create function takes one or two params"
274
+	echo "openser_create function takes one or two params"
275 275
 	exit 1
276 276
 fi
277 277
 
... ...
@@ -314,45 +313,61 @@ CREATE TABLE version (
314 314
  * Dumping data for table 'version'
315 315
  */
316 316
 
317
-INSERT INTO version VALUES ( 'acc', '2');
318
-INSERT INTO version VALUES ( 'active_sessions', '1');
319
-INSERT INTO version VALUES ( 'admin_privileges', '1');
317
+INSERT INTO version VALUES ( 'subscriber', '5');
318
+INSERT INTO version VALUES ( 'missed_calls', '2');
319
+INSERT INTO version VALUES ( 'location', '1003');
320 320
 INSERT INTO version VALUES ( 'aliases', '1003');
321
-INSERT INTO version VALUES ( 'calls_forwarding', '1');
322
-INSERT INTO version VALUES ( 'config', '1');
323
-INSERT INTO version VALUES ( 'dbaliases', '1');
324
-INSERT INTO version VALUES ( 'domain', '1');
325
-INSERT INTO version VALUES ( 'event', '1');
326 321
 INSERT INTO version VALUES ( 'grp', '2');
327 322
 INSERT INTO version VALUES ( 're_grp', '1');
328
-INSERT INTO version VALUES ( 'gw', '3');
329
-INSERT INTO version VALUES ( 'gw_grp', '1');
330
-INSERT INTO version VALUES ( 'lcr', '2');
331
-INSERT INTO version VALUES ( 'location', '1003');
332
-INSERT INTO version VALUES ( 'missed_calls', '2');
333
-INSERT INTO version VALUES ( 'pending', '4');
334
-INSERT INTO version VALUES ( 'phonebook', '1');
335
-INSERT INTO version VALUES ( 'realm', '1');
336
-INSERT INTO version VALUES ( 'reserved', '1');
337
-INSERT INTO version VALUES ( 'server_monitoring', '1');
338
-INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
323
+INSERT INTO version VALUES ( 'acc', '2');
339 324
 INSERT INTO version VALUES ( 'silo', '4');
340
-INSERT INTO version VALUES ( 'speed_dial', '2');
341
-INSERT INTO version VALUES ( 'subscriber', '5');
342
-INSERT INTO version VALUES ( 'trusted', '3');
325
+INSERT INTO version VALUES ( 'domain', '1');
343 326
 INSERT INTO version VALUES ( 'uri', '1');
327
+INSERT INTO version VALUES ( 'trusted', '3');
344 328
 INSERT INTO version VALUES ( 'usr_preferences', '2');
345
-INSERT INTO version VALUES ( 'usr_preferences_types', '1');
329
+INSERT INTO version VALUES ( 'speed_dial', '2');
330
+INSERT INTO version VALUES ( 'dbaliases', '1');
331
+INSERT INTO version VALUES ( 'gw', '3');
332
+INSERT INTO version VALUES ( 'gw_grp', '1');
333
+INSERT INTO version VALUES ( 'lcr', '2');
346 334
 INSERT INTO version VALUES ( 'sip_trace', '1');
347 335
 
348 336
 
349 337
 /*
350
- * Table structure for table 'acc' -- accounted calls
338
+ * Table structure for table 'subscriber' -- user database
351 339
  */
340
+CREATE TABLE subscriber (
341
+  phplib_id varchar(32) NOT NULL default '',
342
+  $USERCOL varchar(64) NOT NULL default '',
343
+  domain varchar(128) NOT NULL default '',
344
+  password varchar(25) NOT NULL default '',
345
+  first_name varchar(25) NOT NULL default '',
346
+  last_name varchar(45) NOT NULL default '',
347
+  phone varchar(15) NOT NULL default '',
348
+  email_address varchar(50) NOT NULL default '',
349
+  datetime_created $DATETIME,
350
+  datetime_modified $DATETIME,
351
+  confirmation varchar(64) NOT NULL default '',
352
+  flag char(1) NOT NULL default 'o',
353
+  sendnotification varchar(50) NOT NULL default '',
354
+  greeting varchar(50) NOT NULL default '',
355
+  ha1 varchar(128) NOT NULL default '',
356
+  ha1b varchar(128) NOT NULL default '',
357
+  allow_find char(1) NOT NULL default '0',
358
+  timezone varchar(128) default NULL,
359
+  rpid varchar(128) default NULL,
360
+  domn int default NULL,
361
+  uuid varchar(64) default NULL,
362
+  UNIQUE (phplib_id),
363
+  PRIMARY KEY ($USERCOL, domain)
364
+) $TABLE_TYPE;
365
+CREATE INDEX user_2_subs_indx ON subscriber ($USERCOL);
352 366
 
367
+
368
+/*
369
+ * Table structure for table 'acc' -- accounted calls
370
+ */
353 371
 CREATE TABLE acc (
354
-  caller_UUID varchar(64) NOT NULL default '',
355
-  callee_UUID varchar(64) NOT NULL default '',
356 372
   sip_from varchar(128) NOT NULL default '',
357 373
   sip_to varchar(128) NOT NULL default '',
358 374
   sip_status varchar(128) NOT NULL default '',
... ...
@@ -368,41 +383,58 @@ CREATE TABLE acc (
368 368
   totag varchar(128) NOT NULL default '',
369 369
   time $DATETIME,
370 370
   timestamp $TIMESTAMP,
371
-  caller_deleted char(1) NOT NULL default '0',
372
-  callee_deleted char(1) NOT NULL default '0',
373 371
   src_leg varchar(128) default NULL,
374 372
   dst_leg varchar(128) default NULL
375 373
 ) $TABLE_TYPE;
376
-
377 374
 CREATE INDEX acc_user_indx ON acc ($USERCOL, domain);
378 375
 CREATE INDEX sip_callid_indx ON acc (sip_callid);
379 376
 
380 377
 
381
-/*
382
- * Table structure for table 'active_sessions' -- web stuff
383
- */
384
-
385
-CREATE TABLE active_sessions (
386
-  sid varchar(32) NOT NULL default '',
387
-  name varchar(32) NOT NULL default '',
388
-  val text,
389
-  changed varchar(14) NOT NULL default '',
390
-  PRIMARY KEY  (name,sid)
378
+/* 
379
+ * Table structure for table 'missed_calls' -- acc-like table
380
+ * for keeping track of missed calls
381
+ */ 
382
+CREATE TABLE missed_calls (
383
+  sip_from varchar(128) NOT NULL default '',
384
+  sip_to varchar(128) NOT NULL default '',
385
+  sip_status varchar(128) NOT NULL default '',
386
+  sip_method varchar(16) NOT NULL default '',
387
+  i_uri varchar(128) NOT NULL default '',
388
+  o_uri varchar(128) NOT NULL default '',
389
+  from_uri varchar(128) NOT NULL default '',
390
+  to_uri varchar(128) NOT NULL default '',
391
+  sip_callid varchar(128) NOT NULL default '',
392
+  $USERCOL varchar(64) NOT NULL default '',
393
+  domain varchar(128) NOT NULL default '',
394
+  fromtag varchar(128) NOT NULL default '',
395
+  totag varchar(128) NOT NULL default '',
396
+  time $DATETIME,
397
+  timestamp $TIMESTAMP,
398
+  src_leg varchar(128) default NULL,
399
+  dst_leg varchar(128) default NULL
391 400
 ) $TABLE_TYPE;
392
-
393
-CREATE INDEX changed_indx ON active_sessions (changed);
401
+CREATE INDEX mc_user_indx ON missed_calls ($USERCOL, domain);
394 402
 
395 403
 
396 404
 /*
397
- * Table structure for table 'admin_privileges' -- multidomain serweb ACL control
405
+ * Table structure for table 'location' -- that is persistent UsrLoc
398 406
  */
399
-
400
-CREATE TABLE admin_privileges (
407
+CREATE TABLE location (
401 408
   $USERCOL varchar(64) NOT NULL default '',
402 409
   domain varchar(128) NOT NULL default '',
403
-  priv_name varchar(64) NOT NULL default '',
404
-  priv_value varchar(64) NOT NULL default '',
405
-  PRIMARY KEY  ($USERCOL,priv_name,priv_value,domain)
410
+  contact varchar(255) NOT NULL default '',
411
+  received varchar(255) default NULL,
412
+  path varchar(255) default NULL,
413
+  expires $DATETIMELOCATION,
414
+  q $FLOAT NOT NULL default '$DEFAULT_Q',
415
+  callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
416
+  cseq int NOT NULL default '$DEFAULT_CSEQ',
417
+  last_modified $TIMESTAMP,
418
+  flags int NOT NULL default '0',
419
+  user_agent varchar(255) NOT NULL default '',
420
+  socket varchar(128) default NULL,
421
+  methods int default NULL,
422
+  PRIMARY KEY($USERCOL, domain, contact)
406 423
 ) $TABLE_TYPE;
407 424
 
408 425
 
... ...
@@ -410,7 +442,6 @@ CREATE TABLE admin_privileges (
410 410
  * Table structure for table 'aliases' -- location-like table
411 411
  * (aliases_contact index makes lookup of missed calls much faster)
412 412
  */
413
-
414 413
 CREATE TABLE aliases (
415 414
   $USERCOL varchar(64) NOT NULL default '',
416 415
   domain varchar(128) NOT NULL default '',
... ...
@@ -428,14 +459,12 @@ CREATE TABLE aliases (
428 428
   methods int default NULL,
429 429
   PRIMARY KEY($USERCOL, domain, contact)
430 430
 ) $TABLE_TYPE;
431
-
432 431
 CREATE INDEX aliases_contact_indx ON aliases (contact);
433 432
 
434 433
 
435 434
 /*
436 435
  * DB aliases
437 436
  */
438
-
439 437
 CREATE TABLE dbaliases (
440 438
   alias_username varchar(64) NOT NULL default '',
441 439
   alias_domain varchar(128) NOT NULL default '',
... ...
@@ -443,26 +472,13 @@ CREATE TABLE dbaliases (
443 443
   domain varchar(128) NOT NULL default '',
444 444
   UNIQUE (alias_username,alias_domain)
445 445
 ) $TABLE_TYPE;
446
-
447 446
 CREATE INDEX alias_user_indx ON dbaliases ($USERCOL, domain);
448
-		  
449
-
450
-/*
451
- * Table structure for table 'domain' -- domains proxy is responsible for
452
- */
453
-
454
-CREATE TABLE domain (
455
-  domain varchar(128) NOT NULL default '',
456
-  last_modified $DATETIME,
457
-  PRIMARY KEY  (domain)
458
-) $TABLE_TYPE;
459 447
 
460 448
 
461 449
 /*
462 450
  * Table structure for table 'grp' -- group membership
463 451
  * table; used primarily for ACLs
464 452
  */
465
-
466 453
 CREATE TABLE grp (
467 454
   $USERCOL varchar(64) NOT NULL default '',
468 455
   domain varchar(128) NOT NULL default '',
... ...
@@ -476,7 +492,6 @@ CREATE TABLE grp (
476 476
  * Table structure for table 're_grp' -- group membership
477 477
  * based on regular expressions
478 478
  */
479
-
480 479
 CREATE TABLE re_grp (
481 480
   reg_exp varchar(128) NOT NULL default '',
482 481
   group_id int NOT NULL default '0',
... ...
@@ -485,9 +500,94 @@ CREATE TABLE re_grp (
485 485
 
486 486
 
487 487
 /*
488
- * Table structure for table 'gw' (lcr module)
488
+ * "instant" message silo
489
+ */
490
+CREATE TABLE silo(
491
+    mid $AUTO_INCREMENT,
492
+    src_addr VARCHAR(255) NOT NULL DEFAULT '',
493
+    dst_addr VARCHAR(255) NOT NULL DEFAULT '',
494
+    r_uri VARCHAR(255) NOT NULL DEFAULT '',
495
+    $USERCOL VARCHAR(64) NOT NULL DEFAULT '',
496
+    domain VARCHAR(128) NOT NULL DEFAULT '',
497
+    inc_time INTEGER NOT NULL DEFAULT 0,
498
+    exp_time INTEGER NOT NULL DEFAULT 0,
499
+    snd_time INTEGER NOT NULL DEFAULT 0,
500
+    ctype VARCHAR(32) NOT NULL DEFAULT 'text/plain',
501
+    body TEXT NOT NULL DEFAULT ''
502
+) $TABLE_TYPE;
503
+
504
+
505
+/*
506
+ * Table structure for table 'domain' -- domains proxy is responsible for
507
+ */
508
+CREATE TABLE domain (
509
+  domain varchar(128) NOT NULL default '',
510
+  last_modified $DATETIME,
511
+  PRIMARY KEY  (domain)
512
+) $TABLE_TYPE;
513
+
514
+
515
+/*
516
+ * Table structure for table 'uri' -- uri user parts users are allowed to use