Browse code

stable changes projected to developer's

Jiri Kuthan authored on 13/08/2003 20:53:04
Showing 4 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,58 @@
0
+#!/bin/sh
1
+#
2
+# $Id$
3
+#
4
+# tool for filtering SIP messages from log by a RegExp
5
+#
6
+# Example of use: ./filter_msg.sh /var/log/sip/sip.1056844800 'CallId: abc'
7
+#
8
+
9
+
10
+#####################
11
+
12
+usage()
13
+{
14
+	echo "Usage: $0 <filename> <RegExp>"
15
+}
16
+
17
+if [ "$#" -ne 2 ] ; then
18
+	usage
19
+	exit
20
+fi
21
+
22
+AWK_PG='
23
+BEGIN {
24
+	IGNORECASE=1;
25
+	line=0;
26
+	msg_match=0;
27
+}
28
+
29
+/^#$/ {
30
+	line=0
31
+	msg_match=0
32
+	next
33
+}
34
+
35
+msg_match==1 {
36
+	print
37
+	next
38
+}
39
+
40
+{ 
41
+	if (match($0, RE)) {
42
+		msg_match=1;
43
+		# dump all accumulated lines here
44
+		for (i=1; i<=line; i++) print buffer[i];
45
+		print
46
+		next
47
+	}
48
+	# there are still chances for a match in following lines;
49
+	# keep buffering this request
50
+	line++
51
+	buffer[line]=$0
52
+}
53
+
54
+'
55
+
56
+
57
+cat $1 | awk "$AWK_PG" RE="$2"
... ...
@@ -24,7 +24,7 @@
24 24
 #
25 25
 
26 26
 
27
-LOGDIR=/var/log
27
+LOGDIR=/var/log/sip
28 28
 
29 29
 #####################
30 30
 
... ...
@@ -48,7 +48,7 @@ BEGIN {
48 48
     rpl300=0; rpl302=0; rpl3xx=0;
49 49
     rpl400=0; rpl401=0; rpl403=0; rpl404=0; rpl405=0;
50 50
         rpl406=0;rpl407=0;rpl408=0;rpl410=0; rpl415=0;
51
-        rpl476=0;rpl480=0;rpl481=0;rpl483=0;rpl486=0;rpl478=0;rpl487=0;
51
+        rpl476=0;rpl477=0;rpl480=0;rpl481=0;rpl482=0;rpl483=0;rpl486=0;rpl478=0;rpl487=0;
52 52
 		rpl488=0;rpl489=0;
53 53
         rpl4xx=0;
54 54
 	rpl479=0;
... ...
@@ -117,6 +117,16 @@ BEGIN {
117 117
 	ua_gphone=0;
118 118
 	ua_xlite=0;
119 119
 	ua_edial=0;
120
+	ua_gs=0;
121
+	ua_sipps=0;
122
+	ua_i3micro=0;
123
+	ua_act=0;
124
+	ua_ibm=0;
125
+	ua_xpro=0;
126
+	ua_hearme=0;
127
+	ua_draytek=0;
128
+	ua_st280;
129
+	ua_dta=0;
120 130
 	ua_xx=0;
121 131
 
122 132
 	server_cisco=0
... ...
@@ -137,6 +147,10 @@ BEGIN {
137 137
 	server_starsip=0;
138 138
 	server_ipdialog=0;
139 139
 	server_edial=0;
140
+	server_ma=0;
141
+	server_fwd=0;
142
+	server_columbia=0;
143
+	server_partysip=0;
140 144
 	server_xx=0
141 145
 
142 146
 }
... ...
@@ -331,10 +345,54 @@ ua==0 && /User-Agent:.*eDial/ {
331 331
 	ua_edial++
332 332
 	ua=1
333 333
 }
334
+ua==0 && /User-Agent:.*Grandstream/ {
335
+	ua_gs++
336
+	ua=1
337
+}
338
+ua==0 && /User-Agent:.*Ahead SIPPS/ {
339
+	ua_sipps++
340
+	ua=1
341
+}
342
+ua==0 && /User-Agent:.*IBM user agent/ {
343
+	ua_ibm++
344
+	ua=1
345
+}
346
+ua==0 && /User-Agent:.*Vega/ {
347
+	ua_vega++
348
+	ua=1
349
+}
350
+ua==0 && /User-Agent:.*i3micro/ {
351
+	ua_i3micro++
352
+	ua=1
353
+}
354
+ua==0 && /User-Agent:.*ACT/ {
355
+	ua_act++
356
+	ua=1
357
+}
358
+ua==0 && /User-Agent:.*X-Pro/ {
359
+	ua_xpro++
360
+	ua=1
361
+}
362
+ua==0 && /User-Agent:.*HearMe/ {
363
+	ua_hearme++
364
+	ua=1
365
+}
366
+ua==0 && /User-Agent:.*DrayTek/ {
367
+	ua_draytek++
368
+	ua=1
369
+}
334 370
 ua==0 && /User-Agent:.*X-Lite/ {
335 371
 	ua_xlite++
336 372
 	ua=1
337 373
 }
374
+ua==0 && /User-Agent:.*DTA/ {
375
+	ua_dta++
376
+	ua=1
377
+}
378
+ua==0 && /User-Agent:.*ST280/ {
379
+	ua_st++
380
+	ua=1
381
+}
338 382
 
339 383
 
340 384
  { comment="hack to deal with old version of ngrep (breaking in columns)"
... ...
@@ -425,6 +483,23 @@ server==0 && /Server:.*eDial/ {
425 425
 	server_edial++
426 426
 	server=1
427 427
 }
428
+server==0 && /Server:.*MA/ {
429
+	server_ma++
430
+	server=1
431
+}
432
+server==0 && /Server:.*Free World/ {
433
+	server_fwd++
434
+	server=1
435
+}
436
+server==0 && /Server:.*SIPUA-Columbia-University/ {
437
+	server_columbia++
438
+	server=1
439
+}
440
+server==0 && /Server:.*partysip/ {
441
+	server_partysip++
442
+	server=1
443
+}
444
+
428 445
 server==0 && /Server:/ {
429 446
 	server_xx++
430 447
 	print
... ...
@@ -568,6 +643,10 @@ reply==0 && request=0 {
568 568
     rpl476++
569 569
     next
570 570
 }
571
+/SIP\/2\.0 477/ {
572
+    rpl477++
573
+    next
574
+}
571 575
 /SIP\/2\.0 480/ {
572 576
     rpl480++
573 577
     next
... ...
@@ -576,6 +655,10 @@ reply==0 && request=0 {
576 576
     rpl481++
577 577
     next
578 578
 }
579
+/SIP\/2\.0 482/ {
580
+    rpl482++
581
+    next
582
+}
579 583
 /SIP\/2\.0 483/ {
580 584
     rpl483++
581 585
     next
... ...
@@ -704,10 +787,12 @@ END {
704 704
 	print "410 (Gone): " rpl410
705 705
 	print "415 (Unsupported Media): " rpl415
706 706
 	print "476 (no recursive registrations): " rpl476 
707
+	print "477 (next hop error): " rpl477
707 708
 	print "478 (Unresolveable): " rpl478 
708 709
 	print "479 (private IP): " rpl479 
709 710
 	print "480 (Unavailable): " rpl480 
710 711
 	print "481 (Call/Transaction does not exist): " rpl481 
712
+	print "482 (Loop Detected): " rpl482 
711 713
 	print "483 (Too Many Hops): " rpl483 
712 714
 	print "486 (Busy Here): " rpl486 
713 715
 	print "487 (Request Terminated): " rpl487
... ...
@@ -723,29 +808,59 @@ END {
723 723
 	print "6xx: " rpl6xx
724 724
 
725 725
 	print "## Request Methods"
726
-    print "INVITE: " invite " CANCEL: " cancel " ACK: " ack
727
-    print "REGISTER: " register " BYE: " bye " OPTIONS: " options " INFO: " info
728
-    print "MESSAGE: " message " SUBSCRIBE: " subscribe " NOTIFY: " notify
726
+    print "INVITE: " invite 
727
+	print "CANCEL: " cancel 
728
+	print "ACK: " ack
729
+    print "REGISTER: " register 
730
+	print "BYE: " bye 
731
+	print "OPTIONS: " options 
732
+	print "INFO: " info
733
+    print "MESSAGE: " message 
734
+	print "SUBSCRIBE: " subscribe 
735
+	print "NOTIFY: " notify
729 736
 
730 737
 	print "## Outbound Routes"
731
-	print "To imgw: " hint_imgw " To voicemail: " hint_voicemail
732
-	print "To bat: " hint_battest " To UsrLoc: " hint_usrloc
733
-	print "Outbound: " hint_outbound " To SMS: " hint_sms
734
-	print "To PSTN: " hint_gw " To: VM on off-line" hint_off_voicemail
738
+	print "To imgw: " hint_imgw 
739
+	print "To voicemail: " hint_voicemail
740
+	print "To bat: " hint_battest 
741
+	print "To UsrLoc: " hint_usrloc
742
+	print "Outbound: " hint_outbound
743
+	print "To SMS: " hint_sms
744
+	print "To PSTN: " hint_gw 
745
+	print "To: VM on off-line" hint_off_voicemail
735 746
 
736 747
 	print "## User Agents"
737
-	print "Snom: " ua_snom " MSN: " ua_msn " Mitel: " ua_mitel
738
-	print "Pingtel: " ua_pingtel " SER: " ua_ser " osip: " ua_osip
739
-	print "linphone: " ua_linphone " ubiquity: " ua_ubiquity
740
-	print "3com: " ua_3com " IPDialog: " ua_ipdialog " Epygi: " ua_epygi
741
-	print "Jasomi: " ua_jasomi " Cisco: " ua_cisco " insipid: " ua_insipid
742
-	print "Hotsip: " ua_hotsip " mxsf: " ua_mxsf " GrandStream: " ua_grandstream
743
-	print "Tellme: " ua_tellme " PocketSipM: " ua_pocketsipm 
744
-	print "eStara: " ua_estara " Vovida: " ua_vovida 
745
-	print "jSIP: " ua_jsip " Nortel: " ua_nortel " Polycom: " ua_polycom
746
-	print "Leader: " ua_leader " csco: " ua_csco " Nebula: " ua_nebula
747
-	print "MagicPPC: " ua_magicppc " SCS: " ua_scs 
748
-	print "SJPhone: " ua_sjphone " KPhone: " ua_kphone
748
+	print "Snom: " ua_snom 
749
+	print "MSN: " ua_msn 
750
+	print "Mitel: " ua_mitel
751
+	print "Pingtel: " ua_pingtel 
752
+	print "SER: " ua_ser 
753
+	print "osip: " ua_osip
754
+	print "linphone: " ua_linphone 
755
+	print "ubiquity: " ua_ubiquity
756
+	print "3com: " ua_3com 
757
+	print "IPDialog: " ua_ipdialog 
758
+	print "Epygi: " ua_epygi
759
+	print "Jasomi: " ua_jasomi 
760
+	print "Cisco: " ua_cisco 
761
+	print "insipid: " ua_insipid
762
+	print "Hotsip: " ua_hotsip 
763
+	print "mxsf: " ua_mxsf 
764
+	print "GrandStream: " ua_grandstream
765
+	print "Tellme: "ua_tellme 
766
+	print "PocketSipM: " ua_pocketsipm 
767
+	print "eStara: " ua_estara 
768
+	print "Vovida: " ua_vovida 
769
+	print "jSIP: " ua_jsip 
770
+	print "Nortel: " ua_nortel 
771
+	print "Polycom: " ua_polycom
772
+	print "Leader: " ua_leader 
773
+	print "csco: " ua_csco 
774
+	print "Nebula: " ua_nebula
775
+	print "MagicPPC: " ua_magicppc 
776
+	print "SCS: " ua_scs 
777
+	print "SJPhone: " ua_sjphone 
778
+	print "KPhone: " ua_kphone
749 779
 	print "Yamaha: " ua_yamaha 
750 780
 	print "tkcPhone: " ua_tkc
751 781
 	print "EdgeAccess: " ua_edgeaccess
... ...
@@ -762,6 +877,17 @@ END {
762 762
 	print "D-link: " ua_dlink
763 763
 	print "gphone: " ua_gphone
764 764
 	print "X-lite: " ua_xlite
765
+	print "grandstream: " ua_gs
766
+	print "vegastream: " ua_vega
767
+	print "Ahead SIPPS: " ua_sipps
768
+	print "IBM user agent: " ua_ibm
769
+	print "i3micro: " ua_i3micro
770
+	print "ACT: " ua_act
771
+	print "X-pro: " ua_xpro
772
+	print "Hearme: " ua_hearme
773
+	print "DrayTek: " ua_draytek
774
+	print "ST: " ua_st
775
+	print "DTA: " ua_dta
765 776
 	print "UFO: " ua_xx
766 777
 
767 778
 	print "## Servers"
... ...
@@ -778,6 +904,10 @@ END {
778 778
 	print "StarSIP: " server_starsip
779 779
 	print "ipDialog: " server_ipdialog
780 780
 	print "eDial: " server_edial
781
+	print "FWD: " server_fwd
782
+	print "MA: " server_ma
783
+	print "Columbia: " server_columbia
784
+	print "PartySip: " server_partysip
781 785
 	print "UFO: " server_xx
782 786
 }
783 787
 '
... ...
@@ -140,7 +140,7 @@ EOF
140 140
 # read realm
141 141
 prompt_realm() 
142 142
 {
143
-	printf "Doamin (realm) for the default user 'admin': "
143
+	printf "Domain (realm) for the default user 'admin': "
144 144
 	read SIP_DOMAIN
145 145
 	echo
146 146
 }
... ...
@@ -229,7 +229,7 @@ INSERT INTO version VALUES ( 'realm', '1');
229 229
 INSERT INTO version VALUES ( 'domain', '1');
230 230
 INSERT INTO version VALUES ( 'uri', '1');
231 231
 INSERT INTO version VALUES ( 'server_monitoring', '1');
232
-INSERT INTO version VALUES ( 'server_monitoring_ul', '1');
232
+INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
233 233
 
234 234
 
235 235
 #
... ...
@@ -248,6 +248,7 @@ CREATE TABLE acc (
248 248
   to_uri varchar(128) NOT NULL default '',
249 249
   sip_callid varchar(128) NOT NULL default '',
250 250
   $USERCOL varchar(64) NOT NULL default '',
251
+  domain varchar(100) NOT NULL default '',
251 252
   fromtag varchar(128) NOT NULL default '',
252 253
   totag varchar(128) NOT NULL default '',
253 254
   time datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -301,6 +302,7 @@ CREATE TABLE aliases (
301 301
 CREATE TABLE event (
302 302
   id int(10) unsigned NOT NULL auto_increment,
303 303
   $USERCOL varchar(50) NOT NULL default '',
304
+  domain varchar(100) NOT NULL default '',
304 305
   uri varchar(255) NOT NULL default '',
305 306
   description varchar(255) NOT NULL default '',
306 307
   PRIMARY KEY (id)
... ...
@@ -365,6 +367,7 @@ CREATE TABLE missed_calls (
365 365
   to_uri varchar(128) NOT NULL default '',
366 366
   sip_callid varchar(128) NOT NULL default '',
367 367
   $USERCOL varchar(64) NOT NULL default '',
368
+  domain varchar(100) NOT NULL default '',
368 369
   fromtag varchar(128) NOT NULL default '',
369 370
   totag varchar(128) NOT NULL default '',
370 371
   time datetime NOT NULL default '0000-00-00 00:00:00',
... ...
@@ -383,6 +386,7 @@ CREATE TABLE missed_calls (
383 383
 CREATE TABLE pending (
384 384
   phplib_id varchar(32) NOT NULL default '',
385 385
   $USERCOL varchar(100) NOT NULL default '',
386
+  domain varchar(100) NOT NULL default '',
386 387
   password varchar(25) NOT NULL default '',
387 388
   first_name varchar(25) NOT NULL default '',
388 389
   last_name varchar(45) NOT NULL default '',
... ...
@@ -395,7 +399,6 @@ CREATE TABLE pending (
395 395
   sendnotification varchar(50) NOT NULL default '',
396 396
   greeting varchar(50) NOT NULL default '',
397 397
   ha1 varchar(128) NOT NULL default '',
398
-  domain varchar(128) NOT NULL default '',
399 398
   ha1b varchar(128) NOT NULL default '',
400 399
   perms varchar(32) default NULL,
401 400
   allow_find char(1) NOT NULL default '0',
... ...
@@ -416,6 +419,7 @@ CREATE TABLE pending (
416 416
 CREATE TABLE phonebook (
417 417
   id int(10) unsigned NOT NULL auto_increment,
418 418
   $USERCOL varchar(50) NOT NULL default '',
419
+  domain varchar(100) NOT NULL default '',
419 420
   fname varchar(32) NOT NULL default '',
420 421
   lname varchar(32) NOT NULL default '',
421 422
   sip_uri varchar(128) NOT NULL default '',
... ...
@@ -447,6 +451,7 @@ CREATE TABLE reserved (
447 447
 CREATE TABLE subscriber (
448 448
   phplib_id varchar(32) NOT NULL default '',
449 449
   $USERCOL varchar(100) NOT NULL default '',
450
+  domain varchar(100) NOT NULL default '',
450 451
   password varchar(25) NOT NULL default '',
451 452
   first_name varchar(25) NOT NULL default '',
452 453
   last_name varchar(45) NOT NULL default '',
... ...
@@ -459,7 +464,6 @@ CREATE TABLE subscriber (
459 459
   sendnotification varchar(50) NOT NULL default '',
460 460
   greeting varchar(50) NOT NULL default '',
461 461
   ha1 varchar(128) NOT NULL default '',
462
-  domain varchar(128) NOT NULL default '',
463 462
   ha1b varchar(128) NOT NULL default '',
464 463
   perms varchar(32) default NULL,
465 464
   allow_find char(1) NOT NULL default '0',
... ...
@@ -476,6 +480,7 @@ CREATE TABLE config (
476 476
    attribute varchar(32) NOT NULL,
477 477
    value varchar(128) NOT NULL,
478 478
    $USERCOL varchar(100) NOT NULL default '',
479
+   domain varchar(100) NOT NULL default '',
479 480
    modified timestamp(14)
480 481
 ) $TABLE_TYPE;
481 482
 
... ...
@@ -520,39 +525,14 @@ CREATE TABLE uri (
520 520
 #
521 521
 
522 522
 
523
+DROP TABLE IF EXISTS server_monitoring;
523 524
 CREATE TABLE server_monitoring (
524 525
   time datetime NOT NULL default '0000-00-00 00:00:00',
525
-  ts_current int(10) unsigned default NULL,
526
-  ts_waiting int(10) unsigned default NULL,
527
-  ts_total int(10) unsigned default NULL,
528
-  ts_total_local int(10) unsigned default NULL,
529
-  ts_replied int(10) unsigned default NULL,
530
-  ts_6xx int(10) unsigned default NULL,
531
-  ts_5xx int(10) unsigned default NULL,
532
-  ts_4xx int(10) unsigned default NULL,
533
-  ts_3xx int(10) unsigned default NULL,
534
-  ts_2xx int(10) unsigned default NULL,
535
-  sl_200 int(10) unsigned default NULL,
536
-  sl_202 int(10) unsigned default NULL,
537
-  sl_2xx int(10) unsigned default NULL,
538
-  sl_300 int(10) unsigned default NULL,
539
-  sl_301 int(10) unsigned default NULL,
540
-  sl_302 int(10) unsigned default NULL,
541
-  sl_3xx int(10) unsigned default NULL,
542
-  sl_400 int(10) unsigned default NULL,
543
-  sl_401 int(10) unsigned default NULL,
544
-  sl_403 int(10) unsigned default NULL,
545
-  sl_404 int(10) unsigned default NULL,
546
-  sl_407 int(10) unsigned default NULL,
547
-  sl_408 int(10) unsigned default NULL,
548
-  sl_483 int(10) unsigned default NULL,
549
-  sl_4xx int(10) unsigned default NULL,
550
-  sl_500 int(10) unsigned default NULL,
551
-  sl_5xx int(10) unsigned default NULL,
552
-  sl_6xx int(10) unsigned default NULL,
553
-  sl_xxx int(10) unsigned default NULL,
554
-  sl_failures int(10) unsigned default NULL,
555
-  PRIMARY KEY  (time)
526
+  id int(10) unsigned NOT NULL default '0',
527
+  param varchar(32) NOT NULL default '',
528
+  value int(10) NOT NULL default '0',
529
+  increment int(10) NOT NULL default '0',
530
+  PRIMARY KEY  (id,param)
556 531
 ) $TABLE_TYPE;
557 532
 
558 533
 
... ...
@@ -565,19 +545,28 @@ CREATE TABLE preferences (
565 565
 ) $TABLE_TYPE;
566 566
 
567 567
 #
568
-# Table structure for table 'server_monitoring_ul'
568
+# Table structure for table 'server_monitoring_agg'
569 569
 #
570 570
 
571 571
 
572
-CREATE TABLE server_monitoring_ul (
573
-  time datetime NOT NULL default '0000-00-00 00:00:00',
574
-  domain varchar(64) NOT NULL default '',
575
-  registered int(10) unsigned default NULL,
576
-  expired int(10) unsigned default NULL,
577
-  PRIMARY KEY  (domain,time)
572
+DROP TABLE IF EXISTS server_monitoring_agg;
573
+CREATE TABLE server_monitoring_agg (
574
+  param varchar(32) NOT NULL default '',
575
+  s_value int(10) NOT NULL default '0',
576
+  s_increment int(10) NOT NULL default '0',
577
+  last_aggregated_increment int(10) NOT NULL default '0',
578
+  av float NOT NULL default '0',
579
+  mv int(10) NOT NULL default '0',
580
+  ad float NOT NULL default '0',
581
+  lv int(10) NOT NULL default '0',
582
+  min_val int(10) NOT NULL default '0',
583
+  max_val int(10) NOT NULL default '0',
584
+  min_inc int(10) NOT NULL default '0',
585
+  max_inc int(10) NOT NULL default '0',
586
+  lastupdate datetime NOT NULL default '0000-00-00 00:00:00',
587
+  PRIMARY KEY  (param)
578 588
 ) $TABLE_TYPE;
579 589
 
580
-
581 590
 # add an admin user "admin" with password==heslo, 
582 591
 # so that one can try it out on quick start
583 592
 
584 593
new file mode 100755
... ...
@@ -0,0 +1,563 @@
0
+#!/bin/sh
1
+#
2
+# $Id$
3
+#
4
+# SER configuration script
5
+#
6
+# disclaimer: extremely simplistic and experimental
7
+# useful only for people who know what they are doing
8
+# and want to save some typing
9
+#
10
+# call it to generate a basic script -- you have to
11
+# carry out any subsequent changes manually
12
+#
13
+
14
+# ------------------- Variables ------------------------
15
+
16
+# prompted variables
17
+# SER_DOMAIN -- name of served domain, e.g., foo.bar.com
18
+# SER_GWIP -- IP address of PSTN gateway, e.g. 10.0.0.1
19
+
20
+# parameters that are typically not changed
21
+SER_SQL_URI="sql://ser:heslo@localhost/ser"
22
+# set LIB_PATH if all modules are installed in a single
23
+# directory; otherwise, modules are sought in 'modules'
24
+# subdirectories
25
+#SER_LIB_PATH="/usr/local/lib/ser/modules"
26
+
27
+
28
+# --------------------- functions ---------------------------
29
+function go_to_pstn()
30
+{
31
+	if [ -n "$SER_GWIP" ] ; then 
32
+		cat << EOGOTOPSTN
33
+	# now check if it's about PSTN destinations through our gateway;
34
+	# note that 8.... is exempted for numerical non-gw destinations
35
+	if (uri=~"sip:\+?[0-79][0-9]*@.*") {
36
+		route(3);
37
+		break;
38
+	}; 
39
+EOGOTOPSTN
40
+	fi
41
+}
42
+
43
+
44
+function addr2re()
45
+{
46
+	echo $1 |  sed -ne "s/\./\\\./gp"
47
+}
48
+
49
+function gw_check()
50
+{
51
+	if [ -n "$SER_GWIP" ] ; then 
52
+		cat << EOGWTEST
53
+		if (uri=~"sip:[+0-9]+@$SER_GWIP_RE") {
54
+			# it is gateway -- proceed to ACLs
55
+			route(3);
56
+			break;
57
+		};
58
+EOGWTEST
59
+	fi
60
+}
61
+
62
+function mine_check()
63
+{
64
+	printf "uri=~\"[@:](sip[\.)?$SER_DOMAIN_TEST_RE([;:].*)*\" $SER_GW_TEST_RE"
65
+}
66
+
67
+function gw_m_check()
68
+{
69
+	if [ -n "$SER_GWIP" ] ; then 
70
+		cat << EOMCHECK
71
+		if (search("^(Contact|m): .*$SER_GWIP_RE")) {
72
+			log(1, "LOG: alert: protected contacts\n");
73
+			sl_send_reply("476", "No Server Address in Contacts Allowed" );
74
+			break;
75
+		};
76
+EOMCHECK
77
+	fi
78
+}
79
+
80
+function help()
81
+{
82
+	cat << EOHELP
83
+Numbering plan is as follows:
84
+- numbers beginning with 8 are considered aliases
85
+- numbers beginning with + are considered ENUM destinations
86
+EOHELP
87
+	if [ -n "$SER_GWIP" ] ; then
88
+		cat << EOHELP2
89
+- all other numbers are considered PSTN destinations
90
+  ... to dial PSTN, a user must have 'int' privilege
91
+EOHELP2
92
+	else
93
+		echo "- all other numbers are considered usernames"
94
+	fi
95
+}
96
+
97
+function usage()
98
+{
99
+	echo "Usage: $0 <domain_name> [<ip_address_of_gateway>]" \
100
+		'> <config_file>' > /dev/stderr
101
+	exit 1
102
+}
103
+
104
+function load_mod()
105
+{
106
+	if [ -n "$SER_LIB_PATH" ] ; then
107
+		echo "loadmodule \"$SER_LIB_PATH/$1.so\""
108
+	else
109
+		echo "loadmodule \"modules/$1/$1.so\""
110
+	fi
111
+}
112
+
113
+# ----------------------- user-parameter check ---------------
114
+# SER_DOMAIN -- name of served domain, e.g., foo.bar.com
115
+# SER_GWIP -- IP address of PSTN gateway, e.g. 10.0.0.1
116
+
117
+if [ $# -gt 0 ] ; then
118
+	SER_DOMAIN="$1"
119
+	shift
120
+	if [ $# -gt 0 ] ; then
121
+		SER_GWIP="$1"
122
+		shift
123
+	fi
124
+	if [ $# -gt 0 ] ; then
125
+		usage
126
+	fi
127
+else
128
+	usage
129
+fi
130
+
131
+# ---------------------- initialization -------------------------
132
+
133
+# autodetection parameters
134
+SER_IP=`/sbin/ifconfig eth0 | 
135
+	sed -ne 's/\( \)*\(inet addr:\)\([0-9\.]*\).*/\3/gp'`
136
+
137
+# construction of regular expressions
138
+SER_IP_RE=`addr2re $SER_IP`
139
+SER_DOMAIN_RE=`addr2re $SER_DOMAIN`
140
+
141
+# tests
142
+# - is this for my domain
143
+SER_DOMAIN_TEST_RE=`printf "($SER_DOMAIN_RE|$SER_IP_RE)"`
144
+# - is this for my gateway ?
145
+if [ -n "$SER_GWIP" ] ; then
146
+	SER_GWIP_RE=`addr2re $SER_GWIP`
147
+	SER_GW_TEST_RE=`printf "| uri=~\"@$SER_GWIP_RE([;:].*)*\""`
148
+fi
149
+
150
+SER_REGISTRAR="registrar@$SER_DOMAIN"
151
+
152
+# ---------------------- verficiation --------------------------
153
+set | grep ^SER_ > /dev/stderr
154
+echo > /dev/stderr
155
+echo "IS EVERYTHING OK ???? (press ^C to interrupt)" > /dev/stderr
156
+read
157
+
158
+
159
+# --------------------- dump it here -------------------------
160
+
161
+cat << EOF
162
+
163
+#
164
+# \$Id$
165
+#
166
+# autogenerated SER configuration 
167
+#
168
+# user: `id`
169
+# system: `uname -a`
170
+# date: `date`
171
+#
172
+
173
+# ----------- global configuration parameters ------------------------
174
+
175
+debug=3
176
+fork=yes
177
+port=5060
178
+log_stderror=no
179
+memlog=5
180
+
181
+mhomed=yes
182
+
183
+fifo="/tmp/ser_fifo"
184
+
185
+alias=$SER_DOMAIN
186
+
187
+# uncomment to override config values for test 
188
+/* 
189
+debug=3             # debug level (cmd line: -ddd)
190
+fork=no
191
+port=5068
192
+log_stderror=yes	# (cmd line: -E)
193
+fifo="/tmp/ser_fifox"
194
+ */
195
+
196
+
197
+check_via=no		# (cmd. line: -v)
198
+dns=no              # (cmd. line: -r)
199
+rev_dns=no          # (cmd. line: -R)
200
+children=16
201
+# if changing fifo mode to a more restrictive value, put
202
+# decimal value in there, e.g. dec(rw|rw|rw)=dec(666)=438
203
+#fifo_mode=438
204
+
205
+# ------------------ module loading ----------------------------------
206
+
207
+`load_mod tm`
208
+`load_mod sl`
209
+`load_mod acc`
210
+`load_mod rr`
211
+`load_mod maxfwd`
212
+`load_mod mysql`
213
+`load_mod usrloc`
214
+`load_mod registrar`
215
+`load_mod auth`
216
+`load_mod auth_db`
217
+`load_mod textops`
218
+`load_mod uri`
219
+`load_mod group`
220
+`load_mod msilo`
221
+`load_mod enum`
222
+
223
+
224
+
225
+# ----------------- setting module-specific parameters ---------------
226
+
227
+# all DB urls here
228
+modparam("usrloc|acc|auth_db|group|msilo|uri", "db_url",
229
+	"$SER_SQL_URI")
230
+
231
+# -- usrloc params --
232
+/* 0 -- dont use mysql, 1 -- write_through, 2--write_back */
233
+modparam("usrloc", "db_mode",   2)
234
+modparam("usrloc", "timer_interval", 10)
235
+
236
+# -- auth params --
237
+
238
+modparam("auth_db", "calculate_ha1", yes)
239
+#modparam("auth_db", "user_column",   "user_id")
240
+modparam("auth_db", "password_column",   "password")
241
+modparam("auth", "nonce_expire",  300)
242
+
243
+# -- rr params --
244
+# add value to ;lr param to make some broken UAs happy
245
+modparam("rr", "enable_full_lr", 1)
246
+
247
+# -- acc params --
248
+# that is the flag for which we will account -- don't forget to
249
+modparam("acc", "db_flag", 1 )
250
+modparam("acc", "db_missed_flag", 3 )
251
+
252
+# -- tm params --
253
+modparam("tm", "fr_timer", 20 )
254
+modparam("tm", "fr_inv_timer", 90 )
255
+modparam("tm", "wt_timer", 20 )
256
+
257
+# -- msilo params
258
+modparam("msilo", "registrar", "sip:$SER_REGISTRAR")
259
+
260
+# -- enum params --
261
+#
262
+modparam("enum", "domain_suffix", "e164.arpa.")
263
+
264
+
265
+# -------------------------  request routing logic -------------------
266
+
267
+# main routing logic
268
+
269
+route{
270
+
271
+	/* ********* ROUTINE CHECKS  ********************************** */
272
+
273
+	# filter too old messages
274
+	if (!mf_process_maxfwd_header("10")) {
275
+		log("LOG: Too many hops\n");
276
+		sl_send_reply("483","Alas Too Many Hops");
277
+		break;
278
+	};
279
+	if (len_gt( max_len )) {
280
+		sl_send_reply("513", "Message too large sorry");
281
+		break;
282
+	};
283
+
284
+
285
+	# Make sure that requests dont advertise addresses 
286
+	# from private IP space (RFC1918) in Contact HF
287
+	# (note: does not match with folded lines)
288
+	if (search("^(Contact|m): .*@(192\.168\.|10\.|172\.16)")) {
289
+		# allow RR-ed requests, as these may indicate that
290
+		# a NAT-enabled proxy takes care of it; unless it is
291
+		# a REGISTER
292
+		if ((method=="REGISTER" || ! search("^Record-Route:")) 
293
+					&& !( src_ip==192.168.0.0/16 ||
294
+						src_ip==10.0.0.0/8 || src_ip==172.16.0.0/12 )) {
295
+			log("LOG: Someone trying to register from private IP again\n");
296
+			sl_send_reply("479", "We dont accept private IP contacts" );
297
+			break;
298
+		};
299
+	};
300
+
301
+	# anti-spam -- if somene claims to belong to our domain in From,
302
+	# challenge him (skip REGISTERs -- we will chalenge them later)
303
+	if (search("(From|F):.*$SER_DOMAIN_TEST_RE")) {
304
+		# invites forwarded to other domains, like FWD may cause subsequent 
305
+		# request to come from there but have iptel in From -> verify
306
+		# only INVITEs (ignore FIFO/UAC's requests, i.e. src_ip==myself)
307
+		if (method=="INVITE" &  !(src_ip==$SER_IP)) {
308
+			if  (!(proxy_authorize(	"$SER_DOMAIN" /* realm */,
309
+					"subscriber" /* table name */ ))) {
310
+				proxy_challenge("$SER_DOMAIN" /* realm */, "0" /* no-qop */);
311
+				break;
312
+			};
313
+			# to maintain outside credibility of our proxy, we enforce
314
+			# username in From to equal digest username; user with
315
+			# "john.doe" id could advertise "bill.gates" in From otherwise;
316
+			if (!check_from()) {
317
+				log("LOG: From Cheating attempt in INVITE\n");
318
+				sl_send_reply("403", "That is ugly -- use From=id next time (OB)");
319
+				break;
320
+			};
321
+            		# we better don't consume credentials -- some requests may be
322
+            		# spiraled through our server (sfo@iptel->7141@iptel) and the
323
+            		# subsequent iteration may challenge too, for example because of
324
+            		# iptel claim in From; UACs then give up because they
325
+        		# already submitted credentials for the given realm
326
+			#consume_credentials();
327
+		}; # INVITEs claiming to come from our domain
328
+	} else if (method=="INVITE" && !(uri=~"[@:\.]$SER_DOMAIN_TEST_RE([;:].*)*" 
329
+			# ... and we serve our gateway too if present
330
+			$SER_GW_TEST_RE )) {
331
+		#the INVITE neither claims to come from our domain nor is it targeted to it
332
+		# -> junk it
333
+		sl_send_reply("403", "No relaying");
334
+		break;
335
+	};
336
+
337
+
338
+	/* ********* RR ********************************** */
339
+	# to be safe, record route everything; UAs may use different
340
+	# transport protocols and need to have SER in path
341
+	record_route();
342
+	# if route forces us to forward to some explicit destination,
343
+	# do so; check however first that a cheater didn't preload 
344
+	# a gateway destination to bypass PSTN ACLs
345
+
346
+	if (loose_route()) {
347
+		`gw_check`
348
+		# route HF determined next hop; forward there
349
+		append_hf("P-hint: rr-enforced\r\n");
350
+		t_relay();
351
+		break;
352
+	};
353
+
354
+
355
+	/*  *********  check for requests targeted out of our domain... ******* */
356
+	# sign of our domain: there is '@' (username) or  : (nothing) in 
357
+	# front of our domain name	; ('.' is not there -- we handle all
358
+	# xxx.iptel.org as outbound hosts);if none of these cases matches, 
359
+	# proceed with processing of outbound requests in route[2]
360
+	if (!(`mine_check`)) {
361
+		route(2);
362
+		break;
363
+	};
364
+
365
+
366
+	/* ************ requests for our domain ********** */
367
+
368
+
369
+	/* now, the request is for sure for our domain */
370
+
371
+
372
+	# registers always MUST be authenticated to
373
+	# avoid stealing incoming calls	
374
+	if (method=="REGISTER") {
375
+
376
+		# Make sure that user's dont register infinite loops
377
+		# (note: does not match with folded lines)
378
+		if (search("^(Contact|m): .*@$SER_DOMAIN_TEST_RE")) {
379
+			log(1, "LOG: alert: someone trying to set aor==contact\n");
380
+			sl_send_reply("476", "No Server Address in Contacts Allowed" );
381
+			break;
382
+		};
383
+		`gw_m_check`
384
+
385
+		if (!www_authorize(	"$SER_DOMAIN" /* realm */, 
386
+			 				"subscriber" /* table name */ )) {
387
+			# challenge if none or invalid credentials
388
+ 			www_challenge(	"$SER_DOMAIN" /* realm */, 
389
+							"0" /* no qop -- some phones can't deal with it */);
390
+			break;
391
+		};
392
+
393
+		# prohibit attempts to grab someone else's To address 
394
+		# using  valid credentials; 
395
+
396
+		if (!check_to()) {
397
+			log("LOG: To Cheating attempt\n");
398
+			sl_send_reply("403", "That is ugly -- use To=id in REGISTERs");
399
+			break;
400
+		};
401
+		# it is an authenticated request, update Contact database now
402
+		if (!save("location")) {
403
+			sl_reply_error();
404
+		};
405
+		m_dump();
406
+		break;
407
+	};
408
+
409
+	# some UACs might be fooled by Contacts our UACs generate to make MSN 
410
+	# happy (web-im, e.g.) -- tell its urneachable
411
+	if (uri=~"sip:daemon@" ) {
412
+		sl_send_reply("410", "daemon is gone");
413
+		break;
414
+	};
415
+
416
+	# is this an ENUM destination (leading +?)? give it a try, if the lookup
417
+	# doesn't change URI, just continue
418
+	if (uri=~"sip:\+[0-9]+@") {
419
+		if (!enum_query("voice")) { # if parameter empty, it defaults to "e2u+sip"
420
+			enum_query(""); # E2U+sip
421
+		};
422
+	} else {
423
+		# aliases  (take precedences over PSTN number; provisioning interface
424
+		# is set up to assinge aliases beginning with 8)
425
+		lookup("aliases");
426
+	};
427
+
428
+
429
+	# check again, if it is still for our domain after aliases are resolved
430
+	if (!(`mine_check`)) {
431
+		route(5);
432
+		break;
433
+	};
434
+
435
+	`go_to_pstn`
436
+
437
+	# native SIP destinations are handled using our USRLOC DB
438
+	if (!lookup("location")) {
439
+		# handle user which was not found ...
440
+		route(4);
441
+		break;
442
+	};
443
+	# check whether some inventive user has uploaded  gateway 
444
+	# contacts to UsrLoc to bypass our authorization logic
445
+	`gw_check`
446
+
447
+	/* ... and also report on missed calls ... */
448
+	setflag(3);
449
+
450
+	# we now know we may, we know where, let it go out now!
451
+	append_hf("P-hint: USRLOC\r\n");
452
+	if (!t_relay()) {
453
+		sl_reply_error();
454
+		break;
455
+	};
456
+}
457
+#------------------- OUTBOUND ----------------------------------------
458
+
459
+# routing logic for outbound requests targeted out of our domain
460
+# (keep in mind messages to our users can end up here too: for example,
461
+#  an INVITE may be UsrLoc-ed, then the other party uses outbound
462
+#  proxy with r-uri=the usr_loced addredd (typically IP))
463
+route[2] {
464
+	append_hf("P-hint: OUTBOUND\r\n");
465
+	t_relay();
466
+}
467
+
468
+#------- ALIASED OUTBOUND --------------------------------------------
469
+
470
+# routing logic for inbound requests aliased outbound; unlike
471
+# with real outbound requests we do not force authentication
472
+# as these calls are server by our server and we do not want
473
+# to disqualify unathenticated request originatiors from other
474
+# domains
475
+route[5] {
476
+	append_hf("P-hint: ALIASED-OUTBOUND\r\n");
477
+	t_relay();
478
+}
479
+
480
+#----------------- PSTN ----------------------------------------------
481
+
482
+# logic for calls to the PSTN
483
+route[3] {
484
+	# turn accounting on
485
+	setflag(1);
486
+
487
+	/* require all who call PSTN to be members of the "int" group;
488
+	   apply ACLs only to INVITEs -- we don't need to protect other requests, as they
489
+	   don't imply charges; also it could cause troubles when a call comes in via PSTN
490
+	   and goes to a party that can't authenticate (voicemail, other domain) -- BYEs would
491
+	   fail then; exempt Cisco gateway from authentication by IP address -- it does not
492
+	   support digest
493
+	*/
494
+	if (method=="INVITE" && (!src_ip==$SER_GWIP)) {
495
+		if (!proxy_authorize(	"$SER_DOMAIN" /* realm */,
496
+						"subscriber" /* table name */))  {
497
+			proxy_challenge( "$SER_DOMAIN" /* realm */, "0" /* no qop */ );
498
+			break;
499
+		};
500
+		# let's check from=id ... avoids accounting confusion
501
+		if (method=="INVITE" & !check_from()) {
502
+			log("LOG: From Cheating attempt\n");
503
+			sl_send_reply("403", "That is ugly -- use From=id next time (gw)");
504
+			break;
505
+		};
506
+
507
+		if(!is_user_in("credentials", "int")) {
508
+			sl_send_reply("403", "NO PSTN Privileges...");
509
+			break;
510
+		};
511
+		consume_credentials();
512
+
513
+	}; # INVITE to authorized PSTN
514
+
515
+	# if you have passed through all the checks, let your call go to GW!
516
+	rewritehostport("$SER_GWIP:5060");
517
+
518
+	# snom conditioner
519
+	if (method=="INVITE" && search("User-Agent: snom")) {
520
+		replace("100rel, ", "");
521
+	};
522
+
523
+	append_hf("P-hint: GATEWAY\r\n");
524
+	# use UDP to guarantee well-known sender port (TCP ephemeral)
525
+	t_relay_to_udp("$SER_GWIP","5060");
526
+}
527
+
528
+
529
+
530
+/* *********** handling of unavailable user ******************* */
531
+
532
+route[4] {
533
+/**/
534
+	# message store 
535
+	if (method=="MESSAGE") {
536
+		t_newtran();
537
+		if (m_store("0")) {
538
+			t_reply("202", "Accepted for Later Delivery");
539
+		} else {
540
+			t_reply("503", "Service Unavailable");
541
+		};
542
+		break;
543
+	};
544
+/**/
545
+	# non-Voip -- just send "off-line"
546
+	if (!(method=="INVITE" || method=="ACK" || method=="CANCEL")) {
547
+		sl_send_reply("404", "Not Found");
548
+		break;
549
+	};
550
+	# voicemail subscribers ...
551
+	t_newtran();
552
+	t_reply("404", "Not Found");
553
+	# we account missed incoming calls; previous statteful processing
554
+	# guarantees that retransmissions are not accounted
555
+	if (method=="INVITE") {
556
+		acc_db_request("404 missed call", "missed_calls");
557
+	};
558
+}
559
+
560
+EOF
561
+
562
+help > /dev/stderr