Do not delete persistent sessions in the purge script (#325)
This commit is contained in:
parent
5a216dcddc
commit
bf2187c75b
@ -13,7 +13,7 @@ use Lemonldap::NG::Common::Conf::Constants;
|
|||||||
use Lemonldap::NG::Common::Apache::Session;
|
use Lemonldap::NG::Common::Apache::Session;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
my $nb_purged = 0;
|
my $nb_purged = 0;
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
@ -34,10 +34,10 @@ print "Configuration loaded\n" if $debug;
|
|||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Timeout
|
# Timeout
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
$conf->{timeout} ||= 7200;
|
$conf->{timeout} ||= 7200;
|
||||||
$conf->{timeoutActivity} ||= 0;
|
$conf->{timeoutActivity} ||= 0;
|
||||||
|
|
||||||
print "Timeout value: ".$conf->{timeout}."\n" if $debug;
|
print "Timeout value: " . $conf->{timeout} . "\n" if $debug;
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Apache::Session backends
|
# Apache::Session backends
|
||||||
@ -93,41 +93,47 @@ for my $backend (@backends) {
|
|||||||
# Get all expired sessions
|
# Get all expired sessions
|
||||||
$storage->get_key_from_all_sessions(
|
$storage->get_key_from_all_sessions(
|
||||||
$options,
|
$options,
|
||||||
sub {
|
sub {
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
my $id = shift;
|
my $id = shift;
|
||||||
my $time = time;
|
my $time = time;
|
||||||
|
|
||||||
|
# Do net check sessions without _utime
|
||||||
|
return undef unless $entry->{_utime};
|
||||||
|
|
||||||
# Session expired
|
# Session expired
|
||||||
if ( $time - $entry->{_utime} > $conf->{timeout} ) {
|
if ( $time - $entry->{_utime} > $conf->{timeout} ) {
|
||||||
push @t, $id;
|
push @t, $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# User has no activity, so considere the session has expired
|
# User has no activity, so considere the session has expired
|
||||||
elsif ( $conf->{timeoutActivity} and $entry->{_lastSeen}
|
elsif ( $conf->{timeoutActivity}
|
||||||
|
and $entry->{_lastSeen}
|
||||||
and $time - $entry->{_lastSeen} > $conf->{timeoutActivity} )
|
and $time - $entry->{_lastSeen} > $conf->{timeoutActivity} )
|
||||||
{
|
{
|
||||||
push @t, $id
|
push @t, $id;
|
||||||
}
|
}
|
||||||
undef;
|
undef;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
# Delete sessions
|
# Delete sessions
|
||||||
for my $id (@t) {
|
for my $id (@t) {
|
||||||
my %h;
|
my %h;
|
||||||
eval { tie %h, $storage, $id, $options };
|
eval { tie %h, $storage, $id, $options };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
tied(%h)->delete;
|
tied(%h)->delete;
|
||||||
print "Session $id has been purged\n" if $debug;
|
print "Session $id has been purged\n" if $debug;
|
||||||
$nb_purged++;
|
$nb_purged++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove lock files for File backend
|
# Remove lock files for File backend
|
||||||
if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i ) {
|
if ( $options->{backend} =~ /^Apache::Session::(?:Browseable::)?File$/i ) {
|
||||||
require Apache::Session::Lock::File;
|
require Apache::Session::Lock::File;
|
||||||
my $l = new Apache::Session::Lock::File;
|
my $l = new Apache::Session::Lock::File;
|
||||||
my $lock_directory = $options->{LockDirectory} || $options->{Directory};
|
my $lock_directory = $options->{LockDirectory} || $options->{Directory};
|
||||||
$l->clean( $lock_directory, $conf->{timeout} );
|
$l->clean( $lock_directory, $conf->{timeout} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user