]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - modules/Events.pm
Only log the request to flush the firewall chain in debug mode.
[people/stevee/guardian.git] / modules / Events.pm
index 376438fb25681119ac6df1537e046d8994f01a1d..007ad46305f829036e34a8be48e2ea2d44f461a5 100644 (file)
@@ -14,6 +14,7 @@ my %commands = (
        'flush' => \&CallFlush,
        'reload' => \&main::Reload,
        'reload-ignore-list' => \&main::ReloadIgnoreList,
+       'logrotate' => \&main::Logrotate,
 );
 
 # Hash to store addresses and their current count.
@@ -79,6 +80,34 @@ sub Init (%) {
        return $self;
 }
 
+#
+## The "Update" Block settings function.
+#
+## This object based function is called to update various class settings.
+#
+sub Update (\%) {
+        my $self = shift;
+
+       # Dereference the given hash-ref and store
+       # the values into a new temporary hash.
+       my %settings = %{ $_[0] };
+
+       # Skip settings update if some essential settings are missing.
+       unless ((exists($settings{BlockCount})) && (exists($settings{BlockTime}))) {
+               $logger->Log("err", "Values for BlockCount or BlockTime are missing, keeping previously configured settings.");
+
+               # Return unmodified class object.
+               return $self;
+       }
+
+       # Change settings.
+        $self->{BlockCount} = $settings{BlockCount};
+       $self->{BlockTime} = $settings{BlockTime};
+
+       # Return modified class object.
+        return $self;
+}
+
 #
 ## The main "CheckAction" function.
 #
@@ -291,6 +320,44 @@ sub CallUnblock ($) {
        # Drop address from blockhash.
        delete ($blockhash{$address});
 
+       # Drop address from counthash if the address has been unblocked
+       # by the user. This happens when the called module is "Socket".
+       if ($module eq "Socket") {
+               delete ($counthash{$address});
+       }
+
+       # Everything worked well, return nothing.
+       return undef;
+}
+
+#
+## CallFlush function.
+#
+## This function is responsible for calling the used firewall
+## engine to do a flush of the used firewall chain. This will
+## clean the entire firewall chain.
+#
+sub CallFlush ($) {
+       my $self = shift;
+
+       # Log the call for flushing.
+       $logger->Log("debug", "Flush has been called...");
+
+       # Call flush.
+       my $error = &DoFlush();
+
+       # If an error message is returned, something went wrong.
+       if ($error) {
+               # Exit function and return the error message.
+               return $error;
+       } else {
+               # Flush successfully has been performed.
+               $logger->Log("debug", "Flush successfully has been performed...");
+       }
+
+       # Flush blockhash.
+       %blockhash = ();
+
        # Everything worked well, return nothing.
        return undef;
 }
@@ -417,7 +484,19 @@ sub GenerateIgnoreList($) {
        my $amount = scalar(keys(%ignorehash));
 
        # Write out log message.
-       $logger->Log("debug", "Ignore list currently contains $amount entries.");
+       $logger->Log("debug", "Ignore list currently contains $amount entries:");
+
+       # Sort the ignore hash.
+       my @sorted_addresses = &Guardian::Base::SortAddressHash(\%ignorehash);
+
+       # Loop through the entire array.
+       foreach my $address (@sorted_addresses) {
+               # Log the ignored address.
+               $logger->Log("debug", "\- $address");
+       }
+
+       # Finished return nothing.
+       return;
 }
 
 #