x-ui.sh 38 KB

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