mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
336 lines
7.4 KiB
INI
336 lines
7.4 KiB
INI
#
|
|
# $Id$
|
|
#
|
|
# 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 #########
|
|
|
|
debug=3
|
|
log_stderror=no
|
|
log_facility=LOG_LOCAL0
|
|
|
|
fork=yes
|
|
children=4
|
|
|
|
auto_aliases=no
|
|
|
|
disable_tcp=yes
|
|
disable_tls=yes
|
|
|
|
|
|
####### Modules Section ########
|
|
|
|
#set module path
|
|
mpath="/usr/lib/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)
|
|
|
|
#### 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_datagram.so"
|
|
modparam("mi_datagram", "socket_name", "udp:127.0.0.1:8020")
|
|
|
|
#### Eventdatagram module
|
|
loadmodule "event_datagram.so"
|
|
|
|
#### URI module
|
|
loadmodule "uri.so"
|
|
modparam("uri", "use_uri_table", 0)
|
|
|
|
#### USeR LOCation module
|
|
loadmodule "usrloc.so"
|
|
modparam("usrloc", "nat_bflag", "NAT")
|
|
modparam("usrloc", "db_mode", 0)
|
|
|
|
#### REGISTRAR module
|
|
loadmodule "registrar.so"
|
|
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
|
|
|
|
/* uncomment the next line not to allow more than 10 contacts per AOR */
|
|
#modparam("registrar", "max_contacts", 10)
|
|
|
|
#### DIALOG module
|
|
loadmodule "dialog.so"
|
|
modparam("dialog", "dlg_match_mode", 1)
|
|
modparam("dialog", "default_timeout", 21600) # 6 hours timeout
|
|
modparam("dialog", "db_mode", 0)
|
|
|
|
|
|
#### ACCounting module
|
|
loadmodule "acc.so"
|
|
/* what special events should be accounted ? */
|
|
modparam("acc", "early_media", 0)
|
|
modparam("acc", "report_cancels", 1)
|
|
modparam("acc", "cdr_flag", "CDR")
|
|
modparam("acc", "evi_flag", "CDR")
|
|
modparam("acc", "evi_missed_flag", "CDR")
|
|
modparam("acc", "evi_extra",
|
|
"cgr_reqtype=$avp(cgr_reqtype);
|
|
cgr_account=$avp(cgr_account);
|
|
cgr_subject=$avp(cgr_subject);
|
|
cgr_destination=$avp(cgr_destination);
|
|
originalUri=$ou")
|
|
|
|
#### CfgUtils module
|
|
loadmodule "cfgutils.so"
|
|
|
|
#### CacheDB Local
|
|
loadmodule "cachedb_local.so"
|
|
|
|
|
|
####### Routing Logic ########
|
|
|
|
startup_route {
|
|
subscribe_event("E_OPENSIPS_START", "udp:127.0.0.1:2020");
|
|
raise_event("E_OPENSIPS_START");
|
|
}
|
|
|
|
# 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(CDR); # do accounting ...
|
|
} else if (is_method("INVITE")) {
|
|
# 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(relay);
|
|
} else {
|
|
|
|
if ( is_method("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;
|
|
}
|
|
|
|
# CANCEL processing
|
|
if (is_method("CANCEL"))
|
|
{
|
|
if (t_check_trans())
|
|
t_relay();
|
|
exit;
|
|
}
|
|
|
|
t_check_trans();
|
|
|
|
if ( !(is_method("REGISTER") ) ) {
|
|
|
|
if (from_uri==myself)
|
|
|
|
{
|
|
|
|
} else {
|
|
# if caller is not local, then called number must be local
|
|
|
|
if (!uri==myself) {
|
|
send_reply("403","Rely forbidden");
|
|
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")) {
|
|
# create dialog with timeout
|
|
if ( !create_dialog("B") ) {
|
|
send_reply("500","Internal Server Error");
|
|
exit;
|
|
}
|
|
setflag(CDR);
|
|
route(CGR_HANDLER);
|
|
}
|
|
|
|
if (!uri==myself) {
|
|
append_hf("P-hint: outbound\r\n");
|
|
|
|
route(relay);
|
|
}
|
|
|
|
# requests for my domain
|
|
|
|
if (is_method("PUBLISH|SUBSCRIBE"))
|
|
{
|
|
sl_send_reply("503", "Service Unavailable");
|
|
exit;
|
|
}
|
|
|
|
if (is_method("REGISTER"))
|
|
{
|
|
if ( 0 ) setflag(TCP_PERSISTENT);
|
|
|
|
if (!save("location"))
|
|
sl_reply_error();
|
|
|
|
exit;
|
|
}
|
|
|
|
if ($rU==NULL) {
|
|
# request with no Username in RURI
|
|
sl_send_reply("484","Address Incomplete");
|
|
exit;
|
|
}
|
|
|
|
|
|
# do lookup with method filtering
|
|
if (!lookup("location","m")) {
|
|
t_newtran();
|
|
t_reply("404", "Not Found");
|
|
exit;
|
|
}
|
|
|
|
route(relay);
|
|
}
|
|
|
|
|
|
route[relay] {
|
|
if (!t_relay()) {
|
|
send_reply("500","Internal Error");
|
|
};
|
|
exit;
|
|
}
|
|
|
|
route[CGR_HANDLER] {
|
|
# These variables should be populated by script admin on need
|
|
$avp(cgr_reqtype)="rated";
|
|
$avp(cgr_account)=$fU;
|
|
$avp(cgr_subject)=$fU;
|
|
$avp(cgr_destination)=$rU;
|
|
switch ($avp(cgr_account)) {
|
|
case "1002":
|
|
$avp(cgr_reqtype)="postpaid";
|
|
break;
|
|
case "1003":
|
|
$avp(cgr_reqtype)="pseudoprepaid";
|
|
break;
|
|
}
|
|
# End of variables population
|
|
|
|
if $avp(cgr_reqtype)=="pseudoprepaid" || $avp(cgr_reqtype)=="prepaid" { #Make sure we got enough balance for the call
|
|
|
|
$avp(auth_keys) = "cgr_reqtype";
|
|
$avp(auth_vals) = $avp(cgr_reqtype);
|
|
$avp(auth_keys) = "callid";
|
|
$avp(auth_vals) = $ci;
|
|
$avp(auth_keys) = "from_tag";
|
|
$avp(auth_vals) = $ft;
|
|
$avp(auth_keys) = "cgr_account";
|
|
$avp(auth_vals) = $avp(cgr_account);
|
|
$avp(auth_keys) = "cgr_subject";
|
|
$avp(auth_vals) = $avp(cgr_subject);
|
|
$avp(auth_keys) = "cgr_destination";
|
|
$avp(auth_vals) = $avp(cgr_destination);
|
|
$avp(auth_keys) = "created";
|
|
$avp(auth_vals) = $Ts;
|
|
raise_event("E_CGR_AUTHORIZE", $avp(auth_keys), $avp(auth_vals));
|
|
|
|
$var(accid) = $ci+";"+$ft+";";
|
|
$var(rply_cgr_notify) = $var(accid)+"/"+"cgr_notify"; #Key in localcache for cgr_notify
|
|
$var(rply_cgr_maxdur) = $var(accid)+"/"+"cgr_maxdur"; #Key in localcache for cgr_maxdur
|
|
$var(ms) = 0;
|
|
while($var(ms) < 2000) { # Check for values set every 10 ms for maximum 2 seconds
|
|
if cache_fetch("local", "$var(rply_cgr_notify)", $avp(cgr_notify) ) $var(ms) = 2000; # Break out
|
|
$var(ms) = $var(ms) + 10;
|
|
usleep("10");
|
|
}
|
|
if $avp(cgr_notify) == NULL { # Cannot check it in switch
|
|
sl_send_reply("503","Prepaid controller error on notify");
|
|
exit;
|
|
}
|
|
switch ($avp(cgr_notify)) {
|
|
case "SERVER_ERROR":
|
|
sl_send_reply("503","Prepaid controller error");
|
|
exit;
|
|
case "INSUFFICIENT_FUNDS":
|
|
sl_send_reply("403", "Payment required");
|
|
exit;
|
|
}
|
|
if !cache_fetch("local", "$var(rply_cgr_maxdur)", $avp(cgr_maxdur) ) {
|
|
sl_send_reply("503","Prepaid controller error on maxdur");
|
|
exit;
|
|
}
|
|
$DLG_timeout=$avp(cgr_maxdur);
|
|
|
|
}
|
|
|
|
}
|