diff --git a/pkg/web/advanced_actions.go b/pkg/web/advanced_actions.go index 61c4a73..d5ec814 100644 --- a/pkg/web/advanced_actions.go +++ b/pkg/web/advanced_actions.go @@ -1,3 +1,19 @@ +// Fail2ban UI - A Swiss made, management interface for Fail2ban. +// +// Copyright (C) 2026 Swissmakers GmbH (https://swissmakers.ch) +// +// Licensed under the GNU General Public License, Version 3 (GPL-3.0) +// You may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package web import ( @@ -14,6 +30,10 @@ import ( "github.com/swissmakers/fail2ban-ui/internal/storage" ) +// ========================================================================= +// Threshold Evaluation +// ========================================================================= + func evaluateAdvancedActions(ctx context.Context, settings config.AppSettings, server config.Fail2banServer, ip string) { cfg := settings.AdvancedActions if !cfg.Enabled || cfg.Threshold <= 0 || cfg.Integration == "" { @@ -38,6 +58,7 @@ func evaluateAdvancedActions(ctx context.Context, settings config.AppSettings, s return } + // Only if everything above is ok, we execute the configured "advanced actions" integration. if err := runAdvancedIntegrationAction(ctx, "block", ip, settings, server, map[string]any{ "reason": "automatic_threshold", "count": count, @@ -47,6 +68,10 @@ func evaluateAdvancedActions(ctx context.Context, settings config.AppSettings, s } } +// ========================================================================= +// Integration Execution +// ========================================================================= + func runAdvancedIntegrationAction(ctx context.Context, action, ip string, settings config.AppSettings, server config.Fail2banServer, details map[string]any, skipLoggingIfAlreadyBlocked bool) error { cfg := settings.AdvancedActions if cfg.Integration == "" { @@ -92,7 +117,6 @@ func runAdvancedIntegrationAction(ctx context.Context, action, ip string, settin message = err.Error() } - // If IP is already blocked, don't update the database entry - leave existing entry as is if !skipLoggingIfAlreadyBlocked { if details == nil { details = map[string]any{}