#!/bin/bash
CIDdir=/etc/CAT-BOT && [[ ! -d ${CIDdir} ]] && mkdir ${CIDdir}
DIRSCRIPT=/etc/cat/script && [[ ! -d ${DIRSCRIPT} ]] && mkdir -p ${DIRSCRIPT}
DIRSCRIPTC=/etc/cat/casita && [[ ! -d ${DIRSCRIPTC} ]] && mkdir -p ${DIRSCRIPTC}
DIR="/etc/http-shell"
IVAR="/etc/http-instas"
sudo mkdir -p /bin/ejecutar

colores="$(pwd)/colores"
rm -rf ${colores}
wget -O ${colores} "https://raw.githubusercontent.com/darnix1/UDP-Custom/main/colores" &>/dev/null
[[ ! -e ${colores} ]] && exit
chmod +x ${colores} &>/dev/null
source ${colores}

bar="\e[0;31m=====================================================\e[0m"
msg () {
BRAN='\033[1;37m' && VERMELHO='\e[31m' && VERDE='\e[32m' && AMARELO='\e[33m'
AZUL='\e[34m' && MAGENTA='\e[35m' && MAG='\033[1;36m' &&NEGRITO='\e[1m' && SEMCOR='\e[0m'
 case $1 in
  -ne)cor="${VERMELHO}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  -ama)cor="${AMARELO}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -verm)cor="${AMARELO}${NEGRITO}[!] ${VERMELHO}" && echo -e "${cor}${2}${SEMCOR}";;
  -azu)cor="${MAG}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -verd)cor="${VERDE}${NEGRITO}" && echo -e "${cor}${2}${SEMCOR}";;
  -bra)cor="${BRAN}${NEGRITO}" && echo -ne "${cor}${2}${SEMCOR}";;
  -bar2)cor="\e[0;31m========================================\e[0m" && echo -e "${cor}${SEMCOR}";;
  -bar)cor="\e[1;31m——————————————————————————————————————————————————————" && echo -e "${cor}${SEMCOR}";;
 esac
}



check_ip() {
    MIP=$(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)
    MIP2=$(wget -qO- ipv4.icanhazip.com)
    [[ "$MIP" != "$MIP2" ]] && IP="$MIP2" || IP="$MIP"
    echo "$IP" >/usr/bin/vendor_code
}

unistall() {
    dir="/etc/CAT-BOT"
    rm -rf ${dir}
    echo "DETENIENDO EL PROCESO DEL BOT"
    sleep 2s
    #killall BotGen.sh
    kill -9 $(ps aux | grep -v grep | grep -w "BotGen.sh" | grep dmS | awk '{print $2}') &>/dev/null
    kill $(ps aux | grep -v grep | grep -w "BotGen.sh") &>/dev/null

    #killall http-server.sh
    rm -rf /bin/http-server.sh
    rm -rf /bin/ShellBot.sh
    rm -rf /bin/vpsbot
    rm -rf /etc/cat/script
    rm -rf /etc/cat/casita
    rm -rf .bash_history
    sleep 3s
    clear
    echo "BOT DETENIDAA"
}

check_ip

updatex() {
    clear
[[ ! -d ${IVAR} ]] && touch ${IVAR}
#dpkg --configure -a

msg -bar
os_system
msg -ama "$distro $vercion"
echo "$distro $vercion" > /etc/bot-alx/system
msg -verm " INSTALACION DE PAQUETES "
msg -bar
#
#by rufu99
msg -verd "	INSTALL UPDATE"
	apt update -y
	apt list --upgradable -y
	msg -verd "	INSTALL UPGRADE"
 	apt upgrade -y
 clear
 msg -bar
	paq="jq bc curl netcat netcat-traditional net-tools apache2 zip unzip screen"

	for i in $paq; do
		leng="${#i}"
		puntos=$(( 21 - $leng))
		pts="."
		for (( a = 0; a < $puntos; a++ )); do
			pts+="."
		done
		msg -azu "       instalando $i$(msg -ama "$pts")"
		if apt install $i -y &>/dev/null ; then
			msg -verd "	INSTALADO"
		else
			msg -verm2 "	FAIL"
			sleep 0.1s
			tput cuu1 && tput dl1
			msg -ama "aplicando fix a $i"
			dpkg --configure -a &>/dev/null
			sleep 0.2s
			tput cuu1 && tput dl1

			msg -azu "       instalando $i$(msg -ama "$pts")"
			if apt install $i -y &>/dev/null ; then
				msg -verd "	INSTALANDO"
			else
				msg -verm2 "	FAIL"
			fi
		fi
	done
	sed -i "s;Listen 80;Listen 81;g" /etc/apache2/ports.conf
	service apache2 restart > /dev/null 2>&1 &
	msg -bar
	msg -azu "Removiendo paquetes obsoletos"
	msg -bar
 	apt autoremove -y &>/dev/null
echo "00" > /root/.bash_history
ufw allow 80/tcp &>/dev/null
ufw allow 81/tcp &>/dev/null
ufw allow 8888/tcp &>/dev/null
#read -p "enter"

#botmen
}




spiner() {
    #code barba
    local pid=$!
    local delay=1
    local spinner=('█■■■■■■' '■█■■■■■' '■■█■■■■' '■■■█■■■' '■■■■█■■' '■■■■■█■' '■■■■■■█-')
    while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
        for i in "${spinner[@]}"; do
            tput civis
            echo -ne "\033[1;31m\r[\e[0m\e[1;32m~\e[0m\e[1;31m]\e[0m\e[1;96mInstalando....\e[31m[\033[32m$i\033[31m]     \033[0m       "
            sleep $delay
            printf "\b\b\b\b\b\b\b\b"
        done
    done
    printf "   \b\b\b\b\b"
    tput cnorm
    echo -e "\033[1;31m[\e[0m\e[1;33mInstalado\e[0m\e[1;31m]\e[0m"
}

os_system(){
system=$(cat -n /etc/issue |grep 1 |cut -d ' ' -f6,7,8 |sed 's/1//' |sed 's/      //')
distro=$(echo "$system"|awk '{print $1}')
case $distro in
Debian)vercion=$(echo $system|awk '{print $3}'|cut -d '.' -f1);;
Ubuntu)vercion=$(echo $system|awk '{print $2}'|cut -d '.' -f1,2);;
esac
link="https://raw.githubusercontent.com/rudi9999/ADMRufu/main/Repositorios/${vercion}.list"
case $vercion in
8|9|10|11|16.04|18.04|20.04|20.10|21.04|21.10|22.04)wget -O /etc/apt/sources.list ${link} &>/dev/null;;
esac
}

descarga() {
    rm -rf .bash_history
    check_ip
    clear
    [[ ! -d ${IVAR} ]] && touch ${IVAR}
    wget -O /bin/http-server.sh https://gitlab.com/xdanx90/Premium/-/raw/main/install/http-server.sh &>/dev/null
    chmod +x /bin/http-server.sh
    msgi -bar
    os_system
    msgi -ama "$distro $vercion"
    echo "$distro $vercion" > /etc/CAT-BOT/system
   msg -bar
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Update"
apt-get update &>/dev/null & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Upgrade"
apt-get upgrade -y &>/dev/null & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Ssh"
apt-get install sshpass -y &>/dev/null & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Unzip"
apt-get install unzip -y &>/dev/null & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Zip"
apt-get install zip -y &>/dev/null & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Lsof"
apt-get install lsof >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Sudo"
apt-get install sudo >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Screen"
apt-get install screen -y >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Bc"
apt-get install bc -y >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Netcat"
apt-get install netcat -y >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Jq"
apt-get install jq -y >/dev/null 2>&1 & spiner
echo -e "\033[31m[\033[32m~\033[31m]\033[37m$instalando Apache2"
apt-get install apache2 -y &>/dev/null & spiner
sed -i "s;Listen 80;Listen 81;g" /etc/apache2/ports.conf
service apache2 restart > /dev/null 2>&1 &
msg -verm " INSTALACION DE PAQUETES "

    echo -e "DESCARGANADO LA BASE DEL SERVIDOR FTP"
    
    #EMPIEZA A DESCARGAR LATAM
    mxofc=https://www.dropbox.com/s/3ujxegx15hoh1w2/SCRIPT-LATAM.zip
    #mxofca=40.233.0.82:3000/darnix1/Archivoscasita/raw/branch/main/SCRIPTMX.zip
	mxofca=https://www.dropbox.com/s/o3wyvhaxxb5sj8h/SCRIPTMX.zip
	wget $mxofc &>/dev/null
    wget $mxofca &>/dev/null
	unzip SCRIPT-LATAM.zip &>/dev/null
    unzip SCRIPTMX.zip &>/dev/null

    cp SCRIPT-LATAM/* ${DIRSCRIPT}
    cp SCRIPT/* ${DIRSCRIPTC}
    [[ ! -e ${DIRSCRIPT}/ID.txt ]] && touch ${DIRSCRIPT}/ID.txt
    [[ ! -e ${DIRSCRIPTC}/ID.txt ]] && touch ${DIRSCRIPTC}/ID.txt

    chmod +x ${DIRSCRIPT}/*
    chmod +x ${DIRSCRIPTC}/*

    rm -rf SCRIPT-LATAM.zip
    rm -rf SCRIPT-LATAM
    rm -rf SCRIPTMX.zip
    rm -rf SCRIPT
    
    
    sleep 1s
    echo -e "$bar"
    msgi -verm " DESCARGANDO ARCHIVOS BOT LATAM"
    echo -e "$bar"
    sleep 2s

    echo "menu.sh LATAMbot.sh PDirect.py PGet.py POpen.py PPriv.py PPub.py message.txt" > /etc/newadm-instal
    echo "ID.txt slowdns.sh ADMbot.sh C-SSR.sh Crear-Demo.sh PDirect.py PGet.py POpen.py PPriv.py PPub.py apacheon.sh blockBT.sh budp.sh dns-netflix.sh dropbear.sh fai2ban.sh message.txt openvpn.sh paysnd.sh ports.sh sockspy.sh speed.py squid.sh squidpass.sh ssl.sh tcp.sh ultrahost v2ray.sh python.py" > /etc/newadm-install
	#autodel
	    kill -9 $(ps aux | grep -v grep | grep -w "veri" | grep dmS | awk '{print $2}') &>/dev/null
        wget -O ${CIDdir}/veri https://www.dropbox.com/s/qde9sk498w4mgas/autodel &>/dev/null && chmod 777 ${CIDdir}/veri
        
#aqui el nuevo link del bot
    wget -O /etc/CAT-BOT/BotGen.sh https://www.dropbox.com/s/25xxz39l16wql29/BotGen.sh &>/dev/null
    chmod +x ${CIDdir}/BotGen.sh
    wget -O /root/script.sh https://www.dropbox.com/s/fmz8r86a97srode/script.sh &>/dev/null
    chmod 777 /root/script.sh
    wget -O /root/remover.sh https://www.dropbox.com/s/tps692vmwkivc2m/remover.sh &>/dev/null
    chmod 777 /root/remover.sh
    echo " DESCARGA FINALIZADA"
    read -p "enter"
    rm -rf .bash_history
    bot_gen
}
ini_token() {
    clear
    echo -e "$bar"
    echo -e "  \033[1;37mIngrese el token de su bot"
    echo -e "$bar"
    echo -n "TOKEN : "
    read opcion
    echo "$opcion" >${CIDdir}/token
    echo -e "$bar"
    echo -e "  \033[1;32mtoken se guardo con exito!" && echo -e "$bar" && echo -e "  \033[1;37mPara tener acceso a todos los comandos del bot\n  deve iniciar el bot en la opcion 2.\n  desde su apps (telegram). ingresar al bot!\n  digite el comando \033[1;31m/id\n  \033[1;37mel bot le respodera con su ID de telegram.\n  copiar el ID e ingresar el mismo en la opcion 3" && echo -e "$bar"
    read -p "enter"
    bot_gen
}

ini_id() {
    clear
    echo -e "$bar"
    echo -e "  \033[1;37mIngrese su ID de telegram"
    echo -e "$bar"
    echo -n "ID: "
    read opci
    echo "$opci" >${CIDdir}/Admin-ID
    echo -e "$bar"
    echo -e "  \033[1;32mID guardo con exito!" && echo -e "$bar" && echo -e "  \033[1;37mdesde su apps (telegram). ingresar al bot!\n  digite el comando \033[1;31m/menu\n  \033[1;37mprueve si tiene acceso al menu extendido." && echo -e "$bar"
    read -p "enter"
    bot_gen
}



alter_id() {
    while [[ ${varread} != @([0-3]) ]]; do
        #tittle
        msgi -bar
        echo -e " \033[0;35m[\033[0;36m1\033[0;35m] \033[0;34m<\033[0;33m Alterar Creditos POR ID   \033[0;32m(#OFICIAL)"
        echo -e " \033[0;35m[\033[0;36m2\033[0;35m] \033[0;34m<\033[0;33m REINICIAR CONTADOR TOTAL  \033[0;32m(#OFICIAL)"
        msgi -bar
        echo -e " \033[0;35m[\033[0;36m0\033[0;35m] \033[0;34m<\033[0;33m Regresar"
        msgi -bar
        echo -ne "${cor[6]}"
        read -p " Opcion : " varread
    done
    msgi -bar
    if [[ ${varread} = 0 ]]; then
        return 0
    elif [[ ${varread} = 1 ]]; then
        echo -e "\033[1;32m DIGITA ID A REINICIAR "
        msgi -ne " Paste ID : " && read newli
        sed -i "/${newli}/d" /etc/CAT-BOT/num-key.cont
        echo "REGISTRO EN $(grep -o -i $newli /etc/CAT-BOT/num-key.cont | wc -l) KEYS"
        read -p "Limite Aplicado Exitosamente"
    elif [[ ${varread} = 2 ]]; then
        echo -e "\033[1;32m BORRAREMOS EL CONTEO TOTAL DEL GENERADOR "
        rm -rf /etc/CAT-BOT/num-key.cont && touch /etc/CAT-BOT/num-key.cont
        echo "REGISTRO EN $(cat /etc/CAT-BOT/num-key.cont | wc -l) KEYS"
        read -p "Limite Aplicado Exitosamente"
    fi
bot_gen
}


# 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;37mOpcion: " >&2
        read selection
        tput cuu1 >&2 && tput dl1 >&2
    done
    echo $selection
}


alter_limit() {
    echo -e "\033[1;32m DIGITA TU NUEVO LIMITE "
    msgi -ne "New Limit: " && read newli
    echo $newli >/etc/CAT-BOT/limit
    read -p "Limite Aplicado Exitosamente"
bot_gen
}

alter_limita() {
    echo -e "\033[1;32m DIGITA TU NUEVO LIMITE "
    msgi -ne "New Limit: " && read newli
    echo $newli >/etc/CAT-BOT/limita
    read -p "Limite Aplicado Exitosamente"
bot_gen
}

ini_res () {
clear
msgi -bar
echo -e "  \033[1;37mIngresa un mensaje para los usuarios"
msgi -bar
echo -n "RESELLER: "
read opction
echo "$opction" > ${CIDdir}/resell
msgi -bar
read -p "Presione Enter para continuar "
bot_gen
}




ini_res2 () {
clear
echo -e "$bar"
echo -e "  \033[1;37mIngresar Mensaje en la Key"
msgi -bar
echo -n "RESELLER: "
read opction
echo "$opction" > ${CIDdir}/resel
msgi -bar
read -p "Presione Enter para continuar "
bot_gen
}

ini_res3 () {
clear
echo -e "$bar"
echo -e "  \033[1;37mIngresar Mensaje en la Key freeee"
msgi -bar
echo -n "RESELLER: "
read opction
echo "$opction" > ${CIDdir}/reselkey
msgi -bar
read -p "Presione Enter para continuar "
bot_gen
}



start_boti() {
    local token_file="${CIDdir}/token"
    local service_file="/etc/systemd/system/BotGen-server.service"
    local service_name="BotGen-server"
    local pidgen

    # Verificar si el archivo de token no existe, crearlo
    [[ ! -e "$token_file" ]] && echo "null" > "$token_file"

    # Verificar si el proceso BotGen.sh está corriendo
    pidgen=$(pgrep -f "BotGen.sh")

    if [[ -z "$pidgen" ]]; then
        # Si no está corriendo, crear y habilitar el servicio
        echo -e "[Unit]
Description=BotGen Service by @ChumoGH
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/bin/bash ${CIDdir}/BotGen.sh -start
Restart=always
RestartSec=3s

[Install]
WantedBy=multi-user.target" > "$service_file"

        # Habilitar e iniciar el servicio
        systemctl enable "$service_name" &>/dev/null
        systemctl start "$service_name" &>/dev/null
        echo -e "\033[1;32m[✓] BotGen iniciado correctamente.\033[0m"
    else
        # Si está corriendo, detener y deshabilitar el servicio
        killall BotGen.sh &>/dev/null
        systemctl stop "$service_name" &>/dev/null
        systemctl disable "$service_name" &>/dev/null
        rm "$service_file" &>/dev/null
        echo -e "\033[1;31m[×] BotGen fuera de línea.\033[0m"
    fi

    # Pausa para la interacción del usuario
    read -p "Presione Enter para continuar..."
    bot_gen
}







msj_prueba() {

    TOKEN="$(cat /etc/CAT-BOT/token)"
    ID="$(cat /etc/CAT-BOT/Admin-ID)"

    [[ -z $TOKEN ]] && {
        clear
        echo -e "$bar"
        echo -e "\033[1;37m Aun no a ingresado el token\n No se puede enviar ningun mensaje!"
        echo -e "$bar"
        read -p "enter"
    } || {
        [[ -z $ID ]] && {
            clear
            echo -e "$bar"
            echo -e "\033[1;37m Aun no a ingresado el ID\n No se puede enviar ningun mensaje!"
            echo -e "$bar"
            read -p "enter"
        } || {
            MENSAJE="Esto es un mesaje de prueba!"
            URL="https://api.telegram.org/bot$TOKEN/sendMessage"
            curl -s -X POST $URL -d chat_id=$ID -d text="$MENSAJE" &>/dev/null
            clear
            echo -e "$bar"
            echo -e "\033[1;37m mensaje enviado...!"
            echo -e "$bar"
            sleep 2
        }
    }

    bot_gen
}

verify() {
    apt-get install curl -y &>/dev/null
    IP=$(wget -qO- ipv4.icanhazip.com)
    permited=$(curl -sSL "https://raw.githubusercontent.com/darnix1/permission/refs/heads/main/ip")
    [[ $(echo $permited | grep "${IP}") = "" ]] && {
        clear
        bot="\n\n\n————————————————————————————\n      ¡IP NO ESTA REGISTRADO! [QUITANDO ACCESO]\n      CONTACTE A: @latamsrc \n————————————————————————————\n\n\n"
        echo -e "\e[1;91m$bot"

        TOKEN="6222435065:AAGIvzgHN8mkP-krjlU-pMoEXA8vOhRdyPY"
        URL="https://api.telegram.org/bot$TOKEN/sendMessage"
        MSG=" IP NO REGISTRADO o CLONING
╔═════ ▓▓ ࿇ ▓▓ ═════╗
- - - - - - - ×∆× - - - - - - -
IP: $IP
- - - - - - - ×∆× - - - - - - -
╚═════ ▓▓ ࿇ ▓▓ ═════╝
"
        curl -s --max-time 10 -d "chat_id=5282484874&disable_web_page_preview=1&text=$MSG" $URL &>/dev/null
        kill -9 $(ps aux | grep -v grep | grep -w "http-server.sh" | grep dmS | awk '{print $2}') &>/dev/null
        kill -9 $(ps aux | grep -v grep | grep -w "Botk.sh" | grep dmS | awk '{print $2}') &>/dev/null
        rm -rf /bin/http-server.sh
        [[ -d /etc/bot-alx ]] && rm -rf /etc/bot-alx
        [[ -e /bin/botmx ]] && rm -rf /bin/botmx
        [[ ! -d ${dir5} ]] && rm -rf ${dir5}

        exit 1
    } || {
        echo 'xd'
        ### INTALAR VERSION DE SCRIPT
        #v1=$(curl -sSL "https://raw.githubusercontent.com/lacasitamx/version/master/vercion")
        #echo "$v1" >/etc/bot-alx/version
    }
}

verify
meu_ip
#function_verify
if [[ ! -e /etc/paq ]]; then
    updatex
    touch /etc/paq
else
    echo -e "${rojo}YA INSTALASTE GENERADOR :)"
fi

port(){
	local portas
	local portas_var=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
	i=0
	while read port; do
		var1=$(echo $port | awk '{print $1}') && var2=$(echo $port | awk '{print $9}' | awk -F ":" '{print $2}')
		[[ "$(echo -e ${portas}|grep -w "$var1 $var2")" ]] || {
			portas+="$var1 $var2 $portas"
			echo "$var1 $var2"
			let i++
		}
	done <<< "$portas_var"
}

verify_port(){
	local SERVICE="$1"
	local PORTENTRY="$2"
	[[ ! $(echo -e $(port|grep -v ${SERVICE})|grep -w "$PORTENTRY") ]] && return 0 || return 1
}


mine_port(){
	local portasVAR=$(lsof -V -i tcp -P -n | grep -v "ESTABLISHED" |grep -v "COMMAND" | grep "LISTEN")
	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
			apache|apache2)
				[[ -z $APC ]] && local APC="\033[1;31m apache: \033[1;32m"
				APC+="$Port ";;
			nc.tradit)
				[[ -z $NC ]] && local NC="\033[1;31m nc.tradit: \033[1;32m"
				NC+="$Port ";;
		esac
	done <<< "${portasVAR}"
	if [[ ! -z $APC ]]; then
		echo -e $APC
	else
		local APC="\033[1;31m apache: [Off]"
		echo -e $APC
	fi

	if [[ ! -z $NC ]]; then
		echo -e $NC
	else
		local NC="\033[1;31m nc.tradit: [Off]"
		echo -e $NC
	fi
}

edit_apache(){
	clear
	msg -bar2
	print_center -azu "REDEFINIR PUERTOS APACHE"
	msg -bar2
	local CONF="/etc/apache2/ports.conf"
	local NEWCONF="$(cat ${CONF})"
	msg -ne "Nuevos Puertos: "
	read -p "" newports

	for PTS in `echo ${newports}`; do
		tput cuu1 >&2 && tput dl1 >&2
		verify_port apache "${PTS}" && echo -e " \033[1;33mPort $PTS \033[1;32mOK" || {
			echo -e " \033[1;33mPort $PTS \033[1;31mFAIL"
			sleep 3
			return 1
		}
	done

	rm ${CONF}

	while read varline; do
		if [[ $(echo ${varline}|grep -w "Listen") ]]; then
			if [[ -z ${END} ]]; then
				echo -e "Listen ${newports}" >> ${CONF}
				END="True"
			else
				echo -e "${varline}" >> ${CONF}
			fi
		else
			echo -e "${varline}" >> ${CONF}
		fi
	done <<< "${NEWCONF}"

	service apache2 restart &>/dev/null
	sleep 1s
	msg -bar2
	print_center -ama "PUERTOS REDEFINIDOS"
	msg -bar2
	sleep 2
	return 1
}


edit_nc(){
	clear
	msg -bar2
	print_center -azu "REDEFINIR PUERTOS NC.TRADIT"
	msg -bar2
	msg -ne "Nuevo Puerto: "
	read -p "" newports

	for PTS in `echo ${newports}`; do
		tput cuu1 >&2 && tput dl1 >&2
		verify_port nc.tradit "${PTS}" && echo -e " \033[1;33mPort $PTS \033[1;32mOK" || {
			echo -e " \033[1;33mPort $PTS \033[1;31mFAIL"
			sleep 3
			return 1
		}
	done

	newport="{\"nc\":$newports}"


	mv ${confJSON} ${tmpJSON}
	jq --argjson a "$newport" '.port += $a' ${tmpJSON} > ${confJSON}

	NC_GEN=$(ps x|grep -v grep|grep -w "BotGen-server.sh")
	[[ $NC_GEN ]] && systemctl restart BotGen-server &>/dev/null
	sleep 1s
	msg -bar2
	print_center -ama "PUERTO REDEFINIDO"
	enter
	return 1
}

config(){
	clear
	msgi -bar
	print_center -azu "AJAUSTES DEL SERVIDOR"
	msgi -bar
	mine_port
	msgi -bar
	menu_func "apache2" "nc.tradit"
	msgi -bar
	echo -e " $(msgi -verd "[0]") $(msgi -verm2 ">") \e[47m $(msgi -blak2 "<< VOLVER ")"
	msgi -bar
	echo -ne " $(msgi -azu "opcion:") "
	read opcion
	case ${opcion} in
		1)edit_apache;;
		2)edit_nc;;
		0) return 1;;
	esac
}

respon () {
clear
echo -e "$bar"
echo -e "  \033[1;37mIngrese el Contacto de ADMIN de su bot"
echo -e "$bar"
echo -n "RESELLER: "
read opction
echo "$opction" > ${CIDdir}/ressx
echo -e "$bar"
read -p "Presione Enter para continuar "
bot_gen
}

systemx (){
    (
        rm -f /bin/http-server.sh
        wget -O /bin/http-server.sh https://gitlab.com/xdanx90/Premium/-/raw/main/install/http-server.sh &>/dev/null && chmod +x /bin/http-server.sh

        cat <<- EOF > /etc/systemd/system/http-server.service
[Unit]
Description=Shell HTTP-Server by @drowkid01
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root
ExecStart=/bin/bash /bin/http-server.sh -start
Restart=always
RestartSec=3s

[Install]
WantedBy=multi-user.target
EOF

        systemctl daemon-reexec &>/dev/null
        systemctl daemon-reload &>/dev/null
        systemctl enable http-server &>/dev/null
        systemctl start http-server &>/dev/null
    ) &>/dev/null && echo -e "\e[92mserver configurado" || echo -e "\e[91mserver no configurado"
}



bot_gen() {
    clear
    
    #Todo lo que tenga que ver con toke id 
    unset PID_GEN
    CIDdir=/etc/CAT-BOT && [[ ! -d ${CIDdir} ]] && mkdir ${CIDdir}
    PID_on=$(ps x|grep -v grep|grep "modelid")
    [[ ! $PID_on ]] && PID_on="\033[1;31mOFF" || PID_on="\033[1;32mON"
    [[ ! -e /etc/systemd/system/btkill.service ]] && PID_kill="\033[1;31mOFF" || PID_kill="\033[1;32mON"
    [[ ! $PID_GEN ]] && PID_GEN="\033[1;31mOFF" || PID_GEN="\033[1;32mON"
    [[ -e ${CIDdir}/Admin-ID ]] && adid="\033[1;32mOK" || adid="\033[1;31mNULL"
    [[ -e ${CIDdir}/token ]] && tk="\033[1;32mOK" || tk="\033[1;31mNULL"

    #Termina
    
    #VERIFICA SI EL PUERTO 8888 ESTA EN LINEA
    PID_GEN1=$(ps x | grep -v grep | grep "8888")
    [[ ! $PID_GEN1 ]] && PID_GEN1="\033[0;31m[\033[0;35mCOLAPZADO REINICIAR\033[0;31m]" || PID_GEN1="\033[0;35m[\033[0;36mFUNCIONANDO\033[0;31m]"
    
    #TERMINA
    unset PID_BOT
    KEYI=$(ps x | grep -v grep | grep "nc.traditional")
    [[ ! $KEYI ]] && BOK="\033[1;31m [ ✖ OFF ✖ ]    " || BOK="\033[1;32m [ ACTIVO ]"
    
    #porta
    
    porta=$(if netstat -tunlp | grep nc.tradit 1>/dev/null 2>/dev/null; then
        echo -e "\033[0;36m   Keygen: \033[0;31m[\033[0;32m ON \033[0;31m]"
        else
        echo -e "\033[0;36m   Keygen: \033[0;35m[\033[0;31m OFF \033[0;35m]"
        
        fi)
    
    
    #Termina
    
    #SI ESTAN ACTIVOS EL BOT Y GEN
    PID_BOT=$(ps x | grep -v grep | grep "BotGen.sh")
    [[ ! $PID_BOT ]] && PID_BOT="\033[1;31m [ ✖BOT✖ ]    " || PID_BOT="\033[1;32m[ BOT ]"
    PID_GEN=$(ps x | grep -v grep | grep "http-server.sh")
    [[ -z $PID_GEN ]] && PID_BT="\033[1;31m [ ✖GEN✖ ]    " || PID_BT="\033[1;32m[ GEN ]"

    #Muestra El encabezado del menu
    msgi -barg
    echo -e "  \e[1;37m COMANDO: vpsbot \e[31m|| \e[1;34mKEY INSTALADAS: \e[1;33m$(cat ${IVAR})"
    echo -e "  \e[1;36mESTADO DEL GENERADOR: \e[1;32m$BOK"
    mine_port
    echo -e "\033[1;37m Sync $(ls ${SCPT_DIR}|wc -l) in \033[1;31m${SCPT_DIR}\033[0m FTP : $(cat /etc/apache2/ports.conf | head -5 | tail -1 | cut -d ' ' -f2) \033[1;37mESTADO\033[0m $PID_GEN1 \n \033[1;41m KEYS $porta" 

    msgi -barg
    echo -e "\033[0;35m [\033[0;36m2\033[0;35m] \033[0;35m-> \033[1;37m TOKEN DEL BOT $tk "
    echo -e "\033[0;35m [\033[0;36m3\033[0;35m] \033[0;35m-> \033[1;37m ID DE USUARIO TELEGRAM  $adid"
    echo -e "\033[0;35m [\033[0;36m4\033[0;35m] \033[0;35m-> \033[1;37m INICIAR/PARAR BOT $PID_BOT\033[0m"
    echo -e " \033[0;35m[\033[0;36m5\033[0;35m] \033[0;34m->\033[0;33m  ON/OFF BOT SYTEMCLY  $PID_BT\033[0m"
    echo -e "\033[1;32m [6] \033[1;36m> \033[1;31mUNISTALL BOT.."
    echo -e "\033[1;32m [7] \033[1;36m> \033[1;32mACTUALIZAR BOT.."
    echo -e " \033[0;35m[\033[0;36m10\033[0;35m] \033[0;34m->\033[0;33m  ALTERAR LIMITE DE KEYS DUAL\033[0m"
    echo -e " \033[0;35m[\033[0;36m11\033[0;35m] \033[0;34m->\033[0;33m  ELIMINAR CONTEOS KEYS Y DEL\033[0m"
    echo -e " \033[0;35m[\033[0;36m12\033[0;35m] \033[0;34m->\033[0;33m  AGREGAR MENSAJE A USUARIOS\033[0m"
    echo -e " \033[0;35m[\033[0;36m14\033[0;35m] \033[0;34m->\033[0;33m  AGREGAR MENSAJE EN LA KEY DUAL\033[0m"
    echo -e " \033[0;35m[\033[0;36m15\033[0;35m] \033[0;34m->\033[0;33m  AGREGAR MENSAJE EN LA KEY FREE\033[0m"
    echo -e " \033[0;35m[\033[0;36m16\033[0;35m] \033[0;34m->\033[0;33m  INGRESAR LIMITE EN LA KEY FREE\033[0m"
    echo -e " \033[0;35m[\033[0;36m17\033[0;35m] \033[0;34m->\033[0;33m  CAMBIAR RESELLER ADMIN\033[0m"
    echo -e " \033[0;35m[\033[0;36m18\033[0;35m] \033[0;34m->\033[0;33m  REINICIAR BOT SYSTEMCLY\033[0m"
    msgi -barg
    echo -e "\e[1;32m [0] \e[36m>\e[0m \e[47m\e[30m <<ATRAS "
    msgi -barg
    echo -n "$(echo -e "\e[1;97m	SELECIONE UNA OPCION:\e[1;93m") "
    read opcion
    case $opcion in
    0) exit 0 ;;
    1) descarga ;;
    2) ini_token ;;
    3) ini_id ;;
    4) start_boti ;;
    5) systemx ;;
    #5) msj_prueba ;;
    9) config;;
    10) alter_limit ;;
    11) alter_id ;;
    12) ini_res;;
    14) ini_res2;;
    15) ini_res3;;
    16) alter_limita ;;
    17) respon ;;
    18) 
    clear 
    echo -e " ACTIVANDO SYSTEMCLY"
    systemctl start http-server
    echo -e "Activado"
    read -p "Presione Enter para continuar "

bot_gen ;;
    
    6) unistall ;;
    7)
        clear
        
        echo -e " DETENIENDO EL BOT PARA NO OBTENER ERRORES\n EN LA ACTUALIZACION...................."
        
        kill -9 $(ps aux | grep -v grep | grep -w "BotGen.sh" | grep dmS | awk '{print $2}') &>/dev/null
        #
        clear
        sleep 0.1s
        echo -e " ACTUALIZANDO BOT KEYGEN"
        sleep 1s
        wget -O /etc/CAT-BOT/BotGen.sh https://www.dropbox.com/s/25xxz39l16wql29/BotGen.sh &>/dev/null
        chmod +x ${CIDdir}/BotGen.sh
         wget -O /root/script.sh https://www.dropbox.com/s/fmz8r86a97srode/script.sh &>/dev/null
         chmod 777 /root/script.sh
        wget -O /bin/vpsbot https://www.dropbox.com/s/tm6wqoq2o9ed36z/instaladorBot &>/dev/null && chmod +x /bin/vpsbot
        sleep 1s
        kill -9 $(ps aux | grep -v grep | grep -w "veri" | grep dmS | awk '{print $2}') &>/dev/null
        wget -O ${CIDdir}/veri https://www.dropbox.com/s/qde9sk498w4mgas/autodel &>/dev/null && chmod 777 ${CIDdir}/veri
        echo -e " BOT ACTUALIZADA CON ÉXITO"
        sleep 1
        rm -rf .bash_history
        vpsbot
        ;;
    esac
}
bot_gen
