DockerEntrypoint.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # Start fail2ban with the 3x-ipl jail
  3. if [ "$XUI_ENABLE_FAIL2BAN" = "true" ]; then
  4. LOG_FOLDER="${XUI_LOG_FOLDER:-/var/log/x-ui}"
  5. mkdir -p "$LOG_FOLDER"
  6. touch "$LOG_FOLDER/3xipl.log" "$LOG_FOLDER/3xipl-banned.log"
  7. mkdir -p /etc/fail2ban/jail.d /etc/fail2ban/filter.d /etc/fail2ban/action.d
  8. cat > /etc/fail2ban/jail.d/3x-ipl.conf << EOF
  9. [3x-ipl]
  10. enabled=true
  11. backend=auto
  12. filter=3x-ipl
  13. action=3x-ipl
  14. logpath=$LOG_FOLDER/3xipl.log
  15. maxretry=1
  16. findtime=32
  17. bantime=30m
  18. EOF
  19. cat > /etc/fail2ban/filter.d/3x-ipl.conf << 'EOF'
  20. [Definition]
  21. datepattern = ^%Y/%m/%d %H:%M:%S
  22. failregex = \[LIMIT_IP\]\s*Email\s*=\s*<F-USER>.+</F-USER>\s*\|\|\s*Disconnecting OLD IP\s*=\s*<ADDR>\s*\|\|\s*Timestamp\s*=\s*\d+
  23. ignoreregex =
  24. EOF
  25. cat > /etc/fail2ban/action.d/3x-ipl.conf << EOF
  26. [INCLUDES]
  27. before = iptables-allports.conf
  28. [Definition]
  29. actionstart = <iptables> -N f2b-<name>
  30. <iptables> -A f2b-<name> -j <returntype>
  31. <iptables> -I <chain> -p <protocol> -j f2b-<name>
  32. actionstop = <iptables> -D <chain> -p <protocol> -j f2b-<name>
  33. <actionflush>
  34. <iptables> -X f2b-<name>
  35. actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'
  36. actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
  37. echo "\$(date +"%Y/%m/%d %H:%M:%S") BAN [Email] = <F-USER> [IP] = <ip> banned for <bantime> seconds." >> $LOG_FOLDER/3xipl-banned.log
  38. actionunban = <iptables> -D f2b-<name> -s <ip> -j <blocktype>
  39. echo "\$(date +"%Y/%m/%d %H:%M:%S") UNBAN [Email] = <F-USER> [IP] = <ip> unbanned." >> $LOG_FOLDER/3xipl-banned.log
  40. [Init]
  41. name = default
  42. protocol = tcp
  43. chain = INPUT
  44. EOF
  45. fail2ban-client -x start
  46. fi
  47. # Run x-ui
  48. exec /app/x-ui