1
0

utils.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/bash
  2. #06/05/2020
  3. clear
  4. declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
  5. SCPfrm="/etc/ger-frm" && [[ ! -d ${SCPfrm} ]] && exit
  6. SCPinst="/etc/ger-inst" && [[ ! -d ${SCPinst} ]] && exit
  7. TCPspeed () {
  8. if [[ `grep -c "^#ADM" /etc/sysctl.conf` -eq 0 ]]; then
  9. #INSTALA
  10. msg -ama "$(fun_trans "TCP Speed No Activado, Desea Activar Ahora")?"
  11. msg -bar
  12. while [[ ${resposta} != @(s|S|n|N|y|Y) ]]; do
  13. read -p " [S/N]: " -e -i s resposta
  14. tput cuu1 && tput dl1
  15. done
  16. [[ "$resposta" = @(s|S|y|Y) ]] && {
  17. echo "#ADM" >> /etc/sysctl.conf
  18. echo "net.ipv4.tcp_window_scaling = 1
  19. net.core.rmem_max = 16777216
  20. net.core.wmem_max = 16777216
  21. net.ipv4.tcp_rmem = 4096 87380 16777216
  22. net.ipv4.tcp_wmem = 4096 16384 16777216
  23. net.ipv4.tcp_low_latency = 1
  24. net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.conf
  25. sysctl -p /etc/sysctl.conf > /dev/null 2>&1
  26. msg -ama "$(fun_trans "TCP Activo Con Exito")!"
  27. } || msg -ama "$(fun_trans "Cancelado")!"
  28. else
  29. #REMOVE
  30. msg -ama "$(fun_trans "TCP Speed ya esta activado, desea detener ahora")?"
  31. msg -bar
  32. while [[ ${resposta} != @(s|S|n|N|y|Y) ]]; do
  33. read -p " [S/N]: " -e -i s resposta
  34. tput cuu1 && tput dl1
  35. done
  36. [[ "$resposta" = @(s|S|y|Y) ]] && {
  37. grep -v "^#ADM
  38. net.ipv4.tcp_window_scaling = 1
  39. net.core.rmem_max = 16777216
  40. net.core.wmem_max = 16777216
  41. net.ipv4.tcp_rmem = 4096 87380 16777216
  42. net.ipv4.tcp_wmem = 4096 16384 16777216
  43. net.ipv4.tcp_low_latency = 1
  44. net.ipv4.tcp_slow_start_after_idle = 0" /etc/sysctl.conf > /tmp/syscl && mv -f /tmp/syscl /etc/sysctl.conf
  45. sysctl -p /etc/sysctl.conf > /dev/null 2>&1
  46. msg -ama "$(fun_trans "TCP Parado Con Exito")!"
  47. } || msg -ama "$(fun_trans "Cancelado")!"
  48. fi
  49. }
  50. SquidCACHE () {
  51. msg -ama "$(fun_trans "Squid Cache, Aplica cache en Squid")"
  52. msg -ama "$(fun_trans "Mejora la velocidad del squid")"
  53. msg -bar
  54. if [ -e /etc/squid/squid.conf ]; then
  55. squid_var="/etc/squid/squid.conf"
  56. elif [ -e /etc/squid3/squid.conf ]; then
  57. squid_var="/etc/squid3/squid.conf"
  58. else
  59. msg -ama "$(fun_trans "Su sistema no tiene un squid")!" && return 1
  60. fi
  61. teste_cache="#CACHE DO SQUID"
  62. if [[ `grep -c "^$teste_cache" $squid_var` -gt 0 ]]; then
  63. [[ -e ${squid_var}.bakk ]] && {
  64. msg -ama "$(fun_trans "Cache squid identificado, eliminando")!"
  65. mv -f ${squid_var}.bakk $squid_var
  66. msg -ama "$(fun_trans "Cache squid Removido")!"
  67. service squid restart > /dev/null 2>&1 &
  68. service squid3 restart > /dev/null 2>&1 &
  69. return 0
  70. }
  71. fi
  72. msg -ama "$(fun_trans "Aplicando Cache Squid")!"
  73. msg -bar
  74. _tmp="#CACHE DO SQUID\ncache_mem 200 MB\nmaximum_object_size_in_memory 32 KB\nmaximum_object_size 1024 MB\nminimum_object_size 0 KB\ncache_swap_low 90\ncache_swap_high 95"
  75. [[ "$squid_var" = "/etc/squid/squid.conf" ]] && _tmp+="\ncache_dir ufs /var/spool/squid 100 16 256\naccess_log /var/log/squid/access.log squid" || _tmp+="\ncache_dir ufs /var/spool/squid3 100 16 256\naccess_log /var/log/squid3/access.log squid"
  76. while read s_squid; do
  77. [[ "$s_squid" != "cache deny all" ]] && _tmp+="\n${s_squid}"
  78. done < $squid_var
  79. cp ${squid_var} ${squid_var}.bakk
  80. echo -e "${_tmp}" > $squid_var
  81. msg -ama "$(fun_trans "Cache Aplicado con Exito")!"
  82. service squid restart > /dev/null 2>&1 &
  83. service squid3 restart > /dev/null 2>&1 &
  84. }
  85. timemx () {
  86. rm -rf /etc/localtime
  87. ln -s /usr/share/zoneinfo/America/Merida /etc/localtime
  88. echo -e " $(fun_trans "FECHA LOCAL MX APLICADA!")"
  89. }
  90. resetiptables () {
  91. echo -e "Reiniciando Ipetables espere"
  92. iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X && iptables -t mangle -F && iptables -t mangle -X && iptables -t raw -F && iptables -t raw -X && iptables -t security -F && iptables -t security -X && iptables -P INPUT ACCEPT && iptables -P FORWARD ACCEPT && iptables -P OUTPUT ACCEPT
  93. echo -e "iptables reiniciadas con exito"
  94. }
  95. packobs () {
  96. msg -ama "Buscando Paquetes Obsoletos"
  97. dpkg -l | grep -i ^rc
  98. msg -ama "Limpiando Paquetes Obsoloteos"
  99. dpkg -l |grep -i ^rc | cut -d " " -f 3 | xargs dpkg --purge
  100. msg -ama "Limpieza Completa"
  101. }
  102. on="\033[1;32m[ON]" && off="\033[1;31m[OFF]"
  103. [[ $(ps x | grep badvpn | grep -v grep | awk '{print $1}') ]] && badvpn=$on || badvpn=$off
  104. [[ `grep -c "^#ADM" /etc/sysctl.conf` -eq 0 ]] && tcp=$off || tcp=$on
  105. if [ -e /etc/squid/squid.conf ]; then
  106. [[ `grep -c "^#CACHE DO SQUID" /etc/squid/squid.conf` -gt 0 ]] && squid=$on || squid=$off
  107. elif [ -e /etc/squid3/squid.conf ]; then
  108. [[ `grep -c "^#CACHE DO SQUID" /etc/squid3/squid.conf` -gt 0 ]] && squid=$on || squid=$off
  109. fi
  110. msg -bar
  111. msg -ama " OPTIMIZADORES BASICOS "
  112. msg -bar
  113. echo -ne "$(msg -verd " [1]") $(msg -verm2 ">") " && msg -azu "TCP-SPEED $tcp"
  114. echo -ne "$(msg -verd " [2]") $(msg -verm2 ">") " && msg -azu "CACHE PARA SQUID $squid"
  115. echo -ne "$(msg -verd " [3]") $(msg -verm2 ">") " && msg -azu "LIMPIAR PAQUETES OBSOLETOS"
  116. echo -ne "$(msg -verd " [4]") $(msg -verm2 ">") " && msg -azu "$(fun_trans "RESET IPTABLES")"
  117. msg -bar
  118. echo -ne "$(msg -verd " [0]") $(msg -verm2 ">") " && msg -bra " \033[1;41m VOLVER \033[0m"
  119. msg -bar
  120. while [[ ${arquivoonlineadm} != @(0|[1-5]) ]]; do
  121. echo -ne "$(msg -azu "opcion:") "
  122. read arquivoonlineadm
  123. tput cuu1 && tput dl1
  124. done
  125. case $arquivoonlineadm in
  126. 1)TCPspeed;;
  127. 2)SquidCACHE;;
  128. 3)packobs;;
  129. 4)resetiptables;;
  130. 0)exit;;
  131. esac
  132. msg -bar