Thread: [Astpp-commit] SF.net SVN: astpp:[2192] trunk/freeswitch
Brought to you by:
darrenkw
From: <dar...@us...> - 2008-09-02 05:04:52
|
Revision: 2192 http://astpp.svn.sourceforge.net/astpp/?rev=2192&view=rev Author: darrenkw Date: 2008-09-02 05:04:59 +0000 (Tue, 02 Sep 2008) Log Message: ----------- Add a contributed script and modify it to use mostly ASTPP configuration rather than inline configuration. Add partial support for time limiting FreeSwitch LCR calls. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl Added Paths: ----------- trunk/freeswitch/contrib/ trunk/freeswitch/contrib/wasim/ trunk/freeswitch/contrib/wasim/README trunk/freeswitch/contrib/wasim/cdrload.pl Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2008-09-02 05:02:48 UTC (rev 2191) +++ trunk/freeswitch/astpp-fs-xml.pl 2008-09-02 05:04:59 UTC (rev 2192) @@ -149,6 +149,7 @@ exit(0); } +$xml = $ASTPP->fs_dialplan_xml_timelimit( xml => $xml, max_length => $maxlength); # Set the timelimit as well as other variables which are needed in the dialplan. my $timelimit = "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)"; Added: trunk/freeswitch/contrib/wasim/README =================================================================== --- trunk/freeswitch/contrib/wasim/README (rev 0) +++ trunk/freeswitch/contrib/wasim/README 2008-09-02 05:04:59 UTC (rev 2192) @@ -0,0 +1,4 @@ +This script was contributed by Wasim to the Freeswitch project. It is licensed under the GPL, therefore we're including it in this project with the appropriate adjustments made to make it work seemlessly together with ASTPP. + +Darren Wiebe +d...@al... Added: trunk/freeswitch/contrib/wasim/cdrload.pl =================================================================== --- trunk/freeswitch/contrib/wasim/cdrload.pl (rev 0) +++ trunk/freeswitch/contrib/wasim/cdrload.pl 2008-09-02 05:04:59 UTC (rev 2192) @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +# Convergence FreeSwitch Tools Version 7.0 : AGI +# (c) MMII Convergence. All rights reserved. +# <in...@co...> http://www.convergence.pk +# <da...@al...> http://www.aleph-com.net + +# This program is free software, distributed under the terms of +# the GNU General Public License.http://www.gnu.org/licenses.html + +use strict; +use DBI(); +use ASTPP; +use lib './lib', '../lib'; +require "/usr/local/astpp/astpp-common.pl"; + +use vars qw($config $astpp_db $osc_db $agile_db $cdr_db + @output @cardlist $config $params $ASTPP); + +sub initialize() { + $config = &load_config(); + $astpp_db = &connect_db( $config, @output ); + $config = &load_config_db($astpp_db,$config) if $astpp_db; + $cdr_db = &cdr_connect_db( $config, @output ); +} + +$ASTPP = ASTPP->new; +$ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be. +&initialize; + +my @cc = ("killall", "-HUP", "freeswitch"); +system(@cc) == 0 + or die "$0: system @cc failed: $?"; + +my @LS = `ls -1t /usr/local/freeswitch/log/cdr-csv/Master.csv.*`; +foreach my $line (@LS) { + chop($line); + $ASTPP->debug($line); + my $stm = "load data local infile '$line' into table TABLE fields enclosed by '\"' terminated by ','"; + my $ul = $cdr_db->prepare($stm) + or die "$0: Couldn't prepare statement $stm: " . $cdr_db->errstr;; + $ul->execute(); + $ul->finish; + system("cat $line >> /usr/local/freeswitch/log/cdr-csv/FULL_Master.csv"); + unlink $line; +} + +exit; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-02-21 18:37:08
|
Revision: 2236 http://astpp.svn.sourceforge.net/astpp/?rev=2236&view=rev Author: darrenkw Date: 2009-02-21 18:36:58 +0000 (Sat, 21 Feb 2009) Log Message: ----------- Added the beginning of callingcard support for Freeswitch. A few fixes to the xml generator. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl Added Paths: ----------- trunk/freeswitch/astpp-callingcards.pl Added: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl (rev 0) +++ trunk/freeswitch/astpp-callingcards.pl 2009-02-21 18:36:58 UTC (rev 2236) @@ -0,0 +1,556 @@ +#!/usr/bin/perl +# +# ASTPP - Open Source Voip Billing +# +# Copyright (C) 2004, Aleph Communications +# +# Darren Wiebe (da...@al...) +# +# This program is Free Software and is distributed under the +# terms of the GNU General Public License version 2. +############################################################################# +use DBI; +use POSIX qw(ceil floor); +use POSIX qw(strftime); +use Time::HiRes qw( gettimeofday tv_interval ); +use ASTPP; +use strict; +our $session; + +use vars qw(@output $verbosity $config $astpp_db $cdr_db + $ASTPP %stats %input $cc $pricelistinfo $brandinfo $sound @resellerlist $brand); +$stats{start_time} = [gettimeofday]; +$cc = 0; +$verbosity = 1; +require "/usr/local/astpp/astpp-common.pl"; + +$ASTPP = ASTPP->new; +$ASTPP->set_verbosity($verbosity); #Tell ASTPP debugging how verbose we want to be. + +sub initialize() { + $SIG{HUP} = 'ignore_hup'; # We ignore the HUP command that Asterisk sends on a call hangup. + $config = &load_config(); # Load /var/lib/astpp/astpp-config.conf + $astpp_db = &connect_db( $config, @output ); + $ASTPP->set_astpp_db($astpp_db); + $config = &load_config_db($astpp_db,$config); + $brand = "brand"; #$AGI->get_variable("BRAND"); + if ($brand && $brand ne "") { + my $brandinfo = &get_cc_brand($astpp_db, $brand); + if ($brandinfo->{reseller}) { + $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); + } + $config = &load_config_db_brand($astpp_db,$config,$brand); + } + $cdr_db = &cdr_connect_db( $config, @output ); + $ASTPP->set_cdr_db($cdr_db); + $sound = &define_sounds($astpp_db); +} + +sub set_in_use() { # Set the "inuse" flag on the calling cards. This prevents multiple people from +# using the same card. + my ( $cardinfo, $status ) = @_; + my $sql; + $sql = + "UPDATE callingcards SET inuse = " + . $astpp_db->quote($status) + . " WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $astpp_db->do($sql); +} + +sub check_card() { # Check a few things before saying the card is ok. + my ($cardinfo) = @_; + my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; + $ASTPP->debug( debug => "Present Time: $now", + verbosity => $verbosity ); + $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}", + verbosity => $verbosity ); + $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}", + verbosity => $verbosity ); + $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}", + verbosity => $verbosity ); + if ( $cardinfo->{inuse} != 0 ) { # If the card is in use then say so and leave. + $session->streamFile($sound->{card_inuse}); + $session->streamFile($sound->{goodbye}); + &leave($cardinfo); + } + &set_in_use( $cardinfo, 1 ); # Now the card is in use and nobody else can use it. + if ( $cardinfo->{firstused} eq "00000000000000" || $cardinfo->{firstused} eq "0000-00-00 00:00:00" ) { # If "firstused" has not been set, we will set it now. + # At the same time we will update the "maint_day" field. + my $sql = + "UPDATE callingcards SET firstused = NOW() WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( debug => $sql, + verbosity => $verbosity ); + $astpp_db->do($sql); + $sql = + "UPDATE callingcards SET maint_day = DATE_ADD(NOW(), INTERVAL " + . "$cardinfo->{maint_fee_days} day) WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( debug => $sql, + verbosity => $verbosity ); + if ( $cardinfo->{maint_fee_days} > 0 ) { + $astpp_db->do($sql); + } +# $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber} ); + if ( $cardinfo->{validfordays} > 0 ) { #Check if the card is set to expire and deal with that as appropriate. + my $sql = +"UPDATE callingcards SET expiry = DATE_ADD(NOW(), INTERVAL " + . " $cardinfo->{validfordays} day) WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( debug => $sql, + verbosity => $verbosity ); + $astpp_db->do($sql); + $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber}, $config ); + } + } + elsif ( $cardinfo->{validfordays} > 0 ) { + my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; + $cardinfo->{expiry} = $astpp_db->selectall_arrayref("SELECT DATE_FORMAT('$cardinfo->{expiry}' , '\%Y\%m\%d\%H\%i\%s')")->[0][0]; + if ( $now >= $cardinfo->{expiry} ) { + my $sql = + "UPDATE callingcards SET status = 2 WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( debug => $sql, + verbosity => $verbosity ); + $astpp_db->do($sql); + $sql = + "DELETE FROM ani_map WHERE account = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( debug => $sql, + verbosity => $verbosity ); + $astpp_db->do($sql); + $session->streamFile($sound->{card_has_expired}); + $session->streamFile($sound->{goodbye}); + &leave($cardinfo); + } + } + $ASTPP->debug( debug => "Present Time: $now", + verbosity => $verbosity ); + $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}", + verbosity => $verbosity ); + $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}", + verbosity => $verbosity ); + $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}", + verbosity => $verbosity ); +} + +sub tell_cost() { #Say how much the call will cost. + my ( $numberinfo, $pricelistinfo, $cardinfo ) = @_; + if ( $pricelistinfo->{markup} ne "" && $pricelistinfo->{markup} != 0 ) { + $ASTPP->debug( debug => "Adding Markup of $pricelistinfo->{markup}", + verbosity => $verbosity); + $numberinfo->{connectcost} = + $numberinfo->{connectcost} * + ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); + $numberinfo->{cost} = + $numberinfo->{cost} * ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); + } + if ($config->{calling_cards_rate_announce} == 1) { + if ( $numberinfo->{cost} > 0 ) { + $session->streamFile($sound->{call_will_cost}); +# $AGI->say_number(ceil($numberinfo->{cost} / 100)); + $session->streamFile($sound->{currency}); + my @call_cost = split(/\./, ($numberinfo->{cost} / 100)); +# $AGI->say_number(@call_cost[0]); + if (@call_cost[1]) { + $session->streamFile($sound->{point}); +# $AGI->say_number(@call_cost[1]); + $session->streamFile($sound->{sub_currency}); + } + $session->streamFile($sound->{per}); + $session->streamFile($sound->{minute}); + } + if ( $numberinfo->{connectcost} > 0 ) { + $session->streamFile($sound->{a_connect_charge}); +# $AGI->say_number(ceil($numberinfo->{connectcost} / 100)); + $session->streamFile($sound->{sub_currency}); + $session->streamFile($sound->{will_apply}); + } + } +} + +sub timelimit() { #Calculate and say the time limit. + my ( $numberinfo, $pricelistinfo, $cardinfo, $phoneno ) = @_; + my ( $connectfee, $cost, $timelimit, $available, $maxtime, $balance ); + # Timelimit is in seconds + if ($cc == 0) { + $available = + ( $cardinfo->{value} - $cardinfo->{used} ) - $numberinfo->{connectfee}; + $ASTPP->debug( debug => "FUNDS AVAILABLE: $available", + verbosity => $verbosity); + } elsif ( $cc == 1 ) { + $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); + $balance = ($balance * -1) + ( $cardinfo->{credit_limit}); + $available = ($balance - $numberinfo->{connectfee}) / 100; + } + if ( $available > 0 && $numberinfo->{cost} > 0 ) { + $timelimit = ( ( $available / $numberinfo->{cost} ) * 60 ); + } + elsif ( $available >= 0 && $numberinfo->{cost} <= 0 ) { + $timelimit = $config->{callingcards_max_length}; + } + if ( $timelimit > $config->{callingcards_max_length} ) { + $timelimit = $config->{callingcards_max_length}; + } + $ASTPP->debug( debug => "TIMELIMIT: $timelimit", + verbosity => $verbosity); + if ($brandinfo->{reseller} ne "") { + ASTPP->debug( debug => "THIS BRAND BELONGS TO $brandinfo->{reseller}!", + verbosity => $verbosity); + my $carddata = &get_account( $astpp_db, $brandinfo->{reseller} ); +# ($callstatus, $maxlength) = &max_length($astpp_db, $config, $carddata, $phoneno); +# my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist},$carddata ); + my $minimumcharge = $numberinfo->{cost}; + my $belongs_to_reseller = 1; + while ( $belongs_to_reseller == 1 ) { + $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}", + verbosity => $verbosity); + push @resellerlist, $carddata->{number}; + $ASTPP->debug( debug => "PUSHING $carddata->{number} ONTO THE LIST OF RESELLERS", + verbosity => $verbosity); + my ($resellercallstatus, $resellermaxlength) = &max_length($astpp_db, $config, $carddata, $phoneno); + my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist}, $carddata, "CC" ); + if ($resellercallstatus != 1) { + $carddata->{reseller} = ""; + $timelimit = 0; + } elsif ($resellermaxlength < $timelimit / 60) { + $timelimit = $resellermaxlength * 60; + } + if ($resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) { + $carddata->{reseller} = ""; + $timelimit = 0; + } + $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength", + verbosity => $verbosity); + $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus", + verbosity => $verbosity); + if ($carddata->{reseller} && $carddata->{reseller} ne "") { + $carddata = &get_account( $astpp_db, $carddata->{reseller} ); + } else { + $belongs_to_reseller = 0; + } + } + } else { + $ASTPP->debug( debug => "THIS BRAND DOES NOT BELONG TO A RESELLER!", + verbosity => $verbosity); + } + $ASTPP->debug( debug =>"TIMELIMIT: $timelimit", verbosity => $verbosity); + my $minutes = $timelimit / 60; + $ASTPP->debug( debug => "MINUTES: $minutes", verbosity => $verbosity); + if ($minutes > 0 && $config->{calling_cards_timelimit_announce} == 1) { + my $minutes = $timelimit / 60; + $minutes = sprintf( "%.0f", $minutes ); + $session->streamFile($sound->{call_will_last}); + if ( $minutes == 1 ) { +# $AGI->say_number($minutes); + $session->streamFile($sound->{minute}); + } + elsif ( $minutes > 1 ) { +# $AGI->say_number($minutes); + $session->streamFile($sound->{minutes}); + } + } + elsif ($minutes < 1) { + $session->streamFile($sound->{not_enough_credit}); + $session->streamFile($sound->{goodbye}); + &leave($cardinfo); + } + $maxtime = $timelimit * 1000; + + + $timelimit = "\|30\|HL($maxtime:60000:30000)\|Hgj"; + $ASTPP->debug( debug => "Available: $available", + verbosity => $verbosity ); + $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity ); + $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity ); + return $timelimit; +} + +sub say_balance() { #Calculate and say the card balance. + my ($cardinfo) = @_; + my ( $connectfee, $cost, $included, $sub_balance, $balance, $main_balance ); + if ($cc == 0 ) { + $balance = $cardinfo->{value} - $cardinfo->{used}; + } elsif ($cc ==1) { + $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); + $balance = ($balance * -1) + ( $cardinfo->{credit_limit} ); + } + if ( $balance > 0 ) { + $balance = $balance / 10000; + $balance = sprintf( "%.2f", $balance ); + $sub_balance = substr( $balance, -2, 2 ); + $main_balance = substr( $balance, 0, -2 ); + my $interrupt = $session->playAndGetDigits(1,1,1,0,"#*","$sound->{card_has_balance_of}","$sound->{card_has_balance_of}",'^[0-9]+$'); + if (!$interrupt || $interrupt eq "" || $interrupt == 0) { + if ( $main_balance == 1 ) { +# $AGI->say_number($main_balance); + $session->streamFile($sound->{main_currency}); + } + elsif ( $main_balance > 1 ) { +# $AGI->say_number($main_balance); + $session->streamFile($sound->{main_currency_plural}); + } + if ( $sub_balance == 1 ) { +# $AGI->say_number($sub_balance); + $session->streamFile($sound->{sub_currency}); + } + elsif ( $sub_balance > 1 ) { +# $AGI->say_number($sub_balance); + $session->streamFile($sound->{sub_currency_plural}); + } + } + } + else { + $session->streamFile($sound->{card_is_empty}); + $session->streamFile($sound->{goodbye}); + &leave($cardinfo); + } + return $balance; +} + +sub update_balance() { #Update the available credit on the calling card. + my ( $cardinfo, $charge ) = @_; + my $sql = + "UPDATE callingcards SET used = " + . $astpp_db->quote( ($charge) + $cardinfo->{used} ) + . " WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $astpp_db->do($sql); +} +sub write_asterisk_cdr() { #Write the cdr record to the asterisk cdr db. This is done so we get a record of the call the callingcard user placed. + # This is especially important for resellers and calling cards. + my ( + $reseller, $clid, $destination, $status, + $callstart, $answeredtime, $dstchannel, $lastapp, $dialedtime, $uniqueid, $asterisk_time, $cdr_db + ) + = @_; + my ($sql); + if (!$status) {$status = gettext("N/A"); } + $sql = "INSERT INTO cdr (calldate,dst,clid,dstchannel,lastapp,duration,billsec,disposition,accountcode,uniqueid) VALUES(" + . $astpp_db->quote($asterisk_time) . ", " + . $astpp_db->quote($destination) . ", " + . $astpp_db->quote($clid) . ", " + . $astpp_db->quote($dstchannel) . ", " + . $astpp_db->quote($lastapp) . ", " + . $astpp_db->quote($dialedtime) . ", " + . $astpp_db->quote($answeredtime) . ", " + . $astpp_db->quote($status) . ", " + . $astpp_db->quote( $reseller ) . ", " + . $astpp_db->quote( $uniqueid ) . ")"; + $cdr_db->do($sql); + $session->execute("set", "ANSWEREDTIME=0" ); + $session->execute("set", "DIALEDTIME=0" ); + $session->execute("set", "DIALSTATUS=NO ANSWER" ); +} + +sub write_cdr() { # Write the callingcardcdr record if this is a calling card. + my ( + $cardinfo, $clid, $destination, $status, + $callstart, $charge, $answeredtime + ) + = @_; + my ($sql); + if (!$status) {$status = gettext("N/A"); } + $sql = +"INSERT INTO callingcardcdrs (cardnumber,clid,destination,disposition,callstart,seconds," + . "debit) VALUES (" + . $astpp_db->quote( $cardinfo->{cardnumber} ) . ", " + . $astpp_db->quote($clid) . ", " + . $astpp_db->quote($destination) . ", " + . $astpp_db->quote($status) . ", " + . $astpp_db->quote($callstart) . ", " + . $astpp_db->quote($answeredtime) . ", " + . $astpp_db->quote($charge) . ")"; + $astpp_db->do($sql); + $ASTPP->debug( debug => "$sql", verbosity => $verbosity ); + $ASTPP->debug( debug => "Resetting CDR Variables", verbosity => $verbosity ); + $session->execute("set", "ANSWEREDTIME=0" ); + $session->execute("set", "DIALEDTIME=0" ); + $session->execute("set", "DIALSTATUS=NO ANSWER" ); +} + + + +sub leave() { # Prepare everything and then leave the calling card app. + my ($cardinfo) = @_; + my ($whatnow); + my $retries = 0; + &set_in_use( $cardinfo, 0 ) if $cc == 0; + while ($retries < 3) { + $whatnow = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{astpp_callingcard_menu}","$sound->{astpp_callingcard_menu}",'^[0-9]+$'); + $ASTPP->debug( debug => "WHAT NEXT = $whatnow ", verbosity => $verbosity ); + if ($cc == 1) { + $session->execute("set", "CARDNUMBER=$cardinfo->{number}" ); + } else { + $session->execute("set", "CARDNUMBER=$cardinfo->{cardnumber}" ); + } + $session->execute("set", "PIN=$cardinfo->{pin}" ); + if ( $whatnow == 1 ) { + $session->execute("set", "NEWCALL=1" ); + $session->execute("set", "DESTINATION=$stats{destination}" ); + &exit_program(); + } + elsif ( $whatnow == 2 ) { + $session->execute("set", "NEWCALL=1" ); + $session->execute("set", "DESTINATION=" ); + &exit_program(); + } + elsif ( $whatnow == 3 ) { + $session->streamFile($sound->{goodbye}); + $session->hangup; + } else { + $retries++; + } + } + if ($retries == 3) { + $session->streamFile($sound->{goodbye}); + $session->hangup; + } + +} + +sub exit_program() { + $stats{total_time} = tv_interval ($stats{start_time}); + $astpp_db->do("INSERT INTO callingcard_stats(uniqueid,total_time,billable_time) VALUES (" + . $astpp_db->quote($stats{uniqueid}) . "," + . $astpp_db->quote($stats{total_time}) . "," + . $astpp_db->quote($stats{answered_time}) . ")"); + $stats{total_time} = tv_interval ($stats{start_time}); + exit(0); +} + +sub print_console() #Dump string to the console +{ + my ($output) = @_; + freeswitch::consoleLog("ASTPP",$output . "\n"); +} + +sub say() +{ + my($phrase,$say) = @_; + $session->execute("phrase", $phrase ."," . $say ); +} + + + +################# Program Starts Here ################################# +my ( $cardnum, $pin, $destination, $connectsurcharge, $perminsurcharge, $brand ) = + @ARGV; +my ( $retries, $cardinfo, $numberinfo, $pricelistinfo, @outboundroutes, + $callstart ); +$session->answer(); +&initialize; +return 1 if (! $session->ready()); + +if ($cardnum && $cardnum ne "") { + $ASTPP->debug( debug => "We recieved a cardnumber from the dialplan",verbosity => $verbosity); + $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); + if ( !$cardinfo ) { + $cardinfo = &get_account_cc( $astpp_db, $cardnum ); + $cc = 1 if $cardinfo; + } +} else { #We won't play the welcome file when we already have card numbers. + $session->streamFile($config->{calling_cards_welcome_file}); +} +# If $cc == 1 means that we are using an ASTPP account instead of an actual +# calling card. +if ( $cardinfo->{status} != 1 || !$cardinfo->{status}) { + $retries = 0; + while ( $cardinfo->{status} != 1 && $retries < $config->{card_retries} ) { + $cardnum = $session->playAndGetDigits($config->{cardlength},$config->{cardlength},1,$config->{calling_cards_number_input_timeout},"#","$sound->{cardnumber}","$sound->{cardnumber}",'^[0-9]+$'); + $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); + if ( !$cardinfo ) { + $cardinfo = &get_account_cc( $astpp_db, $cardnum ); + $cc = 1 if $cardinfo; + } + $ASTPP->debug(debug => "CARD BRAND: $cardinfo->{brand} SPECIFIED BRAND: $brand", verbosity => $verbosity); + if ($brand && $brand ne "") { + $cardinfo = "" if $cardinfo->{brand} ne $brand; + } + $ASTPP->debug( debug => "ASTPP Number: $cardnum ", verbosity => $verbosity ); + $ASTPP->debug( debug => "ASTPP Number Status: $cardinfo->{status}", verbosity => $verbosity ); + if ( $cardinfo->{status} != 1 ) { + $session->streamFile($sound->{cardnumber_incorrect}); + } + $retries++; + } + if ( $cardinfo->{status} != 1 ) { + $session->streamFile($sound->{goodbye}); + exit(1); + } +} + +if ( $pin != $cardinfo->{pin} ) { + $retries = 0; + while ( $cardinfo->{pin} != $pin && $retries < $config->{pin_retries} ) { + $pin = $session->playAndGetDigits($config->{pinlength},$config->{pinlength},1,$config->{calling_cards_pin_input_timeout},"#","$sound->{pin}","$sound->{pin}",'^[0-9]+$'); + if ( $cardinfo->{pin} != $pin ) { + $session->streamFile($sound->{pin_incorrect}); + } + $retries++; + } + if ( $pin != $cardinfo->{pin} ) { + $session->streamFile($sound->{pin_incorrect}); + $session->streamFile($sound->{goodbye}); + exit(0); + } +} +&check_card($cardinfo) if $cc == 0; +my $balance = &say_balance($cardinfo); + +# Getting this far means we have a valid card and pin. +$brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0; +if ($brandinfo->{reseller}) { + $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); +} +$config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand}); +$pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ) + if $cc == 0; +$pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) + if $cc == 1; +if ($destination && $destination ne "" ) { + $numberinfo = + &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo ) + if $cc == 0; + $numberinfo = + &get_route( $astpp_db, $config, $destination, $cardinfo->{pricelist}, $cardinfo ) + if $cc == 1; +} +$retries = 0; +while ( !$numberinfo->{pattern} && $retries < $config->{number_retries} ) { + $destination = $session->playAndGetDigits(4,999,1,$config->{calling_cards_dial_input_timeout},"#","$sound->{destination}","$sound->{destination}",'^[0-9]+$'); + $numberinfo = + &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo ); + if ( !$numberinfo->{pattern} ) { + $session->streamFile($sound->{destination_incorrect}); + } else { + $numberinfo->{cost} = $numberinfo->{cost} + $perminsurcharge if $perminsurcharge ne ""; + $numberinfo->{connectcost} = $numberinfo->{connectcost} + $connectsurcharge if $connectsurcharge ne ""; + } + $retries++; +} +if ( !$numberinfo->{pattern} ) { + $session->streamFile($sound->{destination_incorrect}); + $session->streamFile($sound->{goodbye}); + $session->hangup(); + &leave($cardinfo); +} + +# Congratulations, we now have a working card,pin, and phone number. +$stats{destination} = $destination; +#&tell_cost( $numberinfo, $pricelistinfo, $cardinfo ); +my $timelimit = &timelimit( $numberinfo, $pricelistinfo, $cardinfo, $destination ); +$session->streamFile($sound->{please_wait_will_connect}) if $config->{calling_cards_connection_prompt} == 1; +#&dialout( $destination, $timelimit, $numberinfo, $pricelistinfo, $cardinfo, $brandinfo ); + + + + + + + + + +1; + Property changes on: trunk/freeswitch/astpp-callingcards.pl ___________________________________________________________________ Added: svn:executable + * Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2009-02-21 18:19:44 UTC (rev 2235) +++ trunk/freeswitch/astpp-fs-xml.pl 2009-02-21 18:36:58 UTC (rev 2236) @@ -42,7 +42,7 @@ ################# Programs start here ####################################### &initialize; -my ( $xml, $maxlength, $maxmins, $callstatus ); +my ( $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); foreach my $param ( param() ) { $params->{$param} = param($param); $ASTPP->debug( debug => "$param $params->{$param}" ); @@ -58,6 +58,17 @@ destination_number => $params->{'Caller-Destination-Number'} ); +# Check to see if this is a DID. If it is we handle it differently. +# + $didinfo = &get_did($astpp_db, $params->{'Caller-Destination-Number'}); + if ($didinfo->{number}) { + $astppdid = "ASTPP-DID"; + $ASTPP->debug( debug => "This is a call for a DID: "); + $params->{variable_accountcode} = $didinfo->{account}; + } + + + if ( !$params->{variable_accountcode} ) { # First we strip off X digits to see if this account is prepending numbers @@ -130,10 +141,11 @@ my $routeinfo = &get_route( $astpp_db, $config, $params->{'Caller-Destination-Number'}, - $carddata->{pricelist}, $carddata + $carddata->{pricelist}, $carddata,$astppdid ); - $ASTPP->debug( debug => "Minimum Charge on call = " . $routeinfo->{cost} ); + $ASTPP->debug( debug => "Cost: " . $routeinfo->{cost} ); + $ASTPP->debug( debug => "Pricelist: " . $routeinfo->{pricelist} ); my $minimumcharge = $routeinfo->{cost}; my @reseller_list; $ASTPP->debug( debug => "CALLSTATUS: $callstatus MAX_LENGTH: $maxlength" ); @@ -213,9 +225,12 @@ my $routeinfo = &get_route( $astpp_db, $config, $params->{'Caller-Destination-Number'}, - $carddata->{pricelist}, $carddata + $carddata->{pricelist}, $carddata, $astppdid ); + if ($astppdid > 0 ) { + $ASTPP->debug( debug => "THIS IS A DID CALL: $xml"); + } else { # Get the list of routes for the phone number. my @outboundroutes = &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'}, @@ -236,6 +251,7 @@ ); } } + } $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); $ASTPP->debug( debug => $xml ); print $xml; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-01 02:57:45
|
Revision: 2265 http://astpp.svn.sourceforge.net/astpp/?rev=2265&view=rev Author: darrenkw Date: 2009-10-01 02:57:30 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Callingcards are working as of now. Modified Paths: -------------- trunk/freeswitch/astpp-callingcards.pl trunk/freeswitch/astpp-fs-cdr-xml.pl Modified: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl 2009-09-28 15:43:12 UTC (rev 2264) +++ trunk/freeswitch/astpp-callingcards.pl 2009-10-01 02:57:30 UTC (rev 2265) @@ -428,13 +428,12 @@ trunk_name => $route->{trunk} ); my ( $dialedtime, $uniqueid, $answeredtime, $clid ); - $session->execute( "export", "CALLINGCARDS=1" ); if ( $cc == 1 ) { - $session->execute( "export", "ACCOUNTCODE=CC:$cardinfo->{number}" ); + $session->execute( "export", "accountcode=$cardinfo->{number}" ); } else { $session->execute( "export", - "ACCOUNTCODE=CC:$cardinfo->{cardnumber}" ); + "callingcard=$cardinfo->{cardnumber}" ); } $session->execute( "bridge", "$data_string" ); return 1; Modified: trunk/freeswitch/astpp-fs-cdr-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-cdr-xml.pl 2009-09-28 15:43:12 UTC (rev 2264) +++ trunk/freeswitch/astpp-fs-cdr-xml.pl 2009-10-01 02:57:30 UTC (rev 2265) @@ -63,7 +63,7 @@ my $data = $xml->XMLin($params->{cdr}); # print output -#print STDERR Dumper($data); +print STDERR Dumper($data); my $tmp = "INSERT INTO " . $config->{freeswitch_cdr_table} . "(accountcode,src,dst,dcontext,clid,channel,dstchannel,lastapp," @@ -162,32 +162,34 @@ print STDERR "VENDOR CHARGES: " . $config->{trackvendorcharges} . "\n"; &vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $data->{callflow}->{caller_profile}->{uuid},"" ) if $config->{trackvendorcharges} == 1; -&process_callingcard_cdr if $data->{variables}->{CALLINGCARDS} == 1; +&process_callingcard_cdr if $data->{variables}->{callingcard}; sub process_callingcard_cdr() { my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc ); - my $cardnumber = substr( $data->{variables}->{accountcode}, 3 ); + my $destination = $data->{callflow}->{caller_profile}->{destination_number}; + $destination =~ s/@.*//g; + my $cardnumber = $data->{variables}->{callingcard}; $cardinfo = &get_callingcard( $astpp_db, $cardnumber, $config ); if ( !$cardinfo ) { $cardinfo = &get_account_cc( $astpp_db, $cardnumber ); $cc = 1 if $cardinfo; } -$brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0; -if ($brandinfo->{reseller}) { - $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); -} -$config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand}); -$pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ) - if $cc == 0; -$pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) - if $cc == 1; + $brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0; + if ($brandinfo->{reseller}) { + $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); + } + $config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand}); + $pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ) + if $cc == 0; + $pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) + if $cc == 1; print STDERR "THIS IS A CALLINGCARD CALL! \n"; print STDERR "CARD: $cardinfo->{cardnumber} \n"; print STDERR "CARD: $cardnumber \n"; $numberinfo = &get_route( $astpp_db, $config, - $data->{callflow}->{caller_profile}->{destination_number}, + $destination, $brandinfo->{pricelist}, $cardinfo ); if ( $data->{variables}->{billsec} > 0 ) @@ -235,14 +237,14 @@ ( ( $cardinfo->{min_length_pennies} * 100 ) + $charge ); } - + print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber}; &write_callingcard_cdr( $astpp_db, $config, $cardinfo, uri_unescape($data->{variables}->{caller_id}), - $data->{callflow}->{caller_profile}->{destination_number}, - $data->{variables}->{hangup_cause}, + $destination, + uri_unescape($data->{variables}->{hangup_cause}), uri_unescape($data->{variables}->{start_stamp}), $charge, $data->{variables}->{billsec} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2011-01-05 06:12:20
|
Revision: 2326 http://astpp.svn.sourceforge.net/astpp/?rev=2326&view=rev Author: darrenkw Date: 2011-01-05 06:12:12 +0000 (Wed, 05 Jan 2011) Log Message: ----------- Replaced XML::Simple Modified Paths: -------------- trunk/freeswitch/astpp-callingcards.pl trunk/freeswitch/astpp-fs-cdr-xml.pl Modified: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl 2010-12-31 02:39:20 UTC (rev 2325) +++ trunk/freeswitch/astpp-callingcards.pl 2011-01-05 06:12:12 UTC (rev 2326) @@ -431,11 +431,12 @@ if ( $cc == 1 ) { $session->execute( "export", "accountcode=CC:$cardinfo->{number}" ); $session->execute( "export", "callingcard=$cardinfo->{number}" ); + $session->execute( "export", "calldestination=$destination" ); } else { - $session->execute( "export", - "accountcode=CC:$cardinfo->{cardnumber}" ); + $session->execute( "export", "accountcode=CC:$cardinfo->{cardnumber}" ); $session->execute( "export", "callingcard=$cardinfo->{cardnumber}" ); + $session->execute( "export", "calldestination=$destination" ); } $session->execute( "bridge", "$data_string" ); return 1; Modified: trunk/freeswitch/astpp-fs-cdr-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-cdr-xml.pl 2010-12-31 02:39:20 UTC (rev 2325) +++ trunk/freeswitch/astpp-fs-cdr-xml.pl 2011-01-05 06:12:12 UTC (rev 2326) @@ -19,9 +19,12 @@ use ASTPP; use URI::Escape; use strict; -use XML::Simple; +#use XML::Simple; use Data::Dumper; +#use XML::Twig; +use XML::LibXML; + use vars qw($cdr_db $params $ASTPP @output $config $freeswitch_db $astpp_db $verbosity ); use Locale::gettext_pp qw(:locale_h); @@ -53,122 +56,172 @@ foreach my $param ( param() ) { $params->{$param} = param($param); } +my $cdrinfo; -#print STDERR $params->{cdr}; +print STDERR $params->{cdr}; -# create object -my $xml = new XML::Simple; +my $parser = XML::LibXML->new(); +my $cdr = $parser->parse_string($params->{cdr}); -# read XML file -my $data = $xml->XMLin($params->{cdr}); +foreach my $var ($cdr->findnodes('/cdr/channel_data/direction')) { + $cdrinfo->{direction} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/callingcard')) { + $cdrinfo->{callingcard} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/callingcard_destination')) { + $cdrinfo->{callingcard_destination} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/accountcode')) { + $cdrinfo->{accountcode} = uri_unescape($var->to_literal); +} +foreach my $var ($cdr->findnodes('/cdr/variables/caller_id')) { + $cdrinfo->{caller_id} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/channel_name')) { + $cdrinfo->{channel_name} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/last_app')) { + $cdrinfo->{last_app} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/last_arg')) { + $cdrinfo->{last_arg} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/start_stamp')) { + $cdrinfo->{start_stamp} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/answer_stamp')) { + $cdrinfo->{answer_stamp} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/end_stamp')) { + $cdrinfo->{end_stamp} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/duration')) { + $cdrinfo->{duration} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/billsec')) { + $cdrinfo->{billsec} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/hangup_cause')) { + $cdrinfo->{hangup_cause} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/read_code')) { + $cdrinfo->{read_code} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/write_code')) { + $cdrinfo->{write_code} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/provider')) { + $cdrinfo->{provider} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/trunk')) { + $cdrinfo->{trunk} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/outbound_route')) { + $cdrinfo->{outbound_route} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/progressmsec')) { + $cdrinfo->{progressmess} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/answermsec')) { + $cdrinfo->{answermsec} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/variables/progress_mediamsec')) { + $cdrinfo->{progress_mediamsec} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/callflow/caller_profile/username')) { + $cdrinfo->{username} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/callflow/caller_profile/destination_number')) { + $cdrinfo->{destination_number} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/callflow/caller_profile/context')) { + $cdrinfo->{context} = $var->to_literal; +} +foreach my $var ($cdr->findnodes('/cdr/callflow/caller_profile/uuid')) { + $cdrinfo->{uuid} = $var->to_literal; +} +if ($cdrinfo->{callingcard_destination} && $cdrinfo->{direction} eq "outbound") { + $cdrinfo->{destination_number} = $cdrinfo->{callingcard_destination}; +} -# print output -print STDERR Dumper($data); +print STDERR Dumper $cdrinfo; - my $tmp = "INSERT INTO " . $config->{freeswitch_cdr_table} . "(accountcode,src,dst,dcontext,clid,channel,dstchannel,lastapp," . "lastdata,calldate,answerdate,enddate,duration,billsec,disposition,amaflags,uniqueid,userfield,read_codec," . "write_codec,cost,vendor,provider,trunk,outbound_route,progressmsec,answermsec,progress_mediamsec) VALUES (" - . "'" - . $data->{variables}->{accountcode} - . "'" + . "'" . $cdrinfo->{accountcode} . "'" + . "," + . "'" . $cdrinfo->{username} . "'" . "," - . "'" - . $data->{callflow}->{caller_profile}->{username} - . "'" + . "'" . $cdrinfo->{destination_number} . "'" . "," -# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{destination_number}) - . "'" - . $data->{callflow}->{caller_profile}->{destination_number} - . "'" + . "'" . $cdrinfo->{context} . "'" . "," -# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{context}) - . "'" - . $data->{callflow}->{caller_profile}->{context} - . "'" + . "'" . uri_unescape($cdrinfo->{caller_id}) . "'" . "," - . "'" - . uri_unescape($data->{variables}->{caller_id}) - . "'" -# . "\"" . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{caller_id_name}) . "\"" -# . "<" . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{caller_id_number}) . ">" -# . "\"" . $data->{callflow}->{caller_profile}->{caller_id_name} . "\"" -# . "<" . $data->{callflow}->{caller_profile}->{caller_id_number} . ">" + . "'" . uri_unescape($cdrinfo->{channel_name}) . "'" . "," - . "'" - . uri_unescape($data->{variables}->{channel_name}) - . "'" - . "," . "''" . "," - . "'" . $data->{variables}->{last_app} . "'" + . "'" . $cdrinfo->{last_app} . "'" . "," - . "'" . uri_unescape($data->{variables}->{last_arg}) . "'" + . "'" . uri_unescape($cdrinfo->{last_arg}) . "'" . "," - . "'" - . uri_unescape($data->{variables}->{start_stamp}) - . "'" + . "'" . uri_unescape($cdrinfo->{start_stamp}) . "'" . "," - . "'" . uri_unescape($data->{variables}->{answer_stamp}) . "'" + . "'" . uri_unescape($cdrinfo->{answer_stamp}) . "'" . "," - . "'" - . uri_unescape($data->{variables}->{end_stamp}) - . "'" + . "'" . uri_unescape($cdrinfo->{end_stamp}) . "'" . "," - . "'" - . $data->{variables}->{duration} - . "'" + . "'" . $cdrinfo->{duration} . "'" . "," - . "'" - . $data->{variables}->{billsec} - . "'" + . "'" . $cdrinfo->{billsec} . "'" . "," - . "'" - . $data->{variables}->{hangup_cause} - . "'" + . "'" . $cdrinfo->{hangup_cause} . "'" . "," . "''" . "," - . "'" - . $data->{callflow}->{caller_profile}->{uuid} - . "'" + . "'" . $cdrinfo->{uuid} . "'" . "," . "''" . "," - . "'" . $data->{variables}->{read_code} . "'" + . "'" . $cdrinfo->{read_code} . "'" . "," - . "'" . $data->{variables}->{write_code} . "'" + . "'" . $cdrinfo->{write_code} . "'" . ",'none','none'" . "," - . "'" . $data->{variables}->{provider} . "'" + . "'" . $cdrinfo->{provider} . "'" . "," - . "'" . $data->{variables}->{trunk} . "'" + . "'" . $cdrinfo->{trunk} . "'" . "," - . "'" . $data->{variables}->{outbound_route} . "'" + . "'" . $cdrinfo->{outbound_route} . "'" . "," - . "'" . $data->{variables}->{progressmsec} . "'" + . "'" . $cdrinfo->{progressmsec} . "'" . "," - . "'" . $data->{variables}->{answermsec} . "'" + . "'" . $cdrinfo->{answermsec} . "'" . "," - . "'" . $data->{variables}->{progress_mediamsec} . "'" + . "'" . $cdrinfo->{progress_mediamsec} . "'" . ")"; print STDERR "\n" . $tmp . "\n"; $cdr_db->do($tmp); -print "Wrote CDR"; +print "Wrote CDR\n"; my (@chargelist); -push @chargelist, $data->{callflow}->{caller_profile}->{uuid}; +push @chargelist, $cdrinfo->{uuid}; &processlist( $astpp_db, $cdr_db, $config, \@chargelist ); print STDERR "VENDOR CHARGES: " . $config->{trackvendorcharges} . "\n"; -&vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $data->{callflow}->{caller_profile}->{uuid},"" ) if $config->{trackvendorcharges} == 1; +&vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $cdrinfo->{uuid},"" ) if $config->{trackvendorcharges} == 1; -&process_callingcard_cdr if $data->{variables}->{callingcard}; +if ($cdrinfo->{callingcard_destination} && $cdrinfo->{direction} eq "outbound") { + &process_callingcard_cdr; +} sub process_callingcard_cdr() { my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc ); - my $destination = $data->{callflow}->{caller_profile}->{destination_number}; + my $destination = $cdrinfo->{destination_number}; $destination =~ s/@.*//g; - my $cardnumber = $data->{variables}->{callingcard}; + my $cardnumber = $cdrinfo->{callingcard}; $cardinfo = &get_callingcard( $astpp_db, $cardnumber, $config ); if ( !$cardinfo ) { $cardinfo = &get_account_cc( $astpp_db, $cardnumber ); @@ -192,7 +245,7 @@ $destination, $brandinfo->{pricelist}, $cardinfo ); - if ( $data->{variables}->{billsec} > 0 ) + if ( $cdrinfo->{billsec} > 0 ) { $ASTPP->debug( debug => "CALL ANSWERED", @@ -207,13 +260,13 @@ } $ASTPP->debug( debug => -"$numberinfo->{connectcost}, $numberinfo->{cost}, $data->{variables}->{billsec}, $increment, $numberinfo->{includedseconds}", +"$numberinfo->{connectcost}, $numberinfo->{cost}, $cdrinfo->{billsec}, $increment, $numberinfo->{includedseconds}", verbosity => $verbosity ); my $charge = &calc_call_cost( $numberinfo->{connectcost}, $numberinfo->{cost}, - $data->{variables}->{billsec}, + $cdrinfo->{billsec}, $increment, $numberinfo->{includedseconds} ); @@ -226,12 +279,12 @@ ( ( $cardinfo->{minute_fee_pennies} * 100 ) + $charge ) if $cardinfo->{timeused} + - $data->{variables}->{billsec} => + $cdrinfo->{billsec} => $cardinfo->{minute_fee_minutes}; } if ( $cardinfo->{min_length_pennies} > 0 && ( $cardinfo->{min_length_minutes} * 60 ) > - $data->{variables}->{billsec} ) + $cdrinfo->{billsec} ) { $charge = ( ( $cardinfo->{min_length_pennies} * 100 ) + @@ -242,12 +295,12 @@ $astpp_db, $config, $cardinfo, - uri_unescape($data->{variables}->{caller_id}), + uri_unescape($cdrinfo->{caller_id}), $destination, - uri_unescape($data->{variables}->{hangup_cause}), - uri_unescape($data->{variables}->{start_stamp}), + uri_unescape($cdrinfo->{hangup_cause}), + uri_unescape($cdrinfo->{start_stamp}), $charge, - $data->{variables}->{billsec} + $cdrinfo->{billsec} ); &callingcard_set_in_use($astpp_db,$cardinfo,0); &callingcard_update_balance($astpp_db,$cardinfo,$charge); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2011-01-11 03:19:12
|
Revision: 2328 http://astpp.svn.sourceforge.net/astpp/?rev=2328&view=rev Author: darrenkw Date: 2011-01-11 03:19:05 +0000 (Tue, 11 Jan 2011) Log Message: ----------- Fixed a few issues. Modified Paths: -------------- trunk/freeswitch/astpp-fs-cdr-xml.pl trunk/freeswitch/astpp-fs-xml.pl Modified: trunk/freeswitch/astpp-fs-cdr-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-cdr-xml.pl 2011-01-05 06:13:02 UTC (rev 2327) +++ trunk/freeswitch/astpp-fs-cdr-xml.pl 2011-01-11 03:19:05 UTC (rev 2328) @@ -16,12 +16,10 @@ use DBI; use CGI; use CGI qw/:standard Vars/; -use ASTPP; +use ASTPP ':all'; use URI::Escape; use strict; -#use XML::Simple; use Data::Dumper; -#use XML::Twig; use XML::LibXML; @@ -145,7 +143,7 @@ $cdrinfo->{destination_number} = $cdrinfo->{callingcard_destination}; } -print STDERR Dumper $cdrinfo; +print STDERR Dumper $cdrinfo if $config->{debug} == 1; my $tmp = "INSERT INTO " . $config->{freeswitch_cdr_table} . "(accountcode,src,dst,dcontext,clid,channel,dstchannel,lastapp," . "lastdata,calldate,answerdate,enddate,duration,billsec,disposition,amaflags,uniqueid,userfield,read_codec," @@ -204,22 +202,23 @@ . "'" . $cdrinfo->{progress_mediamsec} . "'" . ")"; -print STDERR "\n" . $tmp . "\n"; +print STDERR "\n" . $tmp . "\n" if $config->{debug} == 1; $cdr_db->do($tmp); print "Wrote CDR\n"; my (@chargelist); push @chargelist, $cdrinfo->{uuid}; &processlist( $astpp_db, $cdr_db, $config, \@chargelist ); -print STDERR "VENDOR CHARGES: " . $config->{trackvendorcharges} . "\n"; +print STDERR "VENDOR CHARGES: " . $config->{trackvendorcharges} . "\n" if $config->{debug} == 1; &vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $cdrinfo->{uuid},"" ) if $config->{trackvendorcharges} == 1; -if ($cdrinfo->{callingcard_destination} && $cdrinfo->{direction} eq "outbound") { +if ( $cdrinfo->{callingcard_destination} && $cdrinfo->{direction} eq "outbound") { &process_callingcard_cdr; } sub process_callingcard_cdr() { my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc ); my $destination = $cdrinfo->{destination_number}; + $cdrinfo->{billsec} = 0 if $cdrinfo->{hangup_cause} ne "NORMAL_CLEARING"; $destination =~ s/@.*//g; my $cardnumber = $cdrinfo->{callingcard}; $cardinfo = &get_callingcard( $astpp_db, $cardnumber, $config ); @@ -237,9 +236,9 @@ $pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) if $cc == 1; - print STDERR "THIS IS A CALLINGCARD CALL! \n"; - print STDERR "CARD: $cardinfo->{cardnumber} \n"; - print STDERR "CARD: $cardnumber \n"; + print STDERR "THIS IS A CALLINGCARD CALL! \n" if $config->{debug} == 1; + print STDERR "CARD: $cardinfo->{cardnumber} \n" if $config->{debug} == 1; + print STDERR "CARD: $cardnumber \n" if $config->{debug} == 1; $numberinfo = &get_route( $astpp_db, $config, $destination, @@ -290,7 +289,7 @@ ( ( $cardinfo->{min_length_pennies} * 100 ) + $charge ); } - print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber}; + print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber} if $config->{debug} == 1; &write_callingcard_cdr( $astpp_db, $config, @@ -304,7 +303,8 @@ ); &callingcard_set_in_use($astpp_db,$cardinfo,0); &callingcard_update_balance($astpp_db,$cardinfo,$charge); - } + } + &callingcard_set_in_use($astpp_db,$cardinfo,0); } Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2011-01-05 06:13:02 UTC (rev 2327) +++ trunk/freeswitch/astpp-fs-xml.pl 2011-01-11 03:19:05 UTC (rev 2328) @@ -16,7 +16,7 @@ use DBI; use CGI; use CGI qw/:standard Vars/; -use ASTPP; +use ASTPP ':all'; use XML::Simple; use Data::Dumper; use URI::Escape; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |