x-ui.sh 38 KB

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