Documentation

Documentation.Tutorials-Redirect History

Hide minor edits - Show changes to markup

May 16, 2013, at 06:13 PM by 109.99.235.212 -
Changed line 1 from:
to:
Documentation -> Tutorials -> SIP Redirect
May 09, 2013, at 04:33 PM by 79.118.227.150 -
Changed lines 1-2 from:

SIP Redirect with script example

to:
April 24, 2013, at 07:57 PM by 79.118.215.235 -
Added lines 1-38:

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


Page last modified on May 16, 2013, at 06:13 PM