stunnel.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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} Anda tiada kebenaran untuk menjalankan skrip ini! ${RESET}"
  13. exit 1
  14. fi
  15. function installPkg {
  16. read -p "Teruskan dengan pemasangan semula? [Y/n] " _yesno
  17. if [[ "$_yesno" =~ ^[Yy]$ ]]; then
  18. if [[ ! -f /etc/stunnel/stunnel.conf ]]; then
  19. wget -q -O - https://raw.githubusercontent.com/cybertize/debian/buster/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
  25. sleep 3
  26. wget -q -O - https://raw.githubusercontent.com/cybertize/debian/buster/packages/stunnel.sh | bash
  27. else
  28. echo -e "${ERROR} RALAT ${RESET}${TEXT} Membatalkan pemasangan semula ${RESET}"
  29. exit 1
  30. fi
  31. }
  32. function uninstallPkg {
  33. read -p "Adakah anda pasti mahu menyahpasang stunnel4? [Y/n] " _yesno
  34. if [[ "$_yesno" =~ ^[Yy]$ ]]; then
  35. {
  36. apt-get -y -qq --purge remove stunnel*
  37. apt-get -y -qq autoremove
  38. apt-get -y -qq autoclean
  39. } &>/dev/null
  40. echo -e "${SUCCESS} INFO ${RESET}${TEXT} Bersihkan & Keluarkan pakej stunnel ${RESET}"
  41. exit 0
  42. else
  43. echo -e "${ERROR} INFO ${RESET}${TEXT} Batalkan penyahpasangan pakej ${RESET}"
  44. exit 1
  45. fi
  46. }
  47. function configurePkg {
  48. local stunnel_ports=($(cat /etc/stunnel/stunnel.conf | grep -E 'accept = ' | cut -d ' ' -f 3))
  49. echo
  50. echo -e "Secara lalai perkhidmatan stunnel menggunakan 3 port $stunnel_ports"
  51. echo
  52. while true; do
  53. read -r -p "Adakah anda mahu ganti port baharu? [Y/n] " __yesno
  54. if [[ "$__yesno" =~ ^[Yy]$ ]]; then
  55. read -p "Masukkan port baru: " old_dropbear_port old_openvpn_port old_sslibev_port
  56. if [[ -n "$old_dropbear_port" && "$old_dropbear_port" =~ ^[0-9]+$ ]]; then
  57. sed -i 's|${stunnel_ports[0]}|$old_dropbear_port|g' /etc/stunnel/stunnel.conf
  58. fi
  59. if [[ -n "$old_openvpn_port" && "$old_openvpn_port" =~ ^[0-9]+$ ]]; then
  60. sed -i 's|${stunnel_ports[1]}|$old_openvpn_port|g' /etc/stunnel/stunnel.conf
  61. fi
  62. if [[ -n "$old_sslibev_port" && "$old_sslibev_port" =~ ^[0-9]+$ ]]; then
  63. sed -i 's|${stunnel_ports[2]}|$old_sslibev_port|g' /etc/stunnel/stunnel.conf
  64. fi
  65. echo -e "${INFO} INFO ${RESET}${TEXT} Perubahan telah dibuat ${RESET}"
  66. break
  67. else
  68. echo -e "${INFO} INFO ${RESET}${TEXT} Tiada perubahan dibuat ${RESET}"
  69. break
  70. fi
  71. done
  72. }
  73. function detailPkg {
  74. local unit_name=$(systemctl show stunnel4.service -p Names | cut -d '=' -f 2)
  75. local unit_desc=$(systemctl show stunnel4.service -p Description | cut -d '=' -f 2)
  76. local is_active=$(systemctl is-active stunnel4.service)
  77. local is_enable=$(systemctl is-enabled stunnel4.service)
  78. echo
  79. echo -e "${TEXT} ========================================================== ${RESET}"
  80. echo -e "${TEXT} Butiran perkhidmatan Stunnel4 ${RESET}"
  81. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  82. echo
  83. echo -e "${YELLOW} Name:${RESET} ${GREEN}$unit_name${RESET}"
  84. echo -e "${YELLOW} Desc:${RESET} ${GREEN}$unit_desc${RESET}"
  85. echo -e "${YELLOW} Status:${RESET} ${GREEN}$is_active & $is_enable${RESET}"
  86. echo -e "${YELLOW} Ports:${RESET} ${GREEN}$stunnel_ports${RESET}"
  87. echo
  88. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  89. echo -e "${TEXT} Dicipta oleh Doctype, Dikuasakan oleh Cybertize. ${RESET}"
  90. echo -e "${TEXT} ========================================================== ${RESET}"
  91. echo
  92. }
  93. function stunnelMenu {
  94. echo
  95. echo -e "${TEXT} ========================================================== ${RESET}"
  96. echo -e "${TEXT} MENU STUNNEL ${RESET}"
  97. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  98. echo
  99. echo -e "[01] ${GREEN}reinstall${RESET} - ${YELLOW}Reinstall stunnel package${RESET}"
  100. echo -e "[02] ${GREEN}uninstall${RESET} - ${YELLOW}Uninstall stunnel package${RESET}"
  101. echo -e "[03] ${GREEN}configure${RESET} - ${YELLOW}Configure stunnel package${RESET}"
  102. echo -e "[04] ${GREEN}detail ${RESET} - ${YELLOW}Show stunnel detail & status${RESET}"
  103. echo -e "[00] ${GREEN}quit ${RESET} - ${YELLOW}Exit from menu${RESET}"
  104. echo
  105. echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
  106. echo -e "${TEXT} Dicipta oleh Doctype, Dikuasakan oleh Cybertize. ${RESET}"
  107. echo -e "${TEXT} ========================================================== ${RESET}"
  108. echo
  109. while true; do
  110. read -p "Masukkan pilihan anda: " _choice
  111. case "$_choice" in
  112. 01 | reinstall)
  113. installPkg && break
  114. ;;
  115. 02 | uninstall)
  116. uninstallPkg && break
  117. ;;
  118. 03 | configure)
  119. configurePkg && break
  120. ;;
  121. 04 | detail)
  122. detailPkg && break
  123. ;;
  124. 00 | quit)
  125. exit 0
  126. ;;
  127. *)
  128. echo -e "${ERROR} RALAT ${RESET}${TEXT} Pilihan tidak sah ${RESET}"
  129. stunnelMenu
  130. ;;
  131. esac
  132. done
  133. }
  134. if [[ -f /etc/stunnel/stunnel.conf ]]; then
  135. stunnelMenu
  136. elif [[ ! -f /etc/stunnel/stunnel.conf ]]; then
  137. installPkg
  138. fi