Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 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=4
  22. xlog_level=4
  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. socket=udp:10.20.12.125:5060 # CUSTOMIZE ME
  37. socket=tcp:10.20.12.125:5060
  38. socket=tcp:10.20.12.124:5060 as 195.196.197.198 # CUSTOMIZE ME
  39. #socket=udp:10.20.12.124:5060
  40. #socket=tls:127.0.0.1:5061 # CUSTOMIZE ME
  41.  
  42. ####### Modules Section ########
  43.  
  44. #set module path
  45. mpath="/usr/local//lib64/opensips/modules/"
  46.  
  47. #### SIGNALING module
  48. loadmodule "signaling.so"
  49.  
  50. #### StateLess module
  51. loadmodule "sl.so"
  52.  
  53. #### Transaction Module
  54. loadmodule "tm.so"
  55. modparam("tm", "fr_timeout", 5)
  56. modparam("tm", "fr_inv_timeout", 30)
  57. modparam("tm", "restart_fr_on_each_reply", 0)
  58. modparam("tm", "onreply_avp_mode", 1)
  59.  
  60. #### Record Route Module
  61. loadmodule "rr.so"
  62. /* do not append from tag to the RR (no need for this script) */
  63. #modparam("rr", "append_fromtag", 1)
  64. #modparam("rr", "enable_double_rr", 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", "/tmp/opensips_fifo")
  75. modparam("mi_fifo", "fifo_mode", 0666)
  76.  
  77. #### MYSQL module
  78. loadmodule "db_mysql.so"
  79.  
  80. #### HTTPD module
  81. loadmodule "httpd.so"
  82. modparam("httpd", "port", 8888)
  83.  
  84. #### USeR LOCation module
  85. loadmodule "usrloc.so"
  86. modparam("usrloc", "nat_bflag", "NAT")
  87. modparam("usrloc", "working_mode_preset", "single-instance-sql-write-back")
  88. modparam("usrloc", "db_url",
  89. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  90.  
  91.  
  92. #### REGISTRAR module
  93. loadmodule "registrar.so"
  94. modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
  95. modparam("registrar", "received_avp", "$avp(received_nh)")/* uncomment the next line not to allow more than 10 contacts per AOR */
  96. #modparam("registrar", "max_contacts", 10)
  97.  
  98. #### ACCounting module
  99. loadmodule "acc.so"
  100. /* what special events should be accounted ? */
  101. modparam("acc", "early_media", 0)
  102. modparam("acc", "report_cancels", 0)
  103. /* by default we do not adjust the direct of the sequential requests.
  104. if you enable this parameter, be sure to enable "append_fromtag"
  105. in "rr" module */
  106. modparam("acc", "detect_direction", 0)
  107.  
  108. #### ALIAS module
  109. loadmodule "alias_db.so"
  110. modparam("alias_db", "db_url",
  111. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  112.  
  113. #### DOMAIN module
  114. loadmodule "domain.so"
  115. modparam("domain", "db_url",
  116. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  117. modparam("domain", "db_mode", 1) # Use caching
  118. modparam("auth_db|usrloc", "use_domain", 1)
  119.  
  120. #### NAT modules
  121. loadmodule "nathelper.so"
  122. modparam("nathelper", "natping_interval", 10)
  123. modparam("nathelper", "ping_nated_only", 1)
  124. modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG")
  125. modparam("nathelper", "sipping_from", "sip:pinger@127.0.0.1") #CUSTOMIZE ME
  126. modparam("nathelper", "received_avp", "$avp(received_nh)")
  127.  
  128. loadmodule "rtpengine.so"
  129. modparam("rtpengine", "rtpengine_sock", "udp:localhost:2223") # CUSTOMIZE ME
  130.  
  131. #### DYNAMMIC ROUTING module
  132. loadmodule "drouting.so"
  133. modparam("drouting", "db_url",
  134. "mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
  135.  
  136. #### MI_HTTP module
  137. loadmodule "mi_http.so"
  138.  
  139. loadmodule "proto_udp.so"
  140. loadmodule "proto_tcp.so" loadmodule "proto_tls.so"
  141. loadmodule "tls_mgm.so"
  142. modparam("tls_mgm","server_domain", "default")
  143. modparam("tls_mgm","match_ip_address", "[default]*")
  144. modparam("tls_mgm","verify_cert", "[default]1")
  145. modparam("tls_mgm","require_cert", "[default]0")
  146. modparam("tls_mgm","tls_method", "[default]TLSv1")
  147. modparam("tls_mgm","certificate", "[default]/etc/opensips/tls/user/user-cert.pem")
  148. modparam("tls_mgm","private_key", "[default]/etc/opensips/tls/user/user-privkey.pem")
  149. modparam("tls_mgm","ca_list", "[default]/etc/opensips/tls/user/user-calist.pem")
  150.  
  151. ####### Routing Logic ########
  152.  
  153. # main request routing logic
  154.  
  155. route{
  156.  
  157. # initial NAT handling; detect if the request comes from behind a NAT
  158. # and apply contact fixing
  159. force_rport();
  160. #if (nat_uac_test(23)) {
  161. if ($si=~'^10\.193\.') {
  162. if(remove_hf("Contact"))
  163. {
  164. # User Agent header removed
  165. append_hf("Contact: sip:$fU@195.74.132.102:5060;transport=tcp\r\n");
  166. }
  167. setflag("NAT");
  168. }
  169.  
  170. if (!mf_process_maxfwd_header(10)) {
  171. send_reply(483,"Too Many Hops");
  172. exit;
  173. }
  174.  
  175. if (has_totag()) {
  176.  
  177. # handle hop-by-hop ACK (no routing required)
  178. if ( is_method("ACK") && t_check_trans() ) {
  179. t_relay();
  180. exit;
  181. }
  182.  
  183. # sequential request within a dialog should
  184. # take the path determined by record-routing
  185. if ( !loose_route() ) {
  186. # we do record-routing for all our traffic, so we should not
  187. # receive any sequential requests without Route hdr.
  188. #send_reply(404,"Not here mate");
  189. #exit;
  190. xlog("loose routing failed\n");
  191. } else {
  192. xlog("loose routing success\n");
  193. }
  194.  
  195. if (is_method("BYE")) {
  196. # do accounting even if the transaction fails
  197. do_accounting("log","failed");
  198. }
  199.  
  200.  
  201. if (check_route_param("nat=yes"))
  202. setflag("NAT");
  203. # route it out to whatever destination was set by loose_route()
  204. # in $du (destination URI).
  205. route(relay);
  206. exit;
  207. }
  208.  
  209. # CANCEL processing
  210. if (is_method("CANCEL")) {
  211. if (t_check_trans())
  212. t_relay();
  213. exit;
  214. }
  215.  
  216. # absorb retransmissions, but do not create transaction
  217. t_check_trans();
  218.  
  219. if ( !(is_method("REGISTER") || is_from_gw() ) ) {
  220.  
  221. if (is_from_local()) {
  222. xlog("local call\n");
  223. } else {
  224. # if caller is not local, then called number must be local
  225.  
  226. if (!is_uri_host_local()) {
  227. send_reply(403,"Relay Forbidden");
  228. exit;
  229. }
  230. }
  231.  
  232. }
  233.  
  234. # preloaded route checking
  235. if (loose_route()) {
  236. xlog("L_ERR",
  237. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  238. if (!is_method("ACK"))
  239. send_reply(403,"Preload Route denied");
  240. exit;
  241. }
  242.  
  243. # record routing
  244. if (!is_method("REGISTER|MESSAGE"))
  245. record_route();
  246.  
  247. # account only INVITEs
  248. if (is_method("INVITE")) {
  249.  
  250. do_accounting("log");
  251. }
  252.  
  253.  
  254. if (!is_uri_host_local()) {
  255. append_hf("P-hint: outbound\r\n");
  256.  
  257. # if you have some interdomain connections via TLS
  258. ## CUSTOMIZE IF NEEDED
  259. ##if ($rd=="tls_domain1.net"
  260. ## || $rd=="tls_domain2.net"
  261. ##) {
  262. ## force_send_socket("tls:127.0.0.1:5061"); # CUSTOMIZE
  263. ##}
  264.  
  265. route(relay);
  266. }
  267.  
  268. # requests for my domain
  269.  
  270. if (is_method("PUBLISH|SUBSCRIBE")) {
  271. send_reply(503, "Service Unavailable");
  272. exit;
  273. }
  274.  
  275. if (is_method("REGISTER")) {
  276.  
  277. if ($socket_in(proto) == "tcp" || $socket_in(proto) == "tls")
  278. setflag("TCP_PERSISTENT");
  279. if (isflagset("NAT")) {
  280. setbflag("SIP_PING_FLAG");
  281. }
  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.  
  290. if ($rU==NULL) {
  291. # request with no Username in RURI
  292. send_reply(484,"Address Incomplete");
  293. exit;
  294. }
  295.  
  296.  
  297. # apply DB based aliases
  298. alias_db_lookup("dbaliases");
  299.  
  300.  
  301.  
  302.  
  303. if ($rU=~"^\+[1-9][0-9]+$") {
  304.  
  305. strip(1);
  306. if (!do_routing(0)) {
  307. send_reply(500,"No PSTN Route found");
  308. exit;
  309. }
  310.  
  311. route(relay);
  312. exit;
  313. }
  314.  
  315.  
  316. # do lookup with method filtering
  317. if (!lookup("location","m")) {
  318.  
  319.  
  320. t_reply(404, "Not Found");
  321. exit;
  322. }
  323.  
  324. if (isbflagset("NAT")) setflag("NAT");
  325.  
  326. # when routing via usrloc, log the missed calls also
  327. do_accounting("log","missed");
  328. route(relay);
  329. }
  330.  
  331.  
  332. route[relay] {
  333. # for INVITEs enable some additional helper routes
  334. if (is_method("INVITE")) {
  335.  
  336. if (isflagset("NAT")) {
  337. rtpengine_manage("media-address=195.74.132.102");
  338. } else {
  339.  
  340. rtpengine_manage();
  341.  
  342. }
  343.  
  344. t_on_branch("per_branch_ops");
  345. t_on_reply("handle_nat");
  346. t_on_failure("missed_call");
  347. }
  348.  
  349. if (isflagset("NAT")) {
  350. add_rr_param(";nat=yes");
  351. }
  352.  
  353. if (!t_relay()) {
  354. send_reply(500,"Internal Error");
  355. }
  356. exit;
  357. }
  358.  
  359.  
  360.  
  361.  
  362. branch_route[per_branch_ops] {
  363. xlog("new branch at $ru\n");
  364. }
  365.  
  366.  
  367. onreply_route[handle_nat] {
  368. #if (nat_uac_test(1))
  369. # fix_nated_contact();
  370. if ( isflagset("NAT") )
  371. rtpengine_manage("media-address=10.20.12.125");
  372. #rtpengine_manage();
  373. xlog("incoming reply\n");
  374. }
  375.  
  376.  
  377. failure_route[missed_call] {
  378. if (t_was_cancelled()) {
  379. exit;
  380. }
  381.  
  382. # uncomment the following lines if you want to block client
  383. # redirect based on 3xx replies.
  384. ##if (t_check_status("3[0-9][0-9]")) {
  385. ##t_reply(404,"Not found");
  386. ## exit;
  387. ##}
  388.  
  389.  
  390. }
  391.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement