| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- #!/bin/bash
- #19/12/2019
- drop_port(){
- local portasVAR=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
- local NOREPEAT
- local reQ
- local Port
- while read port; do
- reQ=$(echo ${port}|awk '{print $1}')
- Port=$(echo {$port} | awk '{print $9}' | awk -F ":" '{print $2}')
- [[ $(echo -e $NOREPEAT|grep -w "$Port") ]] && continue
- NOREPEAT+="$Port\n"
- case ${reQ} in
- cupsd)continue;;
- systemd-r)continue;;
- stunnel4|stunnel)continue;;
- *)DPB+=" $reQ:$Port";;
- esac
- done <<< "${portasVAR}"
- }
- ssl_stunel(){
- [[ $(mportas|grep stunnel4|head -1) ]] && {
- clear
- msg -bar
- print_center -ama "Parando Stunnel"
- msg -bar
- service stunnel4 stop & >/dev/null 2>&1
- fun_bar 'apt-get purge stunnel4 -y' 'UNINSTALL STUNNEL4 '
- msg -bar
- print_center -verd "Stunnel detenido con Exito!"
- msg -bar
- sleep 2
- return 1
- }
- title "INSTALADOR SSL By @Rufu99"
- print_center -azu "Seleccione puerto de redireccion de trafico"
- msg -bar
- drop_port
- n=1
- for i in $DPB; do
- proto=$(echo $i|awk -F ":" '{print $1}')
- proto2=$(printf '%-12s' "$proto")
- port=$(echo $i|awk -F ":" '{print $2}')
- echo -e " $(msg -verd "[$n]") $(msg -verm2 ">") $(msg -ama "$proto2")$(msg -azu "$port")"
- drop[$n]=$port
- num_opc="$n"
- let n++
- done
- msg -bar
- while [[ -z $opc ]]; do
- msg -ne " opcion: "
- read opc
- tput cuu1 && tput dl1
- if [[ -z $opc ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ ! $opc =~ $numero ]]; then
- msg -verm2 " selecciona solo numeros entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ "$opc" -gt "$num_opc" ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- sleep 2
- tput cuu1 && tput dl1
- unset opc
- continue
- fi
- done
- title "INSTALADOR SSL By @Rufu99"
- echo -e "\033[1;33m Puerto de redireccion de trafico: \033[1;32m${drop[$opc]}"
- msg -bar
- while [[ -z $opc2 ]]; do
- echo -ne "\033[1;37m Ingrese un puerto para SSL: " && read opc2
- tput cuu1 && tput dl1
- [[ $(mportas|grep -w "${opc2}") = "" ]] && {
- echo -e "\033[1;33m $(fun_trans "Puerto de ssl:")\033[1;32m ${opc2} OK"
- } || {
- echo -e "\033[1;33m $(fun_trans "Puerto de ssl:")\033[1;31m ${opc2} FAIL" && sleep 2
- tput cuu1 && tput dl1
- unset opc2
- }
- done
- # openssl x509 -in 2.crt -text -noout |grep -w 'Issuer'|awk -F 'O = ' '{print $2}'|cut -d ',' -f1
- msg -bar
- fun_bar 'apt-get install stunnel4 -y' 'INSTALL STUNNEL4 '
- echo -e "client = no\n[SSL]\ncert = /etc/stunnel/stunnel.pem\naccept = ${opc2}\nconnect = 127.0.0.1:${drop[$opc]}" > /etc/stunnel/stunnel.conf
- db="$(ls ${ADM_crt})"
- opcion="n"
- if [[ ! "$(echo "$db"|grep ".crt")" = "" ]]; then
- cert=$(echo "$db"|grep ".crt")
- key=$(echo "$db"|grep ".key")
- msg -bar
- print_center -azu "CERTIFICADO SSL ENCONTRADO"
- msg -bar
- echo -e "$(msg -azu "CERT:") $(msg -ama "$cert")"
- echo -e "$(msg -azu "KEY:") $(msg -ama "$key")"
- msg -bar
- msg -ne "Continuar, usando estre certificado [S/N]: "
- read opcion
- if [[ $opcion != @(n|N) ]]; then
- cp ${ADM_crt}/$cert ${ADM_tmp}/stunnel.crt
- cp ${ADM_crt}/$key ${ADM_tmp}/stunnel.key
- fi
- fi
- if [[ $opcion != @(s|S) ]]; then
- openssl genrsa -out ${ADM_tmp}/stunnel.key 2048 > /dev/null 2>&1
- (echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "" ; echo "@cloudflare" )|openssl req -new -key ${ADM_tmp}/stunnel.key -x509 -days 1000 -out ${ADM_tmp}/stunnel.crt > /dev/null 2>&1
- fi
- cat ${ADM_tmp}/stunnel.key ${ADM_tmp}/stunnel.crt > /etc/stunnel/stunnel.pem
- sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/stunnel4
- service stunnel4 restart > /dev/null 2>&1
- msg -bar
- print_center -verd "INSTALADO CON EXITO"
- msg -bar
- rm -rf ${ADM_tmp}/stunnel.crt > /dev/null 2>&1
- rm -rf ${ADM_tmp}/stunnel.key > /dev/null 2>&1
- sleep 3
- return 1
- }
- add_port(){
- title "INSTALADOR SSL By @Rufu99"
- print_center -azu "Seleccione puerto de redireccion de trafico"
- msg -bar
- drop_port
- n=1
- for i in $DPB; do
- proto=$(echo $i|awk -F ":" '{print $1}')
- proto2=$(printf '%-12s' "$proto")
- port=$(echo $i|awk -F ":" '{print $2}')
- echo -e " $(msg -verd "[$n]") $(msg -verm2 ">") $(msg -ama "$proto2")$(msg -azu "$port")"
- drop[$n]=$port
- num_opc="$n"
- let n++
- done
- msg -bar
- while [[ -z $opc ]]; do
- msg -ne " opcion: "
- read opc
- tput cuu1 && tput dl1
- if [[ -z $opc ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ ! $opc =~ $numero ]]; then
- msg -verm2 " selecciona solo numeros entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ "$opc" -gt "$num_opc" ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- sleep 2
- tput cuu1 && tput dl1
- unset opc
- continue
- fi
- done
- title "INSTALADOR SSL By @Rufu99"
- echo -e "\033[1;33m Puerto de redireccion de trafico: \033[1;32m${drop[$opc]}"
- msg -bar
- while [[ -z $opc2 ]]; do
- echo -ne "\033[1;37m Ingrese un puerto para SSL: " && read opc2
- tput cuu1 && tput dl1
- [[ $(mportas|grep -w "${opc2}") = "" ]] && {
- echo -e "\033[1;33m $(fun_trans "Puerto de ssl:")\033[1;32m ${opc2} OK"
- } || {
- echo -e "\033[1;33m $(fun_trans "Puerto de ssl:")\033[1;31m ${opc2} FAIL" && sleep 2
- tput cuu1 && tput dl1
- unset opc2
- }
- done
- echo -e "client = no\n[SSL+]\ncert = /etc/stunnel/stunnel.pem\naccept = ${opc2}\nconnect = 127.0.0.1:${drop[$opc]}" >> /etc/stunnel/stunnel.conf
- service stunnel4 restart > /dev/null 2>&1
- msg -bar
- print_center -verd "PUERTO AGREGADO CON EXITO"
- enter
- return 1
- }
- start-stop(){
- clear
- msg -bar
- if [[ $(service stunnel4 status|grep -w 'Active'|awk -F ' ' '{print $2}') = 'inactive' ]]; then
- if service stunnel4 start &> /dev/null ; then
- print_center -verd "Servicio stunnel4 iniciado"
- else
- print_center -verm2 "Falla al iniciar Servicio stunnel4"
- fi
- else
- if service stunnel4 stop &> /dev/null ; then
- print_center -verd "Servicio stunnel4 detenido"
- else
- print_center -verm2 "Falla al detener Servicio stunnel4"
- fi
- fi
- enter
- return 1
- }
- del_port(){
- sslport=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN"|grep -E 'stunnel|stunnel4')
- if [[ $(echo "$sslport"|wc -l) -lt '2' ]];then
- clear
- msg -bar
- print_center -ama "Un solo puerto para eliminar\ndesea detener el servicio? "
- msg -bar
- msg -ne " opcion [S/N]: " && read a
- if [[ "$a" = @(S|s) ]]; then
- clear
- msg -bar
- if service stunnel4 stop &> /dev/null ; then
- print_center -verd "Servicio stunnel4 detenido"
- else
- print_center -verm2 "Falla al detener Servicio stunnel4"
- fi
- fi
- enter
- return 1
- fi
- title "seleccione el num de puerto a quitar"
- n=1
- while read i; do
- port=$(echo $i|awk -F ' ' '{print $9}'|cut -d ':' -f2)
- echo -e " $(msg -verd "[$n]") $(msg -verm2 ">") $(msg -azu "$port")"
- drop[$n]=$port
- num_opc="$n"
- let n++
- done <<< $(echo "$sslport")
- back
- while [[ -z $opc ]]; do
- msg -ne " opcion: "
- read opc
- tput cuu1 && tput dl1
- if [[ -z $opc ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ ! $opc =~ $numero ]]; then
- msg -verm2 " selecciona solo numeros entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ "$opc" -gt "$num_opc" ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- sleep 2
- tput cuu1 && tput dl1
- unset opc
- continue
- fi
- done
- in=$(( $(cat "/etc/stunnel/stunnel.conf"|grep -n "accept = ${drop[$opc]}"|cut -d ':' -f1) - 3 ))
- en=$(( $in + 4))
- sed -i "$in,$en d" /etc/stunnel/stunnel.conf
- sed -i '2 s/\[SSL+\]/\[SSL\]/' /etc/stunnel/stunnel.conf
- title "Puerto ssl ${drop[$opc]} eliminado"
- if service stunnel4 restart &> /dev/null ; then
- print_center -verd "Servicio stunnel4 reiniciado"
- else
- print_center -verm2 "Falla al reiniciar Servicio stunnel4"
- fi
- enter
- return 1
- }
- edit_port(){
- sslport=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN"|grep -E 'stunnel|stunnel4')
- title "seleccione el num de puerto a editar"
- n=1
- while read i; do
- port=$(echo $i|awk -F ' ' '{print $9}'|cut -d ':' -f2)
- echo -e " $(msg -verd "[$n]") $(msg -verm2 ">") $(msg -azu "$port")"
- drop[$n]=$port
- num_opc="$n"
- let n++
- done <<< $(echo "$sslport")
- back
- while [[ -z $opc ]]; do
- msg -ne " opcion: "
- read opc
- tput cuu1 && tput dl1
- if [[ -z $opc ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ ! $opc =~ $numero ]]; then
- msg -verm2 " selecciona solo numeros entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ "$opc" -gt "$num_opc" ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- sleep 2
- tput cuu1 && tput dl1
- unset opc
- continue
- fi
- done
- title "Configuracion actual"
- in=$(( $(cat "/etc/stunnel/stunnel.conf"|grep -n "accept = ${drop[$opc]}"|cut -d ':' -f1) + 1 ))
- en=$(sed -n "${in}p" /etc/stunnel/stunnel.conf|cut -d ':' -f2)
- print_center -ama "${drop[$opc]} >>> $en"
- msg -bar
- drop_port
- n=1
- for i in $DPB; do
- port=$(echo $i|awk -F ":" '{print $2}')
- [[ "$port" = "$en" ]] && continue
- proto=$(echo $i|awk -F ":" '{print $1}')
- proto2=$(printf '%-12s' "$proto")
- echo -e " $(msg -verd "[$n]") $(msg -verm2 ">") $(msg -ama "$proto2")$(msg -azu "$port")"
- drop[$n]=$port
- num_opc="$n"
- let n++
- done
- msg -bar
- unset opc
- while [[ -z $opc ]]; do
- msg -ne " opcion: "
- read opc
- tput cuu1 && tput dl1
- if [[ -z $opc ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ ! $opc =~ $numero ]]; then
- msg -verm2 " selecciona solo numeros entre 1 y $num_opc"
- unset opc
- sleep 2
- tput cuu1 && tput dl1
- continue
- elif [[ "$opc" -gt "$num_opc" ]]; then
- msg -verm2 " selecciona una opcion entre 1 y $num_opc"
- sleep 2
- tput cuu1 && tput dl1
- unset opc
- continue
- fi
- done
- sed -i "$in s/$en/${drop[$opc]}/" /etc/stunnel/stunnel.conf
- title "Puerto de redirecion modificado"
- if service stunnel4 restart &> /dev/null ; then
- print_center -verd "Servicio stunnel4 reiniciado"
- else
- print_center -verm2 "Falla al reiniciar Servicio stunnel4"
- fi
- enter
- return 1
- }
- restart(){
- clear && msg -bar
- if service stunnel4 restart &> /dev/null ; then
- print_center -verd "Servicio stunnel4 reiniciado"
- else
- print_center -verm2 "Falla al reiniciar Servicio stunnel4"
- fi
- enter
- return 1
- }
- edit_nano(){
- nano /etc/stunnel/stunnel.conf
- restart
- return 1
- }
- title "INSTALADOR SSL By @Rufu99"
- echo -e "$(msg -verd " [1]") $(msg -verm2 ">") $(msg -verd "INSTALAR") $(msg -ama "-") $(msg -verm2 "DESINSTALAR")"
- n=1
- if [[ $(dpkg -l|grep 'stunnel'|awk -F ' ' '{print $2}') ]]; then
- msg -bar3
- echo -e "$(msg -verd " [2]") $(msg -verm2 ">") $(msg -verd "AGREGAR PUERTOS SSL")"
- echo -e "$(msg -verd " [3]") $(msg -verm2 ">") $(msg -verm2 "QUITAR PUERTOS SSL")"
- msg -bar3
- echo -e "$(msg -verd " [4]") $(msg -verm2 ">") $(msg -ama "EDITAR PUERTO DE REDIRECCION")"
- echo -e "$(msg -verd " [5]") $(msg -verm2 ">") $(msg -azu "EDITAR MANUAL (NANO)")"
- msg -bar3
- echo -e "$(msg -verd " [6]") $(msg -verm2 ">") $(msg -azu "INICIAR/PARAR SERVICIO SSL")"
- echo -e "$(msg -verd " [7]") $(msg -verm2 ">") $(msg -azu "REINICIAR SERVICIO SSL")"
- n=7
- fi
- back
- opcion=$(selection_fun $n)
- case $opcion in
- 1)ssl_stunel;;
- 2)add_port;;
- 3)del_port;;
- 4)edit_port;;
- 5)edit_nano;;
- 6)start-stop;;
- 7)restart;;
- 0) return 1;;
- esac
|