x-ui.sh 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. #!/bin/bash
  2. red='\033[0;31m'
  3. green='\033[0;32m'
  4. yellow='\033[0;33m'
  5. plain='\033[0m'
  6. #Add some basic function here
  7. function LOGD() {
  8. echo -e "${yellow}[DEG] $* ${plain}"
  9. }
  10. function LOGE() {
  11. echo -e "${red}[ERR] $* ${plain}"
  12. }
  13. function LOGI() {
  14. echo -e "${green}[INF] $* ${plain}"
  15. }
  16. # check root
  17. [[ $EUID -ne 0 ]] && LOGE "ERROR: You must be root to run this script! \n" && exit 1
  18. # Check OS and set release variable
  19. if [[ -f /etc/os-release ]]; then
  20. source /etc/os-release
  21. release=$ID
  22. elif [[ -f /usr/lib/os-release ]]; then
  23. source /usr/lib/os-release
  24. release=$ID
  25. else
  26. echo "Failed to check the system OS, please contact the author!" >&2
  27. exit 1
  28. fi
  29. echo "The OS release is: $release"
  30. os_version=""
  31. os_version=$(grep -i version_id /etc/os-release | cut -d \" -f2 | cut -d . -f1)
  32. if [[ "${release}" == "arch" ]]; then
  33. echo "Your OS is Arch Linux"
  34. elif [[ "${release}" == "manjaro" ]]; then
  35. echo "Your OS is Manjaro"
  36. elif [[ "${release}" == "armbian" ]]; then
  37. echo "Your OS is Armbian"
  38. elif [[ "${release}" == "centos" ]]; then
  39. if [[ ${os_version} -lt 8 ]]; then
  40. echo -e "${red} Please use CentOS 8 or higher ${plain}\n" && exit 1
  41. fi
  42. elif [[ "${release}" == "ubuntu" ]]; then
  43. if [[ ${os_version} -lt 20 ]]; then
  44. echo -e "${red} Please use Ubuntu 20 or higher version!${plain}\n" && exit 1
  45. fi
  46. elif [[ "${release}" == "fedora" ]]; then
  47. if [[ ${os_version} -lt 36 ]]; then
  48. echo -e "${red} Please use Fedora 36 or higher version!${plain}\n" && exit 1
  49. fi
  50. elif [[ "${release}" == "debian" ]]; then
  51. if [[ ${os_version} -lt 11 ]]; then
  52. echo -e "${red} Please use Debian 11 or higher ${plain}\n" && exit 1
  53. fi
  54. elif [[ "${release}" == "almalinux" ]]; then
  55. if [[ ${os_version} -lt 9 ]]; then
  56. echo -e "${red} Please use AlmaLinux 9 or higher ${plain}\n" && exit 1
  57. fi
  58. elif [[ "${release}" == "rocky" ]]; then
  59. if [[ ${os_version} -lt 9 ]]; then
  60. echo -e "${red} Please use Rocky Linux 9 or higher ${plain}\n" && exit 1
  61. fi
  62. elif [[ "${release}" == "oracle" ]]; then
  63. if [[ ${os_version} -lt 8 ]]; then
  64. echo -e "${red} Please use Oracle Linux 8 or higher ${plain}\n" && exit 1
  65. fi
  66. else
  67. echo -e "${red}Your operating system is not supported by this script.${plain}\n"
  68. echo "Please ensure you are using one of the following supported operating systems:"
  69. echo "- Ubuntu 20.04+"
  70. echo "- Debian 11+"
  71. echo "- CentOS 8+"
  72. echo "- Fedora 36+"
  73. echo "- Arch Linux"
  74. echo "- Manjaro"
  75. echo "- Armbian"
  76. echo "- AlmaLinux 9+"
  77. echo "- Rocky Linux 9+"
  78. echo "- Oracle Linux 8+"
  79. exit 1
  80. fi
  81. # Declare Variables
  82. log_folder="${XUI_LOG_FOLDER:=/var/log}"
  83. iplimit_log_path="${log_folder}/3xipl.log"
  84. iplimit_banned_log_path="${log_folder}/3xipl-banned.log"
  85. confirm() {
  86. if [[ $# > 1 ]]; then
  87. echo && read -p "$1 [Default $2]: " temp
  88. if [[ "${temp}" == "" ]]; then
  89. temp=$2
  90. fi
  91. else
  92. read -p "$1 [y/n]: " temp
  93. fi
  94. if [[ "${temp}" == "y" || "${temp}" == "Y" ]]; then
  95. return 0
  96. else
  97. return 1
  98. fi
  99. }
  100. confirm_restart() {
  101. confirm "Restart the panel, Attention: Restarting the panel will also restart xray" "y"
  102. if [[ $? == 0 ]]; then
  103. restart
  104. else
  105. show_menu
  106. fi
  107. }
  108. before_show_menu() {
  109. echo && echo -n -e "${yellow}Press enter to return to the main menu: ${plain}" && read temp
  110. show_menu
  111. }
  112. install() {
  113. bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh)
  114. if [[ $? == 0 ]]; then
  115. if [[ $# == 0 ]]; then
  116. start
  117. else
  118. start 0
  119. fi
  120. fi
  121. }
  122. update() {
  123. confirm "This function will forcefully reinstall the latest version, and the data will not be lost. Do you want to continue?" "y"
  124. if [[ $? != 0 ]]; then
  125. LOGE "Cancelled"
  126. if [[ $# == 0 ]]; then
  127. before_show_menu
  128. fi
  129. return 0
  130. fi
  131. bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh)
  132. if [[ $? == 0 ]]; then
  133. LOGI "Update is complete, Panel has automatically restarted "
  134. exit 0
  135. fi
  136. }
  137. custom_version() {
  138. echo "Enter the panel version (like 2.0.0):"
  139. read panel_version
  140. if [ -z "$panel_version" ]; then
  141. echo "Panel version cannot be empty. Exiting."
  142. exit 1
  143. fi
  144. download_link="https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh"
  145. # Use the entered panel version in the download link
  146. install_command="bash <(curl -Ls $download_link) v$panel_version"
  147. echo "Downloading and installing panel version $panel_version..."
  148. eval $install_command
  149. }
  150. # Function to handle the deletion of the script file
  151. delete_script() {
  152. rm "$0" # Remove the script file itself
  153. exit 1
  154. }
  155. uninstall() {
  156. confirm "Are you sure you want to uninstall the panel? xray will also uninstalled!" "n"
  157. if [[ $? != 0 ]]; then
  158. if [[ $# == 0 ]]; then
  159. show_menu
  160. fi
  161. return 0
  162. fi
  163. systemctl stop x-ui
  164. systemctl disable x-ui
  165. rm /etc/systemd/system/x-ui.service -f
  166. systemctl daemon-reload
  167. systemctl reset-failed
  168. rm /etc/x-ui/ -rf
  169. rm /usr/local/x-ui/ -rf
  170. echo ""
  171. echo -e "Uninstalled Successfully.\n"
  172. echo "If you need to install this panel again, you can use below command:"
  173. echo -e "${green}bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)${plain}"
  174. echo ""
  175. # Trap the SIGTERM signal
  176. trap delete_script SIGTERM
  177. delete_script
  178. }
  179. reset_user() {
  180. confirm "Are you sure to reset the username and password of the panel?" "n"
  181. if [[ $? != 0 ]]; then
  182. if [[ $# == 0 ]]; then
  183. show_menu
  184. fi
  185. return 0
  186. fi
  187. read -rp "Please set the login username [default is a random username]: " config_account
  188. [[ -z $config_account ]] && config_account=$(date +%s%N | md5sum | cut -c 1-8)
  189. read -rp "Please set the login password [default is a random password]: " config_password
  190. [[ -z $config_password ]] && config_password=$(date +%s%N | md5sum | cut -c 1-8)
  191. /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password} >/dev/null 2>&1
  192. /usr/local/x-ui/x-ui setting -remove_secret >/dev/null 2>&1
  193. echo -e "Panel login username has been reset to: ${green} ${config_account} ${plain}"
  194. echo -e "Panel login password has been reset to: ${green} ${config_password} ${plain}"
  195. echo -e "${yellow} Panel login secret token disabled ${plain}"
  196. echo -e "${green} Please use the new login username and password to access the X-UI panel. Also remember them! ${plain}"
  197. confirm_restart
  198. }
  199. reset_config() {
  200. confirm "Are you sure you want to reset all panel settings, Account data will not be lost, Username and password will not change" "n"
  201. if [[ $? != 0 ]]; then
  202. if [[ $# == 0 ]]; then
  203. show_menu
  204. fi
  205. return 0
  206. fi
  207. /usr/local/x-ui/x-ui setting -reset
  208. echo -e "All panel settings have been reset to default, Please restart the panel now, and use the default ${green}2053${plain} Port to Access the web Panel"
  209. confirm_restart
  210. }
  211. check_config() {
  212. info=$(/usr/local/x-ui/x-ui setting -show true)
  213. if [[ $? != 0 ]]; then
  214. LOGE "get current settings error, please check logs"
  215. show_menu
  216. fi
  217. LOGI "${info}"
  218. }
  219. set_port() {
  220. echo && echo -n -e "Enter port number[1-65535]: " && read port
  221. if [[ -z "${port}" ]]; then
  222. LOGD "Cancelled"
  223. before_show_menu
  224. else
  225. /usr/local/x-ui/x-ui setting -port ${port}
  226. echo -e "The port is set, Please restart the panel now, and use the new port ${green}${port}${plain} to access web panel"
  227. confirm_restart
  228. fi
  229. }
  230. start() {
  231. check_status
  232. if [[ $? == 0 ]]; then
  233. echo ""
  234. LOGI "Panel is running, No need to start again, If you need to restart, please select restart"
  235. else
  236. systemctl start x-ui
  237. sleep 2
  238. check_status
  239. if [[ $? == 0 ]]; then
  240. LOGI "x-ui Started Successfully"
  241. else
  242. LOGE "panel Failed to start, Probably because it takes longer than two seconds to start, Please check the log information later"
  243. fi
  244. fi
  245. if [[ $# == 0 ]]; then
  246. before_show_menu
  247. fi
  248. }
  249. stop() {
  250. check_status
  251. if [[ $? == 1 ]]; then
  252. echo ""
  253. LOGI "Panel stopped, No need to stop again!"
  254. else
  255. systemctl stop x-ui
  256. sleep 2
  257. check_status
  258. if [[ $? == 1 ]]; then
  259. LOGI "x-ui and xray stopped successfully"
  260. else
  261. LOGE "Panel stop failed, Probably because the stop time exceeds two seconds, Please check the log information later"
  262. fi
  263. fi
  264. if [[ $# == 0 ]]; then
  265. before_show_menu
  266. fi
  267. }
  268. restart() {
  269. systemctl restart x-ui
  270. sleep 2
  271. check_status
  272. if [[ $? == 0 ]]; then
  273. LOGI "x-ui and xray Restarted successfully"
  274. else
  275. LOGE "Panel restart failed, Probably because it takes longer than two seconds to start, Please check the log information later"
  276. fi
  277. if [[ $# == 0 ]]; then
  278. before_show_menu
  279. fi
  280. }
  281. status() {
  282. systemctl status x-ui -l
  283. if [[ $# == 0 ]]; then
  284. before_show_menu
  285. fi
  286. }
  287. enable() {
  288. systemctl enable x-ui
  289. if [[ $? == 0 ]]; then
  290. LOGI "x-ui Set to boot automatically on startup successfully"
  291. else
  292. LOGE "x-ui Failed to set Autostart"
  293. fi
  294. if [[ $# == 0 ]]; then
  295. before_show_menu
  296. fi
  297. }
  298. disable() {
  299. systemctl disable x-ui
  300. if [[ $? == 0 ]]; then
  301. LOGI "x-ui Autostart Cancelled successfully"
  302. else
  303. LOGE "x-ui Failed to cancel autostart"
  304. fi
  305. if [[ $# == 0 ]]; then
  306. before_show_menu
  307. fi
  308. }
  309. show_log() {
  310. journalctl -u x-ui.service -e --no-pager -f
  311. if [[ $# == 0 ]]; then
  312. before_show_menu
  313. fi
  314. }
  315. show_banlog() {
  316. if test -f "${iplimit_banned_log_path}"; then
  317. if [[ -s "${iplimit_banned_log_path}" ]]; then
  318. cat ${iplimit_banned_log_path}
  319. else
  320. echo -e "${red}Log file is empty.${plain}\n"
  321. fi
  322. else
  323. echo -e "${red}Log file not found. Please Install Fail2ban and IP Limit first.${plain}\n"
  324. fi
  325. }
  326. bbr_menu() {
  327. echo -e "${green}\t1.${plain} Enable BBR"
  328. echo -e "${green}\t2.${plain} Disable BBR"
  329. echo -e "${green}\t0.${plain} Back to Main Menu"
  330. read -p "Choose an option: " choice
  331. case "$choice" in
  332. 0)
  333. show_menu
  334. ;;
  335. 1)
  336. enable_bbr
  337. ;;
  338. 2)
  339. disable_bbr
  340. ;;
  341. *) echo "Invalid choice" ;;
  342. esac
  343. }
  344. disable_bbr() {
  345. if ! grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf || ! grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
  346. echo -e "${yellow}BBR is not currently enabled.${plain}"
  347. exit 0
  348. fi
  349. # Replace BBR with CUBIC configurations
  350. sed -i 's/net.core.default_qdisc=fq/net.core.default_qdisc=pfifo_fast/' /etc/sysctl.conf
  351. sed -i 's/net.ipv4.tcp_congestion_control=bbr/net.ipv4.tcp_congestion_control=cubic/' /etc/sysctl.conf
  352. # Apply changes
  353. sysctl -p
  354. # Verify that BBR is replaced with CUBIC
  355. if [[ $(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}') == "cubic" ]]; then
  356. echo -e "${green}BBR has been replaced with CUBIC successfully.${plain}"
  357. else
  358. echo -e "${red}Failed to replace BBR with CUBIC. Please check your system configuration.${plain}"
  359. fi
  360. }
  361. enable_bbr() {
  362. if grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf && grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
  363. echo -e "${green}BBR is already enabled!${plain}"
  364. exit 0
  365. fi
  366. # Check the OS and install necessary packages
  367. case "${release}" in
  368. ubuntu | debian | armbian)
  369. apt-get update && apt-get install -yqq --no-install-recommends ca-certificates
  370. ;;
  371. centos | almalinux | rocky | oracle)
  372. yum -y update && yum -y install ca-certificates
  373. ;;
  374. fedora)
  375. dnf -y update && dnf -y install ca-certificates
  376. ;;
  377. arch | manjaro)
  378. pacman -Sy --noconfirm ca-certificates
  379. ;;
  380. *)
  381. echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
  382. exit 1
  383. ;;
  384. esac
  385. # Enable BBR
  386. echo "net.core.default_qdisc=fq" | tee -a /etc/sysctl.conf
  387. echo "net.ipv4.tcp_congestion_control=bbr" | tee -a /etc/sysctl.conf
  388. # Apply changes
  389. sysctl -p
  390. # Verify that BBR is enabled
  391. if [[ $(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}') == "bbr" ]]; then
  392. echo -e "${green}BBR has been enabled successfully.${plain}"
  393. else
  394. echo -e "${red}Failed to enable BBR. Please check your system configuration.${plain}"
  395. fi
  396. }
  397. update_shell() {
  398. wget -O /usr/bin/x-ui -N --no-check-certificate https://github.com/MHSanaei/3x-ui/raw/main/x-ui.sh
  399. if [[ $? != 0 ]]; then
  400. echo ""
  401. LOGE "Failed to download script, Please check whether the machine can connect Github"
  402. before_show_menu
  403. else
  404. chmod +x /usr/bin/x-ui
  405. LOGI "Upgrade script succeeded, Please rerun the script" && exit 0
  406. fi
  407. }
  408. # 0: running, 1: not running, 2: not installed
  409. check_status() {
  410. if [[ ! -f /etc/systemd/system/x-ui.service ]]; then
  411. return 2
  412. fi
  413. temp=$(systemctl status x-ui | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
  414. if [[ "${temp}" == "running" ]]; then
  415. return 0
  416. else
  417. return 1
  418. fi
  419. }
  420. check_enabled() {
  421. temp=$(systemctl is-enabled x-ui)
  422. if [[ "${temp}" == "enabled" ]]; then
  423. return 0
  424. else
  425. return 1
  426. fi
  427. }
  428. check_uninstall() {
  429. check_status
  430. if [[ $? != 2 ]]; then
  431. echo ""
  432. LOGE "Panel installed, Please do not reinstall"
  433. if [[ $# == 0 ]]; then
  434. before_show_menu
  435. fi
  436. return 1
  437. else
  438. return 0
  439. fi
  440. }
  441. check_install() {
  442. check_status
  443. if [[ $? == 2 ]]; then
  444. echo ""
  445. LOGE "Please install the panel first"
  446. if [[ $# == 0 ]]; then
  447. before_show_menu
  448. fi
  449. return 1
  450. else
  451. return 0
  452. fi
  453. }
  454. show_status() {
  455. check_status
  456. case $? in
  457. 0)
  458. echo -e "Panel state: ${green}Running${plain}"
  459. show_enable_status
  460. ;;
  461. 1)
  462. echo -e "Panel state: ${yellow}Not Running${plain}"
  463. show_enable_status
  464. ;;
  465. 2)
  466. echo -e "Panel state: ${red}Not Installed${plain}"
  467. ;;
  468. esac
  469. show_xray_status
  470. }
  471. show_enable_status() {
  472. check_enabled
  473. if [[ $? == 0 ]]; then
  474. echo -e "Start automatically: ${green}Yes${plain}"
  475. else
  476. echo -e "Start automatically: ${red}No${plain}"
  477. fi
  478. }
  479. check_xray_status() {
  480. count=$(ps -ef | grep "xray-linux" | grep -v "grep" | wc -l)
  481. if [[ count -ne 0 ]]; then
  482. return 0
  483. else
  484. return 1
  485. fi
  486. }
  487. show_xray_status() {
  488. check_xray_status
  489. if [[ $? == 0 ]]; then
  490. echo -e "xray state: ${green}Running${plain}"
  491. else
  492. echo -e "xray state: ${red}Not Running${plain}"
  493. fi
  494. }
  495. firewall_menu() {
  496. echo -e "${green}\t1.${plain} Install Firewall & open ports"
  497. echo -e "${green}\t2.${plain} Allowed List"
  498. echo -e "${green}\t3.${plain} Delete Ports from List"
  499. echo -e "${green}\t4.${plain} Disable Firewall"
  500. echo -e "${green}\t0.${plain} Back to Main Menu"
  501. read -p "Choose an option: " choice
  502. case "$choice" in
  503. 0)
  504. show_menu
  505. ;;
  506. 1)
  507. open_ports
  508. ;;
  509. 2)
  510. sudo ufw status
  511. ;;
  512. 3)
  513. delete_ports
  514. ;;
  515. 4)
  516. sudo ufw disable
  517. ;;
  518. *) echo "Invalid choice" ;;
  519. esac
  520. }
  521. open_ports() {
  522. if ! command -v ufw &>/dev/null; then
  523. echo "ufw firewall is not installed. Installing now..."
  524. apt-get update
  525. apt-get install -y ufw
  526. else
  527. echo "ufw firewall is already installed"
  528. fi
  529. # Check if the firewall is inactive
  530. if ufw status | grep -q "Status: active"; then
  531. echo "firewall is already active"
  532. else
  533. # Open the necessary ports
  534. ufw allow ssh
  535. ufw allow http
  536. ufw allow https
  537. ufw allow 2053/tcp
  538. # Enable the firewall
  539. ufw --force enable
  540. fi
  541. # Prompt the user to enter a list of ports
  542. read -p "Enter the ports you want to open (e.g. 80,443,2053 or range 400-500): " ports
  543. # Check if the input is valid
  544. if ! [[ $ports =~ ^([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))*$ ]]; then
  545. echo "Error: Invalid input. Please enter a comma-separated list of ports or a range of ports (e.g. 80,443,2053 or 400-500)." >&2
  546. exit 1
  547. fi
  548. # Open the specified ports using ufw
  549. IFS=',' read -ra PORT_LIST <<<"$ports"
  550. for port in "${PORT_LIST[@]}"; do
  551. if [[ $port == *-* ]]; then
  552. # Split the range into start and end ports
  553. start_port=$(echo $port | cut -d'-' -f1)
  554. end_port=$(echo $port | cut -d'-' -f2)
  555. # Loop through the range and open each port
  556. for ((i = start_port; i <= end_port; i++)); do
  557. ufw allow $i
  558. done
  559. else
  560. ufw allow "$port"
  561. fi
  562. done
  563. # Confirm that the ports are open
  564. ufw status | grep $ports
  565. }
  566. delete_ports() {
  567. # Prompt the user to enter the ports they want to delete
  568. read -p "Enter the ports you want to delete (e.g. 80,443,2053 or range 400-500): " ports
  569. # Check if the input is valid
  570. if ! [[ $ports =~ ^([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))*$ ]]; then
  571. echo "Error: Invalid input. Please enter a comma-separated list of ports or a range of ports (e.g. 80,443,2053 or 400-500)." >&2
  572. exit 1
  573. fi
  574. # Delete the specified ports using ufw
  575. IFS=',' read -ra PORT_LIST <<<"$ports"
  576. for port in "${PORT_LIST[@]}"; do
  577. if [[ $port == *-* ]]; then
  578. # Split the range into start and end ports
  579. start_port=$(echo $port | cut -d'-' -f1)
  580. end_port=$(echo $port | cut -d'-' -f2)
  581. # Loop through the range and delete each port
  582. for ((i = start_port; i <= end_port; i++)); do
  583. ufw delete allow $i
  584. done
  585. else
  586. ufw delete allow "$port"
  587. fi
  588. done
  589. # Confirm that the ports are deleted
  590. echo "Deleted the specified ports:"
  591. ufw status | grep $ports
  592. }
  593. update_geo() {
  594. local defaultBinFolder="/usr/local/x-ui/bin"
  595. read -p "Please enter x-ui bin folder path. Leave blank for default. (Default: '${defaultBinFolder}')" binFolder
  596. binFolder=${binFolder:-${defaultBinFolder}}
  597. if [[ ! -d ${binFolder} ]]; then
  598. LOGE "Folder ${binFolder} not exists!"
  599. LOGI "making bin folder: ${binFolder}..."
  600. mkdir -p ${binFolder}
  601. fi
  602. systemctl stop x-ui
  603. cd ${binFolder}
  604. rm -f geoip.dat geosite.dat geoip_IR.dat geosite_IR.dat geoip_VN.dat geosite_VN.dat
  605. wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
  606. wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
  607. wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
  608. wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
  609. wget -O geoip_VN.dat https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geoip.dat
  610. wget -O geosite_VN.dat https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geosite.dat
  611. systemctl start x-ui
  612. echo -e "${green}Geosite.dat + Geoip.dat + geoip_IR.dat + geosite_IR.dat have been updated successfully in bin folder '${binfolder}'!${plain}"
  613. before_show_menu
  614. }
  615. install_acme() {
  616. cd ~
  617. LOGI "install acme..."
  618. curl https://get.acme.sh | sh
  619. if [ $? -ne 0 ]; then
  620. LOGE "install acme failed"
  621. return 1
  622. else
  623. LOGI "install acme succeed"
  624. fi
  625. return 0
  626. }
  627. ssl_cert_issue_main() {
  628. echo -e "${green}\t1.${plain} Get SSL"
  629. echo -e "${green}\t2.${plain} Revoke"
  630. echo -e "${green}\t3.${plain} Force Renew"
  631. echo -e "${green}\t0.${plain} Back to Main Menu"
  632. read -p "Choose an option: " choice
  633. case "$choice" in
  634. 0)
  635. show_menu
  636. ;;
  637. 1)
  638. ssl_cert_issue
  639. ;;
  640. 2)
  641. local domain=""
  642. read -p "Please enter your domain name to revoke the certificate: " domain
  643. ~/.acme.sh/acme.sh --revoke -d ${domain}
  644. LOGI "Certificate revoked"
  645. ;;
  646. 3)
  647. local domain=""
  648. read -p "Please enter your domain name to forcefully renew an SSL certificate: " domain
  649. ~/.acme.sh/acme.sh --renew -d ${domain} --force
  650. ;;
  651. *) echo "Invalid choice" ;;
  652. esac
  653. }
  654. ssl_cert_issue() {
  655. # check for acme.sh first
  656. if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then
  657. echo "acme.sh could not be found. we will install it"
  658. install_acme
  659. if [ $? -ne 0 ]; then
  660. LOGE "install acme failed, please check logs"
  661. exit 1
  662. fi
  663. fi
  664. # install socat second
  665. case "${release}" in
  666. ubuntu | debian | armbian)
  667. apt update && apt install socat -y
  668. ;;
  669. centos | almalinux | rocky | oracle)
  670. yum -y update && yum -y install socat
  671. ;;
  672. fedora)
  673. dnf -y update && dnf -y install socat
  674. ;;
  675. arch | manjaro)
  676. pacman -Sy --noconfirm socat
  677. ;;
  678. *)
  679. echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
  680. exit 1
  681. ;;
  682. esac
  683. if [ $? -ne 0 ]; then
  684. LOGE "install socat failed, please check logs"
  685. exit 1
  686. else
  687. LOGI "install socat succeed..."
  688. fi
  689. # get the domain here,and we need verify it
  690. local domain=""
  691. read -p "Please enter your domain name:" domain
  692. LOGD "your domain is:${domain},check it..."
  693. # here we need to judge whether there exists cert already
  694. local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
  695. if [ ${currentCert} == ${domain} ]; then
  696. local certInfo=$(~/.acme.sh/acme.sh --list)
  697. LOGE "system already has certs here,can not issue again,current certs details:"
  698. LOGI "$certInfo"
  699. exit 1
  700. else
  701. LOGI "your domain is ready for issuing cert now..."
  702. fi
  703. # create a directory for install cert
  704. certPath="/root/cert/${domain}"
  705. if [ ! -d "$certPath" ]; then
  706. mkdir -p "$certPath"
  707. else
  708. rm -rf "$certPath"
  709. mkdir -p "$certPath"
  710. fi
  711. # get needed port here
  712. local WebPort=80
  713. read -p "please choose which port do you use,default will be 80 port:" WebPort
  714. if [[ ${WebPort} -gt 65535 || ${WebPort} -lt 1 ]]; then
  715. LOGE "your input ${WebPort} is invalid,will use default port"
  716. fi
  717. LOGI "will use port:${WebPort} to issue certs,please make sure this port is open..."
  718. # NOTE:This should be handled by user
  719. # open the port and kill the occupied progress
  720. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  721. ~/.acme.sh/acme.sh --issue -d ${domain} --standalone --httpport ${WebPort}
  722. if [ $? -ne 0 ]; then
  723. LOGE "issue certs failed,please check logs"
  724. rm -rf ~/.acme.sh/${domain}
  725. exit 1
  726. else
  727. LOGE "issue certs succeed,installing certs..."
  728. fi
  729. # install cert
  730. ~/.acme.sh/acme.sh --installcert -d ${domain} \
  731. --key-file /root/cert/${domain}/privkey.pem \
  732. --fullchain-file /root/cert/${domain}/fullchain.pem
  733. if [ $? -ne 0 ]; then
  734. LOGE "install certs failed,exit"
  735. rm -rf ~/.acme.sh/${domain}
  736. exit 1
  737. else
  738. LOGI "install certs succeed,enable auto renew..."
  739. fi
  740. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  741. if [ $? -ne 0 ]; then
  742. LOGE "auto renew failed, certs details:"
  743. ls -lah cert/*
  744. chmod 755 $certPath/*
  745. exit 1
  746. else
  747. LOGI "auto renew succeed, certs details:"
  748. ls -lah cert/*
  749. chmod 755 $certPath/*
  750. fi
  751. }
  752. ssl_cert_issue_CF() {
  753. echo -E ""
  754. LOGD "******Instructions for use******"
  755. LOGI "This Acme script requires the following data:"
  756. LOGI "1.Cloudflare Registered e-mail"
  757. LOGI "2.Cloudflare Global API Key"
  758. LOGI "3.The domain name that has been resolved dns to the current server by Cloudflare"
  759. LOGI "4.The script applies for a certificate. The default installation path is /root/cert "
  760. confirm "Confirmed?[y/n]" "y"
  761. if [ $? -eq 0 ]; then
  762. # check for acme.sh first
  763. if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then
  764. echo "acme.sh could not be found. we will install it"
  765. install_acme
  766. if [ $? -ne 0 ]; then
  767. LOGE "install acme failed, please check logs"
  768. exit 1
  769. fi
  770. fi
  771. CF_Domain=""
  772. CF_GlobalKey=""
  773. CF_AccountEmail=""
  774. certPath=/root/cert
  775. if [ ! -d "$certPath" ]; then
  776. mkdir $certPath
  777. else
  778. rm -rf $certPath
  779. mkdir $certPath
  780. fi
  781. LOGD "Please set a domain name:"
  782. read -p "Input your domain here:" CF_Domain
  783. LOGD "Your domain name is set to:${CF_Domain}"
  784. LOGD "Please set the API key:"
  785. read -p "Input your key here:" CF_GlobalKey
  786. LOGD "Your API key is:${CF_GlobalKey}"
  787. LOGD "Please set up registered email:"
  788. read -p "Input your email here:" CF_AccountEmail
  789. LOGD "Your registered email address is:${CF_AccountEmail}"
  790. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  791. if [ $? -ne 0 ]; then
  792. LOGE "Default CA, Lets'Encrypt fail, script exiting..."
  793. exit 1
  794. fi
  795. export CF_Key="${CF_GlobalKey}"
  796. export CF_Email=${CF_AccountEmail}
  797. ~/.acme.sh/acme.sh --issue --dns dns_cf -d ${CF_Domain} -d *.${CF_Domain} --log
  798. if [ $? -ne 0 ]; then
  799. LOGE "Certificate issuance failed, script exiting..."
  800. exit 1
  801. else
  802. LOGI "Certificate issued Successfully, Installing..."
  803. fi
  804. ~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \
  805. --cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \
  806. --fullchain-file /root/cert/fullchain.cer
  807. if [ $? -ne 0 ]; then
  808. LOGE "Certificate installation failed, script exiting..."
  809. exit 1
  810. else
  811. LOGI "Certificate installed Successfully,Turning on automatic updates..."
  812. fi
  813. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  814. if [ $? -ne 0 ]; then
  815. LOGE "Auto update setup Failed, script exiting..."
  816. ls -lah cert
  817. chmod 755 $certPath
  818. exit 1
  819. else
  820. LOGI "The certificate is installed and auto-renewal is turned on, Specific information is as follows"
  821. ls -lah cert
  822. chmod 755 $certPath
  823. fi
  824. else
  825. show_menu
  826. fi
  827. }
  828. warp_cloudflare() {
  829. echo -e "${green}\t1.${plain} Install WARP socks5 proxy"
  830. echo -e "${green}\t2.${plain} Account Type (free, plus, team)"
  831. echo -e "${green}\t3.${plain} Turn on/off WireProxy"
  832. echo -e "${green}\t4.${plain} Uninstall WARP"
  833. echo -e "${green}\t0.${plain} Back to Main Menu"
  834. read -p "Choose an option: " choice
  835. case "$choice" in
  836. 0)
  837. show_menu
  838. ;;
  839. 1)
  840. bash <(curl -sSL https://raw.githubusercontent.com/hamid-gh98/x-ui-scripts/main/install_warp_proxy.sh)
  841. ;;
  842. 2)
  843. warp a
  844. ;;
  845. 3)
  846. warp y
  847. ;;
  848. 4)
  849. warp u
  850. ;;
  851. *) echo "Invalid choice" ;;
  852. esac
  853. }
  854. run_speedtest() {
  855. # Check if Speedtest is already installed
  856. if ! command -v speedtest &>/dev/null; then
  857. # If not installed, install it
  858. local pkg_manager=""
  859. local speedtest_install_script=""
  860. if command -v dnf &>/dev/null; then
  861. pkg_manager="dnf"
  862. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
  863. elif command -v yum &>/dev/null; then
  864. pkg_manager="yum"
  865. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
  866. elif command -v apt-get &>/dev/null; then
  867. pkg_manager="apt-get"
  868. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
  869. elif command -v apt &>/dev/null; then
  870. pkg_manager="apt"
  871. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
  872. fi
  873. if [[ -z $pkg_manager ]]; then
  874. echo "Error: Package manager not found. You may need to install Speedtest manually."
  875. return 1
  876. else
  877. curl -s $speedtest_install_script | bash
  878. $pkg_manager install -y speedtest
  879. fi
  880. fi
  881. # Run Speedtest
  882. speedtest
  883. }
  884. create_iplimit_jails() {
  885. # Use default bantime if not passed => 15 minutes
  886. local bantime="${1:-15}"
  887. # Uncomment 'allowipv6 = auto' in fail2ban.conf
  888. sed -i 's/#allowipv6 = auto/allowipv6 = auto/g' /etc/fail2ban/fail2ban.conf
  889. #On Debian 12+ fail2ban's default backend should be changed to systemd
  890. if [[ "${release}" == "debian" && ${os_version} -ge 12 ]]; then
  891. sed -i '0,/action =/s/backend = auto/backend = systemd/' /etc/fail2ban/jail.conf
  892. fi
  893. cat << EOF > /etc/fail2ban/jail.d/3x-ipl.conf
  894. [3x-ipl]
  895. enabled=true
  896. backend=auto
  897. filter=3x-ipl
  898. action=3x-ipl
  899. logpath=${iplimit_log_path}
  900. maxretry=2
  901. findtime=32
  902. bantime=${bantime}m
  903. EOF
  904. cat << EOF > /etc/fail2ban/filter.d/3x-ipl.conf
  905. [Definition]
  906. datepattern = ^%%Y/%%m/%%d %%H:%%M:%%S
  907. failregex = \[LIMIT_IP\]\s*Email\s*=\s*<F-USER>.+</F-USER>\s*\|\|\s*SRC\s*=\s*<ADDR>
  908. ignoreregex =
  909. EOF
  910. cat << EOF > /etc/fail2ban/action.d/3x-ipl.conf
  911. [INCLUDES]
  912. before = iptables-allports.conf
  913. [Definition]
  914. actionstart = <iptables> -N f2b-<name>
  915. <iptables> -A f2b-<name> -j <returntype>
  916. <iptables> -I <chain> -p <protocol> -j f2b-<name>
  917. actionstop = <iptables> -D <chain> -p <protocol> -j f2b-<name>
  918. <actionflush>
  919. <iptables> -X f2b-<name>
  920. actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'
  921. actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
  922. echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") BAN [Email] = <F-USER> [IP] = <ip> banned for <bantime> seconds." >> ${iplimit_banned_log_path}
  923. actionunban = <iptables> -D f2b-<name> -s <ip> -j <blocktype>
  924. echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") UNBAN [Email] = <F-USER> [IP] = <ip> unbanned." >> ${iplimit_banned_log_path}
  925. [Init]
  926. EOF
  927. echo -e "${green}Ip Limit jail files created with a bantime of ${bantime} minutes.${plain}"
  928. }
  929. iplimit_remove_conflicts() {
  930. local jail_files=(
  931. /etc/fail2ban/jail.conf
  932. /etc/fail2ban/jail.local
  933. )
  934. for file in "${jail_files[@]}"; do
  935. # Check for [3x-ipl] config in jail file then remove it
  936. if test -f "${file}" && grep -qw '3x-ipl' ${file}; then
  937. sed -i "/\[3x-ipl\]/,/^$/d" ${file}
  938. echo -e "${yellow}Removing conflicts of [3x-ipl] in jail (${file})!${plain}\n"
  939. fi
  940. done
  941. }
  942. iplimit_main() {
  943. echo -e "\n${green}\t1.${plain} Install Fail2ban and configure IP Limit"
  944. echo -e "${green}\t2.${plain} Change Ban Duration"
  945. echo -e "${green}\t3.${plain} Unban Everyone"
  946. echo -e "${green}\t4.${plain} Check Logs"
  947. echo -e "${green}\t5.${plain} fail2ban status"
  948. echo -e "${green}\t6.${plain} Uninstall IP Limit"
  949. echo -e "${green}\t0.${plain} Back to Main Menu"
  950. read -p "Choose an option: " choice
  951. case "$choice" in
  952. 0)
  953. show_menu
  954. ;;
  955. 1)
  956. confirm "Proceed with installation of Fail2ban & IP Limit?" "y"
  957. if [[ $? == 0 ]]; then
  958. install_iplimit
  959. else
  960. iplimit_main
  961. fi
  962. ;;
  963. 2)
  964. read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM
  965. if [[ $NUM =~ ^[0-9]+$ ]]; then
  966. create_iplimit_jails ${NUM}
  967. systemctl restart fail2ban
  968. else
  969. echo -e "${red}${NUM} is not a number! Please, try again.${plain}"
  970. fi
  971. iplimit_main
  972. ;;
  973. 3)
  974. confirm "Proceed with Unbanning everyone from IP Limit jail?" "y"
  975. if [[ $? == 0 ]]; then
  976. fail2ban-client reload --restart --unban 3x-ipl
  977. truncate -s 0 "${iplimit_banned_log_path}"
  978. echo -e "${green}All users Unbanned successfully.${plain}"
  979. iplimit_main
  980. else
  981. echo -e "${yellow}Cancelled.${plain}"
  982. fi
  983. iplimit_main
  984. ;;
  985. 4)
  986. show_banlog
  987. ;;
  988. 5)
  989. service fail2ban status
  990. ;;
  991. 6)
  992. remove_iplimit
  993. ;;
  994. *) echo "Invalid choice" ;;
  995. esac
  996. }
  997. install_iplimit() {
  998. if ! command -v fail2ban-client &>/dev/null; then
  999. echo -e "${green}Fail2ban is not installed. Installing now...!${plain}\n"
  1000. # Check the OS and install necessary packages
  1001. case "${release}" in
  1002. ubuntu | debian | armbian)
  1003. apt update && apt install fail2ban -y
  1004. ;;
  1005. centos | almalinux | rocky | oracle)
  1006. yum update -y && yum install epel-release -y
  1007. yum -y install fail2ban
  1008. ;;
  1009. fedora)
  1010. dnf -y update && dnf -y install fail2ban
  1011. ;;
  1012. arch | manjaro)
  1013. pacman -Syu --noconfirm fail2ban
  1014. ;;
  1015. *)
  1016. echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
  1017. exit 1
  1018. ;;
  1019. esac
  1020. if ! command -v fail2ban-client &>/dev/null; then
  1021. echo -e "${red}Fail2ban installation failed.${plain}\n"
  1022. exit 1
  1023. fi
  1024. echo -e "${green}Fail2ban installed successfully!${plain}\n"
  1025. else
  1026. echo -e "${yellow}Fail2ban is already installed.${plain}\n"
  1027. fi
  1028. echo -e "${green}Configuring IP Limit...${plain}\n"
  1029. # make sure there's no conflict for jail files
  1030. iplimit_remove_conflicts
  1031. # Check if log file exists
  1032. if ! test -f "${iplimit_banned_log_path}"; then
  1033. touch ${iplimit_banned_log_path}
  1034. fi
  1035. # Check if service log file exists so fail2ban won't return error
  1036. if ! test -f "${iplimit_log_path}"; then
  1037. touch ${iplimit_log_path}
  1038. fi
  1039. # Create the iplimit jail files
  1040. # we didn't pass the bantime here to use the default value
  1041. create_iplimit_jails
  1042. # Launching fail2ban
  1043. if ! systemctl is-active --quiet fail2ban; then
  1044. systemctl start fail2ban
  1045. systemctl enable fail2ban
  1046. else
  1047. systemctl restart fail2ban
  1048. fi
  1049. systemctl enable fail2ban
  1050. echo -e "${green}IP Limit installed and configured successfully!${plain}\n"
  1051. before_show_menu
  1052. }
  1053. remove_iplimit() {
  1054. echo -e "${green}\t1.${plain} Only remove IP Limit configurations"
  1055. echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit"
  1056. echo -e "${green}\t0.${plain} Abort"
  1057. read -p "Choose an option: " num
  1058. case "$num" in
  1059. 1)
  1060. rm -f /etc/fail2ban/filter.d/3x-ipl.conf
  1061. rm -f /etc/fail2ban/action.d/3x-ipl.conf
  1062. rm -f /etc/fail2ban/jail.d/3x-ipl.conf
  1063. systemctl restart fail2ban
  1064. echo -e "${green}IP Limit removed successfully!${plain}\n"
  1065. before_show_menu
  1066. ;;
  1067. 2)
  1068. rm -rf /etc/fail2ban
  1069. systemctl stop fail2ban
  1070. case "${release}" in
  1071. ubuntu | debian | armbian)
  1072. apt-get remove -y fail2ban
  1073. apt-get purge -y fail2ban -y
  1074. apt-get autoremove -y
  1075. ;;
  1076. centos | almalinux | rocky | oracle)
  1077. yum remove fail2ban -y
  1078. yum autoremove -y
  1079. ;;
  1080. fedora)
  1081. dnf remove fail2ban -y
  1082. dnf autoremove -y
  1083. ;;
  1084. arch | manjaro)
  1085. pacman -Rns --noconfirm fail2ban
  1086. ;;
  1087. *)
  1088. echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n"
  1089. exit 1
  1090. ;;
  1091. esac
  1092. echo -e "${green}Fail2ban and IP Limit removed successfully!${plain}\n"
  1093. before_show_menu
  1094. ;;
  1095. 0)
  1096. echo -e "${yellow}Cancelled.${plain}\n"
  1097. iplimit_main
  1098. ;;
  1099. *)
  1100. echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
  1101. remove_iplimit
  1102. ;;
  1103. esac
  1104. }
  1105. show_usage() {
  1106. echo "x-ui control menu usages: "
  1107. echo "------------------------------------------"
  1108. echo -e "x-ui - Enter control menu"
  1109. echo -e "x-ui start - Start x-ui "
  1110. echo -e "x-ui stop - Stop x-ui "
  1111. echo -e "x-ui restart - Restart x-ui "
  1112. echo -e "x-ui status - Show x-ui status"
  1113. echo -e "x-ui enable - Enable x-ui on system startup"
  1114. echo -e "x-ui disable - Disable x-ui on system startup"
  1115. echo -e "x-ui log - Check x-ui logs"
  1116. echo -e "x-ui banlog - Check Fail2ban ban logs"
  1117. echo -e "x-ui update - Update x-ui "
  1118. echo -e "x-ui install - Install x-ui "
  1119. echo -e "x-ui uninstall - Uninstall x-ui "
  1120. echo "------------------------------------------"
  1121. }
  1122. show_menu() {
  1123. echo -e "
  1124. ${green}3X-ui Panel Management Script${plain}
  1125. ${green}0.${plain} Exit Script
  1126. ————————————————
  1127. ${green}1.${plain} Install
  1128. ${green}2.${plain} Update
  1129. ${green}3.${plain} Custom Version
  1130. ${green}4.${plain} Uninstall
  1131. ————————————————
  1132. ${green}5.${plain} Reset Username & Password & Secret Token
  1133. ${green}6.${plain} Reset Settings
  1134. ${green}7.${plain} Change Port
  1135. ${green}8.${plain} View Current Settings
  1136. ————————————————
  1137. ${green}9.${plain} Start
  1138. ${green}10.${plain} Stop
  1139. ${green}11.${plain} Restart
  1140. ${green}12.${plain} Check Status
  1141. ${green}13.${plain} Check Logs
  1142. ————————————————
  1143. ${green}14.${plain} Enable Autostart
  1144. ${green}15.${plain} Disable Autostart
  1145. ————————————————
  1146. ${green}16.${plain} SSL Certificate Management
  1147. ${green}17.${plain} Cloudflare SSL Certificate
  1148. ${green}18.${plain} IP Limit Management
  1149. ${green}19.${plain} WARP Management
  1150. ${green}20.${plain} Firewall Management
  1151. ————————————————
  1152. ${green}21.${plain} Enable BBR
  1153. ${green}22.${plain} Update Geo Files
  1154. ${green}23.${plain} Speedtest by Ookla
  1155. "
  1156. show_status
  1157. echo && read -p "Please enter your selection [0-23]: " num
  1158. case "${num}" in
  1159. 0)
  1160. exit 0
  1161. ;;
  1162. 1)
  1163. check_uninstall && install
  1164. ;;
  1165. 2)
  1166. check_install && update
  1167. ;;
  1168. 3)
  1169. check_install && custom_version
  1170. ;;
  1171. 4)
  1172. check_install && uninstall
  1173. ;;
  1174. 5)
  1175. check_install && reset_user
  1176. ;;
  1177. 6)
  1178. check_install && reset_config
  1179. ;;
  1180. 7)
  1181. check_install && set_port
  1182. ;;
  1183. 8)
  1184. check_install && check_config
  1185. ;;
  1186. 9)
  1187. check_install && start
  1188. ;;
  1189. 10)
  1190. check_install && stop
  1191. ;;
  1192. 11)
  1193. check_install && restart
  1194. ;;
  1195. 12)
  1196. check_install && status
  1197. ;;
  1198. 13)
  1199. check_install && show_log
  1200. ;;
  1201. 14)
  1202. check_install && enable
  1203. ;;
  1204. 15)
  1205. check_install && disable
  1206. ;;
  1207. 16)
  1208. ssl_cert_issue_main
  1209. ;;
  1210. 17)
  1211. ssl_cert_issue_CF
  1212. ;;
  1213. 18)
  1214. iplimit_main
  1215. ;;
  1216. 19)
  1217. warp_cloudflare
  1218. ;;
  1219. 20)
  1220. firewall_menu
  1221. ;;
  1222. 21)
  1223. bbr_menu
  1224. ;;
  1225. 22)
  1226. update_geo
  1227. ;;
  1228. 23)
  1229. run_speedtest
  1230. ;;
  1231. *)
  1232. LOGE "Please enter the correct number [0-23]"
  1233. ;;
  1234. esac
  1235. }
  1236. if [[ $# > 0 ]]; then
  1237. case $1 in
  1238. "start")
  1239. check_install 0 && start 0
  1240. ;;
  1241. "stop")
  1242. check_install 0 && stop 0
  1243. ;;
  1244. "restart")
  1245. check_install 0 && restart 0
  1246. ;;
  1247. "status")
  1248. check_install 0 && status 0
  1249. ;;
  1250. "enable")
  1251. check_install 0 && enable 0
  1252. ;;
  1253. "disable")
  1254. check_install 0 && disable 0
  1255. ;;
  1256. "log")
  1257. check_install 0 && show_log 0
  1258. ;;
  1259. "banlog")
  1260. check_install 0 && show_banlog 0
  1261. ;;
  1262. "update")
  1263. check_install 0 && update 0
  1264. ;;
  1265. "install")
  1266. check_uninstall 0 && install 0
  1267. ;;
  1268. "uninstall")
  1269. check_install 0 && uninstall 0
  1270. ;;
  1271. *) show_usage ;;
  1272. esac
  1273. else
  1274. show_menu
  1275. fi