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 | parch)
  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. echo "Activating firewall..."
  534. # Open the necessary ports
  535. ufw allow ssh
  536. ufw allow http
  537. ufw allow https
  538. ufw allow 2053/tcp
  539. # Enable the firewall
  540. ufw --force enable
  541. fi
  542. # Prompt the user to enter a list of ports
  543. read -p "Enter the ports you want to open (e.g. 80,443,2053 or range 400-500): " ports
  544. # Check if the input is valid
  545. if ! [[ $ports =~ ^([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))*$ ]]; then
  546. 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
  547. exit 1
  548. fi
  549. # Open the specified ports using ufw
  550. IFS=',' read -ra PORT_LIST <<<"$ports"
  551. for port in "${PORT_LIST[@]}"; do
  552. if [[ $port == *-* ]]; then
  553. # Split the range into start and end ports
  554. start_port=$(echo $port | cut -d'-' -f1)
  555. end_port=$(echo $port | cut -d'-' -f2)
  556. ufw allow $start_port:$end_port
  557. else
  558. ufw allow "$port"
  559. fi
  560. done
  561. # Confirm that the ports are open
  562. echo "The following ports are now open:"
  563. ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?"
  564. echo "Firewall status:"
  565. ufw status verbose
  566. }
  567. delete_ports() {
  568. # Prompt the user to enter the ports they want to delete
  569. read -p "Enter the ports you want to delete (e.g. 80,443,2053 or range 400-500): " ports
  570. # Check if the input is valid
  571. if ! [[ $ports =~ ^([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))*$ ]]; then
  572. 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
  573. exit 1
  574. fi
  575. # Delete the specified ports using ufw
  576. IFS=',' read -ra PORT_LIST <<<"$ports"
  577. for port in "${PORT_LIST[@]}"; do
  578. if [[ $port == *-* ]]; then
  579. # Split the range into start and end ports
  580. start_port=$(echo $port | cut -d'-' -f1)
  581. end_port=$(echo $port | cut -d'-' -f2)
  582. # Delete the port range
  583. ufw delete allow $start_port:$end_port
  584. else
  585. ufw delete allow "$port"
  586. fi
  587. done
  588. # Confirm that the ports are deleted
  589. echo "Deleted the specified ports:"
  590. ufw status | grep "ALLOW" | grep -Eo "[0-9]+(/[a-z]+)?"
  591. }
  592. update_geo() {
  593. local defaultBinFolder="/usr/local/x-ui/bin"
  594. read -p "Please enter x-ui bin folder path. Leave blank for default. (Default: '${defaultBinFolder}')" binFolder
  595. binFolder=${binFolder:-${defaultBinFolder}}
  596. if [[ ! -d ${binFolder} ]]; then
  597. LOGE "Folder ${binFolder} not exists!"
  598. LOGI "making bin folder: ${binFolder}..."
  599. mkdir -p ${binFolder}
  600. fi
  601. systemctl stop x-ui
  602. cd ${binFolder}
  603. rm -f geoip.dat geosite.dat geoip_IR.dat geosite_IR.dat geoip_VN.dat geosite_VN.dat
  604. wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
  605. wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
  606. wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
  607. wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
  608. wget -O geoip_VN.dat https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geoip.dat
  609. wget -O geosite_VN.dat https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geosite.dat
  610. systemctl start x-ui
  611. echo -e "${green}Geosite.dat + Geoip.dat + geoip_IR.dat + geosite_IR.dat have been updated successfully in bin folder '${binfolder}'!${plain}"
  612. before_show_menu
  613. }
  614. install_acme() {
  615. cd ~
  616. LOGI "install acme..."
  617. curl https://get.acme.sh | sh
  618. if [ $? -ne 0 ]; then
  619. LOGE "install acme failed"
  620. return 1
  621. else
  622. LOGI "install acme succeed"
  623. fi
  624. return 0
  625. }
  626. ssl_cert_issue_main() {
  627. echo -e "${green}\t1.${plain} Get SSL"
  628. echo -e "${green}\t2.${plain} Revoke"
  629. echo -e "${green}\t3.${plain} Force Renew"
  630. echo -e "${green}\t0.${plain} Back to Main Menu"
  631. read -p "Choose an option: " choice
  632. case "$choice" in
  633. 0)
  634. show_menu
  635. ;;
  636. 1)
  637. ssl_cert_issue
  638. ;;
  639. 2)
  640. local domain=""
  641. read -p "Please enter your domain name to revoke the certificate: " domain
  642. ~/.acme.sh/acme.sh --revoke -d ${domain}
  643. LOGI "Certificate revoked"
  644. ;;
  645. 3)
  646. local domain=""
  647. read -p "Please enter your domain name to forcefully renew an SSL certificate: " domain
  648. ~/.acme.sh/acme.sh --renew -d ${domain} --force
  649. ;;
  650. *) echo "Invalid choice" ;;
  651. esac
  652. }
  653. ssl_cert_issue() {
  654. # check for acme.sh first
  655. if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then
  656. echo "acme.sh could not be found. we will install it"
  657. install_acme
  658. if [ $? -ne 0 ]; then
  659. LOGE "install acme failed, please check logs"
  660. exit 1
  661. fi
  662. fi
  663. # install socat second
  664. case "${release}" in
  665. ubuntu | debian | armbian)
  666. apt update && apt install socat -y
  667. ;;
  668. centos | almalinux | rocky | oracle)
  669. yum -y update && yum -y install socat
  670. ;;
  671. fedora)
  672. dnf -y update && dnf -y install socat
  673. ;;
  674. arch | manjaro | parch)
  675. pacman -Sy --noconfirm socat
  676. ;;
  677. *)
  678. echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
  679. exit 1
  680. ;;
  681. esac
  682. if [ $? -ne 0 ]; then
  683. LOGE "install socat failed, please check logs"
  684. exit 1
  685. else
  686. LOGI "install socat succeed..."
  687. fi
  688. # get the domain here,and we need verify it
  689. local domain=""
  690. read -p "Please enter your domain name:" domain
  691. LOGD "your domain is:${domain},check it..."
  692. # here we need to judge whether there exists cert already
  693. local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
  694. if [ ${currentCert} == ${domain} ]; then
  695. local certInfo=$(~/.acme.sh/acme.sh --list)
  696. LOGE "system already has certs here,can not issue again,current certs details:"
  697. LOGI "$certInfo"
  698. exit 1
  699. else
  700. LOGI "your domain is ready for issuing cert now..."
  701. fi
  702. # create a directory for install cert
  703. certPath="/root/cert/${domain}"
  704. if [ ! -d "$certPath" ]; then
  705. mkdir -p "$certPath"
  706. else
  707. rm -rf "$certPath"
  708. mkdir -p "$certPath"
  709. fi
  710. # get needed port here
  711. local WebPort=80
  712. read -p "please choose which port do you use,default will be 80 port:" WebPort
  713. if [[ ${WebPort} -gt 65535 || ${WebPort} -lt 1 ]]; then
  714. LOGE "your input ${WebPort} is invalid,will use default port"
  715. fi
  716. LOGI "will use port:${WebPort} to issue certs,please make sure this port is open..."
  717. # NOTE:This should be handled by user
  718. # open the port and kill the occupied progress
  719. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  720. ~/.acme.sh/acme.sh --issue -d ${domain} --standalone --httpport ${WebPort}
  721. if [ $? -ne 0 ]; then
  722. LOGE "issue certs failed,please check logs"
  723. rm -rf ~/.acme.sh/${domain}
  724. exit 1
  725. else
  726. LOGE "issue certs succeed,installing certs..."
  727. fi
  728. # install cert
  729. ~/.acme.sh/acme.sh --installcert -d ${domain} \
  730. --key-file /root/cert/${domain}/privkey.pem \
  731. --fullchain-file /root/cert/${domain}/fullchain.pem
  732. if [ $? -ne 0 ]; then
  733. LOGE "install certs failed,exit"
  734. rm -rf ~/.acme.sh/${domain}
  735. exit 1
  736. else
  737. LOGI "install certs succeed,enable auto renew..."
  738. fi
  739. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  740. if [ $? -ne 0 ]; then
  741. LOGE "auto renew failed, certs details:"
  742. ls -lah cert/*
  743. chmod 755 $certPath/*
  744. exit 1
  745. else
  746. LOGI "auto renew succeed, certs details:"
  747. ls -lah cert/*
  748. chmod 755 $certPath/*
  749. fi
  750. }
  751. ssl_cert_issue_CF() {
  752. echo -E ""
  753. LOGD "******Instructions for use******"
  754. LOGI "This Acme script requires the following data:"
  755. LOGI "1.Cloudflare Registered e-mail"
  756. LOGI "2.Cloudflare Global API Key"
  757. LOGI "3.The domain name that has been resolved dns to the current server by Cloudflare"
  758. LOGI "4.The script applies for a certificate. The default installation path is /root/cert "
  759. confirm "Confirmed?[y/n]" "y"
  760. if [ $? -eq 0 ]; then
  761. # check for acme.sh first
  762. if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then
  763. echo "acme.sh could not be found. we will install it"
  764. install_acme
  765. if [ $? -ne 0 ]; then
  766. LOGE "install acme failed, please check logs"
  767. exit 1
  768. fi
  769. fi
  770. CF_Domain=""
  771. CF_GlobalKey=""
  772. CF_AccountEmail=""
  773. certPath=/root/cert
  774. if [ ! -d "$certPath" ]; then
  775. mkdir $certPath
  776. else
  777. rm -rf $certPath
  778. mkdir $certPath
  779. fi
  780. LOGD "Please set a domain name:"
  781. read -p "Input your domain here:" CF_Domain
  782. LOGD "Your domain name is set to:${CF_Domain}"
  783. LOGD "Please set the API key:"
  784. read -p "Input your key here:" CF_GlobalKey
  785. LOGD "Your API key is:${CF_GlobalKey}"
  786. LOGD "Please set up registered email:"
  787. read -p "Input your email here:" CF_AccountEmail
  788. LOGD "Your registered email address is:${CF_AccountEmail}"
  789. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  790. if [ $? -ne 0 ]; then
  791. LOGE "Default CA, Lets'Encrypt fail, script exiting..."
  792. exit 1
  793. fi
  794. export CF_Key="${CF_GlobalKey}"
  795. export CF_Email=${CF_AccountEmail}
  796. ~/.acme.sh/acme.sh --issue --dns dns_cf -d ${CF_Domain} -d *.${CF_Domain} --log
  797. if [ $? -ne 0 ]; then
  798. LOGE "Certificate issuance failed, script exiting..."
  799. exit 1
  800. else
  801. LOGI "Certificate issued Successfully, Installing..."
  802. fi
  803. ~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \
  804. --cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \
  805. --fullchain-file /root/cert/fullchain.cer
  806. if [ $? -ne 0 ]; then
  807. LOGE "Certificate installation failed, script exiting..."
  808. exit 1
  809. else
  810. LOGI "Certificate installed Successfully,Turning on automatic updates..."
  811. fi
  812. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  813. if [ $? -ne 0 ]; then
  814. LOGE "Auto update setup Failed, script exiting..."
  815. ls -lah cert
  816. chmod 755 $certPath
  817. exit 1
  818. else
  819. LOGI "The certificate is installed and auto-renewal is turned on, Specific information is as follows"
  820. ls -lah cert
  821. chmod 755 $certPath
  822. fi
  823. else
  824. show_menu
  825. fi
  826. }
  827. warp_cloudflare() {
  828. echo -e "${green}\t1.${plain} Install WARP socks5 proxy"
  829. echo -e "${green}\t2.${plain} Account Type (free, plus, team)"
  830. echo -e "${green}\t3.${plain} Turn on/off WireProxy"
  831. echo -e "${green}\t4.${plain} Uninstall WARP"
  832. echo -e "${green}\t0.${plain} Back to Main Menu"
  833. read -p "Choose an option: " choice
  834. case "$choice" in
  835. 0)
  836. show_menu
  837. ;;
  838. 1)
  839. bash <(curl -sSL https://raw.githubusercontent.com/hamid-gh98/x-ui-scripts/main/install_warp_proxy.sh)
  840. ;;
  841. 2)
  842. warp a
  843. ;;
  844. 3)
  845. warp y
  846. ;;
  847. 4)
  848. warp u
  849. ;;
  850. *) echo "Invalid choice" ;;
  851. esac
  852. }
  853. run_speedtest() {
  854. # Check if Speedtest is already installed
  855. if ! command -v speedtest &>/dev/null; then
  856. # If not installed, install it
  857. local pkg_manager=""
  858. local speedtest_install_script=""
  859. if command -v dnf &>/dev/null; then
  860. pkg_manager="dnf"
  861. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
  862. elif command -v yum &>/dev/null; then
  863. pkg_manager="yum"
  864. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh"
  865. elif command -v apt-get &>/dev/null; then
  866. pkg_manager="apt-get"
  867. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
  868. elif command -v apt &>/dev/null; then
  869. pkg_manager="apt"
  870. speedtest_install_script="https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh"
  871. fi
  872. if [[ -z $pkg_manager ]]; then
  873. echo "Error: Package manager not found. You may need to install Speedtest manually."
  874. return 1
  875. else
  876. curl -s $speedtest_install_script | bash
  877. $pkg_manager install -y speedtest
  878. fi
  879. fi
  880. # Run Speedtest
  881. speedtest
  882. }
  883. create_iplimit_jails() {
  884. # Use default bantime if not passed => 15 minutes
  885. local bantime="${1:-15}"
  886. # Uncomment 'allowipv6 = auto' in fail2ban.conf
  887. sed -i 's/#allowipv6 = auto/allowipv6 = auto/g' /etc/fail2ban/fail2ban.conf
  888. #On Debian 12+ fail2ban's default backend should be changed to systemd
  889. if [[ "${release}" == "debian" && ${os_version} -ge 12 ]]; then
  890. sed -i '0,/action =/s/backend = auto/backend = systemd/' /etc/fail2ban/jail.conf
  891. fi
  892. cat << EOF > /etc/fail2ban/jail.d/3x-ipl.conf
  893. [3x-ipl]
  894. enabled=true
  895. backend=auto
  896. filter=3x-ipl
  897. action=3x-ipl
  898. logpath=${iplimit_log_path}
  899. maxretry=2
  900. findtime=32
  901. bantime=${bantime}m
  902. EOF
  903. cat << EOF > /etc/fail2ban/filter.d/3x-ipl.conf
  904. [Definition]
  905. datepattern = ^%%Y/%%m/%%d %%H:%%M:%%S
  906. failregex = \[LIMIT_IP\]\s*Email\s*=\s*<F-USER>.+</F-USER>\s*\|\|\s*SRC\s*=\s*<ADDR>
  907. ignoreregex =
  908. EOF
  909. cat << EOF > /etc/fail2ban/action.d/3x-ipl.conf
  910. [INCLUDES]
  911. before = iptables-allports.conf
  912. [Definition]
  913. actionstart = <iptables> -N f2b-<name>
  914. <iptables> -A f2b-<name> -j <returntype>
  915. <iptables> -I <chain> -p <protocol> -j f2b-<name>
  916. actionstop = <iptables> -D <chain> -p <protocol> -j f2b-<name>
  917. <actionflush>
  918. <iptables> -X f2b-<name>
  919. actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'
  920. actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
  921. echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") BAN [Email] = <F-USER> [IP] = <ip> banned for <bantime> seconds." >> ${iplimit_banned_log_path}
  922. actionunban = <iptables> -D f2b-<name> -s <ip> -j <blocktype>
  923. echo "\$(date +"%%Y/%%m/%%d %%H:%%M:%%S") UNBAN [Email] = <F-USER> [IP] = <ip> unbanned." >> ${iplimit_banned_log_path}
  924. [Init]
  925. EOF
  926. echo -e "${green}Ip Limit jail files created with a bantime of ${bantime} minutes.${plain}"
  927. }
  928. iplimit_remove_conflicts() {
  929. local jail_files=(
  930. /etc/fail2ban/jail.conf
  931. /etc/fail2ban/jail.local
  932. )
  933. for file in "${jail_files[@]}"; do
  934. # Check for [3x-ipl] config in jail file then remove it
  935. if test -f "${file}" && grep -qw '3x-ipl' ${file}; then
  936. sed -i "/\[3x-ipl\]/,/^$/d" ${file}
  937. echo -e "${yellow}Removing conflicts of [3x-ipl] in jail (${file})!${plain}\n"
  938. fi
  939. done
  940. }
  941. iplimit_main() {
  942. echo -e "\n${green}\t1.${plain} Install Fail2ban and configure IP Limit"
  943. echo -e "${green}\t2.${plain} Change Ban Duration"
  944. echo -e "${green}\t3.${plain} Unban Everyone"
  945. echo -e "${green}\t4.${plain} Check Logs"
  946. echo -e "${green}\t5.${plain} fail2ban status"
  947. echo -e "${green}\t6.${plain} Uninstall IP Limit"
  948. echo -e "${green}\t0.${plain} Back to Main Menu"
  949. read -p "Choose an option: " choice
  950. case "$choice" in
  951. 0)
  952. show_menu
  953. ;;
  954. 1)
  955. confirm "Proceed with installation of Fail2ban & IP Limit?" "y"
  956. if [[ $? == 0 ]]; then
  957. install_iplimit
  958. else
  959. iplimit_main
  960. fi
  961. ;;
  962. 2)
  963. read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM
  964. if [[ $NUM =~ ^[0-9]+$ ]]; then
  965. create_iplimit_jails ${NUM}
  966. systemctl restart fail2ban
  967. else
  968. echo -e "${red}${NUM} is not a number! Please, try again.${plain}"
  969. fi
  970. iplimit_main
  971. ;;
  972. 3)
  973. confirm "Proceed with Unbanning everyone from IP Limit jail?" "y"
  974. if [[ $? == 0 ]]; then
  975. fail2ban-client reload --restart --unban 3x-ipl
  976. truncate -s 0 "${iplimit_banned_log_path}"
  977. echo -e "${green}All users Unbanned successfully.${plain}"
  978. iplimit_main
  979. else
  980. echo -e "${yellow}Cancelled.${plain}"
  981. fi
  982. iplimit_main
  983. ;;
  984. 4)
  985. show_banlog
  986. ;;
  987. 5)
  988. service fail2ban status
  989. ;;
  990. 6)
  991. remove_iplimit
  992. ;;
  993. *) echo "Invalid choice" ;;
  994. esac
  995. }
  996. install_iplimit() {
  997. if ! command -v fail2ban-client &>/dev/null; then
  998. echo -e "${green}Fail2ban is not installed. Installing now...!${plain}\n"
  999. # Check the OS and install necessary packages
  1000. case "${release}" in
  1001. ubuntu | debian | armbian)
  1002. apt update && apt install fail2ban -y
  1003. ;;
  1004. centos | almalinux | rocky | oracle)
  1005. yum update -y && yum install epel-release -y
  1006. yum -y install fail2ban
  1007. ;;
  1008. fedora)
  1009. dnf -y update && dnf -y install fail2ban
  1010. ;;
  1011. arch | manjaro | parch)
  1012. pacman -Syu --noconfirm fail2ban
  1013. ;;
  1014. *)
  1015. echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
  1016. exit 1
  1017. ;;
  1018. esac
  1019. if ! command -v fail2ban-client &>/dev/null; then
  1020. echo -e "${red}Fail2ban installation failed.${plain}\n"
  1021. exit 1
  1022. fi
  1023. echo -e "${green}Fail2ban installed successfully!${plain}\n"
  1024. else
  1025. echo -e "${yellow}Fail2ban is already installed.${plain}\n"
  1026. fi
  1027. echo -e "${green}Configuring IP Limit...${plain}\n"
  1028. # make sure there's no conflict for jail files
  1029. iplimit_remove_conflicts
  1030. # Check if log file exists
  1031. if ! test -f "${iplimit_banned_log_path}"; then
  1032. touch ${iplimit_banned_log_path}
  1033. fi
  1034. # Check if service log file exists so fail2ban won't return error
  1035. if ! test -f "${iplimit_log_path}"; then
  1036. touch ${iplimit_log_path}
  1037. fi
  1038. # Create the iplimit jail files
  1039. # we didn't pass the bantime here to use the default value
  1040. create_iplimit_jails
  1041. # Launching fail2ban
  1042. if ! systemctl is-active --quiet fail2ban; then
  1043. systemctl start fail2ban
  1044. systemctl enable fail2ban
  1045. else
  1046. systemctl restart fail2ban
  1047. fi
  1048. systemctl enable fail2ban
  1049. echo -e "${green}IP Limit installed and configured successfully!${plain}\n"
  1050. before_show_menu
  1051. }
  1052. remove_iplimit() {
  1053. echo -e "${green}\t1.${plain} Only remove IP Limit configurations"
  1054. echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit"
  1055. echo -e "${green}\t0.${plain} Abort"
  1056. read -p "Choose an option: " num
  1057. case "$num" in
  1058. 1)
  1059. rm -f /etc/fail2ban/filter.d/3x-ipl.conf
  1060. rm -f /etc/fail2ban/action.d/3x-ipl.conf
  1061. rm -f /etc/fail2ban/jail.d/3x-ipl.conf
  1062. systemctl restart fail2ban
  1063. echo -e "${green}IP Limit removed successfully!${plain}\n"
  1064. before_show_menu
  1065. ;;
  1066. 2)
  1067. rm -rf /etc/fail2ban
  1068. systemctl stop fail2ban
  1069. case "${release}" in
  1070. ubuntu | debian | armbian)
  1071. apt-get remove -y fail2ban
  1072. apt-get purge -y fail2ban -y
  1073. apt-get autoremove -y
  1074. ;;
  1075. centos | almalinux | rocky | oracle)
  1076. yum remove fail2ban -y
  1077. yum autoremove -y
  1078. ;;
  1079. fedora)
  1080. dnf remove fail2ban -y
  1081. dnf autoremove -y
  1082. ;;
  1083. arch | manjaro | parch)
  1084. pacman -Rns --noconfirm fail2ban
  1085. ;;
  1086. *)
  1087. echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n"
  1088. exit 1
  1089. ;;
  1090. esac
  1091. echo -e "${green}Fail2ban and IP Limit removed successfully!${plain}\n"
  1092. before_show_menu
  1093. ;;
  1094. 0)
  1095. echo -e "${yellow}Cancelled.${plain}\n"
  1096. iplimit_main
  1097. ;;
  1098. *)
  1099. echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
  1100. remove_iplimit
  1101. ;;
  1102. esac
  1103. }
  1104. show_usage() {
  1105. echo "x-ui control menu usages: "
  1106. echo "------------------------------------------"
  1107. echo -e "x-ui - Enter control menu"
  1108. echo -e "x-ui start - Start x-ui "
  1109. echo -e "x-ui stop - Stop x-ui "
  1110. echo -e "x-ui restart - Restart x-ui "
  1111. echo -e "x-ui status - Show x-ui status"
  1112. echo -e "x-ui enable - Enable x-ui on system startup"
  1113. echo -e "x-ui disable - Disable x-ui on system startup"
  1114. echo -e "x-ui log - Check x-ui logs"
  1115. echo -e "x-ui banlog - Check Fail2ban ban logs"
  1116. echo -e "x-ui update - Update x-ui "
  1117. echo -e "x-ui install - Install x-ui "
  1118. echo -e "x-ui uninstall - Uninstall x-ui "
  1119. echo "------------------------------------------"
  1120. }
  1121. show_menu() {
  1122. echo -e "
  1123. ${green}3X-ui Panel Management Script${plain}
  1124. ${green}0.${plain} Exit Script
  1125. ————————————————
  1126. ${green}1.${plain} Install
  1127. ${green}2.${plain} Update
  1128. ${green}3.${plain} Custom Version
  1129. ${green}4.${plain} Uninstall
  1130. ————————————————
  1131. ${green}5.${plain} Reset Username & Password & Secret Token
  1132. ${green}6.${plain} Reset Settings
  1133. ${green}7.${plain} Change Port
  1134. ${green}8.${plain} View Current Settings
  1135. ————————————————
  1136. ${green}9.${plain} Start
  1137. ${green}10.${plain} Stop
  1138. ${green}11.${plain} Restart
  1139. ${green}12.${plain} Check Status
  1140. ${green}13.${plain} Check Logs
  1141. ————————————————
  1142. ${green}14.${plain} Enable Autostart
  1143. ${green}15.${plain} Disable Autostart
  1144. ————————————————
  1145. ${green}16.${plain} SSL Certificate Management
  1146. ${green}17.${plain} Cloudflare SSL Certificate
  1147. ${green}18.${plain} IP Limit Management
  1148. ${green}19.${plain} WARP Management
  1149. ${green}20.${plain} Firewall Management
  1150. ————————————————
  1151. ${green}21.${plain} Enable BBR
  1152. ${green}22.${plain} Update Geo Files
  1153. ${green}23.${plain} Speedtest by Ookla
  1154. "
  1155. show_status
  1156. echo && read -p "Please enter your selection [0-23]: " num
  1157. case "${num}" in
  1158. 0)
  1159. exit 0
  1160. ;;
  1161. 1)
  1162. check_uninstall && install
  1163. ;;
  1164. 2)
  1165. check_install && update
  1166. ;;
  1167. 3)
  1168. check_install && custom_version
  1169. ;;
  1170. 4)
  1171. check_install && uninstall
  1172. ;;
  1173. 5)
  1174. check_install && reset_user
  1175. ;;
  1176. 6)
  1177. check_install && reset_config
  1178. ;;
  1179. 7)
  1180. check_install && set_port
  1181. ;;
  1182. 8)
  1183. check_install && check_config
  1184. ;;
  1185. 9)
  1186. check_install && start
  1187. ;;
  1188. 10)
  1189. check_install && stop
  1190. ;;
  1191. 11)
  1192. check_install && restart
  1193. ;;
  1194. 12)
  1195. check_install && status
  1196. ;;
  1197. 13)
  1198. check_install && show_log
  1199. ;;
  1200. 14)
  1201. check_install && enable
  1202. ;;
  1203. 15)
  1204. check_install && disable
  1205. ;;
  1206. 16)
  1207. ssl_cert_issue_main
  1208. ;;
  1209. 17)
  1210. ssl_cert_issue_CF
  1211. ;;
  1212. 18)
  1213. iplimit_main
  1214. ;;
  1215. 19)
  1216. warp_cloudflare
  1217. ;;
  1218. 20)
  1219. firewall_menu
  1220. ;;
  1221. 21)
  1222. bbr_menu
  1223. ;;
  1224. 22)
  1225. update_geo
  1226. ;;
  1227. 23)
  1228. run_speedtest
  1229. ;;
  1230. *)
  1231. LOGE "Please enter the correct number [0-23]"
  1232. ;;
  1233. esac
  1234. }
  1235. if [[ $# > 0 ]]; then
  1236. case $1 in
  1237. "start")
  1238. check_install 0 && start 0
  1239. ;;
  1240. "stop")
  1241. check_install 0 && stop 0
  1242. ;;
  1243. "restart")
  1244. check_install 0 && restart 0
  1245. ;;
  1246. "status")
  1247. check_install 0 && status 0
  1248. ;;
  1249. "enable")
  1250. check_install 0 && enable 0
  1251. ;;
  1252. "disable")
  1253. check_install 0 && disable 0
  1254. ;;
  1255. "log")
  1256. check_install 0 && show_log 0
  1257. ;;
  1258. "banlog")
  1259. check_install 0 && show_banlog 0
  1260. ;;
  1261. "update")
  1262. check_install 0 && update 0
  1263. ;;
  1264. "install")
  1265. check_uninstall 0 && install 0
  1266. ;;
  1267. "uninstall")
  1268. check_install 0 && uninstall 0
  1269. ;;
  1270. *) show_usage ;;
  1271. esac
  1272. else
  1273. show_menu
  1274. fi