kamailio_cassa.cfg 18 KB

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