stunnel.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. clear
  3. TEXT='\033[30;107;2m'
  4. INFO='\033[97;44m'
  5. WARNING='\033[97;43m'
  6. ERROR='\033[97;41m'
  7. SUCCESS='\033[97;42m'
  8. GREEN='\033[92m'
  9. YELLOW='\033[93m'
  10. RESET='\033[0m'
  11. if [ "${EUID}" -ne 0 ]; then
  12. echo -e "${ERROR} RALAT ${RESET}${TEXT} You need to run this script as root! ${RESET}"; exit 1
  13. fi
  14. function installPkg {
  15. clear
  16. read -p "Continue with the reinstallation? " _yesno
  17. if [[ "$_yesno" =~ ^[Yy]$ ]]; then
  18. if [[ ! -f /etc/stunnel/stunnel.conf ]]; then
  19. wget -q -O - https://raw.githubusercontent.com/cybertize/doctype/default/packages/stunnel.sh | bash
  20. fi
  21. apt-get -y -qq --purge remove stunnel &>/dev/null
  22. apt-get -y -qq autoremove &>/dev/null
  23. apt-get -qq autoclean &>/dev/null
  24. clear; sleep 3
  25. wget -q -O - https://raw.githubusercontent.com/cybertize/doctype/default/packages/stunnel.sh | bash
  26. else
  27. echo -e "${ERROR} ERROR ${RESET}${TEXT} Aborted... ${RESET}"; exit 1
  28. fi
  29. }
  30. function uninstallPkg {
  31. clear
  32. read -p "Are you sure you want to uninstall stunnel4? [Y/n] " _yesno
  33. if [[ "$_yesno" =~ ^[Yy]$ ]]; then
  34. apt-get -y -qq --purge remove stunnel &>/dev/null
  35. apt-get -y -qq autoremove &>/dev/null
  36. apt-get -y -qq autoclean &>/dev/null
  37. echo -e "${SUCCESS} SUCCESS ${RESET}${TEXT} Purge & Removing stunnel package ${RESET}"; exit 0
  38. else
  39. echo -e "${ERROR} ERROR ${RESET}${TEXT} Aborted... ${RESET}"; exit 1
  40. fi
  41. }
  42. function detailPkg {
  43. clear
  44. local unit_id=$(systemctl show stunnel4.service -p Id | cut -d '=' -f 2)
  45. local unit_name=$(systemctl show stunnel4.service -p Names | cut -d '=' -f 2)
  46. local unit_desc=$(systemctl show stunnel4.service -p Description | cut -d '=' -f 2)
  47. local is_active=$(systemctl is-active stunnel4.service)
  48. local is_enable=$(systemctl is-enabled stunnel4.service)
  49. echo
  50. echo -e "${TEXT} ========================================================== ${RESET}"
  51. echo -e "${TEXT} Stunnel4 service detail ${RESET}"
  52. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  53. echo
  54. echo -e "${YELLOW} ID:${RESET} ${GREEN}$unit_id${RESET}"
  55. echo -e "${YELLOW} Name:${RESET} ${GREEN}$unit_name${RESET}"
  56. echo -e "${YELLOW} Desc:${RESET} ${GREEN}$unit_desc${RESET}"
  57. echo -e "${YELLOW} Status:${RESET} ${GREEN}$is_active & $is_enable${RESET}"
  58. # echo -e "${YELLOW}Listening:${RESET} ${GREEN}$squid_ports{RESET}";
  59. echo
  60. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  61. echo -e "${TEXT} Created by Doctype, Powered by Cybertize. ${RESET}"
  62. echo -e "${TEXT} Copyright 2021, Allright Reserved. ${RESET}"
  63. echo -e "${TEXT} ========================================================== ${RESET}"
  64. echo
  65. }
  66. function stunnelMenu {
  67. echo
  68. echo -e "${TEXT} ========================================================== ${RESET}"
  69. echo -e "${TEXT} STUNNEL MENU ${RESET}"
  70. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  71. echo
  72. echo -e "[01] ${GREEN}reinstall${RESET} - ${YELLOW}Reinstall stunnel package${RESET}"
  73. echo -e "[02] ${GREEN}uninstall${RESET} - ${YELLOW}Uninstall stunnel package${RESET}"
  74. echo -e "[03] ${GREEN}detail ${RESET} - ${YELLOW}Show stunnel detail & status${RESET}"
  75. echo -e "[00] ${GREEN}quit ${RESET} - ${YELLOW}Exit from menu${RESET}"
  76. echo
  77. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  78. echo -e "${TEXT} Created by Doctype, Powered by Cybertize. ${RESET}"
  79. echo -e "${TEXT} Copyright 2021, Allright Reserved. ${RESET}"
  80. echo -e "${TEXT} ========================================================== ${RESET}"
  81. echo
  82. while true; do
  83. read -p "Enter your choice: " _choice
  84. case "$_choice" in
  85. 01|reinstall)
  86. installPkg && break
  87. ;;
  88. 02|uninstall)
  89. uninstallPkg && break
  90. ;;
  91. 03|detail)
  92. detailPkg && break
  93. ;;
  94. 00|quit)
  95. exit 0
  96. ;;
  97. *)
  98. echo -e "${ERROR} ERROR ${RESET}${TEXT} Invalid option! ${RESET}"; stunnelMenu
  99. ;;
  100. esac
  101. done
  102. }
  103. if [[ -f /etc/stunnel/stunnel.conf ]]; then
  104. stunnelMenu
  105. elif [[ ! -f /etc/stunnel/stunnel.conf ]]; then
  106. installPkg
  107. fi