mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-19 06:53:14 +02:00
Optimize error-reporting of failure when reloading fail2ban
This commit is contained in:
@@ -155,7 +155,11 @@ function saveJailConfig() {
|
||||
return;
|
||||
}
|
||||
closeModal('jailConfigModal');
|
||||
showToast(t('filter_debug.save_success', 'Filter and jail config saved and reloaded'), 'success');
|
||||
if (data.warning) {
|
||||
showToast(t('filter_debug.save_reload_warning', 'Config saved, but fail2ban reload failed') + ': ' + data.warning, 'warning', 12000);
|
||||
} else {
|
||||
showToast(t('filter_debug.save_success', 'Filter and jail config saved and reloaded'), 'success');
|
||||
}
|
||||
return refreshData({ silent: true });
|
||||
})
|
||||
.catch(function(err) {
|
||||
@@ -468,17 +472,17 @@ function saveManageJailsSingle(checkbox) {
|
||||
console.error('Could not find jail name span');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const jailName = nameSpan.textContent.trim();
|
||||
if (!jailName) {
|
||||
console.error('Jail name is empty');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const isEnabled = checkbox.checked;
|
||||
const updatedJails = {};
|
||||
updatedJails[jailName] = isEnabled;
|
||||
|
||||
|
||||
console.log('Saving jail state:', jailName, 'enabled:', isEnabled, 'payload:', updatedJails);
|
||||
|
||||
// Send updated state to the API endpoint /api/jails/manage.
|
||||
@@ -500,22 +504,20 @@ function saveManageJailsSingle(checkbox) {
|
||||
if (data.error) {
|
||||
var errorMsg = data.error;
|
||||
var toastType = 'error';
|
||||
|
||||
|
||||
// If jails were auto-disabled, check if this jail was one of them
|
||||
var wasAutoDisabled = data.autoDisabled && data.enabledJails && Array.isArray(data.enabledJails) && data.enabledJails.indexOf(jailName) !== -1;
|
||||
|
||||
|
||||
if (wasAutoDisabled) {
|
||||
checkbox.checked = false;
|
||||
toastType = 'warning';
|
||||
// Use the message if available, otherwise use the error
|
||||
errorMsg = data.message || errorMsg;
|
||||
} else {
|
||||
// Revert checkbox state on error
|
||||
checkbox.checked = !isEnabled;
|
||||
}
|
||||
|
||||
showToast(errorMsg, toastType);
|
||||
|
||||
|
||||
showToast(errorMsg, toastType, wasAutoDisabled ? 15000 : undefined);
|
||||
|
||||
// Still reload the jail list to reflect the actual state
|
||||
return fetch(withServerParam('/api/jails/manage'), {
|
||||
headers: serverHeaders()
|
||||
|
||||
Reference in New Issue
Block a user