my $opt = {};
my($start, $end, $svc_acct, $ip, $prefix) = ( '', '', '', '', '');
+ my $summarize = 0;
if ( ref($_[0]) ) {
$opt = shift;
$start = $opt->{stoptime_start};
$svc_acct = $opt->{svc_acct};
$ip = $opt->{ip};
$prefix = $opt->{prefix};
+ $summarize = $opt->{summarize};
} else {
( $start, $end ) = splice(@_, 0, 2);
$svc_acct = @_ ? shift : '';
"$str2time acctstoptime ) as acctstoptime",
);
+ @fields = ( 'username', 'sum(acctsessiontime) as acctsessiontime', 'sum(acctinputoctets) as acctinputoctets',
+ 'sum(acctoutputoctets) as acctoutputoctets',
+ ) if $summarize;
+
my @param = ();
my @where = ();
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({}) } ];