squid.sh 12 KB

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