1
0

utils.sh 5.3 KB

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