Permalink
Browse files

Read jails from jail.local file

  • Loading branch information...
jcameron committed May 23, 2014
1 parent c768cc2 commit eee243a6cd2e13bcc87d48a88bba3875ec06e929
Showing with 20 additions and 6 deletions.
  1. +15 −4 fail2ban/fail2ban-lib.pl
  2. +5 −2 fail2ban/save_jail.cgi
View
@@ -72,7 +72,18 @@ sub list_jails
my @rv;
my $jfile = "$config{'config_dir'}/jail.conf";
if (-r $jfile) {
- push(@rv, &parse_config_file("$config{'config_dir'}/jail.conf"));
+ push(@rv, &parse_config_file($jfile));
+ }
+my $jlfile = "$config{'config_dir'}/jail.local";
+if (-r $jlfile) {
+ # Add jails from .local file that aren't directive-level overrides
+ my @lrv = &parse_config_file($jlfile);
+ my %names = map { $_->{'name'}, $_ } @rv;
+ foreach my $j (@lrv) {
+ if (!$names{$j->{'name'}}) {
+ push(@rv, $j);
+ }
+ }
}
my $jdir = "$config{'config_dir'}/jail.d";
if (-d $jdir) {
@@ -204,11 +215,11 @@ sub modify_section
&flush_file_lines($file);
}
-# delete_section(file, &section)
+# delete_section(file, &section, [keep-file])
# Remove a section and all directives from a file
sub delete_section
{
-my ($file, $sect) = @_;
+my ($file, $sect, $keepfile) = @_;
my $lref = &read_file_lines($file);
splice(@$lref, $sect->{'line'}, $sect->{'eline'} - $sect->{'line'} + 1);
my $empty = 1;
@@ -217,7 +228,7 @@ sub delete_section
$ll =~ s/^\s*#.*//;
$empty = 0 if ($ll =~ /\S/);
}
-if ($empty) {
+if ($empty && !$keepfile) {
# File is now empty, so delete it
&unflush_file_lines($file);
&unlink_file($file);
View
@@ -13,8 +13,10 @@ my @jails = &list_jails();
if ($in{'new'}) {
# Create new jail object
+ my $jfile = "$config{'config_dir'}/jail.conf";
+ my $jlfile = "$config{'config_dir'}/jail.local";
$jail = { 'members' => [ ],
- 'file' => "$config{'config_dir'}/jail.conf" };
+ 'file' => -r $jlfile ? $jlfile : $jfile };
}
else {
# Find existing jail
@@ -25,7 +27,8 @@ else {
if ($in{'delete'}) {
# Just delete the jail
&lock_file($jail->{'file'});
- &delete_section($jail->{'file'}, $jail);
+ &delete_section($jail->{'file'}, $jail,
+ $jail->{'file'} =~ /jail.local$/ ? 1 : 0);
&unlock_file($jail->{'file'});
}
else {

0 comments on commit eee243a

Please sign in to comment.