SHOW:
|
|
- or go back to the newest paste.
1 | #!define WITH_MYSQL | |
2 | #!define WITH_AUTH | |
3 | #!define WITH_USRLOCDB | |
4 | #!define WITH_ALIASDB | |
5 | #!define WITH_VOICEMAIL | |
6 | - | #!define WITH_FREESWITCH # jlee Freeswitch Integration |
6 | + | #!define WITH_FREESWITCH # limark Freeswitch Integration |
7 | ||
8 | #!ifdef ACCDB_COMMENT | |
9 | ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; | |
10 | ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; | |
11 | ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default ''; | |
12 | ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; | |
13 | ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; | |
14 | ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; | |
15 | ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT ''; | |
16 | ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT ''; | |
17 | ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default ''; | |
18 | ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT ''; | |
19 | ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT ''; | |
20 | ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT ''; | |
21 | #!endif | |
22 | ||
23 | ####### Include Local Config If Exists ######### | |
24 | import_file "kamailio-local.cfg" | |
25 | ||
26 | ####### Defined Values ######### | |
27 | ||
28 | # *** Value defines - IDs used later in config | |
29 | #!ifdef WITH_MYSQL | |
30 | # - database URL - used to connect to database server by modules such | |
31 | # as: auth_db, acc, usrloc, a.s.o. | |
32 | #!ifndef DBURL | |
33 | #!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio" | |
34 | #!endif | |
35 | #!endif | |
36 | #!ifdef WITH_MULTIDOMAIN | |
37 | # - the value for 'use_domain' parameters | |
38 | #!define MULTIDOMAIN 1 | |
39 | #!else | |
40 | #!define MULTIDOMAIN 0 | |
41 | #!endif | |
42 | ||
43 | # - flags | |
44 | # FLT_ - per transaction (message) flags | |
45 | # FLB_ - per branch flags | |
46 | #!define FLT_ACC 1 | |
47 | #!define FLT_ACCMISSED 2 | |
48 | #!define FLT_ACCFAILED 3 | |
49 | #!define FLT_NATS 5 | |
50 | ||
51 | #!define FLB_NATB 6 | |
52 | #!define FLB_NATSIPPING 7 | |
53 | ||
54 | ####### Global Parameters ######### | |
55 | ||
56 | #!ifdef WITH_DEBUG | |
57 | debug=4 | |
58 | log_stderror=yes | |
59 | #!else | |
60 | debug=2 | |
61 | log_stderror=no | |
62 | #!endif | |
63 | ||
64 | memdbg=5 | |
65 | memlog=5 | |
66 | ||
67 | log_facility=LOG_LOCAL0 | |
68 | ||
69 | fork=yes | |
70 | children=4 | |
71 | ||
72 | /* uncomment the next line to disable TCP (default on) */ | |
73 | #disable_tcp=yes | |
74 | ||
75 | /* uncomment the next line to disable the auto discovery of local aliases | |
76 | based on reverse DNS on IPs (default on) */ | |
77 | #auto_aliases=no | |
78 | ||
79 | /* add local domain aliases */ | |
80 | #alias="sip.mydomain.com" | |
81 | ||
82 | /* uncomment and configure the following line if you want Kamailio to | |
83 | bind on a specific interface/port/proto (default bind on all available) */ | |
84 | #listen=udp:10.0.0.10:5060 | |
85 | ||
86 | /* port to listen to | |
87 | * - can be specified more than once if needed to listen on many ports */ | |
88 | port=5060 | |
89 | ||
90 | #!ifdef WITH_TLS | |
91 | enable_tls=yes | |
92 | #!endif | |
93 | ||
94 | # life time of TCP connection when there is no traffic | |
95 | # - a bit higher than registration expires to cope with UA behind NAT | |
96 | tcp_connection_lifetime=3605 | |
97 | ||
98 | #!ifdef WITH_XHTTP | |
99 | tcp_accept_no_cl=yes | |
100 | #!endif | |
101 | ||
102 | ####### Custom Parameters ######### | |
103 | ||
104 | # These parameters can be modified runtime via RPC interface | |
105 | # - see the documentation of 'cfg_rpc' module. | |
106 | # | |
107 | # Format: group.id = value 'desc' description | |
108 | # Access: $sel(cfg_get.group.id) or @cfg_get.group.id | |
109 | # | |
110 | ||
111 | #!ifdef WITH_PSTN | |
112 | # PSTN GW Routing | |
113 | # | |
114 | # - pstn.gw_ip: valid IP or hostname as string value, example: | |
115 | # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address" | |
116 | # | |
117 | # - by default is empty to avoid misrouting | |
118 | pstn.gw_ip = "" desc "PSTN GW Address" | |
119 | pstn.gw_port = "" desc "PSTN GW Port" | |
120 | #!endif | |
121 | ||
122 | - | # jlee Freeswitch Integration |
122 | + | # limark Freeswitch Integration |
123 | #!ifdef WITH_FREESWITCH | |
124 | freeswitch.bindip = "192.168.1.111" desc "FreeSWITCH IP Address" | |
125 | freeswitch.bindport = "5060" desc "FreeSWITCH Port" | |
126 | #!endif | |
127 | ||
128 | #!ifdef WITH_VOICEMAIL | |
129 | # VoiceMail Routing on offline, busy or no answer | |
130 | # | |
131 | # - by default Voicemail server IP is empty to avoid misrouting | |
132 | voicemail.srv_ip = "" desc "VoiceMail IP Address" | |
133 | voicemail.srv_port = "5060" desc "VoiceMail Port" | |
134 | #!endif | |
135 | ||
136 | ####### Modules Section ######## | |
137 | ||
138 | # set paths to location of modules (to sources or installation folders) | |
139 | #!ifdef WITH_SRCPATH | |
140 | mpath="modules_k:modules" | |
141 | #!else | |
142 | mpath="/usr/local/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/" | |
143 | #!endif | |
144 | ||
145 | #!ifdef WITH_MYSQL | |
146 | loadmodule "db_mysql.so" | |
147 | #!endif | |
148 | ||
149 | loadmodule "mi_fifo.so" | |
150 | loadmodule "kex.so" | |
151 | loadmodule "corex.so" | |
152 | loadmodule "tm.so" | |
153 | loadmodule "tmx.so" | |
154 | loadmodule "sl.so" | |
155 | loadmodule "rr.so" | |
156 | loadmodule "pv.so" | |
157 | loadmodule "maxfwd.so" | |
158 | loadmodule "usrloc.so" | |
159 | loadmodule "registrar.so" | |
160 | loadmodule "textops.so" | |
161 | loadmodule "siputils.so" | |
162 | loadmodule "xlog.so" | |
163 | loadmodule "sanity.so" | |
164 | loadmodule "ctl.so" | |
165 | loadmodule "cfg_rpc.so" | |
166 | loadmodule "mi_rpc.so" | |
167 | loadmodule "acc.so" | |
168 | ||
169 | #!ifdef WITH_AUTH | |
170 | loadmodule "auth.so" | |
171 | loadmodule "auth_db.so" | |
172 | #!ifdef WITH_IPAUTH | |
173 | loadmodule "permissions.so" | |
174 | #!endif | |
175 | #!endif | |
176 | ||
177 | #!ifdef WITH_ALIASDB | |
178 | loadmodule "alias_db.so" | |
179 | #!endif | |
180 | ||
181 | #!ifdef WITH_SPEEDDIAL | |
182 | loadmodule "speeddial.so" | |
183 | #!endif | |
184 | ||
185 | #!ifdef WITH_MULTIDOMAIN | |
186 | loadmodule "domain.so" | |
187 | #!endif | |
188 | ||
189 | #!ifdef WITH_PRESENCE | |
190 | loadmodule "presence.so" | |
191 | loadmodule "presence_xml.so" | |
192 | #!endif | |
193 | ||
194 | #!ifdef WITH_NAT | |
195 | loadmodule "nathelper.so" | |
196 | loadmodule "rtpproxy.so" | |
197 | #!endif | |
198 | ||
199 | #!ifdef WITH_TLS | |
200 | loadmodule "tls.so" | |
201 | #!endif | |
202 | ||
203 | #!ifdef WITH_ANTIFLOOD | |
204 | loadmodule "htable.so" | |
205 | loadmodule "pike.so" | |
206 | #!endif | |
207 | ||
208 | #!ifdef WITH_XMLRPC | |
209 | loadmodule "xmlrpc.so" | |
210 | #!endif | |
211 | ||
212 | #!ifdef WITH_DEBUG | |
213 | loadmodule "debugger.so" | |
214 | #!endif | |
215 | ||
216 | #!ifdef WITH_XHTTP | |
217 | loadmodule "xhttp.so" | |
218 | #!endif | |
219 | ||
220 | #!ifdef WITH_XHTTP_RPC | |
221 | loadmodule "xhttp_rpc.so" | |
222 | #!endif | |
223 | ||
224 | #!ifdef WITH_XHTTP_PI | |
225 | loadmodule "xhttp_pi.so" | |
226 | #!endif | |
227 | ||
228 | # ----------------- setting module-specific parameters --------------- | |
229 | ||
230 | ||
231 | # ----- mi_fifo params ----- | |
232 | modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo") | |
233 | ||
234 | ||
235 | # ----- tm params ----- | |
236 | # auto-discard branches from previous serial forking leg | |
237 | modparam("tm", "failure_reply_mode", 3) | |
238 | # default retransmission timeout: 30sec | |
239 | modparam("tm", "fr_timer", 30000) | |
240 | # default invite retransmission timeout after 1xx: 120sec | |
241 | modparam("tm", "fr_inv_timer", 120000) | |
242 | ||
243 | ||
244 | # ----- rr params ----- | |
245 | # add value to ;lr param to cope with most of the UAs | |
246 | modparam("rr", "enable_full_lr", 1) | |
247 | # do not append from tag to the RR (no need for this script) | |
248 | modparam("rr", "append_fromtag", 0) | |
249 | ||
250 | ||
251 | # ----- registrar params ----- | |
252 | modparam("registrar", "method_filtering", 1) | |
253 | /* uncomment the next line to disable parallel forking via location */ | |
254 | # modparam("registrar", "append_branches", 0) | |
255 | /* uncomment the next line not to allow more than 10 contacts per AOR */ | |
256 | #modparam("registrar", "max_contacts", 10) | |
257 | # max value for expires of registrations | |
258 | modparam("registrar", "max_expires", 3600) | |
259 | # set it to 1 to enable GRUU | |
260 | modparam("registrar", "gruu_enabled", 0) | |
261 | ||
262 | ||
263 | # ----- acc params ----- | |
264 | /* what special events should be accounted ? */ | |
265 | modparam("acc", "early_media", 0) | |
266 | modparam("acc", "report_ack", 0) | |
267 | modparam("acc", "report_cancels", 0) | |
268 | /* by default ww do not adjust the direct of the sequential requests. | |
269 | if you enable this parameter, be sure the enable "append_fromtag" | |
270 | in "rr" module */ | |
271 | modparam("acc", "detect_direction", 0) | |
272 | /* account triggers (flags) */ | |
273 | modparam("acc", "log_flag", FLT_ACC) | |
274 | modparam("acc", "log_missed_flag", FLT_ACCMISSED) | |
275 | modparam("acc", "log_extra", | |
276 | "src_user=$fU;src_domain=$fd;src_ip=$si;" | |
277 | "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd") | |
278 | modparam("acc", "failed_transaction_flag", FLT_ACCFAILED) | |
279 | /* enhanced DB accounting */ | |
280 | #!ifdef WITH_ACCDB | |
281 | modparam("acc", "db_flag", FLT_ACC) | |
282 | modparam("acc", "db_missed_flag", FLT_ACCMISSED) | |
283 | modparam("acc", "db_url", DBURL) | |
284 | modparam("acc", "db_extra", | |
285 | "src_user=$fU;src_domain=$fd;src_ip=$si;" | |
286 | "dst_ouser=$tU;dst_user=$rU;dst_domain=$rd") | |
287 | #!endif | |
288 | ||
289 | ||
290 | # ----- usrloc params ----- | |
291 | /* enable DB persistency for location entries */ | |
292 | #!ifdef WITH_USRLOCDB | |
293 | modparam("usrloc", "db_url", DBURL) | |
294 | modparam("usrloc", "db_mode", 2) | |
295 | modparam("usrloc", "use_domain", MULTIDOMAIN) | |
296 | #!endif | |
297 | ||
298 | ||
299 | # ----- auth_db params ----- | |
300 | #!ifdef WITH_AUTH | |
301 | modparam("auth_db", "db_url", DBURL) | |
302 | modparam("auth_db", "calculate_ha1", yes) | |
303 | modparam("auth_db", "password_column", "password") | |
304 | modparam("auth_db", "load_credentials", "") | |
305 | modparam("auth_db", "use_domain", MULTIDOMAIN) | |
306 | ||
307 | # ----- permissions params ----- | |
308 | #!ifdef WITH_IPAUTH | |
309 | modparam("permissions", "db_url", DBURL) | |
310 | modparam("permissions", "db_mode", 1) | |
311 | #!endif | |
312 | ||
313 | #!endif | |
314 | ||
315 | ||
316 | # ----- alias_db params ----- | |
317 | #!ifdef WITH_ALIASDB | |
318 | modparam("alias_db", "db_url", DBURL) | |
319 | modparam("alias_db", "use_domain", MULTIDOMAIN) | |
320 | #!endif | |
321 | ||
322 | ||
323 | # ----- speeddial params ----- | |
324 | #!ifdef WITH_SPEEDDIAL | |
325 | modparam("speeddial", "db_url", DBURL) | |
326 | modparam("speeddial", "use_domain", MULTIDOMAIN) | |
327 | #!endif | |
328 | ||
329 | ||
330 | # ----- domain params ----- | |
331 | #!ifdef WITH_MULTIDOMAIN | |
332 | modparam("domain", "db_url", DBURL) | |
333 | # register callback to match myself condition with domains list | |
334 | modparam("domain", "register_myself", 1) | |
335 | #!endif | |
336 | ||
337 | ||
338 | #!ifdef WITH_PRESENCE | |
339 | # ----- presence params ----- | |
340 | modparam("presence", "db_url", DBURL) | |
341 | ||
342 | # ----- presence_xml params ----- | |
343 | modparam("presence_xml", "db_url", DBURL) | |
344 | modparam("presence_xml", "force_active", 1) | |
345 | #!endif | |
346 | ||
347 | ||
348 | #!ifdef WITH_NAT | |
349 | # ----- rtpproxy params ----- | |
350 | modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722") | |
351 | ||
352 | # ----- nathelper params ----- | |
353 | modparam("nathelper", "natping_interval", 30) | |
354 | modparam("nathelper", "ping_nated_only", 1) | |
355 | modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) | |
356 | modparam("nathelper", "sipping_from", "sip:[email protected]") | |
357 | ||
358 | # params needed for NAT traversal in other modules | |
359 | modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)") | |
360 | modparam("usrloc", "nat_bflag", FLB_NATB) | |
361 | #!endif | |
362 | ||
363 | ||
364 | #!ifdef WITH_TLS | |
365 | # ----- tls params ----- | |
366 | modparam("tls", "config", "/etc/kamailio/tls.cfg") | |
367 | #!endif | |
368 | ||
369 | #!ifdef WITH_ANTIFLOOD | |
370 | # ----- pike params ----- | |
371 | modparam("pike", "sampling_time_unit", 2) | |
372 | modparam("pike", "reqs_density_per_unit", 16) | |
373 | modparam("pike", "remove_latency", 4) | |
374 | ||
375 | # ----- htable params ----- | |
376 | # ip ban htable with autoexpire after 5 minutes | |
377 | modparam("htable", "htable", "ipban=>size=8;autoexpire=300;") | |
378 | #!endif | |
379 | ||
380 | #!ifdef WITH_XMLRPC | |
381 | # ----- xmlrpc params ----- | |
382 | modparam("xmlrpc", "route", "XMLRPC"); | |
383 | modparam("xmlrpc", "url_match", "^/RPC") | |
384 | #!endif | |
385 | ||
386 | #!ifdef WITH_DEBUG | |
387 | # ----- debugger params ----- | |
388 | modparam("debugger", "cfgtrace", 1) | |
389 | #!endif | |
390 | ||
391 | #!ifdef WITH_XHTTP_RPC | |
392 | modparam("xhttp_rpc", "xhttp_rpc_root", "http_rpc") | |
393 | #!endif | |
394 | ||
395 | #!ifdef WITH_XHTTP_PI | |
396 | modparam("xhttp_pi", "xhttp_pi_root", "http_pi") | |
397 | modparam("xhttp_pi", "framework", "/etc/kamailio/pi_framework.xml") | |
398 | #!endif | |
399 | ||
400 | ####### Routing Logic ######## | |
401 | ||
402 | ||
403 | # Main SIP request routing logic | |
404 | # - processing of any incoming SIP request starts with this route | |
405 | # - note: this is the same as route { ... } | |
406 | request_route { | |
407 | ||
408 | # per request initial checks | |
409 | route(REQINIT); | |
410 | ||
411 | # NAT detection | |
412 | route(NATDETECT); | |
413 | ||
414 | # CANCEL processing | |
415 | if (is_method("CANCEL")) | |
416 | { | |
417 | if (t_check_trans()) | |
418 | t_relay(); | |
419 | exit; | |
420 | } | |
421 | ||
422 | # handle requests within SIP dialogs | |
423 | route(WITHINDLG); | |
424 | ||
425 | ### only initial requests (no To tag) | |
426 | ||
427 | t_check_trans(); | |
428 | ||
429 | # authentication | |
430 | route(AUTH); | |
431 | ||
432 | # record routing for dialog forming requests (in case they are routed) | |
433 | # - remove preloaded route headers | |
434 | remove_hf("Route"); | |
435 | if (is_method("INVITE|SUBSCRIBE")) | |
436 | record_route(); | |
437 | ||
438 | # account only INVITEs | |
439 | if (is_method("INVITE")) | |
440 | { | |
441 | setflag(FLT_ACC); # do accounting | |
442 | } | |
443 | ||
444 | # dispatch requests to foreign domains | |
445 | route(SIPOUT); | |
446 | ||
447 | ### requests for my local domains | |
448 | ||
449 | # handle presence related requests | |
450 | route(PRESENCE); | |
451 | ||
452 | # handle registrations | |
453 | route(REGISTRAR); | |
454 | ||
455 | if ($rU==$null) | |
456 | { | |
457 | # request with no Username in RURI | |
458 | sl_send_reply("484","Address Incomplete"); | |
459 | exit; | |
460 | } | |
461 | ||
462 | # dispatch destinations to PSTN | |
463 | route(PSTN); | |
464 | ||
465 | - | # jlee Freeswitch Integration |
465 | + | # limark Freeswitch Integration |
466 | #!ifdef WITH_FREESWITCH | |
467 | # save callee ID | |
468 | $avp(callee) = $rU; | |
469 | route(FSDISPATCH); | |
470 | #!endif | |
471 | ||
472 | # user location service | |
473 | route(LOCATION); | |
474 | ||
475 | route(RELAY); | |
476 | } | |
477 | ||
478 | ||
479 | route[RELAY] { | |
480 | ||
481 | # enable additional event routes for forwarded requests | |
482 | # - serial forking, RTP relaying handling, a.s.o. | |
483 | if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { | |
484 | if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); | |
485 | } | |
486 | if (is_method("INVITE|SUBSCRIBE|UPDATE")) { | |
487 | if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY"); | |
488 | } | |
489 | if (is_method("INVITE")) { | |
490 | if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); | |
491 | } | |
492 | ||
493 | if (!t_relay()) { | |
494 | sl_reply_error(); | |
495 | } | |
496 | exit; | |
497 | } | |
498 | ||
499 | # Per SIP request initial checks | |
500 | route[REQINIT] { | |
501 | #!ifdef WITH_ANTIFLOOD | |
502 | # flood dection from same IP and traffic ban for a while | |
503 | # be sure you exclude checking trusted peers, such as pstn gateways | |
504 | # - local host excluded (e.g., loop to self) | |
505 | if(src_ip!=myself) | |
506 | { | |
507 | if($sht(ipban=>$si)!=$null) | |
508 | { | |
509 | # ip is already blocked | |
510 | xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n"); | |
511 | exit; | |
512 | } | |
513 | if (!pike_check_req()) | |
514 | { | |
515 | xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n"); | |
516 | $sht(ipban=>$si) = 1; | |
517 | exit; | |
518 | } | |
519 | } | |
520 | #!endif | |
521 | ||
522 | if (!mf_process_maxfwd_header("10")) { | |
523 | sl_send_reply("483","Too Many Hops"); | |
524 | exit; | |
525 | } | |
526 | ||
527 | if(!sanity_check("1511", "7")) | |
528 | { | |
529 | xlog("Malformed SIP message from $si:$sp\n"); | |
530 | exit; | |
531 | } | |
532 | } | |
533 | ||
534 | # Handle requests within SIP dialogs | |
535 | route[WITHINDLG] { | |
536 | if (has_totag()) { | |
537 | # sequential request withing a dialog should | |
538 | # take the path determined by record-routing | |
539 | if (loose_route()) { | |
540 | route(DLGURI); | |
541 | if (is_method("BYE")) { | |
542 | setflag(FLT_ACC); # do accounting ... | |
543 | setflag(FLT_ACCFAILED); # ... even if the transaction fails | |
544 | } | |
545 | else if ( is_method("ACK") ) { | |
546 | # ACK is forwarded statelessy | |
547 | route(NATMANAGE); | |
548 | } | |
549 | else if ( is_method("NOTIFY") ) { | |
550 | # Add Record-Route for in-dialog NOTIFY as per RFC 6665. | |
551 | record_route(); | |
552 | } | |
553 | route(RELAY); | |
554 | } else { | |
555 | if (is_method("SUBSCRIBE") && uri == myself) { | |
556 | # in-dialog subscribe requests | |
557 | route(PRESENCE); | |
558 | exit; | |
559 | } | |
560 | if ( is_method("ACK") ) { | |
561 | if ( t_check_trans() ) { | |
562 | # no loose-route, but stateful ACK; | |
563 | # must be an ACK after a 487 | |
564 | # or e.g. 404 from upstream server | |
565 | t_relay(); | |
566 | exit; | |
567 | } else { | |
568 | # ACK without matching transaction ... ignore and discard | |
569 | exit; | |
570 | } | |
571 | } | |
572 | sl_send_reply("404","Not here"); | |
573 | } | |
574 | exit; | |
575 | } | |
576 | } | |
577 | ||
578 | # Handle SIP registrations | |
579 | route[REGISTRAR] { | |
580 | if (is_method("REGISTER")) | |
581 | { | |
582 | if(isflagset(FLT_NATS)) | |
583 | { | |
584 | setbflag(FLB_NATB); | |
585 | # uncomment next line to do SIP NAT pinging | |
586 | ## setbflag(FLB_NATSIPPING); | |
587 | } | |
588 | if (!save("location")) | |
589 | sl_reply_error(); | |
590 | ||
591 | exit; | |
592 | } | |
593 | } | |
594 | ||
595 | # USER location service | |
596 | route[LOCATION] { | |
597 | ||
598 | #!ifdef WITH_SPEEDDIAL | |
599 | # search for short dialing - 2-digit extension | |
600 | if($rU=~"^[0-9][0-9]$") | |
601 | if(sd_lookup("speed_dial")) | |
602 | route(SIPOUT); | |
603 | #!endif | |
604 | ||
605 | #!ifdef WITH_ALIASDB | |
606 | # search in DB-based aliases | |
607 | if(alias_db_lookup("dbaliases")) | |
608 | route(SIPOUT); | |
609 | #!endif | |
610 | ||
611 | $avp(oexten) = $rU; | |
612 | if (!lookup("location")) { | |
613 | $var(rc) = $rc; | |
614 | route(TOVOICEMAIL); | |
615 | t_newtran(); | |
616 | switch ($var(rc)) { | |
617 | case -1: | |
618 | case -3: | |
619 | send_reply("404", "Not Found"); | |
620 | exit; | |
621 | case -2: | |
622 | send_reply("405", "Method Not Allowed"); | |
623 | exit; | |
624 | } | |
625 | } | |
626 | ||
627 | # when routing via usrloc, log the missed calls also | |
628 | if (is_method("INVITE")) | |
629 | { | |
630 | setflag(FLT_ACCMISSED); | |
631 | } | |
632 | } | |
633 | ||
634 | # Presence server route | |
635 | route[PRESENCE] { | |
636 | if(!is_method("PUBLISH|SUBSCRIBE")) | |
637 | return; | |
638 | ||
639 | #!ifdef WITH_PRESENCE | |
640 | if (!t_newtran()) | |
641 | { | |
642 | sl_reply_error(); | |
643 | exit; | |
644 | }; | |
645 | ||
646 | if(is_method("PUBLISH")) | |
647 | { | |
648 | handle_publish(); | |
649 | t_release(); | |
650 | } | |
651 | else | |
652 | if( is_method("SUBSCRIBE")) | |
653 | { | |
654 | handle_subscribe(); | |
655 | t_release(); | |
656 | } | |
657 | exit; | |
658 | #!endif | |
659 | ||
660 | # if presence enabled, this part will not be executed | |
661 | if (is_method("PUBLISH") || $rU==$null) | |
662 | { | |
663 | sl_send_reply("404", "Not here"); | |
664 | exit; | |
665 | } | |
666 | return; | |
667 | } | |
668 | ||
669 | # Authentication route | |
670 | route[AUTH] { | |
671 | #!ifdef WITH_AUTH | |
672 | ||
673 | - | # jlee Freeswitch Integration |
673 | + | # limark Freeswitch Integration |
674 | #!ifdef WITH_FREESWITCH | |
675 | if(route(FSINBOUND)) | |
676 | return; | |
677 | #!endif | |
678 | ||
679 | ||
680 | #!ifdef WITH_IPAUTH | |
681 | if((!is_method("REGISTER")) && allow_source_address()) | |
682 | { | |
683 | # source IP allowed | |
684 | return; | |
685 | } | |
686 | #!endif | |
687 | ||
688 | if (is_method("REGISTER") || from_uri==myself) | |
689 | { | |
690 | # authenticate requests | |
691 | if (!auth_check("$fd", "subscriber", "1")) { | |
692 | auth_challenge("$fd", "0"); | |
693 | exit; | |
694 | } | |
695 | # user authenticated - remove auth header | |
696 | if(!is_method("REGISTER|PUBLISH")) | |
697 | consume_credentials(); | |
698 | } | |
699 | # if caller is not local subscriber, then check if it calls | |
700 | # a local destination, otherwise deny, not an open relay here | |
701 | if (from_uri!=myself && uri!=myself) | |
702 | { | |
703 | sl_send_reply("403","Not relaying"); | |
704 | exit; | |
705 | } | |
706 | ||
707 | #!endif | |
708 | return; | |
709 | } | |
710 | ||
711 | # Caller NAT detection route | |
712 | route[NATDETECT] { | |
713 | #!ifdef WITH_NAT | |
714 | force_rport(); | |
715 | if (nat_uac_test("19")) { | |
716 | if (is_method("REGISTER")) { | |
717 | fix_nated_register(); | |
718 | } else { | |
719 | add_contact_alias(); | |
720 | } | |
721 | setflag(FLT_NATS); | |
722 | } | |
723 | #!endif | |
724 | return; | |
725 | } | |
726 | ||
727 | # RTPProxy control | |
728 | route[NATMANAGE] { | |
729 | #!ifdef WITH_NAT | |
730 | if (is_request()) { | |
731 | if(has_totag()) { | |
732 | if(check_route_param("nat=yes")) { | |
733 | setbflag(FLB_NATB); | |
734 | } | |
735 | } | |
736 | } | |
737 | if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) | |
738 | return; | |
739 | ||
740 | rtpproxy_manage(); | |
741 | ||
742 | if (is_request()) { | |
743 | if (!has_totag()) { | |
744 | add_rr_param(";nat=yes"); | |
745 | } | |
746 | } | |
747 | if (is_reply()) { | |
748 | if(isbflagset(FLB_NATB)) { | |
749 | add_contact_alias(); | |
750 | } | |
751 | } | |
752 | #!endif | |
753 | return; | |
754 | } | |
755 | ||
756 | # URI update for dialog requests | |
757 | route[DLGURI] { | |
758 | #!ifdef WITH_NAT | |
759 | if(!isdsturiset()) { | |
760 | handle_ruri_alias(); | |
761 | } | |
762 | #!endif | |
763 | return; | |
764 | } | |
765 | ||
766 | # Routing to foreign domains | |
767 | route[SIPOUT] { | |
768 | if (!uri==myself) | |
769 | { | |
770 | append_hf("P-hint: outbound\r\n"); | |
771 | route(RELAY); | |
772 | } | |
773 | } | |
774 | ||
775 | # PSTN GW routing | |
776 | route[PSTN] { | |
777 | #!ifdef WITH_PSTN | |
778 | # check if PSTN GW IP is defined | |
779 | if (strempty($sel(cfg_get.pstn.gw_ip))) { | |
780 | xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n"); | |
781 | return; | |
782 | } | |
783 | ||
784 | # route to PSTN dialed numbers starting with '+' or '00' | |
785 | # (international format) | |
786 | # - update the condition to match your dialing rules for PSTN routing | |
787 | if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$")) | |
788 | return; | |
789 | ||
790 | # only local users allowed to call | |
791 | if(from_uri!=myself) { | |
792 | sl_send_reply("403", "Not Allowed"); | |
793 | exit; | |
794 | } | |
795 | ||
796 | if (strempty($sel(cfg_get.pstn.gw_port))) { | |
797 | $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip); | |
798 | } else { | |
799 | $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":" | |
800 | + $sel(cfg_get.pstn.gw_port); | |
801 | } | |
802 | ||
803 | route(RELAY); | |
804 | exit; | |
805 | #!endif | |
806 | ||
807 | return; | |
808 | } | |
809 | ||
810 | # XMLRPC routing | |
811 | #!ifdef WITH_XMLRPC | |
812 | route[XMLRPC] { | |
813 | # allow XMLRPC from localhost | |
814 | if ((method=="POST" || method=="GET") | |
815 | && (src_ip==127.0.0.1)) { | |
816 | # close connection only for xmlrpclib user agents (there is a bug in | |
817 | # xmlrpclib: it waits for EOF before interpreting the response). | |
818 | if ($hdr(User-Agent) =~ "xmlrpclib") | |
819 | set_reply_close(); | |
820 | set_reply_no_connect(); | |
821 | dispatch_rpc(); | |
822 | exit; | |
823 | } | |
824 | send_reply("403", "Forbidden"); | |
825 | exit; | |
826 | } | |
827 | #!endif | |
828 | ||
829 | - | # jlee Freeswitch Integration |
829 | + | # limark Freeswitch Integration |
830 | #!ifdef WITH_FREESWITCH | |
831 | # FreeSWITCH routing blocks | |
832 | route[FSINBOUND] { | |
833 | if($si== $sel(cfg_get.freeswitch.bindip) | |
834 | && $sp==$sel(cfg_get.freeswitch.bindport)) | |
835 | return 1; | |
836 | return -1; | |
837 | } | |
838 | ||
839 | route[FSDISPATCH] { | |
840 | if(!is_method("INVITE")) | |
841 | return; | |
842 | if(route(FSINBOUND)) | |
843 | return; | |
844 | ||
845 | # dial number selection | |
846 | switch($rU) { | |
847 | case /"^41$": | |
848 | # 41 - voicebox menu | |
849 | # allow only authenticated users | |
850 | if($au==$null) | |
851 | { | |
852 | sl_send_reply("403", "Not allowed"); | |
853 | exit; | |
854 | } | |
855 | $rU = "vm-" + $au; | |
856 | break; | |
857 | case /"^441[0-9][0-9]$": | |
858 | # starting with 44 folowed by 1XY - direct call to voice box | |
859 | strip(2); | |
860 | route(FSVBOX); | |
861 | break; | |
862 | case /"^433[01][0-9][0-9]$": | |
863 | # starting with 433 folowed by (0|1)XY - conference | |
864 | strip(2); | |
865 | break; | |
866 | case /"^45[0-9]+$": | |
867 | strip(2); | |
868 | break; | |
869 | default: | |
870 | # offline - send to voicebox | |
871 | if (!registered("location")) | |
872 | { | |
873 | route(FSVBOX); | |
874 | exit; | |
875 | } | |
876 | # online - do bridging | |
877 | prefix("kb-"); | |
878 | if(is_method("INVITE")) | |
879 | { | |
880 | # in case of failure - re-route to FreeSWITCH VoiceMail | |
881 | t_on_failure("FAIL_FSVBOX"); | |
882 | } | |
883 | } | |
884 | route(FSRELAY); | |
885 | exit; | |
886 | } | |
887 | ||
888 | route[FSVBOX] { | |
889 | if(!($rU=~"^1[0-9][0-9]+$")) | |
890 | return; | |
891 | prefix("vb-"); | |
892 | route(FSRELAY); | |
893 | } | |
894 | ||
895 | # Send to FreeSWITCH | |
896 | route[FSRELAY] { | |
897 | $du = "sip:" + $sel(cfg_get.freeswitch.bindip) + ":" | |
898 | + $sel(cfg_get.freeswitch.bindport); | |
899 | if($var(newbranch)==1) | |
900 | { | |
901 | append_branch(); | |
902 | $var(newbranch) = 0; | |
903 | } | |
904 | route(RELAY); | |
905 | exit; | |
906 | } | |
907 | ||
908 | #!endif | |
909 | - | # jlee Freeswitch Integration stop |
909 | + | # limark Freeswitch Integration stop |
910 | ||
911 | ||
912 | # route to voicemail server | |
913 | route[TOVOICEMAIL] { | |
914 | #!ifdef WITH_VOICEMAIL | |
915 | if(!is_method("INVITE")) | |
916 | return; | |
917 | ||
918 | # check if VoiceMail server IP is defined | |
919 | if (strempty($sel(cfg_get.voicemail.srv_ip))) { | |
920 | xlog("SCRIPT: VoiceMail rotuing enabled but IP not defined\n"); | |
921 | return; | |
922 | } | |
923 | if($avp(oexten)==$null) | |
924 | return; | |
925 | ||
926 | $ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip) | |
927 | + ":" + $sel(cfg_get.voicemail.srv_port); | |
928 | route(RELAY); | |
929 | exit; | |
930 | #!endif | |
931 | ||
932 | return; | |
933 | } | |
934 | ||
935 | # manage outgoing branches | |
936 | branch_route[MANAGE_BRANCH] { | |
937 | xdbg("new branch [$T_branch_idx] to $ru\n"); | |
938 | route(NATMANAGE); | |
939 | } | |
940 | ||
941 | # manage incoming replies | |
942 | onreply_route[MANAGE_REPLY] { | |
943 | xdbg("incoming reply\n"); | |
944 | if(status=~"[12][0-9][0-9]") | |
945 | route(NATMANAGE); | |
946 | } | |
947 | ||
948 | # manage failure routing cases | |
949 | failure_route[MANAGE_FAILURE] { | |
950 | route(NATMANAGE); | |
951 | ||
952 | if (t_is_canceled()) { | |
953 | exit; | |
954 | } | |
955 | ||
956 | #!ifdef WITH_BLOCK3XX | |
957 | # block call redirect based on 3xx replies. | |
958 | if (t_check_status("3[0-9][0-9]")) { | |
959 | t_reply("404","Not found"); | |
960 | exit; | |
961 | } | |
962 | #!endif | |
963 | ||
964 | #!ifdef WITH_VOICEMAIL | |
965 | # serial forking | |
966 | # - route to voicemail on busy or no answer (timeout) | |
967 | if (t_check_status("486|408")) { | |
968 | route(TOVOICEMAIL); | |
969 | exit; | |
970 | } | |
971 | #!endif | |
972 | } | |
973 | ||
974 | #!ifdef WITH_XHTTP | |
975 | event_route[xhttp:request] { | |
976 | #!ifdef WITH_XHTTP_RPC | |
977 | $var(xhttp_rpc_root) = $(hu{s.substr,0,9}); | |
978 | if ($var(xhttp_rpc_root) == "/http_rpc") { | |
979 | dispatch_xhttp_rpc(); | |
980 | } | |
981 | #!endif | |
982 | #!ifdef WITH_XHTTP_PI | |
983 | $var(xhttp_rpc_root) = $(hu{s.substr,0,8}); | |
984 | if ($var(xhttp_rpc_root) == "/http_pi") { | |
985 | dispatch_xhttp_pi(); | |
986 | } | |
987 | #!endif | |
988 | xhttp_reply("200", "OK", "text/html", | |
989 | "<html><body>Wrong URL $hu</body></html>"); | |
990 | } | |
991 | #!endif |