mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
Dedublicate banner stuff and add missing init-vars for banactions
This commit is contained in:
@@ -132,6 +132,24 @@ const (
|
||||
actionServerIDPlaceholder = "__SERVER_ID__"
|
||||
)
|
||||
|
||||
// jailLocalBanner is the standard banner for jail.local files
|
||||
const jailLocalBanner = `################################################################################
|
||||
# Fail2Ban-UI Managed Configuration
|
||||
#
|
||||
# WARNING: This file is automatically managed by Fail2Ban-UI.
|
||||
# DO NOT EDIT THIS FILE MANUALLY - your changes will be overwritten.
|
||||
#
|
||||
# This file overrides settings from /etc/fail2ban/jail.conf
|
||||
# Custom jail configurations should be placed in /etc/fail2ban/jail.d/
|
||||
################################################################################
|
||||
|
||||
`
|
||||
|
||||
// JailLocalBanner returns the standard banner for jail.local files
|
||||
func JailLocalBanner() string {
|
||||
return jailLocalBanner
|
||||
}
|
||||
|
||||
const fail2banActionTemplate = `[INCLUDES]
|
||||
|
||||
before = sendmail-common.conf
|
||||
@@ -771,18 +789,8 @@ func ensureJailLocalStructure() error {
|
||||
return updateJailLocalDefaultSection(settings)
|
||||
}
|
||||
|
||||
// Build the banner
|
||||
banner := `################################################################################
|
||||
# Fail2Ban-UI Managed Configuration
|
||||
#
|
||||
# WARNING: This file is automatically managed by Fail2Ban-UI.
|
||||
# DO NOT EDIT THIS FILE MANUALLY - your changes will be overwritten.
|
||||
#
|
||||
# This file overrides settings from /etc/fail2ban/jail.conf
|
||||
# Custom jail configurations should be placed in /etc/fail2ban/jail.d/
|
||||
################################################################################
|
||||
|
||||
`
|
||||
// Use the standard banner
|
||||
banner := jailLocalBanner
|
||||
|
||||
// Build [DEFAULT] section
|
||||
// Convert IgnoreIPs array to space-separated string
|
||||
@@ -846,7 +854,8 @@ func updateJailLocalDefaultSection(settings AppSettings) error {
|
||||
return fmt.Errorf("failed to read jail.local: %w", err)
|
||||
}
|
||||
|
||||
lines := strings.Split(string(content), "\n")
|
||||
contentStr := string(content)
|
||||
lines := strings.Split(contentStr, "\n")
|
||||
var outputLines []string
|
||||
inDefault := false
|
||||
defaultUpdated := false
|
||||
@@ -878,9 +887,23 @@ func updateJailLocalDefaultSection(settings AppSettings) error {
|
||||
}
|
||||
keysUpdated := make(map[string]bool)
|
||||
|
||||
// Always add the full banner at the start
|
||||
outputLines = append(outputLines, strings.Split(strings.TrimRight(jailLocalBanner, "\n"), "\n")...)
|
||||
|
||||
// Skip everything before [DEFAULT] section (old banner, comments, empty lines)
|
||||
foundSection := false
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if strings.HasPrefix(trimmed, "[") && strings.HasSuffix(trimmed, "]") {
|
||||
// Found a section - stop skipping and process this line
|
||||
foundSection = true
|
||||
}
|
||||
if !foundSection {
|
||||
// Skip lines before any section (old banner, comments, empty lines)
|
||||
continue
|
||||
}
|
||||
|
||||
// Process lines after we found a section
|
||||
if strings.HasPrefix(trimmed, "[") && strings.HasSuffix(trimmed, "]") {
|
||||
sectionName := strings.Trim(trimmed, "[]")
|
||||
if sectionName == "DEFAULT" {
|
||||
|
||||
Reference in New Issue
Block a user