Skip to content

Instantly share code, notes, and snippets.

Created February 22, 2013 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5009704 to your computer and use it in GitHub Desktop.
Save anonymous/5009704 to your computer and use it in GitHub Desktop.
#
# $Id: opensips.cfg 8758 2012-02-29 11:59:26Z vladut-paiu $
#
# OpenSIPS residential configuration script
# by OpenSIPS Solutions <team@opensips-solutions.com>
#
# This script was generated via "make menuconfig", from
# the "Residential" scenario.
# You can enable / disable more features / functionalities by
# re-generating the scenario with different options.#
#
# Please refer to the Core CookBook at:
# http://www.opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#
####### Global Parameters #########
log_facility=LOG_LOCAL0
log_name="opensips"
fork=yes
children=4
/* uncomment the following lines to enable debugging */
debug=9
#fork=no
#log_stderror=yes
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
#auto_aliases=no
alias=63.246.156.40
mhomed=1
port=5060
disable_tcp=yes
disable_tls=yes
####### Modules Section ########
#set module path
mpath="/usr/local/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timer", 5)
modparam("tm", "fr_inv_timer", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
#modparam("rr", "append_fromtag", 0)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 1)
#### 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)
# loadmodule "mi_xmlrpc.so"
# modparam("mi_xmlrpc", "port", 8000)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
loadmodule "db_mysql.so"
#loadmodule "auth.so"
#loadmodule "auth_db.so"
#modparam("auth_db", "calculate_ha1", yes)
#modparam("auth_db", "password_column", "password")
#modparam("auth_db", "db_url", "mysql://opensips:open321sips@192.168.1.23/opensips")
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", 10)
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url", "mysql://opensips:open321sips@192.168.1.23/opensips")
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", 7)
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
#### ACCounting module
loadmodule "acc.so"
#/* what special events should be accounted ? */
#modparam("acc", "early_media", 0)
#modparam("acc", "report_cancels", 0)
#/* by default we 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)
#modparam("acc", "failed_transaction_flag", 3)
#/* account triggers (flags) */
#modparam("acc", "log_flag", 1)
#modparam("acc", "log_missed_flag", 2)
#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)
modparam("acc", "db_extra", "from_did=$avp(s:from_did); to_did=$avp(s:to_did); carrier=$avp(s:provider); direction=$avp(s:direction);src_ip=$si;dst_ip=$rd")
#### NAT HELPER module
loadmodule "nathelper.so"
loadmodule "rtpproxy.so"
#
modparam("rtpproxy", "rtpproxy_sock", "udp:63.246.156.xx:9000")
modparam("rtpproxy", "rtpproxy_disable_tout", 20)
loadmodule "dialog.so"
loadmodule "uac_auth.so"
loadmodule "uac.so"
loadmodule "dispatcher.so"
loadmodule "avpops.so"
loadmodule "siptrace.so"
loadmodule "permissions.so"
loadmodule "textops.so"
loadmodule "cfgutils.so"
loadmodule "drouting.so"
# ----- drouting params -----
modparam("drouting", "gw_attrs_avp", '$avp(s:provider)')
modparam("dispatcher|permissions|drouting", "db_url", "mysql://opensips:open321sips@192.168.1.23/opensips")
modparam("siptrace|acc", "db_url", "mysql://opensips:open321sips@192.168.1.23/opensips")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_from", "sip:proxy@vcomservices.com")
modparam("dispatcher", "ds_ping_interval", 60)
modparam("dispatcher", "ds_probing_threshhold", 3)
modparam("dispatcher", "ds_probing_mode", 0)
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "dst_avp", "$avp(i:271)")
modparam("dispatcher", "grp_avp", "$avp(i:273)")
modparam("dispatcher", "attrs_avp", "$avp(s:attr)")
modparam("dispatcher", "cnt_avp", "$avp(i:274)")
modparam("dispatcher", "options_reply_codes", "404")
modparam("avpops", "db_url", "mysql://opensips:open321sips@192.168.1.23/opensips")
# ----- dialog params -----
modparam("dialog", "profiles_no_value", "inbound ; outbound")
# ----- sip trace params -----
modparam("siptrace", "trace_flag", 22)
modparam("siptrace", "trace_on", 1)
modparam("siptrace", "enable_ack_trace", 1)
####### Routing Logic ########
# main request routing logic
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
setflag(1); # do accounting ...
setflag(3); # ... even if the transaction fails
} else if (is_method("INVITE")) {
if(has_body("application/sdp")) {
rtpproxy_offer("FACII");
}
# 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(1);
} else {
xlog("L_INFO","NOT A LOOSE ROUTE****************************************");
if ( is_method("ACK") ) {
xlog("L_INFO","IN 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;
}
#initial requests
create_dialog();
if (is_method("INVITE")) {
trace_dialog();
$avp(s:from_did)=$fU;
if ($fU =~ "^\+1.*") {
$avp(s:from_did) = $(avp(s:from_did){s.substr,2,0});
$avp(s:from_uri) = "sip:" + $avp(s:from_did) + "@" + $si;
xlog("L_INFO","New FROM DID: $avp(s:from_did) NEW FROM URI: $avp(s:from_uri)\n");
uac_replace_from("$avp(s:from_did)","$avp(s:from_uri)");
}
if (!is_present_hf("Remote-Party-ID")) {
append_hf("Remote-Party-ID: \"$avp(s:from_did)\" <sip:$avp(s:from_did)@$rd>;privacy=off;screen=yes\r\n");
} else {
remove_hf("Remote-Party-ID");
append_hf("Remote-Party-ID: \"$avp(s:from_did)\" <sip:$avp(s:from_did)@$rd>;privacy=off;screen=yes\r\n");
}
$avp(s:to_did)=$rU;
if ($rU =~ "^\+1.*") {
$avp(s:to_did) = $(avp(s:to_did){s.substr,2,0});
$avp(s:to_uri) = "sip:" + $avp(s:to_did) + "@" + $si;
xlog("L_INFO","New TO DID: $avp(s:to_did) NEW TO URI: $avp(s:to_uri)\n");
uac_replace_to("$avp(s:to_did)","$avp(s:to_uri)");
strip(2);
}
}
if (method == "BYE" || method == "CANCEL")
unforce_rtp_proxy();
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans())
t_relay();
exit;
}
t_check_trans();
if (is_method("ACK") && has_body("application/sdp"))
rtpproxy_answer();
if (is_method("OPTIONS")) {
usleep("500");
if(!has_body("application/sdp")) {
sl_send_reply("200","OK");
}
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();
# account only INVITEs
if (is_method("INVITE")) {
setflag(1); # do accounting
}
if (!uri==myself) {
#append_hf("P-hint: outbound\r\n");
#route(1);
sl_send_reply("503","Relay Denied");
exit;
}
# requests for my domain
#if (is_method("PUBLISH|SUBSCRIBE"))
#{
# sl_send_reply("503", "Service Unavailable");
# exit;
#}
#if (is_method("REGISTER"))
#{
#
# if ( 0 ) setflag(7);
# if (!save("location"))
# sl_reply_error();
# exit;
#}
if ($rU==NULL) {
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
################### Here we apply routing logic
if (is_method("INVITE")) {
#$avp(s:group) = get_source_group();
get_source_group("$avp(s:group)");
xlog("L_INFO","GROIUP: $avp(s:group)");
if(has_body("application/sdp")) {
rtpproxy_offer("FACII");
if(search("X-Phone-Extension")) {
xlog("L_INFO","Found X phone agent numer");
#start_recording();
}
}
# Reject if no group found for this call
if ($avp(s:group) == -1) {
sl_send_reply("503","Service Unavailable - NOPERM");
exit;
}
# Known troublemaker, reject outright
if ($avp(s:group) == 3) {
sl_send_reply("503","Service Unavailable - PERMDENY");
exit;
}
# Known BAD troublemaker, Just Ignore everything they send us (play dead)
if ($avp(s:group) == 4) {
drop();
exit;
}
### If we got this far, call shouldn't be rejected
### Check if it's inbound or outbound
if ($avp(s:group) == 2) {
$avp(s:direction)='Outbound';
route("OUTBOUND");
exit;
} else {
# This is an inbound call.. we need to retrieve context_info to know what media proxy to use
check_source_address("$avp(s:group)","$avp(s:provider)");
$avp(s:direction)='Inbound';
route("INBOUND");
}
}
sl_send_reply("503","Service Unavailable - ES");
exit;
}
local_route {
if(is_method("BYE")) {
acc_db_request("200","acc");
}
}
# do lookup with method filtering
#if (!lookup("location","m")) {
#
#
# t_newtran();
# t_reply("404", "Not Found");
# exit;
#}
#
## when routing via usrloc, log the missed calls also
#setflag(2);
#route(1);
route[OUTBOUND] {
#set_dlg_profile("outbound");
#xlog("L_INFO","In OUTBOUND Route block.. but I'm not really ready for outbound calls yet.. dying..") ;
if (!do_routing("10","1")){
sl_send_reply("404","Route Not Found -$rU-");
exit;
}
route("OUTBOUND_GO");
exit;
}
route[INBOUND] {
#set_dlg_profile("inbound");
## Look up DID in our DIDtable
xlog("L_INFO","Looking for DID $rU in didtable...\n");
xlog("Looking for DID $rU in didtable...\n");
#if (!avp_db_query("SELECT setid,prefix,postfix,enabled,description FROM didtable WHERE didid='$rU'","$avp(s:setid),$avp(s:prefix),$avp(s:postfix),$avp(s:enabled),$avp(s:description)")) {
if (!avp_db_query("SELECT 1 setid,null prefix,null postfix, 1 enabled, '' description FROM vcs_dev.pbx_DIDs WHERE number='$rU' and status='A'","$avp(s:setid),$avp(s:prefix),$avp(s:postfix),$avp(s:enabled),$avp(s:description)")) {
sl_send_reply("404","Not Found");
exit;
}
if (!is_avp_set("$avp(s:prefix)")) {
$avp(s:prefix) = "";
}
if (!is_avp_set("$avp(s:postfix)")) {
$avp(s:postfix) = "";
}
xlog("L_INFO","Found DID:$rU Type:$avp(s:setid) Prefix:$avp(s:prefix) Postfix:$avp(s:postfix) Enabled:$avp(s:enabled) Description: $avp(s:description)\n");
if ($avp(s:enabled) == 0) {
sl_send_reply("480","Account Temporarily Disabled");
exit;
}
xlog("L_INFO","Going to rewrite rU: Method:$rm rU:$rU Prefix:$avp(s:prefix) Postfix: $avp(s:postfix)\n");
$rU = $avp(s:prefix) + $rU + $avp(s:postfix);
if (!ds_select_domain("$avp(s:setid)","4")) {
sl_send_reply("503","Service Unavailable - NOSETID");
exit;
}
if (method==INVITE && !has_totag()) {
xlog("L_INFO","Engaging Media Proxy...\n");
}
route(1);
}
route[1] {
# for INVITEs enable some additional helper routes
if (is_method("INVITE")) {
t_on_branch("2");
t_on_reply("2");
t_on_failure("1");
}
if (!t_relay()) {
sl_reply_error();
};
exit;
}
route[OUTBOUND_GO] {
# for INVITEs enable some additional helper routes
if (is_method("INVITE")) {
t_on_failure("OUTBOUND_FAIL");
}
t_on_reply("2");
if (!t_relay()) {
sl_reply_error();
};
exit;
}
branch_route[2] {
xlog("new branch at $ru\n");
}
onreply_route[2] {
xlog("incoming reply\n");
if (!(status =~ "180" || status=~"183" || status=~"200"))
exit;
if(has_body("application/sdp")) {
rtpproxy_offer("FACII");
#if(search("X-Header")) {
# xlog("L_INFO","Found X phone agent numer");
#start_recording();
#}
}
#rtpproxy_offer("FACII");
#force_rtp_proxy("FA");
}
failure_route[1] {
xlog("L_INFO","In failure route $rc $rr");
if (t_was_cancelled()) {
exit;
}
if (t_check_status("408|484|5..|6..")) {
if (!ds_next_domain()) {
t_reply("503","No more gateways");
exit;
}
if (!t_relay()){
t_reply("500","Service Unavailable");
exit;
}
}
}
failure_route[OUTBOUND_FAIL] {
xlog("L_INFO","In OUTBOUND failure route $rc $rr");
if (t_was_cancelled()) {
exit;
}
if (t_check_status("408|403|404|5..|6..")) {
if (!use_next_gw()) {
# I couldn't get another.. crud
t_reply("503","Service Unavailable - NOMRGW");
exit;
} else {
route("OUTBOUND_GO");
exit;
}
}
xlog("L_INFO","OUTBOUND Failure condition does not match a set condition.. passing thru..");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment