sub checkaction {
my ($source, $message) = @_;
- # Call block subfunction again if we got a higher count than the
- # configured blockcount.
- if ($addresshash{$source} >= $blockcount) {
- &call_block($source);
- return 0;
- }
-
# Check if the source address equals the hosts ip address.
# This will prevent us from nuking ourselves.
return 1 if ($source eq $hostipaddr);
return 1 if ($source eq $gatewayaddr);
# Watch if the source address is part of our ignore list.
- if ($ignorehash{$source} == 1) {
+ if (exists $ignorehash{$source}) {
&logger("info", "Ignoring attack because $source is in my ignore list!\n");
return 1;
}
}
# Start counting for new source addresses.
- if ($addresshash{$source} eq "") {
- # Set addresshash to "1".
- $addresshash{$source} = 1;
-
+ unless (exists $addresshash{$source}) {
&logger("debug", "Start counting for $source\n");
- return 0;
+
+ # Set count to "1".
+ $addresshash{$source} = 1;
} else {
# Increase counting of existing addresses.
$addresshash{$source} = $addresshash{$source} + 1;
&logger("debug", "Source $source current count $addresshash{$source}.\n");
}
- # Check if the "source" reached our blocking count (default 3).
- if ($addresshash{$source} eq $blockcount ) {
+ # Check if the "source" has reached or passed the block count (default 3).
+ if ($addresshash{$source} >= $blockcount ) {
# Write out log message.
&logger("info", "Blocking $source: $message\n");
# Block the source address.
&call_block($source);
-
- # Update the addresshash.
- $addresshash{$source} = $addresshash{$source} + 1;
- return 0;
}
+
}
#
# Check if the address currently is not blocked.
if ($blockhash{"$address"} eq "") {
# Call guardianctrl to block the address.
- system("$guardianctrl block $address");
+ system("$guardianctrl block $address >/dev/null 2>&1");
}
# Reblock an address if it already has been blocked,
elsif (exists $blockhash{"$address"}) {
# Try to unblock the address to prevent from
# doubble entries in iptables chain.
- system("$guardianctrl unblock $address");
+ system("$guardianctrl unblock $address >/dev/null 2>&1");
# Call guardianctrl to block the address.
- system("$guardianctrl block $address");
+ system("$guardianctrl block $address >/dev/null 2>&1");
}
# Store/update the generated expire time.
my $address = $_[0];
# Call guardianctrl to unblock the address.
- system ("$guardianctrl unblock $address");
+ system ("$guardianctrl unblock $address >/dev/null 2>&1");
}
#