[freeside-commits] freeside/FS/FS/part_export sqlradius.pm, 1.30, 1.31
Jeff Finucane,420,,
jeff at wavetail.420.am
Thu Dec 27 17:41:25 PST 2007
Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail:/tmp/cvs-serv26559/FS/FS/part_export
Modified Files:
sqlradius.pm
Log Message:
last login reporting (#2952)
Index: sqlradius.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/sqlradius.pm,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- sqlradius.pm 28 Oct 2007 03:55:27 -0000 1.30
+++ sqlradius.pm 28 Dec 2007 01:41:23 -0000 1.31
@@ -619,9 +619,11 @@
my $conf = new FS::Conf;
+ my $fdbh = dbh;
my $dbh = sqlradius_connect( map $self->option($_),
qw( datasrc username password ) );
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my @fields = qw( radacctid username realm acctsessiontime );
my @param = ();
@@ -629,6 +631,7 @@
my $sth = $dbh->prepare("
SELECT RadAcctId, UserName, Realm, AcctSessionTime,
+ $str2time AcctStartTime), $str2time AcctStopTime),
AcctInputOctets, AcctOutputOctets
FROM radacct
WHERE FreesideStatus IS NULL
@@ -637,8 +640,8 @@
$sth->execute() or die $sth->errstr;
while ( my $row = $sth->fetchrow_arrayref ) {
- my($RadAcctId, $UserName, $Realm, $AcctSessionTime,
- $AcctInputOctets, $AcctOutputOctets) = @$row;
+ my($RadAcctId, $UserName, $Realm, $AcctSessionTime, $AcctStartTime,
+ $AcctStopTime, $AcctInputOctets, $AcctOutputOctets) = @$row;
warn "processing record: ".
"$RadAcctId ($UserName\@$Realm for ${AcctSessionTime}s"
if $DEBUG;
@@ -653,6 +656,9 @@
WHERE svc_domain.svcnum = svc_acct.domsvc ) ";
}
+ my $oldAutoCommit = $FS::UID::AutoCommit; # can't undo side effects, but at
+ local $FS::UID::AutoCommit = 0; # least we can avoid over counting
+
my @svc_acct =
grep { qsearch( 'export_svc', { 'exportnum' => $self->exportnum,
'svcpart' => $_->cust_svc->svcpart, } )
@@ -672,15 +678,15 @@
warn "WARNING: multiple svc_acct records found $errinfo - skipping\n";
} else {
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';
+ $svc_acct[0]->last_login($AcctStartTime);
+ $svc_acct[0]->last_logout($AcctStopTime);
+ my @stati;
+ push @stati, _try_decrement($svc_acct[0], 'seconds', $AcctSessionTime);
+ push @stati, _try_decrement($svc_acct[0], 'upbytes', $AcctInputOctets);
+ push @stati, _try_decrement($svc_acct[0], 'downbytes', $AcctOutputOctets);
+ push @stati, _try_decrement($svc_acct[0], 'totalbytes', $AcctInputOctets +
+ $AcctOutputOctets);
+ $status=join(' ', @stati);
}
warn "setting FreesideStatus to $status $errinfo\n" if $DEBUG;
@@ -690,6 +696,8 @@
) or die $dbh->errstr;
$psth->execute($status, $RadAcctId) or die $psth->errstr;
+ $fdbh->commit or die $fdbh->errstr if $oldAutoCommit;
+
}
}
@@ -707,7 +715,7 @@
} else {
warn " no existing $column value for svc_acct - skipping\n" if $DEBUG;
}
- return '';
+ return 'skipped';
}
1;
More information about the freeside-commits
mailing list