#!/usr/bin/perl
our
$opt_d
;
our
$opt_f
;
getopts(
'df'
);
my
$debug
=
$opt_d
;
my
$force
=
$opt_f
;
my
$nb_purged
= 0;
my
$nb_error
= 0;
unless
(
@ARGV
) {
print
STDERR
"Usage: $0 <uid>\n"
;
print
STDERR
"This script is deprecated, use lemonldap-ng-sessions instead\n"
;
exit
1;
}
my
$lmconf
= Lemonldap::NG::Common::Conf->new()
or
die
$Lemonldap::NG::Common::Conf::msg
;
my
$conf
=
$lmconf
->getConf or
die
"Unable to get configuration ($!)"
;
my
$localconf
=
$lmconf
->getLocalConf(PORTALSECTION)
or
die
"Unable to get local configuration ($!)"
;
if
(
$localconf
) {
$conf
->{
$_
} =
$localconf
->{
$_
}
foreach
(
keys
%$localconf
);
}
print
"Configuration loaded\n"
if
$debug
;
print
"Timeout value: "
.
$conf
->{timeout} .
"\n"
if
$debug
;
my
@backends
;
my
$module
;
if
(
defined
$conf
->{globalStorage} ) {
$module
=
$conf
->{globalStorage};
eval
"use $module"
;
die
$@
if
($@);
$conf
->{globalStorageOptions}->{backend} =
$module
;
push
@backends
,
$conf
->{globalStorageOptions};
print
"Session backend $module will be used\n"
if
$debug
;
}
else
{
print
STDERR
"Unable to find 'globalStorage' configuration key, aborting\n"
;
exit
1;
}
for
my
$options
(
@backends
) {
next
if
(
$options
->{backend} eq
"Apache::Session::Memcached"
);
foreach
my
$reSession
(
@ARGV
) {
my
$sessions
=
Lemonldap::NG::Common::Apache::Session->searchOnExpr(
$options
,
$conf
->{whatToTrace},
$reSession
);
foreach
my
$id
(
keys
%$sessions
) {
my
$session
= Lemonldap::NG::Common::Session->new(
storageModule
=>
$options
->{backend},
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"
;
$nb_error
++;
next
;
}
unless
(
$session
->remove ) {
print
"Error while deleting session $id\n"
if
$debug
;
print
STDERR
"Error on session $id\n"
;
$nb_error
++;
next
;
}
print
"Session $id has been purged\n"
if
$debug
;
$nb_purged
++;
}
}
}
print
"$nb_purged sessions have been purged\n"
if
$debug
;
print
STDERR
"$nb_error sessions remaining, try to purge them with force (option -f)\n"
if
$nb_error
;
my
$exit
=
$nb_error
? 1 :
$nb_purged
? 0 : 1;
exit
$exit
;