# Used variables and default values..
my $configfile = "$General::swroot/guardian/guardian.conf";
+my $blockcount;
my $ignorefile;
my $loglevel;
my $logfile;
my ($source, $message) = @_;
# Do nothing if the source allready has been blocked.
- return 0 if ($addresshash{$source} > 4);
+ return 0 if ($addresshash{$source} >= $blockcount);
# Check if the source address equals the hosts ip address.
# This will prevent us from nuking ourselves.
}
}
- # Check if the "source" reached our blocking count (4).
- if ( $addresshash{$source} == 4 ) {
- # 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;
- }
# Start counting for new source addresses.
- elsif ($addresshash{$source} eq "") {
+ if ($addresshash{$source} eq "") {
# Set addresshash to "1".
$addresshash{$source} = 1;
} else {
# Increase counting of existing addresses.
$addresshash{$source} = $addresshash{$source}+1;
- &logger("debug", "Source $source count $addresshash{$source} - No action done yet.\n");
+ &logger("debug", "Source $source current count $addresshash{$source}.\n");
+ }
+
+ # Check if the "source" reached our blocking count (default 3).
+ if ( $addresshash{$source} eq $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;
}
}
$TimeLimit = $1;
}
+ # Omit BlockCount, when a host shoult be blocked.
+ if (/BlockCount\s+(.*)/) {
+ $blockcount = $1;
+ }
+
# HostGatewayByte for automatically adding the gateway to
# the ignore hash.
if (/HostGatewayByte\s+(.*)/) {
$options{"d"} = 1;
}
+ # Check if the BlockCount is a valid number.
+ if (! $blockcount =~ /^\d+$/) {
+ &logger("debug", "Got no or invalid BlockCount from config file. Using default one (5).\n");
+ $blockcount = "3";
+ }
+
# Check if guardianctrl is available.
if (! -e $guardianctrl) {
print "Error! Could not find $guardianctrl. Exiting. \n";