Advertisement
Guest User

Untitled

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