Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 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_LOCAL6
  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:127.0.0.1:5060 # CUSTOMIZE ME
  38. socket=udp:172.18.7.118:5060
  39. socket=udp:x.x.x.x:5080
  40.  
  41.  
  42.  
  43. ####### Modules Section ########
  44.  
  45. #set module path
  46. mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"
  47.  
  48. #### SIGNALING module
  49. loadmodule "signaling.so"
  50.  
  51. #### StateLess module
  52. loadmodule "sl.so"
  53.  
  54. #### Transaction Module
  55. loadmodule "tm.so"
  56. modparam("tm", "fr_timeout", 5)
  57. modparam("tm", "fr_inv_timeout", 30)
  58. modparam("tm", "restart_fr_on_each_reply", 0)
  59. modparam("tm", "onreply_avp_mode", 1)
  60.  
  61. #### Record Route Module
  62. loadmodule "rr.so"
  63. /* do not append from tag to the RR (no need for this script) */
  64. modparam("rr", "append_fromtag", 0)
  65.  
  66. #### MAX ForWarD module
  67. loadmodule "maxfwd.so"
  68.  
  69. #### SIP MSG OPerationS module
  70. loadmodule "sipmsgops.so"
  71.  
  72. #### FIFO Management Interface
  73. loadmodule "mi_fifo.so"
  74. modparam("mi_fifo", "fifo_name", "/run/opensips/opensips_fifo")
  75. modparam("mi_fifo", "fifo_mode", 0666)
  76.  
  77. #### USeR LOCation module
  78. loadmodule "usrloc.so"
  79. modparam("usrloc", "nat_bflag", "NAT")
  80. #modparam("usrloc", "working_mode_preset", "single-instance-sql-write-back")
  81. modparam("usrloc", "working_mode_preset", "single-instance-sql-write-through")
  82. modparam("usrloc", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  83.  
  84. #### REGISTRAR module
  85. loadmodule "registrar.so"
  86. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
  87. /* uncomment the next line not to allow more than 10 contacts per AOR */
  88. modparam("registrar", "max_contacts", 10)
  89.  
  90. #### ACCounting module
  91. loadmodule "acc.so"
  92. /* what special events should be accounted ? */
  93. modparam("acc", "early_media", 0)
  94. modparam("acc", "report_cancels", 0)
  95. /* by default we do not adjust the direct of the sequential requests.
  96. if you enable this parameter, be sure to enable "append_fromtag"
  97. in "rr" module */
  98. modparam("acc", "detect_direction", 0)
  99.  
  100. loadmodule "proto_udp.so"
  101.  
  102. #### event_route module ####
  103. #loadmodule "event_route.so"
  104.  
  105. #### mysql module ####
  106. loadmodule "db_mysql.so"
  107.  
  108. #### mid_registrar module ####
  109. loadmodule "mid_registrar.so"
  110. modparam("mid_registrar", "mode", 0)
  111.  
  112. #### jsonrpc module ####
  113. loadmodule "jsonrpc.so"
  114.  
  115. #### httpd module ####
  116. loadmodule "httpd.so"
  117. modparam("httpd", "ip", "127.0.0.1")
  118.  
  119. #### http_mi module ####
  120. loadmodule "mi_http.so"
  121.  
  122. #### domain module ####
  123. loadmodule "domain.so"
  124. modparam("domain", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  125. modparam("domain", "db_mode", 1) # Use caching
  126.  
  127. #### dispatcher module ####
  128. loadmodule "dispatcher.so"
  129. modparam("dispatcher", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  130.  
  131. #### permissions module ####
  132. loadmodule "permissions.so"
  133. modparam("permissions", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  134. modparam("permissions", "address_table", "address")
  135.  
  136. #### nathelper module ####
  137. loadmodule "nathelper.so"
  138.  
  139.  
  140. ####### Routing Logic ########
  141.  
  142. # main request routing logic
  143.  
  144. route{
  145.  
  146. if (!mf_process_maxfwd_header(10)) {
  147. send_reply(483,"Too Many Hops");
  148. exit;
  149. }
  150.  
  151. if (has_totag()) {
  152. if ( is_method("INVITE") ) {
  153. xlog("HAS TO TAG INVITE\n");
  154. }
  155.  
  156. # handle hop-by-hop ACK (no routing required)
  157. if ( is_method("ACK") && t_check_trans() ) {
  158. t_relay();
  159. exit;
  160. }
  161.  
  162. # sequential request within a dialog should
  163. # take the path determined by record-routing
  164. if ( !loose_route() ) {
  165. # we do record-routing for all our traffic, so we should not
  166. # receive any sequential requests without Route hdr.
  167. send_reply(404,"Not here");
  168. exit;
  169. }
  170.  
  171. if (is_method("BYE")) {
  172. # do accounting even if the transaction fails
  173. do_accounting("log","failed");
  174. }
  175.  
  176. # route it out to whatever destination was set by loose_route()
  177. # in $du (destination URI).
  178. route(relay);
  179. exit;
  180. }
  181.  
  182. # CANCEL processing
  183. if (is_method("CANCEL")) {
  184. if (t_check_trans())
  185. t_relay();
  186. exit;
  187. }
  188.  
  189. # absorb retransmissions, but do not create transaction
  190. t_check_trans();
  191.  
  192. if ( !(is_method("REGISTER") ) ) {
  193.  
  194. if (is_myself("$fd")) {
  195.  
  196. } else {
  197. # if caller is not local, then called number must be local
  198.  
  199. if (!is_myself("$rd")) {
  200. send_reply(403,"Relay Forbidden");
  201. exit;
  202. }
  203. }
  204.  
  205. }
  206.  
  207. # preloaded route checking
  208. if (loose_route()) {
  209. xlog("L_ERR",
  210. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  211. if (!is_method("ACK"))
  212. send_reply(403,"Preload Route denied");
  213. exit;
  214. }
  215.  
  216. # record routing
  217. if (!is_method("REGISTER|MESSAGE"))
  218. record_route();
  219.  
  220. # account only INVITEs
  221. if (is_method("INVITE")) {
  222. xlog("INVITE from $si\n");
  223. if (check_source_address(1)) {
  224. xlog("Authorized INVITE\n");
  225. # if (!t_relay()) {
  226. # send_reply(500,"Relaying Failed");
  227. # }
  228. # t_relay();
  229. }
  230. do_accounting("log");
  231. #exit;
  232. }
  233.  
  234.  
  235. if (!is_myself("$rd")) {
  236. xlog("NOT MYSELF\n");
  237. append_hf("P-hint: outbound\r\n");
  238.  
  239. route(relay);
  240. }
  241.  
  242. # requests for my domain
  243.  
  244. if (is_method("PUBLISH|SUBSCRIBE")) {
  245. send_reply(503, "Service Unavailable");
  246. exit;
  247. }
  248.  
  249. if (is_method("REGISTER")) {
  250. xlog("registration received:\n AD: $ad \n DD: $dd \n FD: $fd\n");
  251. if ($fd =~ ".*thisdomain\.tld$") {
  252. xlog("registration to domain $fd on PBX\n");
  253. ds_select_dst(2,0);
  254. xlog("DU: $du\n");
  255. # t_relay();
  256. # exit;
  257. }
  258. if ($fd == "pbx.otherdomain.tld") {
  259. xlog("registration to Office PBX\n");
  260. ds_select_dst(1,0);
  261. # t_relay();
  262. # exit;
  263. }
  264. mid_registrar_save("location");
  265. switch ($retcode) {
  266. case 1:
  267. xlog("L_INFO", "forwarding REGISTER to main registrar...\n");
  268. # $ru = "sip:10.0.0.3:5070";
  269. if (!t_relay()) {
  270. send_reply(500, "Server Internal Error 1");
  271. }
  272. break;
  273. case 2:
  274. xlog("L_INFO", "REGISTER has been absorbed!\n");
  275. break;
  276. default:
  277. xlog("L_ERR", "mid-registrar error!\n");
  278. send_reply(500, "Server Internal Error 2");
  279. }
  280.  
  281. exit;
  282. # store the registration and generate a SIP reply
  283. # if (!save("location"))
  284. # xlog("failed to register AoR $tu\n");
  285. #
  286. # exit;
  287. }
  288.  
  289. if ($rU==NULL) {
  290. # request with no Username in RURI
  291. send_reply(484,"Address Incomplete");
  292. exit;
  293. }
  294.  
  295.  
  296.  
  297. # do lookup with method filtering
  298. if (!lookup("location","m")) {
  299. t_reply(404, "Not Found");
  300. exit;
  301. }
  302.  
  303. # when routing via usrloc, log the missed calls also
  304. do_accounting("log","missed");
  305. route(relay);
  306. }
  307.  
  308.  
  309. route[relay] {
  310. # for INVITEs enable some additional helper routes
  311. if (is_method("INVITE")) {
  312. t_on_branch("per_branch_ops");
  313. t_on_reply("handle_nat");
  314. t_on_failure("missed_call");
  315. }
  316.  
  317. if (!t_relay()) {
  318. send_reply(500,"Internal Error");
  319. }
  320. exit;
  321. }
  322.  
  323.  
  324.  
  325.  
  326. branch_route[per_branch_ops] {
  327. xlog("new branch at $ru\n");
  328. }
  329.  
  330.  
  331. onreply_route[handle_nat] {
  332. xlog("incoming reply (handling nat)\n");
  333. fix_nated_contact();
  334. }
  335.  
  336.  
  337. failure_route[missed_call] {
  338. if (t_was_cancelled()) {
  339. exit;
  340. }
  341.  
  342. # uncomment the following lines if you want to block client
  343. # redirect based on 3xx replies.
  344. ##if (t_check_status("3[0-9][0-9]")) {
  345. ##t_reply(404,"Not found");
  346. ## exit;
  347. ##}
  348.  
  349.  
  350. }
  351.  
  352.  
  353.  
  354.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement