[Astpp-commit] SF.net SVN: astpp:[2264] trunk/freeswitch/astpp-fs-cdr-xml.pl
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2009-09-28 15:43:27
|
Revision: 2264
http://astpp.svn.sourceforge.net/astpp/?rev=2264&view=rev
Author: darrenkw
Date: 2009-09-28 15:43:12 +0000 (Mon, 28 Sep 2009)
Log Message:
-----------
Missed committing the realtime xml cdr writer and rating engine.
Added Paths:
-----------
trunk/freeswitch/astpp-fs-cdr-xml.pl
Added: trunk/freeswitch/astpp-fs-cdr-xml.pl
===================================================================
--- trunk/freeswitch/astpp-fs-cdr-xml.pl (rev 0)
+++ trunk/freeswitch/astpp-fs-cdr-xml.pl 2009-09-28 15:43:12 UTC (rev 2264)
@@ -0,0 +1,256 @@
+#!/usr/bin/perl
+#
+# ASTPP - Open Source Voip Billing
+#
+# Copyright (C) 2008, 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.
+############################################################
+#
+# Usage-example:
+#
+
+use DBI;
+use CGI;
+use CGI qw/:standard Vars/;
+use ASTPP;
+use URI::Escape;
+use strict;
+use XML::Simple;
+use Data::Dumper;
+
+use vars
+ qw($cdr_db $params $ASTPP @output $config $freeswitch_db $astpp_db $verbosity );
+use Locale::gettext_pp qw(:locale_h);
+require "/usr/local/astpp/astpp-common.pl";
+$ENV{LANGUAGE} = "en"; # de, es, br - whatever
+print STDERR "Interface language is set to: " . $ENV{LANGUAGE} . "\n";
+bindtextdomain( "astpp", "/usr/local/share/locale" );
+textdomain("astpp");
+$verbosity = 2;
+@output = ("STDERR");
+$ASTPP = ASTPP->new;
+$ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be.
+
+sub initialize() {
+ $config = &load_config();
+ $astpp_db = &connect_db( $config, @output );
+ $ASTPP->set_astpp_db($astpp_db);
+ $config = &load_config_db( $astpp_db, $config ) if $astpp_db;
+ $freeswitch_db = &connect_freeswitch_db( $config, @output );
+ $ASTPP->set_freeswitch_db($freeswitch_db);
+ $cdr_db = &cdr_connect_db( $config, @output );
+ $config->{cdr_table} = $config->{freeswitch_cdr_table};
+}
+
+################# Programs start here #######################################
+print header( -type => 'text/plain' );
+&initialize;
+my ( $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo );
+foreach my $param ( param() ) {
+ $params->{$param} = param($param);
+}
+
+#print STDERR $params->{cdr};
+
+# create object
+my $xml = new XML::Simple;
+
+# read XML file
+my $data = $xml->XMLin($params->{cdr});
+
+# print output
+#print STDERR Dumper($data);
+
+
+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}
+ . "'"
+ . ","
+ . "'"
+ . $data->{callflow}->{caller_profile}->{username}
+ . "'"
+ . ","
+# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{destination_number})
+ . "'"
+ . $data->{callflow}->{caller_profile}->{destination_number}
+ . "'"
+ . ","
+# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{context})
+ . "'"
+ . $data->{callflow}->{caller_profile}->{context}
+ . "'"
+ . ","
+ . "'"
+ . 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($data->{variables}->{channel_name})
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'" . $data->{variables}->{last_app} . "'"
+ . ","
+ . "'" . uri_unescape($data->{variables}->{last_arg}) . "'"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{start_stamp})
+ . "'"
+ . ","
+ . "'" . uri_unescape($data->{variables}->{answer_stamp}) . "'"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{end_stamp})
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{duration}
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{billsec}
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{hangup_cause}
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'"
+ . $data->{callflow}->{caller_profile}->{uuid}
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'" . $data->{variables}->{read_code} . "'"
+ . ","
+ . "'" . $data->{variables}->{write_code} . "'"
+ . ",'none','none'"
+ . ","
+ . "'" . $data->{variables}->{provider} . "'"
+ . ","
+ . "'" . $data->{variables}->{trunk} . "'"
+ . ","
+ . "'" . $data->{variables}->{outbound_route} . "'"
+ . ","
+ . "'" . $data->{variables}->{progressmsec} . "'"
+ . ","
+ . "'" . $data->{variables}->{answermsec} . "'"
+ . ","
+ . "'" . $data->{variables}->{progress_mediamsec} . "'"
+ . ")";
+
+print STDERR "\n" . $tmp . "\n";
+$cdr_db->do($tmp);
+print "Wrote CDR";
+my (@chargelist);
+push @chargelist, $data->{callflow}->{caller_profile}->{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;
+
+&process_callingcard_cdr if $data->{variables}->{CALLINGCARDS} == 1;
+
+sub process_callingcard_cdr() {
+ my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc );
+ my $cardnumber = substr( $data->{variables}->{accountcode}, 3 );
+ $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;
+
+ 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},
+ $brandinfo->{pricelist}, $cardinfo
+ );
+ if ( $data->{variables}->{billsec} > 0 )
+ {
+ $ASTPP->debug(
+ debug => "CALL ANSWERED",
+ verbosity => $verbosity
+ );
+ my $increment;
+ if ( $numberinfo->{inc} > 0 ) {
+ $increment = $numberinfo->{inc};
+ }
+ else {
+ $increment = $pricelistinfo->{inc};
+ }
+ $ASTPP->debug(
+ debug =>
+"$numberinfo->{connectcost}, $numberinfo->{cost}, $data->{variables}->{billsec}, $increment, $numberinfo->{includedseconds}",
+ verbosity => $verbosity
+ );
+ my $charge = &calc_call_cost(
+ $numberinfo->{connectcost},
+ $numberinfo->{cost},
+ $data->{variables}->{billsec},
+ $increment,
+ $numberinfo->{includedseconds}
+ );
+ $ASTPP->debug(
+ debug => "Cost $charge ",
+ verbosity => $verbosity
+ );
+ if ( $cardinfo->{minute_fee_pennies} > 0 ) {
+ $charge =
+ ( ( $cardinfo->{minute_fee_pennies} * 100 ) +
+ $charge )
+ if $cardinfo->{timeused} +
+ $data->{variables}->{billsec} =>
+ $cardinfo->{minute_fee_minutes};
+ }
+ if ( $cardinfo->{min_length_pennies} > 0
+ && ( $cardinfo->{min_length_minutes} * 60 ) >
+ $data->{variables}->{billsec} )
+ {
+ $charge =
+ ( ( $cardinfo->{min_length_pennies} * 100 ) +
+ $charge );
+ }
+
+ &write_callingcard_cdr(
+ $astpp_db,
+ $config,
+ $cardinfo,
+ uri_unescape($data->{variables}->{caller_id}),
+ $data->{callflow}->{caller_profile}->{destination_number},
+ $data->{variables}->{hangup_cause},
+ uri_unescape($data->{variables}->{start_stamp}),
+ $charge,
+ $data->{variables}->{billsec}
+ );
+ &callingcard_set_in_use($astpp_db,$cardinfo,0);
+ &callingcard_update_balance($astpp_db,$cardinfo,$charge);
+ }
+ }
+
+
+exit(0);
Property changes on: trunk/freeswitch/astpp-fs-cdr-xml.pl
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|