Add a cleanup script to purge rules in case fail2ban lost them

tags/0.0.1
Daniel Berteaud 12 years ago
parent c5685730a7
commit 242cdc05a3
  1. 27
      root/etc/cron.daily/cleanup_fail2ban
  2. 1
      smeserver-fail2ban.spec

@ -0,0 +1,27 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use esmith::ConfigDB;
my $c = esmith::ConfigDB->open_ro;
my $f = esmith::ConfigDB->open('fail2ban');
my $f2b = $c->get('fail2ban');
exit (0) unless ($f2b);
my $bantime = $f2b->prop('BanTime') || '1800';
my $mod = 0;
foreach my $ban ($f->get_all_by_prop( type => 'ban')){
my $ts = $ban->prop('Timestamp') || time;
if ( ($ts + $bantime) < time ){
$ban->delete;
$mod = 1;
}
}
if ($mod == 1){
die "An error occured during fail2ban rule update\n"
unless (system('/sbin/e-smith/signal-event fail2ban-update') == 0);
}
exit (0);

@ -38,6 +38,7 @@ perl createlinks
/bin/rm -f %{name}-%{version}-filelist
/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \
--dir /var/log/fail2ban 'attr(0750,root,root)' \
--file /etc/cron.daily/cleanup_fail2ban 'attr(0755,root,root)' \
> %{name}-%{version}-filelist
%files -f %{name}-%{version}-filelist

Loading…
Cancel
Save