[freeside-commits] freeside/FS/FS/part_export sqlradius.pm, 1.21,
1.22
Jeff Finucane,420,,
jeff at wavetail.420.am
Wed Nov 29 18:27:57 PST 2006
Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail:/tmp/cvs-serv12489/FS/FS/part_export
Modified Files:
sqlradius.pm
Log Message:
prepaid download/upload tracking
Index: sqlradius.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/sqlradius.pm,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- sqlradius.pm 31 Oct 2006 18:56:32 -0000 1.21
+++ sqlradius.pm 30 Nov 2006 02:27:55 -0000 1.22
@@ -615,7 +615,8 @@
my $where = '';
my $sth = $dbh->prepare("
- SELECT RadAcctId, UserName, Realm, AcctSessionTime
+ SELECT RadAcctId, UserName, Realm, AcctSessionTime,
+ AcctInputOctets, AcctOutputOctets
FROM radacct
WHERE FreesideStatus IS NULL
AND AcctStopTime != 0
@@ -623,7 +624,8 @@
$sth->execute() or die $sth->errstr;
while ( my $row = $sth->fetchrow_arrayref ) {
- my($RadAcctId, $UserName, $Realm, $AcctSessionTime) = @$row;
+ my($RadAcctId, $UserName, $Realm, $AcctSessionTime,
+ $AcctInputOctets, $AcctOutputOctets) = @$row;
warn "processing record: ".
"$RadAcctId ($UserName\@$Realm for ${AcctSessionTime}s"
if $DEBUG;
@@ -633,7 +635,6 @@
if ( ref($self) =~ /withdomain/ ) { #well...
$extra_sql = " AND '$Realm' = ( SELECT domain FROM svc_domain
WHERE svc_domain.svcnum = svc_acct.domsvc ) ";
- my $svc_domain = qsearch
}
my @svc_acct =
@@ -654,18 +655,16 @@
} elsif ( scalar(@svc_acct) > 1 ) {
warn "WARNING: multiple svc_acct records found $errinfo - skipping\n";
} else {
- my $svc_acct = $svc_acct[0];
- warn "found svc_acct ". $svc_acct->svcnum. " $errinfo\n" if $DEBUG;
- if ( $svc_acct->seconds !~ /^$/ ) {
- warn " svc_acct.seconds found (". $svc_acct->seconds.
- ") - decrementing\n"
- if $DEBUG;
- my $error = $svc_acct->decrement_seconds($AcctSessionTime);
- die $error if $error;
- $status = 'done';
- } else {
- warn " no existing seconds value for svc_acct - skiping\n" if $DEBUG;
- }
+ warn "found svc_acct ". $svc_acct[0]->svcnum. " $errinfo\n" if $DEBUG;
+ _try_decrement($svc_acct[0], 'seconds', $AcctSessionTime)
+ and $status='done';
+ _try_decrement($svc_acct[0], 'upbytes', $AcctInputOctets)
+ and $status='done';
+ _try_decrement($svc_acct[0], 'downbytes', $AcctOutputOctets)
+ and $status='done';
+ _try_decrement($svc_acct[0], 'totalbytes', $AcctInputOctets +
+ $AcctOutputOctets)
+ and $status='done';
}
warn "setting FreesideStatus to $status $errinfo\n" if $DEBUG;
@@ -679,5 +678,21 @@
}
+sub _try_decrement {
+ my ($svc_acct, $column, $amount) = @_;
+ if ( $svc_acct->$column !~ /^$/ ) {
+ warn " svc_acct.$column found (". $svc_acct->$column.
+ ") - decrementing\n"
+ if $DEBUG;
+ my $method = 'decrement_' . $column;
+ my $error = $svc_acct->$method($amount);
+ die $error if $error;
+ return 'done';
+ } else {
+ warn " no existing $column value for svc_acct - skipping\n" if $DEBUG;
+ }
+ return '';
+}
+
1;
More information about the freeside-commits
mailing list