From 4019f47de2c38cb8f02cb77c1766dbb1cc69adb1 Mon Sep 17 00:00:00 2001 From: ilyusha Date: Thu, 3 Sep 2026 21:42:14 +0300 Subject: [PATCH] fix(x-ui.sh): put the fail2ban backend override in jail.d, not jail.conf (#6392) * fix(x-ui.sh): put the fail2ban backend override in jail.d, not jail.conf create_iplimit_jails switched the global fail2ban backend to systemd on Debian 12+ and Ubuntu 22.04+ with sed on /etc/fail2ban/jail.conf. That file is the package's conffile: the next fail2ban upgrade either drops the edit or keeps a stale jail.conf, depending on the conffile prompt. Write the same override to /etc/fail2ban/jail.d/3x-ipl-backend.conf, which fail2ban reads after jail.conf and which upgrades leave alone, and remove it together with the other 3x-ipl files on uninstall. The 3x-ipl jail itself keeps its explicit backend=auto. Assisted-by: Claude Code:claude-fable-5-1 * fix(x-ui.sh): only override the stock fail2ban backend, keep it on partial removal Review follow-ups. The old sed only rewrote a literal 'backend = auto' in jail.conf's [DEFAULT], so an operator's own backend survived it; the override file was written unconditionally. Write it only when jail.conf still carries the stock value. And keep the file when only the IP-limit jail is removed: the sed was never reverted either, and deleting a [DEFAULT] override there would flip every inheriting jail back to auto on the restart in the same branch. The full /etc/fail2ban removal path still deletes it. Assisted-by: Claude Code:claude-fable-5-1 --- x-ui.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/x-ui.sh b/x-ui.sh index e9d74a9a5..7213ff3e2 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -2505,9 +2505,14 @@ create_iplimit_jails() { # Uncomment 'allowipv6 = auto' in fail2ban.conf sed -i 's/#allowipv6 = auto/allowipv6 = auto/g' /etc/fail2ban/fail2ban.conf - # On Debian 12+ and Ubuntu 22.04+ fail2ban's default backend should be changed to systemd - if [[ ( "${release}" == "debian" && ${os_version} -ge 12 ) || ( "${release}" == "ubuntu" && ${os_version} -ge 2200 ) ]]; then - sed -i '0,/action =/s/backend = auto/backend = systemd/' /etc/fail2ban/jail.conf + # Debian 12+ / Ubuntu 22.04+ log sshd to the journal only; a jail.d override + # survives package upgrades. Only the stock 'backend = auto' is overridden. + if [[ ( "${release}" == "debian" && ${os_version} -ge 12 ) || ( "${release}" == "ubuntu" && ${os_version} -ge 2200 ) ]] && + sed -n '0,/action =/p' /etc/fail2ban/jail.conf | grep -q '^backend = auto'; then + cat << EOF > /etc/fail2ban/jail.d/3x-ipl-backend.conf +[DEFAULT] +backend = systemd +EOF fi cat << EOF > /etc/fail2ban/jail.d/3x-ipl.conf