ws-cdn.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. clear
  3. check_drop(){
  4. ins=$(dpkg --get-selections|grep -w "dropbear"|grep -v "dropbear-"|awk '{printf $2}')
  5. [[ -z "$ins" ]] && ins="deinstall"
  6. if [[ "$ins" = "deinstall" ]]; then
  7. encab
  8. print_center -ama "Dropbear no se encuentra instalado"
  9. msg -bar
  10. echo -ne "\033[1;37m desea instalarlo [s/n]: "
  11. read opcion
  12. [[ $opcion = @(s|S|y|Y) ]] && clear && msg -bar && ${ADM_inst}/dropbear.sh
  13. fi
  14. }
  15. drop_port () {
  16. local portasVAR=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
  17. local NOREPEAT
  18. local reQ
  19. local Port
  20. while read port; do
  21. reQ=$(echo ${port}|awk '{print $1}')
  22. Port=$(echo {$port} | awk '{print $9}' | awk -F ":" '{print $2}')
  23. [[ $(echo -e $NOREPEAT|grep -w "$Port") ]] && continue
  24. NOREPEAT+="$Port\n"
  25. case ${reQ} in
  26. dropbear)
  27. if [[ ! $Port = 22 ]]; then
  28. DPB+=" $Port"
  29. fi;;
  30. esac
  31. done <<< "${portasVAR}"
  32. }
  33. conf(){
  34. check_drop
  35. [[ $opcion = @(n|N) ]] && return 1
  36. drop_port
  37. encab
  38. print_center -azu "Selecciones puerto de redireccion de trafico"
  39. msg -bar
  40. n=1
  41. for i in $DPB; do
  42. echo -e " \033[1;32m[$n] \033[1;31m> \033[1;37m$i\033[0m"
  43. drop[$n]=$i
  44. num_opc=$n
  45. let n++
  46. done
  47. back
  48. opc=$(selection_fun $num_opc)
  49. [[ $opc = 0 ]] && return 1
  50. encab
  51. echo -e "\033[1;33m Puerto de redireccion de trafico: \033[1;32m${drop[$opc]}"
  52. msg -bar
  53. while [[ -z $opc2 ]]; do
  54. echo -ne "\033[1;37m Ingrese un puerto para WEBSOCKET: " && read opc2
  55. tput cuu1 && tput dl1
  56. [[ $(mportas|grep -w "${opc2}") = "" ]] && {
  57. echo -e "\033[1;33m $(fun_trans "Puerto de websocket:")\033[1;32m ${opc2} OK"
  58. msg -bar
  59. } || {
  60. echo -e "\033[1;33m $(fun_trans "Puerto de websocket:")\033[1;31m ${opc2} FAIL" && sleep 2
  61. tput cuu1 && tput dl1
  62. unset opc2
  63. }
  64. done
  65. while :
  66. do
  67. echo -ne "\033[1;37m Desea continuar [s/n]: " && read start
  68. tput cuu1 && tput dl1
  69. if [[ -z $start ]]; then
  70. echo -e "\033[1;37m deves ingresar una opcion \033[1;32m[S] \033[1;37mpara Si \033[1;31m[n] \033[1;37mpara No." && sleep 2
  71. tput cuu1 && tput dl1
  72. else
  73. [[ $start = @(n|N) ]] && break
  74. if [[ $start = @(s|S) ]]; then
  75. node_v="$(which nodejs)" && [[ $(ls -l ${node_v}|grep -w 'node') ]] && node_v="$(which node)"
  76. echo -e "[Unit]
  77. Description=P7COM-nodews1
  78. Documentation=https://p7com.net/
  79. After=network.target nss-lookup.target\n
  80. [Service]
  81. User=nobody
  82. CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  83. AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
  84. NoNewPrivileges=true
  85. ExecStart=${node_v} /etc/ADMRufu/install/WS-Proxy.js -dhost 127.0.0.1 -dport ${drop[$opc]} -mport $opc2
  86. Restart=on-failure
  87. RestartSec=3s\n
  88. [Install]
  89. WantedBy=multi-user.target" > /etc/systemd/system/nodews.$opc2.service
  90. systemctl enable nodews.$opc2 &>/dev/null
  91. systemctl start nodews.$opc2 &>/dev/null
  92. print_center -verd "Ejecucion con exito"
  93. enter
  94. break
  95. fi
  96. fi
  97. done
  98. return 1
  99. }
  100. stop_ws () {
  101. ck_ws=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND"|grep "node")
  102. if [[ -z $(echo "$ck_ws" | awk '{print $1}' | head -n 1) ]]; then
  103. print_center -verm2 "WEBSOCKET no encontrado"
  104. else
  105. ck_port=$(echo "$ck_ws" | awk '{print $9}' | awk -F ":" '{print $2}')
  106. for i in $ck_port; do
  107. systemctl stop nodews.${i} &>/dev/null
  108. systemctl disable nodews.${1} &>/dev/null
  109. rm /etc/systemd/system/nodews.${i}.service &>/dev/null
  110. done
  111. print_center -verm2 "WEBSOCKET detenido"
  112. fi
  113. enter
  114. return 1
  115. }
  116. stop_port () {
  117. clear
  118. STWS=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND"|grep "node" | awk '{print $9}' | awk -F ":" '{print $2}')
  119. title "DETENER UN PUERTO"
  120. n=1
  121. for i in $STWS; do
  122. echo -e " \033[1;32m[$n] \033[1;31m> \033[1;37m$i\033[0m"
  123. wspr[$n]=$i
  124. let n++
  125. done
  126. back
  127. echo -ne "\033[1;37m opcion: " && read prws
  128. tput cuu1 && tput dl1
  129. [[ $prws = "0" ]] && return
  130. systemctl stop nodews.${wspr[$prws]} &>/dev/null
  131. systemctl disable nodews.${wspr[$prws]} &>/dev/null
  132. rm /etc/systemd/system/nodews.${wspr[$prws]}.service &>/dev/null
  133. print_center -verm2 "PUERTO WEBSOCKET ${wspr[$prws]} detenido"
  134. enter
  135. return 1
  136. }
  137. encab(){
  138. title "SSH OVER WEBSOCKET CDN CLOUDFLARE"
  139. }
  140. encab
  141. menu_func "INICIAR/AGREGAR PROXY WS CDN" "DETENER PROXY WS CDN"
  142. sf=2
  143. [[ $(lsof -V -i tcp -P -n|grep -v "ESTABLISHED"|grep -v "COMMAND"|grep "node"|wc -l) -ge "2" ]] && echo -e "$(msg -verd " [3]") $(msg -verm2 ">") $(msg -azu "DETENER UN PUERTO")" && sf=3
  144. back
  145. selection=$(selection_fun ${sf})
  146. case ${selection} in
  147. 1) conf;;
  148. 2) stop_ws && read foo;;
  149. 3) stop_port;;
  150. 0)return 1;;
  151. esac