astpp-commit Mailing List for ASTPP - Open Source Voip Billing (Page 3)
Brought to you by:
darrenkw
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(8) |
Oct
(1) |
Nov
(34) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
(3) |
Jul
(1) |
Aug
(3) |
Sep
(8) |
Oct
(3) |
Nov
(11) |
Dec
(6) |
2009 |
Jan
(9) |
Feb
(11) |
Mar
(6) |
Apr
(3) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
(14) |
Oct
(32) |
Nov
(2) |
Dec
|
2010 |
Jan
(1) |
Feb
(11) |
Mar
(2) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
|
Dec
(5) |
2011 |
Jan
(7) |
Feb
|
Mar
(1) |
Apr
(3) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dar...@us...> - 2009-10-09 14:59:52
|
Revision: 2288 http://astpp.svn.sourceforge.net/astpp/?rev=2288&view=rev Author: darrenkw Date: 2009-10-09 14:59:42 +0000 (Fri, 09 Oct 2009) Log Message: ----------- This file can be run as an apache module. Added Paths: ----------- trunk/freeswitch/ASTPP.pm Added: trunk/freeswitch/ASTPP.pm =================================================================== --- trunk/freeswitch/ASTPP.pm (rev 0) +++ trunk/freeswitch/ASTPP.pm 2009-10-09 14:59:42 UTC (rev 2288) @@ -0,0 +1,559 @@ +package ModPerl::ASTPP; + +# +# 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 Apache2::Const qw(:common); +use Apache2::Request; +use Apache::DBI; +use DBI; +use CGI; +use CGI qw/:standard Vars/; +use ASTPP; +use XML::Simple; +use Data::Dumper; +use URI::Escape; +use Time::HiRes qw( gettimeofday tv_interval ); + +use POSIX; +use POSIX qw(strftime); + +use strict; +$Apache::DBI::DEBUG = 2; + +use vars + qw( $cdr_db $ASTPP @output $config $freeswitch_db $astpp_db $verbosity ); +use Locale::gettext_pp qw(:locale_h); +my $starttime = [gettimeofday]; +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 ####################################### +&initialize; + +sub handler { + my $r = shift; +my ( $ipinfo, $params,$xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); +my $starttime = [gettimeofday]; +my $q = new CGI; + + +foreach my $param ( $q->param() ) { + $params->{$param} = $q->param($param); + $ASTPP->debug( debug => "$param $params->{$param}" ); +} + +$xml = header( -type => 'text/plain' ); + +$ASTPP->debug( + debug => "Destination = $params->{'Caller-Destination-Number'}" ); + +if ( $params->{section} eq "dialplan" ) { + # 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 + # as authentications + $ASTPP->debug( debug => "Checking CC Number: " + . $params->{'Caller-Destination-Number'} ); + my $cc = substr( $params->{'Caller-Destination-Number'}, + 0, $config->{cardlength} ); + my $sql = + $astpp_db->prepare("SELECT number FROM accounts WHERE cc = $cc"); + $sql->execute; + my $record = $sql->fetchrow_hashref; + $sql->finish; + $params->{variable_accountcode} = $record->{cardnum} + if ( $record->{cardnum} ); + } + if ( !$params->{variable_accountcode} ) { + $ASTPP->debug( + debug => "Checking IP Address:" . $params->{'Hunt-Network-Addr'} ); + $ipinfo = $ASTPP->ip_address_authenticate( + ip_address => $params->{'Hunt-Network-Addr'}, + destination => $params->{'Caller-Destination-Number'} + ); + if ($ipinfo->{account} ne "") { + $params->{variable_accountcode} = $ipinfo->{account}; + $params->{'Caller-Destination-Number'} =~ s/$ipinfo->{prefix}//g; + } + } +print STDERR "IP ACCOUNT: $ipinfo->{account} \n"; + + $xml = $ASTPP->fs_dialplan_xml_header( + xml => $xml, + destination_number => $params->{'Caller-Destination-Number'}, + DID => $didinfo->{number}, + IP => 123 #$ipinfo->{account} + ); + + $ASTPP->debug( debug => +"$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}" + ); + + my $carddata = + &get_account( $astpp_db, $params->{variable_accountcode} ) + ; # Fetch all the account info from the db. + + if ( !$carddata->{number} ) + { # Check to see if the account exists. If not then exit. + $ASTPP->debug( debug => "CALLSTATUS 2" ); + $ASTPP->debug( debug => "CANNOT RETRIEVE CARD" ); + $xml .= + "<action application=\"reject\" data=\"CANNOT RETRIEVE ACCOUNT\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); +# print $xml; + $ASTPP->debug( debug => "Returning nothing so dialplan can continue." ); + $r->print(""); + +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; + + exit(1); +# return OK; + } + + if ( $carddata->{dialed_modify} ) { + my @regexs = split( m/,/m, $carddata->{dialed_modify} ); + foreach my $regex (@regexs) { + $regex =~ s/"//g; #Strip off quotation marks + my ( $grab, $replace ) = split( m!/!i, $regex ) + ; # This will split the variable into a "grab" and "replace" as needed + $ASTPP->debug( debug => "Grab: $grab" ); + $ASTPP->debug( debug => "Replacement: $replace" ); + $ASTPP->debug( debug => + "Phone Before: $params->{'Caller-Destination-Number'}" ); + $$params->{'Caller-Destination-Number'} =~ s/$grab/$replace/is; + $ASTPP->debug( debug => + "Phone After: $params->{'Caller-Destination-Number'}" ); + } + } + + $ASTPP->debug( debug => "FINDING LIMIT FOR: " . $carddata->{number} ); + ( $callstatus, $maxlength ) = + &max_length( $astpp_db, $config, $carddata, + $params->{'Caller-Destination-Number'} ); + + my $routeinfo = &get_route( + $astpp_db, $config, + $params->{'Caller-Destination-Number'}, + $carddata->{pricelist}, $carddata,$astppdid + ); + + $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" ); + + if (!$routeinfo->{cost} && !$routeinfo->{pricelist}) { + $ASTPP->debug( debug => "COULD NOT FIND ROUTE. EXITING SO DIALPLAN CAN TAKE OVER" ); +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; + $r->print($xml); + exit(1); +# return OK; + } + while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1 ) { + $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}" ); + $carddata = &get_account( $astpp_db, $carddata->{reseller} ); + push @reseller_list, $carddata->{number}; + $ASTPP->debug( debug => +"ADDING $carddata->{number} to the list of resellers for this account" + ); + my ( $resellercallstatus, $resellermaxlength ) = + &max_length( $astpp_db, $config, $carddata, + $params->{'Caller-Destination-Number'} ); + my $routeinfo = &get_route( + $astpp_db, $config, + $params->{'Caller-Destination-Number'}, + $carddata->{pricelist}, $carddata + ); + if ( $resellercallstatus != 1 ) { + $carddata->{reseller} = ""; + $callstatus = $resellercallstatus; + } + elsif ( $resellermaxlength < $maxlength ) { + $maxlength = $resellermaxlength; + } + $ASTPP->debug( debug => +"Reseller cost = $routeinfo->{cost} and minimum charge is $minimumcharge" + ); + if ( $resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) { + $ASTPP->debug( debug => + "Reseller call is priced too cheap! Call being barred!" ); + $xml .= +"<action application=\"reject\" data=\"Reseller call is priced too cheap! Call being barred!\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + $r->print( $xml); +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; + exit(1); + } + $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength" ); + $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus" ); + } + + if ( $config->{debug} == 1 ) { + $ASTPP->debug( debug => "PRINTING LIST OF RESELLERS FOR THIS ACCOUNT" ); + foreach my $reseller (@reseller_list) { + $ASTPP->debugb( debug => "RESELLER: $reseller" ); + } + } + + $ASTPP->debug("Max Call Length: $maxlength minutes"); + $ASTPP->debug("Call Status: $callstatus"); + + if ( $maxlength <= 1 ) { + $ASTPP->debug( debug => "NOT ENOUGH CREDIT" ); + $xml .= "<action application=\"reject\" data=\"NOT ENOUGH CREDIT\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + $r->print( $xml); +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; + exit(1); + } elsif ($config->{call_max_length} && $maxlength < $config->{call_max_length} / 1000){ + $maxlength = $config->{call_max_length} / 1000; + } + + $xml = $ASTPP->fs_dialplan_xml_timelimit( + xml => $xml, + max_length => $maxlength, + accountcode => $carddata->{number} + ); + +# Set the timelimit as well as other variables which are needed in the dialplan. + my $timelimit = + "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)"; + + $ASTPP->debug( debug => "Looking for outbound Route" ); + $routeinfo = &get_route( + $astpp_db, $config, + $params->{'Caller-Destination-Number'}, + $carddata->{pricelist}, $carddata, $astppdid + ); + + if ($didinfo->{number} ) { + $ASTPP->debug( debug => "THIS IS A DID CALL: $xml"); + my ($returned_data) = $ASTPP->fs_dialplan_xml_did( + did => $params->{'Caller-Destination-Number'} + ); + $xml .= $returned_data; + } else { + # Get the list of routes for the phone number. + my @outboundroutes = + &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'}, + $carddata, $routeinfo, @reseller_list ); + foreach my $route (@outboundroutes) { + $ASTPP->debug( debug => + "$route->{trunk}: cost $route->{cost}\t $route->{pattern}" ); + if ( $route->{cost} > $routeinfo->{cost} ) { + $ASTPP->debug( debug => +"$route->{trunk}: $route->{cost} > $routeinfo->{cost}, skipping" + ); + } + else { + my ($returned_data,$junk) = $ASTPP->fs_dialplan_xml_bridge( + destination_number => $params->{'Caller-Destination-Number'}, + route_prepend => $route->{prepend}, + trunk_name => $route->{trunk}, + route_id => $route->{id} + ); + $xml .= $returned_data; + } + } + } + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + $ASTPP->debug( debug => $xml ); + print $xml; + exit(1); +} +if ( $params->{section} eq "directory" ) { + + #hostname darren-laptop + #section directory + #tag_name domain + #key_name name + #key_value 192.168.2.119 + #action sip_auth + #sip_profile internal + #sip_user_agent Zoiper rev.1118 + #sip_auth_username 1000 + #sip_auth_realm 192.168.2.119 + #sip_auth_nonce 83005e62-7e13-11dd-9eb1-25560b0691a8 + #sip_auth_uri sip:192.168.2.119;transport=UDP + #sip_auth_qop auth + #sip_auth_cnonce a79169d2656f292a + #sip_auth_nc 00000001 + #sip_auth_response 4475154556879ec2017978f1347192a6 + #sip_auth_method REGISTER + #key id + #user 1000 + #domain 192.168.2.119 + #ip 192.168.2.119 + + if ($params->{'user'}) { + $xml = $ASTPP->fs_directory_xml_header( xml => $xml ); + $xml = $ASTPP->fs_directory_xml( + xml => $xml, + ip => $params->{'ip'}, + user => $params->{'user'}, + domain => $params->{'domain'} + ); + $xml = $ASTPP->fs_directory_xml_footer( xml => $xml ); + } + $ASTPP->debug( debug => $xml ); + $r->print ($xml); + exit(1); +} +if ( $params->{cdr} ) { + +$r->print(header( -type => 'text/plain' )); + +# 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); +$r->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"; +if ($config->{trackvendorcharges} == 1 && $data->{variables}->{accountcode}) { + &vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $data->{callflow}->{caller_profile}->{uuid},""); +} + +&process_callingcard_cdr if $data->{variables}->{callingcard}; + +sub process_callingcard_cdr() { + my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc ); + 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; + + 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, + $destination, + $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 ); + } + print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber}; + &write_callingcard_cdr( + $astpp_db, + $config, + $cardinfo, + uri_unescape($data->{variables}->{caller_id}), + $destination, + uri_unescape($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); + } + } + + +} + +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; +} +my $generation_time = tv_interval($starttime); +print STDERR "TOOK: " . $generation_time ; +1; Property changes on: trunk/freeswitch/ASTPP.pm ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-09 14:57:49
|
Revision: 2287 http://astpp.svn.sourceforge.net/astpp/?rev=2287&view=rev Author: darrenkw Date: 2009-10-09 14:57:38 +0000 (Fri, 09 Oct 2009) Log Message: ----------- Add some sql finish statements. Modified Paths: -------------- trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-08 05:07:10 UTC (rev 2286) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-09 14:57:38 UTC (rev 2287) @@ -258,7 +258,7 @@ . " AND prefix IN (NULL,'') OR ip = " . $self->{_astpp_db}->quote($arg{ip_address}); $tmp .= " AND " . $self->{_astpp_db}->quote($arg{destination}) . " RLIKE prefix" if $arg{destination}; $tmp .= " ORDER BY LENGTH(prefix) DESC LIMIT 1"; - print STDERR $tmp; + print STDERR $tmp . "\n"; $sql = $self->{_astpp_db}->prepare($tmp); $sql->execute; my $anidata = $sql->fetchrow_hashref; @@ -289,7 +289,7 @@ $arg{xml} .= "<section name=\"dialplan\" description=\"ASTPP Dynamic Routing\">\n"; if ($arg{DID} > 0) { $arg{xml} .= "<context name=\"public\">\n"; - } elsif ($arg{IP} ne "") { + } elsif ($arg{IP} ne "" || $arg{ip} > 0) { $arg{xml} .= "<context name=\"public\">\n"; } else { $arg{xml} .= "<context name=\"default\">\n"; @@ -519,10 +519,12 @@ my $sql = $self->{_freeswitch_db}->prepare($tmp); if ( !$sql->execute ) { print "$tmp failed"; + $sql->finish; return (1,"SIP Device Creation Failed!"); } else { my $directory_id = $sql->{'mysql_insertid'}; + $sql->finish; my $tmp = "INSERT INTO directory_vars (directory_id,var_name,var_value) VALUES (" . $self->{_freeswitch_db}->quote($directory_id) . "," . "'accountcode'," @@ -544,7 +546,6 @@ . $self->{_freeswitch_db}->quote($arg{password}) . ")"; print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); - return (0, "SIP Device Added!" . "Username:" . " " . $sipid . " " . "Password:" . " " . $arg{password}, $sipid); } } @@ -1106,6 +1107,7 @@ . ")"; my $sql = $self->{_astpp_db}->prepare($tmp); $sql->execute; + $sql->finish; return $arg{sort_order}++; } @@ -1181,6 +1183,7 @@ $sql->execute; $arg{sort_order}++; + $sql->finish; } return $arg{sort_order}; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-08 05:07:19
|
Revision: 2286 http://astpp.svn.sourceforge.net/astpp/?rev=2286&view=rev Author: darrenkw Date: 2009-10-08 05:07:10 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Make astpp-admin.cgi "strict" compliant Modified Paths: -------------- trunk/web_interface/astpp-admin.cgi Modified: trunk/web_interface/astpp-admin.cgi =================================================================== --- trunk/web_interface/astpp-admin.cgi 2009-10-06 05:28:39 UTC (rev 2285) +++ trunk/web_interface/astpp-admin.cgi 2009-10-08 05:07:10 UTC (rev 2286) @@ -52,6 +52,7 @@ use DateTime; use DateTime::TimeZone; use ASTPP; +use strict; ; # We use DateTime::TimeZone to show users cdrs in their own timezones. @@ -62,12 +63,13 @@ textdomain("astpp"); use vars qw(@output $astpp_db $params $config $status $config $limit $accountinfo - $freepbx_db $rt_db $openser_db $ASTPP); + $osc_db $freepbx_db $rt_db $fs_db $openser_db $ASTPP); my $starttime = [gettimeofday]; $ASTPP = ASTPP->new; $ASTPP->set_verbosity(4); #Tell ASTPP debugging how verbose we want to be. #$ASTPP->set_asterisk_agi($AGI); $ASTPP->set_pagination_script("astpp-admin.cgi"); +my %types; my @Home = ( gettext("Home Page") ); my @Accounts = ( gettext("Create Account"), gettext("Process Payment"), @@ -157,7 +159,7 @@ my @output = ("STDERR"); # "LOGFILE" ); my @language = all_language_codes; @language = sort @language; -#my @currency; +my @currency; my @deviceprotocol = ("SIP"); my @countries = all_country_names(); @countries = sort @countries; @@ -759,7 +761,7 @@ . gettext("Start date:") . "</td><td><input type=text name=start_year value=\"$start_year\" size=5><select name=start_month>"; - for ( $id = 0 ; $id < 12 ; $id++ ) { + for ( my $id = 0 ; $id < 12 ; $id++ ) { if ( $id == ( $start_month - 1 ) ) { $body .= "<option value=$id selected>$months[$id]"; } @@ -779,7 +781,7 @@ "<tr><td>" . gettext("End date:") . "</td><td><input type=text name=end_year value=\"$end_year\" size=5><select name=end_month>"; - for ( $id = 0 ; $id < 12 ; $id++ ) { + for ( my $id = 0 ; $id < 12 ; $id++ ) { if ( $id == ( $end_month - 1 ) ) { $body .= "<option value=$id selected>$months[$id]"; } @@ -851,7 +853,8 @@ sub build_list_box($$) { my ( $in, $selected ) = @_; my $body = ""; - undef %list; + my %list; +# undef %list; @list{@$in} = (); my @out = sort keys %list; # remove sort if undesired for ( my $i = 0 ; $i < @out ; $i++ ) { @@ -868,7 +871,7 @@ sub build_report($$) { return gettext("Cannot display reports until database is configured") unless $astpp_db; - $cdr_db = &cdr_connect_db( $config, $enh_config, @output ); + $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot display reports until database is configured") unless $cdr_db; @@ -1103,7 +1106,7 @@ $price = $row1->{'price'}; $cost = $row1->{'cost'}; - $notes = "notes = " . $astpp_db->quote( $row1->{notes} ); + my $notes = "notes = " . $astpp_db->quote( $row1->{notes} ); my $sql2 = $astpp_db->prepare( "SELECT COUNT(*) AS completed FROM $table WHERE $notes AND disposition = 'ANSWERED'" @@ -1168,7 +1171,7 @@ my ($body); return gettext("Cannot display reports until database is configured") unless $astpp_db; - $cdr_db = &cdr_connect_db( $config, $enh_config, @output ); + $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot display reports until database is configured") unless $cdr_db; @@ -1179,7 +1182,7 @@ my ($body); return gettext("Cannot display reports until database is configured") unless $astpp_db; - $cdr_db = &cdr_connect_db( $config, $enh_config, @output ); + $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot display reports until database is configured") unless $cdr_db; @@ -1193,7 +1196,7 @@ my ( $body, $id ); return gettext("Cannot display stats until database is configured") unless $astpp_db; - $cdr_db = &cdr_connect_db( $config, $enh_config, @output ); + $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot display stats until database is configured") unless $cdr_db; @@ -1237,6 +1240,7 @@ . gettext("Congestion") . "</td></tr>\n"; + my $count = 0; while ( my $row = $sth->fetchrow_hashref ) { my $freeswitch_trunk; if ( $row->{tech} eq "SIP" ) { @@ -1483,7 +1487,7 @@ $tmp .= " limit $params->{limit} , $results_per_page"; $sql = $cdr_db->prepare($tmp); $sql->execute; - + my $count = 0; while ( my $record = $sql->fetchrow_hashref ) { $count++; if ( $count % 2 == 0 ) { @@ -1517,32 +1521,32 @@ \n"; } $sql->finish; - $filter{'start_month'} = $filter{'start_month'} - 1; + $filter->{'start_month'} = $filter->{'start_month'} - 1; $string = "&start_year=" - . $filter{'start_year'} + . $filter->{'start_year'} . "&start_month=" - . $filter{'start_month'} + . $filter->{'start_month'} . "&start_day=" - . $filter{'start_day'} + . $filter->{'start_day'} . "&start_hour=" - . $filter{'start_hour'} + . $filter->{'start_hour'} . "&start_minute=" - . $filter{'start_minute'} + . $filter->{'start_minute'} . "&start_second=" - . $filter{'start_second'} + . $filter->{'start_second'} . "&end_year=" - . $filter{'end_year'} + . $filter->{'end_year'} . "&end_month=" - . $filter{'end_month'} + . $filter->{'end_month'} . "&end_day=" - . $filter{'end_day'} + . $filter->{'end_day'} . "&end_hour=" - . $filter{'end_hour'} + . $filter->{'end_hour'} . "&end_minute=" - . $filter{'end_minute'} + . $filter->{'end_minute'} . "&end_second=" - . $filter{'end_second'} + . $filter->{'end_second'} . "&trunk=" . $params->{trunk}; for ( my $i = 0 ; $i <= $pagesrequired - 1 ; $i++ ) { @@ -1606,6 +1610,7 @@ &list_accounts_selective( $astpp_db, $params->{username}, "-1" ); my $accounts; my $tot_count = scalar @accountlist; + my $count = 0; foreach (@accountlist) { $count++; $accounts .= "'" . $_ . "',"; @@ -1687,7 +1692,7 @@ my ( $total, $body, $status, $description, $pricelists, $chargeid, $tmp, $number, - $pagesrequired, $results_per_page, $results, $pageno + $pagesrequired, $results_per_page, $results, $pageno, $reseller ); my $template = HTML::Template->new( filename => '/var/lib/astpp/templates/account-info.tpl', @@ -1695,7 +1700,7 @@ ); return gettext("Cannot view account until database is configured") unless $astpp_db; - @pricelists = + my @pricelists = $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); return gettext("Cannot view account until pricelists configured") unless @pricelists; @@ -2229,7 +2234,7 @@ else { $reseller = ""; } - $types{-1} = gettext("All"); + %types->{-1} = gettext("All"); $body = start_form . "<table class=\"default\"><tr class=\"header\"><td colspan=9>" @@ -2514,6 +2519,7 @@ } } if ( $config->{openser} == 1 ) { + my $name = $params->{number}; # TEMPORARY PATCH $status .= &add_sip_user_openser( $openser_db, $config, $name, $params->{accountpassword}, @@ -2527,7 +2533,7 @@ } } if ( $config->{users_dids_freeswitch} == 1 ) { - my $failure; + my ($failure,$name); ($failure, $status, $name) = $ASTPP->fs_add_sip_user( accountcode => $params->{number}, freeswitch_domain => $config->{freeswitch_domain}, @@ -2620,7 +2626,7 @@ accounttype_menu => popup_menu( -name => "accounttype", -values => \%types, - -labels => $types, + -labels => %types, -default => 0 ) ); @@ -3181,7 +3187,7 @@ } sub build_update_card_status() { - my ( @pricelists, $status, $body, $count, $sql ); + my (@brands,$brandsql, @pricelists, $status, $body, $count, $sql ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { @brands = &list_cc_brands_reseller( $astpp_db, $params->{username} ); @@ -3264,7 +3270,7 @@ } sub build_reset_card_inuse() { - my ( @pricelists, $status, $body, $count ); + my ( @brands,$brandsql,@pricelists, $status, $body, $count ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; if ( $params->{action} eq gettext("Reset") ) { my $brandssql; @@ -3317,7 +3323,7 @@ sub update_balance() { my ( $cardinfo, $charge ) = @_; - my (@brands); + my (@brands,$brandsql); if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { @brands = &list_cc_brands_reseller( $astpp_db, $params->{username} ); } @@ -3393,7 +3399,7 @@ } sub build_delete_cards() { - my ( @pricelists, $status, $body, $count ); + my ( @brands,$brandsql,@pricelists, $status, $body, $count ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; if ( $params->{action} eq gettext("Delete") ) { if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { @@ -3448,7 +3454,7 @@ } sub build_list_cards() { - my ( @pricelists, $status, $body, $number, $inuse, $cardstat, $cardinfo, + my ($where,@brands,$brandsql, @pricelists, $status, $body, $number, $inuse, $cardstat, $cardinfo, $count, $sql, $pageno, $results, $results_per_page, $pagesrequired ); if ( $params->{logintype} == 1 || $params->{logintype} == 5 ) { @brands = &list_cc_brands_reseller( $astpp_db, $params->{username} ); @@ -3524,7 +3530,7 @@ "SELECT COUNT(*) FROM callingcards WHERE status < 2 and brand " . $brandsql ); $sql->execute; - $record = $sql->fetchrow_hashref; + my $record = $sql->fetchrow_hashref; $total_entries = $record->{"COUNT(*)"}; $sql->finish; $te_match = Digest::MD5::md5_hex("unique_cypher-$total_entries-$where"); @@ -3634,7 +3640,7 @@ } sub build_view_card() { - my ( @pricelists, $status, $body, $count, $inuse, $cardstat, $value, + my ( @brands, $brandsql, @pricelists, $status, $body, $count, $inuse, $cardstat, $value, $used ); my $no = gettext("NO"); my $yes = gettext("YES"); @@ -3941,7 +3947,7 @@ $pattern =~ m/\)(\d+)\./; my $pat = $1; $mpls = $npls; - if ( $config->{debug} ) { &pt("enter $pat"); } + if ( $config->{debug} ) { &pt($t0, "enter $pat"); } my $highest = 0; my $lowest = -1; @@ -4029,35 +4035,34 @@ $td = tv_interval($t0); print "\n$td\twhee ... got total $counter\n"; $sdp->finish(); - &mktb( $ztable, + &mktb($t0, $ztable, "select * from $ltable where offer is not null order by pattern" ); - &mktb( $otable, "select pattern,comment,offer from $ztable" ); + &mktb($t0, $otable, "select pattern,comment,offer from $ztable" ); return $body; } sub mktb { - my $table = shift @_; - my $select = shift @_; - my $tt1 = $dbh->prepare("DROP TABLE IF EXISTS `$table`"); + my ($t0, $table, $select) = @_; + my $tt1 = $astpp_db->prepare("DROP TABLE IF EXISTS `$table`"); $tt1->execute(); - $tt1 = $dbh->prepare("create table $table $select"); + $tt1 = $astpp_db->prepare("create table $table $select"); $tt1->execute(); - $tt1 = $dbh->prepare("alter table $table ADD PRIMARY KEY ( `pattern` )"); + $tt1 = $astpp_db->prepare("alter table $table ADD PRIMARY KEY ( `pattern` )"); $tt1->execute(); - $td = tv_interval($t0); + my $td = tv_interval($t0); print "$td\tmade table $table\n"; } sub pt { - my $p = shift; - $td = tv_interval($t0); + my ($t0,$p); + my $td = tv_interval($t0); print "$p\t$td\n"; } ### End of Code from convergence.com.pk sub build_list_errors() { - my ( $results, $body, $status, $count, $pageno, $pagesrequired ); + my ( @cdrlist, $results, $body, $status, $count, $pageno, $pagesrequired ); $cdr_db = &cdr_connect_db( $config, @output ); return gettext("Cannot list errors until database is configured!") . "\n" unless $cdr_db; @@ -4179,7 +4184,7 @@ foreach my $record (@sip_peers) { $status .= "<br>" . $record; - @info = split( " ", $record ); + my @info = split( " ", $record ); if ( $info[0] !~ "^--END" && $info[0] !~ "^Name.*" @@ -4241,7 +4246,7 @@ "; foreach my $record (@sip_users) { $status .= "<br>" . $record; - @info = split( " ", $record ); + my @info = split( " ", $record ); if ( $info[0] !~ "^--END.*" && $info[0] !~ "^Username.*" && $info[0] !~ "^Response.*" @@ -4299,7 +4304,7 @@ foreach my $record (@iax2_peers) { $status .= "<br>" . $record; - @info = split( " ", $record ); + my @info = split( " ", $record ); if ( $info[0] !~ "^--END" && $info[0] !~ "^Name.*" && $info[0] !~ "^Response.*" @@ -4350,7 +4355,7 @@ "; foreach my $record (@iax2_users) { $status .= "<br>" . $record; - @info = split( " ", $record ); + my @info = split( " ", $record ); if ( $info[0] !~ "^--END" && $info[0] !~ "^Username.*" && $info[0] !~ "^Response.*" @@ -4397,7 +4402,7 @@ "; foreach my $record (@show_channels) { - @info = split( " ", $record ); + my @info = split( " ", $record ); if ( $info[0] !~ "^--END" && $info[0] !~ "^Channel.*" && $info[0] !~ "^Privilege.*" @@ -5161,7 +5166,7 @@ my $csv = Text::CSV->new(); my $prepend = "^"; my $append = ".*"; - $uploaded = upload('rateimport'); + my $uploaded = upload('rateimport'); my ( @data, $record ); while ( my $record = <$uploaded> ) { $ASTPP->debug( user => $param->{username}, debug => $record ); @@ -5170,7 +5175,7 @@ } foreach my $temp (@data) { if ( $csv->parse($temp) ) { - @columns = $csv->fields(); + my @columns = $csv->fields(); my $pattern = $prepend . $columns[0] . $columns[2] . $columns[3] . $append; if ( @@ -5310,8 +5315,8 @@ } foreach my $temp (@data) { if ( $csv->parse($temp) ) { - my $tmp; - @columns = $csv->fields(); + my ($tmp,$valid); + my @columns = $csv->fields(); my $pattern = $prepend . $columns[0] . $columns[1] . $columns[2] . $append; $status .= @@ -5331,7 +5336,8 @@ . $astpp_db->quote( $resellerdata->{pricelist} ) . " LIMIT 1"; $ASTPP->debug( user => $param->{username}, debug => $tmp ); - $sql = $astpp_db->prepare($tmp); + my $sql = $astpp_db->prepare($tmp); + my ($routeinfo,$row); $sql->execute; while ( $row = $sql->fetchrow_hashref ) { $routeinfo = $row; @@ -5476,7 +5482,7 @@ unless $astpp_db; if ( $params->{action} eq gettext("Import...") ) { my $csv = Text::CSV->new(); - $uploaded = upload('didimport'); + my $uploaded = upload('didimport'); my ( @data, $record ); while ( my $record = <$uploaded> ) { chomp; @@ -5484,7 +5490,7 @@ } foreach my $temp (@data) { if ( $csv->parse($temp) ) { - @columns = $csv->fields(); + my @columns = $csv->fields(); if ( $astpp_db->do( "DELETE FROM dids WHERE number = " @@ -5643,7 +5649,7 @@ } sub build_remove_account() { - my ( $body, $tmp, $sql, $status, $number, @accountlist, @pricelists, + my ( $reseller, $body, $tmp, $sql, $status, $number, @accountlist, @pricelists, $accountinfo ); my $template = HTML::Template->new( filename => '/var/lib/astpp/templates/account-remove.tpl', @@ -7272,6 +7278,7 @@ $params->{action} = gettext("Information..."); } elsif ( $params->{action} eq gettext("Add...") ) { + my ($didinfo); my $resellerinfo = &get_account( $astpp_db, $params->{username} ); if ( $resellerinfo->{reseller} ) { $didinfo = @@ -7620,7 +7627,7 @@ } sub build_routes() { - my ( @pricelists, $sql, $count, $tmp ); + my ( $pageno, @pricelists, $sql, $count, $tmp ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; @pricelists = $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); @@ -7647,7 +7654,7 @@ $ASTPP->debug( user => $param->{username}, debug => $tmp ); $sql = $astpp_db->prepare($tmp); $sql->execute; - $record = $sql->fetchrow_hashref; + my $record = $sql->fetchrow_hashref; $sql->finish; $body = start_form @@ -7748,8 +7755,9 @@ . $astpp_db->quote( $resellerdata->{pricelist} ) . " LIMIT 1"; $ASTPP->debug( user => $param->{username}, debug => $tmp ); - $sql = $astpp_db->prepare($tmp); + my $sql = $astpp_db->prepare($tmp); $sql->execute; + my ($row, $routeinfo); while ( $row = $sql->fetchrow_hashref ) { $routeinfo = $row; } @@ -7806,7 +7814,7 @@ if ( $pricelist->{reseller} ne $params->{username} ) { $params->{pricelist} = $params->{username}; } - $reseller = $params->{username}; + my $reseller = $params->{username}; my $resellerdata = &get_account( $astpp_db, $reseller ); my $tmp = "SELECT * FROM routes WHERE pattern = " @@ -7815,8 +7823,9 @@ . $astpp_db->quote( $resellerdata->{pricelist} ) . " LIMIT 1"; $ASTPP->debug( user => $param->{username}, debug => $tmp ); - $sql = $astpp_db->prepare($tmp); + my $sql = $astpp_db->prepare($tmp); $sql->execute; + my ($routeinfo, $row); while ( $row = $sql->fetchrow_hashref ) { $routeinfo = $row; } @@ -8171,7 +8180,7 @@ } sub build_packages() { - my ( $pagination, $sql, $record, $count, $tmp, $pageno, $pagesrequired ); + my ( $sql_select, $sql_count, $pagination, $sql, $record, $count, $tmp, $pageno, $pagesrequired ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; my $template = HTML::Template->new( filename => '/var/lib/astpp/templates/packages-list.tpl', @@ -8180,7 +8189,7 @@ if ( $params->{limit} < 1 ) { $params->{limit} = 0 } my $results_per_page = $config->{results_per_page}; if ( $results_per_page eq "" ) { $results_per_page = 25; } - @pricelists = + my @pricelists = $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); $template->param( pricelists => popup_menu( @@ -8303,6 +8312,7 @@ ); my $results = $astpp_db->prepare($sql); $results->execute; + my @package_list; while ( my $packageinfo = $results->fetchrow_hashref ) { $ASTPP->debug( user => $param->{username}, @@ -9120,6 +9130,7 @@ $params->{action} = gettext("Information..."); } elsif ( $params->{action} eq gettext("Save...") ) { + my @resellers = &list_resellers($astpp_db); my $resellerlist; foreach my $reseller (@resellers) { my $resellerparam = "reseller-" . $reseller; @@ -9469,12 +9480,12 @@ sub build_calc_charge() { my ( $status, $body, $cost, $length, $increment ); - $template = HTML::Template->new( + my $template = HTML::Template->new( filename => '/var/lib/astpp/templates/calc-charge.tpl', die_on_bad_params => $config->{template_die_on_bad_params} ); return gettext("Database is NOT configured!") . "\n" unless $astpp_db; - @pricelists = + my @pricelists = $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); $template->param( pricelists => popup_menu( @@ -9710,6 +9721,7 @@ $ASTPP->debug( user => $param->{username}, debug => "Adding User"); $params->{domain} = $config->{freeswitch_domain} if !$params->{domain}; $params->{context} = $config->{freeswitch_context} if !$params->{context}; + my ($failure,$name); ($failure, $status, $name) = $ASTPP->fs_add_sip_user( username => $params->{fs_username}, accountcode => $params->{accountcode}, @@ -11036,13 +11048,13 @@ $status .= gettext("CallShop Exists Already!"); } } - $sweep_menu = popup_menu( -name => "sweep", -values => \%sweeplist ); - $language_menu = popup_menu( + my $sweep_menu = popup_menu( -name => "sweep", -values => \%sweeplist ); + my $language_menu = popup_menu( -name => "language", -values => \@language, -default => $config->{default_language} ); - $currency_menu = popup_menu( + my $currency_menu = popup_menu( -name => "currency", -values => \@currency ); @@ -11097,7 +11109,7 @@ . gettext("removed successfully!") . "<br>"; } } - $callshop_list = popup_menu( + my $callshop_list = popup_menu( -name => "callshop_list", -values => \@callshops ); @@ -11122,9 +11134,10 @@ -values => \@language, -default => $config->{default_language} ); - @pricelists = + my @pricelists = $ASTPP->list_pricelists( reseller => $params->{logged_in_reseller} ); - $pricelists = popup_menu( + + my $pricelists = popup_menu( -name => "pricelist", -values => \@pricelists ); @@ -11172,6 +11185,7 @@ $status .= "<br>"; } if ( $config->{openser} == 1 ) { + my $name = $params->{number}; # TEMPORARY PATCH $status .= &add_sip_user_openser( $openser_db, $config, $name, $params->{accountpassword}, @@ -11228,12 +11242,12 @@ else { my $reseller_info = &get_account( $astpp_db, $params->{username} ); - $tmp = + my $tmp = "SELECT countries_id FROM countries WHERE countries_name LIKE " . $osc_db->quote( $reseller_info->{country} ); my $sql = $osc_db->prepare($tmp); $sql->execute; - $record = $sql->fetchrow_hashref; + my $record = $sql->fetchrow_hashref; $tmp = "INSERT INTO customers (customers_gender,customers_firstname,customers_lastname," . "customers_email_address," @@ -11391,7 +11405,7 @@ } sub build_list_booths() { - my (@booth_list); + my (@booth_list, $booth_status); my @booths = (); @booth_list = &list_booths_callshop( $astpp_db, $params->{username}, $config ); @@ -11411,7 +11425,7 @@ &hangup_call( $astpp_db, $config, $params->{channel} ); } foreach my $name (@booth_list) { - my ( %row, $balance, $tmp, $sql ); + my ( $sip_login, $iax2_login, %row, $balance, $tmp, $sql ); my $boothinfo = &get_account_including_closed( $astpp_db, $name ); $balance = $ASTPP->accountbalance( account => $name ); $tmp = @@ -11420,7 +11434,7 @@ . " AND status = 0"; $sql = $astpp_db->prepare($tmp); $sql->execute; - $record = $sql->fetchrow_hashref; + my $record = $sql->fetchrow_hashref; $row{name} = $name; $row{balance} = sprintf( "%.2f", $balance / 10000 ); $row{call_count} = $record->{"COUNT(*)"}; @@ -11539,10 +11553,10 @@ push( @booths, \%row ); $sql->finish; $ASTPP->debug( user => $param->{username}, debug => $tmp ); - $ASTPP->debug( - user => $param->{username}, - debug => $record->{"COUNT(*)"} - ); +# $ASTPP->debug( +# user => $param->{username}, +# debug => $record->{"COUNT(*)"} +# ); $ASTPP->debug( user => $param->{username}, debug => $balance / 10000 ); } @@ -11558,7 +11572,7 @@ my ( $sql, @cdrs, $sip_login, $iax2_login ); # Prepare the booth list for the menu. - @booth_list = + my @booth_list = &list_booths_callshop( $astpp_db, $params->{username}, $config ); my $booths = popup_menu( -name => "booth_list", @@ -11661,7 +11675,7 @@ $config->{cdr_table}, \@chargelist ); # Bill as many calls as we can. $status .= gettext("We rated as many CDRS as we could") . "<br>"; - $tmp = + my $tmp = "SELECT uniqueid,callstart,callerid,callednum,disposition,billseconds,debit,credit,notes,cost FROM cdrs WHERE cardnum = " . $astpp_db->quote( $params->{booth_name} ) . "and status = 0" @@ -11907,7 +11921,7 @@ if $config->{users_dids_amp} == 1; $rt_db = &rt_connect_db( $config, @output ) if $config->{users_dids_rt} == 1; - $osc_db = &osc_connect_db( $config, $config, @output ) + my $osc_db = &osc_connect_db( $config, $config, @output ) if $config->{externalbill} eq "oscommerce"; $ASTPP->debug( user => $param->{username}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 05:28:47
|
Revision: 2285 http://astpp.svn.sourceforge.net/astpp/?rev=2285&view=rev Author: darrenkw Date: 2009-10-06 05:28:39 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Remove links to obsoleted files. Modified Paths: -------------- trunk/Makefile Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2009-10-06 05:02:59 UTC (rev 2284) +++ trunk/Makefile 2009-10-06 05:28:39 UTC (rev 2285) @@ -64,9 +64,7 @@ @echo "--------------------"; install_samples: - install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.reseller-config.conf $(DESTDIR)$(ASTPPDIR)/sample.reseller-config.conf install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-config.conf $(DESTDIR)$(ASTPPDIR)/astpp-config.conf - install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-enh-config.conf $(DESTDIR)$(ASTPPDIR)/astpp-enh-config.conf install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-dialplan.conf $(DESTDIR)$(ASTERISKDIR)/astpp-dialplan.conf install_php: @@ -124,7 +122,7 @@ perl -MCPAN -e "install Locale::Language"; perl -MCPAN -e "install DBI"; perl -MCPAN -e "install DBD::mysql"; - perl -MCPAN -e "install DBD::Pg"; +# perl -MCPAN -e "install DBD::Pg"; perl -MCPAN -e "install CGI"; perl -MCPAN -e "install Asterisk::AGI"; perl -MCPAN -e "install LWP::Simple"; @@ -140,9 +138,10 @@ perl -MCPAN -e "install HTML::Template::Expr"; perl -MCPAN -e "install DateTime::TimeZone"; perl -MCPAN -e "install DateTime"; -# perl -MCPAN -e "install POSIX"; -# perl -MCPAN -e "install Data::Dumper"; + cd modules/ASTPP && perl Makefile.PL && make && make install && cd ../../ + + install_instructions_print: @echo "------------------------------"; @echo "ASTPP install appears to be successfull."; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 05:03:08
|
Revision: 2284 http://astpp.svn.sourceforge.net/astpp/?rev=2284&view=rev Author: darrenkw Date: 2009-10-06 05:02:59 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Add sample code to call callingcard application. Added Paths: ----------- trunk/freeswitch/conf/02_astpp_callingcards.xml Added: trunk/freeswitch/conf/02_astpp_callingcards.xml =================================================================== --- trunk/freeswitch/conf/02_astpp_callingcards.xml (rev 0) +++ trunk/freeswitch/conf/02_astpp_callingcards.xml 2009-10-06 05:02:59 UTC (rev 2284) @@ -0,0 +1,8 @@ +<include> + <extension name="astpp_callingcards"> + <condition field="destination_number" expression="^9912345$"> + <action application="answer"/> + <action application="perl" data="astpp-callingcards.pl" /> + </condition> + </extension> +</include> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 05:01:14
|
Revision: 2283 http://astpp.svn.sourceforge.net/astpp/?rev=2283&view=rev Author: darrenkw Date: 2009-10-06 05:01:08 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Add/update freeswitch sample files. Modified Paths: -------------- trunk/freeswitch/conf/xml_curl.conf.xml Added Paths: ----------- trunk/freeswitch/conf/cdr_csv.conf.xml trunk/freeswitch/conf/xml_cdr.conf.xml Added: trunk/freeswitch/conf/cdr_csv.conf.xml =================================================================== --- trunk/freeswitch/conf/cdr_csv.conf.xml (rev 0) +++ trunk/freeswitch/conf/cdr_csv.conf.xml 2009-10-06 05:01:08 UTC (rev 2283) @@ -0,0 +1,17 @@ +<configuration name="cdr_csv.conf" description="CDR CSV Format"> + <settings> + <!-- 'cdr-csv' will always be appended to log-base --> + <!--<param name="log-base" value="/var/log"/>--> + <param name="default-template" value="astpp"/> + <!-- This is like the info app but after the call is hung up --> + <!--<param name="debug" value="true"/>--> + <param name="rotate-on-hup" value="true"/> + <!-- may be a b or ab --> + <param name="legs" value="ab"/> + </settings> + <templates> + <template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}", "${accountcode}","${read_codec}","${write_codec}"</template> + <template name="astpp">"${accountcode}","${caller_id_number}","${destination_number}","${context}","${caller_id}","${channel_name}","${bridge_channel}","${last_app}","${last_arg}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${amaflags}","${uuid}","uf=${userfield},pt=${progress_time},pmt=${progress_media_time}","${read_codec}","${write_codec}","none","none"</template> + </templates> +</configuration> + Added: trunk/freeswitch/conf/xml_cdr.conf.xml =================================================================== --- trunk/freeswitch/conf/xml_cdr.conf.xml (rev 0) +++ trunk/freeswitch/conf/xml_cdr.conf.xml 2009-10-06 05:01:08 UTC (rev 2283) @@ -0,0 +1,67 @@ +<configuration name="xml_cdr.conf" description="XML CDR CURL logger"> + <settings> + <!-- the url to post to if blank web posting is disabled --> + + <param name="url" value="http://localhost/cgi-bin/astpp-fs-xml.cgi"/> +<!-- <param name="url" value="http://localhost/perl/astpp-fs-xml.pl"/> --> + + <!-- optional: credentials to send to web server --> + <!-- <param name="cred" value="user:pass"/> --> + + <!-- the total number of retries (not counting the first 'try') to post to webserver incase of failure --> + <param name="retries" value="2"/> + + <!-- delay between retries in seconds, default is 5 seconds --> + <!-- <param name="delay" value="1"/> --> + + <!-- optional: if not present we do not log every record to disk --> + <!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank value will default to ${prefix}/logs/xml_cdr --> + <param name="log-dir" value=""/> + + <!-- optional: if not present we do log the b leg --> + <!-- true or false if we should create a cdr for the b leg of a call--> + <param name="log-b-leg" value="true"/> + + <!-- optional: if not present, all filenames are the uuid of the call --> + <!-- true or false if a leg files are prefixed "a_" --> + <param name="prefix-a-leg" value="true"/> + + <!-- encode the post data may be 'true' for url encoding, 'false' for no encoding or 'base64' for base64 encoding --> + <param name="encode" value="true"/> + + <!-- optional: set to true to disable Expect: 100-continue lighttpd requires this setting --> + <!--<param name="disable-100-continue" value="true"/>--> + + <!-- optional: full path to the error log dir for failed web posts if not specified its the same as log-dir --> + <!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank or omitted value will default to ${prefix}/logs/xml_cdr --> + <!-- <param name="err-log-dir" value="/tmp"/> --> + + <!-- optional: this will enable the CA root certificate check by libcurl to + verify that the certificate was issued by a major Certificate Authority. + note: default value is disabled. only enable if you want this! --> + <!--<param name="enable-cacert-check" value="true"/>--> + <!-- optional: verify that the server is actually the one listed in the cert --> + <!-- <param name="enable-ssl-verifyhost" value="true"/> --> + + <!-- optional: these options can be used to specify custom SSL certificates + to use for HTTPS communications. Either use both options or neither. + Specify your public key with 'ssl-cert-path' and the private key with + 'ssl-key-path'. If your private key has a password, specify it with + 'ssl-key-password'. --> + <!-- <param name="ssl-cert-path" value="$${base_dir}/conf/certs/public_key.pem"/> --> + <!-- <param name="ssl-key-path" value="$${base_dir}/conf/certs/private_key.pem"/> --> + <!-- <param name="ssl-key-password" value="MyPrivateKeyPassword"/> --> + + <!-- optional: use a custom CA certificate in PEM format to verify the peer + with. This is useful if you are acting as your own certificate authority. + note: only makes sense if used in combination with "enable-cacert-check." --> + <!-- <param name="ssl-cacert-file" value="$${base_dir}/conf/certs/cacert.pem"/> --> + + <!-- optional: specify the SSL version to force HTTPS to use. Valid options are + "SSLv3" and "TLSv1". Otherwise libcurl will auto-negotiate the version. --> + <!-- <param name="ssl-version" value="TLSv1"/> --> + + <!-- optional: enables cookies and stores them in the specified file. --> + <!-- <param name="cookie-file" value="/tmp/cookie-mod_xml_curl.txt"/> --> + </settings> +</configuration> Modified: trunk/freeswitch/conf/xml_curl.conf.xml =================================================================== --- trunk/freeswitch/conf/xml_curl.conf.xml 2009-10-06 03:56:05 UTC (rev 2282) +++ trunk/freeswitch/conf/xml_curl.conf.xml 2009-10-06 05:01:08 UTC (rev 2283) @@ -6,7 +6,9 @@ need it) --> <!-- one or more |-delim of configuration|directory|dialplan --> - <param name="gateway-url" value="http://localhost/cgi-bin/astpp-fs-xml.pl" bindings="dialplan"/> + <param name="gateway-url" value="http://localhost/cgi-bin/astpp-fs-xml.cgi" bindings="dialplan|directory"/> +<!-- <param name="gateway-url" value="http://localhost/perl/astpp-fs-xml.pl" bindings="dialplan|directory"/> --> + <!-- set this to provide authentication credentials to the server --> <!--<param name="gateway-credentials" value="muser:mypass"/>--> <!-- set to true to disable Expect: 100-continue lighttpd requires this setting --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:56:11
|
Revision: 2282 http://astpp.svn.sourceforge.net/astpp/?rev=2282&view=rev Author: darrenkw Date: 2009-10-06 03:56:05 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Start adding support to be able to link the A and B legs of calls in Freeswitch. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl Added Paths: ----------- trunk/sql/cdrdb-2009-10-05.sql Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2009-10-06 03:54:35 UTC (rev 2281) +++ trunk/freeswitch/astpp-fs-xml.pl 2009-10-06 03:56:05 UTC (rev 2282) @@ -322,7 +322,7 @@ 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," + . "lastdata,calldate,answerdate,enddate,duration,billsec,disposition,amaflags,uniqueid,originator,userfield,read_codec," . "write_codec,cost,vendor,provider,trunk,outbound_route,progressmsec,answermsec,progress_mediamsec) VALUES (" . "'" . $data->{variables}->{accountcode} @@ -388,6 +388,10 @@ . $data->{callflow}->{caller_profile}->{uuid} . "'" . "," + . "'" + . $data->{variables}->{originator} + . "'" + . "," . "''" . "," . "'" . $data->{variables}->{read_code} . "'" Added: trunk/sql/cdrdb-2009-10-05.sql =================================================================== --- trunk/sql/cdrdb-2009-10-05.sql (rev 0) +++ trunk/sql/cdrdb-2009-10-05.sql 2009-10-06 03:56:05 UTC (rev 2282) @@ -0,0 +1,70 @@ +-- +-- Table structure for table `cdr` +-- + +DROP TABLE IF EXISTS `cdr`; +CREATE TABLE `cdr` ( + `calldate` datetime NOT NULL default '0000-00-00 00:00:00', + `clid` varchar(80) NOT NULL default '', + `src` varchar(80) NOT NULL default '', + `dst` varchar(80) NOT NULL default '', + `dcontext` varchar(80) NOT NULL default '', + `channel` varchar(80) NOT NULL default '', + `dstchannel` varchar(80) NOT NULL default '', + `lastapp` varchar(80) NOT NULL default '', + `lastdata` varchar(80) NOT NULL default '', + `duration` int(11) NOT NULL default '0', + `billsec` int(11) NOT NULL default '0', + `disposition` varchar(45) NOT NULL default '', + `amaflags` int(11) NOT NULL default '0', + `accountcode` varchar(20) NOT NULL default '', + `uniqueid` varchar(32) NOT NULL default '', + `userfield` varchar(255) NOT NULL default '', + `cost` varchar(20) NOT NULL default 'none', + `vendor` varchar(20) NOT NULL default 'none', + KEY `calldate` (`calldate`), + KEY `dst` (`dst`), + KEY `accountcode` (`accountcode`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +-- +-- Table structure for table `fscdr` +-- + +DROP TABLE IF EXISTS `fscdr`; +CREATE TABLE IF NOT EXISTS `fscdr` ( + `accountcode` varchar(20) NOT NULL default '', + `src` varchar(80) NOT NULL default '', + `dst` varchar(80) NOT NULL default '', + `dcontext` varchar(80) NOT NULL default '', + `clid` varchar(80) NOT NULL default '', + `channel` varchar(80) NOT NULL default '', + `dstchannel` varchar(80) NOT NULL default '', + `lastapp` varchar(80) NOT NULL default '', + `lastdata` varchar(80) NOT NULL default '', + `calldate` datetime NOT NULL default '0000-00-00 00:00:00', + `answerdate` datetime NOT NULL default '0000-00-00 00:00:00', + `enddate` datetime NOT NULL default '0000-00-00 00:00:00', + `duration` int(11) NOT NULL default '0', + `billsec` int(11) NOT NULL default '0', + `disposition` varchar(45) NOT NULL default '', + `amaflags` int(11) NOT NULL default '0', + `uniqueid` varchar(60) NOT NULL, + `originator` varchar(60), + `userfield` varchar(255) NOT NULL default '', + `read_codec` varchar(60) NOT NULL default '', + `write_codec` varchar(60) NOT NULL default '', + `cost` varchar(20) NOT NULL default 'none', + `vendor` varchar(20) NOT NULL default 'none', + `provider` varchar(60) NOT NULL, + `trunk` varchar(60) NOT NULL, + `outbound_route` varchar(60) NOT NULL, + `progressmsec` varchar(20) NOT NULL, + `answermsec` varchar(20) NOT NULL, + `progress_mediamsec` varchar(20) NOT NULL, + KEY `calldate` (`calldate`), + KEY `dst` (`dst`), + KEY `accountcode` (`accountcode`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:54:43
|
Revision: 2281 http://astpp.svn.sourceforge.net/astpp/?rev=2281&view=rev Author: darrenkw Date: 2009-10-06 03:54:35 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Clean up the account balance calculations. Modified Paths: -------------- trunk/scripts/astpp-common.pl Modified: trunk/scripts/astpp-common.pl =================================================================== --- trunk/scripts/astpp-common.pl 2009-10-06 03:43:17 UTC (rev 2280) +++ trunk/scripts/astpp-common.pl 2009-10-06 03:54:35 UTC (rev 2281) @@ -1777,7 +1777,7 @@ . $astpp_db->quote($destination) . " RLIKE pattern AND pricelist = " . $astpp_db->quote($pricelist) - . " ORDER BY LENGTH(pattern) DESC"; + . " ORDER BY LENGTH(pattern) DESC LIMIT 1"; print STDERR "$tmp\n" if $config->{debug} == 1; $sql = $astpp_db->prepare($tmp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:43:25
|
Revision: 2280 http://astpp.svn.sourceforge.net/astpp/?rev=2280&view=rev Author: darrenkw Date: 2009-10-06 03:43:17 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Removed links to deprecated files. Modified Paths: -------------- trunk/Makefile Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2009-10-06 03:42:26 UTC (rev 2279) +++ trunk/Makefile 2009-10-06 03:43:17 UTC (rev 2280) @@ -51,9 +51,7 @@ install -m 644 -o $(OWNER) -g $(GROUP) web_interface/menu.js $(DESTDIR)$(WWWDIR)/html/_astpp/ # Install Sample Configuration Files -# install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.reseller-config.conf $(DESTDIR)$(ASTPPDIR)/sample.reseller-config.conf install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-config.conf $(DESTDIR)$(ASTPPDIR)/sample.astpp-config.conf -# install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-enh-config.conf $(DESTDIR)$(ASTPPDIR)/sample.astpp-enh-config.conf install_asterisk_config: install -m 644 -o $(OWNER) -g $(GROUP) ./samples/sample.astpp-dialplan.conf $(DESTDIR)$(ASTERISKDIR)/sample.astpp-dialplan.conf This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:42:35
|
Revision: 2279 http://astpp.svn.sourceforge.net/astpp/?rev=2279&view=rev Author: darrenkw Date: 2009-10-06 03:42:26 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Removed old sample files. Removed Paths: ------------- trunk/samples/sample.astpp-enh-config.conf trunk/samples/sample.reseller-config.conf Deleted: trunk/samples/sample.reseller-config.conf =================================================================== --- trunk/samples/sample.reseller-config.conf 2009-10-06 03:41:14 UTC (rev 2278) +++ trunk/samples/sample.reseller-config.conf 2009-10-06 03:42:26 UTC (rev 2279) @@ -1,118 +0,0 @@ -# This file contains the more advanced ASTPP variables which should remain -# mostly constant between installs and which you do not want to change too easily. -# Changing this variables without knowing exactly what you are doing could have -# far ranging consequences. -# The Author - -results_per_page = 30 # How many results per page do we should in the web interface? -astpp_dir = /var/lib/astpp # Where do the astpp configs live? - -# This is the override authorization code and will allow access to the system. Should -# be set to something "impossible" to guess. DO NOT LEAVE AT THE DEFAULT!!! -auth = a23asudf9810-zalkj32423 - -# Database type: ASTPP was designed for a MySQL database initially. Valid options are: -# MySQL. Pgsql is coming but is not ready yet. -astpp_dbengine = MySQL -rt_dbengine = MySQL -cdr_dbengine = MySQL -osc_dbengine = MySQL -agile_dbengine = MySQL -freepbx_dbengine = MySQL - -# Please specify the external billing application to use. If you are not using any -# the leave it blank. Valid options are "agile" and "oscommerce". -externalbill = oscommerce - -# Do you wish to enable calling cards? 1 for yes and 2 for no. -callingcards = 1 - -# Change this one at your own peril. If you switch it off, calls will not be marked -# as billed in asterisk once they are billed. -astcdr = 1 - -# Change this one at your own peril. If you switch it off, calls will not be written -# to astpp when they are calculated. -posttoastpp = 1 - -# This is used when calling astpp-rate-engine.pl from the extensions.conf file. -# I would recommend 10 seconds as that gives that time to Asterisk to get the call written -# to the cdr database. -sleep = 10 - -# If this is enabled, ASTPP will create users and DIDs in the FreePBX (www.freepbx.org) -# mysql DB. -users_dids_amp = 0 - -# If this is enabled, ASTPP will create users and DIDs in the Asterisk Realtime -# mysql DB. -users_dids_rt = 1 - -# Service prepend is the number that ASTPP attaches to the front of the id that it is passed -# in astpp-auto-admin.cgi -# If service_prepend is left blank, then the new method kicks in. The new method allows you -# to specify a required extension length and default filler. It then chops the strings up. -service_prepend = 778 -service_length = 7 -service_filler = 4110000 - -# AgileBill(Trademark of AgileCo) Settings: -agile_host = 127.0.0.1 -agile_db = agile -agile_user = root -agile_pass = -agile_site_id = 1 -agile_charge_status = 0 -agile_taxable = 1 -agile_dbprefix = _ -agile_service_prepend = 778 - -# OSCommerce Settings (www.oscommerce.org) -osc_host = 127.0.0.1 -osc_db = oscommerce -osc_user = root -osc_pass = password -osc_product_id = 99999999 -osc_payment_method = "Charge" -osc_order_status = 1 - -# FreePBX Settings (www.freepbx.org) -freepbx_host = 127.0.0.1 -freepbx_db = asterisk -freepbx_user = root -freepbx_pass = passw0rd -freepbx_iax_table = iax -freepbx_sip_table = sip -freepbx_extensions_table = extensions -freepbx_codec_allow = g729,ulaw,alaw -freepbx_codec_disallow = all -freepbx_mailbox_group = default -freepbx_sip_nat = yes -freepbx_sip_canreinvite = no -freepbx_sip_dtmfmode = rfc2833 -freepbx_sip_qualify = yes -freepbx_sip_type = friend -freepbx_sip_callgroup = -freepbx_sip_pickupgroup = -freepbx_iax_notransfer = yes -freepbx_iax_type = friend -freepbx_iax_qualify = yes - -# Asterisk -realtime Settings -rt_host = 127.0.0.1 -rt_db = realtime -rt_user = root -rt_pass = -rt_iax_table = iax -rt_sip_table = sip -rt_extensions_table = extensions -rt_sip_insecure = very -rt_sip_nat = yes -rt_sip_canreinvite = no -rt_codec_allow = g729,ulaw,alaw -rt_codec_disallow = all -rt_mailbox_group = default -rt_sip_qualify = yes -rt_sip_type = friend -rt_iax_qualify = yes -rt_voicemail_table = voicemail_users This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:41:22
|
Revision: 2278 http://astpp.svn.sourceforge.net/astpp/?rev=2278&view=rev Author: darrenkw Date: 2009-10-06 03:41:14 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Moved to the new balance calculating code found in the perl module. Modified Paths: -------------- trunk/web_interface/astpp-admin.cgi Modified: trunk/web_interface/astpp-admin.cgi =================================================================== --- trunk/web_interface/astpp-admin.cgi 2009-10-06 03:40:09 UTC (rev 2277) +++ trunk/web_interface/astpp-admin.cgi 2009-10-06 03:41:14 UTC (rev 2278) @@ -1644,8 +1644,7 @@ &accounts_total_balance( $astpp_db, $params->{username} ) / 10000 ); $template->param( - total_due => &accountbalance( $astpp_db, $params->{username} ) / - 10000 ); + total_due => $ASTPP->accountbalance( account => $params->{username} ) / 10000 ); $template->param( calling_cards_in_use => &count_callingcards( $astpp_db, @@ -1934,9 +1933,8 @@ $accountinfo = &get_account( $astpp_db, $params->{numberlist} ); } if ( $accountinfo->{number} ) { + $accountinfo->{balance} = $ASTPP->accountbalance( account => $accountinfo->{number} ); $accountinfo->{balance} = - &accountbalance( $astpp_db, $accountinfo->{number} ); - $accountinfo->{balance} = sprintf( "%.2f", $accountinfo->{balance} / 10000 ); $template->param( first_name => $accountinfo->{first_name} ); $template->param( middle_name => $accountinfo->{middle_name} ); @@ -2256,8 +2254,7 @@ my %row; $accountcount++; my $accountinfo = &get_account( $astpp_db, $account ); - my $balance = &accountbalance( $astpp_db, $account ); - $balance = $balance / 10000; + my $balance = $ASTPP->accountbalance( account => $account ) / 10000 ; $balance = sprintf( "%." . $config->{decimalpoints} . "f", $balance ); $totalbalance = $totalbalance + $balance; $row{cc} = $accountinfo->{cc}; @@ -11416,7 +11413,7 @@ foreach my $name (@booth_list) { my ( %row, $balance, $tmp, $sql ); my $boothinfo = &get_account_including_closed( $astpp_db, $name ); - $balance = &accountbalance( $astpp_db, $name ); + $balance = $ASTPP->accountbalance( account => $name ); $tmp = "SELECT COUNT(*) FROM cdrs WHERE cardnum = " . $astpp_db->quote($name) @@ -11715,7 +11712,7 @@ ); $template->param( booth_name => $params->{booth_name} ); - my $balance = &accountbalance( $astpp_db, $params->{booth_name} ) / 10000; + my $balance = $ASTPP->accountbalance( account => $params->{booth_name} ) / 10000; my $unrated = &count_unrated_cdrs_account( $config, $cdr_db, $accountinfo->{number}, $accountinfo->{cc} ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:40:18
|
Revision: 2277 http://astpp.svn.sourceforge.net/astpp/?rev=2277&view=rev Author: darrenkw Date: 2009-10-06 03:40:09 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Speed up the balance calculating SQL. This should cut the time taken to about 1/3rd. Modified Paths: -------------- trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-06 03:39:24 UTC (rev 2276) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-06 03:40:09 UTC (rev 2277) @@ -1429,35 +1429,21 @@ sub accountbalance() { my ($self, %arg) = @_; my ( $tmp, $sql, $row, $debit, $credit, $balance, $posted_balance ); - $tmp = - "SELECT SUM(debit) FROM cdrs WHERE cardnum= " - . $self->{_astpp_db}->quote($arg{account}) - . " AND status NOT IN (1, 2)"; - $sql = $self->{_astpp_db}->prepare($tmp); + $tmp = "SELECT SUM(cdrs.debit),SUM(cdrs.credit),accounts.balance " + . " from cdrs,accounts WHERE cardnum = " + . $self->{_astpp_db}->quote($arg{account}) + . " AND cdrs.status NOT IN(1,2)"; $sql->execute; - $row = $sql->fetchrow_hashref; - $debit = $row->{"SUM(debit)"}; + $row = $sql->fetchrow_hashref; + $credit = $row->{"SUM(cdrs.credit)"}; + $debit = $row->{"SUM(cdrs.debit)"}; + $posted_balance = $row->{"balance"}; $sql->finish; - $tmp = - "SELECT SUM(credit) FROM cdrs WHERE cardnum= " - . $self->{_astpp_db}->quote($arg{account}) - . " AND status NOT IN (1, 2)"; - $sql = $self->{_astpp_db}->prepare($tmp); - $sql->execute; - $row = $sql->fetchrow_hashref; - $credit = $row->{"SUM(credit)"}; - $sql->finish; - $tmp = - "SELECT * FROM accounts WHERE number = " . $self->{_astpp_db}->quote($arg{account}); - $sql = $self->{_astpp_db}->prepare($tmp); - $sql->execute; - $row = $sql->fetchrow_hashref; - $posted_balance = $row->{balance}; - $sql->finish; if ( !$credit ) { $credit = 0; } if ( !$debit ) { $debit = 0; } - if ( !$posted_balance ) { $posted_balance = 0; } + if ( !$posted_balance ) { $posted_balance = 0; } $balance = ( $debit - $credit + $posted_balance ); + $sql->finish; return $balance; } @@ -1567,7 +1553,7 @@ . $self->{_astpp_db}->quote($arg{destination}) . " RLIKE pattern AND pricelist = " . $self->{_astpp_db}->quote($arg{pricelist}) - . " ORDER BY LENGTH(pattern) DESC"; + . " ORDER BY LENGTH(pattern) DESC LIMIT 1"; print STDERR "$tmp\n"; $sql = $self->{_astpp_db}->prepare($tmp); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-06 03:39:38
|
Revision: 2276 http://astpp.svn.sourceforge.net/astpp/?rev=2276&view=rev Author: darrenkw Date: 2009-10-06 03:39:24 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Remove temporary file. Removed Paths: ------------- trunk/freeswitch/astpp-fs-xml.pl.mod_perl Deleted: trunk/freeswitch/astpp-fs-xml.pl.mod_perl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl.mod_perl 2009-10-04 20:27:10 UTC (rev 2275) +++ trunk/freeswitch/astpp-fs-xml.pl.mod_perl 2009-10-06 03:39:24 UTC (rev 2276) @@ -1,350 +0,0 @@ -#!/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 strict; -use lib qw(.); - -use vars - qw($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 = $ASTPP->load_config(); - $astpp_db = $ASTPP->connect_db( - dbengine => $config->{astpp_dbengine}, - dbname => $config->{dbname}, - dbhost => $config->{dbhost}, - dbuser => $config->{dbuser}, - dbpass => $config->{dbpass} - ); - $ASTPP->set_astpp_db($astpp_db); - $config = $ASTPP->load_config_db( config => $config ) if $astpp_db; - $freeswitch_db = $ASTPP->connect_db( - dbengine => "MySQL", - dbname => $config->{freeswitch_dbname}, - dbhost => $config->{freeswitch_dbhost}, - dbuser => $config->{freeswitch_dbuser}, - dbpass => $config->{freeswitch_dbpass} - ); - $ASTPP->set_freeswitch_db($freeswitch_db); -} - -################# Programs start here ####################################### -&initialize; -my ( $ipinfo, $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); -foreach my $param ( param() ) { - $params->{$param} = param($param); - $ASTPP->debug( debug => "$param $params->{$param}" ); -} -$xml = header( -type => 'text/plain' ); - -$ASTPP->debug( - debug => "Destination = $params->{'Caller-Destination-Number'}" ); - -if ( $params->{section} eq "dialplan" ) { - # Check to see if this is a DID. If it is we handle it differently. - # - $didinfo = $ASTPP->get_did( did => $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 - # as authentications - $ASTPP->debug( debug => "Checking CC Number: " - . $params->{'Caller-Destination-Number'} ); - my $cc = substr( $params->{'Caller-Destination-Number'}, - 0, $config->{cardlength} ); - my $sql = - $astpp_db->prepare("SELECT number FROM accounts WHERE cc = $cc"); - $sql->execute; - my $record = $sql->fetchrow_hashref; - $sql->finish; - $params->{variable_accountcode} = $record->{cardnum} - if ( $record->{cardnum} ); - } - if ( !$params->{variable_accountcode} ) { - $ASTPP->debug( - debug => "Checking IP Address:" . $params->{'Hunt-Network-Addr'} ); - $ipinfo = $ASTPP->ip_address_authenticate( - ip_address => $params->{'Hunt-Network-Addr'}, - destination => $params->{'Caller-Destination-Number'} - ); - if ($ipinfo->{account} ne "") { - $params->{variable_accountcode} = $ipinfo->{account}; - $params->{'Caller-Destination-Number'} =~ s/$ipinfo->{prefix}//g; - } - } - - $xml = $ASTPP->fs_dialplan_xml_header( - xml => $xml, - destination_number => $params->{'Caller-Destination-Number'}, - DID => $didinfo->{number}, - IP => $ipinfo->{account} - ); - - $ASTPP->debug( debug => -"$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}" - ); - - my $carddata = $ASTPP->get_account(account => $params->{variable_accountcode}); - - if ( !$carddata->{number} ) - { # Check to see if the account exists. If not then exit. - $ASTPP->debug( debug => "CALLSTATUS 2" ); - $ASTPP->debug( debug => "CANNOT RETRIEVE CARD" ); - $xml .= - "<action application=\"reject\" data=\"CANNOT RETRIEVE ACCOUNT\"/>\n"; - $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); -# print $xml; - $ASTPP->debug( debug => "Returning nothing so dialplan can continue." ); - print ""; - exit(0); - } - - if ( $carddata->{dialed_modify} ) { - my @regexs = split( m/,/m, $carddata->{dialed_modify} ); - foreach my $regex (@regexs) { - $regex =~ s/"//g; #Strip off quotation marks - my ( $grab, $replace ) = split( m!/!i, $regex ) - ; # This will split the variable into a "grab" and "replace" as needed - $ASTPP->debug( debug => "Grab: $grab" ); - $ASTPP->debug( debug => "Replacement: $replace" ); - $ASTPP->debug( debug => - "Phone Before: $params->{'Caller-Destination-Number'}" ); - $$params->{'Caller-Destination-Number'} =~ s/$grab/$replace/is; - $ASTPP->debug( debug => - "Phone After: $params->{'Caller-Destination-Number'}" ); - } - } - - $ASTPP->debug( debug => "FINDING LIMIT FOR: " . $carddata->{number} ); - my $pricelistdata = $ASTPP->get_pricelist( - pricelist => $carddata->{pricelist}); - my $routeinfo; - ( $callstatus, $maxlength, $routeinfo ) = $ASTPP->max_length( - destination => $params->{'Caller-Destination-Number'}, - call_max_length => $config->{call_max_length}, - max_free_length => $config->{max_free_length}, - markup => $pricelistdata->{markup}, - account => $carddata->{number}, - account_creditlimit => $carddata->{credit_limit}, - account_maxchannels => $carddata->{maxchannels}, - debug => $config->{debug}, - account_pricelist => $carddata->{pricelist}, - account_reseller => $carddata->{reseller}, - default_brand => $config->{default_brand}, - ); -# &max_length( $astpp_db, $config, $carddata, -# $params->{'Caller-Destination-Number'} ); - -# my $routeinfo = &get_route( -# $astpp_db, $config, -# $params->{'Caller-Destination-Number'}, -# $carddata->{pricelist}, $carddata,$astppdid -# ); - - $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" ); - - if (!$routeinfo->{cost} && !$routeinfo->{pricelist}) { - $ASTPP->debug( debug => "COULD NOT FIND ROUTE. EXITING SO DIALPLAN CAN TAKE OVER" ); - exit(0); - } - while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1 ) { - $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}" ); - $carddata = &ASTPP->get_account( account => $carddata->{reseller} ); - push @reseller_list, $carddata->{number}; - $ASTPP->debug( debug => -"ADDING $carddata->{number} to the list of resellers for this account" - ); - my ( $resellercallstatus, $resellermaxlength, $routeinfo ) = $ASTPP->max_length( - destination => $params->{'Caller-Destination-Number'}, - call_max_length => $config->{call_max_length}, - max_free_length => $config->{max_free_length}, - markup => $pricelistdata->{markup}, - account => $carddata->{number}, - account_creditlimit => $carddata->{credit_limit}, - account_maxchannels => $carddata->{maxchannels}, - debug => $config->{debug}, - account_pricelist => $carddata->{pricelist}, - account_reseller => $carddata->{reseller}, - default_brand => $config->{default_brand}, - - ); - - -# my ( $resellercallstatus, $resellermaxlength ) = -# &max_length( $astpp_db, $config, $carddata, -# $params->{'Caller-Destination-Number'} ); -# -# my $routeinfo = &get_route( -# $astpp_db, $config, -# $params->{'Caller-Destination-Number'}, -# $carddata->{pricelist}, $carddata -# ); - if ( $resellercallstatus != 1 ) { - $carddata->{reseller} = ""; - $callstatus = $resellercallstatus; - } - elsif ( $resellermaxlength < $maxlength ) { - $maxlength = $resellermaxlength; - } - $ASTPP->debug( debug => -"Reseller cost = $routeinfo->{cost} and minimum charge is $minimumcharge" - ); - if ( $resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) { - $ASTPP->debug( debug => - "Reseller call is priced too cheap! Call being barred!" ); - $xml .= -"<action application=\"reject\" data=\"Reseller call is priced too cheap! Call being barred!\"/>\n"; - $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); - print $xml; - exit(0); - } - $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength" ); - $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus" ); - } - - if ( $config->{debug} == 1 ) { - $ASTPP->debug( debug => "PRINTING LIST OF RESELLERS FOR THIS ACCOUNT" ); - foreach my $reseller (@reseller_list) { - $ASTPP->debugb( debug => "RESELLER: $reseller" ); - } - } - - $ASTPP->debug("Max Call Length: $maxlength minutes"); - $ASTPP->debug("Call Status: $callstatus"); - - if ( $maxlength <= 1 ) { - $ASTPP->debug( debug => "NOT ENOUGH CREDIT" ); - $xml .= "<action application=\"reject\" data=\"NOT ENOUGH CREDIT\"/>\n"; - $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); - print $xml; - exit(0); - } elsif ($config->{call_max_length} && $maxlength < $config->{call_max_length} / 1000){ - $maxlength = $config->{call_max_length} / 1000; - } - - $xml = $ASTPP->fs_dialplan_xml_timelimit( - xml => $xml, - max_length => $maxlength, - accountcode => $carddata->{number} - ); - -# Set the timelimit as well as other variables which are needed in the dialplan. - my $timelimit = - "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)"; - - $ASTPP->debug( debug => "Looking for outbound Route" ); -# my $routeinfo = &get_route( -# $astpp_db, $config, -# $params->{'Caller-Destination-Number'}, -# $carddata->{pricelist}, $carddata, $astppdid -# ); - - if ($didinfo->{number} ) { - $ASTPP->debug( debug => "THIS IS A DID CALL: $xml"); - my ($returned_data) = $ASTPP->fs_dialplan_xml_did( - did => $params->{'Caller-Destination-Number'} - ); - $xml .= $returned_data; - } else { - # Get the list of routes for the phone number. - my @outboundroutes = - &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'}, - $carddata, $routeinfo, @reseller_list ); - foreach my $route (@outboundroutes) { - $ASTPP->debug( debug => - "$route->{trunk}: cost $route->{cost}\t $route->{pattern}" ); - if ( $route->{cost} > $routeinfo->{cost} ) { - $ASTPP->debug( debug => -"$route->{trunk}: $route->{cost} > $routeinfo->{cost}, skipping" - ); - } - else { - my ($returned_data,$junk) = $ASTPP->fs_dialplan_xml_bridge( - destination_number => $params->{'Caller-Destination-Number'}, - route_prepend => $route->{prepend}, - trunk_name => $route->{trunk}, - route_id => $route->{id} - ); - $xml .= $returned_data; - } - } - } - $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); - $ASTPP->debug( debug => $xml ); - print $xml; -} -elsif ( $params->{section} eq "directory" ) { - - #hostname darren-laptop - #section directory - #tag_name domain - #key_name name - #key_value 192.168.2.119 - #action sip_auth - #sip_profile internal - #sip_user_agent Zoiper rev.1118 - #sip_auth_username 1000 - #sip_auth_realm 192.168.2.119 - #sip_auth_nonce 83005e62-7e13-11dd-9eb1-25560b0691a8 - #sip_auth_uri sip:192.168.2.119;transport=UDP - #sip_auth_qop auth - #sip_auth_cnonce a79169d2656f292a - #sip_auth_nc 00000001 - #sip_auth_response 4475154556879ec2017978f1347192a6 - #sip_auth_method REGISTER - #key id - #user 1000 - #domain 192.168.2.119 - #ip 192.168.2.119 - - if ($params->{'user'}) { - $xml = $ASTPP->fs_directory_xml_header( xml => $xml ); - $xml = $ASTPP->fs_directory_xml( - xml => $xml, - ip => $params->{'ip'}, - user => $params->{'user'}, - domain => $params->{'domain'} - ); - $xml = $ASTPP->fs_directory_xml_footer( xml => $xml ); - } - $ASTPP->debug( debug => $xml ); - print $xml; -} -exit(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-04 20:27:21
|
Revision: 2275 http://astpp.svn.sourceforge.net/astpp/?rev=2275&view=rev Author: darrenkw Date: 2009-10-04 20:27:10 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Finish merging .pl files into one for freeswitch. This makes mod_perl support much, much simpler. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2009-10-04 20:16:28 UTC (rev 2274) +++ trunk/freeswitch/astpp-fs-xml.pl 2009-10-04 20:27:10 UTC (rev 2275) @@ -17,9 +17,13 @@ use CGI; use CGI qw/:standard Vars/; use ASTPP; +use XML::Simple; +use Data::Dumper; +use URI::Escape; use strict; + use vars - qw($params $ASTPP @output $config $freeswitch_db $astpp_db $verbosity ); + 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 @@ -38,6 +42,7 @@ $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}; } @@ -304,6 +309,7 @@ $ASTPP->debug( debug => $xml ); print $xml; } elsif ( $params->{cdr} ) { +print header( -type => 'text/plain' ); # create object my $xml = new XML::Simple; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-04 20:17:15
|
Revision: 2274 http://astpp.svn.sourceforge.net/astpp/?rev=2274&view=rev Author: darrenkw Date: 2009-10-04 20:16:28 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Merge astpp-fs-cdr-xml.pl into astpp-fs-xml.pl. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2009-10-03 05:17:07 UTC (rev 2273) +++ trunk/freeswitch/astpp-fs-xml.pl 2009-10-04 20:16:28 UTC (rev 2274) @@ -38,6 +38,7 @@ $config = &load_config_db( $astpp_db, $config ) if $astpp_db; $freeswitch_db = &connect_freeswitch_db( $config, @output ); $ASTPP->set_freeswitch_db($freeswitch_db); + $config->{cdr_table} = $config->{freeswitch_cdr_table}; } ################# Programs start here ####################################### @@ -302,5 +303,206 @@ } $ASTPP->debug( debug => $xml ); print $xml; +} elsif ( $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}->{callingcard}; + +sub process_callingcard_cdr() { + my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc ); + 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; + + 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, + $destination, + $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 ); + } + print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber}; + &write_callingcard_cdr( + $astpp_db, + $config, + $cardinfo, + uri_unescape($data->{variables}->{caller_id}), + $destination, + uri_unescape($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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-03 05:17:15
|
Revision: 2273 http://astpp.svn.sourceforge.net/astpp/?rev=2273&view=rev Author: darrenkw Date: 2009-10-03 05:17:07 +0000 (Sat, 03 Oct 2009) Log Message: ----------- Fix a couple of problems in the perl module so that it will compile again. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl.mod_perl trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/freeswitch/astpp-fs-xml.pl.mod_perl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl.mod_perl 2009-10-03 04:40:49 UTC (rev 2272) +++ trunk/freeswitch/astpp-fs-xml.pl.mod_perl 2009-10-03 05:17:07 UTC (rev 2273) @@ -43,7 +43,7 @@ dbpass => $config->{dbpass} ); $ASTPP->set_astpp_db($astpp_db); - $config = &load_config_db( $astpp_db, $config ) if $astpp_db; + $config = $ASTPP->load_config_db( config => $config ) if $astpp_db; $freeswitch_db = $ASTPP->connect_db( dbengine => "MySQL", dbname => $config->{freeswitch_dbname}, @@ -164,7 +164,6 @@ account_pricelist => $carddata->{pricelist}, account_reseller => $carddata->{reseller}, default_brand => $config->{default_brand}, - ); # &max_length( $astpp_db, $config, $carddata, # $params->{'Caller-Destination-Number'} ); @@ -187,19 +186,36 @@ } while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1 ) { $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}" ); - $carddata = &get_account( $astpp_db, $carddata->{reseller} ); + $carddata = &ASTPP->get_account( account => $carddata->{reseller} ); push @reseller_list, $carddata->{number}; $ASTPP->debug( debug => "ADDING $carddata->{number} to the list of resellers for this account" ); - my ( $resellercallstatus, $resellermaxlength ) = - &max_length( $astpp_db, $config, $carddata, - $params->{'Caller-Destination-Number'} ); - my $routeinfo = &get_route( - $astpp_db, $config, - $params->{'Caller-Destination-Number'}, - $carddata->{pricelist}, $carddata + my ( $resellercallstatus, $resellermaxlength, $routeinfo ) = $ASTPP->max_length( + destination => $params->{'Caller-Destination-Number'}, + call_max_length => $config->{call_max_length}, + max_free_length => $config->{max_free_length}, + markup => $pricelistdata->{markup}, + account => $carddata->{number}, + account_creditlimit => $carddata->{credit_limit}, + account_maxchannels => $carddata->{maxchannels}, + debug => $config->{debug}, + account_pricelist => $carddata->{pricelist}, + account_reseller => $carddata->{reseller}, + default_brand => $config->{default_brand}, + ); + + +# my ( $resellercallstatus, $resellermaxlength ) = +# &max_length( $astpp_db, $config, $carddata, +# $params->{'Caller-Destination-Number'} ); +# +# my $routeinfo = &get_route( +# $astpp_db, $config, +# $params->{'Caller-Destination-Number'}, +# $carddata->{pricelist}, $carddata +# ); if ( $resellercallstatus != 1 ) { $carddata->{reseller} = ""; $callstatus = $resellercallstatus; @@ -254,11 +270,11 @@ "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)"; $ASTPP->debug( debug => "Looking for outbound Route" ); - my $routeinfo = &get_route( - $astpp_db, $config, - $params->{'Caller-Destination-Number'}, - $carddata->{pricelist}, $carddata, $astppdid - ); +# my $routeinfo = &get_route( +# $astpp_db, $config, +# $params->{'Caller-Destination-Number'}, +# $carddata->{pricelist}, $carddata, $astppdid +# ); if ($didinfo->{number} ) { $ASTPP->debug( debug => "THIS IS A DID CALL: $xml"); Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-03 04:40:49 UTC (rev 2272) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-03 05:17:07 UTC (rev 2273) @@ -180,6 +180,24 @@ return $config; } +# Load configuration from database. Please pass the configuration from astpp-config.conf along. This will overwrite +# those settings with settings from the database. +sub load_config_db() { + my ($self, %arg) = @_; + my $config = $arg{config}; + my ($sql, @didlist, $row, $tmp ); + $tmp = + "SELECT name,value FROM system WHERE reseller IS NULL"; + $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + while ( $row = $sql->fetchrow_hashref ) { + $config->{$row->{name}} = $row->{value}; + } + $sql->finish; + return $config; +} + + =item $ASTPP->connect_db() Connect to a database and return the connection. This can be used for either @@ -1475,13 +1493,13 @@ $branddata = &get_pricelist($self, pricelist => $carddata->{pricelist}); print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; } - elsif ($config->{thirdlane_mods} == 1 && $arg{type} =~ m/.\d\d\d-IN/) { + elsif ($arg{thirdlane_mods} == 1 && $arg{type} =~ m/.\d\d\d-IN/) { print STDERR "Call belongs to a Thirdlane(tm) DID.\n"; ($arg{destination} = $arg{type}) =~ s/-IN//g; print STDERR "Destination: $arg{destination} \n"; $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; $record->{pattern} = "DID:" . $arg{destination}; - $branddata = &get_pricelist($self, pricelist => $carddata->{{pricelist}); + $branddata = &get_pricelist($self, pricelist => $carddata->{pricelist}); print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-03 04:40:57
|
Revision: 2272 http://astpp.svn.sourceforge.net/astpp/?rev=2272&view=rev Author: darrenkw Date: 2009-10-03 04:40:49 +0000 (Sat, 03 Oct 2009) Log Message: ----------- Add a bunch of documentation to our perl module Modified Paths: -------------- trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-02 20:44:18 UTC (rev 2271) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-03 04:40:49 UTC (rev 2272) @@ -10,7 +10,6 @@ bindtextdomain( "astpp", "/usr/local/share/locale" ); textdomain("astpp"); - require Exporter; our @ISA = qw(Exporter); @@ -19,7 +18,7 @@ # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. -# This allows declaration use ASTPP ':all'; +# This allows declaration use ASTPP ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( @@ -34,49 +33,116 @@ our $VERSION = '0.01'; + +=head1 NAME + +ASTPP - Perl extension for ASTPP (www.astpp.org). +Module contains functions to assist with the operation of ASTPP (www.astpp.org) + +=head1 EXPORT + +Everything by default. + + +=head1 SYNOPSIS + +use ASTPP; + +$ASTPP = new ASTPP; + +=head1 DESCRIPTION + +This module should make it easier to write scripts that interact with ASTPP + +=head1 MODULE COMMANDS + +=over 4 + +=cut + sub new { my ($class,%arg) = @_; bless { - _astpp_db => $_[1], - _freeswitch_db => $_[1], - _verbosity_level => $arg{verbosity_level} || 1, - _asterisk_agi => $_[3], - _cdr_db => $_[4], - _verbosity_item_level => $arg{verbosity_item_level} || 1, - _script => $arg{script} || "astpp-admin.cgi", - _config => $_[7], + _astpp_db => $_[1], + _freeswitch_db => $_[1], + _verbosity_level => $arg{verbosity_level} || 1, + _asterisk_agi => $_[3], + _cdr_db => $_[4], + _verbosity_item_level => $arg{verbosity_item_level} || 1, + _script => $arg{script} || "astpp-admin.cgi", + _config => $_[7], }, $class; } -sub set_verbosity_level { $_[0]->{_verbosity_level} } #Sets the verbosity level. -sub set_verbosity { $_[0]->{_verbosity_level} } #Sets the verbosity level. One of these needs to be deprecated. +sub set_verbosity_level { $_[0]->{_verbosity_level} } #Sets the verbosity level. +sub set_verbosity { $_[0]->{_verbosity_level} } #Sets the verbosity level. One of these needs to be deprecated. +=item $ASTPP->set_astpp_db() + +Pushes the ASTPP database connection into module for internal use + +Example: $ASTPP->set_astpp_db($astpp_db) + +=cut + sub set_astpp_db { my ($self, $astpp_db) = @_; $self->{_astpp_db} = $astpp_db if $astpp_db; } +=item $ASTPP->set_freeswitch_db() + +Pushes the Freeswitch database connection into module for internal use + +Example: $ASTPP->set_freeswitch_db($freeswitch_db) + +=cut + sub set_freeswitch_db { my ($self, $freeswitch_db) = @_; $self->{_freeswitch_db} = $freeswitch_db if $freeswitch_db; } +=item $ASTPP->set_cdr_db() + +Pushes the cdr database connection into module for internal use + +Example: $ASTPP->set_cdr_db($cdr_db) + +=cut + sub set_cdr_db { my ($self, $cdr_db) = @_; $self->{_cdr_db} = $cdr_db if $cdr_db; } +=item $ASTPP->set_asterisk_agi() + +Pushes the Asterisk AGI connection into module for internal use + +Example: $ASTPP->set_asterisk_agi($AGI) + +=cut + sub set_asterisk_agi { my ($self, $asterisk_agi) = @_; $self->{_asterisk_agi} = $asterisk_agi if $asterisk_agi; } -sub set_pagination_script #Set the location of the script we are working in. +=item $ASTPP->set_pagination_script() + +Set the location of the script we are working in so that we return the correct url + +Example: $ASTPP->set_pagination_script("astpp-admin.cgi") + +=cut + +sub set_pagination_script { my ($self, $script) = @_; $self->{_script} = $script if $script; @@ -84,62 +150,95 @@ #sub set_config #{ -# my ($self, %config_hash) = @_; -# $self->{_config} = %config_hash if %config_hash; +# my ($self, %config_hash) = @_; +# $self->{_config} = %config_hash if %config_hash; #} +=item $ASTPP->load_config() + +Read the ASTPP configuration file and return it as a hash + +Example: $config = $ASTPP->load_config() + +=cut + sub load_config { my ($self, %arg) = @_; my $config; open( CONFIG, "</var/lib/astpp/astpp-config.conf" ); while (<CONFIG>) { - chomp; # no newline - s/#.*//; # no comments - s/^\s+//; # no leading white - s/\s+$//; # no trailing white - next unless length; # anything left? - my ( $var, $value ) = split( /\s*=\s*/, $_, 2 ); - $config->{$var} = $value; + chomp; # no newline + s/#.*//; # no comments + s/^\s+//; # no leading white + s/\s+$//; # no trailing white + next unless length; # anything left? + my ( $var, $value ) = split( /\s*=\s*/, $_, 2 ); + $config->{$var} = $value; } close(CONFIG); return $config; } +=item $ASTPP->connect_db() + +Connect to a database and return the connection. This can be used for either +Postgresql on MySQL. + +Example: +$astpp_db = $ASTPP->connect_db( + dbengine => "MySQL", + dbname => "astpp", + dbhost => "localhost", + dbuser => "root", + dbpass => "Passw0rd!" +) + +=cut + sub connect_db { my ($self, %arg) = @_; my ( $dbh, $dsn ); if ( $arg{dbengine} eq "MySQL" ) { - $dsn = "DBI:mysql:database=$arg{dbname};host=$arg{dbhost}"; + $dsn = "DBI:mysql:database=$arg{dbname};host=$arg{dbhost}"; } elsif ( $arg{dbengine} eq "Pgsql" ) { - $dsn = "DBI:Pg:database=$arg{dbname};host=$arg{dbhost}"; + $dsn = "DBI:Pg:database=$arg{dbname};host=$arg{dbhost}"; } $dbh = DBI->connect( $dsn, $arg{dbuser}, $arg{dbpass} ); if ( !$dbh ) { - print STDERR "ASTPP DATABASE IS DOWN\n"; - return 0; + print STDERR "DATABASE: " . $arg{dbname} . " IS DOWN\n"; + return 0; } else { - $dbh->{mysql_auto_reconnect} = 1; - print STDERR gettext("Connected to ASTPP Database!") . "\n"; - return $dbh; + $dbh->{mysql_auto_reconnect} = 1; + print STDERR "Connected to " . $arg{dbname} . " Database!" . "\n"; + return $dbh; } } +=item $ASTPP->ip_address_authenticate() -sub ip_address_authenticate #Authenticates call by caller ip address. Works with both Asterisk(tm) and Freeswitch(tm) -# Requires -# ip_address = IP Address of calling device -# destination = Dialed number +Authenticates call by caller ip address. Works with both Asterisk(tm) and +Freeswitch(tm). + +Example: +$ipdata = $ASTPP->ip_address_authenticate( + ip_address => "192.168.1.1", + destination => "18005551212" +) + +=cut + +sub ip_address_authenticate { my ($self, %arg) = @_; - my ($sql,$tmp); + my ($sql,$tmp); $arg{ip_address} = $arg{ip} if $arg{ip}; #Freeswitch passes the ip in a different format. $tmp = "SELECT * FROM ip_map WHERE ip = " . $self->{_astpp_db}->quote($arg{ip_address}) . " AND prefix IN (NULL,'') OR ip = " . $self->{_astpp_db}->quote($arg{ip_address}); - $tmp .= " AND " . $self->{_astpp_db}->quote($arg{destination}) . " RLIKE prefix" if $arg{destination}; + $tmp .= " AND " . $self->{_astpp_db}->quote($arg{destination}) . " RLIKE prefix" if $arg{destination}; $tmp .= " ORDER BY LENGTH(prefix) DESC LIMIT 1"; print STDERR $tmp; $sql = $self->{_astpp_db}->prepare($tmp); @@ -149,8 +248,22 @@ return $anidata; } +=item $ASTPP->fs_dialplan_xml_header() + +Return the opening lines of the Freeswitch(TM) xml dialplan. If a call is +inbound via a DID or if we're authenticating via IP address we need to be in the +public context instead of the default context. + +Example: +$xml .= $ASTPP->fs_dialplan_xml_header( + DID => $diddata->{number}, + IP => $ipdata->{account}, + destination_number => $dialed_number +) + +=cut + sub fs_dialplan_xml_header -#Return the opening lines of the Freeswitch(TM) xml dialplan { my ($self, %arg) = @_; $arg{xml} .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; @@ -168,24 +281,45 @@ return $arg{xml}; } -sub fs_dialplan_xml_timelimit -#Return the opening lines of the Freeswitch(TM) xml dialplan -{ +=item $ASTPP->fs_dialplan_xml_timelimit() + +Return lines of the Freeswitch(TM) xml dialplan that set the accountcode as well +as limit the length of the call. + +Example: +$xml .= $ASTPP->fs_dialplan_xml_timelimit( + accountcode => $carddata->{number}, + max_length => $maxlength +) + +=cut + +sub fs_dialplan_xml_timelimit() { my ($self, %arg) = @_; $arg{xml} .= "<action application=\"sched_hangup\" data=\"+" . $arg{max_length} * 60 . "\"/>\n"; $arg{xml} .= "<action application=\"set\" data=\"accountcode=" . $arg{accountcode} . "\"/>\n"; return $arg{xml}; } -sub fs_dialplan_xml_did -# Return the dialplan code for an incoming call to a DID. -{ +=item $ASTPP->fs_dialplan_xml_did() + +Return the dialplan code for an incoming call to a DID. + +Example: +$xml .= $ASTPP->fs_dialplan_xml_did( + did => $destination, + accountcode => $carddata->{number} +) + +=cut + +sub fs_dialplan_xml_did() { my ($self, %arg) = @_; my ( $xml,$sql, $trunkdata, $dialstring,$data ); my $tmp = "SELECT * FROM dids WHERE number = " . $self->{_astpp_db}->quote( $arg{did} ) . " LIMIT 1"; - print STDERR $tmp; + print STDERR $tmp; $sql = $self->{_astpp_db}->prepare($tmp); $sql->execute; my $diddata = $sql->fetchrow_hashref; @@ -205,16 +339,24 @@ $xml .= "<action application=\"bridge\" data=\"" . $diddata->{extensions} . "\"/>\n"; } - return $xml; + return $xml; } -sub fs_dialplan_xml_bridge -#Return the bridge command along with details. This is only called if a call is approved. -# Requires the following variables: -# destination_number = The number we are trying to call -# trunk_name = The name of the trunk we're using. -# route_prepend = What do we tag on for numbers on this route? -{ + +=item $ASTPP->fs_dialplan_xml_bridge() + +Return the bridge command along with details. This is only called if a call is approved. + +Example: +$xml .= $ASTPP->fs_dialplan_xml_bridge( + destination_number => $destination, + trunk_name => $route->{trunk}, + route_prepend => $route->{prepend} +) + +=cut + +sub fs_dialplan_xml_bridge() { my ($self, %arg) = @_; my ( $sql, $trunkdata, $dialstring,$data ); $sql = $self->{_astpp_db}->prepare( "SELECT * FROM trunks WHERE name = " @@ -240,7 +382,7 @@ } if ( $trunkdata->{tech} eq "Zap" ) { $dialstring .= "<action application=\"bridge\" data=\"openzap/" . $trunkdata->{path} . "/1/" . $arg{route_prepend} . $arg{destination_number} . "\"/>\n"; - return ($dialstring,$data); + return ($dialstring,$data); } elsif ( $trunkdata->{tech} eq "SIP" ) { my ($profile,$dest) = split(m/","/m, $trunkdata->{path}); @@ -253,17 +395,23 @@ $data = "sofia/" . $profile . "/" . $arg{route_prepend} . $arg{destination_number} . "\@" . $dest; $dialstring .= "<action application=\"bridge\" data=\"" . $data . "\"/>\n"; } - return ($dialstring,$data); + return ($dialstring,$data); } else { print STDERR "CANNOT ROUTE THIS CALL!!!!!\n"; - return ""; + return ""; } } -sub fs_dialplan_xml_footer -#Return the closing lines of the Freeswitch(TM) xml dialplan -{ +=item $ASTPP->fs_dialplan_xml_footer() + +Return the closing lines of the Freeswitch(TM) xml dialplan + +Example: $xml .= $ASTPP->fs_dialplan_xml_footer(); + +=cut + +sub fs_dialplan_xml_footer() { my ($self, %arg) = @_; $arg{xml} .= "</condition>\n"; $arg{xml} .= "</extension>\n"; @@ -273,11 +421,17 @@ return $arg{xml}; } -sub fs_directory_xml_header -#Return the opening lines of the Freeswitch(TM) xml directory -#xml = Current XML code, usually blank. -#domain = domain name -{ +=item $ASTPP->fs_directory_xml_header() + +Return the opening lines of the Freeswitch(TM) xml directory. + +Example: $xml .= $ASTPP->fs_directory_xml_header( + xml => "" +); + +=cut + +sub fs_directory_xml_header() { my ($self, %arg) = @_; $arg{xml} .= "<?xml version=\"1.0\"?>\n"; $arg{xml} .= "<document type=\"freeswitch/xml\">\n"; @@ -285,198 +439,224 @@ return $arg{xml}; } -sub fs_add_sip_user -# Add a SIP user -# Arguments -# sip_ext_prepend = $config->{sip_ext_prepend} -# accountcode -# context = $config->{freeswitch_context} -# vm_password = Password -# password = Password -# -{ +=item $ASTPP->fs_directory_xml_header() + +Add a SIP user to the Freeswitch database. The "username" parameter is optional. +if it is not passed then we generate a random one using "accountcode" as a base. + +Example: + +($status_code,$status_text) = $ASTPP->fs_add_sip_user( + sip_ext_prepend => $config->{sip_ext_prepend} + accountcode => $params->{accountcode}, + context => $config->{freeswitch_context}, + vm_password => $params->{vmpassword}, + password => $params->{password}, + username => $params->{username} +); + +=cut + +sub fs_add_sip_user() { my ($self, %arg) = @_; # Find uniqueid to prepend to the login my $sipid = 0; if (!$arg{username} || $arg{username} eq "") { $arg{username} = $arg{accountcode}; for ( ; ; ) { - my $count = 1; - $sipid = - int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ) - . int( rand() * 9000 + 1000 ); - $sipid = $arg{sip_ext_prepend} . $sipid; - $sipid = substr( $sipid, 0, 5 ); - $sipid = $arg{username} . $sipid; - my $sql = - $self->{_freeswitch_db}->prepare( - "SELECT COUNT(*) FROM directory WHERE username = " - . $self->{_freeswitch_db}->quote($sipid) ); - $sql->execute; - my $record = $sql->fetchrow_hashref; - $sql->finish; - if ( $record->{"COUNT(*)"} == 0 ) { + my $count = 1; + $sipid = + int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ) + . int( rand() * 9000 + 1000 ); + $sipid = $arg{sip_ext_prepend} . $sipid; + $sipid = substr( $sipid, 0, 5 ); + $sipid = $arg{username} . $sipid; + my $sql = + $self->{_freeswitch_db}->prepare( + "SELECT COUNT(*) FROM directory WHERE username = " + . $self->{_freeswitch_db}->quote($sipid) ); + $sql->execute; + my $record = $sql->fetchrow_hashref; + $sql->finish; + if ( $record->{"COUNT(*)"} == 0 ) { last; } } } else { - $arg{username} =~ s/\W//mg; + $arg{username} =~ s/\W//mg; $sipid = $arg{username} } my $tmp = - "INSERT INTO directory (username,domain) VALUES (" + "INSERT INTO directory (username,domain) VALUES (" . $self->{_freeswitch_db}->quote($sipid) . ", " . $self->{_freeswitch_db}->quote($arg{freeswitch_domain}). ")"; print STDERR $tmp . "\n"; my $sql = $self->{_freeswitch_db}->prepare($tmp); if ( !$sql->execute ) { - print "$tmp failed"; - return (1,"SIP Device Creation Failed!"); + print "$tmp failed"; + return (1,"SIP Device Creation Failed!"); } else { - my $directory_id = $sql->{'mysql_insertid'}; - my $tmp = "INSERT INTO directory_vars (directory_id,var_name,var_value) VALUES (" - . $self->{_freeswitch_db}->quote($directory_id) . "," - . "'accountcode'," - . $self->{_freeswitch_db}->quote($arg{accountcode}) + my $directory_id = $sql->{'mysql_insertid'}; + my $tmp = "INSERT INTO directory_vars (directory_id,var_name,var_value) VALUES (" + . $self->{_freeswitch_db}->quote($directory_id) . "," + . "'accountcode'," + . $self->{_freeswitch_db}->quote($arg{accountcode}) . "),(" - . $self->{_freeswitch_db}->quote($directory_id) . "," - . "'user_context'," - . $self->{_freeswitch_db}->quote($arg{freeswitch_context}) . ")"; + . $self->{_freeswitch_db}->quote($directory_id) . "," + . "'user_context'," + . $self->{_freeswitch_db}->quote($arg{freeswitch_context}) . ")"; print STDERR $tmp . "\n"; - $self->{_freeswitch_db}->do($tmp); + $self->{_freeswitch_db}->do($tmp); - $tmp = "INSERT INTO directory_params (directory_id,param_name,param_value) VALUES (" - . $self->{_freeswitch_db}->quote($directory_id) . "," - . "'vm-password'," - . $self->{_freeswitch_db}->quote($arg{vm_password}) + $tmp = "INSERT INTO directory_params (directory_id,param_name,param_value) VALUES (" + . $self->{_freeswitch_db}->quote($directory_id) . "," + . "'vm-password'," + . $self->{_freeswitch_db}->quote($arg{vm_password}) . "),(" - . $self->{_freeswitch_db}->quote($directory_id) . "," - . "'password'," - . $self->{_freeswitch_db}->quote($arg{password}) . ")"; + . $self->{_freeswitch_db}->quote($directory_id) . "," + . "'password'," + . $self->{_freeswitch_db}->quote($arg{password}) . ")"; print STDERR $tmp . "\n"; - $self->{_freeswitch_db}->do($tmp); + $self->{_freeswitch_db}->do($tmp); - return (0, "SIP Device Added!" . "Username:" . " " . $sipid . " " . "Password:" . " " . $arg{password}, $sipid); + return (0, "SIP Device Added!" . "Username:" . " " . $sipid . " " . "Password:" . " " . $arg{password}, $sipid); } } -sub fs_save_sip_user -{ +sub fs_save_sip_user() { my ($self, %arg) = @_; my $tmp = "UPDATE directory SET username = " - . $self->{_freeswitch_db}->quote($arg{username}) - . " WHERE id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{username}) + . " WHERE id = " + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); - $tmp = "UPDATE directory_vars SET var_value = " - . $self->{_freeswitch_db}->quote($arg{accountcode}) + $tmp = "UPDATE directory_vars SET var_value = " + . $self->{_freeswitch_db}->quote($arg{accountcode}) . " WHERE var_name = 'accountcode'" . " AND directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); $tmp = "UPDATE directory_vars SET var_value = " - . $self->{_freeswitch_db}->quote($arg{freeswitch_context}) + . $self->{_freeswitch_db}->quote($arg{freeswitch_context}) . " WHERE var_name = 'user_context'" . " AND directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); $tmp = "UPDATE directory_params SET param_value = " - . $self->{_freeswitch_db}->quote($arg{vm_password}) + . $self->{_freeswitch_db}->quote($arg{vm_password}) . " WHERE param_name = 'vm-password'" . " AND directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); - $tmp = "UPDATE directory_params SET param_value = " - . $self->{_freeswitch_db}->quote($arg{password}) + $tmp = "UPDATE directory_params SET param_value = " + . $self->{_freeswitch_db}->quote($arg{password}) . " WHERE param_name = 'password'" . " AND directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; $self->{_freeswitch_db}->do($tmp); - return (0, "SIP Device Saved!" . "Username:" . " " . $arg{username} . " " . "Password:" . " " . $arg{password}, $arg{username}); + return (0, "SIP Device Saved!" . "Username:" . " " . $arg{username} . " " . "Password:" . " " . $arg{password}, $arg{username}); } -sub fs_retrieve_sip_user -# Retrieve a SIP user -# Parameters -# directory_id = directory_id of sip user you are looking for. -{ +=item $ASTPP->fs_retrieve_sip_user() + +Returns the details on the specified Freeswitch SIP user. + +Example: + +$user_data = $ASTPP->fs_retrieve_sip_user( + directory_id => "1" #directory_id of sip user you are looking for. +); + +=cut + +sub fs_retrieve_sip_user() { my ($self, %arg) = @_; - my ($tmp,$record,$sql,$deviceinfo); + my ($tmp,$record,$sql,$deviceinfo); $tmp = "SELECT username FROM directory WHERE id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}); + . $self->{_freeswitch_db}->quote($arg{directory_id}); print STDERR $tmp . "\n"; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - $record = $sql->fetchrow_hashref; - $sql->finish; + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; $deviceinfo->{username} = $record->{username}; - $tmp = "SELECT var_value FROM directory_vars WHERE directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}) - . " AND var_name = 'user_context'"; + $tmp = "SELECT var_value FROM directory_vars WHERE directory_id = " + . $self->{_freeswitch_db}->quote($arg{directory_id}) + . " AND var_name = 'user_context'"; print STDERR $tmp . "\n"; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - $record = $sql->fetchrow_hashref; - $sql->finish; - $deviceinfo->{context} = $record->{var_value}; + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; + $deviceinfo->{context} = $record->{var_value}; - $tmp = "SELECT param_value FROM directory_params WHERE directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}) - . " AND param_name = 'password' LIMIT 1"; + $tmp = "SELECT param_value FROM directory_params WHERE directory_id = " + . $self->{_freeswitch_db}->quote($arg{directory_id}) + . " AND param_name = 'password' LIMIT 1"; print STDERR $tmp . "\n"; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - $record = $sql->fetchrow_hashref; - $sql->finish; - $deviceinfo->{password} = $record->{param_value}; + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; + $deviceinfo->{password} = $record->{param_value}; - $tmp = "SELECT param_value FROM directory_params WHERE directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}) - . " AND param_name = 'vm-password' LIMIT 1"; + $tmp = "SELECT param_value FROM directory_params WHERE directory_id = " + . $self->{_freeswitch_db}->quote($arg{directory_id}) + . " AND param_name = 'vm-password' LIMIT 1"; print STDERR $tmp . "\n"; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - $record = $sql->fetchrow_hashref; - $sql->finish; - $deviceinfo->{vm_password} = $record->{param_value}; + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; + $deviceinfo->{vm_password} = $record->{param_value}; - $tmp = "SELECT var_value FROM directory_vars WHERE directory_id = " - . $self->{_freeswitch_db}->quote($arg{directory_id}) - . " AND var_name = 'accountcode' LIMIT 1"; + $tmp = "SELECT var_value FROM directory_vars WHERE directory_id = " + . $self->{_freeswitch_db}->quote($arg{directory_id}) + . " AND var_name = 'accountcode' LIMIT 1"; print STDERR $tmp . "\n"; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - $record = $sql->fetchrow_hashref; - $sql->finish; - $deviceinfo->{accountcode} = $record->{var_value}; + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; + $deviceinfo->{accountcode} = $record->{var_value}; return $deviceinfo; } -sub fs_delete_sip_user -#Delete the SIP user -#id = directory.id to delete -{ + +=item $ASTPP->fs_dele_sip_user() + +Delete the specified Freeswitch SIP user. + +Example: + +$status_code = $ASTPP->fs_delete_sip_user( + id => "1" #directory_id of sip user you are deleting. +); + +=cut + +sub fs_delete_sip_user() { my ($self, %arg) = @_; my ($tmp,$sql,@results); $tmp = "DELETE FROM directory WHERE id = " . $self->{_freeswitch_db}->quote($arg{id}); @@ -515,17 +695,17 @@ . $self->{_freeswitch_db}->quote($arg{domain}) . ",'\$\${local_ip_v4}')"; } -# } else { -# if ($arg{domain}) { -# $tmp .= " WHERE domain = " -# . $self->{_freeswitch_db}->quote($arg{domain}); -# } +# } else { +# if ($arg{domain}) { +# $tmp .= " WHERE domain = " +# . $self->{_freeswitch_db}->quote($arg{domain}); +# } } } print STDERR $tmp; - $sql = $self->{_freeswitch_db}->prepare($tmp); - $sql->execute; - while (my $record = $sql->fetchrow_hashref) { + $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql->execute; + while (my $record = $sql->fetchrow_hashref) { print STDERR $record->{username}; push @results, $record; } @@ -540,7 +720,7 @@ my ($tmp,$sql,@results); $tmp = "SELECT * FROM directory_params WHERE directory_id = " . $self->{_freeswitch_db}->quote($id); - $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql = $self->{_freeswitch_db}->prepare($tmp); $sql->execute; while (my $record = $sql->fetchrow_hashref) { push @results, $record; @@ -556,7 +736,7 @@ my ($tmp,$sql,@results); $tmp = "SELECT * FROM directory_vars WHERE directory_id = " . $self->{_freeswitch_db}->quote($id); - $sql = $self->{_freeswitch_db}->prepare($tmp); + $sql = $self->{_freeswitch_db}->prepare($tmp); $sql->execute; while (my $record = $sql->fetchrow_hashref) { push @results, $record; @@ -576,7 +756,7 @@ my ($sql,$sql1,$tmp,$tmp1); $arg{xml} .= "<domain name=\"" . $arg{domain} . "\">"; my @sip_users = &fs_list_sip_usernames($self,%arg); - foreach my $record (@sip_users) { + foreach my $record (@sip_users) { $arg{xml} .= "<user id=\"" . $record->{username} . "\" mailbox=\"" . $record->{mailbox} . "\">\n"; $arg{xml} .= "<params>\n"; my @params = &fs_list_sip_params($self,$record->{id}); @@ -653,8 +833,8 @@ # Therefore we need to pass the Data::Paginate stuff # as well as the total number of pages. # - # mode = What mode do we want. - # sql = SQL to select what we want without the limit commands. + # mode = What mode do we want. + # sql = SQL to select what we want without the limit commands. # # Check to see if there is a parameter called "results_per_page" set. If it's set it overrides our defaults. if (!$arg{results_per_page} || $arg{results_per_page} > 1 ) { @@ -675,14 +855,14 @@ my $te_match = $total_entries ? Digest::MD5::md5_hex("unique_cypher-$total_entries-$arg{sql_check}") : ''; if ( !$total_entries || $verify ne $te_match ) { - # its not ok so re-fetch + # its not ok so re-fetch # $sql = $self->{_astpp_db}->prepare($arg{sql_count}); - $sql = $db->prepare($arg{sql_count}); - $sql->execute; - $record = $sql->fetchrow_hashref; - $total_entries = $record->{"COUNT(*)"}; - $sql->finish; - $te_match = Digest::MD5::md5_hex("unique_cypher-$total_entries-$arg{sql_check}"); + $sql = $db->prepare($arg{sql_count}); + $sql->execute; + $record = $sql->fetchrow_hashref; + $total_entries = $record->{"COUNT(*)"}; + $sql->finish; + $te_match = Digest::MD5::md5_hex("unique_cypher-$total_entries-$arg{sql_check}"); } #if ($te_match <= 0) { $te_match = 0; } @@ -690,44 +870,44 @@ # otherwise its all ok so use it my $pgr = Data::Paginate->new( - { - 'start_array_index_at_zero' => 1, - 'total_entries' => $total_entries, - 'entries_per_page' => $arg{results_per_page}, - 'total_entries_verify_param_value' => $te_match - } + { + 'start_array_index_at_zero' => 1, + 'total_entries' => $total_entries, + 'entries_per_page' => $arg{results_per_page}, + 'total_entries_verify_param_value' => $te_match + } ); # only SELECT current page's records: if ( $total_entries > $pgr->get_entries_on_this_page() ) { - $sql = - $arg{sql_select} . " LIMIT " - . ( $pgr->get_first() - 1 ) . ", " - . $pgr->get_entries_on_this_page(); + $sql = + $arg{sql_select} . " LIMIT " + . ( $pgr->get_first() - 1 ) . ", " + . $pgr->get_entries_on_this_page(); } else { - $sql = $arg{sql_select}; + $sql = $arg{sql_select}; } # First we decide if we have multiple pages... if ($total_entries > 1) { - my $html; - $html = - "<a href=\"" . $self->{_script} . "?mode=" - . $arg{mode} . "&ve=" - . $arg{ve} . "&te=" - . $total_entries - . "&pg=1\">" - . "First Page" - . "</a> | " - . scalar $pgr->get_navi_html() - . "<a href=\"" . $self->{_script} . "?mode=" - . $arg{mode} . "&ve=" - . $arg{ve} . "&te=" - . $total_entries . "&pg=" - . $pgr->get_last_page() . "\">" - . "Last Page" . "</a>"; + my $html; + $html = + "<a href=\"" . $self->{_script} . "?mode=" + . $arg{mode} . "&ve=" + . $arg{ve} . "&te=" + . $total_entries + . "&pg=1\">" + . "First Page" + . "</a> | " + . scalar $pgr->get_navi_html() + . "<a href=\"" . $self->{_script} . "?mode=" + . $arg{mode} . "&ve=" + . $arg{ve} . "&te=" + . $total_entries . "&pg=" + . $pgr->get_last_page() . "\">" + . "Last Page" . "</a>"; return ($sql,$html); } else { @@ -738,16 +918,16 @@ sub list_pricelists { my ($self, %arg) = @_; # Return a list of all pricelists either for the appropriate reseller or without reseller. - my ( $sql, @pricelistlist, $row, $tmp ); - if ( !$arg{reseller} || $arg{reseller} eq "") { - $tmp = + my ( $sql, @pricelistlist, $row, $tmp ); + if ( !$arg{reseller} || $arg{reseller} eq "") { + $tmp = "SELECT name FROM pricelists WHERE status < 2 AND reseller IS NULL ORDER BY name"; } else { - $tmp = - "SELECT name FROM pricelists WHERE status < 2 AND reseller = " - . $self->{_astpp_db}->quote($arg{reseller}) - . " ORDER BY name"; + $tmp = + "SELECT name FROM pricelists WHERE status < 2 AND reseller = " + . $self->{_astpp_db}->quote($arg{reseller}) + . " ORDER BY name"; } $sql = $self->{_astpp_db}->prepare($tmp); $sql->execute; @@ -763,7 +943,7 @@ # Function 2 = return crds # Function 3 = Internal Invoices, Post CDRs. { - my ($self, %arg) = @_; #Count the cdrs billable on a specific account + my ($self, %arg) = @_; #Count the cdrs billable on a specific account my $tmp; if ($arg{function} == 1) { $tmp = "SELECT COUNT(*) FROM cdrs WHERE cardnum = "; @@ -811,9 +991,9 @@ } elsif ($arg{function} == 2) { my @cdrs; - while ( my $record = $sql->fetchrow_hashref ) { - push @cdrs, $record; - } + while ( my $record = $sql->fetchrow_hashref ) { + push @cdrs, $record; + } $sql->finish; return( @cdrs @@ -823,7 +1003,7 @@ sub invoice_list_internal { - my ($self, %arg) = @_; # List Internal Invoices. + my ($self, %arg) = @_; # List Internal Invoices. my ($tmp,$sql,@invoices); $tmp = "SELECT * FROM invoice_list_view"; if ($arg{accountid}) { @@ -841,7 +1021,7 @@ sub invoice_create_internal { - my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. + my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. my $tmp = "INSERT into invoices (accountid,date) VALUES(" . $self->{_astpp_db}->quote($arg{accountid}) . ",curdate())"; @@ -856,7 +1036,7 @@ sub invoice_cdrs_subtotal_internal { - my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. + my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. my ($tmp,$row,$sql,$credit,$debit,$total); $tmp = "SELECT SUM(debit) FROM cdrs WHERE invoiceid = " . $self->{_astpp_db}->quote($arg{invoiceid}); @@ -877,22 +1057,22 @@ $total = ( $debit - $credit ); return ($total/10000); -# $tmp = "INSERT into invoices_total (invoiceid,title,text,value,class,sort_order) VALUES(" -# . $self->{_astpp_db}->quote($arg{invoiceid}) -# . ",'Subtotal',''," -# . $self->{_astpp_db}->quote($total/10000) -# . ",1," -# . $self->{_astpp_db}->quote($arg{sort_order}) -# . ")"; -# $sql = $ $self->{_astpp_db}->prepare($tmp); -# $sql->execute; -# return $arg{sort_order}++; +# $tmp = "INSERT into invoices_total (invoiceid,title,text,value,class,sort_order) VALUES(" +# . $self->{_astpp_db}->quote($arg{invoiceid}) +# . ",'Subtotal',''," +# . $self->{_astpp_db}->quote($total/10000) +# . ",1," +# . $self->{_astpp_db}->quote($arg{sort_order}) +# . ")"; +# $sql = $ $self->{_astpp_db}->prepare($tmp); +# $sql->execute; +# return $arg{sort_order}++; } sub invoice_subtotal_post_internal { my ($self, %arg) = @_; - $arg{value} = sprintf( "%." . $arg{decimalpoints_total} . "f", $arg{value} ); + $arg{value} = sprintf( "%." . $arg{decimalpoints_total} . "f", $arg{value} ); my $tmp = "INSERT into invoices_total (invoices_id,title,text,value,class,sort_order) VALUES(" . $self->{_astpp_db}->quote($arg{invoiceid}) . "," @@ -914,12 +1094,12 @@ sub invoice_subtotal_internal { my ($self, %arg) = @_; - my $tmp = "SELECT SUM(value) FROM invoices_total WHERE invoices_id = " - . $self->{_astpp_db}->quote($arg{invoiceid}); - my $sql = $self->{_astpp_db}->prepare($tmp); - $sql->execute; - my $row = $sql->fetchrow_hashref; - my $value = $row->{"SUM(value)"}; + my $tmp = "SELECT SUM(value) FROM invoices_total WHERE invoices_id = " + . $self->{_astpp_db}->quote($arg{invoiceid}); + my $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + my $row = $sql->fetchrow_hashref; + my $value = $row->{"SUM(value)"}; $sql->finish; return $value; } @@ -928,7 +1108,7 @@ # function 1 = list # function 2 = post { - my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. + my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. my (@taxes,$row,$tmp,$sql); $tmp = "SELECT * FROM taxes_to_accounts_view WHERE accountid = " . $self->{_astpp_db}->quote($arg{accountid}) @@ -947,27 +1127,27 @@ my $sort = 1; my $tax_priority = ""; my $subtotal = $arg{invoice_subtotal}; - foreach my $tax (@taxes) { + foreach my $tax (@taxes) { my ($tax_amount); if ($tax_priority eq "") { $tax_priority = $tax->{taxes_priority}; } elsif($tax->{taxes_priority} > $tax_priority) { $tax_priority = $tax->{taxes_priority}; - my $tmp = "SELECT SUM(value) FROM invoices_total WHERE invoices_id = " - . $self->{_astpp_db}->quote($arg{invoiceid}); + my $tmp = "SELECT SUM(value) FROM invoices_total WHERE invoices_id = " + . $self->{_astpp_db}->quote($arg{invoiceid}); print STDERR $tmp . "\n"; - my $sql = $self->{_astpp_db}->prepare($tmp); - $sql->execute; - my $row = $sql->fetchrow_hashref; - $subtotal = $row->{"SUM(value)"}; + my $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + my $row = $sql->fetchrow_hashref; + $subtotal = $row->{"SUM(value)"}; $sql->finish; } print STDERR "Subtotal: $subtotal \n"; print STDERR "Tax_rate: $tax->{taxes_rate} \n"; - my $tax_total = (($subtotal * ( $tax->{taxes_rate} / 100 )) + $tax->{taxes_amount} ); + my $tax_total = (($subtotal * ( $tax->{taxes_rate} / 100 )) + $tax->{taxes_amount} ); print STDERR "Tax Total: $tax_total \n"; print STDERR "Round to: $arg{decimalpoints_tax} \n"; - $tax_total = sprintf( "%." . $arg{decimalpoints_tax} . "f", $tax_total ); + $tax_total = sprintf( "%." . $arg{decimalpoints_tax} . "f", $tax_total ); print STDERR "Tax Total: $tax_total \n"; my $tmp = "INSERT INTO invoices_total (invoices_id,title,text,value,class,sort_order) VALUES(" . $self->{_astpp_db}->quote($arg{invoiceid}) @@ -982,15 +1162,15 @@ my $sql = $self->{_astpp_db}->prepare($tmp); $sql->execute; - $arg{sort_order}++; - } + $arg{sort_order}++; + } return $arg{sort_order}; } sub account_cdr_post { - my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. + my ($self, %arg) = @_; # Create invoice in ASTPP Internally and return the invoice number. $arg{description} = "" if !$arg{timestamp}; $arg{pricelist} = "" if !$arg{pricelist}; $arg{pattern} = "" if !$arg{pattern}; @@ -1011,50 +1191,62 @@ . $self->{_astpp_db}->quote($arg{pattern}) . ")"; if ( $self->{_astpp_db}->do($tmp) ) { - return (1, "POSTED CDR: $arg{account} in the amount of: " . $arg{amount} / 10000 . "\n"); + return (1, "POSTED CDR: $arg{account} in the amount of: " . $arg{amount} / 10000 . "\n"); } else { - return (2, $tmp . " FAILED! \n"); + return (2, $tmp . " FAILED! \n"); } } -sub get_did -{ - my ($self, %arg) = @_; +=item $ASTPP->get_did() + +Returns the details on the specified DID. + +Example: + +$diddata = $ASTPP->get_did( + reseller => $carddata->{reseller}, + did => $destination +); + +=cut + +sub get_did() { + my ($self, %arg) = @_; my ( $tmp, $sql, $diddata ); if (!$arg{reseller} || $arg{reseller} eq "") { - $tmp = "SELECT * FROM dids WHERE number = " + $tmp = "SELECT * FROM dids WHERE number = " . $self->{_astpp_db}->quote($arg{did}); } else { $tmp = - "SELECT dids.number AS number, " - . "reseller_pricing.monthlycost AS monthlycost, " - . "reseller_pricing.prorate AS prorate, " - . "reseller_pricing.setup AS setup, " - . "reseller_pricing.cost AS cost, " - . "reseller_pricing.connectcost AS connectcost, " - . "reseller_pricing.includedseconds AS includedseconds, " - . "reseller_pricing.inc AS inc, " - . "reseller_pricing.disconnectionfee AS disconnectionfee, " - . "dids.provider AS provider, " - . "dids.country AS country, " - . "dids.city AS city, " - . "dids.province AS province, " - . "dids.extensions AS extensions, " - . "dids.account AS account, " - . "dids.variables AS variables, " - . "dids.options AS options, " - . "dids.maxchannels AS maxchannels, " - . "dids.chargeonallocation AS chargeonallocation, " - . "dids.allocation_bill_status AS allocation_bill_status, " - . "dids.limittime AS limittime, " - . "dids.dial_as AS dial_as, " - . "dids.status AS status " - . "FROM dids, reseller_pricing " - . "WHERE dids.number = " . $self->{_astpp_db}->quote($arg{did}) - . " AND reseller_pricing.type = '1' AND reseller_pricing.reseller = " - . $self->{_astpp_db}->quote($arg{reseller}) . " AND reseller_pricing.note = " - . $self->{_astpp_db}->quote($arg{did}); + "SELECT dids.number AS number, " + . "reseller_pricing.monthlycost AS monthlycost, " + . "reseller_pricing.prorate AS prorate, " + . "reseller_pricing.setup AS setup, " + . "reseller_pricing.cost AS cost, " + . "reseller_pricing.connectcost AS connectcost, " + . "reseller_pricing.includedseconds AS includedseconds, " + . "reseller_pricing.inc AS inc, " + . "reseller_pricing.disconnectionfee AS disconnectionfee, " + . "dids.provider AS provider, " + . "dids.country AS country, " + . "dids.city AS city, " + . "dids.province AS province, " + . "dids.extensions AS extensions, " + . "dids.account AS account, " + . "dids.variables AS variables, " + . "dids.options AS options, " + . "dids.maxchannels AS maxchannels, " + . "dids.chargeonallocation AS chargeonallocation, " + . "dids.allocation_bill_status AS allocation_bill_status, " + . "dids.limittime AS limittime, " + . "dids.dial_as AS dial_as, " + . "dids.status AS status " + . "FROM dids, reseller_pricing " + . "WHERE dids.number = " . $self->{_astpp_db}->quote($arg{did}) + . " AND reseller_pricing.type = '1' AND reseller_pricing.reseller = " + . $self->{_astpp_db}->quote($arg{reseller}) . " AND reseller_pricing.note = " + . $self->{_astpp_db}->quote($arg{did}); } print STDERR "$tmp\n"; $sql = @@ -1065,35 +1257,48 @@ return $diddata; } +=item $ASTPP->get_account() +Returns the details on the specified ASTPP account. It will search first by +"cardnum" then by "cc" and finally by "accountid". Accountid is the prefered +method but most installations use cardnum for legacy reasons. + +Example: + +$carddata = $ASTPP->get_account( + account => $params->{accountcode} +); + +=cut + sub get_account() { - my ($self, %arg) = @_; + my ($self, %arg) = @_; my ( $sql, $accountdata ); $sql = $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE number = " - . $self->{_astpp_db}->quote($arg{account}) - . " AND status = 1" ); + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); $sql->execute; $accountdata = $sql->fetchrow_hashref; $sql->finish; if ($accountdata) { - return $accountdata; + return $accountdata; } else { $sql = $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE cc = " - . $self->{_astpp_db}->quote($arg{account}) - . " AND status = 1" ); + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); $sql->execute; $accountdata = $sql->fetchrow_hashref; $sql->finish; } if ($accountdata) { - return $accountdata; + return $accountdata; } else { $sql = $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE accountid = " - . $self->{_astpp_db}->quote($arg{account}) - . " AND status = 1" ); + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); $sql->execute; $accountdata = $sql->fetchrow_hashref; $sql->finish; @@ -1101,9 +1306,21 @@ } } -# Return data on specified pricelist +=item $ASTPP->get_pricelist() + +Returns the details on the specified pricelist. Is used both internally and +externally. + +Example: + +$pricelistdata = $ASTPP->get_pricelist( + account => $carddata->{pricelist} +); + +=cut + sub get_pricelist() { - my ($self, %arg) = @_; + my ($self, %arg) = @_; my $tmp = "SELECT * FROM pricelists WHERE name = " . $self->{_astpp_db}->quote($arg{pricelist}); my $sql = $self->{_astpp_db}->prepare($tmp); print STDERR "$tmp\n" . "\n"; @@ -1113,66 +1330,89 @@ return $pricelistdata; } +=item $ASTPP->max_length() +Returns the maximum allowable length for a call. + +Example: + +$max_length = $ASTPP->max_length( + account_pricelist => $carddata->{pricelist}, + account_credit_limit => $carddata->{creditlimit}, + account => $carddata->{number}, + destination => $destination, + call_max_length => $config->{call_max_length}, + max_free_length => $config->{max_free_length} +); + +=cut sub max_length() { - my ($self, %arg) = @_; - my ($branddata, $numdata, $credit, $credit_limit, $maxlength); - $branddata = &get_pricelist($self, pricelist => $arg{account_pricelist} ); # Fetch all the brand info from the db. + my ($self, %arg) = @_; + my ($branddata, $numdata, $credit, $credit_limit, $maxlength); + $branddata = &get_pricelist($self, pricelist => $arg{account_pricelist} ); # Fetch all the brand info from the db. + $numdata = &get_route($self, account => $arg{account}, destination => $arg{destination}, pricelist => $arg{account_pricelist} ); # Find the appropriate rate to charge the customer. - $numdata = &get_route($self, account => $arg{account}, destination => $arg{destination}, pricelist => $arg{account_pricelist} ); # Find the appropriate rate to charge the customer. - - if ( !$numdata->{pattern} ){ # If the pattern doesn't exist, we don't know what to charge the customer - # and therefore must exit. - print STDERR "CALLSTATUS 1\n" if $arg{debug} == 1; - print STDERR "INVALID PHONE NUMBER\n" if $arg{debug} == 1; - return (1,0); - } - print STDERR "Found pattern: $numdata->{pattern}\n"; - $credit = &accountbalance($self, account => $arg{account} ); # Find the available credit to the customer. - print STDERR "Account Balance: " . $credit * 10000; - $credit_limit = $arg{account_credit_limit} * 10000; - print STDERR "Credit Limit: $credit_limit"; - $credit = ($credit * -1) + ($credit_limit); # Add on the accounts credit limit. - #$credit = $credit / $arg{maxchannels} if $arg{maxchannels} > 0; - print STDERR "Credit: $credit \n"; - if ($arg{markup} > 0) { - $numdata->{connectcost} = - $numdata->{connectcost} * ( ( $arg{markup} / 10000 ) + 1 ); - $numdata->{cost} = - $numdata->{cost} * ( ( $arg{markup} / 10000 ) + 1 ); - } - if ( $numdata->{connectcost} > $credit ) { # If our connection fee is higher than the available money we can't connect. - return (0,0); - } - if ( $numdata->{cost} > 0 ) { - $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); - if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ - $maxlength = $arg{call_max_length} / 1000 / 60; - } - } - else { - $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. - } - if ( $numdata->{cost} > 0 ) { - $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); - if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ - $maxlength = $arg{call_max_length} / 1000 / 60; - } - } - else { - $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. - } - return (1, $maxlength,$numdata); + if ( !$numdata->{pattern} ){ # If the pattern doesn't exist, we don't know what to charge the customer + # and therefore must exit. + print STDERR "CALLSTATUS 1\n" if $arg{debug} == 1; + print STDERR "INVALID PHONE NUMBER\n" if $arg{debug} == 1; + return (1,0); + } + print STDERR "Found pattern: $numdata->{pattern}\n"; + $credit = &accountbalance($self, account => $arg{account} ); # Find the available credit to the customer. + print STDERR "Account Balance: " . $credit * 10000; + $credit_limit = $arg{account_credit_limit} * 10000; + print STDERR "Credit Limit: $credit_limit"; + $credit = ($credit * -1) + ($credit_limit); # Add on the accounts credit limit. + #$credit = $credit / $arg{maxchannels} if $arg{maxchannels} > 0; + print STDERR "Credit: $credit \n"; + if ($branddata->{markup} > 0) { + $numdata->{connectcost} = + $numdata->{connectcost} * ( ( $branddata->{markup} / 10000 ) + 1 ); + $numdata->{cost} = + $numdata->{cost} * ( ( $branddata->{markup} / 10000 ) + 1 ); + } + if ( $numdata->{connectcost} > $credit ) { # If our connection fee is higher than the available money we can't connect. + return (0,0); + } + if ( $numdata->{cost} > 0 ) { + $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); + if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ + $maxlength = $arg{call_max_length} / 1000 / 60; + } + } + else { + $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. + } + if ( $numdata->{cost} > 0 ) { + $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); + if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ + $maxlength = $arg{call_max_length} / 1000 / 60; + } + } + else { + $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. + } + return (1, $maxlength,$numdata); } +=item $ASTPP->accountbalance() +Return the balance for a specific ASTPP account. -# Return the balance for a specific ASTPP account. +Example: + +$balance .= $ASTPP->max_length( + account => $carddata->{number}, +); + +=cut + sub accountbalance() { - my ($self, %arg) = @_; + my ($self, %arg) = @_; my ( $tmp, $sql, $row, $debit, $credit, $balance, $posted_balance ); $tmp = - "SELECT SUM(debit) FROM cdrs WHERE cardnum= " + "SELECT SUM(debit) FROM cdrs WHERE cardnum= " . $self->{_astpp_db}->quote($arg{account}) . " AND status NOT IN (1, 2)"; $sql = $self->{_astpp_db}->prepare($tmp); @@ -1181,7 +1421,7 @@ $debit = $row->{"SUM(debit)"}; $sql->finish; $tmp = - "SELECT SUM(credit) FROM cdrs WHERE cardnum= " + "SELECT SUM(credit) FROM cdrs WHERE cardnum= " . $self->{_astpp_db}->quote($arg{account}) . " AND status NOT IN (1, 2)"; $sql = $self->{_astpp_db}->prepare($tmp); @@ -1203,85 +1443,113 @@ return $balance; } -# Return the appropriate "route" to use for determining costing on a call. + +=item $ASTPP->get_route() + +Return the appropriate "route" to use for determining costing on a call. This +is used both in rating as well as in determining the maximum length of a call. + +Example: + +$routeinfo = $ASTPP->get_route( + thirdlane_mods => $config->{thirdlane_mods}, + account => $carddata->{number}, #accountnumber + type => $userfield, # etc,etc + reseller => $carddata->{reseller}, + destination => $destination, #number we care calling + default_brand => $config->{default_brand} +); + +=cut + sub get_route() { my ($self, %arg) = @_; -# TEMPORARY -my $config; -$config->{thirdlane_mods} = 1; -# my ($branddata, $record, $sql, $tmp ); my $carddata = &get_account($self, account => $arg{account}); if ($arg{type} =~ /ASTPP-DID/) { - print STDERR "Call belongs to a DID.\n"; - $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); - $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; - $record->{pattern} = "DID:" . $arg{destination}; - $record->{pricelist} = $arg{pricelist}; - $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + print STDERR "Call belongs to a DID.\n"; + $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); + $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; + $record->{pattern} = "DID:" . $arg{destination}; + $record->{pricelist} = $arg{pricelist}; + $branddata = &get_pricelist($self, pricelist => $carddata->{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; } elsif ($config->{thirdlane_mods} == 1 && $arg{type} =~ m/.\d\d\d-IN/) { - print STDERR "Call belongs to a Thirdlane(tm) DID.\n"; - ($arg{destination} = $arg{type}) =~ s/-IN//g; - print STDERR "Destination: $arg{destination} \n"; - $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); - $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; $record->{pattern} = "DID:" . $arg{destination}; - $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + print STDERR "Call belongs to a Thirdlane(tm) DID.\n"; + ($arg{destination} = $arg{type}) =~ s/-IN//g; + print STDERR "Destination: $arg{destination} \n"; + $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); + $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; $record->{pattern} = "DID:" . $arg{destination}; + $branddata = &get_pricelist($self, pricelist => $carddata->{{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; } else { - my @pricelists = split ( m/,/m, $arg{pricelist} ); - foreach my $pricelistname (@pricelists) { - $pricelistname =~ s/"//g; #Strip off quotation marks - print STDERR "Pricelist: $pricelistname \n"; - $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; - last if $record->{pattern}; #Returnes if we've found a match. - } + my @pricelists = split ( m/,/m, $carddata->{pricelist} ); + foreach my $pricelistname (@pricelists) { + $pricelistname =~ s/"//g; #Strip off quotation marks + print STDERR "Pricelist: $pricelistname \n"; + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + last if $record->{pattern}; #Returnes if we've found a match. + } - while ( !$record->{pattern} && $carddata->{reseller} ) { - $carddata = &get_account($self, account => $carddata->{reseller}); - $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; - } - if (!$record->{pattern}) { #If we still haven't found a match then we modify the dialed number as per the regular expressions set - # in the account. - my @regexs = split(m/","/m, $carddata->{dialed_modify}); - foreach my $regex (@regexs) { - $regex =~ s/"//g; #Strip off quotation marks - my ($grab,$replace) = split(m!/!i, $regex); # This will split the variable into a "grab" and "replace" as needed - print STDERR "Grab: $grab\n"; - print STDERR "Replacement: $replace\n"; - print STDERR "Phone Before: $arg{destination}\n"; - $arg{destination} =~ s/$grab/$replace/is; - print STDERR "Phone After: $arg{destination}\n"; - } - $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; - } - if ( !$record->{pattern} ) { #If we have not found a route yet then we look in the "Default" pricelist. - $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); - print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; - } - print STDERR "Route: $record->{comment} Cost: $record->{cost} Pricelist: $record->{pricelist} Pattern: $record->{pattern}\n" if $record; + while ( !$record->{pattern} && $carddata->{reseller} ) { + $carddata = &get_account($self, account => $carddata->{reseller}); + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + if (!$record->{pattern}) { #If we still haven't found a match then we modify the dialed number as per the regular expressions set + # in the account. + my @regexs = split(m/","/m, $carddata->{dialed_modify}); + foreach my $regex (@regexs) { + $regex =~ s/"//g; #Strip off quotation marks + my ($grab,$replace) = split(m!/!i, $regex); # This will split the variable into a "grab" and "replace" as needed + print STDERR "Grab: $grab\n"; + print STDERR "Replacement: $replace\n"; + print STDERR "Phone Before: $arg{destination}\n"; + $arg{destination} =~ s/$grab/$replace/is; + print STDERR "Phone After: $arg{destination}\n"; + } + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + if ( !$record->{pattern} ) { #If we have not found a route yet then we look in the "Default" pricelist. + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + print STDERR "Route: $record->{comment} Cost: $record->{cost} Pricelist: $record->{pricelist} Pattern: $record->{pattern}\n" if $record; } if ( $record->{inc} eq "" || $record->{inc} == 0 ) { - $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); - $record->{inc} = $branddata->{inc}; + $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); + $record->{inc} = $branddata->{inc}; } return $record; } + +=item $ASTPP->search_for_route() + +Return the exact route. This is used internally and will only very rarely be +used outside of this module. + +Example: + +$routeinfo = $ASTPP->search_for_route( + pricelist => $carddata->{pricelist}, + reseller => $carddata->{reseller} +); + +=cut + sub search_for_route(){ -# my ($astpp_db,$config,$destination,$pricelist) = @_; my ($self, %arg) = @_; - my ($tmp,$sql,$record); + my ($tmp,$sql,$record); $tmp = "SELECT * FROM routes WHERE " - . $self->{_astpp_db}->quote($arg{destination}) - . " RLIKE pattern AND pricelist = " - . $self->{_astpp_db}->quote($arg{pricelist}) - . " ORDER BY LENGTH(pattern) DESC"; + . $self->{_astpp_db}->quote($arg{destination}) + . " RLIKE pattern AND pricelist = " + . $self->{_astpp_db}->quote($arg{pricelist}) + . " ORDER BY LENGTH(pattern) DESC"; print STDERR "$tmp\n"; $sql = $self->{_astpp_db}->prepare($tmp); @@ -1291,47 +1559,14 @@ return $record; }; +1; - -# Preloaded methods go here. - -1; __END__ -# Below is stub documentation for your module. You'd better edit it! -=head1 NAME - -ASTPP - Perl extension for ASTPP (www.astpp.org) - -=head1 SYNOPSIS - - use ASTPP; - -=head1 DESCRIPTION - -Stub documentation for ASTPP, created by h2xs. It looks like the -author of the extension was negligent enough to leave the stub -unedited. - -Blah blah blah. - -=head2 EXPORT - -None by default. - - - =head1 SEE ALSO -Mention other useful documentation such as the documentation of -related modules or operating system documentation (such as man pages -in UNIX), or any relevant external documentation such as RFCs or -standards. +For more information visit our website at (www.astpp.org) -If you have a mailing list set up for your module, mention it here. - -If you have a web site set up for your module, mention it here. - =head1 AUTHOR Darren Wiebe, E<lt>da...@al...E<gt> @@ -1340,9 +1575,6 @@ Copyrig... [truncated message content] |
From: <dar...@us...> - 2009-10-02 20:44:33
|
Revision: 2271 http://astpp.svn.sourceforge.net/astpp/?rev=2271&view=rev Author: darrenkw Date: 2009-10-02 20:44:18 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Copy a bunch of code into the module. This is required to get it working under mod_perl. Modified Paths: -------------- trunk/modules/ASTPP/lib/ASTPP.pm Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-02 20:43:15 UTC (rev 2270) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-02 20:44:18 UTC (rev 2271) @@ -5,7 +5,12 @@ use warnings; use DBI; use Data::Paginate; +use Locale::gettext_pp qw(:locale_h); +bindtextdomain( "astpp", "/usr/local/share/locale" ); +textdomain("astpp"); + + require Exporter; our @ISA = qw(Exporter); @@ -83,6 +88,47 @@ # $self->{_config} = %config_hash if %config_hash; #} +sub load_config +{ + my ($self, %arg) = @_; + my $config; + open( CONFIG, "</var/lib/astpp/astpp-config.conf" ); + while (<CONFIG>) { + chomp; # no newline + s/#.*//; # no comments + s/^\s+//; # no leading white + s/\s+$//; # no trailing white + next unless length; # anything left? + my ( $var, $value ) = split( /\s*=\s*/, $_, 2 ); + $config->{$var} = $value; + } + close(CONFIG); + return $config; +} + +sub connect_db +{ + my ($self, %arg) = @_; + my ( $dbh, $dsn ); + if ( $arg{dbengine} eq "MySQL" ) { + $dsn = "DBI:mysql:database=$arg{dbname};host=$arg{dbhost}"; + } + elsif ( $arg{dbengine} eq "Pgsql" ) { + $dsn = "DBI:Pg:database=$arg{dbname};host=$arg{dbhost}"; + } + $dbh = DBI->connect( $dsn, $arg{dbuser}, $arg{dbpass} ); + if ( !$dbh ) { + print STDERR "ASTPP DATABASE IS DOWN\n"; + return 0; + } + else { + $dbh->{mysql_auto_reconnect} = 1; + print STDERR gettext("Connected to ASTPP Database!") . "\n"; + return $dbh; + } +} + + sub ip_address_authenticate #Authenticates call by caller ip address. Works with both Asterisk(tm) and Freeswitch(tm) # Requires # ip_address = IP Address of calling device @@ -972,8 +1018,281 @@ } } +sub get_did +{ + my ($self, %arg) = @_; + my ( $tmp, $sql, $diddata ); + if (!$arg{reseller} || $arg{reseller} eq "") { + $tmp = "SELECT * FROM dids WHERE number = " + . $self->{_astpp_db}->quote($arg{did}); + } else { + $tmp = + "SELECT dids.number AS number, " + . "reseller_pricing.monthlycost AS monthlycost, " + . "reseller_pricing.prorate AS prorate, " + . "reseller_pricing.setup AS setup, " + . "reseller_pricing.cost AS cost, " + . "reseller_pricing.connectcost AS connectcost, " + . "reseller_pricing.includedseconds AS includedseconds, " + . "reseller_pricing.inc AS inc, " + . "reseller_pricing.disconnectionfee AS disconnectionfee, " + . "dids.provider AS provider, " + . "dids.country AS country, " + . "dids.city AS city, " + . "dids.province AS province, " + . "dids.extensions AS extensions, " + . "dids.account AS account, " + . "dids.variables AS variables, " + . "dids.options AS options, " + . "dids.maxchannels AS maxchannels, " + . "dids.chargeonallocation AS chargeonallocation, " + . "dids.allocation_bill_status AS allocation_bill_status, " + . "dids.limittime AS limittime, " + . "dids.dial_as AS dial_as, " + . "dids.status AS status " + . "FROM dids, reseller_pricing " + . "WHERE dids.number = " . $self->{_astpp_db}->quote($arg{did}) + . " AND reseller_pricing.type = '1' AND reseller_pricing.reseller = " + . $self->{_astpp_db}->quote($arg{reseller}) . " AND reseller_pricing.note = " + . $self->{_astpp_db}->quote($arg{did}); + } + print STDERR "$tmp\n"; + $sql = + $self->{_astpp_db}->prepare($tmp); + $sql->execute; + $diddata = $sql->fetchrow_hashref; + $sql->finish; + return $diddata; +} +sub get_account() { + my ($self, %arg) = @_; + my ( $sql, $accountdata ); + $sql = + $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE number = " + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); + $sql->execute; + $accountdata = $sql->fetchrow_hashref; + $sql->finish; + if ($accountdata) { + return $accountdata; + } else { + $sql = + $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE cc = " + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); + $sql->execute; + $accountdata = $sql->fetchrow_hashref; + $sql->finish; + } + if ($accountdata) { + return $accountdata; + } else { + $sql = + $self->{_astpp_db}->prepare( "SELECT * FROM accounts WHERE accountid = " + . $self->{_astpp_db}->quote($arg{account}) + . " AND status = 1" ); + $sql->execute; + $accountdata = $sql->fetchrow_hashref; + $sql->finish; + return $accountdata; + } +} + +# Return data on specified pricelist +sub get_pricelist() { + my ($self, %arg) = @_; + my $tmp = "SELECT * FROM pricelists WHERE name = " . $self->{_astpp_db}->quote($arg{pricelist}); + my $sql = $self->{_astpp_db}->prepare($tmp); + print STDERR "$tmp\n" . "\n"; + $sql->execute; + my $pricelistdata = $sql->fetchrow_hashref; + $sql->finish; + return $pricelistdata; +} + + +sub max_length() { + my ($self, %arg) = @_; + my ($branddata, $numdata, $credit, $credit_limit, $maxlength); + $branddata = &get_pricelist($self, pricelist => $arg{account_pricelist} ); # Fetch all the brand info from the db. + + $numdata = &get_route($self, account => $arg{account}, destination => $arg{destination}, pricelist => $arg{account_pricelist} ); # Find the appropriate rate to charge the customer. + + if ( !$numdata->{pattern} ){ # If the pattern doesn't exist, we don't know what to charge the customer + # and therefore must exit. + print STDERR "CALLSTATUS 1\n" if $arg{debug} == 1; + print STDERR "INVALID PHONE NUMBER\n" if $arg{debug} == 1; + return (1,0); + } + print STDERR "Found pattern: $numdata->{pattern}\n"; + $credit = &accountbalance($self, account => $arg{account} ); # Find the available credit to the customer. + print STDERR "Account Balance: " . $credit * 10000; + $credit_limit = $arg{account_credit_limit} * 10000; + print STDERR "Credit Limit: $credit_limit"; + $credit = ($credit * -1) + ($credit_limit); # Add on the accounts credit limit. + #$credit = $credit / $arg{maxchannels} if $arg{maxchannels} > 0; + print STDERR "Credit: $credit \n"; + if ($arg{markup} > 0) { + $numdata->{connectcost} = + $numdata->{connectcost} * ( ( $arg{markup} / 10000 ) + 1 ); + $numdata->{cost} = + $numdata->{cost} * ( ( $arg{markup} / 10000 ) + 1 ); + } + if ( $numdata->{connectcost} > $credit ) { # If our connection fee is higher than the available money we can't connect. + return (0,0); + } + if ( $numdata->{cost} > 0 ) { + $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); + if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ + $maxlength = $arg{call_max_length} / 1000 / 60; + } + } + else { + $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. + } + if ( $numdata->{cost} > 0 ) { + $maxlength = ( ( $credit - $numdata->{connectcost} ) / $numdata->{cost} ); + if ($arg{call_max_length} && $maxlength < $arg{call_max_length} / 1000){ + $maxlength = $arg{call_max_length} / 1000 / 60; + } + } + else { + $maxlength = $arg{max_free_length}; # If the call is set to be free then assign a max length. + } + return (1, $maxlength,$numdata); +} + + + +# Return the balance for a specific ASTPP account. +sub accountbalance() { + my ($self, %arg) = @_; + my ( $tmp, $sql, $row, $debit, $credit, $balance, $posted_balance ); + $tmp = + "SELECT SUM(debit) FROM cdrs WHERE cardnum= " + . $self->{_astpp_db}->quote($arg{account}) + . " AND status NOT IN (1, 2)"; + $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + $row = $sql->fetchrow_hashref; + $debit = $row->{"SUM(debit)"}; + $sql->finish; + $tmp = + "SELECT SUM(credit) FROM cdrs WHERE cardnum= " + . $self->{_astpp_db}->quote($arg{account}) + . " AND status NOT IN (1, 2)"; + $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + $row = $sql->fetchrow_hashref; + $credit = $row->{"SUM(credit)"}; + $sql->finish; + $tmp = + "SELECT * FROM accounts WHERE number = " . $self->{_astpp_db}->quote($arg{account}); + $sql = $self->{_astpp_db}->prepare($tmp); + $sql->execute; + $row = $sql->fetchrow_hashref; + $posted_balance = $row->{balance}; + $sql->finish; + if ( !$credit ) { $credit = 0; } + if ( !$debit ) { $debit = 0; } + if ( !$posted_balance ) { $posted_balance = 0; } + $balance = ( $debit - $credit + $posted_balance ); + return $balance; +} + +# Return the appropriate "route" to use for determining costing on a call. +sub get_route() { + my ($self, %arg) = @_; +# TEMPORARY +my $config; +$config->{thirdlane_mods} = 1; +# + my ($branddata, $record, $sql, $tmp ); + my $carddata = &get_account($self, account => $arg{account}); + if ($arg{type} =~ /ASTPP-DID/) { + print STDERR "Call belongs to a DID.\n"; + $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); + $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; + $record->{pattern} = "DID:" . $arg{destination}; + $record->{pricelist} = $arg{pricelist}; + $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + elsif ($config->{thirdlane_mods} == 1 && $arg{type} =~ m/.\d\d\d-IN/) { + print STDERR "Call belongs to a Thirdlane(tm) DID.\n"; + ($arg{destination} = $arg{type}) =~ s/-IN//g; + print STDERR "Destination: $arg{destination} \n"; + $record = &get_did( reseller => $arg{reseller}, did => $arg{destination}); + $record->{comment} = $record->{city} . "," . $record->{province} . "," . $record->{country}; $record->{pattern} = "DID:" . $arg{destination}; + $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + else { + my @pricelists = split ( m/,/m, $arg{pricelist} ); + foreach my $pricelistname (@pricelists) { + $pricelistname =~ s/"//g; #Strip off quotation marks + print STDERR "Pricelist: $pricelistname \n"; + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + last if $record->{pattern}; #Returnes if we've found a match. + } + + while ( !$record->{pattern} && $carddata->{reseller} ) { + $carddata = &get_account($self, account => $carddata->{reseller}); + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{pricelist}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + if (!$record->{pattern}) { #If we still haven't found a match then we modify the dialed number as per the regular expressions set + # in the account. + my @regexs = split(m/","/m, $carddata->{dialed_modify}); + foreach my $regex (@regexs) { + $regex =~ s/"//g; #Strip off quotation marks + my ($grab,$replace) = split(m!/!i, $regex); # This will split the variable into a "grab" and "replace" as needed + print STDERR "Grab: $grab\n"; + print STDERR "Replacement: $replace\n"; + print STDERR "Phone Before: $arg{destination}\n"; + $arg{destination} =~ s/$grab/$replace/is; + print STDERR "Phone After: $arg{destination}\n"; + } + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + if ( !$record->{pattern} ) { #If we have not found a route yet then we look in the "Default" pricelist. + $record = &search_for_route($self, destination => $arg{destination}, pricelist => $arg{default_brand}); + print STDERR "pattern: $record->{pattern}\n" if $record->{pattern}; + } + print STDERR "Route: $record->{comment} Cost: $record->{cost} Pricelist: $record->{pricelist} Pattern: $record->{pattern}\n" if $record; + } + if ( $record->{inc} eq "" || $record->{inc} == 0 ) { + $branddata = &get_pricelist($self, pricelist => $arg{pricelist}); + $record->{inc} = $branddata->{inc}; + } + return $record; +} + +sub search_for_route(){ +# my ($astpp_db,$config,$destination,$pricelist) = @_; + my ($self, %arg) = @_; + my ($tmp,$sql,$record); + $tmp = "SELECT * FROM routes WHERE " + . $self->{_astpp_db}->quote($arg{destination}) + . " RLIKE pattern AND pricelist = " + . $self->{_astpp_db}->quote($arg{pricelist}) + . " ORDER BY LENGTH(pattern) DESC"; + print STDERR "$tmp\n"; + $sql = + $self->{_astpp_db}->prepare($tmp); + $sql->execute; + $record = $sql->fetchrow_hashref; + $sql->finish; + return $record; +}; + + + # Preloaded methods go here. 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-02 20:43:22
|
Revision: 2270 http://astpp.svn.sourceforge.net/astpp/?rev=2270&view=rev Author: darrenkw Date: 2009-10-02 20:43:15 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Add temporary file. Added Paths: ----------- trunk/freeswitch/astpp-fs-xml.pl.mod_perl Added: trunk/freeswitch/astpp-fs-xml.pl.mod_perl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl.mod_perl (rev 0) +++ trunk/freeswitch/astpp-fs-xml.pl.mod_perl 2009-10-02 20:43:15 UTC (rev 2270) @@ -0,0 +1,334 @@ +#!/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 strict; +use lib qw(.); + +use vars + qw($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 = $ASTPP->load_config(); + $astpp_db = $ASTPP->connect_db( + dbengine => $config->{astpp_dbengine}, + dbname => $config->{dbname}, + dbhost => $config->{dbhost}, + dbuser => $config->{dbuser}, + dbpass => $config->{dbpass} + ); + $ASTPP->set_astpp_db($astpp_db); + $config = &load_config_db( $astpp_db, $config ) if $astpp_db; + $freeswitch_db = $ASTPP->connect_db( + dbengine => "MySQL", + dbname => $config->{freeswitch_dbname}, + dbhost => $config->{freeswitch_dbhost}, + dbuser => $config->{freeswitch_dbuser}, + dbpass => $config->{freeswitch_dbpass} + ); + $ASTPP->set_freeswitch_db($freeswitch_db); +} + +################# Programs start here ####################################### +&initialize; +my ( $ipinfo, $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); +foreach my $param ( param() ) { + $params->{$param} = param($param); + $ASTPP->debug( debug => "$param $params->{$param}" ); +} +$xml = header( -type => 'text/plain' ); + +$ASTPP->debug( + debug => "Destination = $params->{'Caller-Destination-Number'}" ); + +if ( $params->{section} eq "dialplan" ) { + # Check to see if this is a DID. If it is we handle it differently. + # + $didinfo = $ASTPP->get_did( did => $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 + # as authentications + $ASTPP->debug( debug => "Checking CC Number: " + . $params->{'Caller-Destination-Number'} ); + my $cc = substr( $params->{'Caller-Destination-Number'}, + 0, $config->{cardlength} ); + my $sql = + $astpp_db->prepare("SELECT number FROM accounts WHERE cc = $cc"); + $sql->execute; + my $record = $sql->fetchrow_hashref; + $sql->finish; + $params->{variable_accountcode} = $record->{cardnum} + if ( $record->{cardnum} ); + } + if ( !$params->{variable_accountcode} ) { + $ASTPP->debug( + debug => "Checking IP Address:" . $params->{'Hunt-Network-Addr'} ); + $ipinfo = $ASTPP->ip_address_authenticate( + ip_address => $params->{'Hunt-Network-Addr'}, + destination => $params->{'Caller-Destination-Number'} + ); + if ($ipinfo->{account} ne "") { + $params->{variable_accountcode} = $ipinfo->{account}; + $params->{'Caller-Destination-Number'} =~ s/$ipinfo->{prefix}//g; + } + } + + $xml = $ASTPP->fs_dialplan_xml_header( + xml => $xml, + destination_number => $params->{'Caller-Destination-Number'}, + DID => $didinfo->{number}, + IP => $ipinfo->{account} + ); + + $ASTPP->debug( debug => +"$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}" + ); + + my $carddata = $ASTPP->get_account(account => $params->{variable_accountcode}); + + if ( !$carddata->{number} ) + { # Check to see if the account exists. If not then exit. + $ASTPP->debug( debug => "CALLSTATUS 2" ); + $ASTPP->debug( debug => "CANNOT RETRIEVE CARD" ); + $xml .= + "<action application=\"reject\" data=\"CANNOT RETRIEVE ACCOUNT\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); +# print $xml; + $ASTPP->debug( debug => "Returning nothing so dialplan can continue." ); + print ""; + exit(0); + } + + if ( $carddata->{dialed_modify} ) { + my @regexs = split( m/,/m, $carddata->{dialed_modify} ); + foreach my $regex (@regexs) { + $regex =~ s/"//g; #Strip off quotation marks + my ( $grab, $replace ) = split( m!/!i, $regex ) + ; # This will split the variable into a "grab" and "replace" as needed + $ASTPP->debug( debug => "Grab: $grab" ); + $ASTPP->debug( debug => "Replacement: $replace" ); + $ASTPP->debug( debug => + "Phone Before: $params->{'Caller-Destination-Number'}" ); + $$params->{'Caller-Destination-Number'} =~ s/$grab/$replace/is; + $ASTPP->debug( debug => + "Phone After: $params->{'Caller-Destination-Number'}" ); + } + } + + $ASTPP->debug( debug => "FINDING LIMIT FOR: " . $carddata->{number} ); + my $pricelistdata = $ASTPP->get_pricelist( + pricelist => $carddata->{pricelist}); + my $routeinfo; + ( $callstatus, $maxlength, $routeinfo ) = $ASTPP->max_length( + destination => $params->{'Caller-Destination-Number'}, + call_max_length => $config->{call_max_length}, + max_free_length => $config->{max_free_length}, + markup => $pricelistdata->{markup}, + account => $carddata->{number}, + account_creditlimit => $carddata->{credit_limit}, + account_maxchannels => $carddata->{maxchannels}, + debug => $config->{debug}, + account_pricelist => $carddata->{pricelist}, + account_reseller => $carddata->{reseller}, + default_brand => $config->{default_brand}, + + ); +# &max_length( $astpp_db, $config, $carddata, +# $params->{'Caller-Destination-Number'} ); + +# my $routeinfo = &get_route( +# $astpp_db, $config, +# $params->{'Caller-Destination-Number'}, +# $carddata->{pricelist}, $carddata,$astppdid +# ); + + $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" ); + + if (!$routeinfo->{cost} && !$routeinfo->{pricelist}) { + $ASTPP->debug( debug => "COULD NOT FIND ROUTE. EXITING SO DIALPLAN CAN TAKE OVER" ); + exit(0); + } + while ( $carddata->{reseller} && $maxlength > 1 && $callstatus == 1 ) { + $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}" ); + $carddata = &get_account( $astpp_db, $carddata->{reseller} ); + push @reseller_list, $carddata->{number}; + $ASTPP->debug( debug => +"ADDING $carddata->{number} to the list of resellers for this account" + ); + my ( $resellercallstatus, $resellermaxlength ) = + &max_length( $astpp_db, $config, $carddata, + $params->{'Caller-Destination-Number'} ); + my $routeinfo = &get_route( + $astpp_db, $config, + $params->{'Caller-Destination-Number'}, + $carddata->{pricelist}, $carddata + ); + if ( $resellercallstatus != 1 ) { + $carddata->{reseller} = ""; + $callstatus = $resellercallstatus; + } + elsif ( $resellermaxlength < $maxlength ) { + $maxlength = $resellermaxlength; + } + $ASTPP->debug( debug => +"Reseller cost = $routeinfo->{cost} and minimum charge is $minimumcharge" + ); + if ( $resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) { + $ASTPP->debug( debug => + "Reseller call is priced too cheap! Call being barred!" ); + $xml .= +"<action application=\"reject\" data=\"Reseller call is priced too cheap! Call being barred!\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + print $xml; + exit(0); + } + $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength" ); + $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus" ); + } + + if ( $config->{debug} == 1 ) { + $ASTPP->debug( debug => "PRINTING LIST OF RESELLERS FOR THIS ACCOUNT" ); + foreach my $reseller (@reseller_list) { + $ASTPP->debugb( debug => "RESELLER: $reseller" ); + } + } + + $ASTPP->debug("Max Call Length: $maxlength minutes"); + $ASTPP->debug("Call Status: $callstatus"); + + if ( $maxlength <= 1 ) { + $ASTPP->debug( debug => "NOT ENOUGH CREDIT" ); + $xml .= "<action application=\"reject\" data=\"NOT ENOUGH CREDIT\"/>\n"; + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + print $xml; + exit(0); + } elsif ($config->{call_max_length} && $maxlength < $config->{call_max_length} / 1000){ + $maxlength = $config->{call_max_length} / 1000; + } + + $xml = $ASTPP->fs_dialplan_xml_timelimit( + xml => $xml, + max_length => $maxlength, + accountcode => $carddata->{number} + ); + +# Set the timelimit as well as other variables which are needed in the dialplan. + my $timelimit = + "L(" . sprintf( "%.0f", $maxlength * 60 * 1000 ) . ":60000:30000)"; + + $ASTPP->debug( debug => "Looking for outbound Route" ); + my $routeinfo = &get_route( + $astpp_db, $config, + $params->{'Caller-Destination-Number'}, + $carddata->{pricelist}, $carddata, $astppdid + ); + + if ($didinfo->{number} ) { + $ASTPP->debug( debug => "THIS IS A DID CALL: $xml"); + my ($returned_data) = $ASTPP->fs_dialplan_xml_did( + did => $params->{'Caller-Destination-Number'} + ); + $xml .= $returned_data; + } else { + # Get the list of routes for the phone number. + my @outboundroutes = + &get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'}, + $carddata, $routeinfo, @reseller_list ); + foreach my $route (@outboundroutes) { + $ASTPP->debug( debug => + "$route->{trunk}: cost $route->{cost}\t $route->{pattern}" ); + if ( $route->{cost} > $routeinfo->{cost} ) { + $ASTPP->debug( debug => +"$route->{trunk}: $route->{cost} > $routeinfo->{cost}, skipping" + ); + } + else { + my ($returned_data,$junk) = $ASTPP->fs_dialplan_xml_bridge( + destination_number => $params->{'Caller-Destination-Number'}, + route_prepend => $route->{prepend}, + trunk_name => $route->{trunk}, + route_id => $route->{id} + ); + $xml .= $returned_data; + } + } + } + $xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml ); + $ASTPP->debug( debug => $xml ); + print $xml; +} +elsif ( $params->{section} eq "directory" ) { + + #hostname darren-laptop + #section directory + #tag_name domain + #key_name name + #key_value 192.168.2.119 + #action sip_auth + #sip_profile internal + #sip_user_agent Zoiper rev.1118 + #sip_auth_username 1000 + #sip_auth_realm 192.168.2.119 + #sip_auth_nonce 83005e62-7e13-11dd-9eb1-25560b0691a8 + #sip_auth_uri sip:192.168.2.119;transport=UDP + #sip_auth_qop auth + #sip_auth_cnonce a79169d2656f292a + #sip_auth_nc 00000001 + #sip_auth_response 4475154556879ec2017978f1347192a6 + #sip_auth_method REGISTER + #key id + #user 1000 + #domain 192.168.2.119 + #ip 192.168.2.119 + + if ($params->{'user'}) { + $xml = $ASTPP->fs_directory_xml_header( xml => $xml ); + $xml = $ASTPP->fs_directory_xml( + xml => $xml, + ip => $params->{'ip'}, + user => $params->{'user'}, + domain => $params->{'domain'} + ); + $xml = $ASTPP->fs_directory_xml_footer( xml => $xml ); + } + $ASTPP->debug( debug => $xml ); + print $xml; +} +exit(0); Property changes on: trunk/freeswitch/astpp-fs-xml.pl.mod_perl ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-02 18:51:18
|
Revision: 2269 http://astpp.svn.sourceforge.net/astpp/?rev=2269&view=rev Author: darrenkw Date: 2009-10-02 18:32:24 +0000 (Fri, 02 Oct 2009) Log Message: ----------- There was an error in the available credit calculations resulting in calls being refused. Modified Paths: -------------- trunk/scripts/astpp-common.pl Modified: trunk/scripts/astpp-common.pl =================================================================== --- trunk/scripts/astpp-common.pl 2009-10-02 16:22:27 UTC (rev 2268) +++ trunk/scripts/astpp-common.pl 2009-10-02 18:32:24 UTC (rev 2269) @@ -3750,11 +3750,12 @@ } print STDERR "Found pattern: $numdata->{pattern}\n" if $config->{debug} == 1; $credit = &accountbalance( $astpp_db, $carddata->{number} ); # Find the available credit to the customer. - print STDERR "Account Balance: $credit" if $config->{debug} == 1; - $credit_limit = $carddata->{credit_limit}; + print STDERR "Account Balance: " . $credit * 10000 if $config->{debug} == 1; + $credit_limit = $carddata->{credit_limit} * 10000; print STDERR "Credit Limit: $credit_limit" if $config->{debug} == 1; - $credit = ($credit * -1) + ($carddata->{credit_limit}); # Add on the accounts credit limit. + $credit = ($credit * -1) + ($credit_limit); # Add on the accounts credit limit. #$credit = $credit / $carddata->{maxchannels} if $carddata->{maxchannels} > 0; + print STDERR "Credit: $credit \n" if $config->{debug} == 1; if ($branddata->{markup} > 0) { $numdata->{connectcost} = $numdata->{connectcost} * ( ( $branddata->{markup} / 10000 ) + 1 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-02 16:38:19
|
Revision: 2268 http://astpp.svn.sourceforge.net/astpp/?rev=2268&view=rev Author: darrenkw Date: 2009-10-02 16:22:27 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Resolved a problem with authenticating calls by IP address as well as with rating calls with no increment set. Modified Paths: -------------- trunk/freeswitch/astpp-fs-xml.pl trunk/modules/ASTPP/lib/ASTPP.pm trunk/scripts/astpp-common.pl Modified: trunk/freeswitch/astpp-fs-xml.pl =================================================================== --- trunk/freeswitch/astpp-fs-xml.pl 2009-10-01 04:43:47 UTC (rev 2267) +++ trunk/freeswitch/astpp-fs-xml.pl 2009-10-02 16:22:27 UTC (rev 2268) @@ -42,7 +42,7 @@ ################# Programs start here ####################################### &initialize; -my ( $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); +my ( $ipinfo, $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo ); foreach my $param ( param() ) { $params->{$param} = param($param); $ASTPP->debug( debug => "$param $params->{$param}" ); @@ -62,11 +62,6 @@ $params->{variable_accountcode} = $didinfo->{account}; } - $xml = $ASTPP->fs_dialplan_xml_header( - xml => $xml, - destination_number => $params->{'Caller-Destination-Number'}, - DID => $didinfo->{number} - ); if ( !$params->{variable_accountcode} ) { @@ -87,16 +82,23 @@ if ( !$params->{variable_accountcode} ) { $ASTPP->debug( debug => "Checking IP Address:" . $params->{'Hunt-Network-Addr'} ); - my $ip_data = $ASTPP->ip_address_authenticate( + $ipinfo = $ASTPP->ip_address_authenticate( ip_address => $params->{'Hunt-Network-Addr'}, destination => $params->{'Caller-Destination-Number'} ); - if ($ip_data) { - $params->{variable_accountcode} = $ip_data->{account}; - $params->{'Caller-Destination-Number'} =~ s/$ip_data->{prefix}//g; + if ($ipinfo->{account} ne "") { + $params->{variable_accountcode} = $ipinfo->{account}; + $params->{'Caller-Destination-Number'} =~ s/$ipinfo->{prefix}//g; } } + $xml = $ASTPP->fs_dialplan_xml_header( + xml => $xml, + destination_number => $params->{'Caller-Destination-Number'}, + DID => $didinfo->{number}, + IP => $ipinfo->{account} + ); + $ASTPP->debug( debug => "$params->{variable_accountcode}, $params->{'Caller-Destination-Number'}" ); Modified: trunk/modules/ASTPP/lib/ASTPP.pm =================================================================== --- trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-01 04:43:47 UTC (rev 2267) +++ trunk/modules/ASTPP/lib/ASTPP.pm 2009-10-02 16:22:27 UTC (rev 2268) @@ -111,9 +111,11 @@ $arg{xml} .= "<document type=\"freeswitch/xml\">\n"; $arg{xml} .= "<section name=\"dialplan\" description=\"ASTPP Dynamic Routing\">\n"; if ($arg{DID} > 0) { - $arg{xml} .= "<context name=\"public\">\n"; + $arg{xml} .= "<context name=\"public\">\n"; + } elsif ($arg{IP} ne "") { + $arg{xml} .= "<context name=\"public\">\n"; } else { - $arg{xml} .= "<context name=\"default\">\n"; + $arg{xml} .= "<context name=\"default\">\n"; }; $arg{xml} .= "<extension name=\"" . $arg{destination_number} . "\">\n"; $arg{xml} .= "<condition field=\"destination_number\" expression=\"" . $arg{destination_number} . "\">\n"; Modified: trunk/scripts/astpp-common.pl =================================================================== --- trunk/scripts/astpp-common.pl 2009-10-01 04:43:47 UTC (rev 2267) +++ trunk/scripts/astpp-common.pl 2009-10-02 16:22:27 UTC (rev 2268) @@ -1109,6 +1109,9 @@ my ( $connect, $cost, $answeredtime, $increment, $inc_seconds ) = @_; print STDERR "Connect: $connect Cost: $cost Answered: $answeredtime \n"; print STDERR " Inc: $increment included: $inc_seconds \n"; + if (!$increment || $increment == 0) { + $increment = 1; + } if ($answeredtime > 0) { my ($total_seconds); $total_seconds = ( $answeredtime - $inc_seconds ) / $increment if $inc_seconds; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-01 04:43:55
|
Revision: 2267 http://astpp.svn.sourceforge.net/astpp/?rev=2267&view=rev Author: darrenkw Date: 2009-10-01 04:43:47 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Committed code to allow viewing invoices in HTML. The html is stored in a template and can easily be modified to suit your requirements. Modified Paths: -------------- trunk/scripts/astpp-common.pl trunk/templates/invoice.tpl trunk/web_interface/astpp-admin.cgi Modified: trunk/scripts/astpp-common.pl =================================================================== --- trunk/scripts/astpp-common.pl 2009-10-01 03:21:35 UTC (rev 2266) +++ trunk/scripts/astpp-common.pl 2009-10-01 04:43:47 UTC (rev 2267) @@ -324,8 +324,22 @@ return $trunkdata; } +sub get_invoice() { + my ( $astpp_db, $invoiceid ) = @_; + my ( $sql, $invoicedata ); + $sql = + $astpp_db->prepare( + "SELECT * FROM invoice_list_view WHERE invoiceid = " . $astpp_db->quote($invoiceid) ); + $sql->execute; + $invoicedata = $sql->fetchrow_hashref; + $sql->finish; + return $invoicedata; +} + # This is used by calling cards as well as lcr. Pass on the phone number as well as the trunk to use. It will return the dialstring # for Asterisk(tm). +# This is used by calling cards as well as lcr. Pass on the phone number as well as the trunk to use. It will return the dialstring +# for Asterisk(tm). sub get_dial_string() { my ( $astpp_db, $route, $phone ) = @_; my ( $sql, $trunkdata, $dialstring ); @@ -1655,8 +1669,20 @@ $sql->execute; $accountdata = $sql->fetchrow_hashref; $sql->finish; + } + if ($accountdata) { + return $accountdata; + } else { + $sql = + $astpp_db->prepare( "SELECT * FROM accounts WHERE accountid = " + . $astpp_db->quote($accountno) + . " AND status = 1" ); + $sql->execute; + $accountdata = $sql->fetchrow_hashref; + $sql->finish; return $accountdata; } + } @@ -1681,8 +1707,20 @@ $sql->execute; $accountdata = $sql->fetchrow_hashref; $sql->finish; + } + if ($accountdata) { + return $accountdata; + } else { + $sql = + $astpp_db->prepare( "SELECT * FROM accounts WHERE accountid = " + . $astpp_db->quote($accountno) + . " AND status = 1" ); + $sql->execute; + $accountdata = $sql->fetchrow_hashref; + $sql->finish; return $accountdata; } + } # Go looking for account by CC number. Modified: trunk/templates/invoice.tpl =================================================================== --- trunk/templates/invoice.tpl 2009-10-01 03:21:35 UTC (rev 2266) +++ trunk/templates/invoice.tpl 2009-10-01 04:43:47 UTC (rev 2267) @@ -1,14 +1,76 @@ +<div align="center"> + <table width="100%" border="0"> + <tr> + <td width="50%">VOIP Wholesale Company</td> + <td><div align="right">www.astpp.org</div></td> + </tr> + <tr> + <td width="50%">123 Street</td> + <td><div align="right">(800) 555-1212</div></td> + </tr> + <tr> + <td width="50%">City, Province</td> + <td><div align="right">su...@as...</div></td> + </tr> + <tr> + <td width="50%">Canada</td> + <td><div align="right"></div></td> + </tr> + </table> + <hr /> + <p>I N V O I C E +</p> +</div> - -<table class="default"> +<div align="left"> +<table border="0"> +<tr><td> +To: +</td></tr> +<tr><td> +<TMPL_VAR NAME="firstname"> <TMPL_VAR NAME="lastname"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="company_name"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="address_1"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="address_2"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="address_3"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="city">, <TMPL_VAR NAME="province"> <TMPL_VAR NAME="postal_code"> +</td></tr> +<tr><td> +<TMPL_VAR NAME="country"></pre> +</td></tr> +</table> +</div> +<table width="100%" border="1" cellspacing="0"> + <tr> + <td width="33.3%"><div align="center">Account ID</div></td> + <td width="33.3%"><div align="center">Invoice Number</div></td> + <td width="33.3%"><div align="center">Invoice Date</div></td> + </tr> + <tr> + <td><div align="center"><TMPL_VAR NAME="accountid"></div></td> + <td><div align="center"><TMPL_VAR NAME="invoiceid"></div></td> + <td><div align="center"><TMPL_VAR NAME="invoicedate"></div></td> + </tr> +</table> +<p> </p> +<table width="100%" class="default"> <tr class="header"> - <td>Date & Time</td> - <td>Caller*ID</td> - <td>Called Number</td> - <td>Disposition</td> - <td>Billable Seconds</td> - <td>Charge</td> - <td>Notes</td> + <td width="20%">Date & Time</td> + <td width="20%">Caller*ID</td> + <td width="20%">Called Number</td> + <td width="20%">Disposition</td> + <td width="10%">Duration</td> + <td width="10%">Charge</td> </tr> <TMPL_LOOP NAME="invoice_cdr_list"> <TR> @@ -17,9 +79,24 @@ <TD><TMPL_VAR NAME="callednum"></TD> <TD><TMPL_VAR NAME="disposition"></TD> <TD><TMPL_VAR NAME="billseconds"></TD> - <TD><TMPL_VAR NAME="charge"></TD> - <TD><TMPL_VAR NAME="notes"></TD> + <TD><div align="right"><TMPL_VAR NAME="charge"></div></TD> </TR> </TMPL_LOOP> </table> - +<br> +<table width="100%" class="default"> + <tr class="header"> + <td width="40%"></td> + <td width="20%">Title</td> + <td width="20%">Text</td> + <td width="20%">Fee</td> + </tr> + <TMPL_LOOP NAME="invoice_total_list"> + <TR> + <TD></td> + <TD><TMPL_VAR NAME="title"></TD> + <TD><TMPL_VAR NAME="text"></TD> + <TD><div align="right"><TMPL_VAR NAME="value"></div></TD> + </TR> + </TMPL_LOOP> +</table> Modified: trunk/web_interface/astpp-admin.cgi =================================================================== --- trunk/web_interface/astpp-admin.cgi 2009-10-01 03:21:35 UTC (rev 2266) +++ trunk/web_interface/astpp-admin.cgi 2009-10-01 04:43:47 UTC (rev 2267) @@ -428,6 +428,8 @@ return &build_view_cdrs() if $params->{mode} eq gettext("View CDRs"); return &build_configuration() if $params->{mode} eq gettext("Configuration"); + return &build_view_invoice() + if $params->{mode} eq gettext("View Invoice"); return &build_add_callshop() if $params->{mode} eq gettext("Create CallShop"); @@ -2394,6 +2396,61 @@ return $status; } +sub build_view_invoice() { + my ($tmp,$sql,$body, $status, @cdr_list,@total_list); + my $template = HTML::Template->new( + filename => '/var/lib/astpp/templates/invoice.tpl', + die_on_bad_params => $config->{template_die_on_bad_params} + ); + return gettext("Database is NOT configured!") . " \n" unless $astpp_db; + return gettext("No Invoice Selected!") . " \n" unless $params->{invoiceid}; + $params->{format} = "html" if !$params->{format}; + + $tmp = "SELECT * FROM cdrs WHERE invoiceid = " + . $astpp_db->quote($params->{invoiceid}); + $sql = $astpp_db->prepare($tmp); + $sql->execute; + + while ( my $cdr = $sql->fetchrow_hashref ) { + $cdr->{charge} = ($cdr->{debit} - $cdr->{credit}) / 10000; + $cdr->{charge} = sprintf( "%." . $config->{decimalpoints} . "f", $cdr->{charge} ); + push( @cdr_list, $cdr ); + } + $template->param( invoice_cdr_list => \@cdr_list ); + + $tmp = "SELECT * FROM invoices_total WHERE invoices_id = " + . $astpp_db->quote($params->{invoiceid}) + . " ORDER BY sort_order"; + $sql = $astpp_db->prepare($tmp); + $sql->execute; + + while ( my $total = $sql->fetchrow_hashref ) { +# $cdr->{charge} = ($cdr->{debit} - $cdr->{credit}) / 10000; +# $cdr->{charge} = sprintf( "%." . $config->{decimalpoints} . "f", $cdr->{charge} ); + push( @total_list, $total ); + } + $template->param( invoice_total_list => \@total_list ); + + my $invoicedata = &get_invoice( $astpp_db, $params->{invoiceid}); + $template->param( invoiceid => $invoicedata->{invoiceid} ); + $template->param( invoicedate => $invoicedata->{date} ); + $template->param( accountid => $invoicedata->{accountid} ); + + my $accountinfo = &get_account_including_closed( $astpp_db, $invoicedata->{accountid} ); + $template->param( first_name => $accountinfo->{first_name} ); + $template->param( last_name => $accountinfo->{last_name} ); + $template->param( company => $accountinfo->{company} ); + $template->param( address_1 => $accountinfo->{address_1} ); + $template->param( address_2 => $accountinfo->{address_2} ); + $template->param( address_3 => $accountinfo->{address_3} ); + $template->param( city => $accountinfo->{city} ); + $template->param( province => $accountinfo->{province} ); + $template->param( country => $accountinfo->{country} ); + $template->param( postal_code => $accountinfo->{postal_code} ); + + return $template->output; +} + sub build_create_account() { my ( @pricelists, $status, $body ); my $template = HTML::Template->new( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dar...@us...> - 2009-10-01 03:21:53
|
Revision: 2266 http://astpp.svn.sourceforge.net/astpp/?rev=2266&view=rev Author: darrenkw Date: 2009-10-01 03:21:35 +0000 (Thu, 01 Oct 2009) Log Message: ----------- Change makefile to point users back to website for docs. Modified Paths: -------------- trunk/Makefile Modified: trunk/Makefile =================================================================== --- trunk/Makefile 2009-10-01 02:57:30 UTC (rev 2265) +++ trunk/Makefile 2009-10-01 03:21:35 UTC (rev 2266) @@ -149,34 +149,7 @@ @echo "------------------------------"; @echo "ASTPP install appears to be successfull."; @echo "------------------------------"; - @echo "It is now time to prepare the database and the inital configuration files."; - @echo "To create the ASTPP database use the following commands as root on your system:"; - @echo "mysqladmin create astpp"; - @echo "This will have created a database called astpp. It's now time to populate that database with the necessary tables."; - @echo "mysql -u root -p astpp < sql/astpp-1.4.sql"; - @echo "You will be prompted for the password."; - @echo ''; - @echo "If you do not currently have a cdr database, please create one by following these commands:"; - @echo "mysqladmin create asteriskcdrdb"; - @echo "mysql -u root -p asteriskcdrdb < sql/asteriskcdrdb.sql"; - @echo "You will be prompted for the password."; - @echo ''; - @echo "If you do not currently have a -realtime database and you want to use -realtime,"; - @echo "please create one by following these commands:"; - @echo "mysqladmin create asterisk"; - @echo "mysql -u root -p asterisk < sql/asterisk-realtime.sql"; - @echo "You will be prompted for the password."; - @echo ''; - @echo "Once these databases have been created please be sure to edit /var/lib/astpp/astpp-config.conf"; - @echo "to update your database connection information. It is also necessary to edit /var/lib/astpp/astpp-enh-config.conf"; - @echo "to change the 'auth' code as well as set more advanced features." - @echo ""; - @echo "'make install' updates all the sample files which have been installed but to overwrite any settings you have in place"; - @echo "If this is the first time you are installing ASTPP you need to perform a 'make samples'. "; - @echo "Be aware that this will overwrite any astpp settings you may have as well as replace"; - @echo "your astpp-dialplan.conf file."; - @echo ""; - @echo "Thank you for using ASTPP! Please visit www.astpp.org for support information."; + @echo "Please visit www.astpp.org for further instructions."; install_all_pre: install_misc install_astpp_exec install_all_post: install_instructions_print 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...> - 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. |