diff --git a/lib/Virtualmin/Config/Plugin/Fail2ban.pm b/lib/Virtualmin/Config/Plugin/Fail2ban.pm new file mode 100644 index 0000000..6045b56 --- /dev/null +++ b/lib/Virtualmin/Config/Plugin/Fail2ban.pm @@ -0,0 +1,136 @@ +package Virtualmin::Config::Plugin::Fail2ban; +# Enables fail2ban and sets up a reasonable set of rules. +use strict; +use warnings; +no warnings qw(once); +use parent 'Virtualmin::Config::Plugin'; + +our $config_directory; +our (%gconfig, %miniserv); +our $trust_unknown_referers = 1; + +sub new { + my $class = shift; + + # inherit from Plugin + my $self = $class->SUPER::new(name => 'Fail2ban'); + + return $self; +} + +# actions method performs whatever configuration is needed for this +# plugin. XXX Needs to make a backup so changes can be reverted. +sub actions { + my $self = shift; + + # XXX Webmin boilerplate. + use Cwd; + my $cwd = getcwd(); + my $root = $self->root(); + chdir($root); + $0 = "$root/virtual-server/config-system.pl"; + push(@INC, $root); + eval 'use WebminCore'; ## no critic + init_config(); + # End of Webmin boilerplate. + + $self->spin(); + eval { + my @firewall_filters = qw(webmin-auth ); + my @tcpports + = qw(submission domain ftp-data 2222 10000-10010 20000); + my @udpports = qw(domain); + + foreign_require('init', 'init-lib.pl'); + init::enable_at_boot('fail2ban'); + + if (has_command('fail2ban-server')) { + # Create a jail.local with some basic config + create_fail2ban_jail(); + create_fail2ban_firewalld(); + } + + $self->done(1); # OK! + }; + if ($@) { + $self->done(0); + } +} + +sub create_fail2ban_jail { + if (-e "/etc/fail2ban/jail.local") { + die "Fail2ban already has local configuration. Will not overwrite."; + } + open(my $JAIL_LOCAL, '>', '/etc/faiil2ban/jail.local'); +print $JAIL_LOCAL <', '/etc/fail2ban/jail.d/00-firewalld.conf'); + print $FIREWALLD_CONF <