[freeside-commits] branch FREESIDE_3_BRANCH updated. 7de7c267ca9e04b1f057307ac03325c6d37228f2
Ivan
ivan at 420.am
Fri Aug 8 14:54:49 PDT 2014
The branch, FREESIDE_3_BRANCH has been updated
via 7de7c267ca9e04b1f057307ac03325c6d37228f2 (commit)
from 5d9403ca2d6113ba85bbfd3ba1fe09fb9106112d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7de7c267ca9e04b1f057307ac03325c6d37228f2
Author: Ivan Kohler <ivan at freeside.biz>
Date: Fri Aug 8 14:54:48 2014 -0700
aradial usage import: fix integer binding, update statement RT#29053
diff --git a/bin/aradial-sftp_and_import b/bin/aradial-sftp_and_import
index d48e218..cc2238e 100755
--- a/bin/aradial-sftp_and_import
+++ b/bin/aradial-sftp_and_import
@@ -6,7 +6,7 @@ use strict;
use Getopt::Std;
use Date::Format;
use Text::CSV_XS;
-use DBI;
+use DBI qw( :sql_types );
use Net::SFTP::Foreign;
#use FS::UID qw( adminsuidsetup datasrc );
@@ -35,6 +35,14 @@ our %aradial2db = (
'Acct-Terminate-Cause' => 'AcctTerminateCause',
);
+our %bind_type = (
+ 'AcctInputOctets' => SQL_INTEGER,
+ 'AcctOutputOctets' => SQL_INTEGER,
+ 'AcctSessionTime' => SQL_INTEGER,
+ 'AcctStartDelay' => SQL_INTEGER,
+ 'AcctStopDelay' => SQL_INTEGER,
+);
+
#http://www.iana.org/assignments/radius-types/radius-types.xhtml#radius-types-10
our %status_type = (
1 => 'Start',
@@ -148,29 +156,28 @@ foreach my $filename ( @$ls ) {
keys %hash;
my @keys = keys %dbhash;
- my @values = map $dbhash{$_}, @keys;
$hash{'Status-Type'} = $status_type{ $hash{'Status-Type'} }
if exists $status_type{ $hash{'Status-Type'} };
+ my $sql;
+ my @extra_values = ();
if ( $hash{'Status-Type'} eq 'Start' ) {
$dbhash{'AcctStartTime'} = $hash{'Date'};
- my $sql = 'INSERT INTO radacct ( ', join(',', @keys).
- ' ) VALUES ( '. map( ' ? ', @values ). ' )';
- my $sth = $dbh->prepare($sql) or die $dbh->errstr;
- $sth->execute(@values) or die $sth->errstr;
+ $sql = 'INSERT INTO radacct ( ', join(',', @keys).
+ ' ) VALUES ( '. map( ' ? ', @keys ). ' )';
} elsif ( $hash{'Status-Type'} eq 'Stop' ) {
my $AcctSessionId = delete($dbhash{AcctSessionId});
$dbhash{'AcctStopTime'} = $hash{'Date'};
- my $sql = 'UPDATE radacct '. join(' , ', map "SET $_ = ?", @keys ).
- ' WHERE AcctSessionId = ? ';
- my $sth = $dbh->prepare($sql) or die $dbh->errstr;
- $sth->execute(@values, $AcctSessionId) or die $sth->errstr;
+ push @extra_values, $AcctSessionId;
+
+ $sql = 'UPDATE radacct SET '. join(',', map "$_ = ?", @keys ).
+ ' WHERE AcctSessionId = ? ';
} elsif ( $hash{'Status-Type'} eq 'Interim' ) {
#not handled, but stop should capture the usage. unless session are
@@ -178,7 +185,22 @@ foreach my $filename ( @$ls ) {
# real-time-ish data usage detail, it isn't a big deal
} else {
warn 'Unknown Status-Type '. $hash{'Status-Type'}. "; skipping\n";
+ next;
+ }
+
+ my $sth = $dbh->prepare($sql) or die $dbh->errstr;
+
+ my $p_num = 1;
+ foreach my $value ( map $dbhash{$_}, @keys ) {
+ my $key = shift @keys;
+ my $type = exists($bind_type{$key}) ? $bind_type{$key} : SQL_VARCHAR;
+ $sth->bind_param($p_num++, $value, $type);
}
+ foreach my $value ( @extra_values ) {
+ $sth->bind_param($p_num++, $value);
+ }
+
+ $sth->execute or die $sth->errstr;
}
-----------------------------------------------------------------------
Summary of changes:
bin/aradial-sftp_and_import | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
More information about the freeside-commits
mailing list