summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/sqlradius.pm
diff options
context:
space:
mode:
authorlevinse <levinse>2011-05-11 15:23:56 +0000
committerlevinse <levinse>2011-05-11 15:23:56 +0000
commit38eb380a88ea7a130e83b77ff9c51ef6967b707b (patch)
treeb6417e68499956b5bdb1aba6393dc749e819d816 /FS/FS/part_export/sqlradius.pm
parent9c6d500c5fc6704e6186caa8727e79e7c600bd8a (diff)
add summarized RADIUS report feature, RT11776
Diffstat (limited to 'FS/FS/part_export/sqlradius.pm')
-rw-r--r--FS/FS/part_export/sqlradius.pm18
1 files changed, 14 insertions, 4 deletions
diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm
index 15aa986..d1663dc 100644
--- a/FS/FS/part_export/sqlradius.pm
+++ b/FS/FS/part_export/sqlradius.pm
@@ -610,6 +610,7 @@ sub usage_sessions {
my $opt = {};
my($start, $end, $svc_acct, $ip, $prefix) = ( '', '', '', '', '');
+ my $summarize = 0;
if ( ref($_[0]) ) {
$opt = shift;
$start = $opt->{stoptime_start};
@@ -617,6 +618,7 @@ sub usage_sessions {
$svc_acct = $opt->{svc_acct};
$ip = $opt->{ip};
$prefix = $opt->{prefix};
+ $summarize = $opt->{summarize};
} else {
( $start, $end ) = splice(@_, 0, 2);
$svc_acct = @_ ? shift : '';
@@ -644,6 +646,10 @@ sub usage_sessions {
"$str2time acctstoptime ) as acctstoptime",
);
+ @fields = ( 'username', 'sum(acctsessiontime) as acctsessiontime', 'sum(acctinputoctets) as acctinputoctets',
+ 'sum(acctoutputoctets) as acctoutputoctets',
+ ) if $summarize;
+
my @param = ();
my @where = ();
@@ -696,11 +702,15 @@ sub usage_sessions {
my $where = join(' AND ', @where);
$where = "WHERE $where" if $where;
+ my $groupby = '';
+ $groupby = 'GROUP BY username' if $summarize;
+
+ my $orderby = 'ORDER BY AcctStartTime DESC';
+ $orderby = '' if $summarize;
+
my $sth = $dbh->prepare('SELECT '. join(', ', @fields).
- " FROM radacct
- $where
- ORDER BY AcctStartTime DESC
- ") or die $dbh->errstr;
+ " FROM radacct $where $groupby $orderby
+ ") or die $dbh->errstr;
$sth->execute(@param) or die $sth->errstr;
[ map { { %$_ } } @{ $sth->fetchall_arrayref({}) } ];