mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-30 23:06:18 +00:00
Update x-ui.sh to apply single source of truth for jail file
This commit is contained in:
parent
295f705684
commit
218590394e
1 changed files with 33 additions and 7 deletions
32
x-ui.sh
32
x-ui.sh
|
@ -56,6 +56,13 @@ elif [[ "${release}" == "debian" ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Declare Variables
|
||||
log_folder="${XUI_LOG_FOLDER:=/var/log}"
|
||||
jail_log_path="${log_folder}/3xipl.log"
|
||||
jail_banned_log_path="${log_folder}/3xipl-banned.log"
|
||||
|
||||
|
||||
confirm() {
|
||||
if [[ $# > 1 ]]; then
|
||||
echo && read -p "$1 [Default $2]: " temp
|
||||
|
@ -696,6 +703,24 @@ run_speedtest() {
|
|||
speedtest
|
||||
}
|
||||
|
||||
create_iplimit_jail() {
|
||||
# Use default bantime if not passed => 5 minutes
|
||||
local bantime="${1:-5}"
|
||||
|
||||
cat << EOF > /etc/fail2ban/jail.d/3x-ipl.conf
|
||||
[3x-ipl]
|
||||
enabled=true
|
||||
filter=3x-ipl
|
||||
action=3x-ipl
|
||||
logpath=${jail_log_path}
|
||||
maxretry=3
|
||||
findtime=100
|
||||
bantime=${bantime}m
|
||||
EOF
|
||||
|
||||
echo -e "${green}Created Ip Limit jail with a bantime of ${bantime} minutes.${plain}"
|
||||
}
|
||||
|
||||
iplimit_main() {
|
||||
echo -e "\n${green}\t1.${plain} Install Fail2ban and configure IP Limit"
|
||||
echo -e "${green}\t2.${plain} Change Ban Duration"
|
||||
|
@ -717,7 +742,7 @@ iplimit_main() {
|
|||
2)
|
||||
read -rp "Please enter new Ban Duration in Minutes [default 5]: " NUM
|
||||
if [[ $NUM =~ ^[0-9]+$ ]]; then
|
||||
echo -e "\n[3x-ipl]\nenabled=true\nfilter=3x-ipl\naction=3x-ipl\nlogpath=/var/log/3xipl.log\nmaxretry=3\nfindtime=100\nbantime=${NUM}m" > /etc/fail2ban/jail.d/3x-ipl.conf
|
||||
create_iplimit_jail ${NUM}
|
||||
sudo systemctl restart fail2ban
|
||||
echo -e "${green}Bantime set to ${NUM} minutes successfully.${plain}"
|
||||
else
|
||||
|
@ -789,8 +814,9 @@ install_iplimit() {
|
|||
touch /var/log/3xipl.log
|
||||
fi
|
||||
|
||||
|
||||
echo -e "\n[3x-ipl]\nenabled=true\nfilter=3x-ipl\naction=3x-ipl\nlogpath=/var/log/3xipl.log\nmaxretry=3\nfindtime=100\nbantime=5m" > /etc/fail2ban/jail.d/3x-ipl.conf
|
||||
# Create the iplimit jail file
|
||||
# we didn't pass the bantime here to use the default value
|
||||
create_iplimit_jail
|
||||
|
||||
sudo cat > /etc/fail2ban/filter.d/3x-ipl.conf << EOF
|
||||
[Definition]
|
||||
|
|
Loading…
Reference in a new issue