Resources.DocsTutRedirect History

Hide minor edits - Show changes to markup

April 24, 2013, at 07:58 PM by 79.118.215.235 -
Changed lines 1-38 from:

SIP Redirect with script example

You will need to load the exec.so module so you can run external scripts

loadmodule "exec.so"

In this snippet I am restricting by IP address and by a IP range. You will notice that I used a regular expression to determine the IP range 192.168.0.0/16. You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" header to the returned SIP URI. You can also use pseudo variables in the exec_dset() function. In this example $tU (To Username) and $fU (From Username) are used.

route {
    if ( src_ip == 10.x.x.x || src_ip =~ "^192\.168\..*") {
        if(method == "INVITE") {
            exec_dset("/usr/local/bin/local_check $fU $tU");
            sl_send_reply("302","LCR Redirect");
        } else {
            route(1);
        }
    } else {
        sl_send_reply( "403", "You are not allowed here!" );
        exit;
    }
}

Now here is just a dummy script that echoes a SIP URI. You can make it any script you want but is needs to output a valid SIP URI to standard out: (IE. sip:+12125551212@domain.com)

#!/bin/sh

echo sip:+12125551212@domain.com

NOTE: To get this to work correctly with Asterisk you need to add "promiscredir=yes" to the general section of your sip.conf

to:

(:redirect Documentation.Tutorials-Redirect quiet=1 :)

April 29, 2010, at 04:52 PM by outcast -
Changed line 11 from:

You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" header to the returned SIP URI.

to:

You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" header to the returned SIP URI. You can also use pseudo variables in the exec_dset() function. In this example $tU (To Username) and $fU (From Username) are used.

April 29, 2010, at 04:41 PM by outcast -
Changed lines 36-38 from:

@]

to:

@]

NOTE: To get this to work correctly with Asterisk you need to add "promiscredir=yes" to the general section of your sip.conf

April 29, 2010, at 04:26 PM by outcast -
Added lines 27-35:

@]

Now here is just a dummy script that echoes a SIP URI. You can make it any script you want but is needs to output a valid SIP URI to standard out: (IE. sip:+12125551212@domain.com)

[@

  1. !/bin/sh

echo sip:+12125551212@domain.com

April 29, 2010, at 04:10 PM by Thomas - Indention
Changed lines 15-21 from:
        if ( src_ip == 10.x.x.x || src_ip =~ "^192\.168\..*") {
                if(method == "INVITE") {
                        exec_dset("/usr/local/thing5/bin/local_check $fU $tU");
                        sl_send_reply("302","LCR Redirect");
                } else {
                        route(1);
                }
to:
    if ( src_ip == 10.x.x.x || src_ip =~ "^192\.168\..*") {
        if(method == "INVITE") {
            exec_dset("/usr/local/bin/local_check $fU $tU");
            sl_send_reply("302","LCR Redirect");
Changed lines 20-21 from:
                        sl_send_reply( "403", "You are not allowed here!" );
                        exit;
to:
            route(1);
Changed lines 22-23 from:
to:
    } else {
        sl_send_reply( "403", "You are not allowed here!" );
        exit;
    }
Deleted line 26:
April 29, 2010, at 04:02 PM by outcast -
Changed line 11 from:

You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

to:

You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" header to the returned SIP URI.

April 29, 2010, at 04:02 PM by outcast -
Changed line 11 from:

You will also notice in this example the use of the function exec_dest(). This function calls an extern script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

to:

You will also notice in this example the use of the function exec_dest(). This function calls an external script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

April 29, 2010, at 04:01 PM by outcast -
Changed line 11 from:

You will also notice in this example the use of the function exec_dest(). This function call an extern script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

to:

You will also notice in this example the use of the function exec_dest(). This function calls an extern script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

April 29, 2010, at 04:00 PM by outcast -
Changed line 3 from:

You will need to load the exec.so module so you can run extern scripts

to:

You will need to load the exec.so module so you can run external scripts

April 29, 2010, at 04:00 PM by outcast -
Changed lines 1-4 from:

SIP Redirect with script example

to:

SIP Redirect with script example

You will need to load the exec.so module so you can run extern scripts

Deleted lines 5-51:
  1. $Id: opensips.cfg 6464 2009-12-24 08:00:54Z bogdan_iancu $
  2. OpenSIPS basic configuration script
  3. by Anca Vamanu <anca@voice-system.ro>
  4. Please refer to the Core CookBook at:
  5. http://www.opensips.org/index.php?n=Resources.DocsCookbooks
  6. for a explanation of possible statements, functions and parameters.
    1. Global Parameters #########

debug=0 log_stderror=no log_facility=LOG_LOCAL0

  1. fork=yes
  2. children=4
  3. port=5060
  4. listen=udp:10.210.2.92:5060

/* uncomment the following lines to enable debugging */

  1. debug=6
  2. fork=yes
  3. log_stderror=yes
    1. Modules Section ########
  4. set module path

mpath="/usr/local/thing5/lib/opensips/modules/"

/* uncomment next line for MySQL DB support */

  1. loadmodule "db_mysql.so"

loadmodule "signaling.so" loadmodule "sl.so" loadmodule "tm.so"

  1. loadmodule "rr.so"

loadmodule "maxfwd.so"

  1. loadmodule "usrloc.so"
  2. loadmodule "registrar.so"
  3. loadmodule "textops.so"

loadmodule "mi_fifo.so" loadmodule "uri.so" loadmodule "xlog.so" loadmodule "acc.so"

Changed lines 7-75 from:
  1. ----------------- setting module-specific parameters ---------------
  2. ----- mi_fifo params -----

modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")

  1. ----- rr params -----
  2. add value to ;lr param to cope with most of the UAs
  3. modparam("rr", "enable_full_lr", 1)
  4. do not append from tag to the RR (no need for this script)
  5. modparam("rr", "append_fromtag", 0)
  6. ----- registrar params -----

/* uncomment the next line not to allow more than 10 contacts per AOR */

  1. modparam("registrar", "max_contacts", 10)
  2. ----- usrloc params -----
  3. modparam("usrloc", "db_mode", 0)

/* uncomment the following lines if you want to enable DB persistency

   for location entries */
  1. modparam("usrloc", "db_mode", 2)
  2. modparam("usrloc", "db_url",
  3. "mysql://opensips:opensipsrw@localhost/opensips")
  4. ----- uri params -----

modparam("uri", "use_uri_table", 0)

  1. ----- acc params -----

/* what sepcial events should be accounted ? */ modparam("acc", "early_media", 1) modparam("acc", "report_ack", 1) modparam("acc", "report_cancels", 1) /* by default ww do not adjust the direct of the sequential requests.

   if you enable this parameter, be sure the enable "append_fromtag"
   in "rr" module */

modparam("acc", "detect_direction", 0) /* account triggers (flags) */ modparam("acc", "failed_transaction_flag", 3) modparam("acc", "log_flag", 1) modparam("acc", "log_missed_flag", 2) /* uncomment the following lines to enable DB accounting also */ modparam("acc", "db_flag", 1) modparam("acc", "db_missed_flag", 2)

  1. Routing Logic ########
  1. main request routing logic

route{

        if (!mf_process_maxfwd_header("10")) {
                sl_send_reply("483","Too Many Hops");
                exit;
        }

        if ( msg:len >=  2048 ) {
                sl_send_reply( "513", "Message too big" );
                return;
        }
to:

@]

In this snippet I am restricting by IP address and by a IP range. You will notice that I used a regular expression to determine the IP range 192.168.0.0/16. You will also notice in this example the use of the function exec_dest(). This function call an extern script and assumes that the script returns a SIP URI. Then sets the "Contact" to the return SIP URI.

[@ route {

Deleted lines 27-39:

}

route[1] {

        if ( ! t_relay() ) {
                sl_reply_error();
        }

}

failure_route[1] {

        if (t_was_cancelled()) {
                exit;
        }
April 29, 2010, at 03:00 PM by outcast -
Changed line 120 from:
        if ( src_ip == 10.240.2.40 || src_ip == 10.240.2.60 || src_ip == 10.210.2.243) {
to:
        if ( src_ip == 10.x.x.x || src_ip =~ "^192\.168\..*") {
April 29, 2010, at 02:58 PM by outcast -
Added line 1:

SIP Redirect with script example

April 29, 2010, at 02:58 PM by outcast -
Added lines 1-147:
# $Id: opensips.cfg 6464 2009-12-24 08:00:54Z bogdan_iancu $
#
# OpenSIPS basic configuration script
#     by Anca Vamanu <anca@voice-system.ro>
#
# Please refer to the Core CookBook at:
#      http://www.opensips.org/index.php?n=Resources.DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#


####### Global Parameters #########

debug=0
log_stderror=no
log_facility=LOG_LOCAL0

#fork=yes
#children=4
#port=5060
#listen=udp:10.210.2.92:5060

/* uncomment the following lines to enable debugging */
#debug=6
#fork=yes
#log_stderror=yes


####### Modules Section ########

#set module path
mpath="/usr/local/thing5/lib/opensips/modules/"

/* uncomment next line for MySQL DB support */
#loadmodule "db_mysql.so"
loadmodule "signaling.so"
loadmodule "sl.so"
loadmodule "tm.so"
#loadmodule "rr.so"
loadmodule "maxfwd.so"
#loadmodule "usrloc.so"
#loadmodule "registrar.so"
#loadmodule "textops.so"
loadmodule "mi_fifo.so"
loadmodule "uri.so"
loadmodule "xlog.so"
loadmodule "acc.so"
loadmodule "exec.so"

# ----------------- setting module-specific parameters ---------------


# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")


# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
#modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
#modparam("rr", "append_fromtag", 0)


# ----- registrar params -----
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)


# ----- usrloc params -----
#modparam("usrloc", "db_mode",   0)
/* uncomment the following lines if you want to enable DB persistency
   for location entries */
#modparam("usrloc", "db_mode",   2)
#modparam("usrloc", "db_url",
#       "mysql://opensips:opensipsrw@localhost/opensips")


# ----- uri params -----
modparam("uri", "use_uri_table", 0)


# ----- acc params -----
/* what sepcial events should be accounted ? */
modparam("acc", "early_media", 1)
modparam("acc", "report_ack", 1)
modparam("acc", "report_cancels", 1)
/* by default ww do not adjust the direct of the sequential requests.
   if you enable this parameter, be sure the enable "append_fromtag"
   in "rr" module */
modparam("acc", "detect_direction", 0)
/* account triggers (flags) */
modparam("acc", "failed_transaction_flag", 3)
modparam("acc", "log_flag", 1)
modparam("acc", "log_missed_flag", 2)
/* uncomment the following lines to enable DB accounting also */
modparam("acc", "db_flag", 1)
modparam("acc", "db_missed_flag", 2)



####### Routing Logic ########


# main request routing logic

route{

        if (!mf_process_maxfwd_header("10")) {
                sl_send_reply("483","Too Many Hops");
                exit;
        }

        if ( msg:len >=  2048 ) {
                sl_send_reply( "513", "Message too big" );
                return;
        }

        if ( src_ip == 10.240.2.40 || src_ip == 10.240.2.60 || src_ip == 10.210.2.243) {
                if(method == "INVITE") {
                        exec_dset("/usr/local/thing5/bin/local_check $fU $tU");
                        sl_send_reply("302","LCR Redirect");
                } else {
                        route(1);
                }
        } else {
                        sl_send_reply( "403", "You are not allowed here!" );
                        exit;
        }


}

route[1] {
        if ( ! t_relay() ) {
                sl_reply_error();
        }

}

failure_route[1] {
        if (t_was_cancelled()) {
                exit;
        }
}


Page last modified on April 24, 2013, at 07:58 PM