Advertisement
Guest User

sc

a guest
Jan 18th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.02 KB | None | 0 0
  1. ####### Global Parameters #########
  2.  
  3. debug=5
  4. log_stderror=yes
  5. log_facility=LOG_LOCAL7
  6. log_name="ckswitch"
  7.  
  8. fork=yes
  9. children=8
  10.  
  11. /* uncomment the following lines to enable debugging */
  12. #debug=6
  13. #fork=no
  14. #log_stderror=yes
  15.  
  16. /* uncomment the next line to enable the auto temporary blacklisting of
  17. not available destinations (default disabled) */
  18. #disable_dns_blacklist=no
  19.  
  20. /* uncomment the next line to enable IPv6 lookup after IPv4 dns
  21. lookup failures (default disabled) */
  22. #dns_try_ipv6=yes
  23.  
  24. /* comment the next line to enable the auto discovery of local aliases
  25. based on revers DNS on IPs */
  26. auto_aliases=yes
  27.  
  28. #disable_core_dump=no
  29.  
  30. sip_warning=yes
  31.  
  32. #server_signature=no
  33. server_header="Server: Residencial Gateway v1.8.2"
  34. user_agent_header="User-Agent: Residencial Gateway v1.8.2"
  35.  
  36. listen=udp:5.104.224.33:5060
  37. #listen=udp:192.168.150.129:5060
  38. tos=IPTOS_LOWDELAY
  39.  
  40. ######################################################################
  41. ## SIP
  42. ######################################################################
  43. #check_via=0
  44. #! disable_503_translation=no
  45. #disable_stateless_fwd=no
  46. disable_tcp=yes
  47.  
  48. # disable_tls=no
  49. #! reply_to_via=1
  50. ######################################################################
  51. ## TLS
  52. ######################################################################
  53. #disable_tls=yes
  54. # listen=tls:your_IP:5061
  55. # tls_verify_server=1
  56. # tls_verify_client=1
  57. # tls_require_client_certificate=0
  58. # tls_method=TLSv1
  59. # tls_certificate="/usr/local/etc/opensips/tls/user/user-cert.pem"
  60. # tls_private_key="/usr/local/etc/opensips/tls/user/user-privkey.pem"
  61. # tls_ca_list="/usr/local/etc/opensips/tls/user/user-calist.pem"
  62.  
  63. ######################################################################
  64. ## Destination Blacklist
  65. ######################################################################
  66. # dst_blacklist=gw:{( tcp , 192.168.2.100 , 5060 , "" ),( any , 192.168.2.101 , 0 , "" )}
  67. # dst_blacklist=net_filter2:{ !( any , 192.168.30.0/255.255.255.0 , 0 , "" )}
  68.  
  69. ######################################################################
  70. ## Attribute Value Pairs
  71. ######################################################################
  72. # avp_aliases="uuid=I:660;email=s:email_addr;fwd=i:753"
  73.  
  74. ######################################################################
  75.  
  76.  
  77. /* uncomment the next line to enable the auto temporary blacklisting of
  78. not available destinations (default disabled) */
  79. #disable_dns_blacklist=no
  80.  
  81. /* uncomment the next line to enable IPv6 lookup after IPv4 dns
  82. lookup failures (default disabled) */
  83. #dns_try_ipv6=yes
  84.  
  85.  
  86. ######################################################################
  87. ## Module Loading
  88. ######################################################################
  89. ####### Modules Section ########
  90.  
  91. #set module path
  92. mpath="/usr/src/opensips-1.8.2-tls/modules/"
  93. #mpath="/usr/local/lib/opensips/modules/"
  94.  
  95.  
  96. #### DB MySQL module
  97. loadmodule "db_mysql.so"
  98.  
  99. ### BD Virtual #####################################
  100. loadmodule "db_virtual.so"
  101. modparam("db_virtual", "db_max_consec_retrys", 5)
  102. modparam("db_virtual", "db_urls", "define set1 FAILOVER") # Failover db PARALLEL ROUND
  103. modparam("db_virtual", "db_urls","mysql://root:XXXXXXXXXX@localhost/opensips") # Set 1
  104. #modparam("db_virtual", "db_urls","mysql://root:@localhost/opensips") # Set 1
  105. ###############Define set 2 and then database connection####################################
  106. ##############################################################################################
  107.  
  108. #### SIGNALING module
  109. loadmodule "signaling.so"
  110.  
  111. #### StateLess module
  112. loadmodule "sl.so"
  113.  
  114. #### Transaction Module
  115. loadmodule "tm.so"
  116. modparam("tm", "fr_timer", 10)
  117. modparam("tm", "wt_timer", 10)
  118. modparam("tm", "fr_inv_timer", 60)
  119. modparam("tm", "onreply_avp_mode", 1)
  120. modparam("tm", "fr_timer_avp", "$avp(4)")
  121. modparam("tm", "fr_inv_timer_avp", "$avp(5)")
  122.  
  123. #### Record Route Module
  124. loadmodule "rr.so"
  125. modparam("rr", "add_username", 1)
  126. /* do not append from tag to the RR (no need for this script) */
  127. modparam("rr", "append_fromtag", 1)
  128. modparam("rr", "enable_double_rr", 1)
  129.  
  130. #### MAX ForWarD module
  131. loadmodule "maxfwd.so"
  132.  
  133. #### SIP MSG OPerationS module
  134. loadmodule "sipmsgops.so"
  135.  
  136. #### FIFO Management Interface
  137. loadmodule "mi_fifo.so"
  138. modparam("mi_fifo", "fifo_name", "/var/run/opensips_fifo")
  139. modparam("mi_fifo", "fifo_mode", 0666)
  140.  
  141. #### Datagram Management Interface
  142. loadmodule "mi_datagram.so"
  143. modparam("mi_datagram", "socket_name", "/var/run/opensips.sock")
  144.  
  145. #### URI module
  146. loadmodule "uri.so"
  147. modparam("uri", "db_url", "virtual://set1")
  148. modparam("uri", "use_uri_table", 1)
  149.  
  150. #### PERMISSIONS module
  151. loadmodule "permissions.so"
  152. modparam("permissions", "db_url","virtual://set1") # CUSTOMIZE ME
  153. modparam("permissions", "address_table", "address")
  154. modparam("permissions", "mask_col", "mask")
  155. #modparam("permissions", "check_all_branches", 1)
  156.  
  157. #### AUTHentication modules
  158. loadmodule "auth.so"
  159.  
  160. #### AUTHentication DB modules
  161. loadmodule "auth_db.so"
  162. modparam("auth_db", "calculate_ha1", 1)
  163. modparam("auth_db", "load_credentials", "")
  164. modparam("auth_db", "password_column", "password")
  165. modparam("auth_db", "db_url","virtual://set1") # CUSTOMIZE ME
  166.  
  167. #### USeR LOCation module
  168. loadmodule "usrloc.so"
  169. modparam("usrloc", "db_mode", 2)
  170. modparam("usrloc", "nat_bflag", 6)
  171. modparam("usrloc", "cseq_delay", 10)
  172. modparam("usrloc", "db_url", "virtual://set1") # CUSTOMIZE ME
  173.  
  174. #### NAT Travesal
  175. loadmodule "nat_traversal.so"
  176.  
  177. #### NAT Helper module
  178. loadmodule "nathelper.so"
  179. #modparam("nathelper", "sipping_bflag", 6)
  180. modparam("nathelper", "ping_nated_only", 0)
  181. modparam("nathelper", "natping_interval", 10)
  182. modparam("nathelper", "natping_processes", 4)
  183. modparam("nathelper", "received_avp", "$avp(rcv)")
  184. #modparam("nathelper", "sipping_from", "sip:[email protected]:5065")
  185.  
  186. #### REGISTRAR module
  187. loadmodule "registrar.so"
  188. modparam("registrar", "min_expires", 300)
  189. modparam("registrar", "max_expires", 300)
  190. modparam("registrar", "case_sensitive", 1)
  191. /* uncomment the next line not to allow more than 10 contacts per AOR */
  192. #modparam("registrar", "max_contacts", 10)
  193. modparam("registrar", "default_expires", 300)
  194. modparam("registrar", "tcp_persistent_flag", 10)
  195. modparam("registrar", "received_avp", "$avp(rcv)")
  196.  
  197. #### ALIAS module
  198. loadmodule "alias_db.so"
  199. modparam("alias_db", "db_url", "virtual://set1") # CUSTOMIZE ME
  200.  
  201. #### DOMAIN module
  202. loadmodule "domain.so"
  203. modparam("domain", "db_url", "virtual://set1") # CUSTOMIZE ME
  204. modparam("domain", "db_mode", 1) # Use caching
  205. modparam("auth_db|usrloc|uri", "use_domain", 1)
  206.  
  207. #### Dialog module
  208. loadmodule "dialog.so"
  209. modparam("dialog", "db_mode", 1)
  210. modparam("dialog", "dlg_match_mode", 1)
  211. modparam("dialog", "default_timeout", 3540) # 6 hours timeout
  212. modparam("dialog", "dlg_extra_hdrs", "Hint: destination unreachable\r\n")
  213. modparam("dialog", "db_url","virtual://set1") # CUSTOMIZE ME
  214. # dialog profiles
  215. modparam("dialog", "profiles_with_value", "trunkCalls")
  216. modparam("dialog", "timeout_avp", "$avp(timeout2)")
  217.  
  218. #### DIALPLAN module
  219. loadmodule "dialplan.so"
  220. modparam("dialplan", "db_url", "virtual://set1") # CUSTOMIZE ME
  221.  
  222. #### DYNAMMIC ROUTING module
  223. loadmodule "drouting.so"
  224. modparam("drouting", "db_url", "virtual://set1") # CUSTOMIZE ME
  225. modparam("drouting", "use_domain", 1)
  226. modparam("drouting", "drd_table", "dr_gateways")
  227. modparam("drouting", "drr_table", "dr_rules")
  228. modparam("drouting", "drg_table", "dr_groups")
  229. modparam("drouting", "drc_table", "dr_carriers")
  230. modparam("drouting", "drg_user_col", "username")
  231. modparam("drouting", "drg_domain_col", "domain")
  232. modparam("drouting", "drg_grpid_col", "groupid")
  233. modparam("drouting", "force_dns", 1)
  234. #frequency of probing per paramete in seconds
  235. modparam("drouting", "probing_interval", 120)
  236. modparam("drouting", "probing_method", "OPTIONS")
  237. modparam("drouting", "probing_from", "sip:pinger@opensips")
  238. modparam("drouting", "probing_reply_codes", "501, 403,404,487")
  239. modparam("drouting", "use_domain", 1)
  240. modparam("drouting", "gw_attrs_avp", '$avp(gw_attrs)')
  241. modparam("drouting", "gw_id_avp", '$avp(gw_id)')
  242.  
  243. # XML RPC module
  244. loadmodule "mi_xmlrpc.so"
  245. modparam("mi_xmlrpc", "log_file", "/var/log/openser-xmlrpc.log")
  246. modparam("mi_xmlrpc", "port", 8000)
  247. modparam("mi_xmlrpc", "reply_option", 0)
  248. modparam("mi_xmlrpc", "buffer_size", 8192)
  249.  
  250. # SIP TRACE module
  251. loadmodule "siptrace.so"
  252. modparam("siptrace", "db_url", "virtual://set1") # CUSTOMIZE ME
  253. modparam("siptrace", "traced_user_avp", "$avp(traced_user)")
  254. modparam("siptrace", "trace_on", 0)
  255. modparam("siptrace", "trace_flag", 20) #22
  256.  
  257. # TEXT OPtionS
  258. loadmodule "textops.so"
  259.  
  260. ################## Mediaproxy####################################
  261. loadmodule "mediaproxy.so"
  262. modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
  263. modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
  264. modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
  265.  
  266. # Call Control module
  267. #loadmodule "call_control.so"
  268. #modparam("call_control", "prepaid_account_flag", 8) #if flag>=0 this is a prepaid account#
  269. #modparam("call_control", "disable", 0)
  270. #modparam("call_control", "canonical_uri_avp", "$avp(can_uri)")
  271. #modparam("call_control", "signaling_ip_avp", "$avp(signaling_ip)")
  272.  
  273. #### AVPOPS module
  274. loadmodule "avpops.so"
  275. modparam("avpops", "db_url", "virtual://set1")
  276. modparam("avpops", "avp_table", "usr_preferences")
  277. modparam("avpops", "use_domain", 1)
  278. modparam("avpops", "uuid_column", "uuid")
  279. modparam("avpops", "username_column", "username")
  280. modparam("avpops", "domain_column", "domain")
  281. modparam("avpops", "attribute_column", "attribute")
  282. modparam("avpops", "value_column", "value")
  283. modparam("avpops", "type_column", "type")
  284. #modparam("avpops", "avp_aliases", "c_uri" )
  285.  
  286. #### ACCounting module
  287. loadmodule "acc.so"
  288. modparam("acc", "early_media", 0)
  289. modparam("acc", "report_cancels", 1)
  290.  
  291. /* by default we do not adjust the direct of the sequential requests.
  292. if you enable this parameter, be sure the enable "append_fromtag"
  293. in "rr" module */
  294. modparam("acc", "detect_direction", 1)
  295. modparam("acc", "log_level", 1)
  296.  
  297. /* account triggers (flags) */
  298. modparam("acc", "db_flag", 1)
  299. modparam("acc", "db_missed_flag", 2)
  300. modparam("acc", "log_missed_flag", 2)
  301. modparam("acc", "failed_transaction_flag", 3)
  302. modparam("acc", "cdr_flag", 4)
  303.  
  304. modparam("acc", "db_table_acc", "acc")
  305. modparam("acc", "db_table_missed_calls", "missed_calls")
  306. modparam("acc", "db_url","virtual://set1") # CUSTOMIZE ME
  307.  
  308. modparam("acc", "db_extra_bye", "timeout=$dlg_val(timeout)")
  309. modparam("acc", "multi_leg_info","leg_src=$avp(src);leg_dst=$avp(dst)")
  310. 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 ;
  311.  
  312.  
  313. ####### Routing Logic ########
  314.  
  315. # main request routing logic
  316.  
  317. route {
  318. if (!mf_process_maxfwd_header("10")) {
  319. sl_send_reply("483","Too Many Hops");
  320. exit;
  321. }
  322.  
  323. if (msg:len > max_len) {
  324. sl_send_reply("513","Message Too Big");
  325. exit;
  326. };
  327.  
  328. if(!(is_method("INVITE|ACK|CANCEL|BYE|UPDATE|OPTIONS|INFO"))) {
  329. xlog("L_INFO", ">>>>> Rejecting method '$rm' from '$fu' to '$ru' - User-Agent: $ua <<<<<\n");
  330. sl_send_reply("405","Method Not Allowed");
  331. exit;
  332. }
  333.  
  334. $avp(tmp) = $Ts ; # store the current time (at request processing)
  335. #xlog("tmp timr-----$avp(tmp)--------\n");
  336.  
  337. if (nat_uac_test("23")) {
  338. if (is_method("REGISTER")) {
  339. fix_nated_register();
  340. } else {
  341. fix_nated_contact();
  342. }
  343. setflag(5);
  344. };
  345.  
  346. force_rport();
  347.  
  348. ######################Permission granted###############################################
  349.  
  350. if (!(is_method("REGISTER") || is_from_gw())) {
  351. $avp(ip) = $si;
  352. $avp(port) = 5060;
  353. $avp(proto) = $proto;
  354.  
  355. # this meens that the Group 1 is a Permission garanted and others Permission denied.
  356. #check_address("1", related to address table group value 1
  357.  
  358. if (check_address("1","$avp(ip)","$avp(port)","$avp(proto)","$avp(10)", "") ) {
  359.  
  360. /* Get Customer ID */
  361. avp_db_query("SELECT `id` FROM `address` WHERE `context_info` ='$avp(10)' LIMIT 1", "$avp(Cusid)");
  362.  
  363. xlog("L_INFO", "##############################Debug Customer ID:$avp(Cusid)/IP:$si##############################\n");
  364. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Call Start\n");
  365. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Permission:OK-\n");
  366. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Customer Prefix:$avp(10)\n");
  367.  
  368. # request comes from trunks
  369. xlog("L_WARN", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Permission OK For $si\n");
  370. setflag(20);
  371.  
  372. } else {
  373.  
  374. xlog("L_WARN", "--Debug Customer IP:$si-----Permission Denied\n");
  375. send_reply("403","Forbidden");
  376. exit;
  377. }
  378. }
  379.  
  380. ###########################End of Permission granted###############################
  381.  
  382. if (has_totag()) {
  383. if ( is_method("INVITE")) {
  384. $avp(timeout2) = 10;
  385. } else if (is_method("ACK")) {
  386. $avp(timeout2) = 3600;
  387. }
  388.  
  389. # sequential request withing a dialog should
  390. # take the path determined by record-routing
  391.  
  392. if (loose_route()) {
  393. # validate the sequential request against dialog
  394. if ( $DLG_status!=NULL && !validate_dialog() ) {
  395. xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
  396. #exit;
  397. }
  398.  
  399. if (is_method("BYE")) {
  400. end_media_session();
  401. setflag(1); # do accounting ...
  402. setflag(3); #transaction falis
  403.  
  404. if ($dlg_val("connected")!="null" || $dlg_val("connected")!="0") {
  405. $var(connectedtime) = $dlg_val("connected");
  406. $var(ended) = $Ts -$(var(connectedtime){s.int}) ;
  407. $var(endedmillsec)=$Tsm/1000;
  408. 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");
  409. $var(differenceMillsec)=(($var(ended)*1000)-1000)+$var(endedmillsec);
  410. }
  411.  
  412. if ($dlg_val("customerid") !="null" || $dlg_val("customerid") !="" || $dlg_val("customerid") !="0" ) {
  413. $var(customer) = $dlg_val("customerid");
  414. }
  415.  
  416. xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Bye Sent From IP $si\n");
  417. xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Duration in Millesec=$var(differenceMillsec)\n");
  418. xlog("L_INFO", "--Debug Customer ID:$(var(customer){s.int})/GW-IP:$si-----Duration:$var(ended)\n");
  419. avp_db_query("UPDATE `opensips`.`acc` SET `durationms` = '$var(differenceMillsec)' WHERE `CALLID` ='$ci'" );
  420. xlog( "L_INFO", "##########==========End of invite for Customer ID:$(var(customer){s.int})/GW-IP:$si Over $rd==========##########999 \n");
  421.  
  422. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  423.  
  424. } else if (is_method("INVITE")) {
  425. # even if in most of the cases is useless, do RR for
  426. # re-INVITEs alos, as some buggy clients do change route set
  427. # during the dialog.
  428. record_route();
  429. }
  430.  
  431. if (check_route_param("nat=yes")) {
  432. setflag(5);
  433. }
  434.  
  435. # route it out to whatever destination was set by loose_route()
  436. # in $du (destination URI).
  437. route(1);
  438.  
  439. } else {
  440. if ( is_method("ACK") ) {
  441. if ( t_check_trans() ) {
  442. # non loose-route, but stateful ACK; must be an ACK after
  443. # a 487 or e.g. 404 from upstream server
  444. t_relay();
  445. exit;
  446. } else {
  447. # ACK without matching transaction ->
  448. # ignore and discard
  449. exit;
  450. }
  451. }
  452. sl_send_reply("404","Not here");
  453. }
  454. exit;
  455. }
  456.  
  457. /*#### INITIAL REQUESTS*/
  458. if ( !isflagset(20) ) {
  459. ## accept new calls only from trunks
  460. send_reply("403","Not from trunk");
  461. exit;
  462. }
  463.  
  464. # CANCEL processing
  465. if (is_method("CANCEL")) {
  466.  
  467.  
  468.  
  469. avp_db_query("update `acc` set `uaB` ='ck' where `callid`='$ci' ");
  470.  
  471. if (t_check_trans()) {
  472. t_relay();
  473. }
  474. exit;
  475. }
  476.  
  477. t_check_trans();
  478.  
  479. if (from_uri==myself) {
  480. # if caller is local
  481. } else if (uri==myself){
  482. # if caller is not local, then called number must be local
  483. } else {
  484. # neither caller nor callee is local, so drop this call
  485. send_reply("403","Rely forbidden");
  486. exit;
  487. }
  488.  
  489. # preloaded route checking
  490. if (loose_route()) {
  491. xlog("L_ERR", "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
  492.  
  493. if (!is_method("ACK")) {
  494. sl_send_reply("403","Preload Route denied");
  495. }
  496.  
  497. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----###################Delete BYE######2##########\n\n");
  498. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  499. exit;
  500. }
  501.  
  502. # record routing
  503. if (!is_method("REGISTER|MESSAGE")) {
  504. record_route();
  505. }
  506.  
  507. if (!is_uri_host_local()) {
  508. append_hf("P-hint: outbound\r\n");
  509. route(1);
  510. }
  511.  
  512. # requests for my domain
  513. if (is_method("PUBLISH|SUBSCRIBE")) {
  514. sl_send_reply("503", "Service Unavailable");
  515. exit;
  516. }
  517.  
  518. if (is_method("REGISTER")) {
  519. if ( 0 ) setflag(7);
  520.  
  521. if (!save("location")) {
  522. sl_reply_error();
  523. }
  524.  
  525. exit;
  526. }
  527.  
  528. if ($rU==NULL) {
  529. # request with no Username in RURI
  530. sl_send_reply("484","Address Incomplete");
  531. exit;
  532. }
  533.  
  534. # account only INVITEs
  535. if (!has_totag() &&is_method("INVITE")) {
  536.  
  537. ########################################################################################
  538. if(has_body("application/sdp")) {
  539. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Checking Codec\n");
  540. if (codec_exists("PCMU")) {
  541. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with PCMU $ru and Moving Down\n");
  542. codec_move_down("PCMU","8000");
  543. }
  544.  
  545. if (codec_exists("PCMA")) {
  546. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with PCMA $ru and Moving Down\n");
  547. codec_move_down("PCMA","8000");
  548. }
  549.  
  550. if (codec_exists("G729")) {
  551. codec_move_up("G729","8000");
  552. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----I've found a call with G729 $ru and Moving UP\n");
  553. }
  554. }
  555. ############################################################################################
  556.  
  557.  
  558. #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");
  559.  
  560. /*Insert Call in invites table*/
  561. avp_db_query("INSERT INTO `opensips`.`invites` (`ID`, `CALLID`, `IP`, `Dialed_number`) VALUES (NULL, '$ci', '$si', '$tU')");
  562. /*Check for duplicates*/
  563. avp_db_query("SELECT COUNT('ID') FROM invites where `Dialed_number` like('%$tU%') " , "$avp(Existance)");
  564.  
  565.  
  566. if ( $avp(Existance) > 1 ) {
  567. #send error
  568. xlog("unable to send request to destination Duplicated Call ");
  569. t_reply("403","CK-Switch:Loop Number Detected ");
  570. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  571. xlog("###################Delete BYE########3########\n\n");
  572. exit;
  573. }
  574.  
  575. /*Get Number dialed calls per destination for customer*/
  576. 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)");
  577.  
  578. /*Get number of channels per destination allowed by administration*/
  579. 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)");
  580.  
  581. #xlog("SELECT `Num_Channels` FROM `PeerLimits` WHERE `Cusid` = '$avp(Cusid)' AND '$(tu{s.substr,4,0})'----$tU\n");
  582.  
  583. #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");
  584. 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)");
  585.  
  586. #getting balance
  587. avp_db_query("SELECT `limit` FROM `address` WHERE `id` ='$avp(Cusid)' ORDER BY 'CAST(limit AS INT) DESC'", "$avp(Rbalance)");
  588.  
  589. #trace_dialog();
  590. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----CusID:$avp(Cusid)\n");
  591. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Dest Num:$rU\n");
  592. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Rate:$avp(rate)\n");
  593. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Billing Country :$avp(destination)\n");
  594. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Billing Dest Num:$avp(prefix)\n");
  595. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----NOCPDA/Dialed=$avp(nocpdA)\n");
  596. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----NOCPDL/Limit=$avp(nocpdL)\n");
  597. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Current Balance=$avp(Rbalance)\n");
  598.  
  599. if ($avp(nocpdL) =="null" || $avp(nocpdL) ==" "){
  600. $avp(nocpda)="180";
  601. }
  602.  
  603. if ($avp(nocpdA) =="0") {
  604. $avp(nocpdA)="1";
  605. }
  606.  
  607. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Available Session:$(avp(nocpdA){s.int}) > $(avp(nocpdL){s.int})\n");
  608.  
  609. if ($(avp(nocpdA)) > $(avp(nocpdL)) ) {
  610. #send error
  611. xlog("unable to send request to destination Limit reached ");
  612. t_reply("403","CK-Switch:You Exceed The Number Of channels To $avp(destination)");
  613. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  614. xlog("###################Delete BYE########3########\n\n");
  615. exit;
  616. }
  617.  
  618. #########################Rate Check#################################################
  619. if ($avp(rate)==null ){
  620. #send error
  621. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----No Rate Found For $rU \n");
  622. xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si==========##########1 \n");
  623. t_reply("403","CK-Switch:No Rate Found for $rU");
  624. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  625. exit;
  626.  
  627. } else if ($avp(Rbalance) < 1 ){
  628. #send error
  629. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Out Of Credit for $rU \n");
  630. xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si==========##########2 \n");
  631. t_reply("503","CK-Switch: Out Of Funds");
  632. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  633. exit;
  634.  
  635. } else {
  636.  
  637. ##########################################################################
  638. engage_media_proxy();
  639.  
  640. setflag(1); # do accounting
  641. setflag(2); #Missed calls
  642. #setflag(3); #transaction falis
  643. setflag(4); #CDR flag
  644.  
  645. # create dialog with timeout
  646. if ( !create_dialog("B") ) {
  647. send_reply("500","Internal Server Error");
  648. exit;
  649. }
  650. }
  651. /*
  652. if (is_avp_set("$avp(trunk_attrs)") && $avp(trunk_attrs)=~"^[0-9]+$") {
  653. get_profile_size("trunkCalls","$si","$var(size)");
  654.  
  655. if ( $(var(size){s.int}) >= $(avp(trunk_attrs){s.int}) ) {
  656. send_reply("486","Busy Here");
  657. exit;
  658. }
  659. }
  660.  
  661. set_dlg_profile("trunkCalls","$si");
  662. */
  663. }
  664.  
  665. # apply DB based aliases
  666. alias_db_lookup("dbaliases");
  667.  
  668. # apply transformations from dialplan table
  669. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Before translation:$rU\n");
  670. dp_translate("1","$rU/$rU");
  671.  
  672. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Ingress Translation:$rU\n");
  673.  
  674. if ($rU=~"^.") {
  675. if (!do_routing("0","FW")) {
  676. send_reply("404","No PSTN Route found");
  677. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  678. exit;
  679. }
  680.  
  681. if (is_avp_set("$avp(gw_attrs)") ) {
  682.  
  683. #&& $avp(trunk_attrs)=~"^[0-9]+$")
  684. get_profile_size("trunkCalls","$si","$var(size)");
  685.  
  686. $var(size) = $var(size) + 1;
  687. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Max Call allowed to trunk: $avp(gw_attrs)--Available:$var(size)\n");
  688.  
  689. if ( $(var(size){s.int}) >= $(avp(gw_attrs){s.int}) ) {
  690. send_reply("503","Service Not Available");
  691. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  692. exit;
  693. }
  694. }
  695.  
  696. set_dlg_profile("trunkCalls","$si");
  697. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Trunk Name:$avp(gw_id)\n");
  698.  
  699. dp_translate("1","$rU/$rU");
  700. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Egress translation:$rU\n");
  701.  
  702. route(1);
  703. exit;
  704. }
  705.  
  706. # do lookup with method filtering
  707. if (!lookup("location","m")) {
  708. if (!db_does_uri_exist()) {
  709. send_reply("420","Bad Extension");
  710. exit;
  711. }
  712.  
  713. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si------10##Reply: $T_reply_code--------------CK\n");
  714. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  715.  
  716. t_newtran();
  717. t_reply("404", "Not Found");
  718. exit;
  719. }
  720.  
  721. if (isflagset(5)) {
  722. setbflag(6);
  723.  
  724. if (proto == TCP) {
  725. setflag(10);
  726. }
  727. }
  728.  
  729. route(1);
  730. }
  731.  
  732. route[1] {
  733. if (subst_uri('/(sip:.*);nat=yes/\1/')) {
  734. setbflag(6);
  735. }
  736.  
  737. if (isflagset(5)) {
  738. search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
  739. }
  740.  
  741. # for INVITEs enable some additional helper routes
  742. if (is_method("INVITE")) {
  743. t_on_branch("2");
  744. t_on_reply("2");
  745. t_on_failure("1");
  746.  
  747. avp_db_query("UPDATE `opensips`.`invites` set `trunkip` ='$rd' where `CALLID` = '$ci' ");
  748. }
  749.  
  750. if (!t_relay()) {
  751. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si------#11###Reply: $T_reply_code\n");
  752. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  753. send_reply("500","Internal Error");
  754. };
  755.  
  756. exit;
  757. }
  758.  
  759. branch_route[2] {
  760. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----new branch at $ru\n");
  761. }
  762.  
  763.  
  764. onreply_route[2] {
  765. search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes');
  766.  
  767. if (isbflagset(6)) {
  768. fix_nated_contact();
  769. };
  770.  
  771. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----incoming reply\n");
  772.  
  773. if (t_check_status("200") ) {
  774. /*Set dialog variable Cusid*/
  775. $dlg_val("customerid") = $avp(Cusid);
  776. $dlg_val("connected") = $Ts;
  777.  
  778. #$var(connected) = $Ts ;
  779. $var(connectedmillsec) = 1000-($Tsm/1000) ;
  780. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Connected at $dlg_val(\"connected\")--connectedmillsec=$var(connectedmillsec)-----Tsm=$Tsm- \n");
  781. }
  782.  
  783. if (t_check_status("180")|| t_check_status("183") ) {
  784. # calculate the setup time
  785. $var(setup_time) = $Ts - $avp(tmp);
  786. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----PDD:$var(setup_time)\n");
  787. }
  788.  
  789. if (status =~ "(180)|(183)") {
  790. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Ringing \n");
  791. }
  792. }
  793.  
  794.  
  795. route[6] {
  796. if ( use_next_gw() ) {
  797. setflag(26); #Missed calls
  798. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/GW-IP:$si-----Trunk Name:$avp(gw_id)\n");
  799.  
  800. t_on_failure("1");
  801. t_relay();
  802. exit;
  803. }
  804.  
  805. send_reply("503", "Service Unavailable");
  806. exit;
  807. }
  808.  
  809.  
  810. failure_route[1] {
  811. if (t_was_cancelled()) {
  812. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----Call Canceled--SIP Reason:$T_reply_code\n");
  813. xlog("L_INFO", "##########==========End of invite for Customer ID:$avp(Cusid)/IP:$si--Over $rd====on_route_failure_1======##########3 \n");
  814. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  815.  
  816. exit;
  817. }
  818.  
  819. # uncomment the following lines if you want to block client
  820. # redirect based on 3xx replies.
  821. ##if (t_check_status("3[0-9][0-9]")) {
  822. ##t_reply("404","Not found");
  823. ## exit;
  824. ##}
  825.  
  826. if (t_check_status("481") ) {
  827. acc_db_request("200 Dialog Timeout", "acc");
  828. xlog("-----Reply: $T_reply_code#----------481-422-487--#####$rm from $si (callid=$ci)######################################");
  829. }
  830.  
  831. if( t_check_status("4[0-9][0-9]") || t_check_status("5[0-9][0-9]") ){
  832. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$rd-----$si Reply: $T_reply_code#######13\n");
  833. xlog("L_INFO", "##########==========End of invite ID:$avp(Cusid)/IP:$rd###############\n");
  834.  
  835. #xlog( "L_NOTICE", "[$Tf] FR: $ci ------$rd----------Delete 2--------------\n" );
  836. avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  837. route(6);
  838. }
  839.  
  840. # If fr_timer expires t_check_status("408") is true, although $rs is <null>
  841. if (t_check_status("(408)|([56][0-9][0-9])")) {
  842. #xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$rd-----Delete Invite #####$rd Reply: $T_reply_code#######14\n");
  843. xlog( "L_NOTICE", "[$Tf] FR: $ci -- TIMEOUT for Gateway $rd (marking as bad)\n" );
  844. }
  845.  
  846. # 403 -- typically ISDN network says 'not a valid number' etc..
  847. if( t_check_status("403")){
  848. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si-----INFO:ISDN network says 'not a valid number: $T_reply_code\n");
  849. #xlog("L_WARN", "--Debug Customer ID:$avp(Cusid)/IP:$si---------Time=[$Tf] Method:$rm--CallID:$ci--IP:$si-- Forbidden -> ISDN Cause Code 1\n" );
  850. xlog("L_INFO", "##########==========End of invite ID:$avp(Cusid)/IP:$rd==========##########\n");
  851.  
  852. #@avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  853. return;
  854. }
  855. }
  856.  
  857.  
  858. local_route {
  859. if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
  860. end_media_session();
  861. xlog("L_INFO", "--Debug Customer ID:$avp(Cusid)/IP:$si---------Reply: $T_reply_code------Source:$rd\nDialed:$fU\n:");
  862.  
  863. acc_db_request("200 Dialog Timeout", "acc");
  864. @avp_db_query("delete FROM `invites` WHERE `CALLID` ='$ci'");
  865. }
  866. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement