LEMONLDAP::NG : little bug in Simple.pm : previous $datas was used for new users in status collect

Uptime displayed now in Status.pm
This commit is contained in:
Xavier Guimard 2008-05-13 09:07:30 +00:00
parent a3297e2dbb
commit 851d0d0caa
2 changed files with 42 additions and 26 deletions

View File

@ -482,9 +482,8 @@ sub forgeHeadersInit {
} }
sub updateStatus { sub updateStatus {
my ( $class, $url, $action ) = @_; my ( $class, $user, $url, $action ) = @_;
print $statusPipe ( $datas->{$whatToTrace} ? $datas->{$whatToTrace} : '' ) print $statusPipe "$user => "
. " => "
. $apacheRequest->hostname . $apacheRequest->hostname
. "$url $action\n" . "$url $action\n"
if ($statusPipe); if ($statusPipe);
@ -508,12 +507,12 @@ sub grant {
sub forbidden { sub forbidden {
my $class = shift; my $class = shift;
if ( $datas->{_logout} ) { if ( $datas->{_logout} ) {
$class->updateStatus( $_[0], 'LOGOUT' ); $class->updateStatus( $datas->{$whatToTrace}, $_[0], 'LOGOUT' );
my $u = $datas->{_logout}; my $u = $datas->{_logout};
$class->localUnlog; $class->localUnlog;
return $class->goToPortal( $u, 'logout=1' ); return $class->goToPortal( $u, 'logout=1' );
} }
$class->updateStatus( $_[0], 'REJECT' ); $class->updateStatus( $datas->{$whatToTrace}, $_[0], 'REJECT' );
$class->logForbidden(@_); $class->logForbidden(@_);
return FORBIDDEN; return FORBIDDEN;
} }
@ -593,7 +592,7 @@ sub run ($$) {
my $id; my $id;
unless ( $id = $class->fetchId ) { unless ( $id = $class->fetchId ) {
$class->lmLog( "$class: No cookie found", 'info' ); $class->lmLog( "$class: No cookie found", 'info' );
$class->updateStatus( $apacheRequest->uri, 'REDIRECT' ); $class->updateStatus( $apacheRequest->connection->remote_ip, $apacheRequest->uri, 'REDIRECT' );
return $class->goToPortal($uri); return $class->goToPortal($uri);
} }
@ -613,7 +612,7 @@ sub run ($$) {
# The cookie isn't yet available # The cookie isn't yet available
$class->lmLog( "The cookie $id isn't yet available: $@", $class->lmLog( "The cookie $id isn't yet available: $@",
'info' ); 'info' );
$class->updateStatus( $apacheRequest->uri, 'EXPIRED' ); $class->updateStatus( $apacheRequest->connection->remote_ip, $apacheRequest->uri, 'EXPIRED' );
return $class->goToPortal($uri); return $class->goToPortal($uri);
} }
$datas->{$_} = $h{$_} foreach ( keys %h ); $datas->{$_} = $h{$_} foreach ( keys %h );
@ -632,7 +631,7 @@ sub run ($$) {
# AUTHORIZATION # AUTHORIZATION
return $class->forbidden($uri) unless ( $class->grant($uri) ); return $class->forbidden($uri) unless ( $class->grant($uri) );
$class->updateStatus( $apacheRequest->uri, 'OK' ); $class->updateStatus( $datas->{$whatToTrace}, $apacheRequest->uri, 'OK' );
$class->lmLog( $class->lmLog(
"User " "User "
. $datas->{$whatToTrace} . $datas->{$whatToTrace}
@ -695,7 +694,7 @@ sub unlog ($$) {
my $class; my $class;
( $class, $apacheRequest ) = @_; ( $class, $apacheRequest ) = @_;
$class->localUnlog; $class->localUnlog;
$class->updateStatus( $apacheRequest->uri, 'LOGOUT' ); $class->updateStatus( $apacheRequest->connection->remote_ip, $apacheRequest->uri, 'LOGOUT' );
return $class->goToPortal( '/', 'logout=1' ); return $class->goToPortal( '/', 'logout=1' );
} }
@ -714,7 +713,7 @@ sub redirectFilter {
} }
while ( $f->read( my $buffer, 1024 ) ) { while ( $f->read( my $buffer, 1024 ) ) {
} }
$class->updateStatus( 'filter', 'REDIRECT' ); $class->updateStatus( ( $datas->{$whatToTrace} ? $datas->{$whatToTrace} : $f->r->connection->remote_ip ), 'filter', 'REDIRECT' );
return REDIRECT; return REDIRECT;
} }

View File

@ -87,9 +87,9 @@ sub run {
# if request is http://test.example.com/status?a=1). To be used # if request is http://test.example.com/status?a=1). To be used
# later... # later...
elsif (/^STATUS(?:\s+(\S+))?$/) { elsif (/^STATUS(?:\s+(\S+))?$/) {
my $tmp = $1; my $tmp = $1;
my $args = {}; my $args = {};
%$args = split (/[=&]/,$tmp) if($tmp); %$args = split( /[=&]/, $tmp ) if ($tmp);
&head; &head;
#print Dumper($args),&end;next; #print Dumper($args),&end;next;
my ( $c, $m, $u ); my ( $c, $m, $u );
@ -136,38 +136,55 @@ sub run {
$args->{categories} ||= 'REJECT,PORTAL_FIRSTACCESS,LOGOUT,OK'; $args->{categories} ||= 'REJECT,PORTAL_FIRSTACCESS,LOGOUT,OK';
# General # General
print "<h2>Top used URI</h2>\n<div id=\"uri\"><pre>\n"; print "<h2>Top used URI</h2>\n<div id=\"uri\"><pre>\n";
foreach my $uri (keys %{$status->{uri}}) { foreach my $uri ( keys %{ $status->{uri} } ) {
$count->{$uri} += $_ foreach (values %{$status->{uri}->{$uri}}); $count->{$uri} += $_
foreach ( values %{ $status->{uri}->{$uri} } );
} }
my $i=0; my $i = 0;
foreach (sort {$count->{$b} <=> $count->{$a}} keys %$count) { foreach ( sort { $count->{$b} <=> $count->{$a} } keys %$count )
last if($i == $args->{top}); {
last unless($count->{$_}); last if ( $i == $args->{top} );
last unless ( $count->{$_} );
$i++; $i++;
print sprintf( "%-80s : %4d\n", $_, $count->{$_} ); print sprintf( "%-80s : %4d\n", $_, $count->{$_} );
} }
print "\n</pre></div>\n"; print "\n</pre></div>\n";
# Top by category # Top by category
print "<table border=\"1\" width=\"100%\"><tr><th>Code</th><th>Top</ht></tr>\n"; print "<table border=\"1\" width=\"100%\"><tr><th>Code</th><th>Top</ht></tr>\n";
foreach my $cat (split /,/,$args->{categories}) { foreach my $cat ( split /,/, $args->{categories} ) {
print "<tr><td><pre>$cat</pre></td><td nowrap>\n<div id=\"$cat\">\n"; print "<tr><td><pre>$cat</pre></td><td nowrap>\n<div id=\"$cat\">\n";
topByCat($cat,$args->{top}); topByCat( $cat, $args->{top} );
print "</div>\n</td></tr>"; print "</div>\n</td></tr>";
} }
print '</table>'; print "</table>\n";
} }
print "<div id=\"up\"><p>\nServer up for : "
. &timeUp($mn)
. "\n</p></div>\n";
&end; &end;
} }
} }
} }
sub timeUp {
my $d = shift;
my $mn = $d % 60;
$d = ( $d - $mn ) / 60;
my $h = $d % 24;
$d = ( $a - $h ) / 24;
return "$d\d $h\h $mn\mn";
}
sub topByCat { sub topByCat {
my($cat,$max) = @_; my ( $cat, $max ) = @_;
my $i=0; my $i = 0;
print "<pre>\n"; print "<pre>\n";
foreach (sort {$status->{uri}->{$b}->{$cat} <=> $status->{uri}->{$a}->{$cat}} keys %{$status->{uri}}) { foreach (
last if($i == $max); sort { $status->{uri}->{$b}->{$cat} <=> $status->{uri}->{$a}->{$cat} }
last unless($status->{uri}->{$_}->{$cat}); keys %{ $status->{uri} } )
{
last if ( $i == $max );
last unless ( $status->{uri}->{$_}->{$cat} );
$i++; $i++;
print sprintf( "%-80s : %4d\n", $_, $status->{uri}->{$_}->{$cat} ); print sprintf( "%-80s : %4d\n", $_, $status->{uri}->{$_}->{$cat} );
} }