squid.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. systemctl stop squid &>/dev/null
  75. systemctl disable squid &>/dev/null
  76. elif [[ -e /etc/squid3/squid.conf ]]; then
  77. var_squid="/etc/squid3/squid.conf"
  78. systemctl stop squid3 &>/dev/null
  79. systemctl disable squid3 &>/dev/null
  80. fi
  81. [[ -e $var_squid ]] && {
  82. echo -e "\033[1;32m $(fun_trans "REMOVIENDO SQUID")"
  83. msg -bar
  84. service squid stop > /dev/null 2>&1
  85. apt-get remove squid -y &>/dev/null
  86. apt-get remove squid3 -y &>/dev/null && echo -e " \033[1;33m[\033[1;31m#################################\033[1;33m] - \033[1;32m100%\033[0m"
  87. msg -bar
  88. echo -e "\033[1;32m $(fun_trans "Procedimento Concluido")"
  89. msg -bar
  90. [[ -e $var_squid ]] && rm $var_squid
  91. return 0
  92. }
  93. msg -bar
  94. msg -tit
  95. msg -ama " INSTALADOR SQUID VPS-MX"
  96. msg -bar
  97. fun_ip
  98. echo -ne " Confirme su ip\033[1;91m"; read -p ": " -e -i $IP ip
  99. msg -bar
  100. echo -e " \033[1;97mAhora elige los puertos que desea en el Squid"
  101. echo -e " \033[1;97mSeleccione puertos en orden secuencial,\n \033[1;92mEjemplo: 80 8080 8799 3128"
  102. msg -bar
  103. echo -ne " Digite losPuertos:\033[1;32m "; read portasx
  104. msg -bar
  105. totalporta=($portasx)
  106. unset PORT
  107. for((i=0; i<${#totalporta[@]}; i++)); do
  108. [[ $(mportas|grep "${totalporta[$i]}") = "" ]] && {
  109. echo -e "\033[1;33m Puerto Escojido:\033[1;32m ${totalporta[$i]} OK"
  110. PORT+="${totalporta[$i]}\n"
  111. } || {
  112. echo -e "\033[1;33m Puerto Escojido:\033[1;31m ${totalporta[$i]} FAIL"
  113. }
  114. done
  115. [[ -z $PORT ]] && {
  116. echo -e "\033[1;31m No se ha elegido ninguna puerto valido\033[0m"
  117. return 1
  118. }
  119. msg -bar
  120. echo -e " INSTALANDO SQUID"
  121. msg -bar
  122. 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
  123. apt-get install squid -y
  124. msg -bar
  125. echo -e " $(fun_trans "INICIANDO CONFIGURACION")"
  126. 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
  127. msg -bar
  128. echo -e "\033[1;32m $(fun_trans "Ahora Escoja Una Conf Para Su Proxy")"
  129. msg -bar
  130. echo -e "|1| $(fun_trans "Basico")"
  131. echo -e "|2| $(fun_trans "Avanzado recomendado")\033[1;37m"
  132. msg -bar
  133. read -p "[1/2]: " -e -i 1 proxy_opt
  134. tput cuu1 && tput dl1
  135. if [[ $proxy_opt = 1 ]]; then
  136. echo -e " $(fun_trans " INSTALANDO SQUID BASICO")"
  137. elif [[ $proxy_opt = 2 ]]; then
  138. echo -e " $(fun_trans " INSTALANDO SQUID AVANZADO")"
  139. else
  140. echo -e " $(fun_trans " INSTALANDO SQUID BASICO")"
  141. proxy_opt=1
  142. fi
  143. unset var_squid
  144. if [[ -d /etc/squid ]]; then
  145. var_squid="/etc/squid/squid.conf"
  146. systemctl enable squid &>/dev/null
  147. systemctl start squid &>/dev/null
  148. elif [[ -d /etc/squid3 ]]; then
  149. var_squid="/etc/squid3/squid.conf"
  150. systemctl enable squid3 &>/dev/null
  151. systemctl start squid3 &>/dev/null
  152. fi
  153. if [[ "$proxy_opt" = @(02|2) ]]; then
  154. echo -e "#ConfiguracaoSquiD
  155. acl url1 dstdomain -i $IP
  156. acl url2 dstdomain -i 127.0.0.1
  157. acl url3 url_regex -i '/etc/payloads'
  158. acl url4 url_regex -i '/etc/opendns'
  159. acl url5 dstdomain -i localhost
  160. acl accept dstdomain -i GET
  161. acl accept dstdomain -i POST
  162. acl accept dstdomain -i OPTIONS
  163. acl accept dstdomain -i CONNECT
  164. acl accept dstdomain -i PUT
  165. acl HEAD dstdomain -i HEAD
  166. acl accept dstdomain -i TRACE
  167. acl accept dstdomain -i OPTIONS
  168. acl accept dstdomain -i PATCH
  169. acl accept dstdomain -i PROPATCH
  170. acl accept dstdomain -i DELETE
  171. acl accept dstdomain -i REQUEST
  172. acl accept dstdomain -i METHOD
  173. acl accept dstdomain -i NETDATA
  174. acl accept dstdomain -i MOVE
  175. acl all src 0.0.0.0/0
  176. http_access allow url1
  177. http_access allow url2
  178. http_access allow url3
  179. http_access allow url4
  180. http_access allow url5
  181. http_access allow accept
  182. http_access allow HEAD
  183. http_access deny all
  184. # Request Headers Forcing
  185. request_header_access Allow allow all
  186. request_header_access Authorization allow all
  187. request_header_access WWW-Authenticate allow all
  188. request_header_access Proxy-Authorization allow all
  189. request_header_access Proxy-Authenticate allow all
  190. request_header_access Cache-Control allow all
  191. request_header_access Content-Encoding allow all
  192. request_header_access Content-Length allow all
  193. request_header_access Content-Type allow all
  194. request_header_access Date allow all
  195. request_header_access Expires allow all
  196. request_header_access Host allow all
  197. request_header_access If-Modified-Since allow all
  198. request_header_access Last-Modified allow all
  199. request_header_access Location allow all
  200. request_header_access Pragma allow all
  201. request_header_access Accept allow all
  202. request_header_access Accept-Charset allow all
  203. request_header_access Accept-Encoding allow all
  204. request_header_access Accept-Language allow all
  205. request_header_access Content-Language allow all
  206. request_header_access Mime-Version allow all
  207. request_header_access Retry-After allow all
  208. request_header_access Title allow all
  209. request_header_access Connection allow all
  210. request_header_access Proxy-Connection allow all
  211. request_header_access User-Agent allow all
  212. request_header_access Cookie allow all
  213. #request_header_access All deny all
  214. # Response Headers Spoofing
  215. #reply_header_access Via deny all
  216. #reply_header_access X-Cache deny all
  217. #reply_header_access X-Cache-Lookup deny all
  218. #portas" > $var_squid
  219. for pts in $(echo -e $PORT); do
  220. echo -e "http_port $pts" >> $var_squid
  221. done
  222. echo -e "
  223. #nome
  224. visible_hostname VPS-MX
  225. via off
  226. forwarded_for off
  227. pipeline_prefetch off" >> $var_squid
  228. else
  229. echo -e "#Configuracion SquiD
  230. acl localhost src 127.0.0.1/32 ::1
  231. acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
  232. acl SSL_ports port 443
  233. acl Safe_ports port 80
  234. acl Safe_ports port 21
  235. acl Safe_ports port 443
  236. acl Safe_ports port 70
  237. acl Safe_ports port 210
  238. acl Safe_ports port 1025-65535
  239. acl Safe_ports port 280
  240. acl Safe_ports port 488
  241. acl Safe_ports port 8080
  242. acl Safe_ports port 591
  243. acl Safe_ports port 777
  244. acl CONNECT method CONNECT
  245. acl SSH dst $ip-$ip/255.255.255.255
  246. http_access allow SSH
  247. http_access allow manager localhost
  248. http_access deny manager
  249. http_access allow localhost
  250. http_access deny all
  251. coredump_dir /var/spool/squid
  252. refresh_pattern ^ftp: 1440 20% 10080
  253. refresh_pattern ^gopher: 1440 0% 1440
  254. refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
  255. refresh_pattern . 0 20% 4320
  256. #Puertos" > $var_squid
  257. for pts in $(echo -e $PORT); do
  258. echo -e "http_port $pts" >> $var_squid
  259. done
  260. echo -e "
  261. #HostName
  262. visible_hostname VPS-MX
  263. via off
  264. forwarded_for off
  265. pipeline_prefetch off" >> $var_squid
  266. fi
  267. touch /etc/opendns
  268. fun_eth
  269. msg -bar
  270. echo -ne " \033[1;31m [ ! ] \033[1;33m$(fun_trans " REINICIANDO SERVICIOS")"
  271. squid3 -k reconfigure > /dev/null 2>&1
  272. squid -k reconfigure > /dev/null 2>&1
  273. service ssh restart > /dev/null 2>&1
  274. systemctl restart squid &>/dev/null
  275. systemctl restart squid3 &>/dev/null
  276. service squid3 restart > /dev/null 2>&1
  277. service squid restart > /dev/null 2>&1
  278. systemctl restart unattended-upgrades.service &>/dev/null
  279. echo -e " \033[1;32m[OK]"
  280. msg -bar
  281. echo -e "${cor[3]}$(fun_trans " SQUID CONFIGURADO")"
  282. msg -bar
  283. #UFW
  284. for ufww in $(mportas|awk '{print $2}'); do
  285. ufw allow $ufww > /dev/null 2>&1
  286. done
  287. }
  288. SPR &
  289. online_squid () {
  290. payload="/etc/payloads"
  291. msg -bar
  292. echo -e "\033[1;33m SQUID CONFIGURADO"
  293. msg -bar
  294. echo -e "${cor[2]} [1] >${cor[3]} Colocar Host en Squid"
  295. echo -e "${cor[2]} [2] >${cor[3]} Remover Host de Squid"
  296. echo -e "${cor[2]} [3] >${cor[3]} Desinstalar Squid"
  297. echo -e "${cor[2]} [0] >${cor[3]} Volver"
  298. msg -bar
  299. while [[ $varpay != @(0|[1-3]) ]]; do
  300. read -p "[0/3]: " varpay
  301. tput cuu1 && tput dl1
  302. done
  303. if [[ "$varpay" = "0" ]]; then
  304. return 1
  305. elif [[ "$varpay" = "1" ]]; then
  306. echo -e "${cor[4]} $(fun_trans "Hosts Actuales Dentro del Squid")"
  307. msg -bar
  308. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  309. msg -bar
  310. while [[ $hos != \.* ]]; do
  311. echo -ne "${cor[4]}$(fun_trans "Escriba el nuevo host"): " && read hos
  312. tput cuu1 && tput dl1
  313. [[ $hos = \.* ]] && continue
  314. echo -e "${cor[4]}$(fun_trans "Comience con") .${cor[0]}"
  315. sleep 2s
  316. tput cuu1 && tput dl1
  317. done
  318. host="$hos/"
  319. [[ -z $host ]] && return 1
  320. [[ `grep -c "^$host" $payload` -eq 1 ]] &&:echo -e "${cor[4]}$(fun_trans "Host ya Exciste")${cor[0]}" && return 1
  321. echo "$host" >> $payload && grep -v "^$" $payload > /tmp/a && mv /tmp/a $payload
  322. echo -e "${cor[4]}$(fun_trans "Host Agregado con Exito")"
  323. msg -bar
  324. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  325. msg -bar
  326. if [[ ! -f "/etc/init.d/squid" ]]; then
  327. service squid3 reload
  328. systemctl restart squid3
  329. service squid3 restart
  330. else
  331. /etc/init.d/squid reload
  332. syetemctl restart squid
  333. service squid restart
  334. fi
  335. return 0
  336. elif [[ "$varpay" = "2" ]]; then
  337. echo -e "${cor[4]} $(fun_trans "Hosts Actuales Dentro del Squid")"
  338. msg -bar
  339. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  340. msg -bar
  341. while [[ $hos != \.* ]]; do
  342. echo -ne "${cor[4]}Digite un Host: " && read hos
  343. tput cuu1 && tput dl1
  344. [[ $hos = \.* ]] && continue
  345. echo -e "${cor[4]}Comience con ."
  346. sleep 2s
  347. tput cuu1 && tput dl1
  348. done
  349. host="$hos/"
  350. [[ -z $host ]] && return 1
  351. [[ `grep -c "^$host" $payload` -ne 1 ]] &&!echo -e "${cor[5]}Host No Encontrado" && return 1
  352. grep -v "^$host" $payload > /tmp/a && mv /tmp/a $payload
  353. echo -e "${cor[4]}Host Removido Con Exito"
  354. msg -bar
  355. cat $payload | awk -F "/" '{print $1,$2,$3,$4}'
  356. msg -bar
  357. if [[ ! -f "/etc/init.d/squid" ]]; then
  358. service squid3 reload
  359. systemctl restart squid3
  360. service squid3 restart
  361. service squid reload
  362. systemctl restart squid
  363. service squid restart
  364. else
  365. /etc/init.d/squid reload
  366. systemctl restart squid
  367. service squid restart
  368. /etc/init.d/squid3 reload
  369. systemctl restart squid3
  370. service squid3 restart
  371. fi
  372. return 0
  373. elif [[ "$varpay" = "3" ]]; then
  374. fun_squid
  375. fi
  376. }
  377. if [[ -e /etc/squid/squid.conf ]]; then
  378. online_squid
  379. elif [[ -e /etc/squid3/squid.conf ]]; then
  380. online_squid
  381. else
  382. fun_squid
  383. fi