mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-26 09:52:14 +03: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:
30
install.sh
30
install.sh
@@ -1300,6 +1300,32 @@ EOF
|
||||
${xui_folder}/x-ui migrate
|
||||
}
|
||||
|
||||
# setup_fail2ban auto-installs and configures fail2ban for the IP Limit feature
|
||||
# by invoking the freshly installed x-ui CLI. IP Limit is load-bearing on
|
||||
# fail2ban (without it the panel disables the limitIp field and zeroes existing
|
||||
# limits), so a fresh install should make it work out of the box, just like the
|
||||
# Docker image already does. Non-fatal by design: a fail2ban failure must never
|
||||
# abort the panel install.
|
||||
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
|
||||
}
|
||||
|
||||
install_x-ui() {
|
||||
cd ${xui_folder%/x-ui}/
|
||||
|
||||
@@ -1487,6 +1513,10 @@ install_x-ui() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# IP Limit relies on fail2ban; install + configure it now so the feature
|
||||
# works out of the box (no-op when XUI_ENABLE_FAIL2BAN=false). Never fatal.
|
||||
setup_fail2ban
|
||||
|
||||
echo -e "${green}x-ui ${tag_version}${plain} installation finished, it is running now..."
|
||||
echo -e ""
|
||||
echo -e "┌───────────────────────────────────────────────────────┐
|
||||
|
||||
Reference in New Issue
Block a user