Resources.DocsTutRedirect History

Hide minor edits - Show changes to output

April 24, 2013, at 08: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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 05:52 PM by outcast -
Changed line 11 from:
You will also notice in this example the use of the function [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 05: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 05: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)

[@
#!/bin/sh

echo sip:+12125551212@domain.com
April 29, 2010, at 05: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 05:02 PM by outcast -
Changed line 11 from:
You will also notice in this example the use of the function [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 05:02 PM by outcast -
Changed line 11 from:
You will also notice in this example the use of the function [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 05:01 PM by outcast -
Changed line 11 from:
You will also notice in this example the use of the function [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 05: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 05: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:
# $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"
Changed lines 7-75 from:

# ----------------- 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;
}
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 [[http://www.opensips.org/html/docs/modules/1.4.x/exec.html#id228172 | 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 04: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 03:58 PM by outcast -
Added line 1:
!!!!SIP Redirect with script example
April 29, 2010, at 03: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 08:58 PM