ssl.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #!/bin/bash
  2. #25/01/2021 by @Kalix1
  3. clear
  4. clear
  5. SCPdir="/etc/VPS-MX"
  6. SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && exit
  7. SCPinst="${SCPdir}/protocolos"&& [[ ! -d ${SCPinst} ]] && exit
  8. declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
  9. dirapache="/usr/local/lib/ubuntn/apache/ver" && [[ ! -d ${dirapache} ]] && exit
  10. mportas () {
  11. unset portas
  12. portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  13. while read port; do
  14. var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
  15. [[ "$(echo -e $portas|grep "$var1 $var2")" ]] || portas+="$var1 $var2\n"
  16. done <<< "$portas_var"
  17. i=1
  18. echo -e "$portas"
  19. }
  20. fun_bar () {
  21. comando="$1"
  22. _=$(
  23. $comando > /dev/null 2>&1
  24. ) & > /dev/null
  25. pid=$!
  26. while [[ -d /proc/$pid ]]; do
  27. echo -ne " \033[1;33m["
  28. for((i=0; i<20; i++)); do
  29. echo -ne "\033[1;31m##"
  30. sleep 0.5
  31. done
  32. echo -ne "\033[1;33m]"
  33. sleep 1s
  34. echo
  35. tput cuu1
  36. tput dl1
  37. done
  38. echo -e " \033[1;33m[\033[1;31m########################################\033[1;33m] - \033[1;32m OK \033[0m"
  39. sleep 1s
  40. }
  41. ssl_stunel () {
  42. [[ $(mportas|grep stunnel4|head -1) ]] && {
  43. echo -e "\033[1;33m $(fun_trans "Deteniendo Stunnel")"
  44. msg -bar
  45. service stunnel4 stop > /dev/null 2>&1
  46. fun_bar "apt-get purge stunnel4 -y"
  47. msg -bar
  48. echo -e "\033[1;33m $(fun_trans "Detenido Con Exito!")"
  49. msg -bar
  50. return 0
  51. }
  52. echo -e "\033[1;32m $(fun_trans " INSTALADOR SSL By VPS-MX")"
  53. msg -bar
  54. echo -e "\033[1;33m $(fun_trans "Seleccione una puerta de redirección interna.")"
  55. echo -e "\033[1;33m $(fun_trans "Un puerto SSH/DROPBEAR/SQUID/OPENVPN/SSL")"
  56. msg -bar
  57. while true; do
  58. echo -e "\033[1;37m"
  59. read -p " Local-Port: " portx
  60. echo ""
  61. if [[ ! -z $portx ]]; then
  62. if [[ $(echo $portx|grep [0-9]) ]]; then
  63. [[ $(mportas|grep $portx|head -1) ]] && break || echo -e "\033[1;31m Puerto Invalido"
  64. fi
  65. fi
  66. done
  67. msg -bar
  68. DPORT="$(mportas|grep $portx|awk '{print $2}'|head -1)"
  69. echo -e "\033[1;33m Ahora Que Puerto sera SSL"
  70. msg -bar
  71. while true; do
  72. echo -e "\033[1;37m"
  73. read -p " Listen-SSL: " SSLPORT
  74. echo ""
  75. [[ $(mportas|grep -w "$SSLPORT") ]] || break
  76. echo -e "\033[1;33m Este Puerto esta en Uso"
  77. unset SSLPORT
  78. done
  79. msg -bar
  80. echo -e "\033[1;33m $(fun_trans "Instalando SSL")"
  81. msg -bar
  82. fun_bar "apt-get install stunnel4 -y"
  83. apt-get install stunnel4 -y > /dev/null 2>&1
  84. echo -e "client = no\n[SSL]\ncert = /etc/stunnel/stunnel.pem\naccept = ${SSLPORT}\nconnect = 127.0.0.1:${portx}" > /etc/stunnel/stunnel.conf
  85. ####Coreccion2.0#####
  86. openssl genrsa -out stunnel.key 2048 > /dev/null 2>&1
  87. # (echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "@vpsmx" )|openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt > /dev/null 2>&1
  88. openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt
  89. cat stunnel.crt stunnel.key > stunnel.pem
  90. mv stunnel.pem /etc/stunnel/
  91. ######-------
  92. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  93. service stunnel4 restart > /dev/null 2>&1
  94. msg -bar
  95. echo -e "\033[1;33m $(fun_trans "INSTALADO CON EXITO")"
  96. msg -bar
  97. rm -rf /etc/ger-frm/stunnel.crt > /dev/null 2>&1
  98. rm -rf /etc/ger-frm/stunnel.key > /dev/null 2>&1
  99. rm -rf /root/stunnel.crt > /dev/null 2>&1
  100. rm -rf /root/stunnel.key > /dev/null 2>&1
  101. return 0
  102. }
  103. SPR &
  104. ssl_stunel_2 () {
  105. echo -e "\033[1;32m $(fun_trans " AGREGAR MAS PUESRTOS SSL")"
  106. msg -bar
  107. echo -e "\033[1;33m $(fun_trans "Seleccione una puerta de redirección interna.")"
  108. echo -e "\033[1;33m $(fun_trans "Un puerto SSH/DROPBEAR/SQUID/OPENVPN/SSL")"
  109. msg -bar
  110. while true; do
  111. echo -ne "\033[1;37m"
  112. read -p " Local-Port: " portx
  113. echo ""
  114. if [[ ! -z $portx ]]; then
  115. if [[ $(echo $portx|grep [0-9]) ]]; then
  116. [[ $(mportas|grep $portx|head -1) ]] && break || echo -e "\033[1;31m $(fun_trans "Puerto Invalido")"
  117. fi
  118. fi
  119. done
  120. msg -bar
  121. DPORT="$(mportas|grep $portx|awk '{print $2}'|head -1)"
  122. echo -e "\033[1;33m $(fun_trans "Ahora Que Puerto sera SSL")"
  123. msg -bar
  124. while true; do
  125. echo -ne "\033[1;37m"
  126. read -p " Listen-SSL: " SSLPORT
  127. echo ""
  128. [[ $(mportas|grep -w "$SSLPORT") ]] || break
  129. echo -e "\033[1;33m $(fun_trans "Esta puerta está en uso")"
  130. unset SSLPORT
  131. done
  132. msg -bar
  133. echo -e "\033[1;33m $(fun_trans "Instalando SSL")"
  134. msg -bar
  135. fun_bar "apt-get install stunnel4 -y"
  136. echo -e "client = no\n[SSL+]\ncert = /etc/stunnel/stunnel.pem\naccept = ${SSLPORT}\nconnect = 127.0.0.1:${DPORT}" >> /etc/stunnel/stunnel.conf
  137. ######-------
  138. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  139. service stunnel4 restart > /dev/null 2>&1
  140. msg -bar
  141. echo -e "${cor[4]} INSTALADO CON EXITO"
  142. msg -bar
  143. rm -rf /etc/ger-frm/stunnel.crt > /dev/null 2>&1
  144. rm -rf /etc/ger-frm/stunnel.key > /dev/null 2>&1
  145. rm -rf /root/stunnel.crt > /dev/null 2>&1
  146. rm -rf /root/stunnel.key > /dev/null 2>&1
  147. return 0
  148. }
  149. ssl_stunel_3 () {
  150. clear
  151. clear
  152. msg -bar
  153. msg -tit
  154. echo -e "\033[1;93m SSL + PYDIREC \033[1;94m By @AleSosaCreaciones "
  155. msg -bar
  156. echo -e "\033[1;91m Deveras tener el Puerto 22 SSH y libre (80 y 443)"
  157. msg -bar
  158. install_python(){
  159. echo -e "\033[1;97m Activando Python Direc 80\n"
  160. fun_bar "apt-get install python -y"
  161. sleep 3
  162. screen -dmS pydic-80 python ${SCPinst}/python.py 80 "VPS-MX" && echo "80 VPS-MX" >> /etc/VPS-MX/PySSL.log
  163. msg -bar
  164. }
  165. install_ssl(){
  166. echo -e "\033[1;97m Activando Servicios SSL 80 ► 443\n"
  167. fun_bar "apt-get install stunnel4 -y"
  168. apt-get install stunnel4 -y > /dev/null 2>&1
  169. echo -e "client = no\n[SSL]\ncert = /etc/stunnel/stunnel.pem\naccept = 443\nconnect = 127.0.0.1:80" > /etc/stunnel/stunnel.conf
  170. openssl genrsa -out stunnel.key 2048 > /dev/null 2>&1
  171. #(echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "mx" ; echo "@vpsmx" )|openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt > /dev/null 2>&1
  172. openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt
  173. cat stunnel.crt stunnel.key > stunnel.pem
  174. mv stunnel.pem /etc/stunnel/
  175. ######-------
  176. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
  177. service stunnel4 restart > /dev/null 2>&1
  178. rm -rf /root/stunnel.crt > /dev/null 2>&1
  179. rm -rf /root/stunnel.key > /dev/null 2>&1
  180. }
  181. install_python
  182. install_ssl
  183. msg -bar
  184. echo -e "${cor[4]} INSTALACION COMPLETA"
  185. msg -bar
  186. }
  187. clear
  188. clear
  189. msg -bar
  190. msg -bar3
  191. msg -tit
  192. echo -e "${cor[3]} INSTALADOR MONO Y MULTI SSL By @Kalix1"
  193. msg -bar
  194. echo -e "${cor[1]} Escoja la opcion deseada."
  195. msg -bar
  196. echo -e "${cor[4]} 1).-\033[1;37m INICIAR | PARAR SSL "
  197. echo -e "${cor[4]} 2).-\033[1;37m AGREGAR PUERTOS SSL "
  198. msg -bar
  199. echo -e "${cor[4]} 3).-\033[1;37m SSL+PYDIREC (AUTO CONFIGURACION) "
  200. echo -ne ""$(msg -bar)" \n$(msg -verd " 0).-") $(msg -verm2 "==>")" && msg -bra " \e[97m\033[1;41m VOLVER \033[1;37m"
  201. msg -bar
  202. echo -ne "\033[1;37mDigite solo el numero segun su respuesta: "
  203. read opcao
  204. case $opcao in
  205. 1)
  206. msg -bar
  207. ssl_stunel
  208. ;;
  209. 2)
  210. msg -bar
  211. ssl_stunel_2
  212. ;;
  213. 3)
  214. msg -bar
  215. ssl_stunel_3
  216. msg -ne "Enter Para Continuar" && read enter
  217. /etc/VPS-MX/protocolos/ssl.sh
  218. ;;
  219. 4)
  220. exit
  221. ;;
  222. esac