Wednesday 16 July 2014

Opensips.cfg with Presence server and with Xcap support | Kamalio.cfg with presence server Implementation and Xcap Support

By vm  |  22:43 No comments

  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: <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 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 anti-flood detection execute:
  63. #     - adjust pike and htable=>ipban settings as needed (default is
  64. #       block if more than 16 requests in 2 seconds and ban for 300 seconds)
  65. #     - define WITH_ANTIFLOOD
  66. #
  67. # *** To enhance accounting execute:
  68. #     - enable mysql
  69. #     - define WITH_ACCDB
  70. #     - add following columns to database
  71. #!ifdef ACCDB_COMMENT
  72.   ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  73.   ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  74.   ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  75.   ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  76.   ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  77.   ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
  78.   ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
  79.   ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
  80.   ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
  81.   ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
  82. #!endif
  83.  
  84. ####### Defined Values #########
  85. #!define WITH_MYSQL
  86. #!define WITH_AUTH
  87. #!define WITH_PRESENCE
  88. #!define WITH_XCAPSRV
  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. tcp_connection_lifetime=3604
  155.  
  156. #!ifdef WITH_XCAPSRV
  157. tcp_accept_no_cl=yes
  158. #!endif
  159.  
  160. ####### Custom Parameters #########
  161.  
  162. # These parameters can be modified runtime via RPC interface
  163. # - see the documentation of 'cfg_rpc' module.
  164. #
  165. # Format: group.id = value 'desc' description
  166. # Access: $sel(cfg_get.group.id) or @cfg_get.group.id
  167. #
  168.  
  169. #!ifdef WITH_PSTN
  170. # PSTN GW Routing
  171. #
  172. # - pstn.gw_ip: valid IP or hostname as string value, example:
  173. # pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
  174. #
  175. # - by default is empty to avoid misrouting
  176. pstn.gw_ip = "" desc "PSTN GW Address"
  177. #!endif
  178.  
  179.  
  180. ####### Modules Section ########
  181.  
  182. # set paths to location of modules
  183. #!ifdef LOCAL_TEST_RUN
  184. mpath="modules_k:modules"
  185. #!else
  186. mpath="/usr/local/kamailio-3.1-xcap/lib/kamailio/modules_k/:/usr/local/kamailio-3.1-xcap/lib/kamailio/modules/"
  187. #!endif
  188.  
  189. #!ifdef WITH_MYSQL
  190. loadmodule "db_mysql.so"
  191. #!endif
  192.  
  193. loadmodule "mi_fifo.so"
  194. loadmodule "kex.so"
  195. loadmodule "tm.so"
  196. loadmodule "tmx.so"
  197. loadmodule "sl.so"
  198. loadmodule "rr.so"
  199. loadmodule "pv.so"
  200. loadmodule "maxfwd.so"
  201. loadmodule "usrloc.so"
  202. loadmodule "registrar.so"
  203. loadmodule "textops.so"
  204. loadmodule "siputils.so"
  205. loadmodule "xlog.so"
  206. loadmodule "sanity.so"
  207. loadmodule "ctl.so"
  208. loadmodule "mi_rpc.so"
  209. loadmodule "acc.so"
  210.  
  211. #!ifdef WITH_AUTH
  212. loadmodule "auth.so"
  213. loadmodule "auth_db.so"
  214. #!ifdef WITH_IPAUTH
  215. loadmodule "permissions.so"
  216. #!endif
  217. #!endif
  218.  
  219. #!ifdef WITH_ALIASDB
  220. loadmodule "alias_db.so"
  221. #!endif
  222.  
  223. #!ifdef WITH_MULTIDOMAIN
  224. loadmodule "domain.so"
  225. #!endif
  226.  
  227. #!ifdef WITH_PRESENCE
  228. loadmodule "presence.so"
  229. loadmodule "presence_xml.so"
  230. #!endif
  231.  
  232. #!ifdef WITH_NAT
  233. loadmodule "nathelper.so"
  234. loadmodule "rtpproxy.so"
  235. #!endif
  236.  
  237. #!ifdef WITH_TLS
  238. loadmodule "tls.so"
  239. #!endif
  240.  
  241. #!ifdef WITH_ANTIFLOOD
  242. loadmodule "htable.so"
  243. loadmodule "pike.so"
  244. #!endif
  245.  
  246. #!ifdef WITH_XCAPSRV
  247. loadmodule "xhttp.so"
  248. loadmodule "xcap_server.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. modparam("presence", "fallback2db", 1)
  354. modparam("presence", "db_update_period", 20)
  355.  
  356. # ----- presence_xml params -----
  357. modparam("presence_xml", "db_url", DBURL)
  358. modparam("presence_xml", "force_active", 0)
  359. modparam("presence_xml", "integrated_xcap_server", 1)
  360. #!endif
  361.  
  362.  
  363. #!ifdef WITH_NAT
  364. # ----- rtpproxy params -----
  365. modparam("rtpproxy", "rtpproxy_sock", "udp:127.0.0.1:7722")
  366.  
  367. # ----- nathelper params -----
  368. modparam("nathelper", "natping_interval", 30)
  369. modparam("nathelper", "ping_nated_only", 1)
  370. modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
  371. modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
  372.  
  373. # params needed for NAT traversal in other modules
  374. modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
  375. modparam("usrloc", "nat_bflag", FLB_NATB)
  376. #!endif
  377.  
  378.  
  379. #!ifdef WITH_TLS
  380. # ----- tls params -----
  381. modparam("tls", "config", "/tmp/kamailio-xcap/etc/kamailio/tls.cfg")
  382. #!endif
  383.  
  384. #!ifdef WITH_ANTIFLOOD
  385. # ----- pike params -----
  386. modparam("pike", "sampling_time_unit", 2)
  387. modparam("pike", "reqs_density_per_unit", 16)
  388. modparam("pike", "remove_latency", 4)
  389.  
  390. # ----- htable params -----
  391. # ip ban htable with autoexpire after 5 minutes
  392. modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
  393. #!endif
  394.  
  395. #!ifdef WITH_XCAPSRV
  396. # ----- xcap_server params -----
  397. modparam("xcap_server", "db_url", DBURL)
  398. #!endif
  399.  
  400. ####### Routing Logic ########
  401.  
  402.  
  403. # Main SIP request routing logic
  404. # - processing of any incoming SIP request starts with this route
  405. route {
  406.  
  407.         # per request initial checks
  408.         route(REQINIT);
  409.  
  410.         # NAT detection
  411.         route(NAT);
  412.  
  413.         # handle requests within SIP dialogs
  414.         route(WITHINDLG);
  415.  
  416.         ### only initial requests (no To tag)
  417.  
  418.         # CANCEL processing
  419.         if (is_method("CANCEL"))
  420.         {
  421.                 if (t_check_trans())
  422.                         t_relay();
  423.                 exit;
  424.         }
  425.  
  426.         t_check_trans();
  427.  
  428.         # authentication
  429.         route(AUTH);
  430.  
  431.         # record routing for dialog forming requests (in case they are routed)
  432.         # - remove preloaded route headers
  433.         remove_hf("Route");
  434.         if (is_method("INVITE|SUBSCRIBE"))
  435.                 record_route();
  436.  
  437.         # account only INVITEs
  438.         if (is_method("INVITE"))
  439.         {
  440.                 setflag(FLT_ACC); # do accounting
  441.         }
  442.  
  443.         # dispatch requests to foreign domains
  444.         route(SIPOUT);
  445.  
  446.         ### requests for my local domains
  447.  
  448.         # handle presence related requests
  449.         route(PRESENCE);
  450.  
  451.         # handle registrations
  452.         route(REGISTRAR);
  453.  
  454.         if ($rU==$null)
  455.         {
  456.                 # request with no Username in RURI
  457.                 sl_send_reply("484","Address Incomplete");
  458.                 exit;
  459.         }
  460.  
  461.         # dispatch destinations to PSTN
  462.         route(PSTN);
  463.  
  464.         # user location service
  465.         route(LOCATION);
  466.  
  467.         route(RELAY);
  468. }
  469.  
  470.  
  471. route[RELAY] {
  472. #!ifdef WITH_NAT
  473.         if (check_route_param("nat=yes")) {
  474.                 setbflag(FLB_NATB);
  475.         }
  476.         if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {
  477.                 route(RTPPROXY);
  478.         }
  479. #!endif
  480.  
  481.         /* example how to enable some additional event routes */
  482.         if (is_method("INVITE")) {
  483.                 #t_on_branch("BRANCH_ONE");
  484.                 t_on_reply("REPLY_ONE");
  485.                 t_on_failure("FAIL_ONE");
  486.         }
  487.  
  488.         if (!t_relay()) {
  489.                 sl_reply_error();
  490.         }
  491.         exit;
  492. }
  493.  
  494. # Per SIP request initial checks
  495. route[REQINIT] {
  496. #!ifdef WITH_ANTIFLOOD
  497.         # flood dection from same IP and traffic ban for a while
  498.         # be sure you exclude checking trusted peers, such as pstn gateways
  499.         # - local host excluded (e.g., loop to self)
  500.         if(src_ip!=myself)
  501.         {
  502.                 if($sht(ipban=>$si)!=$null)
  503.                 {
  504.                         # ip is already blocked
  505.                         xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  506.                         exit;
  507.                 }
  508.                 if (!pike_check_req())
  509.                 {
  510.                         xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  511.                         $sht(ipban=>$si) = 1;
  512.                         exit;
  513.                 }
  514.         }
  515. #!endif
  516.  
  517.         if (!mf_process_maxfwd_header("10")) {
  518.                 sl_send_reply("483","Too Many Hops");
  519.                 exit;
  520.         }
  521.  
  522.         if(!sanity_check("1511", "7"))
  523.         {
  524.                 xlog("Malformed SIP message from $si:$sp\n");
  525.                 exit;
  526.         }
  527. }
  528.  
  529. # Handle requests within SIP dialogs
  530. route[WITHINDLG] {
  531.         if (has_totag()) {
  532.                 # sequential request withing a dialog should
  533.                 # take the path determined by record-routing
  534.                 if (loose_route()) {
  535.                         if (is_method("BYE")) {
  536.                                 setflag(FLT_ACC); # do accounting ...
  537.                                 setflag(FLT_ACCFAILED); # ... even if the transaction fails
  538.                         }
  539.                         route(RELAY);
  540.                 } else {
  541.                         if (is_method("SUBSCRIBE") && uri == myself) {
  542.                                 # in-dialog subscribe requests
  543.                                 route(PRESENCE);
  544.                                 exit;
  545.                         }
  546.                         if ( is_method("ACK") ) {
  547.                                 if ( t_check_trans() ) {
  548.                                         # no loose-route, but stateful ACK;
  549.                                         # must be an ACK after a 487
  550.                                         # or e.g. 404 from upstream server
  551.                                         t_relay();
  552.                                         exit;
  553.                                 } else {
  554.                                         # ACK without matching transaction ... ignore and discard
  555.                                         exit;
  556.                                 }
  557.                         }
  558.                         sl_send_reply("404","Not here");
  559.                 }
  560.                 exit;
  561.         }
  562. }
  563.  
  564. # Handle SIP registrations
  565. route[REGISTRAR] {
  566.         if (is_method("REGISTER"))
  567.         {
  568.                 if(isflagset(FLT_NATS))
  569.                 {
  570.                         setbflag(FLB_NATB);
  571.                         # uncomment next line to do SIP NAT pinging
  572.                         ## setbflag(FLB_SIPPING);
  573.                 }
  574.                 if (!save("location"))
  575.                         sl_reply_error();
  576.  
  577.                 exit;
  578.         }
  579. }
  580.  
  581. # USER location service
  582. route[LOCATION] {
  583.  
  584. #!ifdef WITH_ALIASDB
  585.         # search in DB-based aliases
  586.         alias_db_lookup("dbaliases");
  587. #!endif
  588.  
  589.         if (!lookup("location")) {
  590.                 switch ($rc) {
  591.                         case -1:
  592.                         case -3:
  593.                                 t_newtran();
  594.                                 t_reply("404", "Not Found");
  595.                                 exit;
  596.                         case -2:
  597.                                 sl_send_reply("405", "Method Not Allowed");
  598.                                 exit;
  599.                 }
  600.         }
  601.  
  602.         # when routing via usrloc, log the missed calls also
  603.         if (is_method("INVITE"))
  604.         {
  605.                 setflag(FLT_ACCMISSED);
  606.         }
  607. }
  608.  
  609. # Presence server route
  610. route[PRESENCE] {
  611.         if(!is_method("PUBLISH|SUBSCRIBE"))
  612.                 return;
  613.  
  614. #!ifdef WITH_PRESENCE
  615.         if (!t_newtran())
  616.         {
  617.                 sl_reply_error();
  618.                 exit;
  619.         };
  620.  
  621.         if(is_method("PUBLISH"))
  622.         {
  623.                 handle_publish();
  624.                 t_release();
  625.         }
  626.         else
  627.         if( is_method("SUBSCRIBE"))
  628.         {
  629.                 handle_subscribe();
  630.                 t_release();
  631.         }
  632.         exit;
  633. #!endif
  634.  
  635.         # if presence enabled, this part will not be executed
  636.         if (is_method("PUBLISH") || $rU==$null)
  637.         {
  638.                 sl_send_reply("404", "Not here");
  639.                 exit;
  640.         }
  641.         return;
  642. }
  643.  
  644. # Authentication route
  645. route[AUTH] {
  646. #!ifdef WITH_AUTH
  647.         if (is_method("REGISTER"))
  648.         {
  649.                 # authenticate the REGISTER requests (uncomment to enable auth)
  650.                 if (!www_authorize("$td", "subscriber"))
  651.                 {
  652.                         www_challenge("$td", "0");
  653.                         exit;
  654.                 }
  655.  
  656.                 if ($au!=$tU)
  657.                 {
  658.                         sl_send_reply("403","Forbidden auth ID");
  659.                         exit;
  660.                 }
  661.         } else {
  662.  
  663. #!ifdef WITH_IPAUTH
  664.                 if(allow_source_address())
  665.                 {
  666.                         # source IP allowed
  667.                         return;
  668.                 }
  669. #!endif
  670.  
  671.                 # authenticate if from local subscriber
  672.                 if (from_uri==myself)
  673.                 {
  674.                         if (!proxy_authorize("$fd", "subscriber")) {
  675.                                 proxy_challenge("$fd", "0");
  676.                                 exit;
  677.                         }
  678.                         if (is_method("PUBLISH"))
  679.                         {
  680.                                 if ($au!=$tU) {
  681.                                         sl_send_reply("403","Forbidden auth ID");
  682.                                         exit;
  683.                                 }
  684.                         } else {
  685.                                 if ($au!=$fU) {
  686.                                         sl_send_reply("403","Forbidden auth ID");
  687.                                         exit;
  688.                                 }
  689.                         }
  690.  
  691.                         consume_credentials();
  692.                         # caller authenticated
  693.                 } else {
  694.                         # caller is not local subscriber, then check if it calls
  695.                         # a local destination, otherwise deny, not an open relay here
  696.                         if (!uri==myself)
  697.                         {
  698.                                 sl_send_reply("403","Not relaying");
  699.                                 exit;
  700.                         }
  701.                 }
  702.         }
  703. #!endif
  704.         return;
  705. }
  706.  
  707. # Caller NAT detection route
  708. route[NAT] {
  709. #!ifdef WITH_NAT
  710.         force_rport();
  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.                 force_rtp_proxy();
  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. # Sample branch router
  776. branch_route[BRANCH_ONE] {
  777.         xdbg("new branch at $ru\n");
  778. }
  779.  
  780. # Sample onreply route
  781. onreply_route[REPLY_ONE] {
  782.         xdbg("incoming reply\n");
  783. #!ifdef WITH_NAT
  784.         if ((isflagset(FLT_NATS) || isbflagset(FLB_NATB))
  785.                         && status=~"(183)|(2[0-9][0-9])") {
  786.                 force_rtp_proxy();
  787.         }
  788.         if (isbflagset("6")) {
  789.                 fix_nated_contact();
  790.         }
  791. #!endif
  792. }
  793.  
  794. # Sample failure route
  795. failure_route[FAIL_ONE] {
  796. #!ifdef WITH_NAT
  797.         if (is_method("INVITE")
  798.                         && (isbflagset(FLB_NATB) || isflagset(FLT_NATS))) {
  799.                 unforce_rtp_proxy();
  800.         }
  801. #!endif
  802.  
  803.         if (t_is_canceled()) {
  804.                 exit;
  805.         }
  806.  
  807.         # uncomment the following lines if you want to block client
  808.         # redirect based on 3xx replies.
  809.         ##if (t_check_status("3[0-9][0-9]")) {
  810.         ##t_reply("404","Not found");
  811.         ##      exit;
  812.         ##}
  813.  
  814.         # uncomment the following lines if you want to redirect the failed
  815.         # calls to a different new destination
  816.         ##if (t_check_status("486|408")) {
  817.         ##      sethostport("192.168.2.100:5060");
  818.         ##      append_branch();
  819.         ##      # do not set the missed call flag again
  820.         ##      t_relay();
  821.         ##}
  822. }
  823.  
  824.  
  825. #!ifdef WITH_XCAPSRV
  826. #!define WITH_XHTTPAUTH
  827. event_route[xhttp:request] {
  828.         xdbg("===== xhttp: request [$rv] $rm => $hu\n");
  829. #!ifdef WITH_XHTTPAUTH
  830.         if (!www_authorize("xcap", "subscriber"))
  831.         {
  832.                 www_challenge("xcap", "0");
  833.                 exit;
  834.         }
  835. #!endif
  836.         if($hu=~"^/xcap-root/")
  837.         {
  838.                 set_reply_close();
  839.                 set_reply_no_connect();
  840.                 # xcap ops
  841.                 $xcapuri(u=>data) = $hu;
  842.                 if($xcapuri(u=>xuid)=~"^sip:.+@.+")
  843.                         $var(uri) = $xcapuri(u=>xuid);
  844.                 else if($xcapuri(u=>xuid)=~".+@.+")
  845.                         $var(uri) = "sip:" + $xcapuri(u=>xuid);
  846.                 else
  847.                         $var(uri) = "sip:"+ $xcapuri(u=>xuid) + "@" + $Ri;
  848.                 xlog("===== xhttp: $xcapuri(u=>auid) : $xcapuri(u=>xuid)\n");
  849.                 if($xcapuri(u=>auid)=="xcap-caps")
  850.                 {
  851.                         $var(xbody) =
  852. "<?xml version='1.0' encoding='UTF-8'?>
  853. <xcap-caps xmlns='urn:ietf:params:xml:ns:xcap-caps'>
  854.  <auids>
  855.    <auid>rls-services</auid>
  856.    <auid>pidf-manipulation</auid>
  857.    <auid>xcap-caps</auid>
  858.    <auid>resource-lists</auid>
  859.    <auid>pres-rules</auid>
  860.    <auid>org.openmobilealliance.pres-rules</auid>
  861.  </auids>
  862.  <extensions>
  863.  </extensions>
  864.  <namespaces>
  865.    <namespace>urn:ietf:params:xml:ns:rls-services</namespace>
  866.    <namespace>urn:ietf:params:xml:ns:pidf</namespace>
  867.    <namespace>urn:ietf:params:xml:ns:xcap-caps</namespace>
  868.    <namespace>urn:ietf:params:xml:ns:resource-lists</namespace>
  869.    <namespace>urn:ietf:params:xml:ns:pres-rules</namespace>
  870.  </namespaces>
  871. </xcap-caps>";
  872.                         xhttp_reply("200", "ok", "application/xcap-caps+xml",
  873.                                         "$var(xbody)");
  874.                         exit;
  875.                 }
  876. #!ifdef WITH_XHTTPAUTH
  877.         # be sure auth user access only its documents
  878.         if ($au!=$(var(uri){uri.user})) {
  879.             xhttp_reply("403", "Forbidden", "text/html",
  880.                     "<html><body>$si:$sp</body></html>");
  881.             exit;
  882.         }
  883.  
  884. #!endif
  885.                 switch($rm) {
  886.                         case "PUT":
  887.                                 xcaps_put("$var(uri)", "$hu", "$rb");
  888.                                 if($xcapuri(u=>auid)=~"pres-rules")
  889.                                 {
  890.                                         xlog("===== xhttp put: refreshing watchers for $var(uri)\n");
  891.                                         pres_update_watchers("$var(uri)", "presence");
  892.                                         pres_refresh_watchers("$var(uri)", "presence", 1);
  893.                                 }
  894.                                 exit;
  895.                         break;
  896.                         case "GET":
  897.                                 xlog("===== xhttp: get $var(uri) => $hu\n");
  898.                                 xcaps_get("$var(uri)", "$hu");
  899.                                 exit;
  900.                         break;
  901.                         case "DELETE":
  902.                                 xcaps_del("$var(uri)", "$hu");
  903.                                 if($xcapuri(u=>auid)=~"pres-rules")
  904.                                 {
  905.                                         xlog("===== xhttp del: refreshing watchers for $var(uri)\n");
  906.                                         pres_update_watchers("$var(uri)", "presence");
  907.                                         pres_refresh_watchers("$var(uri)", "presence", 1);
  908.                                 }
  909.                                 exit;
  910.                         break;
  911.                 }
  912.         }
  913.  
  914.         # http ops
  915.         xhttp_reply("200", "ok", "text/html",
  916.                                         "<html><body>OK: $si:$sp</body></html>");
  917.         exit;
  918. }
  919. #!endif

Author: vm

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

0 comments:

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

© 2014 VOIP4Learn. WP themonic converted by Bloggertheme9. Powered by Blogger.
TOP