Advertisement
apenk

Opensips.cfg

Apr 9th, 2012
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.43 KB | None | 0 0
  1.  
  2.  
  3. #
  4. # $Id: opensips.cfg 5503 2009-03-22 16:22:32Z bogdan_iancu $
  5. #
  6. # Copyright 2010 Voice System
  7. #
  8. # This file is part of opensip LiveCD.
  9. #
  10. # opensips LiveCD is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version
  14. #
  15. # opensips LiveCD is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. #
  24. # Please refer to the Core CookBook at:
  25. # http://www.opensips.org/Resources/DocsCookbooks
  26. # for a explanation of possible statements, functions and parameters.
  27. #
  28.  
  29.  
  30. ####### Global Parameters #########
  31. debug=3
  32. log_stderror=no
  33. log_facility=LOG_LOCAL0
  34. fork=yes
  35. children=4
  36.  
  37. /* uncomment the following lines to enable debugging */
  38. #debug=9
  39. #log_stderror=yes
  40.  
  41. listen=udp:192.168.26.5:5060
  42.  
  43.  
  44. ####### Modules Section ########
  45.  
  46. #set module path
  47. mpath="/lib/opensips/modules/"
  48.  
  49. loadmodule "db_mysql.so"
  50. loadmodule "signaling.so"
  51. loadmodule "sl.so"
  52. loadmodule "tm.so"
  53. loadmodule "rr.so"
  54. loadmodule "maxfwd.so"
  55. loadmodule "usrloc.so"
  56. loadmodule "registrar.so"
  57. loadmodule "textops.so"
  58. loadmodule "mi_fifo.so"
  59. loadmodule "uri.so"
  60. loadmodule "acc.so"
  61. loadmodule "auth.so"
  62. loadmodule "auth_db.so"
  63. loadmodule "alias_db.so"
  64. loadmodule "domain.so"
  65. loadmodule "group.so"
  66. loadmodule "drouting.so"
  67. loadmodule "dialog.so"
  68. loadmodule "avpops.so"
  69. loadmodule "dialplan.so"
  70. loadmodule "nathelper.so"
  71. loadmodule "mi_xmlrpc.so"
  72. loadmodule "presence.so"
  73. loadmodule "presence_xml.so"
  74.  
  75.  
  76. # ----------------- setting module-specific parameters ---------------
  77. # ----- mi_fifo params -----
  78. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  79. modparam("mi_fifo", "fifo_mode", 0666)
  80.  
  81. # ----- rr params -----
  82. # add value to ;lr param to cope with most of the UAs
  83. #modparam("rr", "enable_full_lr", 1)
  84. # do not append from tag to the RR (no need for this script)
  85. modparam("rr", "append_fromtag", 0)
  86.  
  87. # ----- usrloc params -----
  88. modparam("usrloc", "db_mode", 2)
  89. modparam("usrloc", "db_url",
  90. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  91.  
  92. # ----- acc params -----
  93. modparam("acc", "early_media", 0)
  94. modparam("acc", "report_ack", 0)
  95. modparam("acc", "report_cancels", 0)
  96. modparam("acc", "detect_direction", 0)
  97. modparam("acc", "failed_transaction_flag", 3)
  98. modparam("acc", "db_flag", 1)
  99. modparam("acc", "db_missed_flag", 2)
  100. modparam("acc", "db_url",
  101. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  102. modparam("acc", "db_extra", "caller_id=$avp(s:caller);callee_id=$avp(s:callee)")
  103.  
  104. # ----- auth_db params -----
  105. modparam("auth_db", "calculate_ha1", yes)
  106. modparam("auth_db", "password_column", "password")
  107. modparam("auth_db", "db_url",
  108. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  109.  
  110.  
  111. # ----- alias_db params -----
  112. modparam("alias_db", "db_url",
  113. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  114.  
  115.  
  116. # ----- domain params -----
  117. modparam("domain", "db_url",
  118. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  119. modparam("domain", "db_mode", 1) # Use caching
  120.  
  121.  
  122. # ----- group parameters ---- #
  123. modparam("group", "use_domain", 1)
  124. modparam("group", "table", "grp")
  125. modparam("group", "db_url",
  126. "mysql://opensips:opensipsrw@127.0.0.1/opensips")
  127.  
  128.  
  129. # ----- multi-module params -----
  130. modparam("auth_db|usrloc|uri_db", "use_domain", 1)
  131.  
  132. # ----- drouting params -----
  133. modparam("drouting", "use_domain", 1)
  134. modparam("drouting","db_url",
  135. "mysql://opensips:opensipsrw@localhost/opensips")
  136.  
  137. # ---- dialplan params ----
  138. modparam("auth_db", "load_credentials", "")
  139. modparam("dialplan", "db_url",
  140. "mysql://opensips:opensipsrw@localhost/opensips")
  141. ## attribute of the matched line will be store in the $avp(s:dest)
  142. modparam("dialplan", "attrs_pvar", "$avp(s:dest)")
  143.  
  144. #------ avpops params -----
  145. modparam("avpops", "db_url",
  146. "mysql://opensips:opensipsrw@localhost/opensips")
  147. modparam("avpops", "avp_table", "usr_preferences")
  148.  
  149. #------ tm params ----
  150. modparam("tm", "fr_inv_timer",20)
  151. modparam("tm", "fr_timer", 5)
  152.  
  153. #------ nat parameters ----
  154. modparam("registrar","received_avp", "$avp(i:42)")
  155. modparam("usrloc","nat_bflag", 6)
  156. modparam("nathelper","received_avp", "$avp(i:42)")
  157. modparam("nathelper", "natping_interval", 5)
  158. modparam("nathelper", "ping_nated_only", 1)
  159. modparam("nathelper", "sipping_bflag", 7)
  160. modparam("nathelper", "sipping_from", "sip:pinger@192.168.26.5:5060")
  161. modparam("nathelper", "db_url",
  162. "mysql://opensips:opensipsrw@localhost/opensips")
  163.  
  164. # ----- presence params -----
  165. modparam("presence|presence_xml", "db_url",
  166. "mysql://opensips:opensipsrw@localhost/opensips")
  167. modparam("presence_xml", "force_active", 1)
  168. modparam("presence", "server_address", "sip:192.168.26.5:5090")
  169.  
  170. # ----- presence params -----
  171. modparam("dialog", "db_url",
  172. "mysql://opensips:opensipsrw@localhost/opensips")
  173. modparam("dialog", "dlg_match_mode", 1)
  174. modparam("dialog", "db_mode", 2)
  175.  
  176.  
  177.  
  178. ####### Routing Logic ########
  179. # main request routing logic
  180. route{
  181.  
  182. if (!mf_process_maxfwd_header("10")) {
  183. send_reply("483","Too Many Hops");
  184. exit;
  185. }
  186.  
  187.  
  188. #---- NAT Detection ----#
  189. force_rport();
  190. if (nat_uac_test("19")) {
  191. if (is_method("REGISTER")) {
  192. fix_nated_register();
  193. } else {
  194. fix_nated_contact();
  195. #---- Insert nat=yes at the end of the Contact header ----#
  196. #---- This helps with REINVITEs, ----#
  197. #--- nat=yes will be included in the R-URI for sequential requests ---#
  198. search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
  199. }
  200. setflag(5);
  201. }
  202.  
  203.  
  204. #---- Sequential requests section ----#
  205. if (has_totag()) {
  206. # sequential request withing a dialog should
  207. # take the path determined by record-routing
  208. if (loose_route()) {
  209. if (is_method("BYE")) {
  210. setflag(1); # do accounting ...
  211. setflag(3); # ... even if the transaction fails
  212. } else if (is_method("INVITE")) {
  213. record_route();
  214. }
  215. route(generic_relay);
  216. } else {
  217. if (is_method("SUBSCRIBE") && $rd == "192.168.26.5") {
  218. # in-dialog subscribe requests
  219. route(presence_handling);
  220. exit;
  221. }
  222.  
  223. if ( is_method("ACK") ) {
  224. if ( t_check_trans() ) {
  225. t_relay();
  226. exit;
  227. } else {
  228. exit;
  229. }
  230. }
  231. send_reply("404","Not here");
  232. }
  233. exit;
  234. }
  235.  
  236.  
  237. #---- initial requests section ----#
  238. if (is_method("CANCEL")) {
  239. if (t_check_trans())
  240. t_relay();
  241. exit;
  242. }
  243.  
  244.  
  245. #---- catch retransmissions ----#
  246. t_check_trans();
  247.  
  248.  
  249. #---- check request relaying ----#
  250. if ( !is_from_local() && !is_uri_host_local() ) {
  251. send_reply("403","No relaying");
  252. exit;
  253. }
  254.  
  255.  
  256. #---- authenticate caller if local ----#
  257. if (!is_method("REGISTER") && is_from_local()) {
  258. if(!is_from_gw()){
  259. if (!proxy_authorize("", "subscriber")) {
  260. proxy_challenge("", "0");
  261. exit;
  262. }
  263. if (!db_check_from()) {
  264. send_reply("403","Forbidden auth ID");
  265. exit;
  266. }
  267. consume_credentials();
  268. # caller authenticated
  269. }
  270. }
  271.  
  272.  
  273. #---- preloaded route checking ----#
  274. if (loose_route()) {
  275. xlog("L_ERR",
  276. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  277. if (!is_method("ACK"))
  278. send_reply("403","Preload Route denied");
  279. exit;
  280. }
  281.  
  282. #---- record routing ----#
  283. if (!is_method("REGISTER|MESSAGE"))
  284. record_route();
  285.  
  286.  
  287. #---- account only INVITEs -----#
  288. if (is_method("INVITE")) {
  289. setflag(1); # do accounting
  290. $avp(s:caller) = $fu;
  291. create_dialog();
  292. }
  293.  
  294. #---- Routing to external domains ----#
  295. if (!is_uri_host_local()) {
  296. $avp(s:callee) = $ru;
  297. route(generic_relay);
  298. exit;
  299. }
  300.  
  301. #--- presence diversion ----#
  302. if (is_method("PUBLISH|SUBSCRIBE")) {
  303. route(presence_handling);
  304. exit;
  305. }
  306.  
  307. #--- registration handling ----#
  308. if (is_method("REGISTER")) {
  309. # authenticate the REGISTER requests
  310. if (!www_authorize("", "subscriber")) {
  311. www_challenge("", "0");
  312. exit;
  313. }
  314.  
  315. if (!db_check_to()) {
  316. send_reply("403","Forbidden auth ID");
  317. exit;
  318. }
  319.  
  320. #---- Request is behind NAT(flag5) save with bflag 6 ----#
  321. #---- Use bflag 7 to start SIP pinging (Options) ----#
  322. if (isflagset(5)) {
  323. setbflag(6);
  324. setbflag(7);
  325. };
  326.  
  327. if (!save("location"))
  328. sl_reply_error();
  329.  
  330. exit;
  331. }
  332.  
  333. if ($rU==NULL) {
  334. # request with no Username in RURI
  335. send_reply("484","Address Incomplete");
  336. exit;
  337. }
  338.  
  339. # apply DB based aliases
  340. alias_db_lookup("dbaliases");
  341.  
  342.  
  343. #--- handle local numbers ----#
  344.  
  345. if(!dp_translate("0","$ruri.user/$ruri.user")){
  346. send_reply("420", "Invalid Destination");
  347. exit;
  348. }
  349. xlog("$avp(s:dest)");
  350.  
  351. $avp(s:callee) = $ru;
  352.  
  353.  
  354. if ($avp(s:dest)=="usrloc") {
  355. #Route to usrloc
  356. route(user_location);
  357. }
  358.  
  359. if ($avp(s:dest)=="pstn") {
  360. #route to pstn
  361. route(pstn_routing);
  362. }
  363.  
  364. if ($avp(s:dest)=="media") {
  365. #route to media server
  366. route(media_routing);
  367. }
  368. send_reply("420", "Invalid Extension");
  369. exit;
  370.  
  371. }
  372.  
  373.  
  374. route[generic_relay] {
  375. # for INVITEs enable some additional helper routes
  376. #---- Helper route, if nat=yes in the R-URI set flag 6 ----#
  377. #---- This is used to Process REINVITES ----#
  378. if (subst_uri('/((sip:.*)||(sip:.*:.*));nat=yes/\1/')){
  379. setbflag(6);
  380. };
  381.  
  382. #---- If caller(flag 5) or callee(flag 6) are behind NAT ---#
  383. #---- Call the route(6) to force the use of the RTP Proxy ---#
  384. if (isflagset(5)||isbflagset(6)) {
  385. route(nat_fixups);
  386. };
  387.  
  388. if (!t_relay()) {
  389. sl_reply_error();
  390. };
  391. exit;
  392. }
  393.  
  394.  
  395. route[presence_handling]
  396. {
  397. if (!t_newtran()){
  398. sl_reply_error();
  399. exit;
  400. };
  401.  
  402. if(is_method("PUBLISH")) {
  403. handle_publish();
  404. }
  405. else
  406. if( is_method("SUBSCRIBE")) {
  407. handle_subscribe();
  408. }
  409.  
  410. exit;
  411. }
  412.  
  413.  
  414.  
  415. route[user_location]{
  416. if (!lookup("location", "m")) {
  417. switch ($retcode) {
  418. case -1:
  419. case -3:
  420. t_newtran();
  421. send_reply("404", "Not Found");
  422. exit;
  423. case -2:
  424. send_reply("405", "Method Not Allowed");
  425. exit;
  426. }
  427. }
  428. # when routing via usrloc, log the missed calls also
  429. setflag(2); # Account missed calls
  430.  
  431. t_on_failure("user_failure");
  432.  
  433. route(generic_relay);
  434. }
  435.  
  436.  
  437. route[pstn_routing] {
  438. if (!db_is_user_in("from","pstn") ) {
  439. send_reply("403", "No pstn calls");
  440. exit;
  441. }
  442. if(!do_routing("0","0")){
  443. send_reply("503", "No destination for the prefix");
  444. exit;
  445. }
  446.  
  447. t_on_failure("gw_failure");
  448.  
  449. route(generic_relay);
  450. }
  451.  
  452. route[media_routing] {
  453. #---- Route to media servers ----#
  454. #xlog("route to media servers");
  455. rewritehostport("192.168.26.5:5080");
  456. route(generic_relay);
  457. }
  458.  
  459. route[nat_fixups] {
  460. #---- RTP Proxy handling ---#
  461. if (is_method("BYE|CANCEL")) {
  462. unforce_rtp_proxy();
  463. } else if (is_method("INVITE")){
  464. #---- Activates the RTP Proxy for the CALLEE ---#
  465. force_rtp_proxy();
  466. };
  467. # catch and fix replies
  468. t_on_reply("2");
  469. }
  470.  
  471. onreply_route[2] {
  472. #xlog("incoming reply\n");
  473.  
  474. #---- Handling of the SDP for the 200 or 183 reply ----#
  475. #---- If behind nat (flags 5 or 6) start RTP Proxy ----#
  476. #---- Activates the RTP Proxy for the CALLER ----#
  477. if ( is_method("INVITE") &&
  478. (isflagset(5) || isbflagset(6)) &&
  479. has_body("application/sdp") ){
  480. force_rtp_proxy();
  481. }
  482.  
  483. #---- If the CALLEE is behind NAT, fix the CONTACT HF ----#
  484. if (isbflagset(6)) {
  485. fix_nated_contact();
  486. search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
  487. }
  488. exit;
  489. }
  490.  
  491. failure_route[user_failure] {
  492.  
  493. #---- If a failure has ocurred, deactivate the RTP Proxy ----#
  494. if (isflagset(5) || isbflagset(6)){
  495. unforce_rtp_proxy();
  496. }
  497.  
  498. if (t_was_cancelled()) {
  499. exit;
  500. }
  501.  
  502. if ( db_is_user_in("from","voicemail") ) {
  503. # Redirect busy calls to a media server
  504. $ru = $avp(s:callee);
  505. sethostport("192.168.26.5:5080");
  506. t_relay();
  507. }
  508.  
  509. }
  510.  
  511.  
  512. failure_route[gw_failure] {
  513. if (t_was_cancelled()) {
  514. exit;
  515. }
  516.  
  517. if ( t_check_status("(56)[0-9][0-9]") ) {
  518. if (use_next_gw()) {
  519. xlog ("next gateway $ru \n");
  520. t_relay();
  521. exit;
  522. } else {
  523. t_reply("503", "Service not available, no more gws");
  524. exit;
  525. }
  526. }
  527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement