Add proto and port support in masq templates

This commit is contained in:
Daniel Berteaud 2013-05-02 01:15:52 +02:00
parent a99711dd02
commit bc6518ba96

View File

@ -7,12 +7,18 @@
/sbin/iptables --new-chain $NEW_Fail2Ban
EOF
foreach my $ban ( $f2bdb->get_all_by_prop(type=>('ban')) ){
$OUT .= " /sbin/iptables --append \$NEW_Fail2Ban" .
" -s " . $ban->key . " -j denylog\n"
if ( ($fail2ban{'status'} || 'disabled') eq 'enabled' );
$OUT .= " /sbin/iptables --append \$NEW_Fail2Ban" .
" -j RETURN\n";
if ( ($fail2ban{'status'} || 'disabled') eq 'enabled' ){
foreach my $ban ( $f2bdb->get_all_by_prop(type=>('ban')) ){
my $ip = $ban->prop('Host');
my $proto = $ban->prop('Protocol') || '';
my $port = $ban->prop('Port') || '';
$OUT .= " /sbin/iptables --append \$NEW_Fail2Ban -s $ip";
$OUT .= " -p $proto" if ($proto =~ m/^tcp|udp|icmp$/);
$OUT .= " --dport $port" if ($proto =~ m/^tcp|udp$/ && $port =~ m/^\d+$/);
$OUT .= " -j denylog\n"
$OUT .= " /sbin/iptables --append \$NEW_Fail2Ban" .
" -j RETURN\n";
}
}
# Having created a new Fail2Ban chain, activate it and destroy the old.