Advertisement
cmaass

kamailio.cfg

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