Update x-ui.sh

This commit is contained in:
MHSanaei 2024-01-20 17:28:44 +03:30
parent 38378fe36f
commit a7bea936c5

110
x-ui.sh
View file

@ -70,13 +70,11 @@ elif [[ "${release}" == "armbian" ]]; then
echo "Your OS is Armbian"
fi
# Declare Variables
log_folder="${XUI_LOG_FOLDER:=/var/log}"
iplimit_log_path="${log_folder}/3xipl.log"
iplimit_banned_log_path="${log_folder}/3xipl-banned.log"
confirm() {
if [[ $# > 1 ]]; then
echo && read -p "$1 [Default $2]: " temp
@ -348,10 +346,10 @@ enable_bbr() {
# Check the OS and install necessary packages
case "${release}" in
ubuntu|debian)
ubuntu | debian)
apt-get update && apt-get install -yqq --no-install-recommends ca-certificates
;;
centos|almalinux|rocky)
centos | almalinux | rocky)
yum -y update && yum -y install ca-certificates
;;
fedora)
@ -582,9 +580,11 @@ ssl_cert_issue_main() {
read -p "Choose an option: " choice
case "$choice" in
0)
show_menu ;;
show_menu
;;
1)
ssl_cert_issue ;;
ssl_cert_issue
;;
2)
local domain=""
read -p "Please enter your domain name to revoke the certificate: " domain
@ -594,7 +594,8 @@ ssl_cert_issue_main() {
3)
local domain=""
read -p "Please enter your domain name to forcefully renew an SSL certificate: " domain
~/.acme.sh/acme.sh --renew -d ${domain} --force ;;
~/.acme.sh/acme.sh --renew -d ${domain} --force
;;
*) echo "Invalid choice" ;;
esac
}
@ -611,15 +612,19 @@ ssl_cert_issue() {
fi
# install socat second
case "${release}" in
ubuntu|debian|armbian)
apt update && apt install socat -y ;;
centos|almalinux|rocky)
yum -y update && yum -y install socat ;;
ubuntu | debian | armbian)
apt update && apt install socat -y
;;
centos | almalinux | rocky)
yum -y update && yum -y install socat
;;
fedora)
dnf -y update && dnf -y install socat ;;
dnf -y update && dnf -y install socat
;;
*)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
exit 1 ;;
exit 1
;;
esac
if [ $? -ne 0 ]; then
LOGE "install socat failed, please check logs"
@ -783,7 +788,8 @@ warp_cloudflare() {
read -p "Choose an option: " choice
case "$choice" in
0)
show_menu ;;
show_menu
;;
1)
bash <(curl -sSL https://raw.githubusercontent.com/hamid-gh98/x-ui-scripts/main/install_warp_proxy.sh)
;;
@ -810,7 +816,8 @@ multi_protocol() {
read -p "Choose an option: " choice
case "$choice" in
0)
show_menu ;;
show_menu
;;
1)
bash <(curl -Ls https://raw.githubusercontent.com/M4mmad/3xui-multi-protocol/master/install.sh --ipv4)
;;
@ -829,21 +836,21 @@ multi_protocol() {
run_speedtest() {
# Check if Speedtest is already installed
if ! command -v speedtest &> /dev/null; then
if ! command -v speedtest &>/dev/null; then
# If not installed, install it
local pkg_manager=""
local speedtest_install_script=""
if command -v dnf &> /dev/null; then
if command -v dnf &>/dev/null; then
pkg_manager="dnf"
speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
elif command -v yum &> /dev/null; then
elif command -v yum &>/dev/null; then
pkg_manager="yum"
speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
elif command -v apt-get &> /dev/null; then
elif command -v apt-get &>/dev/null; then
pkg_manager="apt-get"
speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
elif command -v apt &> /dev/null; then
elif command -v apt &>/dev/null; then
pkg_manager="apt"
speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
fi
@ -939,23 +946,26 @@ iplimit_main() {
read -p "Choose an option: " choice
case "$choice" in
0)
show_menu ;;
show_menu
;;
1)
confirm "Proceed with installation of Fail2ban & IP Limit?" "y"
if [[ $? == 0 ]]; then
install_iplimit
else
iplimit_main
fi ;;
fi
;;
2)
read -rp "Please enter new Ban Duration in Minutes [default 5]: " NUM
read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM
if [[ $NUM =~ ^[0-9]+$ ]]; then
create_iplimit_jails ${NUM}
systemctl restart fail2ban
else
echo -e "${red}${NUM} is not a number! Please, try again.${plain}"
fi
iplimit_main ;;
iplimit_main
;;
3)
confirm "Proceed with Unbanning everyone from IP Limit jail?" "y"
if [[ $? == 0 ]]; then
@ -965,7 +975,8 @@ iplimit_main() {
else
echo -e "${yellow}Cancelled.${plain}"
fi
iplimit_main ;;
iplimit_main
;;
4)
show_banlog
;;
@ -974,7 +985,8 @@ iplimit_main() {
;;
6)
remove_iplimit ;;
remove_iplimit
;;
*) echo "Invalid choice" ;;
esac
}
@ -985,18 +997,22 @@ install_iplimit() {
# Check the OS and install necessary packages
case "${release}" in
ubuntu|debian)
ubuntu | debian)
wget -O fail2ban.deb https://github.com/fail2ban/fail2ban/releases/download/1.0.2/fail2ban_1.0.2-1.upstream1_all.deb
wget -O fail2ban.deb.asc https://github.com/fail2ban/fail2ban/releases/download/1.0.2/fail2ban_1.0.2-1.upstream1_all.deb.asc
dpkg -i fail2ban.deb ;;
centos|almalinux|rocky)
dpkg -i fail2ban.deb
;;
centos | almalinux | rocky)
yum update -y && yum install epel-release -y
yum -y install fail2ban ;;
yum -y install fail2ban
;;
fedora)
dnf -y update && dnf -y install fail2ban ;;
dnf -y update && dnf -y install fail2ban
;;
*)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
exit 1 ;;
exit 1
;;
esac
if ! command -v fail2ban-client &>/dev/null; then
@ -1041,7 +1057,7 @@ install_iplimit() {
before_show_menu
}
remove_iplimit(){
remove_iplimit() {
echo -e "${green}\t1.${plain} Only remove IP Limit configurations"
echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit"
echo -e "${green}\t0.${plain} Abort"
@ -1053,33 +1069,41 @@ remove_iplimit(){
rm -f /etc/fail2ban/jail.d/3x-ipl.conf
systemctl restart fail2ban
echo -e "${green}IP Limit removed successfully!${plain}\n"
before_show_menu ;;
before_show_menu
;;
2)
rm -rf /etc/fail2ban
systemctl stop fail2ban
case "${release}" in
ubuntu|debian)
ubuntu | debian)
apt-get remove -y fail2ban
apt-get purge -y fail2ban -y
apt-get autoremove -y;;
centos|almalinux|rocky)
apt-get autoremove -y
;;
centos | almalinux | rocky)
yum remove fail2ban -y
yum autoremove -y;;
yum autoremove -y
;;
fedora)
dnf remove fail2ban -y
dnf autoremove -y;;
dnf autoremove -y
;;
*)
echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n"
exit 1 ;;
exit 1
;;
esac
echo -e "${green}Fail2ban and IP Limit removed successfully!${plain}\n"
before_show_menu ;;
before_show_menu
;;
0)
echo -e "${yellow}Cancelled.${plain}\n"
iplimit_main ;;
iplimit_main
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
remove_iplimit ;;
remove_iplimit
;;
esac
}