Advertisement
Vince-0

opensips.cfg residential

Jan 18th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. #
  2. # OpenSIPS residential configuration script
  3. # by OpenSIPS Solutions <team@opensips-solutions.com>
  4. #
  5. # This script was generated via "make menuconfig", from
  6. # the "Residential" scenario.
  7. # You can enable / disable more features / functionalities by
  8. # re-generating the scenario with different options.#
  9. #
  10. # Please refer to the Core CookBook at:
  11. # https://opensips.org/Resources/DocsCookbooks
  12. # for a explanation of possible statements, functions and parameters.
  13. #
  14.  
  15.  
  16. ####### Global Parameters #########
  17.  
  18. /* uncomment the following lines to enable debugging */
  19. #debug_mode=yes
  20.  
  21. log_level=3
  22. xlog_level=3
  23. log_stderror=no
  24. log_facility=LOG_LOCAL0
  25.  
  26. udp_workers=4
  27.  
  28. /* uncomment the next line to enable the auto temporary blacklisting of
  29. not available destinations (default disabled) */
  30. #disable_dns_blacklist=no
  31.  
  32. /* uncomment the next line to enable IPv6 lookup after IPv4 dns
  33. lookup failures (default disabled) */
  34. #dns_try_ipv6=yes
  35.  
  36.  
  37. socket=udp:XXX.XXX.XXX.XXX:5060 # CUSTOMIZE ME
  38. socket=tcp:XXX.XXX.XXX.XXX:5060 # CUSTOMIZE ME
  39.  
  40.  
  41. ####### Modules Section ########
  42.  
  43. #set module path
  44. mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"
  45.  
  46. #### SIGNALING module
  47. loadmodule "signaling.so"
  48.  
  49. #### StateLess module
  50. loadmodule "sl.so"
  51.  
  52. #### Transaction Module
  53. loadmodule "tm.so"
  54. modparam("tm", "fr_timeout", 5)
  55. modparam("tm", "fr_inv_timeout", 30)
  56. modparam("tm", "restart_fr_on_each_reply", 0)
  57. modparam("tm", "onreply_avp_mode", 1)
  58.  
  59. #### Record Route Module
  60. loadmodule "rr.so"
  61. /* do not append from tag to the RR (no need for this script) */
  62. modparam("rr", "append_fromtag", 0)
  63.  
  64. #### MAX ForWarD module
  65. loadmodule "maxfwd.so"
  66.  
  67. #### SIP MSG OPerationS module
  68. loadmodule "sipmsgops.so"
  69.  
  70. #### FIFO Management Interface
  71. loadmodule "mi_fifo.so"
  72. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  73. modparam("mi_fifo", "fifo_mode", 0666)
  74.  
  75. #### MYSQL module
  76. loadmodule "db_mysql.so"
  77.  
  78. #### HTTPD module
  79. loadmodule "httpd.so"
  80. modparam("httpd", "port", 8888)
  81.  
  82. #### USeR LOCation module
  83. loadmodule "usrloc.so"
  84. modparam("usrloc", "nat_bflag", "NAT")
  85. modparam("usrloc", "working_mode_preset", "single-instance-sql-write-back")
  86. modparam("usrloc", "db_url",
  87. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  88.  
  89.  
  90. #### REGISTRAR module
  91. loadmodule "registrar.so"
  92. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
  93. modparam("registrar", "received_avp", "$avp(received_nh)")/* uncomment the next line not to allow more than 10 contacts per AOR */
  94. #modparam("registrar", "max_contacts", 10)
  95.  
  96. #### ACCounting module
  97. loadmodule "acc.so"
  98. /* what special events should be accounted ? */
  99. modparam("acc", "early_media", 0)
  100. modparam("acc", "report_cancels", 0)
  101. /* by default we do not adjust the direct of the sequential requests.
  102. if you enable this parameter, be sure to enable "append_fromtag"
  103. in "rr" module */
  104. modparam("acc", "detect_direction", 0)
  105. modparam("acc", "db_url",
  106. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  107.  
  108. #### AUTHentication modules
  109. loadmodule "auth.so"
  110. loadmodule "auth_db.so"
  111. modparam("auth_db", "calculate_ha1", yes)
  112. modparam("auth_db", "password_column", "password")
  113. modparam("auth_db", "db_url",
  114. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  115. modparam("auth_db", "load_credentials", "")
  116.  
  117. #### ALIAS module
  118. loadmodule "alias_db.so"
  119. modparam("alias_db", "db_url",
  120. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  121.  
  122. #### DOMAIN module
  123. loadmodule "domain.so"
  124. modparam("domain", "db_url",
  125. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  126. modparam("domain", "db_mode", 1) # Use caching
  127. modparam("auth_db|usrloc", "use_domain", 1)
  128.  
  129. #### PRESENCE modules
  130. loadmodule "xcap.so"
  131. loadmodule "presence.so"
  132. loadmodule "presence_xml.so"
  133. modparam("xcap|presence", "db_url",
  134. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  135. modparam("presence_xml", "force_active", 1)
  136. modparam("presence", "fallback2db", 0)
  137.  
  138. #### DIALOG module
  139. loadmodule "dialog.so"
  140. modparam("dialog", "dlg_match_mode", 1)
  141. modparam("dialog", "default_timeout", 21600) # 6 hours timeout
  142. modparam("dialog", "db_mode", 2)
  143. modparam("dialog", "db_url",
  144. "mysql://opensips:opensipsrwXXX@localhost/opensips") # CUSTOMIZE ME
  145.  
  146. #### NAT modules
  147. loadmodule "nathelper.so"
  148. modparam("nathelper", "natping_interval", 10)
  149. modparam("nathelper", "ping_nated_only", 1)
  150. modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG")
  151. modparam("nathelper", "sipping_from", "sip:pinger@127.0.0.1") #CUSTOMIZE ME
  152. modparam("nathelper", "received_avp", "$avp(received_nh)")
  153.  
  154. loadmodule "rtpproxy.so"
  155. modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:12221") # CUSTOMIZE ME
  156.  
  157. #### DIALPLAN module
  158. loadmodule "dialplan.so"
  159. modparam("dialplan", "db_url",
  160. "mysql://opensips:opensipsrwXXXX@localhost/opensips") # CUSTOMIZE ME
  161.  
  162. #### DYNAMMIC ROUTING module
  163. loadmodule "drouting.so"
  164. modparam("drouting", "db_url",
  165. "mysql://opensips:opensipsrwXXXX@localhost/opensips") # CUSTOMIZE ME
  166.  
  167. #### MI_HTTP module
  168. loadmodule "mi_http.so"
  169.  
  170. loadmodule "proto_udp.so"
  171. loadmodule "proto_tcp.so"
  172. ####### Routing Logic ########
  173.  
  174. # main request routing logic
  175.  
  176. route{
  177.  
  178. # initial NAT handling; detect if the request comes from behind a NAT
  179. # and apply contact fixing
  180. force_rport();
  181. if (nat_uac_test(23)) {
  182. if (is_method("REGISTER")) {
  183. fix_nated_register();
  184. setbflag("NAT");
  185. } else {
  186. fix_nated_contact();
  187. setflag("NAT");
  188. }
  189. }
  190.  
  191. if (!mf_process_maxfwd_header(10)) {
  192. send_reply(483,"Too Many Hops");
  193. exit;
  194. }
  195.  
  196. if (has_totag()) {
  197.  
  198. # handle hop-by-hop ACK (no routing required)
  199. if ( is_method("ACK") && t_check_trans() ) {
  200. t_relay();
  201. exit;
  202. }
  203.  
  204. # sequential request within a dialog should
  205. # take the path determined by record-routing
  206. if ( !loose_route() ) {
  207. if (is_method("SUBSCRIBE") && is_myself("$rd")) {
  208. # in-dialog subscribe requests
  209. route(handle_presence);
  210. exit;
  211. }
  212. # we do record-routing for all our traffic, so we should not
  213. # receive any sequential requests without Route hdr.
  214. send_reply(404,"Not here");
  215. exit;
  216. }
  217.  
  218. # validate the sequential request against dialog
  219. if ( $DLG_status!=NULL && !validate_dialog() ) {
  220. xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
  221. ## exit;
  222. }
  223.  
  224. if (is_method("BYE")) {
  225. # do accounting even if the transaction fails
  226. do_accounting("db","failed");
  227.  
  228. }
  229.  
  230.  
  231. if (check_route_param("nat=yes"))
  232. setflag("NAT");
  233. # route it out to whatever destination was set by loose_route()
  234. # in $du (destination URI).
  235. route(relay);
  236. exit;
  237. }
  238.  
  239. # CANCEL processing
  240. if (is_method("CANCEL")) {
  241. if (t_check_trans())
  242. t_relay();
  243. exit;
  244. }
  245.  
  246. # absorb retransmissions, but do not create transaction
  247. t_check_trans();
  248.  
  249. if ( !(is_method("REGISTER") || is_from_gw() ) ) {
  250.  
  251. if (is_from_local()) {
  252. # authenticate if from local subscriber
  253. # authenticate all initial non-REGISTER request that pretend to be
  254. # generated by local subscriber (domain from FROM URI is local)
  255. if (!proxy_authorize("", "subscriber")) {
  256. proxy_challenge("", "auth");
  257. exit;
  258. }
  259. if ($au!=$fU) {
  260. send_reply(403,"Forbidden auth ID");
  261. exit;
  262. }
  263.  
  264. consume_credentials();
  265. # caller authenticated
  266.  
  267. } else {
  268. # if caller is not local, then called number must be local
  269.  
  270. if (!is_uri_host_local()) {
  271. send_reply(403,"Relay Forbidden");
  272. exit;
  273. }
  274. }
  275.  
  276. }
  277.  
  278. # preloaded route checking
  279. if (loose_route()) {
  280. xlog("L_ERR",
  281. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  282. if (!is_method("ACK"))
  283. send_reply(403,"Preload Route denied");
  284. exit;
  285. }
  286.  
  287. # record routing
  288. if (!is_method("REGISTER|MESSAGE"))
  289. record_route();
  290.  
  291. # account only INVITEs
  292. if (is_method("INVITE")) {
  293.  
  294. # create dialog with timeout
  295. if ( !create_dialog("B") ) {
  296. send_reply(500,"Internal Server Error");
  297. exit;
  298. }
  299.  
  300. do_accounting("db");
  301.  
  302. }
  303.  
  304.  
  305. if (!is_uri_host_local()) {
  306. append_hf("P-hint: outbound\r\n");
  307.  
  308. route(relay);
  309. }
  310.  
  311. # requests for my domain
  312.  
  313. if( is_method("PUBLISH|SUBSCRIBE"))
  314. route(handle_presence);
  315.  
  316. if (is_method("REGISTER")) {
  317. # authenticate the REGISTER requests
  318. if (!www_authorize("", "subscriber")) {
  319. www_challenge("", "auth");
  320. exit;
  321. }
  322.  
  323. if ($au!=$tU) {
  324. send_reply(403,"Forbidden auth ID");
  325. exit;
  326. }
  327. if ($socket_in(proto) == "tcp")
  328. setflag("TCP_PERSISTENT");
  329. if (isflagset("NAT")) {
  330. setbflag("SIP_PING_FLAG");
  331. }
  332. # store the registration and generate a SIP reply
  333. if (!save("location"))
  334. xlog("failed to register AoR $tu\n");
  335.  
  336. exit;
  337. }
  338.  
  339. if ($rU==NULL) {
  340. # request with no Username in RURI
  341. send_reply(484,"Address Incomplete");
  342. exit;
  343. }
  344.  
  345.  
  346. # apply DB based aliases
  347. alias_db_lookup("dbaliases");
  348.  
  349.  
  350. # apply transformations from dialplan table
  351. dp_translate( 0, "$rU", $rU);
  352.  
  353.  
  354. if ($rU=~"^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+$") {
  355. #if (dp_translate(10,"$rU/$rU") ) {
  356. #strip(1);
  357. if (!do_routing(0)) {
  358. send_reply(500,"No PSTN Route found");
  359. exit;
  360. }
  361.  
  362. route(relay);
  363. exit;
  364. }
  365.  
  366.  
  367. # do lookup with method filtering
  368. if (!lookup("location","m")) {
  369. if (!db_does_uri_exist("$ru","subscriber")) {
  370. send_reply(420,"Bad Extension");
  371. exit;
  372. }
  373.  
  374. # redirect to a different VM system
  375. $du = "sip:127.0.0.2:5060"; # CUSTOMIZE ME
  376. route(relay);
  377.  
  378. }
  379.  
  380. if (isbflagset("NAT")) setflag("NAT");
  381.  
  382. # when routing via usrloc, log the missed calls also
  383. do_accounting("db","missed");
  384.  
  385. route(relay);
  386. }
  387.  
  388.  
  389. route[relay] {
  390. # for INVITEs enable some additional helper routes
  391. if (is_method("INVITE")) {
  392.  
  393. if (isflagset("NAT") && has_body("application/sdp")) {
  394. rtpproxy_offer("ro");
  395. }
  396.  
  397. t_on_branch("per_branch_ops");
  398. t_on_reply("handle_nat");
  399. t_on_failure("missed_call");
  400. }
  401.  
  402. if (isflagset("NAT")) {
  403. add_rr_param(";nat=yes");
  404. }
  405.  
  406. if (!t_relay()) {
  407. send_reply(500,"Internal Error");
  408. }
  409. exit;
  410. }
  411.  
  412.  
  413. # Presence route
  414. route[handle_presence]
  415. {
  416. if (!t_newtran()) {
  417. sl_reply_error();
  418. exit;
  419. }
  420.  
  421. if(is_method("PUBLISH")) {
  422. handle_publish();
  423. } else
  424. if( is_method("SUBSCRIBE")) {
  425. handle_subscribe();
  426. }
  427.  
  428. exit;
  429. }
  430.  
  431.  
  432. branch_route[per_branch_ops] {
  433. xlog("new branch at $ru\n");
  434. }
  435.  
  436.  
  437. onreply_route[handle_nat] {
  438. if (nat_uac_test(1))
  439. fix_nated_contact();
  440. if ( isflagset("NAT") && has_body("application/sdp") )
  441. rtpproxy_answer("ro");
  442. xlog("incoming reply\n");
  443. }
  444.  
  445.  
  446. failure_route[missed_call] {
  447. if (t_was_cancelled()) {
  448. exit;
  449. }
  450.  
  451. # uncomment the following lines if you want to block client
  452. # redirect based on 3xx replies.
  453. ##if (t_check_status("3[0-9][0-9]")) {
  454. ##t_reply(404,"Not found");
  455. ## exit;
  456. ##}
  457.  
  458.  
  459. # redirect the failed to a different VM system
  460. if (t_check_status("486|408")) {
  461. $du = "sip:127.0.0.2:5060"; # CUSTOMIZE ME
  462. # do not set the missed call flag again
  463. route(relay);
  464. }
  465. }
  466.  
  467.  
  468.  
  469. local_route {
  470. if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
  471.  
  472. acc_db_request("200 Dialog Timeout", "acc");
  473.  
  474. }
  475. }
  476.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement