mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
rework the reload function. we must change that to restart, because fail2ban does not apply all changes on reload only
This commit is contained in:
@@ -266,7 +266,7 @@ func SetJailFilterConfigHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Mark reload needed in our UI settings
|
||||
// if err := config.MarkReloadNeeded(); err != nil {
|
||||
// if err := config.MarkRestartNeeded(); err != nil {
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
// return
|
||||
// }
|
||||
@@ -276,7 +276,7 @@ func SetJailFilterConfigHandler(c *gin.Context) {
|
||||
// Return a simple JSON response without forcing a blocking alert
|
||||
// c.JSON(http.StatusOK, gin.H{
|
||||
// "message": "Filter updated, reload needed",
|
||||
// "reloadNeeded": true,
|
||||
// "restartNeeded": true,
|
||||
// })
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ func UpdateJailManagementHandler(c *gin.Context) {
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to reload fail2ban: " + err.Error()})
|
||||
// return
|
||||
//}
|
||||
if err := config.MarkReloadNeeded(); err != nil {
|
||||
if err := config.MarkRestartNeeded(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
@@ -355,8 +355,8 @@ func UpdateSettingsHandler(c *gin.Context) {
|
||||
config.DebugLog("Settings updated successfully (handlers.go)")
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "Settings updated",
|
||||
"reloadNeeded": newSettings.ReloadNeeded,
|
||||
"message": "Settings updated",
|
||||
"restartNeeded": newSettings.RestartNeeded,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -428,8 +428,8 @@ func ApplyFail2banSettings(jailLocalPath string) error {
|
||||
return os.WriteFile(jailLocalPath, []byte(content), 0644)
|
||||
}
|
||||
|
||||
// ReloadFail2banHandler reloads the Fail2ban service
|
||||
func ReloadFail2banHandler(c *gin.Context) {
|
||||
// RestartFail2banHandler reloads the Fail2ban service
|
||||
func RestartFail2banHandler(c *gin.Context) {
|
||||
config.DebugLog("----------------------------")
|
||||
config.DebugLog("ApplyFail2banSettings called (handlers.go)") // entry point
|
||||
|
||||
@@ -439,18 +439,18 @@ func ReloadFail2banHandler(c *gin.Context) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// Then reload
|
||||
if err := fail2ban.ReloadFail2ban(); err != nil {
|
||||
// Then restart
|
||||
if err := fail2ban.RestartFail2ban(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// We set reload done in config
|
||||
if err := config.MarkReloadDone(); err != nil {
|
||||
// We set restart done in config
|
||||
if err := config.MarkRestartDone(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Fail2ban reloaded successfully"})
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Fail2ban restarted successfully"})
|
||||
}
|
||||
|
||||
// *******************************************************************
|
||||
|
||||
@@ -54,8 +54,8 @@ func RegisterRoutes(r *gin.Engine) {
|
||||
// TODO: create or generate new filters
|
||||
// api.POST("/filters/generate", GenerateFilterHandler)
|
||||
|
||||
// Reload endpoint
|
||||
api.POST("/fail2ban/reload", ReloadFail2banHandler)
|
||||
// Restart endpoint
|
||||
api.POST("/fail2ban/restart", RestartFail2banHandler)
|
||||
|
||||
// Handle Fail2Ban notifications
|
||||
api.POST("/ban", BanNotificationHandler)
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
height: 4rem;
|
||||
}
|
||||
|
||||
/* Reload banner */
|
||||
#reloadBanner {
|
||||
/* Restart banner */
|
||||
#restartBanner {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -95,10 +95,10 @@
|
||||
</nav>
|
||||
<!-- ******************************************************************* -->
|
||||
|
||||
<!-- Reload Banner -->
|
||||
<div id="reloadBanner" class="bg-warning text-dark p-3 text-center">
|
||||
<strong data-i18n="reload_banner.message">Configuration changed!</strong>
|
||||
<button class="btn btn-dark" onclick="reloadFail2ban()" data-i18n="reload_banner.button">Reload Fail2ban</button>
|
||||
<!-- Restart Banner -->
|
||||
<div id="restartBanner" class="bg-warning text-dark p-3 text-center">
|
||||
<strong class="p-2" data-i18n="restart_banner.message">Fail2ban configuration changed! To apply the changes, please: </strong>
|
||||
<button class="btn btn-dark" onclick="restartFail2ban()" data-i18n="restart_banner.button">Restart Service</button>
|
||||
</div>
|
||||
|
||||
<!-- ******************************************************************* -->
|
||||
@@ -531,7 +531,7 @@
|
||||
var currentJailForConfig = null;
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
showLoading(true);
|
||||
checkReloadNeeded();
|
||||
checkRestartNeeded();
|
||||
fetchSummary().then(function() {
|
||||
showLoading(false);
|
||||
initializeTooltips(); // Initialize tooltips after fetching and rendering
|
||||
@@ -558,17 +558,17 @@
|
||||
}
|
||||
|
||||
// Check if there is still a reload of the fail2ban service needed
|
||||
function checkReloadNeeded() {
|
||||
function checkRestartNeeded() {
|
||||
fetch('/api/settings')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.reloadNeeded) {
|
||||
document.getElementById('reloadBanner').style.display = 'block';
|
||||
if (data.restartNeeded) {
|
||||
document.getElementById('restartBanner').style.display = 'block';
|
||||
} else {
|
||||
document.getElementById('reloadBanner').style.display = 'none';
|
||||
document.getElementById('restartBanner').style.display = 'none';
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Error checking reloadNeeded:', err));
|
||||
.catch(err => console.error('Error checking restartNeeded:', err));
|
||||
}
|
||||
|
||||
// Load dynamically the other pages when navigating in nav
|
||||
@@ -828,11 +828,11 @@
|
||||
if (data.error) {
|
||||
alert("Error saving config: " + data.error);
|
||||
} else {
|
||||
console.log("Filter saved successfully. Reload needed? " + data.reloadNeeded);
|
||||
console.log("Filter saved successfully. Restart needed? " + data.restartNeeded);
|
||||
var modalEl = document.getElementById('jailConfigModal');
|
||||
var modalObj = bootstrap.Modal.getInstance(modalEl);
|
||||
modalObj.hide();
|
||||
document.getElementById('reloadBanner').style.display = 'block';
|
||||
document.getElementById('restartBanner').style.display = 'block';
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
@@ -901,7 +901,7 @@
|
||||
alert("Error saving jail settings: " + data.error);
|
||||
} else {
|
||||
// A restart of fail2ban is needed, to enable or disable jails - a reload is not enough
|
||||
document.getElementById('reloadBanner').style.display = 'block';
|
||||
document.getElementById('restartBanner').style.display = 'block';
|
||||
}
|
||||
})
|
||||
.catch(function(err) {
|
||||
@@ -1014,9 +1014,9 @@
|
||||
} else {
|
||||
var selectedLang = $('#languageSelect').val();
|
||||
loadTranslations(selectedLang);
|
||||
console.log("Settings saved successfully. Reload needed? " + data.reloadNeeded);
|
||||
if (data.reloadNeeded) {
|
||||
document.getElementById('reloadBanner').style.display = 'block';
|
||||
console.log("Settings saved successfully. Restart needed? " + data.restartNeeded);
|
||||
if (data.restartNeeded) {
|
||||
document.getElementById('restartBanner').style.display = 'block';
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1133,19 +1133,19 @@
|
||||
}
|
||||
|
||||
//*******************************************************************
|
||||
//* Reload fail2ban action : *
|
||||
//* Restart fail2ban action : *
|
||||
//*******************************************************************
|
||||
|
||||
function reloadFail2ban() {
|
||||
if (!confirm("It can happen that some logs are not parsed during the reload of fail2ban. Reload Fail2ban now?")) return;
|
||||
function restartFail2ban() {
|
||||
if (!confirm("Keep in mind that while fail2ban is restarting, logs are not being parsed and no IP addresses are blocked. Restart fail2ban now? This will take some time.")) return;
|
||||
showLoading(true);
|
||||
fetch('/api/fail2ban/reload', { method: 'POST' })
|
||||
fetch('/api/fail2ban/restart', { method: 'POST' })
|
||||
.then(function(res) { return res.json(); })
|
||||
.then(function(data) {
|
||||
if (data.error) {
|
||||
alert("Error: " + data.error);
|
||||
} else {
|
||||
document.getElementById('reloadBanner').style.display = 'none';
|
||||
document.getElementById('restartBanner').style.display = 'none';
|
||||
return fetchSummary();
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user