- if (/Shorewall:net-fw:DROP:.* SRC=([^\s]+) DST=.*/ && $1 !~ /$whitelist/) {
- if (Data::Validate::IP::is_ipv4($1)) {
- $ip4s{$1}=1;
- } elsif (Data::Validate::IP::is_ipv6($1)) {
- $ip6s{$1}=1;
+ if (/kernel: net-fw DROP .* SRC=([^\s]+) DST=.*/) {
+ # Save ip
+ my $ip = $1;
+ # Check if v4 ip and not in whitelist
+ if (is_ipv4($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$whitelist{ipv4}}) {
+ $ip4s{$ip}=1;
+ } elsif (is_ipv6($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$whitelist{ipv6}}) {
+ $ip6s{$ip}=1;
+ }
+ } elsif (/op=PAM:authentication grantors=\? acct="(.+)" exe="\/usr\/(?:libexec\/dovecot\/auth|sbin\/sshd)" hostname=.+ addr=(.+) terminal=(?:dovecot|ssh) res=failed/ && grep($_ ne $1, @userlist)) {
+ # Save ip
+ my $ip = $2;
+ # Check if v4 ip and not in whitelist
+ if (is_ipv4($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$whitelist{ipv4}}) {
+ # Add ip in v4 blacklist
+ $ip4s{$ip}=1;
+ # Check if v6 ip
+ } elsif (is_ipv6($ip) && not scalar map { my $network = NetAddr::IP->new($_); my $netip = NetAddr::IP->new($ip); unless ($network->contains($netip)) { (); } } @{$whitelist{ipv6}}) {
+ $ip6s{$ip}=1;