1 <% include( '/elements/header.html', 'RADIUS Sessions') %>
4 % # and finally, display the thing
7 % foreach my $part_export (
8 % #grep $_->can('usage_sessions'), qsearch( 'part_export' )
9 % qsearch( 'part_export', { 'exporttype' => 'sqlradius' } ),
10 % qsearch( 'part_export', { 'exporttype' => 'sqlradius_withdomain' } )
12 % %user2svc_acct = ();
14 % my $efields = tie my %efields, 'Tie::IxHash', %fields;
15 % delete $efields{'framedipaddress'} if $part_export->option('hide_ip');
16 % if ( $part_export->option('hide_data') ) {
17 % delete $efields{$_} foreach qw(acctinputoctets acctoutputoctets);
19 % if ( $part_export->option('show_called_station') ) {
20 % $efields->Splice(1, 0,
21 % 'calledstationid' => {
22 % 'name' => 'Destination',
23 % 'attrib' => 'Called-Station-ID',
25 % sub { length($_[0]) ? shift : ' '; },
33 <% $part_export->exporttype %> to <% $part_export->machine %><BR>
34 <% include( '/elements/table-grid.html' ) %>
35 % my $bgcolor1 = '#eeeeee';
36 % my $bgcolor2 = '#ffffff';
40 % foreach my $field ( keys %efields ) {
42 <TH CLASS="grid" BGCOLOR="#cccccc">
43 <% $efields{$field}->{name} %><BR>
44 <FONT SIZE=-2><% $efields{$field}->{attrib} %></FONT>
50 % foreach my $session (
51 % @{ $part_export->usage_sessions( {
52 % 'stoptime_start' => $beginning,
53 % 'stoptime_end' => $ending,
54 % 'open_sessions' => $open_sessions,
55 % 'starttime_start' => $starttime_beginning,
56 % 'starttime_end' => $starttime_ending,
57 % 'svc_acct' => $cgi_svc_acct,
59 % 'prefix' => $prefix,
63 % if ( $bgcolor eq $bgcolor1 ) {
64 % $bgcolor = $bgcolor2;
66 % $bgcolor = $bgcolor1;
70 % foreach my $field ( keys %efields ) {
71 % my $html = &{ $efields{$field}->{fmt} }( $session->{$field},
75 % my $class = ( $html =~ /<TABLE/ ? 'inv' : 'grid' );
77 <TD CLASS="<%$class%>" BGCOLOR="<% $bgcolor %>" ALIGN="<% $efields{$field}->{align} %>">
93 unless $FS::CurrentUser::CurrentUser->access_right('List rating data');
99 #sort of false laziness w/cust_pay.cgi
100 my( $beginning, $ending ) = ( '', '' );
101 if ( $cgi->param('stoptime_beginning')
102 && $cgi->param('stoptime_beginning') =~ /^([ 0-9\-\/\:\w]{0,54})$/ ) {
103 $beginning = str2time($1);
105 if ( $cgi->param('stoptime_ending')
106 && $cgi->param('stoptime_ending') =~ /^([ 0-9\-\/\:\w]{0,54})$/ ) {
107 $ending = str2time($1); # + 86399;
109 if ( $cgi->param('begin') && $cgi->param('begin') =~ /^(\d+)$/ ) {
112 if ( $cgi->param('end') && $cgi->param('end') =~ /^(\d+)$/ ) {
116 my $open_sessions = '';
117 if ( $cgi->param('open_sessions') =~ /^(\d*)$/ ) {
121 my( $starttime_beginning, $starttime_ending ) = ( '', '' );
122 if ( $cgi->param('starttime_beginning')
123 && $cgi->param('starttime_beginning') =~ /^([ 0-9\-\/\:\w]{0,54})$/ ) {
124 $starttime_beginning = str2time($1);
126 if ( $cgi->param('starttime_ending')
127 && $cgi->param('starttime_ending') =~ /^([ 0-9\-\/\:\w]{0,54})$/ ) {
128 $starttime_ending = str2time($1); # + 86399;
131 my $cgi_svc_acct = '';
132 if ( $cgi->param('svcnum') =~ /^(\d+)$/ ) {
133 $cgi_svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } );
134 } elsif ( $cgi->param('username') =~ /^([^@]+)\@([^@]+)$/ ) {
135 my %search = { 'username' => $1 };
136 my $svc_domain = qsearchs('svc_domain', { 'domain' => $2 } );
138 $search{'domsvc'} = $svc_domain->svcnum;
140 delete $search{'username'};
142 $cgi_svc_acct = qsearchs( 'svc_acct', \%search )
144 } elsif ( $cgi->param('username') =~ /^(.+)$/ ) {
145 $cgi_svc_acct = qsearchs( 'svc_acct', { 'username' => $1 } );
149 if ( $cgi->param('ip') =~ /^((\d+\.){3}\d+)$/ ) {
153 my $prefix = $cgi->param('prefix');
155 if ( $prefix =~ /^(\d+)$/ ) {
157 $prefix = "011$prefix" unless $prefix =~ /^1/;
163 # field formatting subroutines
166 my %user2svc_acct = ();
167 my $user_format = sub {
168 my ( $user, $session, $part_export ) = @_;
171 if ( exists $user2svc_acct{$user} ) {
172 $svc_acct = $user2svc_acct{$user};
175 if ( $part_export->exporttype eq 'sqlradius_withdomain' ) {
177 if ( $user =~ /^([^@]+)\@([^@]+)$/ ) {
178 $search{'username'} = $1;
181 $search{'username'} = $user;
182 $domain = $session->{'realm'};
184 my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } );
186 $search{'domsvc'} = $svc_domain->svcnum;
188 delete $search{'username'};
190 } elsif ( $part_export->exporttype eq 'sqlradius' ) {
191 $search{'username'} = $user;
193 die 'unknown export type '. $part_export->exporttype.
194 " for $part_export\n";
196 if ( keys %search ) {
198 grep { qsearchs( 'export_svc', {
199 'exportnum' => $part_export->exportnum,
200 'svcpart' => $_->cust_svc->svcpart,
202 } qsearch( 'svc_acct', \%search );
204 warn 'multiple svc_acct records for user $user found; '.
205 'using first arbitrarily'
206 if scalar(@svc_acct) > 1;
207 $user2svc_acct{$user} = $svc_acct = shift @svc_acct;
213 my $svcnum = $svc_acct->svcnum;
214 qq(<A HREF="${p}view/svc_acct.cgi?$svcnum"><B>$user</B></A>);
221 my $customer_format = sub {
222 my( $unused, $session ) = @_;
223 return ' ' unless exists $user2svc_acct{$session->{'username'}};
224 my $svc_acct = $user2svc_acct{$session->{'username'}};
225 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
226 return ' ' unless $cust_pkg;
227 my $cust_main = $cust_pkg->cust_main;
229 qq!<A HREF="${p}view/cust_main.cgi?!. $cust_main->custnum. '">'.
230 $cust_pkg->cust_main->name. '</A>';
233 my $time_format = sub {
235 return ' ' if $time == 0;
236 my $pretty = time2str('%T%P %a %b %o %Y', $time );
237 $pretty =~ s/ (\d)(st|dn|rd|th)/$1$2/;
241 my $duration_format = sub {
243 my $hour = int($seconds/3600);
244 my $min = int( ($seconds%3600) / 60 );
245 my $sec = $seconds%60;
246 '<TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0>'.
247 '<TR><TD CLASS="inv" ALIGN="right">'.
248 ( $hour ? "<B>$hour</B>h" : ' ' ).
249 '</TD><TD CLASS="inv" ALIGN="right">'.
250 ( ( $hour || $min ) ? "<B>$min</B>m" : ' ' ).
251 '</TD><TD CLASS="inv" ALIGN="right">'.
253 '</TD></TR></TABLE>';
256 my $octets_format = sub {
258 my $megs = $octets / 1048576;
259 sprintf('<B>%.3f</B> megs', $megs);
260 #my $gigs = $octets / 1073741824
261 #sprintf('<B>%.3f</B> gigabytes', $gigs);
268 tie my %fields, 'Tie::IxHash',
271 attrib => 'UserName',
283 fmt => $customer_format,
286 'framedipaddress' => {
287 name => 'IP Address',
288 attrib => 'Framed-IP-Address',
289 fmt => sub { my $ip = shift;
290 length($ip) ? $ip : ' ';
295 name => 'Start time',
296 attrib => 'Acct-Start-Time',
301 name => 'End time',
302 attrib => 'Acct-Stop-Time',
306 'acctsessiontime' => {
308 attrib => 'Acct-Session-Time',
309 fmt => $duration_format,
312 'acctinputoctets' => {
313 name => 'Upload', # (from user)',
314 attrib => 'Acct-Input-Octets',
315 fmt => $octets_format,
318 'acctoutputoctets' => {
319 name => 'Download', # (to user)',
320 attrib => 'Acct-Output-Octets',
321 fmt => $octets_format,
325 $fields{$_}->{fmt} ||= sub { length($_[0]) ? shift : ' '; }
326 foreach keys %fields;