";
# For each IP node, store sessions sorted by start time
foreach my $session ( sort { $a->{startTime} <=> $b->{startTime} }
@{ $byUid->{$uid}->{$ip} } )
{
$res .=
"
";
}
return $res;
}
# Ajax request to list users starting by a letter
## @method protected string letter()
# Build letter XML part
# @return string XML tree
sub letter {
my $self = shift;
my $letter = $self->param('letter');
my ( $byUid, $res );
my $moduleOptions = $tsv->{globalStorageOptions} || {};
$moduleOptions->{backend} = $tsv->{globalStorage};
my $module = "Lemonldap::NG::Common::Apache::Session";
$res = $module->searchOnExpr(
$moduleOptions, $tsv->{whatToTrace},
"${letter}*", '_httpSessionType',
$tsv->{whatToTrace}
);
while ( my ( $id, $entry ) = each %$res ) {
next if ( $entry->{_httpSessionType} );
$byUid->{ $entry->{ $tsv->{whatToTrace} } }++;
}
$res = '';
foreach my $uid ( sort keys %$byUid ) {
$res .= $self->ajaxNode(
$uid,
$uid
. (
$byUid->{$uid} > 1
? " ($byUid->{$uid} "
. (
$byUid->{$uid} == 1
? $self->translate('session')
: $self->translate('sessions')
)
. ")"
: ''
),
"uid=$uid"
);
}
return $res;
}
## @method protected string p()
# Build IP classes sub tree (call _ipclasses())
# @return string XML tree
sub p {
my $self = shift;
my @t = $self->_ipclasses(@_);
return $t[0];
}
## @method private string _ipclasses()
# Build IP classes (sub) tree
# @return string XML tree
sub _ipclasses {
my ( $self, $p ) = splice @_;
my $partial = $p ? "$p." : '';
my $repartial = quotemeta($partial);
my ( $byIp, $count, $res );
my $moduleOptions = $tsv->{globalStorageOptions} || {};
$moduleOptions->{backend} = $tsv->{globalStorage};
my $module = "Lemonldap::NG::Common::Apache::Session";
$res = $module->searchOnExpr(
$moduleOptions, $self->{ipField},
"${partial}*", '_httpSessionType',
$self->{ipField}
);
while ( my ( $id, $entry ) = each %$res ) {
next if ( $entry->{_httpSessionType} );
$entry->{ $self->{ipField} } =~ /^$repartial(\d+)/ or next;
$byIp->{$1}++;
$count++;
}
$res = '';
foreach my $ip ( sort { $a <=> $b } keys %$byIp ) {
$res .= $self->ajaxNode(
"$partial$ip",
"$partial$ip ($byIp->{$ip} "
. (
$byIp->{$ip} == 1 ? $self->translate('session')
: $self->translate('sessions')
)
. ")",
(
$partial !~ /^\d+\.\d+\.\d+/ ? "ipclasses=1&p=$partial$ip"
: "uidByIp=$partial$ip"
)
);
}
return (
$res,
"$count "
. (
$count == 1
? $self->translate('session')
: $self->translate('sessions')
)
);
#return $res;
}
## @fn protected string htmlquote(string s)
# Change <, > and & to HTML encoded values in the string
# @param $s HTML string
# @return HTML string
sub htmlquote {
my $s = shift;
$s =~ s/&/&/g;
$s =~ s/</g;
$s =~ s/>/>/g;
return $s;
}
## @method private void ajaxnode(string id, string text, string param)
# Display tree node with Ajax functions inside for opening the node.
# @param $id HTML id of the element.
# @param $text text to display
# @param $param Parameters for the Ajax query
sub ajaxNode {
my ( $self, $id, $text, $param ) = @_;
return
"
$text\n
{url:$ENV{SCRIPT_NAME}?$param}
\n";
}
## @method private string _stToStr(string)
# Transform a utime string into readeable string (ex: "2010-08-18 13:03:13")
# @return Formated string
sub _stToStr {
shift;
return
sprintf( '%d-%02d-%02d %d:%02d:%02d', unpack( 'a4a2a2a2a2a2', shift ) );
}
1;
__END__
=encoding utf8
=head1 NAME
Lemonldap::NG::Manager::Sessions - Perl extension to manage Lemonldap::NG
sessions
=head1 SYNOPSIS
#!/usr/bin/perl
use strict;
use Lemonldap::NG::Manager::Sessions;
our $cgi ||= Lemonldap::NG::Manager::Sessions->new({
localStorage => "Cache::FileCache",
localStorageOptions => {
'namespace' => 'lemonldap-ng-config',
'default_expires_in' => 600,
'directory_umask' => '007',
'cache_root' => '/tmp',
'cache_depth' => 5,
},
configStorage => $Lemonldap::NG::Common::configStorage,
configStorage=>{
type=>'File',
dirName=>"/tmp/",
},
https => 1,
jqueryUri => '/js/jquery/jquery.js',
imagePath => '/js/jquery.simple.tree/',
# Optionnal
protection => 'rule: $uid eq "admin"',
# Or to use rules from manager
protection => 'manager',
# Or just to authenticate without managing authorization
protection => 'authenticate',
});
$cgi->process();
=head1 DESCRIPTION
Lemonldap::NG::Manager::Sessions provides a web interface to manage
Lemonldap::NG sessions.
It inherits from L, so see this manpage to
understand how arguments passed to the constructor.
=head1 SEE ALSO
L, L
=head1 AUTHOR
=over
=item Clement Oudot, Eclem.oudot@gmail.comE
=item François-Xavier Deltombe, Efxdeltombe@gmail.com.E
=item Xavier Guimard, Ex.guimard@free.frE
=item Thomas Chemineau, Ethomas.chemineau@gmail.comE
=back
=head1 BUG REPORT
Use OW2 system to report bug or ask for features:
L
=head1 DOWNLOAD
Lemonldap::NG is available at
L
=head1 COPYRIGHT AND LICENSE
=over
=item Copyright (C) 2008, 2009, 2010, 2013 by Xavier Guimard, Ex.guimard@free.frE
=item Copyright (C) 2012 by François-Xavier Deltombe, Efxdeltombe@gmail.com.E
=item Copyright (C) 2009, 2010, 2011, 2012 by Clement Oudot, Eclem.oudot@gmail.comE
=item Copyright (C) 2010, 2011 by Thomas Chemineau, Ethomas.chemineau@gmail.comE
=back
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see L.
=cut