mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-12 14:21:01 +00:00
feat(iplimit): auto-install fail2ban on install and update
IP limit enforcement is gated on fail2ban being present (ce8b1bed), but the bare-metal install.sh/update.sh never installed it, so the feature stayed disabled until the user ran the IP Limit menu by hand. Docker already auto-configures it; bare-metal hosts did not.
Extract the fail2ban install + jail setup out of install_iplimit into a non-interactive setup_fail2ban_iplimit() (no exit/before_show_menu, returns a status) exposed via 'x-ui setup-fail2ban', and call it from install.sh and update.sh after the panel is up. update.sh is the primary update path (x-ui update and the panel self-updater both run it). Honors XUI_ENABLE_FAIL2BAN (proceed only when unset or true, matching the Go gate) and is non-fatal so a fail2ban failure never aborts the install/update.
This commit is contained in:
@@ -854,6 +854,33 @@ config_after_update() {
|
||||
fi
|
||||
}
|
||||
|
||||
# setup_fail2ban auto-installs and configures fail2ban for the IP Limit feature
|
||||
# by invoking the freshly downloaded x-ui CLI. IP Limit is load-bearing on
|
||||
# fail2ban (without it the panel disables the limitIp field and zeroes existing
|
||||
# limits), so updating an older install should make it work without a manual
|
||||
# trip through the IP Limit menu. Non-fatal: a fail2ban failure must never abort
|
||||
# the update. XUI_ENABLE_FAIL2BAN is honored (load_xui_env exports it from the
|
||||
# persisted env file, so a deliberate opt-out survives updates).
|
||||
setup_fail2ban() {
|
||||
if [[ -n "${XUI_ENABLE_FAIL2BAN+x}" && "${XUI_ENABLE_FAIL2BAN}" != "true" ]]; then
|
||||
echo -e "${yellow}XUI_ENABLE_FAIL2BAN=${XUI_ENABLE_FAIL2BAN}, skipping Fail2ban auto-setup.${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! -x /usr/bin/x-ui ]]; then
|
||||
echo -e "${yellow}x-ui CLI not found; skipping Fail2ban auto-setup.${plain}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -e "${green}Setting up Fail2ban for the IP Limit feature...${plain}"
|
||||
if /usr/bin/x-ui setup-fail2ban; then
|
||||
echo -e "${green}Fail2ban setup complete.${plain}"
|
||||
else
|
||||
echo -e "${yellow}Fail2ban setup did not finish; IP Limit stays disabled until you run 'x-ui' and open the IP Limit menu. Continuing.${plain}"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
update_x-ui() {
|
||||
cd ${xui_folder%/x-ui}/
|
||||
|
||||
@@ -1037,6 +1064,11 @@ update_x-ui() {
|
||||
|
||||
config_after_update
|
||||
|
||||
# IP Limit relies on fail2ban; install + configure it now so the feature
|
||||
# works out of the box on update too (no-op when XUI_ENABLE_FAIL2BAN=false).
|
||||
# Never fatal.
|
||||
setup_fail2ban
|
||||
|
||||
echo -e "${green}x-ui ${tag_version}${plain} updating finished, it is running now..."
|
||||
echo -e ""
|
||||
echo -e "┌───────────────────────────────────────────────────────┐
|
||||
|
||||
Reference in New Issue
Block a user