x-ui.sh 41 KB

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