squidpass.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash
  2. #19/12/2019
  3. clear
  4. msg -bar
  5. SCPdir="/etc/newadm" && [[ ! -d ${SCPdir} ]] && exit 1
  6. SCPfrm="/etc/ger-frm" && [[ ! -d ${SCPfrm} ]] && exit
  7. SCPinst="/etc/ger-inst" && [[ ! -d ${SCPinst} ]] && exit
  8. SCPidioma="${SCPdir}/idioma" && [[ ! -e ${SCPidioma} ]] && touch ${SCPidioma}
  9. declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
  10. fun_bar () {
  11. comando[0]="$1"
  12. comando[1]="$2"
  13. (
  14. [[ -e $HOME/fim ]] && rm $HOME/fim
  15. ${comando[0]} -y > /dev/null 2>&1
  16. ${comando[1]} -y > /dev/null 2>&1
  17. touch $HOME/fim
  18. ) > /dev/null 2>&1 &
  19. echo -ne "\033[1;33m ["
  20. while true; do
  21. for((i=0; i<18; i++)); do
  22. echo -ne "\033[1;31m##"
  23. sleep 0.1s
  24. done
  25. [[ -e $HOME/fim ]] && rm $HOME/fim && break
  26. echo -e "\033[1;33m]"
  27. sleep 1s
  28. tput cuu1
  29. tput dl1
  30. echo -ne "\033[1;33m ["
  31. done
  32. echo -e "\033[1;33m]\033[1;31m -\033[1;32m 100%\033[1;37m"
  33. }
  34. #PREENXE A VARIAVEL $IP
  35. meu_ip () {
  36. MEU_IP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
  37. MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
  38. [[ "$MEU_IP" != "$MEU_IP2" ]] && IP="$MEU_IP2" || IP="$MEU_IP"
  39. }
  40. squidpass () {
  41. tmp_arq="/tmp/arq-tmp"
  42. if [ -d "/etc/squid" ]; then
  43. pwd="/etc/squid/passwd"
  44. config_="/etc/squid/squid.conf"
  45. service_="squid"
  46. squid_="0"
  47. elif [ -d "/etc/squid3" ]; then
  48. pwd="/etc/squid3/passwd"
  49. config_="/etc/squid3/squid.conf"
  50. service_="squid3"
  51. squid_="1"
  52. fi
  53. [[ ! -e $config_ ]] &&
  54. msg -bar &&
  55. echo -e " \033[1;36m Proxy Squid no Instalado no puede proseguir" &&
  56. msg -bar &&
  57. return 0
  58. if [ -e $pwd ]; then
  59. echo -e "${cor[3]} Desea Desactivar Autentificasion del Proxy Squid"
  60. read -p " [S/N]: " -e -i n sshsn
  61. [[ "$sshsn" = @(s|S|y|Y) ]] && {
  62. msg -bar
  63. echo -e " \033[1;36mDesintalando Dependencias:"
  64. rm -rf /usr/bin/squid_log1
  65. fun_bar 'apt-get remove apache2-utils'
  66. msg -bar
  67. cat $config_ | grep -v '#Password' > $tmp_arq
  68. mv -f $tmp_arq $config_
  69. cat $config_ | grep -v '^auth_param.*passwd*$' > $tmp_arq
  70. mv -f $tmp_arq $config_
  71. cat $config_ | grep -v '^auth_param.*proxy*$' > $tmp_arq
  72. mv -f $tmp_arq $config_
  73. cat $config_ | grep -v '^acl.*REQUIRED*$' > $tmp_arq
  74. mv -f $tmp_arq $config_
  75. cat $config_ | grep -v '^http_access.*authenticated*$' > $tmp_arq
  76. mv -f $tmp_arq $config_
  77. cat $config_ | grep -v '^http_access.*all*$' > $tmp_arq
  78. mv -f $tmp_arq $config_
  79. echo -e "
  80. http_access allow all" >> "$config_"
  81. rm -f $pwd
  82. service $service_ restart > /dev/null 2>&1 &
  83. echo -e " \033[1;31m Desautentificasion de Proxy Squid Desactivado"
  84. msg -bar
  85. }
  86. else
  87. echo -e "${cor[3]} "Habilitar Autenfificasion de Proxy Squid?""
  88. read -p " [S/N]: " -e -i n sshsn
  89. [[ "$sshsn" = @(s|S|y|Y) ]] && {
  90. msg -bar
  91. echo -e " \033[1;36mInstalando Dependencias:"
  92. echo "Archivo SQUID PASS" > /usr/bin/squid_log1
  93. fun_bar 'apt-get install apache2-utils'
  94. msg -bar
  95. read -e -p " Tu nombre de usuario deseado: " usrn
  96. [[ $usrn = "" ]] &&
  97. msg -bar &&
  98. echo -e " \033[1;31mEl usuario no puede ser nulo" &&
  99. msg -bar &&
  100. return 0
  101. htpasswd -c $pwd $usrn
  102. succes_=$(grep -c "$usrn" $pwd)
  103. if [ "$succes_" = "0" ]; then
  104. rm -f $pwd
  105. msg -bar
  106. echo -e " \033[1;31m Error al generar la contraseña, no se inició la autenticación de Squid"
  107. msg -bar
  108. return 0
  109. elif [[ "$succes_" = "1" ]]; then
  110. cat $config_ | grep -v '^http_access.*all*$' > $tmp_arq
  111. mv -f $tmp_arq $config_
  112. if [ "$squid_" = "0" ]; then
  113. echo -e "#Password
  114. auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd
  115. auth_param basic realm proxy
  116. acl authenticated proxy_auth REQUIRED
  117. http_access allow authenticated
  118. http_access deny all" >> "$config_"
  119. service squid restart > /dev/null 2>&1 &
  120. update-rc.d squid defaults > /dev/null 2>&1 &
  121. elif [ "$squid_" = "1" ]; then
  122. echo -e "#Password
  123. auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/passwd
  124. auth_param basic realm proxy
  125. acl authenticated proxy_auth REQUIRED
  126. http_access allow authenticated
  127. http_access deny all" >> "$config_"
  128. service squid3 restart > /dev/null 2>&1 &
  129. update-rc.d squid3 defaults > /dev/null 2>&1 &
  130. fi
  131. msg -bar
  132. echo -e " \033[1;32m PROTECCION DE PROXY INICIADA"
  133. msg -bar
  134. fi
  135. }
  136. fi
  137. }
  138. echo -e "${cor[3]} AUTENTIFICAR PROXY SQUID ${cor[2]}[VPS-MX]"
  139. msg -bar
  140. unset squid_log1
  141. [[ -e /usr/bin/squid_log1 ]] && squid_log1="\033[1;32m$(source trans -b pt:${id} "ACTIVO")"
  142. echo -e "${cor[2]} [1] > ${cor[3]}AUTENTIFICAR O DESAUTENTIFICAR PROXY $squid_log1"
  143. echo -e "${cor[2]} [0] > ${cor[4]}VOLVER"
  144. msg -bar
  145. echo -ne "\033[1;37mEscoja una Opcion: "
  146. read optons
  147. case $optons in
  148. 0)
  149. msg -bar
  150. exit
  151. ;;
  152. 1)
  153. msg -bar
  154. squidpass
  155. ;;
  156. esac
  157. #Reinicia ADM
  158. [[ "$1" = "1" ]] && squidpass
  159. ####_Eliminar_Tmps_####
  160. [[ -e $_tmp ]] && rm $_tmp
  161. [[ -e $_tmp2 ]] && rm $_tmp2
  162. [[ -e $_tmp3 ]] && rm $_tmp3
  163. [[ -e $_tmp4 ]] && rm $_tmp4