Skip to content

Commit fa86f89

Browse files
committed
Fix configuring Fail2Ban on mini stacks
1 parent 1e0ee60 commit fa86f89

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

lib/Virtualmin/Config/Plugin/Fail2ban.pm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ sub actions {
4747
init::enable_at_boot('fail2ban');
4848

4949
# Create a jail.local with some basic config
50-
create_fail2ban_jail();
50+
create_fail2ban_jail($self);
5151
create_fail2ban_firewalld();
5252

5353
# Switch backend to use systemd to avoid failure on
@@ -79,7 +79,7 @@ sub actions {
7979
}
8080

8181
sub create_fail2ban_jail {
82-
82+
my $self = shift;
8383
# Postfix addendum
8484
my $postfix_jail_extra = "";
8585

@@ -119,6 +119,13 @@ sub create_fail2ban_jail {
119119
$proftpd_jail_extra
120120
.= ' \(\S+\[<HOST>\]\)[: -]+ Maximum login attempts \(\d+\) exceeded\s+$';
121121
}
122+
my $mini_stack =
123+
(defined $self->bundle() && $self->bundle() =~ /mini/i) ?
124+
($self->bundle() =~ /LEMP/i ? 'LEMP' : 'LAMP') : 0;
125+
my $proftpd_block = $mini_stack ? '' :
126+
"[proftpd]\n" .
127+
"enabled = true$proftpd_jail_extra\n\n";
128+
122129
open(my $JAIL_LOCAL, '>', '/etc/fail2ban/jail.local');
123130
print $JAIL_LOCAL <<EOF;
124131
[dovecot]
@@ -130,10 +137,7 @@ enabled = true
130137
[postfix-sasl]
131138
enabled = true$postfix_jail_extra
132139
133-
[proftpd]
134-
enabled = true$proftpd_jail_extra
135-
136-
[sshd]
140+
${proftpd_block}[sshd]
137141
enabled = true
138142
139143
[webmin-auth]

lib/Virtualmin/Config/Plugin/Fail2banFirewalld.pm

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ sub actions {
5353
init::enable_at_boot('fail2ban');
5454

5555
# Create a jail.local with some basic config
56-
create_fail2ban_jail();
56+
create_fail2ban_jail($self);
5757
create_fail2ban_firewalld();
5858

5959
# Switch backend to use systemd to avoid failure on
@@ -85,7 +85,7 @@ sub actions {
8585
}
8686

8787
sub create_fail2ban_jail {
88-
88+
my $self = shift;
8989
# Postfix addendum
9090
my $postfix_jail_extra = "";
9191

@@ -125,6 +125,13 @@ sub create_fail2ban_jail {
125125
$proftpd_jail_extra
126126
.= ' \(\S+\[<HOST>\]\)[: -]+ Maximum login attempts \(\d+\) exceeded\s+$';
127127
}
128+
my $mini_stack =
129+
(defined $self->bundle() && $self->bundle() =~ /mini/i) ?
130+
($self->bundle() =~ /LEMP/i ? 'LEMP' : 'LAMP') : 0;
131+
my $proftpd_block = $mini_stack ? '' :
132+
"[proftpd]\n" .
133+
"enabled = true$proftpd_jail_extra\n\n";
134+
128135
open(my $JAIL_LOCAL, '>', '/etc/fail2ban/jail.local');
129136
print $JAIL_LOCAL <<EOF;
130137
[dovecot]
@@ -136,10 +143,7 @@ enabled = true
136143
[postfix-sasl]
137144
enabled = true$postfix_jail_extra
138145
139-
[proftpd]
140-
enabled = true$proftpd_jail_extra
141-
142-
[sshd]
146+
${proftpd_block}[sshd]
143147
enabled = true
144148
145149
[webmin-auth]

0 commit comments

Comments
 (0)