2017-02-17 08:40:18 +01:00
|
|
|
package Lemonldap::NG::Portal::Plugins::SingleSession;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Plugin',
|
|
|
|
'Lemonldap::NG::Portal::Lib::OtherSessions';
|
|
|
|
|
|
|
|
sub afterDatas { 'run' }
|
|
|
|
|
|
|
|
sub init { 1 }
|
|
|
|
|
|
|
|
sub run {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $deleted = [];
|
|
|
|
my $otherSessions = [];
|
|
|
|
|
|
|
|
my $moduleOptions = $self->conf->{globalStorageOptions} || {};
|
|
|
|
$moduleOptions->{backend} = $self->conf->{globalStorage};
|
|
|
|
|
|
|
|
my $sessions = $self->module->searchOn(
|
|
|
|
$moduleOptions,
|
|
|
|
$self->conf->{whatToTrace},
|
|
|
|
$req->{sessionInfo}->{ $self->conf->{whatToTrace} }
|
|
|
|
);
|
|
|
|
foreach my $id ( keys %$sessions ) {
|
|
|
|
next if ( $req->id eq $id );
|
|
|
|
my $session = $self->p->getApacheSession($id) or next;
|
|
|
|
if (
|
|
|
|
$self->conf->{singleSession}
|
|
|
|
or ( $self->conf->{singleIP}
|
|
|
|
and $req->{sessionInfo}->{ipAddr} ne $session->data->{ipAddr} )
|
|
|
|
)
|
|
|
|
{
|
2017-02-19 08:17:48 +01:00
|
|
|
push @$deleted, $self->p->_sumUpSession( $session->data );
|
2017-02-17 08:40:18 +01:00
|
|
|
$self->p->_deleteSession( $req, $session, 1 );
|
|
|
|
}
|
|
|
|
else {
|
2017-02-19 08:17:48 +01:00
|
|
|
push @$otherSessions, $self->p->_sumUpSession( $session->data );
|
2017-02-17 08:40:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $self->conf->{singleUserByIP} ) {
|
|
|
|
my $sessions =
|
|
|
|
$self->module->searchOn( $moduleOptions, 'ipAddr',
|
|
|
|
$req->sessionInfo->ipAddr );
|
|
|
|
foreach my $id ( keys %$sessions ) {
|
|
|
|
next if ( $req->id eq $id );
|
|
|
|
my $session = $self->p->getApacheSession($id) or next;
|
|
|
|
unless ( $req->{sessionInfo}->{ $self->conf->{whatToTrace} } eq
|
|
|
|
$session->data->{ $self->conf->{whatToTrace} } )
|
|
|
|
{
|
2017-02-19 08:17:48 +01:00
|
|
|
push @$deleted, $self->p->_sumUpSession( $session->data );
|
2017-02-17 08:40:18 +01:00
|
|
|
$self->p->_deleteSession( $req, $session, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-19 22:06:33 +02:00
|
|
|
$req->info( $self->p->mkSessionArray( $deleted, 'sessionsDeleted', 1 ) )
|
2017-02-17 08:40:18 +01:00
|
|
|
if ( $self->conf->{notifyDeleted} and @$deleted );
|
2017-09-19 22:06:33 +02:00
|
|
|
$req->info( $self->p->mkSessionArray( $otherSessions, 'otherSessions', 1 )
|
2017-02-17 08:40:18 +01:00
|
|
|
. $self->_mkRemoveOtherLink() )
|
|
|
|
if ( $self->conf->{notifyOther} and @$otherSessions );
|
|
|
|
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build the removeOther link
|
|
|
|
# Last part of URL is built trough javascript
|
|
|
|
# @return removeOther link in HTML code
|
|
|
|
sub _mkRemoveOtherLink {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# TODO: remove this
|
2017-10-10 13:04:40 +02:00
|
|
|
return $self->loadTemplate(
|
|
|
|
'removeOther',
|
|
|
|
params => {
|
|
|
|
link => $self->conf->{portal} . "?removeOther=1"
|
|
|
|
}
|
|
|
|
);
|
2017-02-17 08:40:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|