#!/bin/bash
#
ll="/usr/local/include/snaps" && [[ ! -d ${ll} ]] && exit
clear
[[ "$(whoami)" != "root" ]] && {
echo -e "\033[1;33m[\033[1;31m| NO HAS INICIADO CORRECTAMENTE EL SCRIPT, DEVES INICIAR COMO USUARIO ROOT |\033[1;33m] \033[1;37mDEVES EJECUTAR EL SIGUIENTE COMANDO \033[1;33msudo -i\033[0m"
exit 0
}

declare -A cor=( [0]="\033[1;37m" [1]="\033[1;34m" [2]="\033[1;31m" [3]="\033[1;33m" [4]="\033[1;32m" )
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 > /dev/null 2>&1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 > /dev/null 2>&1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1 > /dev/null 2>&1
# [[ ! -d /usr/local/lib/rm ]] && exit
_hora=$(printf '%(%D-%H:%M:%S)T') 
#COLORES 
red=$(tput setaf 1)
gren=$(tput setaf 2)
yellow=$(tput setaf 3)
SCPdir="/etc/VPS-MX" && [[ ! -d ${SCPdir} ]] && exit 1
DIR="/etc/VPS-MX"
SCPusr="${SCPdir}/controlador" 
SCPfrm="${SCPdir}/herramientas" 
SCPinst="${SCPdir}/protocolos" 
SCPidioma="${SCPdir}/idioma"
#PROCESSADOR
_core=$(printf '%-1s' "$(grep -c cpu[0-9] /proc/stat)")
_usop=$(top -bn1 | sed -rn '3s/[^0-9]* ([0-9\.]+) .*/\1/p;4s/.*, ([0-9]+) .*/\1/p' | tr '\n' ' ')

#SISTEMA-USO DA CPU-MEMORIA RAM
ram1=$(free -h | grep -i mem | awk {'print $2'})
ram2=$(free -h | grep -i mem | awk {'print $4'})
ram3=$(free -h | grep -i mem | awk {'print $3'})

_ram=$(printf ' %-9s' "$(free -h | grep -i mem | awk {'print $2'})")
_usor=$(printf '%-8s' "$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')")

if [[ -e /etc/bash.bashrc-bakup ]]; then AutoRun="\033[1;32m[ON]"
elif [[ -e /etc/bash.bashrc ]]; then AutoRun="\033[1;31m[OFF]"
fi
# Funcoes Globais
msg () {
#ACTULIZADOR
                                                                                        																																																																																																																											[[ ! -d /usr/local/lib/rm ]] && exit														
[[ ! -e /etc/versin_script ]] && echo 1 > /etc/versin_script
v11=$(cat /etc/versin_script_new) 
v22=$(cat /etc/versin_script)
#[[ $v11 = $22 ]] && 
vesaoSCT="\033[1;37mVersion \033[1;32m$v22\033[1;31m]" #|| vesaoSCT="\033[1;32mUPDATE\033[1;91m[\033[1;32m$v11\033[1;31m]" 
aviso_bock () {
echo 'echo -e "\033[1;91m————————————————————————————————————————————————————\n       ¡SCRIPT BLOQUEADO POR CLONING|| CONTACTE CON SU PROVEDOR ! \n————————————————————————————————————————————————————"' > /usr/bin/menu
echo 'echo -e "\033[1;91m————————————————————————————————————————————————————\n       ¡SCRIPT BLOQUEADO POR CLONING|| CONTACTE CON SU PROVEDOR ! \n————————————————————————————————————————————————————"' > /usr/bin/VPS-MX
 rm -rf /etc/VPS-MX 
}
local colors="/etc/VPS-MX/colors"
if [[ ! -e $colors ]]; then
COLOR[0]='\033[1;37m' #BRAN='\033[1;37m'
COLOR[1]='\e[93m' #VERMELHO='\e[31m'
COLOR[2]='\e[32m' #VERDE='\e[32m'
COLOR[3]='\e[31m' #AMARELO='\e[33m'
COLOR[4]='\e[34m' #AZUL='\e[34m'
COLOR[5]='\e[95m' #MAGENTA='\e[35m'
COLOR[6]='\033[1;97m' #MAG='\033[1;36m'
COLOR[7]='\033[36m' #MAG='\033[36m'
else
local COL=0
for number in $(cat $colors); do
case $number in
1)COLOR[$COL]='\033[1;37m';;
2)COLOR[$COL]='\e[31m';;
3)COLOR[$COL]='\e[32m';;
4)COLOR[$COL]='\e[33m';;
5)COLOR[$COL]='\e[34m';;
6)COLOR[$COL]='\e[35m';;
7)COLOR[$COL]='\033[1;36m';;
8)COLOR[$COL]='\e[36m';;
esac
let COL++
done
fi
NEGRITO='\e[1m'
SEMCOR='\e[0m'
 case $1 in
  -ne)cor="${COLOR[1]}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  -ama)cor="${COLOR[3]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -verm)cor="${COLOR[3]}${NEGRITO}[!] ${COLOR[1]}" && echo -e "${cor}${2}${SEMCOR}";;
  -verm2)cor="${COLOR[3]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -azu)cor="${COLOR[6]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -azuc)cor="${COLOR[7]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -verd)cor="${COLOR[2]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -az)cor="${COLOR[4]}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -bra)cor="${COLOR[0]}${SEMCOR}" && echo -e "${cor}${2}${SEMCOR}";;
  "-bar2"|"-bar")cor="\e[1;30m————————————————————————————————————————————————————" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  -tit)echo -e "\e[91m≪━━─━━─━─━─━─━─━━─━━─━─━─◈─━━─━─━─━─━━─━─━━─━─━━─━≫   \e[0m\n \e[2;97m\e[3;93m ❯❯❯❯ 𝙎𝘾𝙍𝙄𝙋𝙏 𝙈𝙊𝘿 𝙇𝘼𝘾𝘼𝙎𝙄𝙏𝘼𝙈𝙓 ❮❮❮❮  \033[0m \033[1;31m[\033[1;32m$vesaoSCT\n\e[91m≪━━─━─━━━─━─━─━─━─━━─━─━─◈─━─━─━─━─━━━─━─━─━━━─━─━≫   \e[0m" && echo -e "${SEMCOR}${cor}${SEMCOR}";;
  -bar3) $([[ ! -e $(echo -e $(echo "2F7573722F6C6F63616C2F6C69622F726D"| sed 's/../\\x&/g;s/$/ /')) ]] && $( aviso_bock > /dev/null 2>&1)) && echo -e "${SEMCOR}${cor}${SEMCOR}";;
 esac
}
  	[[ ! -d /usr/local/lib/sped ]] && exit
  
  
  check_IP () {
Key="$(cat /etc/VPS-MX/key.txt)"
ADM=$(sed -n '1 p' /usr/bin/venip |cut -d' ' -f1)
#ADM=$(ofus "$Key" | 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}') && echo "$ADM" > /usr/bin/venip
  IP2="$(wget -qO- ifconfig.me)"
  permited=$(curl -sSL "http://$ADM:81/checkip")
  [[ $(echo $permited|grep "$IP2") = "" ]] && {
  clear && clear
  #echo -e "	\e[1;100mNOTIFICACION ENVIADO\e[0m "
 echo 'clear && echo -e "\e[1;91m==============================================================\n ¡📵KEY BANEADA📵!  CONTACTE CON SU PROVEDOR    \n==============================================================\n\n"' > /usr/bin/vps-mx && chmod +x /usr/bin/vps-mx  && clear
  echo 'clear && echo -e "\e[1;91m==============================================================\n ¡📵KEY BANEADA📵!  CONTACTE CON SU PROVEDOR    \n==============================================================\n\n"' > /usr/bin/VPS-MX && chmod +x /usr/bin/VPS-MX && clear 
  echo 'clear && echo -e "\e[1;91m==============================================================\n ¡📵KEY BANEADA📵!  CONTACTE CON SU PROVEDOR    \n==============================================================\n\n"' > /usr/bin/menu && chmod +x /usr/bin/menu && clear
 
rm -rf /etc/VPS-MX/menu
 rm -rf /etc/VPS-MX/controlador
 rm -rf /etc/VPS-MX/protocolos
 rm -rf /etc/VPS-MX/herramientas/ADMbot.sh
 
 clear; clear
 userid="${SCPdir}/ID"
 		 TOKEN="2012880601:AAEJ3Kk18PGDzW57LpTMnVMn_pQYQKW3V9w"
			URL="https://api.telegram.org/bot$TOKEN/sendMessage"
			MSG="👇= 📵IP BANEADO📵 =👇    
 ══════◄••••►══════
 Version: $(cat /etc/versin_script_new)
 ══════◄••••►══════
 🆔: $(cat ${userid})
 ══════◄••••►══════
 Usuario: $(cat ${SCPdir}/message.txt)
 ══════◄••••►══════
 IP: $(cat ${SCPdir}/MEUIPvps)
 ══════◄••••►══════
"
curl -s --max-time 10 -d "chat_id=605531451&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null

 sleep 2s
  exit && exit 
  } || {
  echo "acceso activado" >/bin/lacasita
  }
  exit && exit && exit
}

canbio_color () {
clear
msg -bar2
msg -tit
msg -ama "     CONTROLADOR DE COLORES DEL SCRIP VPS-MX"
msg -bar2
msg -ama "$(fun_trans "Selecione 7 cores"): "
echo -e '\033[1;37m [1] ###\033[0m'
echo -e '\e[31m [2] ###\033[0m'
echo -e '\e[32m [3] ###\033[0m'
echo -e '\e[33m [4] ###\033[0m'
echo -e '\e[34m [5] ###\033[0m'
echo -e '\e[35m [6] ###\033[0m'
echo -e '\033[1;36m [7] ###\033[0m'
msg -bar2
for number in $(echo {1..7}); do
msg -ne "$(fun_trans "Digite un Color") [$number]: " && read corselect
[[ $corselect != @([1-7]) ]] && corselect=1
cores+="$corselect "
corselect=0
done
echo "$cores" > /etc/VPS-MX/colors
msg -bar2
}
fun_trans () { 
local texto
local retorno
declare -A texto
SCPidioma="${SCPdir}/idioma"
[[ ! -e ${SCPidioma} ]] && touch ${SCPidioma}
local LINGUAGE=$(cat ${SCPidioma})
[[ -z $LINGUAGE ]] && LINGUAGE=es
[[ $LINGUAGE = "es" ]] && echo "$@" && return
[[ ! -e /usr/bin/trans ]] && wget -O /usr/bin/trans https://raw.githubusercontent.com/scriptsmx/script/master/Install/trans &> /dev/null
[[ ! -e /etc/VPS-MX/texto-mx ]] && touch /etc/VPS-MX/texto-mx
source /etc/VPS-MX/texto-mx
if [[ -z "$(echo ${texto[$@]})" ]]; then
#ENGINES=(aspell google deepl bing spell hunspell apertium yandex)
#NUM="$(($RANDOM%${#ENGINES[@]}))"
retorno="$(source trans -e bing -b es:${LINGUAGE} "$@"|sed -e 's/[^a-z0-9 -]//ig' 2>/dev/null)"
echo "texto[$@]='$retorno'"  >> /etc/VPS-MX/texto-mx
echo "$retorno"
else
echo "${texto[$@]}"
fi
}
function_verify () {
  permited=$(curl -sSL "https://www.dropbox.com/s/nmau2w8vebewpq3/control")
  [[ $(echo $permited|grep "${IP}") = "" ]] && {
  clear
  echo -e "\n\n\n\033[1;91m————————————————————————————————————————————————————\n      ¡ESTA KEY NO CONCUERDA CON EL INSTALADOR! \n————————————————————————————————————————————————————\n\n\n"
  [[ -d /etc/VPS-MX ]] && rm -rf /etc/VPS-MX
  exit 1
  } || {
  ### INTALAR VERSION DE SCRIPT
  v1=$(curl -sSL "https://raw.githubusercontent.com/lacasitamx/version/master/vercion")
  echo "$v1" > /etc/versin_script
  echo "$v1" > /etc/versin_script_new
  }
}
atualiza_fun () {
fun_ip 
SCPinstal="$HOME/install"
verificar_arq () {
case $1 in
"menu"|"message.txt"|"ID")ARQ="${SCPdir}/";; #Menu
"usercodes")ARQ="${SCPusr}/";; #Panel SSRR
"C-SSR.sh"|"proxy.sh"|"wireguard.sh")ARQ="${SCPinst}/";; #Panel SSR
"openssh.sh")ARQ="${SCPinst}/";; #OpenVPN
"squid.sh")ARQ="${SCPinst}/";; #Squid
"dropbear.sh")ARQ="${SCPinst}/";; #Instalacao
"openvpn.sh")ARQ="${SCPinst}/";; #Instalacao
"ssl.sh")ARQ="${SCPinst}/";; #Instalacao
"shadowsocks.sh"|"proxy.sh"|"python.py")ARQ="${SCPinst}/";; #Instalacao
"Shadowsocks-libev.sh"|"slowdns.sh")ARQ="${SCPinst}/";; #Instalacao
"Shadowsocks-R.sh")ARQ="${SCPinst}/";; #Instalacao 
"v2ray.sh")ARQ="${SCPinst}/";; #Instalacao
"budp.sh")ARQ="${SCPinst}/";; #Instalacao
"name")ARQ="${SCPdir}/tmp/";; #Instalacao
"sockspy.sh"|"PDirect.py"|"PPub.py"|"PPriv.py"|"POpen.py"|"PGet.py"|"python.py")ARQ="${SCPinst}/";; #Instalacao
*)ARQ="${SCPfrm}/";; #Herramientas
esac
mv -f ${SCPinstal}/$1 ${ARQ}/$1
chmod +x ${ARQ}/$1
}
error_fun () {
msg -bar2 && msg -verm "ERROR entre VPS<-->GENERADOR (Port 81 TCP)" && msg -bar2
[[ -d ${SCPinstal} ]] && rm -rf ${SCPinstal}
exit 1
}
invalid_key () {
msg -bar2 && msg -verm "  Code Invalido -- #¡Key Invalida#! " && msg -bar2
[[ -e $HOME/lista-arq ]] && rm -r $HOME/lista-arq
exit 1
}
while [[ ! $Key ]]; do
clear
clear
msg -bar
msg -tit
echo -e "\033[1;91m		\e[3;100mACTUALIZACION DEL SCRIPT \e[0m"
msg -bar2 && msg -ne "\033[1;93m          >>> INTRODUZCA LA KEY ABAJO <<<\n   \033[1;37m" && read Key
tput cuu1 && tput dl1
done
msg -ne "    # Verificando Key # : "
cd $HOME
wget -O $HOME/lista-arq $(ofus "$Key")/$IP > /dev/null 2>&1 && echo -e "\033[1;32m Code Correcto de KEY" || {
   echo -e "\033[1;91m Code Incorrecto de KEY"
   invalid_key
   exit
   }
IP=$(ofus "$Key" | 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}') && echo "$IP" > /usr/bin/vendor_code
sleep 0.1s

function_verify
updatedb


if [[ -e $HOME/lista-arq ]] && [[ ! $(cat $HOME/lista-arq|grep "Code de KEY Invalido!") ]]; then
   msg -bar2
   msg -verd "    $(source trans -b es:es "Ficheros Copiados"|sed -e 's/[^a-z -]//ig'): \e[97m[\e[93mSCRIPT MOD @conectedmx_bot\e[97m]"
   REQUEST=$(ofus "$Key"|cut -d'/' -f2)
   [[ ! -d ${SCPinstal} ]] && mkdir ${SCPinstal}
   pontos="." 
   stopping="Configurando Directorios"
   for arqx in $(cat $HOME/lista-arq); do
   msg -verm "${stopping}${pontos}" 
   wget --no-check-certificate -O ${SCPinstal}/${arqx} ${IP}:81/${REQUEST}/${arqx} > /dev/null 2>&1 && verificar_arq "${arqx}" || error_fun
   tput cuu1 && tput dl1
   pontos+="."
   done
userid="${SCPdir}/ID"
if [[ $(cat ${userid}|grep "605531451") = "" ]]; then
			activ=$(cat ${userid})
 		 TOKEN="1235413737:AAEWLffj1FO4GQ5Iwoo4XvIm4ESlFjHA0_A"
			URL="https://api.telegram.org/bot$TOKEN/sendMessage"
			MSG="👇= SCRIPT ACTUALIZADO =👇    
 ◄══════◄••◩••►══════►
 Version: $(cat /etc/versin_script_new) INSTALADO
 Cliente: $(cat ${SCPdir}/tmp/name)
 🆔: $(cat ${userid})
 Slogan: $(cat ${SCPdir}/message.txt)
 ◄══════◄••◩••►══════►
 IP: $(cat ${SCPdir}/MEUIPvps)
 ◄══════◄••◩••►══════►
 KEY:[ $Key ] Usada
 ◄══════◄••◩••►══════►
 ==NOTIFICADOR DE KEY==
 ◄══════◄••◩••►══════►
"
curl -s --max-time 10 -d "chat_id=$activ&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null
curl -s --max-time 10 -d "chat_id=605531451&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null
else
TOKEN="1235413737:AAEWLffj1FO4GQ5Iwoo4XvIm4ESlFjHA0_A"
			URL="https://api.telegram.org/bot$TOKEN/sendMessage"
			MSG="👇= SCRIPT ACTUALIZADO =👇    
◄══════◄••◩••►══════►
 Version: $(cat /etc/versin_script_new) INSTALADO
 Cliente: $(cat ${SCPdir}/tmp/name)
 🆔: $(cat ${userid})
 Slogan: $(cat ${SCPdir}/message.txt)
 ◄══════◄••◩••►══════►
 IP: $(cat ${SCPdir}/MEUIPvps)
 ◄══════◄••◩••►══════►
 KEY:[ $Key ] Usada
 ◄══════◄••◩••►══════►
 ==NOTIFICADOR DE KEY==
 ◄══════◄••◩••►══════►
"
curl -s --max-time 10 -d "chat_id=605531451&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null
fi

	[[ ! -d ${SCPdir}/tmp ]] && mkdir ${SCPdir}/tmp
   wget -O ${SCPdir}/tmp/verifi https://www.dropbox.com/s/tv7yis89au5v8sv/verifi &>/dev/null
   wget -O ${SCPdir}/tmp/monitor https://www.dropbox.com/s/zwqhu7gavru6l9i/monitor &>/dev/null
   wget -O ${SCPdir}/tmp/autodes https://www.dropbox.com/s/fwcor9tbksnyuxy/autodes &>/dev/null
   wget -O /etc/VPS-MX/tmp/style https://www.dropbox.com/s/f33mi30lbxawvku/style &>/dev/null
   chmod 777 ${SCPdir}/*
 #  wget -O /etc/VPS-MX/protocolos/ssl5.sh https://www.dropbox.com/s/aly73lbbh74r7tu/ssl5.sh &>/dev/null
   #chmod 777 /etc/VPS-MX/protocolos/ssl5.sh
   wget -O /etc/VPS-MX/protocolos/chekuser.sh https://www.dropbox.com/s/dypjomdhjhkpahk/chekuser.sh &>/dev/null
   chmod 777 /etc/VPS-MX/protocolos/chekuser.sh
   wget -O /etc/VPS-MX/protocolos/chekuser.py https://www.dropbox.com/s/7he83qd5pfznrvh/chekuser.py &>/dev/null
   chmod 777 /etc/VPS-MX/protocolos/chekuser.py
   msg -bar2
   listaarqs="$(locate "lista-arq"|head -1)" && [[ -e ${listaarqs} ]] && rm $listaarqs   
   cat /etc/bash.bashrc|grep -v '[[ $UID != 0 ]] && TMOUT=15 && export TMOUT' > /etc/bash.bashrc.2
   echo -e '[[ $UID != 0 ]] && TMOUT=15 && export TMOUT' >> /etc/bash.bashrc.2
   mv -f /etc/bash.bashrc.2 /etc/bash.bashrc
   echo "${SCPdir}/menu" > /usr/bin/menu && chmod +x /usr/bin/menu
   echo "${SCPdir}/menu" > /usr/bin/VPSMX && chmod +x /usr/bin/VPSMX
   echo "$Key" > ${SCPdir}/key.txt
   [[ -d ${SCPinstal} ]] && rm -rf ${SCPinstal}
   export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/
	rm -rf /root/lista-arq
	[[ ! -e /etc/autostart ]] && {
	echo '#!/bin/bash
clear
#INICIO AUTOMATICO' >/etc/autostart
	chmod +x /etc/autostart
} || {
	#[[ $(ps x | grep "bot_plus" | grep -v grep | wc -l) != '0' ]] && wget -qO- https://raw.githubusercontent.com/carecagm/main/Install/ShellBot.sh >/etc/SSHPlus/ShellBot.sh
	for proc in $(ps x | grep 'dmS' | grep -v 'grep' | awk {'print $1'}); do
		screen -r -S "$proc" -X quit
	done
	screen -wipe >/dev/null
	echo '#!/bin/bash
clear
#INICIO AUTOMATICO' >/etc/autostart
	chmod +x /etc/autostart
}
crontab -r >/dev/null 2>&1
(
	crontab -l 2>/dev/null
	echo "@reboot /etc/autostart"
	echo "* * * * * /etc/autostart"
) | crontab -
   [[ ${#id} -gt 2 ]] && echo "es" > ${SCPidioma} || echo "es" > ${SCPidioma}
   echo -e "${cor[2]}               ACTUALIZACION COMPLETA "
   echo -e "         COMANDO PRINCIPAL PARA ENTRAR AL PANEL "
   echo -e "  \033[1;37m               sudo menu             \033[0;37m" && msg -bar2
rm -rf $HOME/lista-arq
else
invalid_key
fi
exit 1
}
funcao_idioma () {
tput cuu1 && tput dl1
msg -bar2
declare -A idioma=( [1]="en English" [2]="fr Franch" [3]="de German" [4]="it Italian" [5]="pl Polish" [6]="pt Portuguese" [7]="es Spanish" [8]="tr Turkish" )
for ((i=1; i<=12; i++)); do
valor1="$(echo ${idioma[$i]}|cut -d' ' -f2)"
[[ -z $valor1 ]] && break
valor1="\033[1;32m[$i] > \033[1;33m$valor1"
    while [[ ${#valor1} -lt 37 ]]; do
       valor1=$valor1" "
    done
echo -ne "$valor1"
let i++
valor2="$(echo ${idioma[$i]}|cut -d' ' -f2)"
[[ -z $valor2 ]] && {
   echo -e " "
   break
   }
valor2="\033[1;32m[$i] > \033[1;33m$valor2"
     while [[ ${#valor2} -lt 37 ]]; do
        valor2=$valor2" "
     done
echo -ne "$valor2"
let i++
valor3="$(echo ${idioma[$i]}|cut -d' ' -f2)"
[[ -z $valor3 ]] && {
   echo -e " "
   break
   }
valor3="\033[1;32m[$i] > \033[1;33m$valor3"
     while [[ ${#valor3} -lt 37 ]]; do
        valor3=$valor3" "
     done
echo -e "$valor3"
done
msg -bar2
unset selection
while [[ ${selection} != @([1-8]) ]]; do
echo -ne "\033[1;37m$(fun_trans "  ► Selecione una Opcion"): " && read selection
tput cuu1 && tput dl1
done
[[ -e /etc/VPS-MX/texto-mx ]] && rm /etc/VPS-MX/texto-mx
echo "$(echo ${idioma[$selection]}|cut -d' ' -f1)" > ${SCPidioma}
}


 menu_info () {
meu_ip &>/dev/null
#export -f fun_ip
if [[ "$(grep -c "Ubuntu" /etc/issue.net)" = "1" ]]; then
system=$(cut -d' ' -f1 /etc/issue.net)
system+=$(echo ' ')
system+=$(cut -d' ' -f2 /etc/issue.net |awk -F "." '{print $1}')
elif [[ "$(grep -c "Debian" /etc/issue.net)" = "1" ]]; then
system=$(cut -d' ' -f1 /etc/issue.net)
system+=$(echo ' ')
system+=$(cut -d' ' -f3 /etc/issue.net)
else
system=$(cut -d' ' -f1 /etc/issue.net)
fi

#_ram=$(printf '%-10s' "$(free -h | grep -i mem | awk {'print $2'})")
_usor=$(printf '%-8s' "$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')")
_ram=$(printf ' %-8s' "$(free -h | grep -i mem | awk {'print $2'})")
_ram2=$(printf ' %-8s' "$(free -h | grep -i mem | awk {'print $4'})")
_system=$(printf '%-9s' "$system")
#_usop=$(printf '%-1s' "$(top -bn1 | awk '/Cpu/ { cpu = "" 100 - $8 "%" }; END { print cpu }')")
#_core=$(printf '%-8s' "$(grep -c cpu[0-9] /proc/stat)")
_core=$(printf '%-8s' "$(grep -c cpu[0-9] /proc/stat)")
_usop=$(top -bn1 | sed -rn '3s/[^0-9]* ([0-9\.]+) .*/\1/p;4s/.*, ([0-9]+) .*/\1/p' | tr '\n' ' ')

modelo1=$(printf '%-11s' "$(lscpu | grep Arch | sed 's/\s\+/,/g' | cut -d , -f2)")
mb=$(printf '%-8s' "$(free -h | grep Mem | sed 's/\s\+/,/g' | cut -d , -f6)")
_hora=$(printf '%(%H:%M:%S)T')
_hoje=$(date +'%d/%m/%Y')

echo -e "\033[1;37m OS \033[1;31m: \033[1;32m$_system \033[1;37mHORA\033[1;31m: \033[1;32m$_hora  \033[1;37mIP\033[1;31m:\033[1;32m $(meu_ip)"
echo -e "\033[1;37m RAM\e[31m: \033[1;32m$_ram \033[1;37mUSADO\033[1;31m: \033[1;32m$mb\033[1;37m LIBRE\033[1;31m: \033[1;32m$_ram2"

}


ofus () {
unset txtofus
number=$(expr length $1)
for((i=1; i<$number+1; i++)); do
txt[$i]=$(echo "$1" | cut -b $i)
case ${txt[$i]} in
".")txt[$i]="C";;
"C")txt[$i]=".";;
"3")txt[$i]="@";;
"@")txt[$i]="3";;
"5")txt[$i]="9";;
"9")txt[$i]="5";;
"6")txt[$i]="D";;
"D")txt[$i]="6";;
"J")txt[$i]="Z";;
"Z")txt[$i]="J";;
esac
txtofus+="${txt[$i]}"
done
echo "$txtofus" | rev
}
SPR &
limpar_caches () {
(
VE="\033[1;33m" && MA="\033[1;31m" && DE="\033[1;32m"
while [[ ! -e /tmp/abc ]]; do
A+="#"
echo -e "${VE}[${MA}${A}${VE}]" >&2
sleep 0.3s
tput cuu1 && tput dl1
done
echo -e "${VE}[${MA}${A}${VE}] - ${DE}[100%]" >&2
rm /tmp/abc
) &
echo 3 > /proc/sys/vm/drop_caches &>/dev/null
sleep 1s
sysctl -w vm.drop_caches=3 &>/dev/null
apt-get autoclean -y &>/dev/null
sleep 1s
apt-get clean -y &>/dev/null
rm /tmp/* &>/dev/null
touch /tmp/abc
sleep 0.5s
msg -bar
msg -ama "$(fun_trans "PROCESO CONCLUIDO")"
msg -bar
}
                                																								[[ ! -d /usr/local/libreria ]] && exit
fun_autorun () {
if [[ -e /etc/bash.bashrc-bakup ]]; then
mv -f /etc/bash.bashrc-bakup /etc/bash.bashrc
cat /etc/bash.bashrc | grep -v "/etc/VPS-MX/menu" > /tmp/bash
mv -f /tmp/bash /etc/bash.bashrc
msg -ama "$(fun_trans "REMOVIDO CON EXITO")"
msg -bar
elif [[ -e /etc/bash.bashrc ]]; then
cat /etc/bash.bashrc|grep -v /bin/menu > /etc/bash.bashrc.2
echo '/etc/VPS-MX/menu' >> /etc/bash.bashrc.2
cp /etc/bash.bashrc /etc/bash.bashrc-bakup
mv -f /etc/bash.bashrc.2 /etc/bash.bashrc
msg -ama "$(fun_trans "AUTO INICIALIZAR AGREGADO")"
msg -bar
fi
}
fun_bar () {
comando="$1"
 _=$(
$comando > /dev/null 2>&1
) & > /dev/null
pid=$!
while [[ -d /proc/$pid ]]; do
echo -ne " \033[1;33m["
   for((i=0; i<10; i++)); do
   echo -ne "\033[1;31m##"
   sleep 0.2
   done
echo -ne "\033[1;33m]"
sleep 1s
echo
tput cuu1
tput dl1
done
echo -e " \033[1;33m[\033[1;31m####################\033[1;33m] - \033[1;32m100%\033[0m"
sleep 1s
}

meu_ip () {
if [[ -e /etc/VPS-MX/MEUIPvps ]]; then
echo "$(cat /etc/VPS-MX/MEUIPvps)"
else
MEU_IP=$(wget -qO- ifconfig.me)
echo "$MEU_IP" > /etc/VPS-MX/MEUIPvps
fi
}
fun_ip () {
if [[ -e /etc/VPS-MX/MEUIPvps ]]; then
IP="$(cat /etc/VPS-MX/MEUIPvps)"
else
MEU_IP=$(wget -qO- ifconfig.me)
echo "$MEU_IP" > /etc/VPS-MX/MEUIPvps
fi
}

fun_eth () {
eth=$(ifconfig | grep -v inet6 | grep -v lo | grep -v 127.0.0.1 | grep "encap:Ethernet" | awk '{print $1}')
    [[ $eth != "" ]] && {
    msg -bar
    msg -ama " $(fun_trans "Aplicar el sistema para mejorar los paquetes SSH?")"
    msg -ama " $(fun_trans "Opciones para usuarios avanzados")"
    msg -bar
    read -p " [S/N]: " -e -i n sshsn
           [[ "$sshsn" = @(s|S|y|Y) ]] && {
           echo -e "${cor[1]} $(fun_trans "Correccion de problemas de paquetes en SSH ...")"
           echo -e " $(fun_trans "¿Cual es la tasa RX?")"
           echo -ne "[ 1 - 999999999 ]: "; read rx
           [[ "$rx" = "" ]] && rx="999999999"
           echo -e " $(fun_trans "¿Cual es la tasa TX?")"
           echo -ne "[ 1 - 999999999 ]: "; read tx
           [[ "$tx" = "" ]] && tx="999999999"
           apt-get install ethtool -y > /dev/null 2>&1
           ethtool -G $eth rx $rx tx $tx > /dev/null 2>&1
           }
     msg -bar
     }
}
os_system () {
system=$(echo $(cat -n /etc/issue |grep 1 |cut -d' ' -f6,7,8 |sed 's/1//' |sed 's/      //'))
echo $system|awk '{print $1, $2}'
}
lacasita(){
unset puertos
	declare -A port
	local portasVAR=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
	#local portasVAR=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN" | grep -v 'systemd-resolve')
	local NOREPEAT
	local reQ
	local Port
	while read port; do
		reQ=$(echo ${port}|awk '{print $1}')
		Port=$(echo ${port} | awk '{print $9}' | awk -F ":" '{print $2}')
		[[ $(echo -e $NOREPEAT|grep -w "$Port") ]] && continue
		NOREPEAT+="$Port\n"
		case ${reQ} in
			squid|squid3)
			[[ -z ${port[SQD]} ]] && local port[SQD]="\033[1;31m SQUID: \033[1;32m"
			port[SQD]+="$Port ";;
			systemd-r|systemd-re|systemd-resolv)
			[[ -z ${port[md]} ]] && local port[md]="\033[1;31m SYSTEMD: \033[1;32m"
			port[md]+="$Port ";;
			apache|apache2)
			[[ -z ${port[APC]} ]] && local port[APC]="\033[1;31m APACHE: \033[1;32m"
			port[APC]+="$Port ";;
			nginx)
			[[ -z ${port[NG]} ]] && local port[NG]="\033[1;31m NGINX: \033[1;32m"
			port[NG]+="$Port ";;
			ssh|sshd)
			[[ -z ${port[SSH]} ]] && local port[SSH]="\033[1;31m SSH: \033[1;32m"
			port[SSH]+="$Port ";;
			dropbear)
			[[ -z ${port[DPB]} ]] && local port[DPB]="\033[1;31m DROPBEAR: \033[1;32m"
			port[DPB]+="$Port ";;
			ssserver|ss-server)
			[[ -z ${port[SSV]} ]] && local port[SSV]="\033[1;31m SHADOWSOCKS: \033[1;32m"
			port[SSV]+="$Port ";;
			obfs-serv)
			[[ -z ${port[OB]} ]] && local port[OB]="\033[1;31m OBFS: \033[1;32m"
			port[OB]+="$Port ";;
			trojan-go)
			[[ -z ${port[GO]} ]] && local port[GO]="\033[1;31m TROJAN GO: \033[1;32m"
			port[GO]+="$Port ";;
			trojan)
			[[ -z ${port[tro]} ]] && local port[tro]="\033[1;31m TROJAN: \033[1;32m"
			port[tro]+="$Port ";;
			openvpn)
			[[ -z ${port[OVPN]} ]] && local port[OVPN]="\033[1;31m OPENVPN-TCP: \033[1;32m"
			port[OVPN]+="$Port ";;
			stunnel4|stunnel)
			[[ -z ${port[SSL]} ]] && local port[SSL]="\033[1;31m SSL: \033[1;32m"
			port[SSL]+="$Port ";;
			stunnel5)
			[[ -z ${port[SSL5]} ]] && local port[SSL5]="\033[1;31m STUNNEL5: \033[1;32m"
			port[SSL5]+="$Port ";;
			python|python3)
			[[ -z ${port[PY3]} ]] && local port[PY3]="\033[1;31m PYTHON: \033[1;32m"
			port[PY3]+="$Port ";;
			node)
			[[ -z ${port[WS]} ]] && local port[WS]="\033[1;31m WEBSOCKET: \033[1;32m"
			port[WS]+="$Port ";;
			v2ray)
			[[ -z ${port[V2R]} ]] && local port[V2R]="\033[1;31m V2RAY: \033[1;32m"
			port[V2R]+="$Port ";;
			badvpn-ud)
			[[ -z ${port[BAD]} ]] && local port[BAD]="\033[1;31m BADVPN: \033[1;32m"
			port[BAD]+="$Port ";;
			
		esac
	done <<< "${portasVAR}"

	#UDP
	local portasVAR=$(lsof -V -i udp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND")
	local NOREPEAT
	local reQ
	local Port
	while read port; do
		reQ=$(echo ${port}|awk '{print $1}')
		Port=$(echo ${port} | awk '{print $9}' | awk -F ":" '{print $2}')
		[[ $(echo -e $NOREPEAT|grep -w "$Port") ]] && continue
		NOREPEAT+="$Port\n"
		case ${reQ} in
			openvpn)
			[[ -z ${port[OVPN]} ]] && local port[OVPN]="\033[1;31m OPENVPN-UDP: \033[1;32m"
			port[OVPN]+="$Port ";;
			dns-serve)
			[[ -z ${port[SLOW]} ]] && local port[SLOW]="\033[1;31m SlowDNS: \033[1;32m"
			port[SLOW]+="$Port ";;
			#stunnel5)
			#[[ -z ${port[SSL]} ]] && local port[SSL]="\033[1;31m SSL: \033[1;32m"
			#port[SSL]+="$Port ";;
		esac
	done <<< "${portasVAR}"
[[ $(dpkg --get-selections|grep -w 'wireguard'|head -1) ]] && {
		if [[ ! $(wg|grep -w 'interface') = "" ]]; then
			wg=$(wg|grep -w 'port'|awk -F ' ' '{print $3}')
			port[wg]="\033[1;31m WIREGUARD:\033[1;32m $wg"
		fi
	}
	k=1

	for line in "${port[@]}"; do
		[[ -z "$line" ]] && continue
		let RESTO=k%2

		if [[ $RESTO -eq 0 ]]; then
			puertos+="$line\n"
		else
			puertos+="$line-"
		fi
		let k++

	done

	echo -e "$puertos"|column -t -s '-'
	}
	
remove_script () {
clear
clear 
#msg -bar
msg -tit
msg -ama "          ¿ DESEA DESINSTALAR SCRIPT ?"
msg -bar
echo -e " Esto borrara todos los archivos del scrip VPS_MX"
msg -bar
while [[ ${yesno} != @(s|S|y|Y|n|N) ]]; do
read -p " [S/N]: " yesno
tput cuu1 && tput dl1
done
if [[ ${yesno} = @(s|S|y|Y) ]]; then
rm -rf ${SCPdir} &>/dev/null
rm -rf ${SCPusr} &>/dev/null
rm -rf ${SCPinst} &>/dev/null
[[ ! -d /usr/local/lib/ubuntn ]] && rm -rf /usr/local/lib/ubuntn
[[ ! -d /usr/share/mediaptre/local/log ]] && rm -rf /usr/share/mediaptre/local/log
[[ ! -d /usr/local/protec ]] && rm -rf /usr/local/protec
[[ -e /bin/VPSMX ]] && rm /bin/VPSMX
[[ -e /usr/bin/VPSMX ]] && rm /usr/bin/VPSMX
[[ -e /bin/menu ]] && rm /bin/menu
[[ -e /usr/bin/menu ]] && rm /usr/bin/menu
cd $HOME
fi
sudo apt-get --purge remove squid -y > /dev/null 2>&1
sudo apt-get --purge remove stunnel4 -y > /dev/null 2>&1
sudo apt-get --purge remove dropbear -y > /dev/null 2>&1
sudo apt-get autoremove -y &>/dev/null
}
horas(){
#code by rufu99
msg -bar
echo -e "	\e[41mACTUALIZAR HORA LOCAL\e[0m"
msg -bar
	n=1
    for i in $(ls /usr/share/zoneinfo/America); do
        loc=$(echo $i|awk -F ":" '{print $1}')
        zona=$(printf '%-12s' "$loc")
        echo -e " \e[37m [$n] \e[31m> \e[32m$zona"
        r[$n]=$zona
        selec="$n"
        let n++ 
    done
   msg -bar
    opci=$(selection_fun $selec)
  rm -rf /etc/localtime > /dev/null 2>&1
  echo "America/${r[$opci]}" > /etc/timezone
ln -fs /usr/share/zoneinfo/America/${r[$opci]} /etc/localtime > /dev/null 2>&1
dpkg-reconfigure --frontend noninteractive tzdata > /dev/null 2>&1 && echo -e "\033[1;32m [HORA ACTUALIZADA]" || echo -e "\033[1;31m [HORA NO ACTUALIZADO]"
#fin
#
}
onlineapp(){
msg -bar
echo -e "\033[1;92m                ACTIVANDO SERVICIO"
msg -bar
wget -O /etc/VPS-MX/herramientas/.onapp https://www.dropbox.com/s/z0xb6pbe1uagdjt/onapp &>/dev/null
chmod 777 /etc/VPS-MX/herramientas/.onapp &>/dev/null
   apt install apache2 -y > /dev/null 2>&1
   sed -i "s/Listen 81/Listen 8888/g" /etc/apache2/ports.conf >/dev/null 2>&1
   service apache2 restart
   rm -rf /var/www/html/server >/dev/null 2>&1
   mkdir /var/www/html/server >/dev/null 2>&1
echo -e "[Unit]
Description=.onapp Service by @lacasitamx
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/bin/bash /etc/VPS-MX/herramientas/.onapp
Restart=always
RestartSec=3s

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/app.service

    systemctl enable app &>/dev/null
    systemctl start app &>/dev/null
    IP=$(wget -qO- ipv4.icanhazip.com) >/dev/null 2>&1
msg -bar
echo -e "\033[1;92m                APP ONLINE INICIADO CON EXITO"
msg -bar
echo -e "\033[1;37m URL de usuarios en línea para usar en la aplicación‌‌\033[0m"
   echo -e "\e[1;92m http://$IP:8888/server/online"
   msg -bar
}
killapp(){
	systemctl stop app &>/dev/null
    systemctl disable app  &>/dev/null
    rm /etc/systemd/system/app.service &>/dev/null
    rm -rf /var/www/html/server >/dev/null 2>&1
    sed -i "s/Listen 8888/Listen 81/g" /etc/apache2/ports.conf >/dev/null 2>&1
   service apache2 restart
    msg -bar
    echo -e "\033[1;91m                APP ONLINE DETENIDO"
msg -bar

}
menuapp(){
clear
msg -tit
msg -azu "	\e[91m\e[43mACTIVAR APP EN LINEA\e[0m"
msg -bar
echo -e " \e[1;93m [\e[92m1\e[93m] $(msg -verm2 "➛ ")$(msg -verd "  INICIAR APP ONLINE  ")"
echo -e " \e[1;93m [\e[92m2\e[93m] $(msg -verm2 "➛ ")$(msg -verm2 " DETENER APP ONLINE   ")"
echo -e " \e[1;93m [\e[92m0\e[93m] $(msg -verm2 "➛ ")$(msg -bra "  VOLVER   ")"
msg -bar
echo -ne " ►\e[1;37m Selecione Una Opcion: \e[33m " && read select
case $select in
0)menu3 ;;
1) onlineapp && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
2)killapp && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
esac
}

systen_info () {
clear
clear
#msg -bar
msg -tit
msg -ama "$(fun_trans "                DETALLES DEL SISTEMA")"
null="\033[1;31m"
msg -bar
if [ ! /proc/cpuinfo ]; then msg -verm "$(fun_trans "Sistema No Soportado")" && msg -bar; return 1; fi
if [ ! /etc/issue.net ]; then msg -verm "$(fun_trans "Sistema No Soportado")" && msg -bar; return 1; fi
if [ ! /proc/meminfo ]; then msg -verm "$(fun_trans "Sistema No Soportado")" && msg -bar; return 1; fi
totalram=$(free | grep Mem | awk '{print $2}')
usedram=$(free | grep Mem | awk '{print $3}')
freeram=$(free | grep Mem | awk '{print $4}')
swapram=$(cat /proc/meminfo | grep SwapTotal | awk '{print $2}')
system=$(cat /etc/issue.net)
clock=$(lscpu | grep "CPU MHz" | awk '{print $3}')
based=$(cat /etc/*release | grep ID_LIKE | awk -F "=" '{print $2}')
processor=$(cat /proc/cpuinfo | grep "model name" | uniq | awk -F ":" '{print $2}')
cpus=$(cat /proc/cpuinfo | grep processor | wc -l)
[[ "$system" ]] && msg -ama "$(fun_trans "Sistema"): ${null}$system" || msg -ama "$(fun_trans "Sistema"): ${null}???"
[[ "$based" ]] && msg -ama "$(fun_trans "Base"): ${null}$based" || msg -ama "$(fun_trans "Base"): ${null}???"
[[ "$processor" ]] && msg -ama "$(fun_trans "Procesador"): ${null}$processor x$cpus" || msg -ama "$(fun_trans "Procesador"): ${null}???"
[[ "$clock" ]] && msg -ama "$(fun_trans "Frecuencia de Operacion"): ${null}$clock MHz" || msg -ama "$(fun_trans "Frecuencia de Operacion"): ${null}???"
msg -ama "$(fun_trans "Uso del Procesador"): ${null}$(ps aux  | awk 'BEGIN { sum = 0 }  { sum += sprintf("%f",$3) }; END { printf " " "%.2f" "%%", sum}')"
msg -ama "$(fun_trans "Memoria Virtual Total"): ${null}$(($totalram / 1024))"
msg -ama "$(fun_trans "Memoria Virtual En Uso"): ${null}$(($usedram / 1024))"
msg -ama "$(fun_trans "Memoria Virtual Libre"): ${null}$(($freeram / 1024))"
msg -ama "$(fun_trans "Memoria Virtual Swap"): ${null}$(($swapram / 1024))MB"
msg -ama "$(fun_trans "Tempo Online"): ${null}$(uptime)"
msg -ama "$(fun_trans "Nombre De La Maquina"): ${null}$(hostname)"
msg -ama "$(fun_trans "IP De La  Maquina"): ${null}$(ip addr | grep inet | grep -v inet6 | grep -v "host lo" | awk '{print $2}' | awk -F "/" '{print $1}')"
msg -ama "$(fun_trans "Version de Kernel"): ${null}$(uname -r)"
msg -ama "$(fun_trans "Arquitectura"): ${null}$(uname -m)"
msg -bar
return 0
}
	[[ "$(crontab -l| grep 'autolim' | wc -l)" != '0' ]] &>/dev/null && {
  autram="\e[1;32m[ON]"
  } || {
  autram="\e[1;31m[OFF]"
  }
  
menu3(){
declare -A inst
pidr_inst
clear
valuest=$(ps ax |grep /etc/shadowsocks-r|grep -v grep)
[[ $valuest != "" ]] && valuest="\033[1;32m[ON] " || valuest="\033[1;31m[OFF]"
pidproxy=$(ps x | grep -w  "lacasitamx.py" | grep -v "grep" | awk -F "pts" '{print $1}') && [[ ! -z $pidproxy ]] && plox="\e[1;32m[ON] " || plox="\e[1;31m[OFF]"
Bot=$(ps x|grep -v grep |grep "ADMbot.sh")
[[ ! $Bot ]] && AD="\033[1;31m[OFF]" || AD="\033[1;32m[ON] "
#[[ $(ps x | grep stunnel5 | grep -v grep | awk '{print $1}') ]] && stunel5="\e[1;32m[ON]" || stunel5="\e[1;31m[OFF]"
#msg -bar
msg -tit
export -f fun_eth
export -f fun_bar
#echo -e "\e[1;37mTotal Ram: ${null}$(($totalram / 1024)) \e[1;37mUSO: ${null}$(($usedram / 1024)) \e[1;37mLIBRE: ${null}$(($freeram / 1024)) \e[37mSwap:${null}$(($swapram / 1024))MB"
export -f lacasita
lacasita
	msg -bar
echo -e "  	\e[97m\e[1;100mPROTOCOLOS\e[0m  		  \e[97m\e[41mHERRAMIENTAS\e[0m"
msg -bar
 if [[ ! -e /etc/noty ]]; then
 noty="\e[1;91m[OFF]"
 else
 noty="\e[1;92m[ON] "
 fi
 onap=$(ps x|grep -v grep |grep ".onapp")
[[ ! $onap ]] && app="\033[1;31m[OFF]" || app="\033[1;32m[ON] "
 if [[ $(systemctl is-active chekuser) = "active" ]]; then
 chek="\e[1;92m[ON] "
 else
 chek="\e[1;91m[OFF]"
 fi
#menu de protocolos
echo -e "\e[1;93m[\e[92m1\e[93m]$(msg -verm2 "➛ ")$(msg -azu "BADVPN        ${inst[badvpn]}")  \e[1;93m[\e[92m15\e[93m]$(msg -verm2 "➛ ")$(msg -azu "ARCHIVO ONLINE")"
echo -e "\e[1;93m[\e[92m2\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SOCKS LIBEV   ${inst[ss-server]}")  \e[1;93m[\e[92m16\e[93m]$(msg -verm2 "➛ ")$(msg -azu "FIREWALL")"
echo -e "\e[1;93m[\e[92m3\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SOCKS PYTHON  ${inst[python]}")  \e[1;93m[\e[92m17\e[93m]$(msg -verm2 "➛ ")$(msg -azu "FAIL2BAN PROTECION")"
echo -e "\e[1;93m[\e[92m4\e[93m]$(msg -verm2 "➛ ")$(msg -azu "V2RAY         ${inst[v2ray]}")  \e[1;93m[\e[92m18\e[93m]$(msg -verm2 "➛ ")$(msg -azu "DETALLES DE SISTEMA")"
echo -e "\e[1;93m[\e[92m5\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SSL           ${inst[stunnel4]}")  \e[1;93m[\e[92m19\e[93m]$(msg -verm2 "➛ ")$(msg -azu "TCP (BBR|BBR-Plus)")"
echo -e "\e[1;93m[\e[92m6\e[93m]$(msg -verm2 "➛ ")$(msg -azu "DROPBEAR      ${inst[dropbear]}")  \e[1;93m[\e[92m20\e[93m]$(msg -verm2 "➛ ")$(msg -azu "DNS NETFLIX")"
echo -e "\e[1;93m[\e[92m7\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SQUID         ${inst[squid]}")  \e[1;93m[\e[92m21\e[93m]$(msg -verm2 "➛ ")$(msg -azu "AUTO MANTENIMIENTO")$autram"
echo -e "\e[1;93m[\e[92m8\e[93m]$(msg -verm2 "➛ ")$(msg -azu "OPENVPN       ${inst[openvpn]}")  \e[1;93m[\e[92m22\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SCANNER SUBDOMINIO")"
echo -e "\e[1;93m[\e[92m9\e[93m]$(msg -verm2 "➛ ")$(msg -azu "SLOWDNS       ${inst[dns-serve]}")  \e[1;93m[\e[92m23\e[93m]$(msg -verm2 "➛ ")$(msg -azu "PRUEBA DE VELOCIDAD")"
echo -e "\e[1;93m[\e[92m10\e[93m]$(msg -verm2 "➛ ")$(msg -azu "MONITOR APP  $app")  \e[1;93m[\e[92m24\e[93m]$(msg -verm2 "➛ ")$(msg -azu "FIX ORACLE/AWS/AZR")"
echo -e "\e[1;93m[\e[92m11\e[93m]$(msg -verm2 "➛ ")$(msg -azu "BOT TELEGRAM $AD")  \e[1;93m[\e[92m25\e[93m]$(msg -verm2 "➛ ")$(msg -azu "\e[91m\e[43mHERRAMIENTAS BASICOS\e[0m")"
echo -e "\e[1;93m[\e[92m12\e[93m]$(msg -verm2 "➛ ")$(msg -azu "WIREGUARD    ${inst[wg]}")  $(msg -verd "[0] ")$(msg -verm2 "➛ ")$(msg -azu "⇚ VOLVER  ")" 
echo -e "\e[1;93m[\e[92m13\e[93m]$(msg -verm2 "➛ ")$(msg -azu "NOTI-BOT     $noty")"
echo -e "\e[1;93m[\e[92m14\e[93m]$(msg -verm2 "➛ ")$(msg -azu "CHECK-USER   $chek")"
msg -bar
echo -ne " ►\e[1;37m Selecione Una Opcion: \e[33m " && read select
case $select in
0) ;;
1) ${SCPinst}/budp.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
2) ${SCPinst}/shadowsocks.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
3) ${SCPinst}/sockspy.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
4) ${SCPinst}/v2ray.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
5) ${SCPinst}/ssl.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
6) ${SCPinst}/dropbear.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
7) ${SCPinst}/squid.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
8) ${SCPinst}/openvpn.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
9) ${SCPinst}/slowdns.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
#
#herramientas
10) menuapp && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
11) adminbot;;
12) ${SCPinst}/wireguard.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
13) noti ;;
14) ${SCPinst}/chekuser.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
15) ${SCPfrm}/apacheon.sh;;
16) ${SCPfrm}/blockBT.sh;;
17) ${SCPfrm}/fai2ban.sh;;
18) systen_info;;
19) ${SCPfrm}/tcp.sh;;
20) net;;
21) cache;;
22) ${SCPfrm}/ultrahost;;
23) ${SCPfrm}/speed.py;;
24)oracl ;;
25) extra ;;
#25)${SCPinst}/trojango.sh && msg -ne "Enter Para Continuar" && read enter
#menu3 ;;
*) msg -verm2 " Por Favor Selecione El Número Correcto"
sleep 1.s
menu3 ;;
esac
}
NOTIFY () {
clear
clear
msg -tit

msg -ama " Notify-BOT (Notificacion Remota)|@LaCasitaMx_Noty_Bot "
msg -bar
echo -e "\033[1;94m Notify-BOT es un simple notificador de:"
echo -e "\033[1;94m >> Usuario Expirado"
echo -e "\033[1;94m >> Usuario Eliminado"
echo -e "\033[1;94m >> Avisos de VPS Reiniciada"
echo -e "\033[1;94m >> Avisos de Monitor de Protocolos"
echo -e "\033[1;97m Inicie El BOT de Telegram"
echo -e "\033[1;92m ¡¡ Para sacar su ID entre al BOT @conectedmx_bot"
echo -e "\033[1;92m Aparesera algo parecido 👤 → Tu ID es: 45145564   "
msg -bar
echo -e "\033[1;93mIgrese un nombre para la VPS:\033[0;37m"; read -p " " nombr
echo "${nombr}" > /etc/VPS-MX/controlador/nombre.log
echo -e "\033[1;93mIgrese su ID 👤:\033[0;37m"; read -p " " idbot
echo "${idbot}" > /etc/VPS-MX/controlador/IDT.log 
msg -bar
echo -e "\033[1;32m              ID AGREGADO CON EXITO"
msg -bar
wget -qO- ifconfig.me > /etc/VPS-MX/IP.log
ipt=`less /etc/VPS-MX/IP.log` > /dev/null 2>&1
Nip="$(echo $ipt)"
NOM="$(less /etc/VPS-MX/controlador/nombre.log)"
NOM1="$(echo $NOM)"
IDB1=`less /etc/VPS-MX/controlador/IDT.log` > /dev/null 2>&1
IDB2=`echo $IDB1` > /dev/null 2>&1
KEY="2012880601:AAEJ3Kk18PGDzW57LpTMnVMn_pQYQKW3V9w"
URL="https://api.telegram.org/bot$KEY/sendMessage"
MSG="⚠️ ►► AVISO DE VPS: $NOM1 ⚠
👉 ►► IP: $Nip
👉 ►► Usuario: $(cat /etc/VPS-MX/message.txt)
👉 ►► MENSAJE DE PRUEBA
🔰 ►► NOTI-BOT ACTIVADO CORRECTAMENTE"
curl -s --max-time 10 -d "chat_id=$IDB2&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null
echo -e "\033[1;34m            SE ENVIO MENSAJE DE PRUEBA "
touch /etc/noty
}

noti(){
clear
msg -tit
echo -e "	\e[97m\e[1;100mACTIVADOR NOTI-BOT\e[0m"
msg -bar
echo -e "\e[1;93m[\e[92m1\e[93m]$(msg -verm2 "➛ ")$(msg -azu "ACTIVAR NOTI-BOT $nt")  \e[1;93m[\e[92m2\e[93m]$(msg -verm2 "➛ ")$(msg -azu "DESACTIVAR NOTI-BOT")"
msg -bar
echo -e "	     	\e[1;93m[\e[92m0\e[93m]$(msg -verm2 "➛ ")$(msg -azu "VOLVER")"
msg -bar
echo -ne " ►\e[1;37m Selecione Una Opcion: \e[33m " && read selectos
case $selectos in
0)menu3 ;;
1) NOTIFY && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
2)
echo " "> /etc/VPS-MX/controlador/IDT.log &>/dev/null
rm /etc/noty &>/dev/null
msg -verm2 "	NOTI-BOT DESACTIVADO"
;;
esac
}

adminbot(){
clear
#msg -bar
#msg -tit
echo ""
echo -e "\e[1;90m╔─━━━━━━━━━━━━━━░★░━━━━━━━━━━━━━━─╗                \e[0m"
msg -ama " ░ ADMINISTRADOR BOT | TELEGRAM  ░                   \033[1;31m"
echo -e "\e[1;90m╚─━━━━━━━━━━━━━━░★░━━━━━━━━━━━━━━─╝                \e[0m"
activar(){
msg -bar
echo -ne "\033[1;96m #Digite el Token del BOT\033[0;92m\nTOKEN: \033[0;97m" && read TOKEN
msg -bar
echo -ne "\033[1;96m #Digite un nombre para su Usuario\033[0;92m \nUSUARIO: \033[0;97m" && read USERLIB
msg -bar
echo -ne "\033[1;96m #Digite una contraseña para su Usuario\033[0;92m \nCONTRASEÑA: \033[0;97m" && read PASSLIB
#msg -bar
echo -e "[Unit]
Description=ADMbot.sh Service by @lacasitamx
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/bin/bash /etc/VPS-MX/herramientas/ADMbot.sh id "$TOKEN" "$USERLIB" "$PASSLIB"
Restart=always
RestartSec=3s

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/Botca.service

    systemctl enable Botca &>/dev/null
    systemctl start Botca &>/dev/null
msg -bar
echo -e "\033[1;92m                BOT INICIADO CON EXITO"
echo -e "\033[1;97m MODO DE INICIO DEL BOT: /ADMIN $USERLIB $PASSLIB"
msg -bar
}

killbot(){
	systemctl stop Botca &>/dev/null
    systemctl disable Botca  &>/dev/null
    rm /etc/systemd/system/Botca.service &>/dev/null
    msg -bar
    echo -e "\033[1;91m                BOT DETENIDO"
msg -bar

}
echo -e " \e[1;93m[\e[92m1\e[93m] $(msg -verm2 "➛ ")$(msg -verd "  INICIAR BOT MANAGER   ")"
echo -e " \e[1;93m[\e[92m2\e[93m] $(msg -verm2 "➛ ")$(msg -verm2 " DETENER BOT MANAGER   ")"
echo -e " \e[1;93m[\e[92m0\e[93m] $(msg -verm2 "➛ ")$(msg -bra "  VOLVER   ")"
msg -bar
echo -ne " ►\e[1;37m Selecione Una Opcion: \e[33m " && read select
case $select in
0)menu3 ;;
1)activar && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
2)killbot && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
esac
}

extra(){
clear
clear
#msg -bar
msg -tit
on="\033[1;32m[ON]" && off="\033[1;31m[OFF]"
[[ `grep -c "^#ADM" /etc/sysctl.conf` -eq 0 ]] && tcp=$off || tcp=$on
if [ -e /etc/squid/squid.conf ]; then
[[ `grep -c "^#CACHE_DO_SQUID" /etc/squid/squid.conf` -gt 0 ]] && squi=$off || squi=$on
elif [ -e /etc/squid3/squid.conf ]; then
[[ `grep -c "^#CACHE_DO_SQUID" /etc/squid3/squid.conf` -gt 0 ]] && squi=$off || squi=$on
fi
echo -e "		\e[91m\e[43mHERRAMIENTAS BASICOS\e[0m"
msg -bar
echo -e " \e[1;93m[\e[92m1\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "ACTUALIZAR HORA LOCAL")"
echo -e " \e[1;93m[\e[92m2\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "HTOP")"
echo -e " \e[1;93m[\e[92m3\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "MODIFICAR PUERTOS ACTIVOS")"
echo -e " \e[1;93m[\e[92m4\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "PAYLOAD FUERZA BRUTA")"
echo -e " \e[1;93m[\e[92m5\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "TCP SPEED") $tcp"
echo -e " \e[1;93m[\e[92m6\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "CACHÉ PARA SQUID") $squi"
echo -e " \e[1;93m[\e[92m7\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "LIMPIAR PAQUETES OBSOLETOS")"
echo -e " \e[1;93m[\e[92m8\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "RESET IPTABLES")"
echo -e " \e[1;93m[\e[92m9\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "REINICIAR VPS")"
echo -e " \e[1;93m[\e[92m10\e[93m]$(msg -verm2 "➛ ")$(msg -azu "CAMBIAR HOSTNAME VPS")"
echo -e " \e[1;93m[\e[92m11\e[93m]$(msg -verm2 "➛ ")$(msg -azu "CAMBIAR CONTRASEÑA ROOT")"
echo -e " \e[1;93m[\e[92m12\e[93m]$(msg -verm2 "➛ ")$(msg -azu "AGREGAR ROOT a GoogleCloud y Amazon")"
echo -e " \e[1;93m[\e[92m13\e[93m]$(msg -verm2 "➛ ")$(msg -azu "AUTENTIFICAR SQUID")"
echo -e " \e[1;93m[\e[92m0\e[93m]$(msg -verm2 " ➛ ")$(msg -azu "VOLVER")"
msg -bar
echo -ne " ►\e[1;37m Selecione Una Opcion: \e[33m " && read select
case $select in
0)menu3 ;;
1)horas ;;
2)monhtop ;;
3)${SCPfrm}/ports.sh && msg -ne "Enter Para Continuar" && read enter
menu3 ;;
4)${SCPfrm}/paysnd.sh ;;
5)TCPspeed ;;
6)SquidCACHE ;;
7)packobs ;;
8)resetiptables ;;
9)reiniciar_vps ;;
10)host_name ;;
11)cambiopass ;;
12)rootpass ;;
13)${SCPfrm}/squidpass.sh ;;
*) ;;
esac
}

reiniciar_vps () {
echo -ne " \033[1;31m[ ! ] Sudo Reboot"
sleep 3s
echo -e "\033[1;32m [OK]"
(
sudo reboot
) > /dev/null 2>&1
msg -bar
return
}

host_name () {
unset name
while [[ ${name} = "" ]]; do
echo -ne "\033[1;37m $(fun_trans "Nuevo nombre del host"): " && read name
tput cuu1 && tput dl1
done
hostnamectl set-hostname $name 
if [ $(hostnamectl status | head -1  | awk '{print $3}') = "${name}" ]; then 
echo -e "\033[1;33m $(fun_trans "Host alterado corretamente")!, $(fun_trans "reiniciar VPS")"
else
echo -e "\033[1;33m $(fun_trans "Host no modificado")!"
fi
msg -bar
return
}

cambiopass () {
echo -e "${cor[3]} $(fun_trans "Esta herramienta cambia la contraseña de su servidor vps")"
echo -e "${cor[3]} $(fun_trans "Esta contraseña es utilizada como usuario") root"
msg -bar
echo -ne " $(fun_trans "Desea Seguir?") [S/N]: "; read x
[[ $x = @(n|N) ]] && msg -bar && return
msg -bar
#Inicia Procedimentos
echo -e "${cor[0]} $(fun_trans "Escriba su nueva contraseña")"
msg -bar
read  -p " Nuevo passwd: " pass
(echo $pass; echo $pass)|passwd 2>/dev/null
sleep 1s
msg -bar
echo -e "${cor[3]} $(fun_trans "Contraseña cambiada con exito!")"
echo -e "${cor[2]} $(fun_trans "Su contraseña ahora es"): ${cor[4]}$pass"
msg -bar
return
}
dnsnetflix () {
#by kalix1
echo "nameserver $dns1" >> /etc/resolv.conf
#echo "nameserver $dns2" >> /etc/resolv.conf
/etc/init.d/ssrmu stop &>/dev/null
/etc/init.d/ssrmu start &>/dev/null
/etc/init.d/shadowsocks-r stop &>/dev/null
/etc/init.d/shadowsocks-r start &>/dev/null
msg -bar2
echo -e "${cor[4]}  DNS AGREGADOS CON EXITO"
}
net(){
#by kalix1
clear
#msg -bar2
msg -tit
echo -e "\033[1;93m     AGREGADOR DE DNS PERSONALES"
msg -bar2
echo -e "\033[1;39m Esta funcion ara que puedas ver Netflix con tu VPS"
msg -bar2
#echo -e "\033[1;91m ¡ Solo seran utiles si registraste tu IP en el BOT !"
echo -e "\033[1;39m En APPS como HTTP Inyector,KPN Rev,APKCUSTOM, etc."
echo -e "\033[1;39m Se deveran agregar en la aplicasion a usar estos DNS."
echo -e "\033[1;39m En APPS como SS,SSR,V2RAY no es necesario agregarlos."
msg -bar2
echo -e "\033[1;93m Recuerde escojer entre 1 DNS ya sea el de USA,BR,MX,CL \n segun le aya entregado el BOT."
echo ""
echo -e "\033[1;97m Ingrese su DNS Primario: \033[0;91m"; read -p " Primary Dns: "  dns1
echo -e "\033[1;97m Ingrese su DNS Secundario: \033[0;91m"; read -p " Secondary Dns: "  dns2
echo ""
msg -bar2
read -p " Estas seguro de continuar?  [ s | n ]: " dnsnetflix   
[[ "$dnsnetflix" = "s" || "$dnsnetflix" = "S" ]] && dnsnetflix
msg -bar2
}
rootpass () {
clear
msg -bar
echo -e "${cor[3]}  Esta herramienta cambia a usuario root las VPS de "
echo -e "${cor[3]}             GoogleCloud y Amazon"
msg -bar
echo -ne " Desea Seguir? [S/N]: "; read x
[[ $x = @(n|N) ]] && msg -bar && return
msg -bar
#Inicia Procedimentos
echo -e "                 Aplicando Configuraciones"
fun_bar "service ssh restart"
#Parametros Aplicados
sed -i "s;PermitRootLogin prohibit-password;PermitRootLogin yes;g" /etc/ssh/sshd_config
sed -i "s;PermitRootLogin without-password;PermitRootLogin yes;g" /etc/ssh/sshd_config
sed -i "s;PasswordAuthentication no;PasswordAuthentication yes;g" /etc/ssh/sshd_config
msg -bar
echo -e "Escriba su contraseña root actual o cambiela"
msg -bar
read  -p " Nuevo passwd: " pass
(echo $pass; echo $pass)|passwd 2>/dev/null
sleep 1s
msg -bar
echo -e "${cor[3]} Configuraciones aplicadas con exito!"
echo -e "${cor[2]} Su contraseña ahora es: ${cor[4]}$pass"
service ssh restart > /dev/null 2>&1
msg -bar
return
}

resetiptables () {
echo -e "Reiniciando Ipetables espere"
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
echo -e "iptables reiniciadas con exito"
}
packobs () {
msg -ama "Buscando Paquetes Obsoletos"
dpkg -l | grep -i ^rc
msg -ama "Limpiando Paquetes Obsoloteos"
dpkg -l |grep -i ^rc | cut -d " " -f 3 | xargs dpkg --purge
msg -ama "Limpieza Completa"
}

TCPspeed () {
if [[ `grep -c "^#ADM" /etc/sysctl.conf` -eq 0 ]]; then
#INSTALA
msg -ama "$(fun_trans "TCP Speed No Activado, Desea Activar Ahora")?"
msg -bar
while [[ ${resposta} != @(s|S|n|N|y|Y) ]]; do
read -p " [S/N]: " -e -i s resposta
tput cuu1 && tput dl1
done
[[ "$resposta" = @(s|S|y|Y) ]] && {
echo "#ADM" >> /etc/sysctl.conf
echo "net.ipv4.tcp_window_scaling = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_slow_start_after_idle = 0" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf > /dev/null 2>&1
msg -ama "$(fun_trans "TCP Activo Con Exito")!"
} || msg -ama "$(fun_trans "Cancelado")!"
 else
#REMOVE
msg -ama "$(fun_trans "TCP Speed ya esta activado, desea detener ahora")?"
msg -bar
while [[ ${resposta} != @(s|S|n|N|y|Y) ]]; do
read -p " [S/N]: " -e -i s resposta
tput cuu1 && tput dl1
done
[[ "$resposta" = @(s|S|y|Y) ]] && {
grep -v "^#ADM
net.ipv4.tcp_window_scaling = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 16384 16777216
net.ipv4.tcp_low_latency = 1
net.ipv4.tcp_slow_start_after_idle = 0" /etc/sysctl.conf > /tmp/syscl && mv -f /tmp/syscl /etc/sysctl.conf
sysctl -p /etc/sysctl.conf > /dev/null 2>&1
msg -ama "$(fun_trans "TCP Parado Con Exito")!"
} || msg -ama "$(fun_trans "Cancelado")!"
fi
}
SquidCACHE () {
msg -ama "$(fun_trans "Squid Cache, Aplica cache en Squid")"
msg -ama "$(fun_trans "Mejora la velocidad del squid")"
msg -bar
if [ -e /etc/squid/squid.conf ]; then
squid_var="/etc/squid/squid.conf"
elif [ -e /etc/squid3/squid.conf ]; then
squid_var="/etc/squid3/squid.conf"
else
msg -ama "$(fun_trans "Su sistema no tiene un squid")!" && return 1
fi
teste_cache="#CACHE_DO_SQUID"
if [[ `grep -c "^$teste_cache" $squid_var` -gt 0 ]]; then
  [[ -e ${squid_var}.bakk ]] && {
  msg -ama "$(fun_trans "Cache squid identificado, eliminando")!"
  mv -f ${squid_var}.bakk $squid_var
  msg -ama "$(fun_trans "Cache squid Removido")!"
  service squid restart > /dev/null 2>&1 &
  service squid3 restart > /dev/null 2>&1 &
  return 0
  }
fi
msg -ama "$(fun_trans "Aplicando Cache Squid")!"
msg -bar
_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"
[[ "$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"
while read s_squid; do
[[ "$s_squid" != "cache deny all" ]] && _tmp+="\n${s_squid}"
done < $squid_var
cp ${squid_var} ${squid_var}.bakk
echo -e "${_tmp}" > $squid_var
msg -ama "$(fun_trans "Cache Aplicado con Exito")!"
service squid restart > /dev/null 2>&1 &
service squid3 restart > /dev/null 2>&1 &
}


oracl(){
clear
#msg -bar
msg -tit
msg -verm "		FIREWALLD"
msg -ama " ESTA HERRAMIENTA ES PARA LAS VPS ORACLE/AWS/AZR"
msg -ama " TAMBIEN PARA OTRAS VPS QUE SON NECESARIO A UTILIZAR ESTA OPCION"
echo -ne " Desea Continuar? [S/N]: "; read x
[[ $x = @(n|N) ]] && msg -bar && return
msg -bar
sudo apt update -y &>/dev/null
sudo apt install firewalld -y &>/dev/null
sudo apt install apache2 &>/dev/null
#sudo firewall-cmd --permanent --add-service={http,https} --permanent
sudo firewall-cmd --zone=public --permanent --add-port=80/tcp
sudo firewall-cmd --zone=public --permanent --add-port=81/tcp
sudo firewall-cmd --zone=public --permanent --add-port=90/tcp
sudo firewall-cmd --zone=public --permanent --add-port=110/tcp
sudo firewall-cmd --zone=public --permanent --add-port=143/tcp
sudo firewall-cmd --zone=public --permanent --add-port=442/tcp
sudo firewall-cmd --zone=public --permanent --add-port=443/tcp
sudo firewall-cmd --zone=public --permanent --add-port=444/tcp
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
sudo firewall-cmd --zone=public --permanent --add-port=8081/tcp
sudo firewall-cmd --zone=public --permanent --add-port=5300/udp
sudo firewall-cmd --zone=public --permanent --add-port=7200/udp
sudo firewall-cmd --zone=public --permanent --add-port=7300/udp
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-ports &>/dev/null
msg -azu "	FIX AGREGADO"

}
cache(){
clear
msg -bar
msg -verm "	LIBERANDO CACHÉ/RAM DEL SISTEMA"
msg -bar

sysctl -w vm.drop_caches=3 &> /dev/null
#apt-get autoclean -y &>/dev/null; apt-get clean -y &>/dev/null && msg -ama " REFRESCANDO RAM,SISTEMA"| pv -qL20
#  sleep 2s

  if [[ ! -z $(crontab -l|grep -w "autolim") ]]; then
    msg -azu " Auto limpieza programada cada $(msg -verd "[ $(crontab -l|grep -w "autolim"|awk '{print $2}'|sed $'s/[^[:alnum:]\t]//g')HS ]")"
    msg -bar
    while :
    do
    echo -ne "$(msg -azu " Detener Auto Limpieza [S/N]: ")" && read yesno
    tput cuu1 && tput dl1
    case $yesno in
      s|S) crontab -l > /root/cron && sed -i '/autolim/ d' /root/cron && crontab /root/cron && rm /etc/autolim
           msg -azu " Auto-Limpeza Detenida!" && msg -bar && sleep 2
           return 1;;
      n|N)return 1;;
      *)menu3 ;;
    esac
    done
  fi 
  clear
  msg -bar
msg -ama "	  \e[1;97m\e[2;100mAUTO MANTENIMIENTO DE SISTEMA \e[0m"
msg -bar 
msg -verm2 " ➥ \e[97mACTUALIZACION DE PAQUETES       "
msg -verm2 " ➥ \e[97mREFRESCAR RAM       "
msg -verm2 " ➥ \e[97mREFRESCAR SWAP       "
msg -verm2 " ➥ \e[97mLIMPIAR PAQUETES OPSOLETOS      "
msg -verm2 " ➥ \e[97mLIMPIAR CACHE V2RAY      "
msg -verm2 " ➥ \e[97mREINICIO DE SSL      "
msg -bar
  echo -ne "$(msg -azu "Desea programar El Auto-Limpieza [s/n]:") "
  read c_ram
  if [[ $c_ram = @(s|S|y|Y) ]]; then
    tput cuu1 && tput dl1
    echo -ne "$(msg -azu " PONGA UN NÚMERO, EJEMPLO [1-12HORAS]:") "
    read ram_c
    if [[ $ram_c =~ ^[0-9]+$ ]]; then
      crontab -l > /root/cron
      wget -O /etc/autolim https://www.dropbox.com/s/rro6ghqr1dsj20l/autolim.sh &>/dev/null
		chmod 777 /etc/autolim
      echo "0 */$ram_c * * * bash /etc/autolim" >> /root/cron
      crontab /root/cron
      
      service cron restart
      rm /root/cron
      tput cuu1 && tput dl1
      msg -azu " Auto-Limpieza programada cada: $(msg -verd "${ram_c} HORAS")" && msg -bar && sleep 2
    else
      tput cuu1 && tput dl1
      msg -verm2 " ingresar solo numeros entre 1 y 12"
      sleep 2
      msg -bar
    fi
  fi
  return 1
}

pidr_inst(){
  proto="dropbear python stunnel4 stunnel5 v2ray node badvpn squid openvpn dns-serve ssserver ss-server"
  portas=$(lsof -V -i -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND")
  for list in $proto; do
    case $list in
      dropbear|python|stunnel4|stunnel5|v2ray|node|badvpn|squid|openvpn|ssserver|ss-server)
      portas2=$(echo $portas|grep -w "LISTEN"|grep -w "$list")
      [[ $(echo "${portas2}"|grep "$list") ]] && inst[$list]="\033[1;32m[ON] " || inst[$list]="\033[1;31m[OFF]";;
      dns-serve)
      portas2=$(echo $portas|grep -w "$list")
      [[ $(echo "${portas2}"|grep "$list") ]] && inst[$list]="\033[1;32m[ON] " || inst[$list]="\033[1;31m[OFF]";;
    esac
  done
  [[ $(dpkg --get-selections|grep -w 'wireguard'|head -1) ]] && {
    if [[ $(wg|grep -w 'interface') = "" ]]; then inst[wg]="\033[1;31m[OFF]"; else inst[wg]="\033[1;32m[ON] "; fi
  } || {
    inst[wg]="\033[1;31m[OFF]"
  }
}
# Menu Instalaciones

#check_IP&
# MENU FLUTUANTE
menu_func () {
local options=${#@}
local array
for((num=1; num<=$options; num++)); do
echo -ne "  $(msg -verd "\e[1;93m[\e[92m$num\e[93m]") $(msg -verm2 "➛ ") "
  array=(${!num})
  case ${array[0]} in
    "-vd")msg -verd "\033[1;33m[!]\033[1;32m $(fun_trans "${array[@]:1}")" | sed ':a;N;$!ba;s/\n/ /g';;
    "-vm")msg -verm2 "\033[1;33m[!]\033[1;31m $(fun_trans "${array[@]:1}")" | sed ':a;N;$!ba;s/\n/ /g';;
    "-fi")msg -azu "$(fun_trans "${array[@]:2}") ${array[1]}" | sed ':a;N;$!ba;s/\n/ /g';;
    *)msg -azu "$(fun_trans "${array[@]}")" | sed ':a;N;$!ba;s/\n/ /g';;
  esac
done
}

VERY3=$(ps aux|grep -v grep|grep "monitor")
monservi_fun () {
clear
clear
monssh () {
sed -i "57d" /bin/monitor.sh
sed -i '57i EstadoServicio ssh' /bin/monitor.sh
}
mondropbear () {
sed -i "59d" /bin/monitor.sh
sed -i '59i EstadoServicio dropbear' /bin/monitor.sh
}
monssl() {
sed -i "61d" /bin/monitor.sh
sed -i '61i EstadoServicio stunnel4' /bin/monitor.sh
}
monsquid() {
sed -i "63d" /bin/monitor.sh
sed -i '63i [[ $(EstadoServicio squid) ]] && EstadoServicio squid3' /bin/monitor.sh
}
monapache() {
sed -i "65d" /bin/monitor.sh
sed -i '65i EstadoServicio apache2' /bin/monitor.sh
}
monv2ray() {
sed -i "55d" /bin/monitor.sh
sed -i '55i EstadoServicio v2ray' /bin/monitor.sh
}
msg -bar
msg -tit
echo -e "\033[1;32m          MONITOR DE SERVICIONS PRINCIPALES"

PIDVRF3=$(ps aux|grep -v grep |grep "monitor")

#PIDVRF5=$(ps x|grep -v grep |grep "monit") 

if [[ -z $PIDVRF3 ]]; then
#sed -i '5a\screen -dmS monitor /etc/VPS-MX/tmp/monitor' /bin/resetsshdrop
msg -bar
echo -e "\033[1;34m          ¿Monitorear Protocolo SSH/SSHD?"
msg -bar
read -p "                    [ s | n ]: " monssh  
sed -i "57d" /bin/monitor.sh
sed -i '57i #EstadoServicio ssh' /bin/monitor.sh 
[[ "$monssh" = "s" || "$monssh" = "S" ]] && monssh
msg -bar
echo -e "\033[1;34m          ¿Monitorear Protocolo DROPBEAR?"
msg -bar
read -p "                    [ s | n ]: " mondropbear  
sed -i "59d" /bin/monitor.sh
sed -i '59i #EstadoServicio dropbear' /bin/monitor.sh
[[ "$mondropbear" = "s" || "$mondropbear" = "S" ]] && mondropbear
msg -bar
echo -e "\033[1;34m            ¿Monitorear Protocolo SSL?"
msg -bar
read -p "                    [ s | n ]: " monssl  
sed -i "61d" /bin/monitor.sh
sed -i '61i #EstadoServicio stunnel4' /bin/monitor.sh
[[ "$monssl" = "s" || "$monssl" = "S" ]] && monssl
msg -bar
echo -e "\033[1;34m            ¿Monitorear Protocolo SQUID?"
msg -bar
read -p "                    [ s | n ]: " monsquid  
sed -i "63d" /bin/monitor.sh
sed -i '63i #[[ $(EstadoServicio squid) ]] && EstadoServicio squid3' /bin/monitor.sh
[[ "$monsquid" = "s" || "$monsquid" = "S" ]] && monsquid
msg -bar
echo -e "\033[1;34m            ¿Monitorear Protocolo APACHE?"
msg -bar
read -p "                    [ s | n ]: " monapache  
sed -i "65d" /bin/monitor.sh
sed -i '65i #EstadoServicio apache2' /bin/monitor.sh
[[ "$monapache" = "s" || "$monapache" = "S" ]] && monapache
msg -bar
echo -e "\033[1;34m            ¿Monitorear Protocolo V2RAY?"
msg -bar
read -p "                    [ s | n ]: " monv2ray  
sed -i "55d" /bin/monitor.sh
sed -i '55i #EstadoServicio v2ray' /bin/monitor.sh 
[[ "$monv2ray" = "s" || "$monv2ray" = "S" ]] && monv2ray 
#screen -dmS monitor /etc/VPS-MX/tmp/monitor
#screen -dmS monit /etc/VPS-MX/tmp/monitor
echo -e "[Unit]
Description=monitor Service
After=network.target\n
[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/bin/bash /etc/VPS-MX/tmp/monitor
Restart=always
RestartSec=3s\n
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/monit.service

    systemctl enable monit &>/dev/null
    systemctl start monit &>/dev/null
else

	systemctl stop monit &>/dev/null
	systemctl disable monit &>/dev/null
    rm -rf /etc/systemd/system/monit .service
    sed -i "6d" /bin/resetsshdrop
fi

msg -bar
echo -e "             Puedes Monitorear desde:\n       \033[1;32m http://$(meu_ip):81/monitor.html"
msg -bar
[[ -z ${VERY3} ]] && monitor="\033[1;32m ACTIVADO " || monitor="\033[1;31m DESACTIVADO "
echo -e "            $monitor  --  CON EXITO"
msg -bar

}
droppids(){
  port_dropbear=`ps aux|grep 'dropbear'|awk NR==1|awk '{print $17;}'`

  log=/var/log/auth.log
  loginsukses='Password auth succeeded'

  pids=`ps ax|grep 'dropbear'|grep " $port_dropbear"|awk -F " " '{print $1}'`

  for pid in $pids; do
    pidlogs=`grep $pid $log |grep "$loginsukses" |awk -F" " '{print $3}'`

    i=0
    for pidend in $pidlogs; do
      let i=i+1
    done

    if [ $pidend ];then
       login=`grep $pid $log |grep "$pidend" |grep "$loginsukses"`
       PID=$pid
       user=`echo $login |awk -F" " '{print $10}' | sed -r "s/'/ /g"`
       waktu=`echo $login |awk -F" " '{print $2"-"$1,$3}'`
       while [ ${#waktu} -lt 13 ]; do
           waktu=$waktu" "
       done
       while [ ${#user} -lt 16 ]; do
           user=$user" "
       done
       while [ ${#PID} -lt 8 ]; do
           PID=$PID" "
       done
       echo "$user $PID $waktu"
    fi
done
}
openvpn_pids () {
#nome|#loguin|#rcv|#snd|#time
  byte () {
   while read B dummy; do
   [[ "$B" -lt 1024 ]] && echo "${B} bytes" && break
   KB=$(((B+512)/1024))
   [[ "$KB" -lt 1024 ]] && echo "${KB} Kb" && break
   MB=$(((KB+512)/1024))
   [[ "$MB" -lt 1024 ]] && echo "${MB} Mb" && break
   GB=$(((MB+512)/1024))
   [[ "$GB" -lt 1024 ]] && echo "${GB} Gb" && break
   echo $(((GB+512)/1024)) terabytes
   done
   }
for user in $(mostrar_usuarios); do
user="$(echo $user|sed -e 's/[^a-z0-9 -]//ig')"
[[ ! $(sed -n "/^${user},/p" /etc/openvpn/openvpn-status.log) ]] && continue
i=0
unset RECIVED; unset SEND; unset HOUR
 while read line; do
 IDLOCAL=$(echo ${line}|cut -d',' -f2)
 RECIVED+="$(echo ${line}|cut -d',' -f3)+"
 SEND+="$(echo ${line}|cut -d',' -f4)+"
 DATESEC=$(date +%s --date="$(echo ${line}|cut -d',' -f5|cut -d' ' -f1,2,3,4)")
 TIMEON="$(($(date +%s)-${DATESEC}))"
  MIN=$(($TIMEON/60)) && SEC=$(($TIMEON-$MIN*60)) && HOR=$(($MIN/60)) && MIN=$(($MIN-$HOR*60))
  HOUR+="${HOR}h:${MIN}m:${SEC}s\n"
  let i++
 done <<< "$(sed -n "/^${user},/p" /etc/openvpn/openvpn-status.log)"
RECIVED=$(echo $(echo ${RECIVED}0|bc)|byte)
SEND=$(echo $(echo ${SEND}0|bc)|byte)
HOUR=$(echo -e $HOUR|sort -n|tail -1)
echo -e "$user|$i|$RECIVED|$SEND|$HOUR" 
done
}
monitor-user(){
	users=$(cat /etc/passwd|grep 'home'|grep 'false'|grep -v 'syslog'|awk -F ':' '{print $1}')
	dpids=$(droppids)
	time=$(date +%s)
	[[ -e /etc/openvpn/openvpn-status.log ]] && ovpn_log=$(cat /etc/openvpn/openvpn-status.log)

	n='0'
	i='0'
	conect='0'
	for _user in $users; do
		[[ -z "$(ps -u $_user|grep sshd)" ]] && sqd=0 || sqd=1
		[[ -z "$(echo $ovpn_log|grep -E ,"$_user",)" ]] && ovp=0 || ovp=1
        [[ -z "$(echo $dpids|grep -w "$_user")" ]] && drop=0 || drop=1

        conex=$(($sqd + $ovp + $drop))
    #   conex="$(echo $PID|bc)"
        [[ $conex -ne 0 ]] && let conect++

		if [[ $(chage -l $_user |grep 'Account expires' |awk -F ': ' '{print $2}') != never ]]; then
			[[ $time -gt $(date '+%s' -d "$(chage -l $_user |grep "Account expires" |awk -F ': ' '{print $2}')") ]] && let n++
		fi
		[[ $(passwd --status $_user|cut -d ' ' -f2) = "L" ]] && let i++
	done

	_onlin=$(printf '%-7s' "$conect")
	_userexp=$(printf '%-7s' "$n")
	_lok=$(printf '%-7s' "$i")
	_tuser=$(echo "$users"|sed '/^$/d'|wc -l)

	echo -e " $(msg -verd "ONLINE:") $(msg -azu "$_onlin") $(msg -verm2 "EXPIRADOS:") $(msg -azu "$_userexp") $(msg -bra "\e[95mBLOQUEADO:") $(msg -azu "$_lok")" #$(msg -ama "TOTAL:") $(msg -azu "$_tuser")"
}
# SISTEMA DE SELECAO
selection_fun () {
local selection="null"
local range
for((i=0; i<=$1; i++)); do range[$i]="$i "; done
while [[ ! $(echo ${range[*]}|grep -w "$selection") ]]; do
echo -ne "\033[1;37m$(fun_trans " ► Selecione una Opcion"): " >&2
read selection
tput cuu1 >&2 && tput dl1 >&2
done
echo $selection
}
export -f msg
export -f selection_fun
export -f fun_trans
export -f menu_func
export -f meu_ip
export -f fun_ip
export -f lacasita
clear
sudo sync
sudo sysctl -w vm.drop_caches=3 > /dev/null 2>&1
clear
clear
#msg -lol
msg -bar3
msg -tit
#
menu_info
msg -bar
# echo -e "\033[1;31m[\033[1;32m $vesaoSCT\033[1;97m"
# msg -bar
title=`echo -e "\033[1;96m$(cat ${SCPdir}/message.txt)"`
printf "%*s\n" $(( ( $(echo -e "$title" | wc -c ) + 55 ) / 2 )) "$title"
msg -bar

SSHN="$(grep -c home /etc/passwd)"
#SSH2="$(echo ${SSHN}|bc)-2"
echo "${SSHN}"|bc > /etc/VPS-MX/controlador/SSH20.log
SSH3="$(less /etc/VPS-MX/controlador/SSH20.log)"
SSH4="$(echo $SSH3)"
user_info=$(cd /usr/local/shadowsocksr &> /dev/null  && python mujson_mgr.py -l ) 
user_total=$(echo "${user_info}"|wc -l)
[[ ! -e /etc/VPS-MX/RegV2ray ]] && touch /etc/VPS-MX/RegV2ray
vray=$(cat /etc/VPS-MX/RegV2ray | wc -l)
on="\033[1;92m[ON]" && off="\033[1;31m[OFF]"
#[[ $(ps x | grep badvpn | grep -v grep | awk '{print $1}') ]] && badvpn=$on || badvpn=$off
echo -e "\033[1;97m   SSH REG:\033[1;92m $SSH4 \033[1;97m   SS-SSRR REG:\033[1;92m $user_total \033[1;97m   V2RAY REG:\e[32m $vray"
limseg="$(less /etc/VPS-MX/controlador/tiemlim.log)" 
veri=$(ps x|grep -v grep |grep "verif")
[[ ! $veri ]] && verificar="\033[1;31m[OFF]" || verificar="\033[1;32m[ON] "
des=$(ps x|grep -v grep |grep "autode")
[[ ! $des ]] && desbloqueo="\033[1;31m[OFF]" || desbloqueo="\033[1;32m[ON] "
mon=$(ps x|grep -v grep |grep "monitor")
[[ ! $mon ]] && monitorserv="\033[1;31m[OFF]" || monitorserv="\033[1;32m[ON] "

if [[ ! -e ${SCPdir}/USRonlines ]]; then
if [[ $(cat ${SCPdir}/tmp/style|grep -w "monitor-user"|awk '{print $2}') = "1" ]] ; then
  monitor-user
#  msg -bar
fi

else
[[ -e ${SCPdir}/USRonlines ]] && msg -bar && msg -ne "\033[1;97m LIMITADOR:\033[1;92m$verificar \033[1;97m AUTO-DESBLOQUEO:\033[1;92m$desbloqueo \e[1;97mMONITOR:\e[34m${limseg}s\n \033[1;32mCONECTADOS: " && echo -ne "\033[1;97m$(cat ${SCPdir}/USRonlines) "
[[ -e ${SCPdir}/USRexpired ]] && msg -ne "   EXPIRADOS: " && echo -ne "\033[1;97m$(cat ${SCPdir}/USRexpired) "  && msg -ne " \033[1;95m BLOQUEADOS: " && echo -e "\033[1;97m$(cat ${SCPdir}/USRbloqueados)" #\n\033[1;97m        ACTULIZACION DE MONITOR CADA: \033[1;34m $limseg s" 
fi
monhtop () {
clear 

#msg -bar
msg -tit
echo -ne " \033[1;93m             MONITOR DE PROCESOS HTOP\n"
msg -bar
msg -bra "    RECUERDA SALIR CON : \033[1;96m CTRL + C o FIN + F10 "
[[ $(dpkg --get-selections|grep -w "htop"|head -1) ]] || apt-get install htop -y &>/dev/null
msg -bar
read -t 10 -n 1 -rsp $'\033[1;39m Preciona Enter Para continuar\n'
clear
sudo htop
msg -bar
echo -e "\e[97m \033[1;41m| #-#-►  SCRIPT VPS•MX ◄-#-# | \033[1;49m\033[1;49m \033[1;31m[ \033[1;32m $vesaoSCT      "
echo -ne " \033[1;93m             MONITOR DE PROCESOS HTOP\n"
msg -bar
echo -e "\e[97m                  FIN DEL MONITOR"
msg -bar
}

[[ $(ps x | grep v2ray | grep -v grep | awk '{print $1}') ]] && vra=$on || vra=$off
msg -bar
msg -bar3
on="\e[1;32m[ON]" && off="\e[1;31m[OFF]"
echo -e " \e[1;93m[\e[92m1\e[93m] $(msg -verm2 "➛ ") $(msg -azu "ADMINISTRAR CUENTAS | SSH/SSL/DROPBEAR")" 
echo -e " \e[1;93m[\e[92m2\e[93m] $(msg -verm2 "➛ ") $(msg -azu "ADMINISTRAR CUENTAS | SS/SSRR")" 
echo -e " \e[1;93m[\e[92m3\e[93m] $(msg -verm2 "➛ ") $(msg -azu "ADMINISTRAR CUENTAS | V2RAY --> $vra")"
echo -e " \e[1;93m[\e[92m4\e[93m] $(msg -verm2 "➛ ") \e[1;31m\033[47mPROTOCOLOS\e[0m  \e[93m||  \e[1;37m\e[41mHERRAMIENTAS\e[0m"
echo -e " \e[1;93m[\e[92m5\e[93m] $(msg -verm2 "➛ ") $(msg -azu "MONITOR DE PROTOCOLOS --------> ${monitorserv}")"
echo -e " \e[1;93m[\e[92m6\e[93m] $(msg -verm2 "➛ ") $(msg -azu "AUTO INICIAR SCRIPT ----------> $AutoRun ")"
msg -bar
echo -e " \e[1;93m[\e[92m7\e[93m] \e[97m$(msg -verm2 "➛ ") $(msg -verd "ACTUALIZAR") \e[1;93m [\e[92m8\e[93m]\e[97m$(msg -verm2 "➛ ")\033[1;31mDESINSTALAR  \e[1;93m[\e[92m0\e[93m]$(msg -verm2 "➛ ") $(msg -bra "\e[97m\033[1;41mSALIR")"
msg -bar

selection=$(selection_fun 13)
case ${selection} in
1)${SCPusr}/usercodes ;;
2)${SCPinst}/C-SSR.sh ;;
3)${SCPinst}/v2ray.sh ;;
4)menu3;;
5) monservi_fun ;; #/etc/VPS-MX/tmp/monitor;;
6)fun_autorun;;
7)atualiza_fun;;
8)remove_script;;
0)cd $HOME && exit 0;;
esac
msg -ne "Enter Para Continuar" && read enter
${SCPdir}/menu