Update cronjob to use Common::Session module (#671)
This commit is contained in:
parent
43a36aba3c
commit
25930249f8
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Cleaner for LemonLDAP::NG: purge local handler cache
|
# Cleaner for LemonLDAP::NG: purge local handler cache and session cache
|
||||||
#
|
#
|
||||||
# This module is written to be used by cron to clean cache objects used
|
# This module is written to be used by cron to clean cache objects used
|
||||||
# by Handler.
|
# by Handler.
|
||||||
|
@ -23,10 +23,19 @@ my $conf = $lmconf->getLocalConf(HANDLERSECTION)
|
||||||
or die "Unable to get local configuration ($!)";
|
or die "Unable to get local configuration ($!)";
|
||||||
|
|
||||||
print "Configuration loaded\n" if $debug;
|
print "Configuration loaded\n" if $debug;
|
||||||
|
|
||||||
|
# Handler cache
|
||||||
exit 0 unless ( $conf->{localStorage} );
|
exit 0 unless ( $conf->{localStorage} );
|
||||||
eval "require $conf->{localStorage}";
|
eval "require $conf->{localStorage}";
|
||||||
$conf->{localStorageOptions}->{default_expires_in} ||= 600;
|
$conf->{localStorageOptions}->{default_expires_in} ||= 600;
|
||||||
my $c = $conf->{localStorage}->new( $conf->{localStorageOptions} );
|
my $c = $conf->{localStorage}->new( $conf->{localStorageOptions} );
|
||||||
$c->purge();
|
$c->purge();
|
||||||
|
|
||||||
|
# Session cache
|
||||||
|
exit 0 unless ( $conf->{localSessionStorage} );
|
||||||
|
eval "require $conf->{localSessionStorage}";
|
||||||
|
$conf->{localSessionStorageOptions}->{default_expires_in} ||= 600;
|
||||||
|
my $s = $conf->{localSessionStorage}->new( $conf->{localSessionStorageOptions} );
|
||||||
|
$s->purge();
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use Lemonldap::NG::Common::Conf;
|
use Lemonldap::NG::Common::Conf;
|
||||||
use Lemonldap::NG::Common::Conf::Constants;
|
use Lemonldap::NG::Common::Conf::Constants;
|
||||||
use Lemonldap::NG::Common::Apache::Session;
|
use Lemonldap::NG::Common::Apache::Session;
|
||||||
|
use Lemonldap::NG::Common::Session;
|
||||||
use strict;
|
use strict;
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
|
|
||||||
|
@ -44,9 +45,6 @@ print "Configuration loaded\n" if $debug;
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Timeout
|
# Timeout
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
$conf->{timeout} ||= 7200;
|
|
||||||
$conf->{timeoutActivity} ||= 0;
|
|
||||||
|
|
||||||
print "Timeout value: " . $conf->{timeout} . "\n" if $debug;
|
print "Timeout value: " . $conf->{timeout} . "\n" if $debug;
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
|
@ -87,6 +85,23 @@ if ( defined $conf->{samlStorage}
|
||||||
print "SAML backend $module will be used\n" if $debug;
|
print "SAML backend $module will be used\n" if $debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# CAS
|
||||||
|
if ( defined $conf->{casStorage}
|
||||||
|
or keys %{ $conf->{casStorageOptions} } )
|
||||||
|
{
|
||||||
|
|
||||||
|
# Load module
|
||||||
|
$module = $conf->{casStorage} || $conf->{globalStorage};
|
||||||
|
eval "use $module";
|
||||||
|
die $@ if ($@);
|
||||||
|
$conf->{casStorageOptions}->{backend} = $module;
|
||||||
|
|
||||||
|
# Add module in managed backends
|
||||||
|
push @backends, $conf->{casStorageOptions};
|
||||||
|
|
||||||
|
print "CAS backend $module will be used\n" if $debug;
|
||||||
|
}
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Load and purge sessions
|
# Load and purge sessions
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
|
@ -136,18 +151,25 @@ for my $options (@backends) {
|
||||||
# Delete sessions
|
# Delete sessions
|
||||||
my @errors;
|
my @errors;
|
||||||
for my $id (@t) {
|
for my $id (@t) {
|
||||||
my %h;
|
|
||||||
eval { tie %h, "Lemonldap::NG::Common::Apache::Session", $id, $options };
|
my $session = Lemonldap::NG::Common::Session->new(
|
||||||
if ($@) {
|
storageModule => $options->{backend},
|
||||||
print "Error while opening session $id: $@\n" if $debug;
|
storageModuleOptions => $options,
|
||||||
|
cacheModule => $conf->{localSessionStorage},
|
||||||
|
cacheModuleOptions => $conf->{localSessionStorageOptions},
|
||||||
|
id => $id,
|
||||||
|
);
|
||||||
|
|
||||||
|
unless ( $session->data ) {
|
||||||
|
print "Error while opening session $id\n" if $debug;
|
||||||
print STDERR "Error on session $id\n";
|
print STDERR "Error on session $id\n";
|
||||||
$nb_error++;
|
$nb_error++;
|
||||||
push @errors, $id;
|
push @errors, $id;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
eval { tied(%h)->delete; };
|
|
||||||
if ($@) {
|
unless ( $session->remove ) {
|
||||||
print "Error while deleting session $id: $@\n" if $debug;
|
print "Error while deleting session $id\n" if $debug;
|
||||||
print STDERR "Error on session $id\n";
|
print STDERR "Error on session $id\n";
|
||||||
$nb_error++;
|
$nb_error++;
|
||||||
push @errors, $id;
|
push @errors, $id;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user