]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - modules/Events.pm
Revert "Except and log if an event could not be parsed correctly."
[people/stevee/guardian.git] / modules / Events.pm
index cfc785ffc24ba00f430a4345558f79560b83fdd7..025fe4f243fa4e685d3dabb6cf83a97ccd22feb3 100644 (file)
@@ -12,6 +12,7 @@ my %commands = (
        'block' => \&CallBlock,
        'unblock' => \&CallUnblock,
        'flush' => \&CallFlush,
+       'reload' => \&main::Reload,
 );
 
 # Hash to store addresses and their current count.
@@ -22,9 +23,14 @@ my %counthash = ();
 my %blockhash = ();
 
 # Hash to store user-defined IP addresses and/or subnets which should be
-# ignored in case any events should be repored for them.
+# ignored in case any events should be repored for them. 
 my %ignorehash = ();
 
+# Array to store localhost related IP addresses.
+# They are always white-listed to prevent guardian from blocking
+# any local traffic.
+my @localhost_addresses = ("127.0.0.1", "::1");
+
 # This object will contain the reference to the logger object after calling Init.
 my $logger;
 
@@ -63,6 +69,9 @@ sub Init (%) {
        if (exists($self->{IgnoreFile})) {
                # Call function to handle the ignore mechanism.
                &GenerateIgnoreList($self->{IgnoreFile});
+       } else {
+               # Whitelist local addresses.
+               %ignorehash = &_whitelist_localhost();
        }
 
        # Return the class object.
@@ -301,6 +310,10 @@ sub GenerateIgnoreList($) {
                return;
        }
 
+       # Reset current ignore hash and add
+       # localhost related IP addresses.
+       %ignorehash = &_whitelist_localhost();
+
        # Open the given IgnoreFile. 
        open (IGNORE, $file);
 
@@ -337,6 +350,12 @@ sub GenerateIgnoreList($) {
 
        # Close filehandle for the IgnoreFile.
        close (IGNORE);
+
+       # Get amount of current elements in hash.
+       my $amount = scalar(keys(%ignorehash));
+
+       # Write out log message.
+       $logger->Log("debug", "Ignore list currently contains $amount entries.");
 }
 
 #
@@ -404,4 +423,30 @@ sub _IsOnIgnoreList ($) {
        return;
 }
 
+#
+## The _whitelist_localhost function.
+#
+## This tiny private function simple generates and returns a hash which contains
+## the clear and binary converted addresses for all array-stored
+## (@localhost_addresses) in an ignorelist compatible format.
+#
+sub _whitelist_localhost () {
+       my %temphash;
+
+       # Loop through the array of localhost related addresses.
+       foreach my $address (@localhost_addresses) {
+               # Validate and convert the addresss into binary format.
+               my @values = &Guardian::Base::IPOrNet2Int($address);
+
+               # Check if any values are returned.
+               if (@values) {
+                       # Store the converted binary values in the temporary hash.
+                       $temphash{$address} = [@values];
+               }
+       }
+
+       # Return the temporary hash.
+       return %temphash;
+}
+
 1;