%= include( '/elements/header.html', 'RADIUS Sessions', include('/elements/menubar.html', 'Main menu' => $p, # popurl(2), ), ) %> <% ### # parse cgi params ### #sort of false laziness w/cust_pay.cgi my $beginning = ''; my $ending = ''; if ( $cgi->param('beginning') && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) { $beginning = str2time($1); } if ( $cgi->param('ending') && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) { $ending = str2time($1) + 86399; } if ( $cgi->param('begin') && $cgi->param('begin') =~ /^(\d+)$/ ) { $beginning = $1; } if ( $cgi->param('end') && $cgi->param('end') =~ /^(\d+)$/ ) { $ending = $1; } my $cgi_svc_acct = ''; if ( $cgi->param('svcnum') =~ /^(\d+)$/ ) { $cgi_svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $1 } ); } elsif ( $cgi->param('username') =~ /^([^@]+)\@([^@]+)$/ ) { my %search = { 'username' => $1 }; my $svc_domain = qsearchs('svc_domain', { 'domain' => $2 } ); if ( $svc_domain ) { $search{'domsvc'} = $svc_domain->svcnum; } else { delete $search{'username'}; } $cgi_svc_acct = qsearchs( 'svc_acct', \%search ) if keys %search; } elsif ( $cgi->param('username') =~ /^(.+)$/ ) { $cgi_svc_acct = qsearchs( 'svc_acct', { 'username' => $1 } ); } my $ip = ''; if ( $cgi->param('ip') =~ /^((\d+\.){3}\d+)$/ ) { $ip = $1; } my $prefix = $cgi->param('prefix'); $prefix =~ s/\D//g; if ( $prefix =~ /^(\d+)$/ ) { $prefix = $1; $prefix = "011$prefix" unless $prefix =~ /^1/; } else { $prefix = ''; } ### # field formatting subroutines ### my %user2svc_acct = (); my $user_format = sub { my ( $user, $session, $part_export ) = @_; my $svc_acct = ''; if ( exists $user2svc_acct{$user} ) { $svc_acct = $user2svc_acct{$user}; } else { my %search = (); if ( $part_export->exporttype eq 'sqlradius_withdomain' ) { my $domain; if ( $user =~ /^([^@]+)\@([^@]+)$/ ) { $search{'username'} = $1; $domain = $2; } else { $search{'username'} = $user; $domain = $session->{'realm'}; } my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } ); if ( $svc_domain ) { $search{'domsvc'} = $svc_domain->svcnum; } else { delete $search{'username'}; } } elsif ( $part_export->exporttype eq 'sqlradius' ) { $search{'username'} = $user; } else { die 'unknown export type '. $part_export->exporttype. " for $part_export\n"; } if ( keys %search ) { my @svc_acct = grep { qsearchs( 'export_svc', { 'exportnum' => $part_export->exportnum, 'svcpart' => $_->cust_svc->svcpart, } ) } qsearch( 'svc_acct', \%search ); if ( @svc_acct ) { warn 'multiple svc_acct records for user $user found; '. 'using first arbitrarily' if scalar(@svc_acct) > 1; $user2svc_acct{$user} = $svc_acct = shift @svc_acct; } } } if ( $svc_acct ) { my $svcnum = $svc_acct->svcnum; qq($user); } else { "$user"; } }; my $customer_format = sub { my( $unused, $session ) = @_; return ' ' unless exists $user2svc_acct{$session->{'username'}}; my $svc_acct = $user2svc_acct{$session->{'username'}}; my $cust_pkg = $svc_acct->cust_svc->cust_pkg; return ' ' unless $cust_pkg; my $cust_main = $cust_pkg->cust_main; qq!'. $cust_pkg->cust_main->name. ''; }; my $time_format = sub { my $time = shift; return ' ' if $time == 0; my $pretty = time2str('%T%P %a %b %o %Y', $time ); $pretty =~ s/ (\d)(st|dn|rd|th)/$1$2/; $pretty; }; my $duration_format = sub { my $seconds = shift; my $hour = int($seconds/3600); my $min = int( ($seconds%3600) / 60 ); my $sec = $seconds%60; '
'. ( $hour ? "$hourh" : ' ' ). ' | '. ( ( $hour || $min ) ? "$minm" : ' ' ). ' | '. "$secs". ' |