39 lines
781 B
Perl
39 lines
781 B
Perl
|
#!/usr/bin/env perl
|
||
|
#
|
||
|
use 5.024;
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
use autodie;
|
||
|
use Fcntl qw(:flock);
|
||
|
use File::Basename;
|
||
|
use File::stat;
|
||
|
use POSIX qw(strftime);
|
||
|
|
||
|
my $ttl = "300";
|
||
|
my $workdir = dirname($0);
|
||
|
|
||
|
opendir my $dh, "${workdir}/tokens";
|
||
|
while (my $file = readdir $dh) {
|
||
|
chomp $file;
|
||
|
next if $file =~ /^\./;
|
||
|
|
||
|
open my $fh, '<', "${workdir}/tokens/$file";
|
||
|
my $client_ip = <$fh>;
|
||
|
chomp $client_ip;
|
||
|
close $fh;
|
||
|
|
||
|
my $mtime = stat("${workdir}/tokens/${file}")->mtime();
|
||
|
if ((time() - $mtime) > $ttl) {
|
||
|
_log("$client_ip $file removed");
|
||
|
unlink("${workdir}/tokens/${file}");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub _log {
|
||
|
my ($msg) = @_;
|
||
|
open my $fh, '>>', '/var/log/ard.log';
|
||
|
flock $fh, LOCK_EX;
|
||
|
print $fh sprintf("%s %s: %s \n", strftime("%b %d %H:%M:%S", localtime), basename($0), $msg);
|
||
|
close $fh;
|
||
|
}
|