Documentation |
Documentation.Tutorials-Redirect HistoryHide minor edits - Show changes to output May 16, 2013, at 07:13 PM
by
- Changed line 1 from:
!![[Documentation.Index | Documentation]] -> [[Documentation.Tutorials | Tutorials ]] -> [[Documentation.Tutorials-Redirect | SIP Redirect]] to:
!!!!!Documentation -> [[Documentation.Tutorials | Tutorials ]] -> SIP Redirect May 09, 2013, at 05:33 PM
by
- Changed lines 1-2 from:
!SIP Redirect with script example to:
!![[Documentation.Index | Documentation]] -> [[Documentation.Tutorials | Tutorials ]] -> [[Documentation.Tutorials-Redirect | SIP Redirect]] ---- April 24, 2013, at 08:57 PM
by
- 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 [[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 |