squid.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. #!/bin/bash
  2. #25/01/2021
  3. declare -A cor=( [0]=" \033[1;37m" [1]=" \033[1;34m" [2]=" \033[1;32m" [3]=" \033[1;36m" [4]=" \033[1;31m" )
  4. clear
  5. clear
  6. SCPdir="/etc/VPS-MX"
  7. SCPfrm="${SCPdir}/herramientas" && [[ ! -d ${SCPfrm} ]] && exit
  8. SCPinst="${SCPdir}/protocolos"&& [[ ! -d ${SCPinst} ]] && exit
  9. #LISTA PORTAS
  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_ip () {
  21. 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)
  22. MEU_IP2=$(wget -qO- ipv4.icanhazip.com)
  23. [[ "$MEU_IP" != "$MEU_IP2" ]] && IP="$MEU_IP2" || IP="$MEU_IP"
  24. }
  25. #ETHOOL SSH
  26. fun_eth () {
  27. eth=$(ifconfig | grep -v inet6 | grep -v lo | grep -v 127.0.0.1 | grep "encap:Ethernet" | awk '{print $1}')
  28. [[ $eth != "" ]] && {
  29. msg -bar
  30. echo -e "${cor[3]} $(fun_trans "Aplicar el sistema para mejorar los paquetes SSH?")"
  31. echo -e "${cor[3]} $(fun_trans "Opciones para usuarios avanzados")"
  32. msg -bar
  33. read -p "[S/N]: " -e -i n sshsn
  34. tput cuu1 && tput dl1
  35. [[ "$sshsn" = @(s|S|y|Y) ]] && {
  36. echo -e "${cor[1]} $(fun_trans "Correccion de problemas de paquetes en SSH...")"
  37. msg -bar
  38. echo -e " $(fun_trans "Cual es la tasa RX")"
  39. echo -ne "[ 1 - 999999999 ]: "; read rx
  40. [[ "$rx" = "" ]] && rx="999999999"
  41. echo -e " $(fun_trans "Cual es la tasa TX")"
  42. echo -ne "[ 1 - 999999999 ]: "; read tx
  43. [[ "$tx" = "" ]] && tx="999999999"
  44. apt-get install ethtool -y > /dev/null 2>&1
  45. ethtool -G $eth rx $rx tx $tx > /dev/null 2>&1
  46. msg -bar
  47. }
  48. }
  49. }
  50. fun_bar () {
  51. comando="$1"
  52. _=$(
  53. $comando > /dev/null 2>&1
  54. ) & > /dev/null
  55. pid=$!
  56. while [[ -d /proc/$pid ]]; do
  57. echo -ne " \033[1;33m["
  58. for((i=0; i<20; i++)); do
  59. echo -ne " \033[1;31m##"
  60. sleep 0.2
  61. done
  62. echo -ne " \033[1;33m]"
  63. sleep 1s
  64. echo
  65. tput cuu1 && tput dl1
  66. done
  67. echo -e " \033[1;33m[ \033[1;31m######################################## \033[1;33m] - \033[1;32m100% \033[0m"
  68. sleep 1s
  69. }
  70. msg -bar3
  71. fun_squid () {
  72. if [[ -e /etc/squid/squid.conf ]]; then
  73. var_squid="/etc/squid/squid.conf"
  74. elif [[ -e /etc/squid3/squid.conf ]]; then
  75. var_squid="/etc/squid3/squid.conf"
  76. fi
  77. [[ -e $var_squid ]] && {
  78. echo -e " \033[1;32m $(fun_trans "REMOVIENDO SQUID")"
  79. msg -bar
  80. service squid stop > /dev/null 2>&1
  81. apt-get remove squid3 -y &>/dev/null && echo -e " \033[1;33m[ \033[1;31m################################# \033[1;33m] - \033[1;32m100% \033[0m"
  82. msg -bar
  83. echo -e " \033[1;32m $(fun_trans "Procedimento Concluido")"
  84. msg -bar
  85. [[ -e $var_squid ]] && rm $var_squid
  86. return 0
  87. }
  88. msg -bar
  89. msg -tit
  90. msg -ama " INSTALADOR SQUID VPS-MX"
  91. msg -bar
  92. fun_ip
  93. echo -ne " $(fun_trans "Confirme su ip") \033[1;91m"; read -p ": " -e -i $IP ip
  94. msg -bar
  95. echo -e " $(fun_trans " \033[1;97mAhora elige los puertos que desea en el Squid")"
  96. echo -e " $(fun_trans " \033[1;97mSeleccione puertos en orden secuencial, \n \033[1;92mEjemplo: 80 8080 8799 3128")"
  97. msg -bar
  98. echo -ne " $(fun_trans "Digite losPuertos:") \033[1;32m "; read portasx
  99. msg -bar
  100. totalporta=($portasx)
  101. unset PORT
  102. for((i=0; i<${#totalporta[@]}; i++)); do
  103. [[ $(mportas|grep "${totalporta[$i]}") = "" ]] && {
  104. echo -e " \033[1;33m $(fun_trans "Puerto Escojido:") \033[1;32m ${totalporta[$i]} OK"
  105. PORT+="${totalporta[$i]} \n"
  106. } || {
  107. echo -e " \033[1;33m $(fun_trans "Puerto Escojido:") \033[1;31m ${totalporta[$i]} FAIL"
  108. }
  109. done
  110. [[ -z $PORT ]] && {
  111. echo -e " \033[1;31m $(fun_trans "No se ha elegido ninguna puerto valido") \033[0m"
  112. return 1
  113. }
  114. msg -bar
  115. echo -e " $(fun_trans "INSTALANDO SQUID")"
  116. msg -bar
  117. apt-get install squid3 -y &>/dev/null && echo -e " \033[1;33m[ \033[1;31m######################################## \033[1;33m] - \033[1;32m100% \033[0m" | pv -qL10
  118. msg -bar
  119. echo -e " $(fun_trans "INICIANDO CONFIGURACION")"
  120. echo -e ".bookclaro.com.br/ \n.claro.com.ar/ \n.claro.com.br/ \n.claro.com.co/ \n.claro.com.ec/ \n.claro.com.gt/ \n.cloudfront.net/ \n.claro.com.ni/ \n.claro.com.pe/ \n.claro.com.sv/ \n.claro.cr/ \n.clarocurtas.com.br/ \n.claroideas.com/ \n.claroideias.com.br/ \n.claromusica.com/ \n.clarosomdechamada.com.br/ \n.clarovideo.com/ \n.facebook.net/ \n.facebook.com/ \n.netclaro.com.br/ \n.oi.com.br/ \n.oimusica.com.br/ \n.speedtest.net/ \n.tim.com.br/ \n.timanamaria.com.br/ \n.vivo.com.br/ \n.rdio.com/ \n.compute-1.amazonaws.com/ \n.portalrecarga.vivo.com.br/ \n.vivo.ddivulga.com/" > /etc/payloads
  121. msg -bar
  122. echo -e " \033[1;32m $(fun_trans "Ahora Escoja Una Conf Para Su Proxy")"
  123. msg -bar
  124. echo -e "|1| $(fun_trans "Basico")"
  125. echo -e "|2| $(fun_trans "Avanzado") \033[1;37m"
  126. msg -bar
  127. read -p "[1/2]: " -e -i 1 proxy_opt
  128. tput cuu1 && tput dl1
  129. if [[ $proxy_opt = 1 ]]; then
  130. echo -e " $(fun_trans " INSTALANDO SQUID BASICO")"
  131. elif [[ $proxy_opt = 2 ]]; then
  132. echo -e " $(fun_trans " INSTALANDO SQUID AVANZADO")"
  133. else
  134. echo -e " $(fun_trans " INSTALANDO SQUID BASICO")"
  135. proxy_opt=1
  136. fi
  137. unset var_squid
  138. if [[ -d /etc/squid ]]; then
  139. var_squid="/etc/squid/squid.conf"
  140. elif [[ -d /etc/squid3 ]]; then
  141. var_squid="/etc/squid3/squid.conf"
  142. fi
  143. if [[ "$proxy_opt" = @(02|2) ]]; then
  144. echo -e "#ConfiguracaoSquiD
  145. acl url1 dstdomain -i $ip
  146. acl url2 dstdomain -i 127.0.0.1
  147. acl url3 url_regex -i '/etc/payloads'
  148. acl url4 url_regex -i '/etc/opendns'
  149. acl url5 dstdomain -i localhost
  150. acl accept dstdomain -i GET
  151. acl accept dstdomain -i POST
  152. acl accept dstdomain -i OPTIONS
  153. acl accept dstdomain -i CONNECT
  154. acl accept dstdomain -i PUT
  155. acl HEAD dstdomain -i HEAD
  156. acl accept dstdomain -i TRACE
  157. acl accept dstdomain -i OPTIONS
  158. acl accept dstdomain -i PATCH
  159. acl accept dstdomain -i PROPATCH
  160. acl accept dstdomain -i DELETE
  161. acl accept dstdomain -i REQUEST
  162. acl accept dstdomain -i METHOD
  163. acl accept dstdomain -i NETDATA
  164. acl accept dstdomain -i MOVE
  165. acl all src 0.0.0.0/0
  166. http_access allow url1
  167. http_access allow url2
  168. http_access allow url3
  169. http_access allow url4
  170. http_access allow url5
  171. http_access allow accept
  172. http_access allow HEAD
  173. http_access deny all
  174. # Request Headers Forcing
  175. request_header_access Allow allow all
  176. request_header_access Authorization allow all
  177. request_header_access WWW-Authenticate allow all
  178. request_header_access Proxy-Authorization allow all
  179. request_header_access Proxy-Authenticate allow all
  180. request_header_access Cache-Control allow all
  181. request_header_access Content-Encoding allow all
  182. request_header_access Content-Length allow all
  183. request_header_access Content-Type allow all
  184. request_header_access Date allow all
  185. request_header_access Expires allow all
  186. request_header_access Host allow all
  187. request_header_access If-Modified-Since allow all
  188. request_header_access Last-Modified allow all
  189. request_header_access Location allow all
  190. request_header_access Pragma allow all
  191. request_header_access Accept allow all
  192. request_header_access Accept-Charset allow all
  193. request_header_access Accept-Encoding allow all
  194. request_header_access Accept-Language allow all
  195. request_header_access Content-Language allow all
  196. request_header_access Mime-Version allow all
  197. request_header_access Retry-After allow all
  198. request_header_access Title allow all
  199. request_header_access Connection allow all
  200. request_header_access Proxy-Connection allow all
  201. request_header_access User-Agent allow all
  202. request_header_access Cookie allow all
  203. #request_header_access All deny all
  204. # Response Headers Spoofing
  205. #reply_header_access Via deny all
  206. #reply_header_access X-Cache deny all
  207. #reply_header_access X-Cache-Lookup deny all
  208. #portas" > $var_squid
  209. for pts in $(echo -e $PORT); do
  210. echo -e "http_port $pts" >> $var_squid
  211. done
  212. echo -e "
  213. #nome
  214. visible_hostname VPS-MX
  215. via off
  216. forwarded_for off
  217. pipeline_prefetch off" >> $var_squid
  218. else
  219. echo -e "#Configuracion SquiD
  220. acl localhost src 127.0.0.1/32 ::1
  221. acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
  222. acl SSL_ports port 443
  223. acl Safe_ports port 80
  224. acl Safe_ports port 21
  225. acl Safe_ports port 443
  226. acl Safe_ports port 70
  227. acl Safe_ports port 210
  228. acl Safe_ports port 1025-65535
  229. acl Safe_ports port 280
  230. acl Safe_ports port 488
  231. acl Safe_ports port 591
  232. acl Safe_ports port 777
  233. acl CONNECT method CONNECT
  234. acl SSH dst $ip-$ip/255.255.255.255
  235. http_access allow SSH
  236. http_access allow manager localhost
  237. http_access deny manager
  238. http_access allow localhost
  239. http_access deny all
  240. coredump_dir /var/spool/squid
  241. refresh_pattern ^ftp: 1440 20% 10080
  242. refresh_pattern ^gopher: 1440 0% 1440
  243. refresh_pattern -i (/cgi-bin/| \?) 0 0% 0
  244. refresh_pattern . 0 20% 4320
  245. #Puertos" > $var_squid
  246. for pts in $(echo -e $PORT); do
  247. echo -e "http_port $pts" >> $var_squid
  248. done
  249. echo -e "
  250. #HostName
  251. visible_hostname VPS-MX
  252. via off
  253. forwarded_for off
  254. pipeline_prefetch off" >> $var_squid
  255. fi
  256. touch /etc/opendns
  257. fun_eth
  258. msg -bar
  259. echo -ne " \033[1;31m [ ! ] \033[1;33m$(fun_trans " REINICIANDO SERVICIOS")"
  260. squid3 -k reconfigure > /dev/null 2>&1
  261. squid -k reconfigure > /dev/null 2>&1
  262. service ssh restart > /dev/null 2>&1
  263. service squid3 restart > /dev/null 2>&1
  264. service squid restart > /dev/null 2>&1
  265. echo -e " \033[1;32m[OK]"
  266. msg -bar
  267. echo -e "${cor[3]}$(fun_trans " SQUID CONFIGURADO")"
  268. msg -bar
  269. #UFW
  270. for ufww in $(mportas|awk '{print $2}'); do
  271. ufw allow $ufww > /dev/null 2>&1
  272. done
  273. }
  274. SPR &
  275. online_squid () {
  276. payload="/etc/payloads"
  277. msg -bar
  278. echo -e " \033[1;33m$(fun_trans " SQUID CONFIGURADO")"
  279. msg -bar
  280. echo -e "${cor[2]} [1] >${cor[3]} $(fun_trans "Colocar Host en Squid")"
  281. echo -e "${cor[2]} [2] >${cor[3]} $(fun_trans "Remover Host de Squid")"
  282. echo -e "${cor[2]} [3] >${cor[3]} $(fun_trans "Desinstalar Squid")"
  283. echo -e "${cor[2]} [0] >${cor[3]} $(fun_trans "Volver")"
  284. msg -bar
  285. while [[ $varpay != @(0|[1-3]) ]]; do
  286. read -p "[0/3]: " varpay
  287. tput cuu1 && tput dl1
  288. done
  289. if [[ "$varpay" = "0" ]]; then
  290. return 1
  291. elif [[ "$varpay" = "1" ]]; then
  292. echo -e "${cor[4]} $(fun_trans "Hosts Actuales Dentro del Squid")"
  293. msg -bar
  294. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  295. msg -bar
  296. while [[ $hos != \.* ]]; do
  297. echo -ne "${cor[4]}$(fun_trans "Escriba el nuevo host"): " && read hos
  298. tput cuu1 && tput dl1
  299. [[ $hos = \.* ]] && continue
  300. echo -e "${cor[4]}$(fun_trans "Comience con") .${cor[0]}"
  301. sleep 2s
  302. tput cuu1 && tput dl1
  303. done
  304. host="$hos/"
  305. [[ -z $host ]] && return 1
  306. [[ `grep -c "^$host" $payload` -eq 1 ]] &&:echo -e "${cor[4]}$(fun_trans "Host ya Exciste")${cor[0]}" && return 1
  307. echo "$host" >> $payload && grep -v "^$" $payload > /tmp/a && mv /tmp/a $payload
  308. echo -e "${cor[4]}$(fun_trans "Host Agregado con Exito")"
  309. msg -bar
  310. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  311. msg -bar
  312. if [[ ! -f "/etc/init.d/squid" ]]; then
  313. service squid3 reload
  314. service squid3 restart
  315. else
  316. /etc/init.d/squid reload
  317. service squid restart
  318. fi
  319. return 0
  320. elif [[ "$varpay" = "2" ]]; then
  321. echo -e "${cor[4]} $(fun_trans "Hosts Actuales Dentro del Squid")"
  322. msg -bar
  323. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  324. msg -bar
  325. while [[ $hos != \.* ]]; do
  326. echo -ne "${cor[4]}$(fun_trans "Digite un Host"): " && read hos
  327. tput cuu1 && tput dl1
  328. [[ $hos = \.* ]] && continue
  329. echo -e "${cor[4]}$(fun_trans "Comience con") ."
  330. sleep 2s
  331. tput cuu1 && tput dl1
  332. done
  333. host="$hos/"
  334. [[ -z $host ]] && return 1
  335. [[ `grep -c "^$host" $payload` -ne 1 ]] &&!echo -e "${cor[5]}$(fun_trans "Host No Encontrado")" && return 1
  336. grep -v "^$host" $payload > /tmp/a && mv /tmp/a $payload
  337. echo -e "${cor[4]}$(fun_trans "Host Removido Con Exito")"
  338. msg -bar
  339. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  340. msg -bar
  341. if [[ ! -f "/etc/init.d/squid" ]]; then
  342. service squid3 reload
  343. service squid3 restart
  344. service squid reload
  345. service squid restart
  346. else
  347. /etc/init.d/squid reload
  348. service squid restart
  349. /etc/init.d/squid3 reload
  350. service squid3 restart
  351. fi
  352. return 0
  353. elif [[ "$varpay" = "3" ]]; then
  354. fun_squid
  355. fi
  356. }
  357. if [[ -e /etc/squid/squid.conf ]]; then
  358. online_squid
  359. elif [[ -e /etc/squid3/squid.conf ]]; then
  360. online_squid
  361. else
  362. fun_squid
  363. fi