Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # OpenSIPS residential configuration script
- # by OpenSIPS Solutions <team@opensips-solutions.com>
- #
- # Please refer to the Core CookBook at:
- # http://www.opensips.org/Resources/DocsCookbooks
- # for a explanation of possible statements, functions and parameters.
- #
- ####### Global Parameters #########
- debug=3
- log_stderror=no
- log_facility=LOG_LOCAL0
- fork=yes
- children=4
- auto_aliases=no
- listen=udp:x.x.x.x:5060 # TODO: update with your local IP and port
- listen=ws:x.x.x.x:7080 # TODO: update with your local IP and port
- tcp_connection_lifetime=3605
- ####### Modules Section ########
- # set module path
- mpath="/usr/lib64/opensips/modules"
- #### SIGNALING module
- loadmodule "signaling.so"
- #### StateLess module
- loadmodule "sl.so"
- #### Transaction Module
- loadmodule "tm.so"
- modparam("tm", "fr_timeout", 5)
- modparam("tm", "fr_inv_timeout", 30)
- modparam("tm", "restart_fr_on_each_reply", 0)
- modparam("tm", "onreply_avp_mode", 1)
- #### Record Route Module
- loadmodule "rr.so"
- modparam("rr", "append_fromtag", 0)
- #### MAX ForWarD module
- loadmodule "maxfwd.so"
- #### SIP MSG OPerationS module
- loadmodule "sipmsgops.so"
- #### FIFO Management Interface
- loadmodule "mi_fifo.so"
- modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
- modparam("mi_fifo", "fifo_mode", 0666)
- #### URI module
- loadmodule "uri.so"
- modparam("uri", "use_uri_table", 0)
- #### USeR LOCation module
- loadmodule "usrloc.so"
- modparam("usrloc", "nat_bflag", "NAT")
- modparam("usrloc", "db_mode", 0)
- #### REGISTRAR module
- loadmodule "registrar.so"
- #### DIALOG module
- loadmodule "dialog.so"
- #### RTPengine protocol
- loadmodule "rtpengine.so"
- modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:60000")
- #### Nathelper protocol
- loadmodule "nathelper.so"
- modparam("registrar|nathelper", "received_avp", "$avp(rcv)")
- #### UDP protocol
- loadmodule "proto_udp.so"
- #### WebSocket protocol
- loadmodule "proto_ws.so"
- #### Topology Hiding
- loadmodule "topology_hiding.so"
- #### Authentication user
- loadmodule "db_mysql.so"
- loadmodule "auth.so"
- loadmodule "auth_db.so"
- #modparam("auth","username_spec","$avp(i:54)")
- #modparam("auth","password_spec","$avp(i:55)")
- #modparam("auth","calculate_ha1",1)
- modparam("auth_db", "calculate_ha1", 0)
- modparam("auth_db", "password_column", "ha1")
- modparam("auth_db", "db_url","mysql://opensips:opensipsrw@localhost/opensips")
- #### Alias DB
- loadmodule "alias_db.so"
- modparam("alias_db", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
- #### sipcapture module
- loadmodule "siptrace.so"
- modparam("siptrace", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
- modparam("siptrace", "trace_on", 1)
- modparam("siptrace", "trace_flag", "TRACE_FLAG")
- modparam("siptrace", "enable_ack_trace", 1)
- modparam("siptrace", "trace_to_database", 0)
- modparam("siptrace", "duplicate_uri", "sip:x.x.x.x:9060")
- modparam("siptrace", "duplicate_with_hep", 1)
- ####### Routing Logic ########
- # main request routing logic
- route{
- setflag(TRACE_FLAG);
- sip_trace();
- if (!mf_process_maxfwd_header("10")) {
- sl_send_reply("483","Too Many Hops");
- exit;
- }
- if (has_totag()) {
- if (topology_hiding_match()) {
- xlog("Succesfully matched this request to a topology hiding dialog. \n");
- xlog("Calller side callid is $ci \n");
- xlog("Callee side callid is $TH_callee_callid \n");
- t_relay();
- exit;
- }
- # sequential requests within a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- if (is_method("INVITE")) {
- # even if in most of the cases is useless, do RR for
- # re-INVITEs alos, as some buggy clients do change route set
- # during the dialog.
- record_route();
- }
- # route it out to whatever destination was set by loose_route()
- # in $du (destination URI).
- route(relay);
- } else {
- if ( is_method("ACK") ) {
- if ( t_check_trans() ) {
- # non loose-route, but stateful ACK; must be an ACK after
- # a 487 or e.g. 404 from upstream server
- t_relay();
- exit;
- } else {
- # ACK without matching transaction ->
- # ignore and discard
- exit;
- }
- }
- sl_send_reply("404","Not here");
- }
- exit;
- }
- # CANCEL processing
- if (is_method("CANCEL")) {
- if (t_check_trans())
- t_relay();
- exit;
- }
- t_check_trans();
- if (!is_method("REGISTER")) {
- if (from_uri!=myself) {
- # if caller is not local, then called number must be local
- if (!uri==myself) {
- send_reply("403","Rely forbidden");
- exit;
- }
- }
- }
- # preloaded route checking
- if (loose_route()) {
- xlog("L_ERR",
- "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
- if (!is_method("ACK"))
- sl_send_reply("403","Preload Route denied");
- exit;
- }
- # record routing
- if (!is_method("REGISTER|MESSAGE"))
- record_route();
- if (!uri==myself) {
- append_hf("P-hint: outbound\r\n");
- route(relay);
- }
- # requests for my domain
- if (is_method("PUBLISH|SUBSCRIBE")) {
- sl_send_reply("503", "Service Unavailable");
- exit;
- }
- # check if the clients are using WebSockets
- if ($rU=~"^08[0-9]+$"){
- if(!alias_db_lookup("dbaliases")){
- xlog("L_INFO", " Inbound call: R-URI=$rU DID Not found in dbaliases\n");
- } else {
- xlog("L_INFO", " Inbound call: DID found in dbaliases. Account ID is $rU\n");
- }
- }
- if (proto == WS)
- setflag(SRC_WS);
- # consider the client is behind NAT - always fix the contact
- fix_nated_contact();
- if (is_method("INVITE")){
- create_dialog();
- topology_hiding("UC");
- }
- #sip trunk NOC-FTEL
- if ($rU=~"^9[0-9]+$") {
- strip(1);
- $rd="x.x.x.x"; #CUSTOMIZE ME
- $rp=5060;
- route(relay);
- exit;
- }
- # sip trunk FTI
- if ($rU=~"^0[0-9]+$") {
- $rd="x.x.x.x"; #CUSTOMIZE ME
- $rp=5060;
- route(relay);
- exit;
- }
- if (is_method("REGISTER")) {
- # indicate that the client supports DTLS
- # so we know when he is called
- if (!www_authorize("", "subscriber")) {
- www_challenge("", "0");
- exit;
- };
- if (isflagset(SRC_WS))
- setbflag(DST_WS);
- fix_nated_register();
- if (!save("location"))
- sl_reply_error();
- exit;
- }
- if ($rU==NULL) {
- # request with no Username in RURI
- sl_send_reply("484","Address Incomplete");
- exit;
- }
- # do lookup with method filtering
- if (!lookup("location","m")) {
- t_newtran();
- t_reply("404", "Not Found");
- exit;
- }
- route(relay);
- }
- route[relay] {
- # for INVITEs enable some additional helper routes
- if (is_method("INVITE")) {
- t_on_branch("handle_nat");
- t_on_reply("handle_nat");
- } else if (is_method("BYE|CANCEL")) {
- rtpengine_delete();
- }
- if (!t_relay()) {
- send_reply("500","Internal Error");
- };
- exit;
- }
- branch_route[handle_nat] {
- if (!is_method("INVITE") || !has_body("application/sdp"))
- return;
- if (isflagset(SRC_WS) && isbflagset(DST_WS)){
- xlog("branch_route ==> isflagset(SRC_WS) && isbflagset(DST_WS)");
- $var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
- }
- else if (isflagset(SRC_WS) && !isbflagset(DST_WS)){
- xlog("branch_route ==> isflagset(SRC_WS) && !isbflagset(DST_WS)");
- $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
- }
- else if (!isflagset(SRC_WS) && isbflagset(DST_WS)){
- xlog("branch_route ==> !isflagset(SRC_WS) && isbflagset(DST_WS)");
- $var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
- }
- else if (!isflagset(SRC_WS) && !isbflagset(DST_WS)){
- xlog("branch_route ==> !isflagset(SRC_WS) && !isbflagset(DST_WS)");
- $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
- }
- rtpengine_offer("$var(rtpengine_flags)");
- }
- onreply_route[handle_nat] {
- fix_nated_contact();
- if (!has_body("application/sdp"))
- return;
- if (isflagset(SRC_WS) && isbflagset(DST_WS)){
- xlog("reply_route ==> isflagset(SRC_WS) && isbflagset(DST_WS)");
- $var(rtpengine_flags) = "ICE=force-relay DTLS=passive";
- }
- else if (isflagset(SRC_WS) && !isbflagset(DST_WS)){
- xlog("onreply_route ==> isflagset(SRC_WS) && !isbflagset(DST_WS)");
- $var(rtpengine_flags) = "UDP/TLS/RTP/SAVPF ICE=force";
- }
- else if (!isflagset(SRC_WS) && isbflagset(DST_WS)){
- xlog("onreply_route ==> !isflagset(SRC_WS) && isbflagset(DST_WS)");
- $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
- }
- else if (!isflagset(SRC_WS) && !isbflagset(DST_WS)){
- xlog("onreply_route ==> !isflagset(SRC_WS) && !isbflagset(DST_WS)");
- $var(rtpengine_flags) = "RTP/AVP replace-session-connection replace-origin ICE=remove";
- }
- rtpengine_answer("$var(rtpengine_flags)");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement