Advertisement
Guest User

kamailio.cfg

a guest
Oct 5th, 2011
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.95 KB | None | 0 0
  1. #!KAMAILIO
  2. #
  3. # Kamailio (OpenSER) SIP Server v3.1 - default configuration script
  4. # - web: http://www.kamailio.org
  5. # - git: http://sip-router.org
  6. #
  7. # Direct your questions about this file to: <[email protected]>
  8. #
  9. # Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php
  10. # for an explanation of possible statements, functions and parameters.
  11. #
  12. # Several features can be enabled using '#!define WITH_FEATURE' directives:
  13. #
  14. # *** To run in debug mode:
  15. # - define WITH_DEBUG
  16. #
  17. # *** To enable mysql:
  18. # - define WITH_MYSQL
  19. #
  20. # *** To enable authentication execute:
  21. # - enable mysql
  22. # - define WITH_AUTH
  23. # - add users using 'kamctl'
  24. #
  25. # *** To enable IP authentication execute:
  26. # - enable mysql
  27. # - enable authentication
  28. # - define WITH_IPAUTH
  29. # - add IP addresses with group id '1' to 'address' table
  30. #
  31. # *** To enable persistent user location execute:
  32. # - enable mysql
  33. # - define WITH_USRLOCDB
  34. #
  35. # *** To enable presence server execute:
  36. # - enable mysql
  37. # - define WITH_PRESENCE
  38. #
  39. # *** To enable nat traversal execute:
  40. # - define WITH_NAT
  41. # - install RTPProxy: http://www.rtpproxy.org
  42. # - start RTPProxy:
  43. # rtpproxy -l _your_public_ip_ -s udp:localhost:7722
  44. #
  45. # *** To enable PSTN gateway routing execute:
  46. # - define WITH_PSTN
  47. # - set the value of pstn.gw_ip
  48. # - check route[PSTN] for regexp routing condition
  49. #
  50. # *** To enable database aliases lookup execute:
  51. # - enable mysql
  52. # - define WITH_ALIASDB
  53. #
  54. # *** To enable multi-domain support execute:
  55. # - enable mysql
  56. # - define WITH_MULTIDOMAIN
  57. #
  58. # *** To enable TLS support execute:
  59. # - adjust CFGDIR/tls.cfg as needed
  60. # - define WITH_TLS
  61. #
  62. # *** To enable XMLRPC support execute:
  63. # - define WITH_XMLRPC
  64. # - adjust route[XMLRPC] for access policy
  65. #
  66. # *** To enable anti-flood detection execute:
  67. # - adjust pike and htable=>ipban settings as needed (default is
  68. # block if more than 16 requests in 2 seconds and ban for 300 seconds)
  69. # - define WITH_ANTIFLOOD
  70. #
  71. # *** To enhance accounting execute:
  72. # - enable mysql
  73. # - define WITH_ACCDB
  74. # - add following columns to database
  75. #!ifdef ACCDB_COMMENT
  76. ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  77. ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  78. ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  79. ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  80. ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  81. ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  82. ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  83. ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  84. ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  85. ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  86. #!endif
  87.  
  88. ####### Defined Values #########
  89.  
  90. # *** Value defines - IDs used later in config
  91. #!ifdef WITH_MYSQL
  92. # - database URL - used to connect to database server by modules such
  93. # as: auth_db, acc, usrloc, a.s.o.
  94. #!define DBURL "mysql://openser:openserrw@localhost/openser"
  95. #!endif
  96. #!ifdef WITH_MULTIDOMAIN
  97. # - the value for 'use_domain' parameters
  98. #!define MULTIDOMAIN 1
  99. #!else
  100. #!define MULTIDOMAIN 0
  101. #!endif
  102.  
  103. # - flags
  104. # FLT_ - per transaction (message) flags
  105. # FLB_ - per branch flags
  106. #!define FLT_ACC 1
  107. #!define FLT_ACCMISSED 2
  108. #!define FLT_ACCFAILED 3
  109. #!define FLT_NATS 5
  110.  
  111. #!define FLB_NATB 6
  112. #!define FLB_NATSIPPING 7
  113.  
  114. ####### Global Parameters #########
  115.  
  116. #!ifdef WITH_DEBUG
  117. debug=4
  118. log_stderror=yes
  119. #!else
  120. debug=2
  121. log_stderror=no
  122. #!endif
  123.  
  124. memdbg=5
  125. memlog=5
  126.  
  127. log_facility=LOG_LOCAL0
  128.  
  129. fork=yes
  130. children=4
  131.  
  132. /* uncomment the next line to disable TCP (default on) */
  133. #disable_tcp=yes
  134.  
  135. /* uncomment the next line to disable the auto discovery of local aliases
  136. based on reverse DNS on IPs (default on) */
  137. #auto_aliases=no
  138.  
  139. /* add local domain aliases */
  140. #alias="sip.mydomain.com"
  141.  
  142. /* uncomment and configure the following line if you want Kamailio to
  143. bind on a specific interface/port/proto (default bind on all available) */
  144. #listen=udp:10.0.0.10:5060
  145.  
  146. /* port to listen to
  147. * - can be specified more than once if needed to listen on many ports */
  148. port=5060
  149.  
  150. #!ifdef WITH_TLS
  151. enable_tls=yes
  152. #!endif
  153.  
  154. ####### Custom Parameters #########
  155.  
  156. # These parameters can be modified runtime via RPC interface
  157. # - see the documentation of 'cfg_rpc' module.
  158. #
  159. # Format: group.id = value 'desc' description
  160. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  161. #
  162.  
  163. #!ifdef WITH_PSTN
  164. # PSTN GW Routing
  165. #
  166. # - pstn.gw_ip: valid IP or hostname as string value, example:
  167. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  168. #
  169. # - by default is empty to avoid misrouting
  170. pstn.gw_ip = "" desc "PSTN GW Address"
  171. #!endif
  172.  
  173.  
  174. ####### Modules Section ########
  175.  
  176. # set paths to location of modules
  177. #!ifdef LOCAL_TEST_RUN
  178. mpath="modules_k:modules"
  179. #!else
  180. mpath="/usr/local/lib64/kamailio/modules_k/:/usr/local/lib64/kamailio/modules/"
  181. #!endif
  182.  
  183. #!ifdef WITH_MYSQL
  184. loadmodule "db_mysql.so"
  185. #!endif
  186.  
  187. loadmodule "mi_fifo.so"
  188. loadmodule "kex.so"
  189. loadmodule "tm.so"
  190. loadmodule "tmx.so"
  191. loadmodule "sl.so"
  192. loadmodule "rr.so"
  193. loadmodule "pv.so"
  194. loadmodule "maxfwd.so"
  195. loadmodule "usrloc.so"
  196. loadmodule "registrar.so"
  197. loadmodule "textops.so"
  198. loadmodule "siputils.so"
  199. loadmodule "xlog.so"
  200. loadmodule "sanity.so"
  201. loadmodule "ctl.so"
  202. loadmodule "mi_rpc.so"
  203. loadmodule "acc.so"
  204.  
  205. #!ifdef WITH_AUTH
  206. loadmodule "auth.so"
  207. loadmodule "auth_db.so"
  208. #!ifdef WITH_IPAUTH
  209. loadmodule "permissions.so"
  210. #!endif
  211. #!endif
  212.  
  213. #!ifdef WITH_ALIASDB
  214. loadmodule "alias_db.so"
  215. #!endif
  216.  
  217. #!ifdef WITH_MULTIDOMAIN
  218. loadmodule "domain.so"
  219. #!endif
  220.  
  221. #!ifdef WITH_PRESENCE
  222. loadmodule "presence.so"
  223. loadmodule "presence_xml.so"
  224. #!endif
  225.  
  226. #!ifdef WITH_NAT
  227. loadmodule "nathelper.so"
  228. loadmodule "rtpproxy.so"
  229. #!endif
  230.  
  231. #!ifdef WITH_TLS
  232. loadmodule "tls.so"
  233. #!endif
  234.  
  235. #!ifdef WITH_ANTIFLOOD
  236. loadmodule "htable.so"
  237. loadmodule "pike.so"
  238. #!endif
  239.  
  240. #!ifdef WITH_XMLRPC
  241. loadmodule "xmlrpc.so"
  242. #!endif
  243.  
  244. # ----------------- setting module-specific parameters ---------------
  245.  
  246.  
  247. # ----- mi_fifo params -----
  248. modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
  249.  
  250.  
  251. # ----- tm params -----
  252. # auto-discard branches from previous serial forking leg
  253. modparam("tm", "failure_reply_mode", 3)
  254. # default retransmission timeout: 30sec
  255. modparam("tm", "fr_timer", 30000)
  256. # default invite retransmission timeout after 1xx: 120sec
  257. modparam("tm", "fr_inv_timer", 120000)
  258.  
  259.  
  260. # ----- rr params -----
  261. # add value to ;lr param to cope with most of the UAs
  262. modparam("rr", "enable_full_lr", 1)
  263. # do not append from tag to the RR (no need for this script)
  264. modparam("rr", "append_fromtag", 0)
  265.  
  266.  
  267. # ----- registrar params -----
  268. modparam("registrar", "method_filtering", 1)
  269. /* uncomment the next line to disable parallel forking via location */
  270. # modparam("registrar", "append_branches", 0)
  271. /* uncomment the next line not to allow more than 10 contacts per AOR */
  272. #modparam("registrar", "max_contacts", 10)
  273.  
  274.  
  275. # ----- acc params -----
  276. /* what special events should be accounted ? */
  277. modparam("acc", "early_media", 0)
  278. modparam("acc", "report_ack", 0)
  279. modparam("acc", "report_cancels", 0)
  280. /* by default ww do not adjust the direct of the sequential requests.
  281. if you enable this parameter, be sure the enable "append_fromtag"
  282. in "rr" module */
  283. modparam("acc", "detect_direction", 0)
  284. /* account triggers (flags) */
  285. modparam("acc", "log_flag", FLT_ACC)
  286. modparam("acc", "log_missed_flag", FLT_ACCMISSED)
  287. modparam("acc", "log_extra",
  288. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  289. modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
  290. /* enhanced DB accounting */
  291. #!ifdef WITH_ACCDB
  292. modparam("acc", "db_flag", FLT_ACC)
  293. modparam("acc", "db_missed_flag", FLT_ACCMISSED)
  294. modparam("acc", "db_url", DBURL)
  295. modparam("acc", "db_extra",
  296. "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
  297. #!endif
  298.  
  299.  
  300. # ----- usrloc params -----
  301. /* enable DB persistency for location entries */
  302. #!ifdef WITH_USRLOCDB
  303. modparam("usrloc", "db_url", DBURL)
  304. modparam("usrloc", "db_mode", 2)
  305. modparam("usrloc", "use_domain", MULTIDOMAIN)
  306. #!endif
  307.  
  308.  
  309. # ----- auth_db params -----
  310. #!ifdef WITH_AUTH
  311. modparam("auth_db", "db_url", DBURL)
  312. modparam("auth_db", "calculate_ha1", yes)
  313. modparam("auth_db", "password_column", "password")
  314. modparam("auth_db", "load_credentials", "")
  315. modparam("auth_db", "use_domain", MULTIDOMAIN)
  316.  
  317. # ----- permissions params -----
  318. #!ifdef WITH_IPAUTH
  319. modparam("permissions", "db_url", DBURL)
  320. modparam("permissions", "db_mode", 1)
  321. #!endif
  322.  
  323. #!endif
  324.  
  325.  
  326. # ----- alias_db params -----
  327. #!ifdef WITH_ALIASDB
  328. modparam("alias_db", "db_url", DBURL)
  329. modparam("alias_db", "use_domain", MULTIDOMAIN)
  330. #!endif
  331.  
  332.  
  333. # ----- domain params -----
  334. #!ifdef WITH_MULTIDOMAIN
  335. modparam("domain", "db_url", DBURL)
  336. # use caching
  337. modparam("domain", "db_mode", 1)
  338. # register callback to match myself condition with domains list
  339. modparam("domain", "register_myself", 1)
  340. #!endif
  341.  
  342.  
  343. #!ifdef WITH_PRESENCE
  344. # ----- presence params -----
  345. modparam("presence", "db_url", DBURL)
  346.  
  347. # ----- presence_xml params -----
  348. modparam("presence_xml", "db_url", DBURL)
  349. modparam("presence_xml", "force_active", 1)
  350. #!endif
  351.  
  352.  
  353. #!ifdef WITH_NAT
  354. # ----- rtpproxy params -----
  355. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  356.  
  357. # ----- nathelper params -----
  358. modparam("nathelper", "natping_interval", 30)
  359. modparam("nathelper", "ping_nated_only", 1)
  360. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  361. modparam("nathelper", "sipping_from", "sip:[email protected]")
  362.  
  363. # params needed for NAT traversal in other modules
  364. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  365. modparam("usrloc", "nat_bflag", FLB_NATB)
  366. #!endif
  367.  
  368.  
  369. #!ifdef WITH_TLS
  370. # ----- tls params -----
  371. modparam("tls", "config", "/usr/local/etc/kamailio/tls.cfg")
  372. #!endif
  373.  
  374. #!ifdef WITH_ANTIFLOOD
  375. # ----- pike params -----
  376. modparam("pike", "sampling_time_unit", 2)
  377. modparam("pike", "reqs_density_per_unit", 16)
  378. modparam("pike", "remove_latency", 4)
  379.  
  380. # ----- htable params -----
  381. # ip ban htable with autoexpire after 5 minutes
  382. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  383. #!endif
  384.  
  385. #!ifdef WITH_XMLRPC
  386. # ----- xmlrpc params -----
  387. modparam("xmlrpc", "route", "XMLRPC");
  388. modparam("xmlrpc", "url_match", "^/RPC")
  389. #!endif
  390.  
  391. ####### Routing Logic ########
  392.  
  393.  
  394. # Main SIP request routing logic
  395. # - processing of any incoming SIP request starts with this route
  396. route {
  397.  
  398. # per request initial checks
  399. route(REQINIT);
  400.  
  401. # NAT detection
  402. route(NAT);
  403.  
  404. # handle requests within SIP dialogs
  405. route(WITHINDLG);
  406.  
  407. ### only initial requests (no To tag)
  408.  
  409. # CANCEL processing
  410. if (is_method("CANCEL"))
  411. {
  412. if (t_check_trans())
  413. t_relay();
  414. exit;
  415. }
  416.  
  417. t_check_trans();
  418.  
  419. # authentication
  420. route(AUTH);
  421.  
  422. # record routing for dialog forming requests (in case they are routed)
  423. # - remove preloaded route headers
  424. remove_hf("Route");
  425. if (is_method("INVITE|SUBSCRIBE"))
  426. record_route();
  427.  
  428. # account only INVITEs
  429. if (is_method("INVITE"))
  430. {
  431. setflag(FLT_ACC); # do accounting
  432. }
  433.  
  434. # dispatch requests to foreign domains
  435. route(SIPOUT);
  436.  
  437. ### requests for my local domains
  438.  
  439. # handle presence related requests
  440. route(PRESENCE);
  441.  
  442. # handle registrations
  443. route(REGISTRAR);
  444.  
  445. if ($rU==$null)
  446. {
  447. # request with no Username in RURI
  448. sl_send_reply("484","Address Incomplete");
  449. exit;
  450. }
  451.  
  452. # dispatch destinations to PSTN
  453. route(PSTN);
  454.  
  455. # user location service
  456. route(LOCATION);
  457.  
  458. route(RELAY);
  459. }
  460.  
  461.  
  462. route[RELAY] {
  463. #!ifdef WITH_NAT
  464. if (check_route_param("nat=yes")) {
  465. setbflag(FLB_NATB);
  466. }
  467. if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
  468. route(RTPPROXY);
  469. }
  470. #!endif
  471.  
  472. /* example how to enable some additional event routes */
  473. if (is_method("INVITE")) {
  474. #t_on_branch("BRANCH_ONE");
  475. t_on_reply("REPLY_ONE");
  476. t_on_failure("FAIL_ONE");
  477. }
  478.  
  479. if (!t_relay()) {
  480. sl_reply_error();
  481. }
  482. exit;
  483. }
  484.  
  485. # Per SIP request initial checks
  486. route[REQINIT] {
  487. #!ifdef WITH_ANTIFLOOD
  488. # flood dection from same IP and traffic ban for a while
  489. # be sure you exclude checking trusted peers, such as pstn gateways
  490. # - local host excluded (e.g., loop to self)
  491. if(src_ip!=myself)
  492. {
  493. if($sht(ipban=>$si)!=$null)
  494. {
  495. # ip is already blocked
  496. xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  497. exit;
  498. }
  499. if (!pike_check_req())
  500. {
  501. xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  502. $sht(ipban=>$si) = 1;
  503. exit;
  504. }
  505. }
  506. #!endif
  507.  
  508. if (!mf_process_maxfwd_header("10")) {
  509. sl_send_reply("483","Too Many Hops");
  510. exit;
  511. }
  512.  
  513. if(!sanity_check("1511", "7"))
  514. {
  515. xlog("Malformed SIP message from $si:$sp\n");
  516. exit;
  517. }
  518. }
  519.  
  520. # Handle requests within SIP dialogs
  521. route[WITHINDLG] {
  522. if (has_totag()) {
  523. # sequential request withing a dialog should
  524. # take the path determined by record-routing
  525. if (loose_route()) {
  526. if (is_method("BYE")) {
  527. setflag(FLT_ACC); # do accounting ...
  528. setflag(FLT_ACCFAILED); # ... even if the transaction fails
  529. }
  530. route(RELAY);
  531. } else {
  532. if (is_method("SUBSCRIBE") && uri == myself) {
  533. # in-dialog subscribe requests
  534. route(PRESENCE);
  535. exit;
  536. }
  537. if ( is_method("ACK") ) {
  538. if ( t_check_trans() ) {
  539. # no loose-route, but stateful ACK;
  540. # must be an ACK after a 487
  541. # or e.g. 404 from upstream server
  542. t_relay();
  543. exit;
  544. } else {
  545. # ACK without matching transaction ... ignore and discard
  546. exit;
  547. }
  548. }
  549. sl_send_reply("404","Not here");
  550. }
  551. exit;
  552. }
  553. }
  554.  
  555. # Handle SIP registrations
  556. route[REGISTRAR] {
  557. if (is_method("REGISTER"))
  558. {
  559. if(isflagset(FLT_NATS))
  560. {
  561. setbflag(FLB_NATB);
  562. # uncomment next line to do SIP NAT pinging
  563. ## setbflag(FLB_NATSIPPING);
  564. }
  565. if (!save("location"))
  566. sl_reply_error();
  567.  
  568. exit;
  569. }
  570. }
  571.  
  572. # USER location service
  573. route[LOCATION] {
  574.  
  575. #!ifdef WITH_ALIASDB
  576. # search in DB-based aliases
  577. alias_db_lookup("dbaliases");
  578. #!endif
  579.  
  580. if (!lookup("location")) {
  581. switch ($rc) {
  582. case -1:
  583. case -3:
  584. t_newtran();
  585. t_reply("404", "Not Found");
  586. exit;
  587. case -2:
  588. sl_send_reply("405", "Method Not Allowed");
  589. exit;
  590. }
  591. }
  592.  
  593. # when routing via usrloc, log the missed calls also
  594. if (is_method("INVITE"))
  595. {
  596. setflag(FLT_ACCMISSED);
  597. }
  598. }
  599.  
  600. # Presence server route
  601. route[PRESENCE] {
  602. if(!is_method("PUBLISH|SUBSCRIBE"))
  603. return;
  604.  
  605. #!ifdef WITH_PRESENCE
  606. if (!t_newtran())
  607. {
  608. sl_reply_error();
  609. exit;
  610. };
  611.  
  612. if(is_method("PUBLISH"))
  613. {
  614. handle_publish();
  615. t_release();
  616. }
  617. else
  618. if( is_method("SUBSCRIBE"))
  619. {
  620. handle_subscribe();
  621. t_release();
  622. }
  623. exit;
  624. #!endif
  625.  
  626. # if presence enabled, this part will not be executed
  627. if (is_method("PUBLISH") || $rU==$null)
  628. {
  629. sl_send_reply("404", "Not here");
  630. exit;
  631. }
  632. return;
  633. }
  634.  
  635. # Authentication route
  636. route[AUTH] {
  637. #!ifdef WITH_AUTH
  638. if (is_method("REGISTER"))
  639. {
  640. # authenticate the REGISTER requests (uncomment to enable auth)
  641. if (!www_authorize("$td", "subscriber"))
  642. {
  643. www_challenge("$td", "0");
  644. exit;
  645. }
  646.  
  647. if ($au!=$tU)
  648. {
  649. sl_send_reply("403","Forbidden auth ID");
  650. exit;
  651. }
  652. } else {
  653.  
  654. #!ifdef WITH_IPAUTH
  655. if(allow_source_address())
  656. {
  657. # source IP allowed
  658. return;
  659. }
  660. #!endif
  661.  
  662. # authenticate if from local subscriber
  663. if (from_uri==myself)
  664. {
  665. if (!proxy_authorize("$fd", "subscriber")) {
  666. proxy_challenge("$fd", "0");
  667. exit;
  668. }
  669. if (is_method("PUBLISH"))
  670. {
  671. if ($au!=$tU) {
  672. sl_send_reply("403","Forbidden auth ID");
  673. exit;
  674. }
  675. } else {
  676. if ($au!=$fU) {
  677. sl_send_reply("403","Forbidden auth ID");
  678. exit;
  679. }
  680. }
  681.  
  682. consume_credentials();
  683. # caller authenticated
  684. } else {
  685. # caller is not local subscriber, then check if it calls
  686. # a local destination, otherwise deny, not an open relay here
  687. if (!uri==myself)
  688. {
  689. sl_send_reply("403","Not relaying");
  690. exit;
  691. }
  692. }
  693. }
  694. #!endif
  695. return;
  696. }
  697.  
  698. # Caller NAT detection route
  699. route[NAT] {
  700. #!ifdef WITH_NAT
  701. force_rport();
  702. if (nat_uac_test("19")) {
  703. if (method=="REGISTER") {
  704. fix_nated_register();
  705. } else {
  706. fix_nated_contact();
  707. }
  708. setflag(FLT_NATS);
  709. }
  710. #!endif
  711. return;
  712. }
  713.  
  714. # RTPProxy control
  715. route[RTPPROXY] {
  716. #!ifdef WITH_NAT
  717. if (is_method("BYE")) {
  718. unforce_rtp_proxy();
  719. } else if (is_method("INVITE")){
  720. force_rtp_proxy();
  721. }
  722. if (!has_totag()) add_rr_param(";nat=yes");
  723. #!endif
  724. return;
  725. }
  726.  
  727. # Routing to foreign domains
  728. route[SIPOUT] {
  729. if (!uri==myself)
  730. {
  731. append_hf("P-hint: outbound\r\n");
  732. route(RELAY);
  733. }
  734. }
  735.  
  736. # PSTN GW routing
  737. route[PSTN] {
  738. #!ifdef WITH_PSTN
  739. # check if PSTN GW IP is defined
  740. if (strempty($sel(cfg_get.pstn.gw_ip))) {
  741. xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");
  742. return;
  743. }
  744.  
  745. # route to PSTN dialed numbers starting with '+' or '00'
  746. # (international format)
  747. # - update the condition to match your dialing rules for PSTN routing
  748. if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))
  749. return;
  750.  
  751. # only local users allowed to call
  752. if(from_uri!=myself) {
  753. sl_send_reply("403", "Not Allowed");
  754. exit;
  755. }
  756.  
  757. $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
  758.  
  759. route(RELAY);
  760. exit;
  761. #!endif
  762.  
  763. return;
  764. }
  765.  
  766. # XMLRPC routing
  767. #!ifdef WITH_XMLRPC
  768. route[XMLRPC]
  769. {
  770. # allow XMLRPC from localhost
  771. if ((method=="POST" || method=="GET")
  772. && (src_ip==127.0.0.1)) {
  773. # close connection only for xmlrpclib user agents (there is a bug in
  774. # xmlrpclib: it waits for EOF before interpreting the response).
  775. if ($hdr(User-Agent) =~ "xmlrpclib")
  776. set_reply_close();
  777. set_reply_no_connect();
  778. dispatch_rpc();
  779. exit;
  780. }
  781. send_reply("403", "Forbidden");
  782. exit;
  783. }
  784. #!endif
  785.  
  786. # Sample branch router
  787. branch_route[BRANCH_ONE] {
  788. xdbg("new branch at $ru\n");
  789. }
  790.  
  791. # Sample onreply route
  792. onreply_route[REPLY_ONE] {
  793. xdbg("incoming reply\n");
  794. #!ifdef WITH_NAT
  795. if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
  796. && status=~"(183)|(2[0-9][0-9])") {
  797. force_rtp_proxy();
  798. }
  799. if (isbflagset(FLB_NATB)) {
  800. fix_nated_contact();
  801. }
  802. #!endif
  803. }
  804.  
  805. # Sample failure route
  806. failure_route[FAIL_ONE] {
  807. #!ifdef WITH_NAT
  808. if (is_method("INVITE")
  809. && (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {
  810. unforce_rtp_proxy();
  811. }
  812. #!endif
  813.  
  814. if (t_is_canceled()) {
  815. exit;
  816. }
  817.  
  818. # uncomment the following lines if you want to block client
  819. # redirect based on 3xx replies.
  820. ##if (t_check_status("3[0-9][0-9]")) {
  821. ##t_reply("404","Not found");
  822. ## exit;
  823. ##}
  824.  
  825. # uncomment the following lines if you want to redirect the failed
  826. # calls to a different new destination
  827. ##if (t_check_status("486|408")) {
  828. ## sethostport("192.168.2.100:5060");
  829. ## append_branch();
  830. ## # do not set the missed call flag again
  831. ## t_relay();
  832. ##}
  833. }
  834.  
  835.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement