X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=bin%2Faradial-sftp_and_import;h=53357033c78b24057ee1669e6607412c3fa4a8aa;hb=8dfa2f14821acce6f5c89d447ba49b47339a3d36;hp=cc2238e1f4b520615c219dee37b1106fb10230a2;hpb=7de7c267ca9e04b1f057307ac03325c6d37228f2;p=freeside.git diff --git a/bin/aradial-sftp_and_import b/bin/aradial-sftp_and_import index cc2238e1f..53357033c 100755 --- a/bin/aradial-sftp_and_import +++ b/bin/aradial-sftp_and_import @@ -65,7 +65,7 @@ our %status_type = ( ### use vars qw( $opt_m $opt_a $opt_b $opt_r $opt_d $opt_v $opt_P ); -getopts('m:abr:dP:v:'); +getopts('m:abr:d:P:v:'); my %options = (); @@ -127,6 +127,8 @@ else { foreach my $filename ( @$ls ) { + next if $opt_d && $filename eq $opt_d; + warn "Downloading $filename\n" if $opt_v; #get the file @@ -157,6 +159,9 @@ foreach my $filename ( @$ls ) { my @keys = keys %dbhash; + #skip blank records + next unless grep defined($_), values %dbhash; + $hash{'Status-Type'} = $status_type{ $hash{'Status-Type'} } if exists $status_type{ $hash{'Status-Type'} }; @@ -164,14 +169,17 @@ foreach my $filename ( @$ls ) { my @extra_values = (); if ( $hash{'Status-Type'} eq 'Start' ) { + push @keys, 'AcctStartTime'; $dbhash{'AcctStartTime'} = $hash{'Date'}; - $sql = 'INSERT INTO radacct ( ', join(',', @keys). - ' ) VALUES ( '. map( ' ? ', @keys ). ' )'; + $sql = 'INSERT INTO radacct ( '. join(',', @keys). + ' ) VALUES ( '. join(',', map ' ? ', @keys ). ' )'; } elsif ( $hash{'Status-Type'} eq 'Stop' ) { my $AcctSessionId = delete($dbhash{AcctSessionId}); + + push @keys, 'AcctStopTime'; $dbhash{'AcctStopTime'} = $hash{'Date'}; push @extra_values, $AcctSessionId; @@ -194,6 +202,7 @@ foreach my $filename ( @$ls ) { foreach my $value ( map $dbhash{$_}, @keys ) { my $key = shift @keys; my $type = exists($bind_type{$key}) ? $bind_type{$key} : SQL_VARCHAR; + $value ||= 0 if $type == SQL_INTEGER; $sth->bind_param($p_num++, $value, $type); } foreach my $value ( @extra_values ) {