x-ui.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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/redhat-release ]]; then
  20. if grep -Eqi "CentOS" /etc/redhat-release; then
  21. release="centos"
  22. elif grep -Eqi "Fedora" /etc/redhat-release; then
  23. release="fedora"
  24. fi
  25. elif grep -Eqi "debian" /etc/issue; then
  26. release="debian"
  27. elif grep -Eqi "ubuntu" /etc/issue; then
  28. release="ubuntu"
  29. elif grep -Eqi "centos" /etc/issue; then
  30. release="centos"
  31. elif grep -Eqi "debian" /proc/version; then
  32. release="debian"
  33. elif grep -Eqi "ubuntu" /proc/version; then
  34. release="ubuntu"
  35. elif grep -Eqi "centos" /proc/version; then
  36. release="centos"
  37. elif grep -Eqi "fedora" /proc/version; then
  38. release="fedora"
  39. else
  40. echo "Failed to check the system OS, please contact the author!" >&2
  41. exit 1
  42. fi
  43. echo "The OS release is: $release"
  44. os_version=""
  45. # os version
  46. if [[ -f /etc/os-release ]]; then
  47. os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
  48. elif [[ -f /etc/lsb-release ]]; then
  49. os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
  50. elif [[ -f /etc/fedora-release ]]; then
  51. os_version=$(awk -F'[= ]+' '/release/{print $3}' /etc/fedora-release)
  52. fi
  53. case "${release}" in
  54. centos)
  55. if [[ ${os_version} -le 8 ]]; then
  56. echo "Please use CentOS 8 or higher version!"
  57. exit 2
  58. fi
  59. ;;
  60. ubuntu)
  61. if [[ ${os_version} -lt 20 ]]; then
  62. echo "Please use Ubuntu 20 or higher version!"
  63. exit 2
  64. fi
  65. ;;
  66. debian)
  67. if [[ ${os_version} -lt 10 ]]; then
  68. echo "Please use Debian 10 or higher version!"
  69. exit 2
  70. fi
  71. ;;
  72. fedora)
  73. if [[ ${os_version} -lt 29 ]]; then
  74. echo "Please use Fedora 29 or higher version!"
  75. exit 2
  76. fi
  77. ;;
  78. *)
  79. echo "Unknown release type '${release}'"
  80. exit 2
  81. ;;
  82. esac
  83. confirm() {
  84. if [[ $# > 1 ]]; then
  85. echo && read -p "$1 [Default$2]: " temp
  86. if [[ x"${temp}" == x"" ]]; then
  87. temp=$2
  88. fi
  89. else
  90. read -p "$1 [y/n]: " temp
  91. fi
  92. if [[ x"${temp}" == x"y" || x"${temp}" == x"Y" ]]; then
  93. return 0
  94. else
  95. return 1
  96. fi
  97. }
  98. confirm_restart() {
  99. confirm "Restart the panel, Attention: Restarting the panel will also restart xray" "y"
  100. if [[ $? == 0 ]]; then
  101. restart
  102. else
  103. show_menu
  104. fi
  105. }
  106. before_show_menu() {
  107. echo && echo -n -e "${yellow}Press enter to return to the main menu: ${plain}" && read temp
  108. show_menu
  109. }
  110. install() {
  111. bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/main/install.sh)
  112. if [[ $? == 0 ]]; then
  113. if [[ $# == 0 ]]; then
  114. start
  115. else
  116. start 0
  117. fi
  118. fi
  119. }
  120. update() {
  121. confirm "This function will forcefully reinstall the latest version, and the data will not be lost. Do you want to continue?" "n"
  122. if [[ $? != 0 ]]; then
  123. LOGE "Cancelled"
  124. if [[ $# == 0 ]]; then
  125. before_show_menu
  126. fi
  127. return 0
  128. fi
  129. bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/main/install.sh)
  130. if [[ $? == 0 ]]; then
  131. LOGI "Update is complete, Panel has automatically restarted "
  132. exit 0
  133. fi
  134. }
  135. uninstall() {
  136. confirm "Are you sure you want to uninstall the panel? xray will also uninstalled!" "n"
  137. if [[ $? != 0 ]]; then
  138. if [[ $# == 0 ]]; then
  139. show_menu
  140. fi
  141. return 0
  142. fi
  143. systemctl stop x-ui
  144. systemctl disable x-ui
  145. rm /etc/systemd/system/x-ui.service -f
  146. systemctl daemon-reload
  147. systemctl reset-failed
  148. rm /etc/x-ui/ -rf
  149. rm /usr/local/x-ui/ -rf
  150. echo ""
  151. echo -e "Uninstalled Successfully,If you want to remove this script,then after exiting the script run ${green}rm /usr/bin/x-ui -f${plain} to delete it."
  152. echo ""
  153. if [[ $# == 0 ]]; then
  154. before_show_menu
  155. fi
  156. }
  157. reset_user() {
  158. confirm "Reset your username and password to admin?" "n"
  159. if [[ $? != 0 ]]; then
  160. if [[ $# == 0 ]]; then
  161. show_menu
  162. fi
  163. return 0
  164. fi
  165. /usr/local/x-ui/x-ui setting -username admin -password admin
  166. echo -e "Username and password have been reset to ${green}admin${plain},Please restart the panel now."
  167. confirm_restart
  168. }
  169. reset_config() {
  170. confirm "Are you sure you want to reset all panel settings,Account data will not be lost,Username and password will not change" "n"
  171. if [[ $? != 0 ]]; then
  172. if [[ $# == 0 ]]; then
  173. show_menu
  174. fi
  175. return 0
  176. fi
  177. /usr/local/x-ui/x-ui setting -reset
  178. 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"
  179. confirm_restart
  180. }
  181. check_config() {
  182. info=$(/usr/local/x-ui/x-ui setting -show true)
  183. if [[ $? != 0 ]]; then
  184. LOGE "get current settings error,please check logs"
  185. show_menu
  186. fi
  187. LOGI "${info}"
  188. }
  189. set_port() {
  190. echo && echo -n -e "Enter port number[1-65535]: " && read port
  191. if [[ -z "${port}" ]]; then
  192. LOGD "Cancelled"
  193. before_show_menu
  194. else
  195. /usr/local/x-ui/x-ui setting -port ${port}
  196. echo -e "The port is set,Please restart the panel now,and use the new port ${green}${port}${plain} to access web panel"
  197. confirm_restart
  198. fi
  199. }
  200. start() {
  201. check_status
  202. if [[ $? == 0 ]]; then
  203. echo ""
  204. LOGI "Panel is running,No need to start again,If you need to restart, please select restart"
  205. else
  206. systemctl start x-ui
  207. sleep 2
  208. check_status
  209. if [[ $? == 0 ]]; then
  210. LOGI "x-ui Started Successfully"
  211. else
  212. LOGE "panel Failed to start,Probably because it takes longer than two seconds to start,Please check the log information later"
  213. fi
  214. fi
  215. if [[ $# == 0 ]]; then
  216. before_show_menu
  217. fi
  218. }
  219. stop() {
  220. check_status
  221. if [[ $? == 1 ]]; then
  222. echo ""
  223. LOGI "Panel stopped,No need to stop again!"
  224. else
  225. systemctl stop x-ui
  226. sleep 2
  227. check_status
  228. if [[ $? == 1 ]]; then
  229. LOGI "x-ui and xray stopped successfully"
  230. else
  231. LOGE "Panel stop failed,Probably because the stop time exceeds two seconds,Please check the log information later"
  232. fi
  233. fi
  234. if [[ $# == 0 ]]; then
  235. before_show_menu
  236. fi
  237. }
  238. restart() {
  239. systemctl restart x-ui
  240. sleep 2
  241. check_status
  242. if [[ $? == 0 ]]; then
  243. LOGI "x-ui and xray Restarted successfully"
  244. else
  245. LOGE "Panel restart failed,Probably because it takes longer than two seconds to start,Please check the log information later"
  246. fi
  247. if [[ $# == 0 ]]; then
  248. before_show_menu
  249. fi
  250. }
  251. status() {
  252. systemctl status x-ui -l
  253. if [[ $# == 0 ]]; then
  254. before_show_menu
  255. fi
  256. }
  257. enable() {
  258. systemctl enable x-ui
  259. if [[ $? == 0 ]]; then
  260. LOGI "x-ui Set to boot automatically on startup successfully"
  261. else
  262. LOGE "x-ui Failed to set Autostart"
  263. fi
  264. if [[ $# == 0 ]]; then
  265. before_show_menu
  266. fi
  267. }
  268. disable() {
  269. systemctl disable x-ui
  270. if [[ $? == 0 ]]; then
  271. LOGI "x-ui Autostart Cancelled successfully"
  272. else
  273. LOGE "x-ui Failed to cancel autostart"
  274. fi
  275. if [[ $# == 0 ]]; then
  276. before_show_menu
  277. fi
  278. }
  279. show_log() {
  280. journalctl -u x-ui.service -e --no-pager -f
  281. if [[ $# == 0 ]]; then
  282. before_show_menu
  283. fi
  284. }
  285. enable_bbr() {
  286. if grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf && grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
  287. echo -e "${green}BBR is already enabled!${plain}"
  288. exit 0
  289. fi
  290. # Check the OS and install necessary packages
  291. if [[ "$(cat /etc/os-release | grep -E '^ID=' | awk -F '=' '{print $2}')" == "ubuntu" ]]; then
  292. sudo apt-get update && sudo apt-get install -yqq --no-install-recommends ca-certificates
  293. elif [[ "$(cat /etc/os-release | grep -E '^ID=' | awk -F '=' '{print $2}')" == "debian" ]]; then
  294. sudo apt-get update && sudo apt-get install -yqq --no-install-recommends ca-certificates
  295. elif [[ "$(cat /etc/os-release | grep -E '^ID=' | awk -F '=' '{print $2}')" == "fedora" ]]; then
  296. sudo dnf -y update && sudo dnf -y install ca-certificates
  297. elif [[ "$(cat /etc/os-release | grep -E '^ID=' | awk -F '=' '{print $2}')" == "centos" ]]; then
  298. sudo yum -y update && sudo yum -y install ca-certificates
  299. else
  300. echo "Unsupported operating system. Please check the script and install the necessary packages manually."
  301. exit 1
  302. fi
  303. # Enable BBR
  304. echo "net.core.default_qdisc=fq" | sudo tee -a /etc/sysctl.conf
  305. echo "net.ipv4.tcp_congestion_control=bbr" | sudo tee -a /etc/sysctl.conf
  306. # Apply changes
  307. sudo sysctl -p
  308. # Verify that BBR is enabled
  309. if [[ $(sysctl net.ipv4.tcp_congestion_control | awk '{print $3}') == "bbr" ]]; then
  310. echo -e "${green}BBR has been enabled successfully.${plain}"
  311. else
  312. echo -e "${red}Failed to enable BBR. Please check your system configuration.${plain}"
  313. fi
  314. }
  315. update_shell() {
  316. wget -O /usr/bin/x-ui -N --no-check-certificate https://github.com/mhsanaei/3x-ui/raw/main/x-ui.sh
  317. if [[ $? != 0 ]]; then
  318. echo ""
  319. LOGE "Failed to download script,Please check whether the machine can connect Github"
  320. before_show_menu
  321. else
  322. chmod +x /usr/bin/x-ui
  323. LOGI "Upgrade script succeeded,Please rerun the script" && exit 0
  324. fi
  325. }
  326. # 0: running, 1: not running, 2: not installed
  327. check_status() {
  328. if [[ ! -f /etc/systemd/system/x-ui.service ]]; then
  329. return 2
  330. fi
  331. temp=$(systemctl status x-ui | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
  332. if [[ x"${temp}" == x"running" ]]; then
  333. return 0
  334. else
  335. return 1
  336. fi
  337. }
  338. check_enabled() {
  339. temp=$(systemctl is-enabled x-ui)
  340. if [[ x"${temp}" == x"enabled" ]]; then
  341. return 0
  342. else
  343. return 1
  344. fi
  345. }
  346. check_uninstall() {
  347. check_status
  348. if [[ $? != 2 ]]; then
  349. echo ""
  350. LOGE "Panel installed,Please do not reinstall"
  351. if [[ $# == 0 ]]; then
  352. before_show_menu
  353. fi
  354. return 1
  355. else
  356. return 0
  357. fi
  358. }
  359. check_install() {
  360. check_status
  361. if [[ $? == 2 ]]; then
  362. echo ""
  363. LOGE "Please install the panel first"
  364. if [[ $# == 0 ]]; then
  365. before_show_menu
  366. fi
  367. return 1
  368. else
  369. return 0
  370. fi
  371. }
  372. show_status() {
  373. check_status
  374. case $? in
  375. 0)
  376. echo -e "Panel state: ${green}Running${plain}"
  377. show_enable_status
  378. ;;
  379. 1)
  380. echo -e "Panel state: ${yellow}Not Running${plain}"
  381. show_enable_status
  382. ;;
  383. 2)
  384. echo -e "Panel state: ${red}Not Installed${plain}"
  385. ;;
  386. esac
  387. show_xray_status
  388. }
  389. show_enable_status() {
  390. check_enabled
  391. if [[ $? == 0 ]]; then
  392. echo -e "Start automatically: ${green}Yes${plain}"
  393. else
  394. echo -e "Start automatically: ${red}No${plain}"
  395. fi
  396. }
  397. check_xray_status() {
  398. count=$(ps -ef | grep "xray-linux" | grep -v "grep" | wc -l)
  399. if [[ count -ne 0 ]]; then
  400. return 0
  401. else
  402. return 1
  403. fi
  404. }
  405. show_xray_status() {
  406. check_xray_status
  407. if [[ $? == 0 ]]; then
  408. echo -e "xray state: ${green}Running${plain}"
  409. else
  410. echo -e "xray state: ${red}Not Running${plain}"
  411. fi
  412. }
  413. #this will be an entrance for ssl cert issue
  414. #here we can provide two different methods to issue cert
  415. #first.standalone mode second.DNS API mode
  416. ssl_cert_issue() {
  417. local method=""
  418. echo -E ""
  419. LOGD "********Usage********"
  420. LOGI "this shell script will use acme to help issue certs."
  421. LOGI "here we provide two methods for issuing certs:"
  422. LOGI "method 1:acme standalone mode,need to keep port:80 open"
  423. LOGI "method 2:acme DNS API mode,need provide Cloudflare Global API Key"
  424. LOGI "recommend method 2 first,if it fails,you can try method 1."
  425. LOGI "certs will be installed in /root/cert directory"
  426. read -p "please choose which method do you want,type 1 or 2": method
  427. LOGI "you choosed method:${method}"
  428. if [ "${method}" == "1" ]; then
  429. ssl_cert_issue_standalone
  430. elif [ "${method}" == "2" ]; then
  431. ssl_cert_issue_by_cloudflare
  432. else
  433. LOGE "invalid input,please check it..."
  434. exit 1
  435. fi
  436. }
  437. install_acme() {
  438. cd ~
  439. LOGI "install acme..."
  440. curl https://get.acme.sh | sh
  441. if [ $? -ne 0 ]; then
  442. LOGE "install acme failed"
  443. return 1
  444. else
  445. LOGI "install acme succeed"
  446. fi
  447. return 0
  448. }
  449. #method for standalone mode
  450. ssl_cert_issue_standalone() {
  451. #check for acme.sh first
  452. if ! command -v ~/.acme.sh/acme.sh &>/dev/null; then
  453. echo "acme.sh could not be found. we will install it"
  454. install_acme
  455. if [ $? -ne 0 ]; then
  456. LOGE "install acme failed, please check logs"
  457. exit 1
  458. fi
  459. fi
  460. #install socat second
  461. if [[ x"${release}" == x"centos" ]]; then
  462. yum install socat -y
  463. else
  464. apt install socat -y
  465. fi
  466. if [ $? -ne 0 ]; then
  467. LOGE "install socat failed,please check logs"
  468. exit 1
  469. else
  470. LOGI "install socat succeed..."
  471. fi
  472. #creat a directory for install cert
  473. certPath=/root/cert
  474. if [ ! -d "$certPath" ]; then
  475. mkdir $certPath
  476. else
  477. rm -rf $certPath
  478. mkdir $certPath
  479. fi
  480. #get the domain here,and we need verify it
  481. local domain=""
  482. read -p "please input your domain:" domain
  483. LOGD "your domain is:${domain},check it..."
  484. #here we need to judge whether there exists cert already
  485. local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
  486. if [ ${currentCert} == ${domain} ]; then
  487. local certInfo=$(~/.acme.sh/acme.sh --list)
  488. LOGE "system already have certs here,can not issue again,current certs details:"
  489. LOGI "$certInfo"
  490. exit 1
  491. else
  492. LOGI "your domain is ready for issuing cert now..."
  493. fi
  494. #get needed port here
  495. local WebPort=80
  496. read -p "please choose which port do you use,default will be 80 port:" WebPort
  497. if [[ ${WebPort} -gt 65535 || ${WebPort} -lt 1 ]]; then
  498. LOGE "your input ${WebPort} is invalid,will use default port"
  499. fi
  500. LOGI "will use port:${WebPort} to issue certs,please make sure this port is open..."
  501. #NOTE:This should be handled by user
  502. #open the port and kill the occupied progress
  503. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  504. ~/.acme.sh/acme.sh --issue -d ${domain} --standalone --httpport ${WebPort}
  505. if [ $? -ne 0 ]; then
  506. LOGE "issue certs failed,please check logs"
  507. rm -rf ~/.acme.sh/${domain}
  508. exit 1
  509. else
  510. LOGE "issue certs succeed,installing certs..."
  511. fi
  512. #install cert
  513. ~/.acme.sh/acme.sh --installcert -d ${domain} --ca-file /root/cert/ca.cer \
  514. --cert-file /root/cert/${domain}.cer --key-file /root/cert/${domain}.key \
  515. --fullchain-file /root/cert/fullchain.cer
  516. if [ $? -ne 0 ]; then
  517. LOGE "install certs failed,exit"
  518. rm -rf ~/.acme.sh/${domain}
  519. exit 1
  520. else
  521. LOGI "install certs succeed,enable auto renew..."
  522. fi
  523. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  524. if [ $? -ne 0 ]; then
  525. LOGE "auto renew failed,certs details:"
  526. ls -lah cert
  527. chmod 755 $certPath
  528. exit 1
  529. else
  530. LOGI "auto renew succeed,certs details:"
  531. ls -lah cert
  532. chmod 755 $certPath
  533. fi
  534. }
  535. #method for DNS API mode
  536. ssl_cert_issue_by_cloudflare() {
  537. echo -E ""
  538. LOGD "******Preconditions******"
  539. LOGI "1.need Cloudflare account associated email"
  540. LOGI "2.need Cloudflare Global API Key"
  541. LOGI "3.your domain use Cloudflare as resolver"
  542. confirm "I have confirmed all these info above[y/n]" "y"
  543. if [ $? -eq 0 ]; then
  544. install_acme
  545. if [ $? -ne 0 ]; then
  546. LOGE "install acme failed,please check logs"
  547. exit 1
  548. fi
  549. CF_Domain=""
  550. CF_GlobalKey=""
  551. CF_AccountEmail=""
  552. certPath=/root/cert
  553. if [ ! -d "$certPath" ]; then
  554. mkdir $certPath
  555. else
  556. rm -rf $certPath
  557. mkdir $certPath
  558. fi
  559. LOGD "please input your domain:"
  560. read -p "Input your domain here:" CF_Domain
  561. LOGD "your domain is:${CF_Domain},check it..."
  562. #here we need to judge whether there exists cert already
  563. local currentCert=$(~/.acme.sh/acme.sh --list | tail -1 | awk '{print $1}')
  564. if [ ${currentCert} == ${CF_Domain} ]; then
  565. local certInfo=$(~/.acme.sh/acme.sh --list)
  566. LOGE "system already have certs here,can not issue again,current certs details:"
  567. LOGI "$certInfo"
  568. exit 1
  569. else
  570. LOGI "your domain is ready for issuing cert now..."
  571. fi
  572. LOGD "please inout your cloudflare global API key:"
  573. read -p "Input your key here:" CF_GlobalKey
  574. LOGD "your cloudflare global API key is:${CF_GlobalKey}"
  575. LOGD "please input your cloudflare account email:"
  576. read -p "Input your email here:" CF_AccountEmail
  577. LOGD "your cloudflare account email:${CF_AccountEmail}"
  578. ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  579. if [ $? -ne 0 ]; then
  580. LOGE "change the default CA to Lets'Encrypt failed,exit"
  581. exit 1
  582. fi
  583. export CF_Key="${CF_GlobalKey}"
  584. export CF_Email=${CF_AccountEmail}
  585. ~/.acme.sh/acme.sh --issue --dns dns_cf -d ${CF_Domain} -d *.${CF_Domain} --log
  586. if [ $? -ne 0 ]; then
  587. LOGE "issue cert failed,exit"
  588. rm -rf ~/.acme.sh/${CF_Domain}
  589. exit 1
  590. else
  591. LOGI "Certificate issued Successfully, Installing..."
  592. fi
  593. ~/.acme.sh/acme.sh --installcert -d ${CF_Domain} -d *.${CF_Domain} --ca-file /root/cert/ca.cer \
  594. --cert-file /root/cert/${CF_Domain}.cer --key-file /root/cert/${CF_Domain}.key \
  595. --fullchain-file /root/cert/fullchain.cer
  596. if [ $? -ne 0 ]; then
  597. LOGE "install cert failed,exit"
  598. rm -rf ~/.acme.sh/${CF_Domain}
  599. exit 1
  600. else
  601. LOGI "Certificate installed Successfully,Turning on automatic updates..."
  602. fi
  603. ~/.acme.sh/acme.sh --upgrade --auto-upgrade
  604. if [ $? -ne 0 ]; then
  605. LOGE "Auto update setup Failed, script exiting..."
  606. ls -lah cert
  607. chmod 755 $certPath
  608. exit 1
  609. else
  610. LOGI "The certificate is installed and auto-renewal is turned on, Specific information is as follows"
  611. ls -lah cert
  612. chmod 755 $certPath
  613. fi
  614. else
  615. show_menu
  616. fi
  617. }
  618. show_usage() {
  619. echo "x-ui control menu usages: "
  620. echo "------------------------------------------"
  621. echo -e "x-ui - Enter control menu"
  622. echo -e "x-ui start - Start x-ui "
  623. echo -e "x-ui stop - Stop x-ui "
  624. echo -e "x-ui restart - Restart x-ui "
  625. echo -e "x-ui status - Show x-ui status"
  626. echo -e "x-ui enable - Enable x-ui on system startup"
  627. echo -e "x-ui disable - Disable x-ui on system startup"
  628. echo -e "x-ui log - Check x-ui logs"
  629. echo -e "x-ui update - Update x-ui "
  630. echo -e "x-ui install - Install x-ui "
  631. echo -e "x-ui uninstall - Uninstall x-ui "
  632. echo "------------------------------------------"
  633. }
  634. show_menu() {
  635. echo -e "
  636. ${green}3X-ui Panel Management Script${plain}
  637. ${green}0.${plain} Exit Script
  638. ————————————————
  639. ${green}1.${plain} Install x-ui
  640. ${green}2.${plain} Update x-ui
  641. ${green}3.${plain} Uninstall x-ui
  642. ————————————————
  643. ${green}4.${plain} Reset Username And Password
  644. ${green}5.${plain} Reset Panel Settings
  645. ${green}6.${plain} Change Panel Port
  646. ${green}7.${plain} View Current Panel Settings
  647. ————————————————
  648. ${green}8.${plain} Start x-ui
  649. ${green}9.${plain} Stop x-ui
  650. ${green}10.${plain} Restart x-ui
  651. ${green}11.${plain} Check x-ui Status
  652. ${green}12.${plain} Check x-ui Logs
  653. ————————————————
  654. ${green}13.${plain} Enable x-ui On Sysyem Startup
  655. ${green}14.${plain} Disabel x-ui On Sysyem Startup
  656. ————————————————
  657. ${green}15.${plain} Enable BBR
  658. ${green}16.${plain} Issuse Certs
  659. "
  660. show_status
  661. echo && read -p "Please enter your selection [0-16]: " num
  662. case "${num}" in
  663. 0)
  664. exit 0
  665. ;;
  666. 1)
  667. check_uninstall && install
  668. ;;
  669. 2)
  670. check_install && update
  671. ;;
  672. 3)
  673. check_install && uninstall
  674. ;;
  675. 4)
  676. check_install && reset_user
  677. ;;
  678. 5)
  679. check_install && reset_config
  680. ;;
  681. 6)
  682. check_install && set_port
  683. ;;
  684. 7)
  685. check_install && check_config
  686. ;;
  687. 8)
  688. check_install && start
  689. ;;
  690. 9)
  691. check_install && stop
  692. ;;
  693. 10)
  694. check_install && restart
  695. ;;
  696. 11)
  697. check_install && status
  698. ;;
  699. 12)
  700. check_install && show_log
  701. ;;
  702. 13)
  703. check_install && enable
  704. ;;
  705. 14)
  706. check_install && disable
  707. ;;
  708. 15)
  709. enable_bbr
  710. ;;
  711. 16)
  712. ssl_cert_issue
  713. ;;
  714. *)
  715. LOGE "Please enter the correct number [0-16]"
  716. ;;
  717. esac
  718. }
  719. if [[ $# > 0 ]]; then
  720. case $1 in
  721. "start")
  722. check_install 0 && start 0
  723. ;;
  724. "stop")
  725. check_install 0 && stop 0
  726. ;;
  727. "restart")
  728. check_install 0 && restart 0
  729. ;;
  730. "status")
  731. check_install 0 && status 0
  732. ;;
  733. "enable")
  734. check_install 0 && enable 0
  735. ;;
  736. "disable")
  737. check_install 0 && disable 0
  738. ;;
  739. "log")
  740. check_install 0 && show_log 0
  741. ;;
  742. "update")
  743. check_install 0 && update 0
  744. ;;
  745. "install")
  746. check_uninstall 0 && install 0
  747. ;;
  748. "uninstall")
  749. check_install 0 && uninstall 0
  750. ;;
  751. *) show_usage ;;
  752. esac
  753. else
  754. show_menu
  755. fi