mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-31 15:26: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
|
||||||
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() {
|
confirm() {
|
||||||
if [[ $# > 1 ]]; then
|
if [[ $# > 1 ]]; then
|
||||||
echo && read -p "$1 [Default $2]: " temp
|
echo && read -p "$1 [Default $2]: " temp
|
||||||
|
@ -696,6 +703,24 @@ run_speedtest() {
|
||||||
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() {
|
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"
|
||||||
|
@ -717,7 +742,7 @@ iplimit_main() {
|
||||||
2)
|
2)
|
||||||
read -rp "Please enter new Ban Duration in Minutes [default 5]: " NUM
|
read -rp "Please enter new Ban Duration in Minutes [default 5]: " NUM
|
||||||
if [[ $NUM =~ ^[0-9]+$ ]]; then
|
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
|
sudo systemctl restart fail2ban
|
||||||
echo -e "${green}Bantime set to ${NUM} minutes successfully.${plain}"
|
echo -e "${green}Bantime set to ${NUM} minutes successfully.${plain}"
|
||||||
else
|
else
|
||||||
|
@ -789,8 +814,9 @@ install_iplimit() {
|
||||||
touch /var/log/3xipl.log
|
touch /var/log/3xipl.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Create the iplimit jail file
|
||||||
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
|
# 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
|
sudo cat > /etc/fail2ban/filter.d/3x-ipl.conf << EOF
|
||||||
[Definition]
|
[Definition]
|
||||||
|
|
Loading…
Reference in a new issue