X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fsqlradius.pm;h=4dea80e494cd7b03c91b71733f99f45710de1948;hb=4665d5af02f915679207a369222472a25e137c9d;hp=15aa9862053beae95d30d48858ff67fcd80ac9f7;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984;p=freeside.git diff --git a/FS/FS/part_export/sqlradius.pm b/FS/FS/part_export/sqlradius.pm index 15aa98620..4dea80e49 100644 --- a/FS/FS/part_export/sqlradius.pm +++ b/FS/FS/part_export/sqlradius.pm @@ -14,6 +14,7 @@ use Carp qw( cluck ); $DEBUG = 0; +my %groups; tie %options, 'Tie::IxHash', 'datasrc' => { label=>'DBI data source ' }, 'username' => { label=>'Database username' }, @@ -47,7 +48,21 @@ tie %options, 'Tie::IxHash', type => 'checkbox', label => 'Show the Called-Station-ID on session reports', }, - 'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', } , + 'overlimit_groups' => { + label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit (if not overridden by overlimit_groups global or per-agent config)', + type => 'select', + multi => 1, + option_label => sub { + $groups{$_[0]}; + }, + option_values => sub { + %groups = ( + map { $_->groupnum, $_->long_description } + qsearch('radius_group', {}), + ); + sort keys (%groups); + }, + } , 'groups_susp_reason' => { label => 'Radius group mapping to reason (via template user) (svcnum|username|username@domain reasonnum|reason)', type => 'textarea', @@ -610,6 +625,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 +633,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 +661,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 +717,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({}) } ];