x-ui.sh 39 KB

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