mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Fail2ban - Real-Time logs
This commit is contained in:
parent
610db7827d
commit
ac84553a68
1 changed files with 19 additions and 9 deletions
28
x-ui.sh
28
x-ui.sh
|
@ -1170,6 +1170,7 @@ run_speedtest() {
|
||||||
# Run Speedtest
|
# Run Speedtest
|
||||||
speedtest
|
speedtest
|
||||||
}
|
}
|
||||||
|
|
||||||
create_iplimit_jails() {
|
create_iplimit_jails() {
|
||||||
# Use default bantime if not passed => 15 minutes
|
# Use default bantime if not passed => 15 minutes
|
||||||
local bantime="${1:-15}"
|
local bantime="${1:-15}"
|
||||||
|
@ -1177,7 +1178,7 @@ create_iplimit_jails() {
|
||||||
# Uncomment 'allowipv6 = auto' in fail2ban.conf
|
# Uncomment 'allowipv6 = auto' in fail2ban.conf
|
||||||
sed -i 's/#allowipv6 = auto/allowipv6 = auto/g' /etc/fail2ban/fail2ban.conf
|
sed -i 's/#allowipv6 = auto/allowipv6 = auto/g' /etc/fail2ban/fail2ban.conf
|
||||||
|
|
||||||
#On Debian 12+ fail2ban's default backend should be changed to systemd
|
# On Debian 12+ fail2ban's default backend should be changed to systemd
|
||||||
if [[ "${release}" == "debian" && ${os_version} -ge 12 ]]; then
|
if [[ "${release}" == "debian" && ${os_version} -ge 12 ]]; then
|
||||||
sed -i '0,/action =/s/backend = auto/backend = systemd/' /etc/fail2ban/jail.conf
|
sed -i '0,/action =/s/backend = auto/backend = systemd/' /etc/fail2ban/jail.conf
|
||||||
fi
|
fi
|
||||||
|
@ -1187,7 +1188,7 @@ create_iplimit_jails() {
|
||||||
enabled=true
|
enabled=true
|
||||||
backend=auto
|
backend=auto
|
||||||
filter=3x-ipl
|
filter=3x-ipl
|
||||||
action=3x-ipl
|
action = %(known/action)s[name=%(__name__)s, protocol="%(protocol)s", chain="%(chain)s"]
|
||||||
logpath=${iplimit_log_path}
|
logpath=${iplimit_log_path}
|
||||||
maxretry=2
|
maxretry=2
|
||||||
findtime=32
|
findtime=32
|
||||||
|
@ -1203,7 +1204,7 @@ EOF
|
||||||
|
|
||||||
cat << EOF > /etc/fail2ban/action.d/3x-ipl.conf
|
cat << EOF > /etc/fail2ban/action.d/3x-ipl.conf
|
||||||
[INCLUDES]
|
[INCLUDES]
|
||||||
before = iptables-allports.conf
|
before = iptables-common.conf
|
||||||
|
|
||||||
[Definition]
|
[Definition]
|
||||||
actionstart = <iptables> -N f2b-<name>
|
actionstart = <iptables> -N f2b-<name>
|
||||||
|
@ -1223,6 +1224,11 @@ actionunban = <iptables> -D f2b-<name> -s <ip> -j <blocktype>
|
||||||
echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") UNBAN [Email] = <F-USER> [IP] = <ip> unbanned." >> ${iplimit_banned_log_path}
|
echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") UNBAN [Email] = <F-USER> [IP] = <ip> unbanned." >> ${iplimit_banned_log_path}
|
||||||
|
|
||||||
[Init]
|
[Init]
|
||||||
|
# Use default settings from iptables-common.conf
|
||||||
|
# This will automatically handle both IPv4 and IPv6
|
||||||
|
name = default
|
||||||
|
protocol = tcp
|
||||||
|
chain = INPUT
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo -e "${green}Ip Limit jail files created with a bantime of ${bantime} minutes.${plain}"
|
echo -e "${green}Ip Limit jail files created with a bantime of ${bantime} minutes.${plain}"
|
||||||
|
@ -1247,10 +1253,11 @@ iplimit_main() {
|
||||||
echo -e "\n${green}\t1.${plain} Install Fail2ban and configure IP Limit"
|
echo -e "\n${green}\t1.${plain} Install Fail2ban and configure IP Limit"
|
||||||
echo -e "${green}\t2.${plain} Change Ban Duration"
|
echo -e "${green}\t2.${plain} Change Ban Duration"
|
||||||
echo -e "${green}\t3.${plain} Unban Everyone"
|
echo -e "${green}\t3.${plain} Unban Everyone"
|
||||||
echo -e "${green}\t4.${plain} Check Logs"
|
echo -e "${green}\t4.${plain} Ban Logs"
|
||||||
echo -e "${green}\t5.${plain} Fail2ban Status"
|
echo -e "${green}\t5.${plain} Real-Time Logs"
|
||||||
echo -e "${green}\t6.${plain} Restart Fail2ban"
|
echo -e "${green}\t6.${plain} Service Status"
|
||||||
echo -e "${green}\t7.${plain} Uninstall Fail2ban"
|
echo -e "${green}\t7.${plain} Service Restart"
|
||||||
|
echo -e "${green}\t8.${plain} Uninstall Fail2ban and IP Limit"
|
||||||
echo -e "${green}\t0.${plain} Back to Main Menu"
|
echo -e "${green}\t0.${plain} Back to Main Menu"
|
||||||
read -p "Choose an option: " choice
|
read -p "Choose an option: " choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
|
@ -1291,12 +1298,15 @@ iplimit_main() {
|
||||||
show_banlog
|
show_banlog
|
||||||
;;
|
;;
|
||||||
5)
|
5)
|
||||||
service fail2ban status
|
tail -f /var/log/fail2ban.log
|
||||||
;;
|
;;
|
||||||
6)
|
6)
|
||||||
systemctl restart fail2ban
|
service fail2ban status
|
||||||
;;
|
;;
|
||||||
7)
|
7)
|
||||||
|
systemctl restart fail2ban
|
||||||
|
;;
|
||||||
|
8)
|
||||||
remove_iplimit
|
remove_iplimit
|
||||||
;;
|
;;
|
||||||
*) echo "Invalid choice" ;;
|
*) echo "Invalid choice" ;;
|
||||||
|
|
Loading…
Reference in a new issue