Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####### Global Parameters #########
- debug=5
- log_stderror=yes
- log_facility=LOG_LOCAL7
- log_name="ckswitch"
- fork=yes
- children=8
- /* uncomment the following lines to enable debugging */
- #debug=6
- #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=yes
- #disable_core_dump=no
- sip_warning=yes
- #server_signature=no
- server_header="Server: Residencial Gateway v1.8.2"
- user_agent_header="User-Agent: Residencial Gateway v1.8.2"
- listen=udp:5.104.224.33:5060
- #listen=udp:192.168.150.129:5060
- tos=IPTOS_LOWDELAY
- ######################################################################
- ## SIP
- ######################################################################
- #check_via=0
- #! disable_503_translation=no
- #disable_stateless_fwd=no
- disable_tcp=yes
- # disable_tls=no
- #! reply_to_via=1
- ######################################################################
- ## TLS
- ######################################################################
- #disable_tls=yes
- # listen=tls:your_IP:5061
- # tls_verify_server=1
- # tls_verify_client=1
- # tls_require_client_certificate=0
- # tls_method=TLSv1
- # tls_certificate="/usr/local/etc/opensips/tls/user/user-cert.pem"
- # tls_private_key="/usr/local/etc/opensips/tls/user/user-privkey.pem"
- # tls_ca_list="/usr/local/etc/opensips/tls/user/user-calist.pem"
- ######################################################################
- ## Destination Blacklist
- ######################################################################
- # dst_blacklist=gw:{( tcp , 192.168.2.100 , 5060 , "" ),( any , 192.168.2.101 , 0 , "" )}
- # dst_blacklist=net_filter2:{ !( any , 192.168.30.0/255.255.255.0 , 0 , "" )}
- ######################################################################
- ## Attribute Value Pairs
- ######################################################################
- # avp_aliases="uuid=I:660;email=s:email_addr;fwd=i:753"
- ######################################################################
- /* 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
- ######################################################################
- ## Module Loading
- ######################################################################
- ####### Modules Section ########
- #set module path
- mpath="/usr/src/opensips-1.8.2-tls/modules/"
- #mpath="/usr/local/lib/opensips/modules/"
- #### DB MySQL module
- loadmodule "db_mysql.so"
- ### BD Virtual #####################################
- loadmodule "db_virtual.so"
- modparam("db_virtual", "db_max_consec_retrys", 5)
- modparam("db_virtual", "db_urls", "define set1 FAILOVER") # Failover db PARALLEL ROUND
- modparam("db_virtual", "db_urls","mysql://root:XXXXXXXXXX@localhost/opensips") # Set 1
- #modparam("db_virtual", "db_urls","mysql://root:@localhost/opensips") # Set 1
- ###############Define set 2 and then database connection####################################
- ##############################################################################################
- #### SIGNALING module
- loadmodule "signaling.so"
- #### StateLess module
- loadmodule "sl.so"
- #### Transaction Module
- loadmodule "tm.so"
- modparam("tm", "fr_timer", 10)
- modparam("tm", "wt_timer", 10)
- modparam("tm", "fr_inv_timer", 60)
- modparam("tm", "onreply_avp_mode", 1)
- modparam("tm", "fr_timer_avp", "$avp(4)")
- modparam("tm", "fr_inv_timer_avp", "$avp(5)")
- #### Record Route Module
- loadmodule "rr.so"
- modparam("rr", "add_username", 1)
- /* do not append from tag to the RR (no need for this script) */
- modparam("rr", "append_fromtag", 1)
- modparam("rr", "enable_double_rr", 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", "/var/run/opensips_fifo")
- modparam("mi_fifo", "fifo_mode", 0666)
- #### Datagram Management Interface
- loadmodule "mi_datagram.so"
- modparam("mi_datagram", "socket_name", "/var/run/opensips.sock")
- #### URI module
- loadmodule "uri.so"
- modparam("uri", "db_url", "virtual://set1")
- modparam("uri", "use_uri_table", 1)
- #### PERMISSIONS module
- loadmodule "permissions.so"
- modparam("permissions", "db_url","virtual://set1") # CUSTOMIZE ME
- modparam("permissions", "address_table", "address")
- modparam("permissions", "mask_col", "mask")
- #modparam("permissions", "check_all_branches", 1)
- #### AUTHentication modules
- loadmodule "auth.so"
- #### AUTHentication DB modules
- loadmodule "auth_db.so"
- modparam("auth_db", "calculate_ha1", 1)
- modparam("auth_db", "load_credentials", "")
- modparam("auth_db", "password_column", "password")
- modparam("auth_db", "db_url","virtual://set1") # CUSTOMIZE ME
- #### USeR LOCation module
- loadmodule "usrloc.so"
- modparam("usrloc", "db_mode", 2)
- modparam("usrloc", "nat_bflag", 6)
- modparam("usrloc", "cseq_delay", 10)
- modparam("usrloc", "db_url", "virtual://set1") # CUSTOMIZE ME
- #### NAT Travesal
- loadmodule "nat_traversal.so"
- #### NAT Helper module
- loadmodule "nathelper.so"
- #modparam("nathelper", "sipping_bflag", 6)
- modparam("nathelper", "ping_nated_only", 0)
- modparam("nathelper", "natping_interval", 10)
- modparam("nathelper", "natping_processes", 4)
- modparam("nathelper", "received_avp", "$avp(rcv)")
- #modparam("nathelper", "sipping_from", "sip:[email protected]:5065")
- #### REGISTRAR module
- loadmodule "registrar.so"
- modparam("registrar", "min_expires", 300)
- modparam("registrar", "max_expires", 300)
- modparam("registrar", "case_sensitive", 1)
- /* uncomment the next line not to allow more than 10 contacts per AOR */
- #modparam("registrar", "max_contacts", 10)
- modparam("registrar", "default_expires", 300)
- modparam("registrar", "tcp_persistent_flag", 10)
- modparam("registrar", "received_avp", "$avp(rcv)")
- #### ALIAS module
- loadmodule "alias_db.so"
- modparam("alias_db", "db_url", "virtual://set1") # CUSTOMIZE ME
- #### DOMAIN module
- loadmodule "domain.so"
- modparam("domain", "db_url", "virtual://set1") # CUSTOMIZE ME
- modparam("domain", "db_mode", 1) # Use caching
- modparam("auth_db|usrloc|uri", "use_domain", 1)
- #### Dialog module
- loadmodule "dialog.so"
- modparam("dialog", "db_mode", 1)
- modparam("dialog", "dlg_match_mode", 1)
- modparam("dialog", "default_timeout", 3540) # 6 hours timeout
- modparam("dialog", "dlg_extra_hdrs", "Hint: destination unreachable\r\n")
- modparam("dialog", "db_url","virtual://set1") # CUSTOMIZE ME
- # dialog profiles
- modparam("dialog", "profiles_with_value", "trunkCalls")
- modparam("dialog", "timeout_avp", "$avp(timeout2)")
- #### DIALPLAN module
- loadmodule "dialplan.so"
- modparam("dialplan", "db_url", "virtual://set1") # CUSTOMIZE ME
- #### DYNAMMIC ROUTING module
- loadmodule "drouting.so"
- modparam("drouting", "db_url", "virtual://set1") # CUSTOMIZE ME
- modparam("drouting", "use_domain", 1)
- modparam("drouting", "drd_table", "dr_gateways")
- modparam("drouting", "drr_table", "dr_rules")
- modparam("drouting", "drg_table", "dr_groups")
- modparam("drouting", "drc_table", "dr_carriers")
- modparam("drouting", "drg_user_col", "username")
- modparam("drouting", "drg_domain_col", "domain")
- modparam("drouting", "drg_grpid_col", "groupid")
- modparam("drouting", "force_dns", 1)
- #frequency of probing per paramete in seconds
- modparam("drouting", "probing_interval", 120)
- modparam("drouting", "probing_method", "OPTIONS")
- modparam("drouting", "probing_from", "sip:pinger@opensips")
- modparam("drouting", "probing_reply_codes", "501, 403,404,487")
- modparam("drouting", "use_domain", 1)
- modparam("drouting", "gw_attrs_avp", '$avp(gw_attrs)')
- modparam("drouting", "gw_id_avp", '$avp(gw_id)')
- # XML RPC module
- loadmodule "mi_xmlrpc.so"
- modparam("mi_xmlrpc", "log_file", "/var/log/openser-xmlrpc.log")
- modparam("mi_xmlrpc", "port", 8000)
- modparam("mi_xmlrpc", "reply_option", 0)
- modparam("mi_xmlrpc", "buffer_size", 8192)
- # SIP TRACE module
- loadmodule "siptrace.so"
- modparam("siptrace", "db_url", "virtual://set1") # CUSTOMIZE ME
- modparam("siptrace", "traced_user_avp", "$avp(traced_user)")
- modparam("siptrace", "trace_on", 0)
- modparam("siptrace", "trace_flag", 20) #22
- # TEXT OPtionS
- loadmodule "textops.so"
- ################## Mediaproxy####################################
- loadmodule "mediaproxy.so"
- modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
- modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
- modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
- # Call Control module
- #loadmodule "call_control.so"
- #modparam("call_control", "prepaid_account_flag", 8) #if flag>=0 this is a prepaid account#
- #modparam("call_control", "disable", 0)
- #modparam("call_control", "canonical_uri_avp", "$avp(can_uri)")
- #modparam("call_control", "signaling_ip_avp", "$avp(signaling_ip)")
- #### AVPOPS module
- loadmodule "avpops.so"
- modparam("avpops", "db_url", "virtual://set1")
- modparam("avpops", "avp_table", "usr_preferences")
- modparam("avpops", "use_domain", 1)
- modparam("avpops", "uuid_column", "uuid")
- modparam("avpops", "username_column", "username")
- modparam("avpops", "domain_column", "domain")
- modparam("avpops", "attribute_column", "attribute")
- modparam("avpops", "value_column", "value")
- modparam("avpops", "type_column", "type")
- #modparam("avpops", "avp_aliases", "c_uri" )
- #### ACCounting module
- loadmodule "acc.so"
- modparam("acc", "early_media", 0)
- modparam("acc", "report_cancels", 1)
- /* 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", 1)
- modparam("acc", "log_level", 1)
- /* account triggers (flags) */
- modparam("acc", "db_flag", 1)
- modparam("acc", "db_missed_flag", 2)
- modparam("acc", "log_missed_flag", 2)
- modparam("acc", "failed_transaction_flag", 3)
- modparam("acc", "cdr_flag", 4)
- modparam("acc", "db_table_acc", "acc")
- modparam("acc", "db_table_missed_calls", "missed_calls")
- modparam("acc", "db_url","virtual://set1") # CUSTOMIZE ME
- modparam("acc", "db_extra_bye", "timeout=$dlg_val(timeout)")
- modparam("acc", "multi_leg_info","leg_src=$avp(src);leg_dst=$avp(dst)")
- modparam("acc", "db_extra", "from_uri=$ct; to_uri=$tu;ani=$fU; dest=$tU; via=$rd ;source=$si;gateway=$avp(gw_id);uaA=$hdr(User-Agent);uaB=$hdr(Server);PDD=$var(setup_time);rate=$avp(rate);cusid=$avp(Cusid);cost=$avp(cost);dstname=$avp(destination);dstprefix=$avp(prefix)") #Extra data ;
- ####### Routing Logic ########
- # main request routing logic
- route {
- if (!mf_process_maxfwd_header("10")) {
- sl_send_reply("483","Too Many Hops");
- exit;
- }
- if (msg:len > max_len) {
- sl_send_reply("513","Message Too Big");
- exit;
- };
- if(!(is_method("INVITE|ACK|CANCEL|BYE|UPDATE|OPTIONS|INFO"))) {
- xlog("L_INFO", ">>>>> Rejecting method '$rm' from '$fu' to '$ru' - User-Agent: $ua <<<<<\n");
- sl_send_reply("405","Method Not Allowed");
- exit;
- }
- $avp(tmp) = $Ts ; # store the current time (at request processing)
- #xlog("tmp timr-----$avp(tmp)--------\n");
- if (nat_uac_test("23")) {
- if (is_method("REGISTER")) {
- fix_nated_register();
- } else {
- fix_nated_contact();
- }
- setflag(5);
- };
- force_rport();
- ######################Permission granted###############################################
- if (!(is_method("REGISTER") || is_from_gw())) {
- $avp(ip) = $si;
- $avp(port) = 5060;
- $avp(proto) = $proto;
- # this meens that the Group 1 is a Permission garanted and others Permission denied.
- #check_address("1", related to address table group value 1
- if (check_address("1","$avp(ip)","$avp(port)","$avp(proto)","$avp(10)", "") ) {
- /* Get Customer ID */
- avp_db_query("SELECT `id` FROM `address` WHERE `context_info` ='$avp(10)' LIMIT 1", "$avp(Cusid)");
- xlog("L_INFO", "##############################Debug Customer ID:$avp(Cusid)/IP:$si##############################\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Call Start\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Permission:OK-\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Customer Prefix:$avp(10)\n");
- # request comes from trunks
- xlog("L_WARN", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Permission OK For $si\n");
- setflag(20);
- } else {
- xlog("L_WARN", "--Debug Customer IP:$si-----Permission Denied\n");
- send_reply("403","Forbidden");
- exit;
- }
- }
- ###########################End of Permission granted###############################
- if (has_totag()) {
- if ( is_method("INVITE")) {
- $avp(timeout2) = 10;
- } else if (is_method("ACK")) {
- $avp(timeout2) = 3600;
- }
- # sequential request withing a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- # validate the sequential request against dialog
- if ( $DLG_status!=NULL && !validate_dialog() ) {
- xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
- #exit;
- }
- if (is_method("BYE")) {
- end_media_session();
- setflag(1); # do accounting ...
- setflag(3); #transaction falis
- if ($dlg_val("connected")!="null" || $dlg_val("connected")!="0") {
- $var(connectedtime) = $dlg_val("connected");
- $var(ended) = $Ts -$(var(connectedtime){s.int}) ;
- $var(endedmillsec)=$Tsm/1000;
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Ended call-Time=$Ts---Connected=$var(connectedtime)--Ended=$var(ended)--Endedms=$var(endedmillsec);\n");
- $var(differenceMillsec)=(($var(ended)*1000)-1000)+$var(endedmillsec);
- }
- if ($dlg_val("customerid") !="null" || $dlg_val("customerid") !="" || $dlg_val("customerid") !="0" ) {
- $var(customer) = $dlg_val("customerid");
- }
- xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Bye Sent From IP $si\n");
- xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Duration in Millesec=$var(differenceMillsec)\n");
- xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Duration:$var(ended)\n");
- avp_db_query("UPDATE `opensips`.`acc` SET `durationms` = '$var(differenceMillsec)' WHERE `CALLID` ='$ci'" );
- xlog( "L_INFO", "##########==========End of invite for Customer ID:$(var(customer){s.int})/GW-IP:$si Over $rd==========##########999 \n");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- } 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();
- }
- if (check_route_param("nat=yes")) {
- setflag(5);
- }
- # route it out to whatever destination was set by loose_route()
- # in $du (destination URI).
- route(1);
- } 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;
- }
- /*#### INITIAL REQUESTS*/
- if ( !isflagset(20) ) {
- ## accept new calls only from trunks
- send_reply("403","Not from trunk");
- exit;
- }
- # CANCEL processing
- if (is_method("CANCEL")) {
- avp_db_query("update `acc` set `uaB` ='ck' where `callid`='$ci' ");
- if (t_check_trans()) {
- t_relay();
- }
- exit;
- }
- t_check_trans();
- if (from_uri==myself) {
- # if caller is local
- } else if (uri==myself){
- # if caller is not local, then called number must be local
- } else {
- # neither caller nor callee is local, so drop this call
- 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");
- }
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----###################Delete BYE######2##########\n\n");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- }
- # record routing
- if (!is_method("REGISTER|MESSAGE")) {
- record_route();
- }
- if (!is_uri_host_local()) {
- append_hf("P-hint: outbound\r\n");
- route(1);
- }
- # 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;
- }
- # account only INVITEs
- if (!has_totag() &&is_method("INVITE")) {
- ########################################################################################
- if(has_body("application/sdp")) {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Checking Codec\n");
- if (codec_exists("PCMU")) {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with PCMU $ru and Moving Down\n");
- codec_move_down("PCMU","8000");
- }
- if (codec_exists("PCMA")) {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with PCMA $ru and Moving Down\n");
- codec_move_down("PCMA","8000");
- }
- if (codec_exists("G729")) {
- codec_move_up("G729","8000");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with G729 $ru and Moving UP\n");
- }
- }
- ############################################################################################
- #khaledxlog("from_uri=$ct; to_uri=$tu;ani=$fU; dest=$tU; via=$rd ;source=$si;gateway=$avp(271);uaA=$hdr(User-Agent);uaB=$hdr(Server);PDD=$var(setup_time);\n");
- /*Insert Call in invites table*/
- avp_db_query("INSERT INTO `opensips`.`invites` (`ID`, `CALLID`, `IP`, `Dialed_number`) VALUES (NULL, '$ci', '$si', '$tU')");
- /*Check for duplicates*/
- avp_db_query("SELECT COUNT('ID') FROM invites where `Dialed_number` like('%$tU%') " , "$avp(Existance)");
- if ( $avp(Existance) > 1 ) {
- #send error
- xlog("unable to send request to destination Duplicated Call ");
- t_reply("403","CK-Switch:Loop Number Detected ");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- xlog("###################Delete BYE########3########\n\n");
- exit;
- }
- /*Get Number dialed calls per destination for customer*/
- avp_db_query("SELECT COUNT('ID') FROM invites WHERE `IP`= '$si' AND '$tU' LIKE CONCAT(Dialed_number,'%') ORDER BY Dialed_number DESC LIMIT 1", "$avp(nocpdA)");
- /*Get number of channels per destination allowed by administration*/
- avp_db_query("SELECT `Num_Channels` FROM `PeerLimits` WHERE `Cusid` = '$avp(Cusid)' AND '$tU' LIKE CONCAT(`Destination_Prefix`,'%') ORDER BY `Destination_Prefix` DESC LIMIT 1","$avp(nocpdL)");
- #xlog("SELECT `Num_Channels` FROM `PeerLimits` WHERE `Cusid` = '$avp(Cusid)' AND '$(tu{s.substr,4,0})'----$tU\n");
- #if from another database avp_db_query("SELECT `name` FROM `billing_rates` WHERE '$rU' LIKE CONCAT(`destination`,'%') ORDER BY `destination` DESC LIMIT 1 ", "$avp(rate)","1");
- avp_db_query("SELECT `durationRate`,`name`,`destination` FROM `billing_rates` WHERE '$rU' LIKE CONCAT(`destination`,'%') and reseller_id='$avp(Cusid)' ORDER BY `destination` DESC LIMIT 1 ", "$avp(rate);$avp(destination);$avp(prefix)");
- #getting balance
- avp_db_query("SELECT `limit` FROM `address` WHERE `id` ='$avp(Cusid)' ORDER BY 'CAST(limit AS INT) DESC'", "$avp(Rbalance)");
- #trace_dialog();
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----CusID:$avp(Cusid)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Dest Num:$rU\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Rate:$avp(rate)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Billing Country :$avp(destination)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Billing Dest Num:$avp(prefix)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----NOCPDA/Dialed=$avp(nocpdA)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----NOCPDL/Limit=$avp(nocpdL)\n");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Current Balance=$avp(Rbalance)\n");
- if ($avp(nocpdL) =="null" || $avp(nocpdL) ==" "){
- $avp(nocpda)="180";
- }
- if ($avp(nocpdA) =="0") {
- $avp(nocpdA)="1";
- }
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Available Session:$(avp(nocpdA){s.int}) > $(avp(nocpdL){s.int})\n");
- if ($(avp(nocpdA)) > $(avp(nocpdL)) ) {
- #send error
- xlog("unable to send request to destination Limit reached ");
- t_reply("403","CK-Switch:You Exceed The Number Of channels To $avp(destination)");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- xlog("###################Delete BYE########3########\n\n");
- exit;
- }
- #########################Rate Check#################################################
- if ($avp(rate)==null ){
- #send error
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----No Rate Found For $rU \n");
- xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si==========##########1 \n");
- t_reply("403","CK-Switch:No Rate Found for $rU");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- } else if ($avp(Rbalance) < 1 ){
- #send error
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Out Of Credit for $rU \n");
- xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si==========##########2 \n");
- t_reply("503","CK-Switch: Out Of Funds");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- } else {
- ##########################################################################
- engage_media_proxy();
- setflag(1); # do accounting
- setflag(2); #Missed calls
- #setflag(3); #transaction falis
- setflag(4); #CDR flag
- # create dialog with timeout
- if ( !create_dialog("B") ) {
- send_reply("500","Internal Server Error");
- exit;
- }
- }
- /*
- if (is_avp_set("$avp(trunk_attrs)") && $avp(trunk_attrs)=~"^[0-9]+$") {
- get_profile_size("trunkCalls","$si","$var(size)");
- if ( $(var(size){s.int}) >= $(avp(trunk_attrs){s.int}) ) {
- send_reply("486","Busy Here");
- exit;
- }
- }
- set_dlg_profile("trunkCalls","$si");
- */
- }
- # apply DB based aliases
- alias_db_lookup("dbaliases");
- # apply transformations from dialplan table
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Before translation:$rU\n");
- dp_translate("1","$rU/$rU");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Ingress Translation:$rU\n");
- if ($rU=~"^.") {
- if (!do_routing("0","FW")) {
- send_reply("404","No PSTN Route found");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- }
- if (is_avp_set("$avp(gw_attrs)") ) {
- #&& $avp(trunk_attrs)=~"^[0-9]+$")
- get_profile_size("trunkCalls","$si","$var(size)");
- $var(size) = $var(size) + 1;
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Max Call allowed to trunk: $avp(gw_attrs)--Available:$var(size)\n");
- if ( $(var(size){s.int}) >= $(avp(gw_attrs){s.int}) ) {
- send_reply("503","Service Not Available");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- }
- }
- set_dlg_profile("trunkCalls","$si");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Trunk Name:$avp(gw_id)\n");
- dp_translate("1","$rU/$rU");
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Egress translation:$rU\n");
- route(1);
- exit;
- }
- # do lookup with method filtering
- if (!lookup("location","m")) {
- if (!db_does_uri_exist()) {
- send_reply("420","Bad Extension");
- exit;
- }
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si------10##Reply: $T_reply_code--------------CK\n");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- t_newtran();
- t_reply("404", "Not Found");
- exit;
- }
- if (isflagset(5)) {
- setbflag(6);
- if (proto == TCP) {
- setflag(10);
- }
- }
- route(1);
- }
- route[1] {
- if (subst_uri('/(sip:.*);nat=yes/\1/')) {
- setbflag(6);
- }
- if (isflagset(5)) {
- search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
- }
- # for INVITEs enable some additional helper routes
- if (is_method("INVITE")) {
- t_on_branch("2");
- t_on_reply("2");
- t_on_failure("1");
- avp_db_query("UPDATE `opensips`.`invites` set `trunkip` ='$rd' where `CALLID` = '$ci' ");
- }
- if (!t_relay()) {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si------#11###Reply: $T_reply_code\n");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- send_reply("500","Internal Error");
- };
- exit;
- }
- branch_route[2] {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----new branch at $ru\n");
- }
- onreply_route[2] {
- search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
- if (isbflagset(6)) {
- fix_nated_contact();
- };
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----incoming reply\n");
- if (t_check_status("200") ) {
- /*Set dialog variable Cusid*/
- $dlg_val("customerid") = $avp(Cusid);
- $dlg_val("connected") = $Ts;
- #$var(connected) = $Ts ;
- $var(connectedmillsec) = 1000-($Tsm/1000) ;
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Connected at $dlg_val(\"connected\")--connectedmillsec=$var(connectedmillsec)-----Tsm=$Tsm- \n");
- }
- if (t_check_status("180")|| t_check_status("183") ) {
- # calculate the setup time
- $var(setup_time) = $Ts - $avp(tmp);
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----PDD:$var(setup_time)\n");
- }
- if (status =~ "(180)|(183)") {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Ringing \n");
- }
- }
- route[6] {
- if ( use_next_gw() ) {
- setflag(26); #Missed calls
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Trunk Name:$avp(gw_id)\n");
- t_on_failure("1");
- t_relay();
- exit;
- }
- send_reply("503", "Service Unavailable");
- exit;
- }
- failure_route[1] {
- if (t_was_cancelled()) {
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Call Canceled--SIP Reason:$T_reply_code\n");
- xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si--Over $rd====on_route_failure_1======##########3 \n");
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- exit;
- }
- # uncomment the following lines if you want to block client
- # redirect based on 3xx replies.
- ##if (t_check_status("3[0-9][0-9]")) {
- ##t_reply("404","Not found");
- ## exit;
- ##}
- if (t_check_status("481") ) {
- acc_db_request("200 Dialog Timeout", "acc");
- xlog("-----Reply: $T_reply_code#----------481-422-487--#####$rm from $si (callid=$ci)######################################");
- }
- if( t_check_status("4[0-9][0-9]") || t_check_status("5[0-9][0-9]") ){
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$rd-----$si Reply: $T_reply_code#######13\n");
- xlog("L_INFO", "##########==========End of invite ID:$avp(Cusid)/IP:$rd###############\n");
- #xlog( "L_NOTICE", "[$Tf] FR: $ci ------$rd----------Delete 2--------------\n" );
- avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- route(6);
- }
- # If fr_timer expires t_check_status("408") is true, although $rs is <null>
- if (t_check_status("(408)|([56][0-9][0-9])")) {
- #xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$rd-----Delete Invite #####$rd Reply: $T_reply_code#######14\n");
- xlog( "L_NOTICE", "[$Tf] FR: $ci -- TIMEOUT for Gateway $rd (marking as bad)\n" );
- }
- # 403 -- typically ISDN network says 'not a valid number' etc..
- if( t_check_status("403")){
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----INFO:ISDN network says 'not a valid number: $T_reply_code\n");
- #xlog("L_WARN", "--Debug Customer ID:$avp(Cusid)/IP:$si---------Time=[$Tf] Method:$rm--CallID:$ci--IP:$si-- Forbidden -> ISDN Cause Code 1\n" );
- xlog("L_INFO", "##########==========End of invite ID:$avp(Cusid)/IP:$rd==========##########\n");
- #@avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- return;
- }
- }
- local_route {
- if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
- end_media_session();
- xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si---------Reply: $T_reply_code------Source:$rd\nDialed:$fU\n:");
- acc_db_request("200 Dialog Timeout", "acc");
- @avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement