Advertisement
Guest User

opensips.cfg

a guest
Feb 22nd, 2016
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.75 KB | None | 0 0
  1. #
  2. # OpenSIPS residential configuration script
  3. # by OpenSIPS Solutions <team@opensips-solutions.com>
  4. #
  5. # Please refer to the Core CookBook at:
  6. # http://www.opensips.org/Resources/DocsCookbooks
  7. # for a explanation of possible statements, functions and parameters.
  8. #
  9.  
  10.  
  11. ####### Global Parameters #########
  12.  
  13. debug=3
  14. log_stderror=no
  15. log_facility=LOG_LOCAL0
  16.  
  17. fork=yes
  18. children=4
  19. auto_aliases=no
  20.  
  21. listen=udp:x.x.x.x:5060 # TODO: update with your local IP and port
  22. listen=ws:x.x.x.x:7080 # TODO: update with your local IP and port
  23.  
  24.  
  25. tcp_connection_lifetime=3605
  26. ####### Modules Section ########
  27.  
  28. # set module path
  29. mpath="/usr/lib64/opensips/modules"
  30.  
  31. #### SIGNALING module
  32. loadmodule "signaling.so"
  33.  
  34. #### StateLess module
  35. loadmodule "sl.so"
  36.  
  37. #### Transaction Module
  38. loadmodule "tm.so"
  39. modparam("tm", "fr_timeout", 5)
  40. modparam("tm", "fr_inv_timeout", 30)
  41. modparam("tm", "restart_fr_on_each_reply", 0)
  42. modparam("tm", "onreply_avp_mode", 1)
  43.  
  44. #### Record Route Module
  45. loadmodule "rr.so"
  46. modparam("rr", "append_fromtag", 0)
  47.  
  48. #### MAX ForWarD module
  49. loadmodule "maxfwd.so"
  50.  
  51. #### SIP MSG OPerationS module
  52. loadmodule "sipmsgops.so"
  53.  
  54. #### FIFO Management Interface
  55. loadmodule "mi_fifo.so"
  56. modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
  57. modparam("mi_fifo", "fifo_mode", 0666)
  58.  
  59. #### URI module
  60. loadmodule "uri.so"
  61. modparam("uri", "use_uri_table", 0)
  62.  
  63. #### USeR LOCation module
  64. loadmodule "usrloc.so"
  65. modparam("usrloc", "nat_bflag", "NAT")
  66. modparam("usrloc", "db_mode", 0)
  67.  
  68. #### REGISTRAR module
  69. loadmodule "registrar.so"
  70.  
  71. #### DIALOG module
  72. loadmodule "dialog.so"
  73.  
  74. #### RTPengine protocol
  75. loadmodule "rtpengine.so"
  76. modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:60000")
  77.  
  78. #### Nathelper protocol
  79. loadmodule "nathelper.so"
  80. modparam("registrar|nathelper", "received_avp", "$avp(rcv)")
  81.  
  82. #### UDP protocol
  83. loadmodule "proto_udp.so"
  84.  
  85. #### WebSocket protocol
  86. loadmodule "proto_ws.so"
  87.  
  88. #### Topology Hiding
  89. loadmodule "topology_hiding.so"
  90.  
  91. #### Authentication user
  92. loadmodule "db_mysql.so"
  93. loadmodule "auth.so"
  94. loadmodule "auth_db.so"
  95.  
  96. #modparam("auth","username_spec","$avp(i:54)")
  97. #modparam("auth","password_spec","$avp(i:55)")
  98. #modparam("auth","calculate_ha1",1)
  99.  
  100. modparam("auth_db", "calculate_ha1", 0)
  101. modparam("auth_db", "password_column", "ha1")
  102. modparam("auth_db", "db_url","mysql://opensips:opensipsrw@localhost/opensips")
  103.  
  104.  
  105. #### Alias DB
  106. loadmodule "alias_db.so"
  107. modparam("alias_db", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  108.  
  109. #### sipcapture module
  110. loadmodule "siptrace.so"
  111. modparam("siptrace", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
  112. modparam("siptrace", "trace_on", 1)
  113. modparam("siptrace", "trace_flag", "TRACE_FLAG")
  114. modparam("siptrace", "enable_ack_trace", 1)
  115. modparam("siptrace", "trace_to_database", 0)
  116. modparam("siptrace", "duplicate_uri", "sip:x.x.x.x:9060")
  117. modparam("siptrace", "duplicate_with_hep", 1)
  118.  
  119.  
  120. ####### Routing Logic ########
  121.  
  122. # main request routing logic
  123. route{
  124. setflag(TRACE_FLAG);
  125. sip_trace();
  126.  
  127. if (!mf_process_maxfwd_header("10")) {
  128. sl_send_reply("483","Too Many Hops");
  129. exit;
  130. }
  131.  
  132. if (has_totag()) {
  133. if (topology_hiding_match()) {
  134. xlog("Succesfully matched this request to a topology hiding dialog. \n");
  135. xlog("Calller side callid is $ci \n");
  136. xlog("Callee side callid is $TH_callee_callid \n");
  137. t_relay();
  138. exit;
  139. }
  140.  
  141. # sequential requests within a dialog should
  142. # take the path determined by record-routing
  143. if (loose_route()) {
  144. if (is_method("INVITE")) {
  145. # even if in most of the cases is useless, do RR for
  146. # re-INVITEs alos, as some buggy clients do change route set
  147. # during the dialog.
  148. record_route();
  149. }
  150.  
  151. # route it out to whatever destination was set by loose_route()
  152. # in $du (destination URI).
  153. route(relay);
  154. } else {
  155. if ( is_method("ACK") ) {
  156. if ( t_check_trans() ) {
  157. # non loose-route, but stateful ACK; must be an ACK after
  158. # a 487 or e.g. 404 from upstream server
  159. t_relay();
  160. exit;
  161. } else {
  162. # ACK without matching transaction ->
  163. # ignore and discard
  164. exit;
  165. }
  166. }
  167. sl_send_reply("404","Not here");
  168. }
  169. exit;
  170. }
  171.  
  172. # CANCEL processing
  173. if (is_method("CANCEL")) {
  174. if (t_check_trans())
  175. t_relay();
  176. exit;
  177. }
  178.  
  179. t_check_trans();
  180.  
  181. if (!is_method("REGISTER")) {
  182. if (from_uri!=myself) {
  183. # if caller is not local, then called number must be local
  184. if (!uri==myself) {
  185. send_reply("403","Rely forbidden");
  186. exit;
  187. }
  188. }
  189. }
  190.  
  191. # preloaded route checking
  192. if (loose_route()) {
  193. xlog("L_ERR",
  194. "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  195. if (!is_method("ACK"))
  196. sl_send_reply("403","Preload Route denied");
  197. exit;
  198. }
  199.  
  200. # record routing
  201. if (!is_method("REGISTER|MESSAGE"))
  202. record_route();
  203.  
  204. if (!uri==myself) {
  205. append_hf("P-hint: outbound\r\n");
  206. route(relay);
  207. }
  208.  
  209. # requests for my domain
  210. if (is_method("PUBLISH|SUBSCRIBE")) {
  211. sl_send_reply("503", "Service Unavailable");
  212. exit;
  213. }
  214.  
  215. # check if the clients are using WebSockets
  216. if ($rU=~"^08[0-9]+$"){
  217. if(!alias_db_lookup("dbaliases")){
  218. xlog("L_INFO", " Inbound call: R-URI=$rU DID Not found in dbaliases\n");
  219. } else {
  220. xlog("L_INFO", " Inbound call: DID found in dbaliases. Account ID is $rU\n");
  221. }
  222. }
  223.  
  224. if (proto == WS)
  225. setflag(SRC_WS);
  226.  
  227. # consider the client is behind NAT - always fix the contact
  228. fix_nated_contact();
  229.  
  230. if (is_method("INVITE")){
  231. create_dialog();
  232.  
  233. topology_hiding("UC");
  234. }
  235.  
  236. #sip trunk NOC-FTEL
  237. if ($rU=~"^9[0-9]+$") {
  238. strip(1);
  239. $rd="x.x.x.x"; #CUSTOMIZE ME
  240. $rp=5060;
  241. route(relay);
  242. exit;
  243. }
  244. # sip trunk FTI
  245. if ($rU=~"^0[0-9]+$") {
  246. $rd="x.x.x.x"; #CUSTOMIZE ME
  247. $rp=5060;
  248. route(relay);
  249. exit;
  250. }
  251.  
  252. if (is_method("REGISTER")) {
  253.  
  254. # indicate that the client supports DTLS
  255. # so we know when he is called
  256. if (!www_authorize("", "subscriber")) {
  257. www_challenge("", "0");
  258. exit;
  259. };
  260.  
  261. if (isflagset(SRC_WS))
  262. setbflag(DST_WS);
  263.  
  264. fix_nated_register();
  265. if (!save("location"))
  266. sl_reply_error();
  267.  
  268. exit;
  269. }
  270.  
  271. if ($rU==NULL) {
  272. # request with no Username in RURI
  273. sl_send_reply("484","Address Incomplete");
  274. exit;
  275. }
  276.  
  277.  
  278. # do lookup with method filtering
  279. if (!lookup("location","m")) {
  280. t_newtran();
  281. t_reply("404", "Not Found");
  282. exit;
  283. }
  284.  
  285. route(relay);
  286. }
  287.  
  288. route[relay] {
  289. # for INVITEs enable some additional helper routes
  290. if (is_method("INVITE")) {
  291. t_on_branch("handle_nat");
  292. t_on_reply("handle_nat");
  293. } else if (is_method("BYE|CANCEL")) {
  294. rtpengine_delete();
  295. }
  296.  
  297. if (!t_relay()) {
  298. send_reply("500","Internal Error");
  299. };
  300. exit;
  301. }
  302.  
  303. branch_route[handle_nat] {
  304.  
  305. if (!is_method("INVITE") || !has_body("application/sdp"))
  306. return;
  307.  
  308. if (isflagset(SRC_WS) && isbflagset(DST_WS)){
  309. xlog("branch_route ==> isflagset(SRC_WS) && isbflagset(DST_WS)");
  310. $var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
  311. }
  312. else if (isflagset(SRC_WS) && !isbflagset(DST_WS)){
  313. xlog("branch_route ==> isflagset(SRC_WS) && !isbflagset(DST_WS)");
  314. $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
  315. }
  316. else if (!isflagset(SRC_WS) && isbflagset(DST_WS)){
  317. xlog("branch_route ==> !isflagset(SRC_WS) && isbflagset(DST_WS)");
  318. $var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
  319. }
  320. else if (!isflagset(SRC_WS) && !isbflagset(DST_WS)){
  321. xlog("branch_route ==> !isflagset(SRC_WS) && !isbflagset(DST_WS)");
  322. $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
  323. }
  324.  
  325. rtpengine_offer("$var(rtpengine_flags)");
  326. }
  327.  
  328. onreply_route[handle_nat] {
  329.  
  330. fix_nated_contact();
  331. if (!has_body("application/sdp"))
  332. return;
  333.  
  334. if (isflagset(SRC_WS) && isbflagset(DST_WS)){
  335. xlog("reply_route ==> isflagset(SRC_WS) && isbflagset(DST_WS)");
  336. $var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
  337. }
  338. else if (isflagset(SRC_WS) && !isbflagset(DST_WS)){
  339. xlog("onreply_route ==> isflagset(SRC_WS) && !isbflagset(DST_WS)");
  340. $var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
  341. }
  342. else if (!isflagset(SRC_WS) && isbflagset(DST_WS)){
  343. xlog("onreply_route ==> !isflagset(SRC_WS) && isbflagset(DST_WS)");
  344. $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
  345. }
  346. else if (!isflagset(SRC_WS) && !isbflagset(DST_WS)){
  347. xlog("onreply_route ==> !isflagset(SRC_WS) && !isbflagset(DST_WS)");
  348. $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
  349. }
  350.  
  351. rtpengine_answer("$var(rtpengine_flags)");
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement