mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-10-31 04:12:51 +00:00 
			
		
		
		
	Update x-ui.sh
This commit is contained in:
		
							parent
							
								
									38378fe36f
								
							
						
					
					
						commit
						a7bea936c5
					
				
					 1 changed files with 195 additions and 171 deletions
				
			
		
							
								
								
									
										356
									
								
								x-ui.sh
									
									
									
									
									
								
							
							
						
						
									
										356
									
								
								x-ui.sh
									
									
									
									
									
								
							|  | @ -70,13 +70,11 @@ elif [[ "${release}" == "armbian" ]]; then | ||||||
|     echo "Your OS is Armbian" |     echo "Your OS is Armbian" | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| # Declare Variables | # Declare Variables | ||||||
| log_folder="${XUI_LOG_FOLDER:=/var/log}" | log_folder="${XUI_LOG_FOLDER:=/var/log}" | ||||||
| iplimit_log_path="${log_folder}/3xipl.log" | iplimit_log_path="${log_folder}/3xipl.log" | ||||||
| iplimit_banned_log_path="${log_folder}/3xipl-banned.log" | iplimit_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 | ||||||
|  | @ -140,7 +138,7 @@ custom_version() { | ||||||
| 
 | 
 | ||||||
|     if [ -z "$panel_version" ]; then |     if [ -z "$panel_version" ]; then | ||||||
|         echo "Panel version cannot be empty. Exiting." |         echo "Panel version cannot be empty. Exiting." | ||||||
|     exit 1 |         exit 1 | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|     download_link="https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh" |     download_link="https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh" | ||||||
|  | @ -329,15 +327,15 @@ show_log() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| show_banlog() { | show_banlog() { | ||||||
|   if test -f "${iplimit_banned_log_path}"; then |     if test -f "${iplimit_banned_log_path}"; then | ||||||
|     if [[ -s "${iplimit_banned_log_path}" ]]; then |         if [[ -s "${iplimit_banned_log_path}" ]]; then | ||||||
|       cat ${iplimit_banned_log_path} |             cat ${iplimit_banned_log_path} | ||||||
|  |         else | ||||||
|  |             echo -e "${red}Log file is empty.${plain}\n" | ||||||
|  |         fi | ||||||
|     else |     else | ||||||
|       echo -e "${red}Log file is empty.${plain}\n"   |         echo -e "${red}Log file not found. Please Install Fail2ban and IP Limit first.${plain}\n" | ||||||
|     fi |     fi | ||||||
|   else |  | ||||||
|     echo -e "${red}Log file not found. Please Install Fail2ban and IP Limit first.${plain}\n" |  | ||||||
|   fi |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| enable_bbr() { | enable_bbr() { | ||||||
|  | @ -348,19 +346,19 @@ enable_bbr() { | ||||||
| 
 | 
 | ||||||
|     # Check the OS and install necessary packages |     # Check the OS and install necessary packages | ||||||
|     case "${release}" in |     case "${release}" in | ||||||
|         ubuntu|debian) |     ubuntu | debian) | ||||||
|             apt-get update && apt-get install -yqq --no-install-recommends ca-certificates |         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 |         yum -y update && yum -y install ca-certificates | ||||||
|             ;; |         ;; | ||||||
|         fedora) |     fedora) | ||||||
|             dnf -y update && dnf -y install ca-certificates |         dnf -y update && dnf -y install ca-certificates | ||||||
|             ;; |         ;; | ||||||
|         *) |     *) | ||||||
|             echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" |         echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" | ||||||
|             exit 1 |         exit 1 | ||||||
|             ;; |         ;; | ||||||
|     esac |     esac | ||||||
| 
 | 
 | ||||||
|     # Enable BBR |     # Enable BBR | ||||||
|  | @ -581,21 +579,24 @@ ssl_cert_issue_main() { | ||||||
|     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 | ||||||
|         0) |     0) | ||||||
|             show_menu ;; |         show_menu | ||||||
|         1)  |         ;; | ||||||
|             ssl_cert_issue ;; |     1) | ||||||
|         2)  |         ssl_cert_issue | ||||||
|             local domain="" |         ;; | ||||||
|             read -p "Please enter your domain name to revoke the certificate: " domain |     2) | ||||||
|             ~/.acme.sh/acme.sh --revoke -d ${domain} |         local domain="" | ||||||
|             LOGI "Certificate revoked" |         read -p "Please enter your domain name to revoke the certificate: " domain | ||||||
|             ;; |         ~/.acme.sh/acme.sh --revoke -d ${domain} | ||||||
|         3) |         LOGI "Certificate revoked" | ||||||
|             local domain="" |         ;; | ||||||
|             read -p "Please enter your domain name to forcefully renew an SSL certificate: " domain |     3) | ||||||
|             ~/.acme.sh/acme.sh --renew -d ${domain} --force ;; |         local domain="" | ||||||
|         *) echo "Invalid choice" ;; |         read -p "Please enter your domain name to forcefully renew an SSL certificate: " domain | ||||||
|  |         ~/.acme.sh/acme.sh --renew -d ${domain} --force | ||||||
|  |         ;; | ||||||
|  |     *) echo "Invalid choice" ;; | ||||||
|     esac |     esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -611,15 +612,19 @@ ssl_cert_issue() { | ||||||
|     fi |     fi | ||||||
|     # install socat second |     # install socat second | ||||||
|     case "${release}" in |     case "${release}" in | ||||||
|         ubuntu|debian|armbian) |     ubuntu | debian | armbian) | ||||||
|             apt update && apt install socat -y ;; |         apt update && apt install socat -y | ||||||
|         centos|almalinux|rocky) |         ;; | ||||||
|             yum -y update && yum -y install socat ;; |     centos | almalinux | rocky) | ||||||
|         fedora) |         yum -y update && yum -y install socat | ||||||
|             dnf -y update && dnf -y install socat ;; |         ;; | ||||||
|         *) |     fedora) | ||||||
|             echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" |         dnf -y update && dnf -y install socat | ||||||
|             exit 1 ;; |         ;; | ||||||
|  |     *) | ||||||
|  |         echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" | ||||||
|  |         exit 1 | ||||||
|  |         ;; | ||||||
|     esac |     esac | ||||||
|     if [ $? -ne 0 ]; then |     if [ $? -ne 0 ]; then | ||||||
|         LOGE "install socat failed, please check logs" |         LOGE "install socat failed, please check logs" | ||||||
|  | @ -750,8 +755,8 @@ ssl_cert_issue_CF() { | ||||||
|             LOGI "Certificate issued Successfully, Installing..." |             LOGI "Certificate issued Successfully, Installing..." | ||||||
|         fi |         fi | ||||||
|         ~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \ |         ~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \ | ||||||
|         --cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \ |             --cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \ | ||||||
|         --fullchain-file /root/cert/fullchain.cer |             --fullchain-file /root/cert/fullchain.cer | ||||||
|         if [ $? -ne 0 ]; then |         if [ $? -ne 0 ]; then | ||||||
|             LOGE "Certificate installation failed, script exiting..." |             LOGE "Certificate installation failed, script exiting..." | ||||||
|             exit 1 |             exit 1 | ||||||
|  | @ -782,21 +787,22 @@ warp_cloudflare() { | ||||||
|     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 | ||||||
|         0) |     0) | ||||||
|             show_menu ;; |         show_menu | ||||||
|         1)  |         ;; | ||||||
|             bash <(curl -sSL https://raw.githubusercontent.com/hamid-gh98/x-ui-scripts/main/install_warp_proxy.sh) |     1) | ||||||
|             ;; |         bash <(curl -sSL https://raw.githubusercontent.com/hamid-gh98/x-ui-scripts/main/install_warp_proxy.sh) | ||||||
|         2)  |         ;; | ||||||
|             warp a |     2) | ||||||
|             ;; |         warp a | ||||||
|         3) |         ;; | ||||||
|             warp y |     3) | ||||||
|             ;; |         warp y | ||||||
|         4) |         ;; | ||||||
|             warp u |     4) | ||||||
|             ;; |         warp u | ||||||
|         *) echo "Invalid choice" ;; |         ;; | ||||||
|  |     *) echo "Invalid choice" ;; | ||||||
|     esac |     esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -809,41 +815,42 @@ multi_protocol() { | ||||||
|     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 | ||||||
|         0) |     0) | ||||||
|             show_menu ;; |         show_menu | ||||||
|         1)  |         ;; | ||||||
|             bash <(curl -Ls https://raw.githubusercontent.com/M4mmad/3xui-multi-protocol/master/install.sh --ipv4) |     1) | ||||||
|             ;; |         bash <(curl -Ls https://raw.githubusercontent.com/M4mmad/3xui-multi-protocol/master/install.sh --ipv4) | ||||||
|         2)  |         ;; | ||||||
|             bash <(curl -Ls https://raw.githubusercontent.com/M4mmad/3xui-multi-protocol/master/unistall.sh --ipv4) |     2) | ||||||
|             ;; |         bash <(curl -Ls https://raw.githubusercontent.com/M4mmad/3xui-multi-protocol/master/unistall.sh --ipv4) | ||||||
|         3) |         ;; | ||||||
|             systemctl start 3xui-multi-protocol |     3) | ||||||
|             ;; |         systemctl start 3xui-multi-protocol | ||||||
|         4) |         ;; | ||||||
|             systemctl stop 3xui-multi-protocol |     4) | ||||||
|             ;; |         systemctl stop 3xui-multi-protocol | ||||||
|         *) echo "Invalid choice" ;; |         ;; | ||||||
|  |     *) echo "Invalid choice" ;; | ||||||
|     esac |     esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| run_speedtest() { | run_speedtest() { | ||||||
|     # Check if Speedtest is already installed |     # 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 |         # If not installed, install it | ||||||
|         local pkg_manager="" |         local pkg_manager="" | ||||||
|         local speedtest_install_script="" |         local speedtest_install_script="" | ||||||
| 
 | 
 | ||||||
|         if command -v dnf &> /dev/null; then |         if command -v dnf &>/dev/null; then | ||||||
|             pkg_manager="dnf" |             pkg_manager="dnf" | ||||||
|             speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh" |             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" |             pkg_manager="yum" | ||||||
|             speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh" |             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" |             pkg_manager="apt-get" | ||||||
|             speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh" |             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" |             pkg_manager="apt" | ||||||
|             speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh" |             speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh" | ||||||
|         fi |         fi | ||||||
|  | @ -938,44 +945,49 @@ iplimit_main() { | ||||||
|     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 | ||||||
|         0) |     0) | ||||||
|             show_menu ;; |         show_menu | ||||||
|         1) |         ;; | ||||||
|             confirm "Proceed with installation of Fail2ban & IP Limit?" "y" |     1) | ||||||
|             if [[ $? == 0 ]]; then |         confirm "Proceed with installation of Fail2ban & IP Limit?" "y" | ||||||
|                 install_iplimit |         if [[ $? == 0 ]]; then | ||||||
|             else |             install_iplimit | ||||||
|                 iplimit_main |         else | ||||||
|             fi ;; |             iplimit_main | ||||||
|         2) |         fi | ||||||
|             read -rp "Please enter new Ban Duration in Minutes [default 5]: " NUM |         ;; | ||||||
|             if [[ $NUM =~ ^[0-9]+$ ]]; then |     2) | ||||||
|                 create_iplimit_jails ${NUM} |         read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM | ||||||
|                 systemctl restart fail2ban |         if [[ $NUM =~ ^[0-9]+$ ]]; then | ||||||
|             else |             create_iplimit_jails ${NUM} | ||||||
|                 echo -e "${red}${NUM} is not a number! Please, try again.${plain}" |             systemctl restart fail2ban | ||||||
|             fi |         else | ||||||
|             iplimit_main ;; |             echo -e "${red}${NUM} is not a number! Please, try again.${plain}" | ||||||
|         3) |         fi | ||||||
|             confirm "Proceed with Unbanning everyone from IP Limit jail?" "y" |         iplimit_main | ||||||
|             if [[ $? == 0 ]]; then |         ;; | ||||||
|                 fail2ban-client reload --restart --unban 3x-ipl |     3) | ||||||
|                 echo -e "${green}All users Unbanned successfully.${plain}" |         confirm "Proceed with Unbanning everyone from IP Limit jail?" "y" | ||||||
|                 iplimit_main |         if [[ $? == 0 ]]; then | ||||||
|             else |             fail2ban-client reload --restart --unban 3x-ipl | ||||||
|                 echo -e "${yellow}Cancelled.${plain}" |             echo -e "${green}All users Unbanned successfully.${plain}" | ||||||
|             fi |             iplimit_main | ||||||
|             iplimit_main ;; |         else | ||||||
|         4) |             echo -e "${yellow}Cancelled.${plain}" | ||||||
|             show_banlog |         fi | ||||||
|             ;; |         iplimit_main | ||||||
|         5) |         ;; | ||||||
|             service fail2ban status |     4) | ||||||
|             ;; |         show_banlog | ||||||
|  |         ;; | ||||||
|  |     5) | ||||||
|  |         service fail2ban status | ||||||
|  |         ;; | ||||||
| 
 | 
 | ||||||
|         6) |     6) | ||||||
|             remove_iplimit ;; |         remove_iplimit | ||||||
|         *) echo "Invalid choice" ;; |         ;; | ||||||
|  |     *) echo "Invalid choice" ;; | ||||||
|     esac |     esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -985,18 +997,22 @@ install_iplimit() { | ||||||
| 
 | 
 | ||||||
|         # Check the OS and install necessary packages |         # Check the OS and install necessary packages | ||||||
|         case "${release}" in |         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 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 |             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 ;; |             dpkg -i fail2ban.deb | ||||||
|             centos|almalinux|rocky) |             ;; | ||||||
|                 yum update -y && yum install epel-release -y |         centos | almalinux | rocky) | ||||||
|                 yum -y install fail2ban ;; |             yum update -y && yum install epel-release -y | ||||||
|             fedora) |             yum -y install fail2ban | ||||||
|                 dnf -y update && dnf -y install fail2ban ;; |             ;; | ||||||
|             *) |         fedora) | ||||||
|                 echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" |             dnf -y update && dnf -y install fail2ban | ||||||
|                 exit 1 ;; |             ;; | ||||||
|  |         *) | ||||||
|  |             echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|         esac |         esac | ||||||
| 
 | 
 | ||||||
|         if ! command -v fail2ban-client &>/dev/null; then |         if ! command -v fail2ban-client &>/dev/null; then | ||||||
|  | @ -1041,45 +1057,53 @@ install_iplimit() { | ||||||
|     before_show_menu |     before_show_menu | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| remove_iplimit(){ | remove_iplimit() { | ||||||
|     echo -e "${green}\t1.${plain} Only remove IP Limit configurations" |     echo -e "${green}\t1.${plain} Only remove IP Limit configurations" | ||||||
|     echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit" |     echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit" | ||||||
|     echo -e "${green}\t0.${plain} Abort" |     echo -e "${green}\t0.${plain} Abort" | ||||||
|     read -p "Choose an option: " num |     read -p "Choose an option: " num | ||||||
|     case "$num" in |     case "$num" in | ||||||
|         1)  |     1) | ||||||
|             rm -f /etc/fail2ban/filter.d/3x-ipl.conf |         rm -f /etc/fail2ban/filter.d/3x-ipl.conf | ||||||
|             rm -f /etc/fail2ban/action.d/3x-ipl.conf |         rm -f /etc/fail2ban/action.d/3x-ipl.conf | ||||||
|             rm -f /etc/fail2ban/jail.d/3x-ipl.conf |         rm -f /etc/fail2ban/jail.d/3x-ipl.conf | ||||||
|             systemctl restart fail2ban |         systemctl restart fail2ban | ||||||
|             echo -e "${green}IP Limit removed successfully!${plain}\n" |         echo -e "${green}IP Limit removed successfully!${plain}\n" | ||||||
|             before_show_menu ;; |         before_show_menu | ||||||
|         2)   |         ;; | ||||||
|             rm -rf /etc/fail2ban |     2) | ||||||
|             systemctl stop fail2ban |         rm -rf /etc/fail2ban | ||||||
|             case "${release}" in |         systemctl stop fail2ban | ||||||
|                 ubuntu|debian) |         case "${release}" in | ||||||
|                     apt-get remove -y fail2ban |         ubuntu | debian) | ||||||
|                     apt-get purge -y fail2ban -y |             apt-get remove -y fail2ban | ||||||
|                     apt-get autoremove -y;; |             apt-get purge -y fail2ban -y | ||||||
|                 centos|almalinux|rocky) |             apt-get autoremove -y | ||||||
|                     yum remove fail2ban -y |             ;; | ||||||
|                     yum autoremove -y;; |         centos | almalinux | rocky) | ||||||
|                 fedora) |             yum remove fail2ban -y | ||||||
|                     dnf remove fail2ban -y |             yum autoremove -y | ||||||
|                     dnf autoremove -y;; |             ;; | ||||||
|                 *) |         fedora) | ||||||
|                     echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n" |             dnf remove fail2ban -y | ||||||
|                     exit 1 ;; |             dnf autoremove -y | ||||||
|             esac |             ;; | ||||||
|             echo -e "${green}Fail2ban and IP Limit removed successfully!${plain}\n" |  | ||||||
|             before_show_menu ;; |  | ||||||
|         0)  |  | ||||||
|             echo -e "${yellow}Cancelled.${plain}\n" |  | ||||||
|             iplimit_main ;; |  | ||||||
|         *) |         *) | ||||||
|             echo -e "${red}Invalid option. Please select a valid number.${plain}\n" |             echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n" | ||||||
|             remove_iplimit ;; |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         esac | ||||||
|  |         echo -e "${green}Fail2ban and IP Limit removed successfully!${plain}\n" | ||||||
|  |         before_show_menu | ||||||
|  |         ;; | ||||||
|  |     0) | ||||||
|  |         echo -e "${yellow}Cancelled.${plain}\n" | ||||||
|  |         iplimit_main | ||||||
|  |         ;; | ||||||
|  |     *) | ||||||
|  |         echo -e "${red}Invalid option. Please select a valid number.${plain}\n" | ||||||
|  |         remove_iplimit | ||||||
|  |         ;; | ||||||
|     esac |     esac | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 MHSanaei
						MHSanaei