blob: 4cc53ce20e16d5eeb084f67534b8a9abe901417d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/perl -T
#----------------------------------------------------------------------
# Fripost's admin panel - session prune job
# Copyright © 2018 Fripost
# Copyright © 2018 Guilhem Moulin <guilhem@fripost.org>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, 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 Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#----------------------------------------------------------------------
use strict;
use warnings;
use lib "lib";
use Fripost::Util "read_config";
my %CONFIG = read_config();
$CONFIG{www} //= {};
my $cache = Fripost::Util::session_cache(%{$CONFIG{www}});
if (-t \*STDOUT) {
my $count = 0;
my $count_expired = 0;
require "POSIX.pm";
foreach my $k ($cache->get_keys()) {
$count++;
my $obj = $cache->get_object($k) // next;
if ($obj->is_expired) {
$count_expired++;
my $date = POSIX::strftime("%Y-%m-%d %T %z",
localtime($obj->expires_at()));
printf " - %-32s expired on %s\n", $k, $date;
}
}
print "$count keys founds (incl. $count_expired expired keys)\n";
print "Purging...\n"
}
$cache->purge();
if (-t \*STDOUT) {
my $count = 0;
$count++ foreach $cache->get_keys();
print "$count keys left after purge()\n";
}
|