Optimize error-reporting of failure when reloading fail2ban

This commit is contained in:
2026-02-11 17:02:18 +01:00
parent bdfd96b65d
commit 08112ff9b9
10 changed files with 58 additions and 24 deletions

View File

@@ -1458,12 +1458,10 @@ func SetJailFilterConfigHandler(c *gin.Context) {
// Reload fail2ban
config.DebugLog("Reloading fail2ban")
if err := conn.Reload(c.Request.Context()); err != nil {
config.DebugLog("Failed to reload fail2ban: %v", err)
// Still return success but warn about reload failure
// The config was saved successfully, user can manually reload
log.Printf("⚠️ Config saved but fail2ban reload failed: %v", err)
c.JSON(http.StatusOK, gin.H{
"message": "Config saved successfully, but fail2ban reload failed",
"warning": "Please check the fail2ban configuration and reload manually: " + err.Error(),
"warning": err.Error(),
})
return
}
@@ -1908,13 +1906,9 @@ func UpdateJailManagementHandler(c *gin.Context) {
}
}
// Update errMsg with detailed error output when debug mode is enabled
settings := config.GetSettings()
if settings.Debug && detailedErrorOutput != "" {
errMsg = fmt.Sprintf("%s\n\nDetailed error output:\n%s", errMsg, detailedErrorOutput)
} else if detailedErrorOutput != "" {
// Even without debug mode, include basic error info
errMsg = fmt.Sprintf("%s (check debug mode for details)", errMsg)
if detailedErrorOutput != "" {
// We use only the extracted error output
errMsg = strings.TrimSpace(detailedErrorOutput)
}
// If any jails were enabled in this request and reload failed, disable them all