#!/bin/bash
IVAR="/etc/http-instas"
onliCHECK=/var/www/html/drowkid01
LIST="lista-arq"
[[ -d /var/www/html/drowkid01 ]] || mkdir ${onliCHECK}
install_fun () {
apt-get install netcat -y
}
meu_ip_fun () {
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"
}

meu_ip_func () {
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"
}
#OFUSCATE

ofus() {
    unset server
    server=$(echo ${txt_ofuscatw} | cut -d':' -f1)
    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]="v" ;;
      "v") txt[$i]="." ;;
      "1") txt[$i]="@" ;;
      "@") txt[$i]="1" ;;
      "2") txt[$i]="?" ;;
      "?") txt[$i]="2" ;;
      "4") txt[$i]="p" ;;
      "p") txt[$i]="4" ;;
      "-") txt[$i]="L" ;;
      "L") txt[$i]="-" ;;
      esac
      txtofus+="${txt[$i]}"
    done
    echo "$txtofus" | rev
  }

ofusc() {
      unset server
      server=$(echo ${txt_ofuscatw} | cut -d':' -f1)
      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";;
"4")txt[$i]="9";;
"9")txt[$i]="4";;
"6")txt[$i]="P";;
"P")txt[$i]="6";;
"L")txt[$i]="K";;
"K")txt[$i]="L";;
esac
        txtofus+="${txt[$i]}"
      done
      echo "$txtofus" | rev
}


# LISTEN
listen_fun () {
local PORTA="8888" && local PROGRAMA="/bin/http-server.sh"
while true; do nc.traditional -l -p "$PORTA" -e "$PROGRAMA"; done
}
# SERVER
server_fun () {
meu_ip_fun

PORTA="8888"
DIR="/etc/http-shell" #DIRETORIO DAS KEYS ARMAZENADAS
unset ENV_ARQ
	if [[ ! -d $DIR ]]; then mkdir $DIR; fi
read URL
	
	
KEY=$(echo $URL|cut -d' ' -f2|cut -d'/' -f2) && [[ ! $KEY ]] && KEY="ERRO" #KEY
ARQ=$(echo $URL|cut -d' ' -f2|cut -d'/' -f3)  && [[ ! $ARQ ]] && ARQ="ERRO" #LISTA INSTALACAO
USRIP=$(echo $URL|cut -d' ' -f2|cut -d'/' -f4) && [[ ! $USRIP ]] && USRIP="ERRO" #IP Del USUARIO
REQ=$(echo $URL|cut -d' ' -f2|cut -d'/' -f5) && [[ ! $REQ ]] && REQ="ERRO"
	
FILE2="${DIR}/${KEY}"
FILE="${DIR}/${KEY}/$ARQ"
	

	
echo "KEY: $KEY" >&2
echo "LISTA: $ARQ" >&2
echo "IP: $USRIP" >&2
echo "REQ: $REQ" >&2
DIRETORIOKEY="$DIR/$KEY" # DIRETORIO DA KEY
LISTADEARQUIVOS="$DIRETORIOKEY/$ARQ" # LISTA DE ARQUIVOS
if [[ -d "$DIRETORIOKEY" ]]; then #VERIFICANDO SE A CHAVE EXISTE
  if [[ -e "$DIRETORIOKEY/$ARQ" ]]; then #VERIFICANDO LISTA DE ARQUIVOS
  #ENVIA LISTA DE DOWLOADS
  FILE="$DIRETORIOKEY/$ARQ" 
  STATUS_NUMBER="200"
  STATUS_NAME="Found"
  ENV_ARQ="True"
  fi
  if [[ -e "$DIRETORIOKEY/FERRAMENTA" ]]; then #VERIFICA SE A KEY E FERRAMETA
   if [[ ${USRIP} != "ERRO" ]]; then #SE FOR FERRAMENTA O IP NAO DEVE SER ENVIADO
    FILE="${DIR}/ERROR-KEY"
    echo "FERRAMENTA KEY!" > ${FILE}
    ENV_ARQ="False"
   fi
 else
   if [[ ${USRIP} = "ERRO" ]]; then #VERIFICA SE FOR INSTALACAO O IP DEVE SER ENVIADO
    FILE="${DIR}/ERROR-KEY"
    echo "KEY DE INSTALACION!" > ${FILE}
    ENV_ARQ="False"
   fi
 fi
else
# KEY INVALIDA
  FILE="${DIR}/ERROR-KEY"
  echo "KEY INVALIDA!" > ${FILE}
  STATUS_NUMBER="200"
  STATUS_NAME="Found"
  ENV_ARQ="False"
fi
#ENVIA DADOS AO USUARIO
cat << EOF
HTTP/1.1 $STATUS_NUMBER - $STATUS_NAME
Date: $(date)
Server: ShellHTTP
Content-Length: $(wc --bytes "$FILE" | cut -d " " -f1)
Connection: close
Content-Type: text/html; charset=utf-8

$(cat "$FILE")
EOF
if [[ $ENV_ARQ = "True" ]]; then
(
mkdir /var/www/html/$KEY
mkdir /var/www/$KEY
TIME="20+"
  for arqs in `cat $FILE`; do
  cp ${FILE2}/$arqs /var/www/html/$KEY/
  cp ${FILE2}/$arqs /var/www/$KEY/
  TIME+="1+"
  done
_key="$(ofus ${IP}:${PORTA}/${KEY}/${LIST})"
_key="$(ofusc ${IP}:${PORTA}/${KEY}/${LIST})"
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" > /var/www/html/$KEY/checkIP.log
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" > /var/www/$KEY/checkIP.log
RESELL="$(cat /var/www/$KEY/message.txt)"
TIME=$(echo "${TIME}0"|bc)
sleep ${TIME}s
rm -rf /var/www/html/$KEY
rm -rf /var/www/$KEY
log="/etc/gerar-sh-log"
_hora=$(printf '%(%D-%H:%M:%S)T') 
if [[ -d $FILE2 ]]; then
PERM="${DIR}/${KEY}/keyfixa" 
if [[ -e $PERM ]]; then
  if [[ $(cat $PERM) != "$USRIP" ]]; then
  log="/etc/gerar-sh-log"
  echo "$(cat ${FILE2}.name) | IP-FIJA:$USRIP | ${_key} | $_hora" >> $log
  echo "$(cat ${FILE2}.name) | IP-FIJA:$USRIP | ${_key} | $_hora" >> ${onliCHECK}/checkIP.log && chmod +x ${onliCHECK}/checkIP.log
  #cat /etc/gerar-sh-log > ${onliCHECK}/checkIP.log
  rm -rf $FILE2
  rm -f ${FILE2}.name
  fi
else
uid=$(uuidgen)
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" >> $log
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" >> ${onliCHECK}/checkIP.log && chmod +x ${onliCHECK}/checkIP.log
[[ -e /etc/adm-db/token ]] && {
ID="$(cat ${FILE2}.name)" && ID="$(echo $ID | awk '{print $1}' | sed -e 's/[^0-9]//ig')"
[[ ${ID} -lt '999' ]] && ID='7570680285'
TOKEN="$(cat /etc/adm-db/data|awk -F '|' '{print $1}')"
urlBOT="https://api.telegram.org/bot$TOKEN/sendMessage"
#MENSAJE="  =======================================\n"
MENSAJE+="     ️✅   𝗞𝗘𝗬 𝗔𝗖𝗧𝗜𝗩𝗔𝗗𝗔   ✅ \n"
MENSAJE+="\n"
MENSAJE+="🔐 Key Encriptado\n"
MENSAJE+="\n"
MENSAJE+="🔑AES $uid\n"
#MENSAJE+=" =========== ☝️ USADA ☝ ============\n"
MENSAJE+="\n"
MENSAJE+=" 👤 ${RESELL}\n"
MENSAJE+=" 🆔 ${ID} \n"
#MENSAJE+=" =======================================\n"
MENSAJE+=" 🌐 : $USRIP \n"
MENSAJE+=" 🕐 $_hora \n"
MENSAJE+=" INSTALACION N° $(cat ${onliCHECK}/checkIP.log  | wc -l)\n"
MENSAJE+=' ===========▫️NotiBot▫️======\n'
#MENSAJE+='           ⚜ By @ChumoGH ⚜ \n'
#MENSAJE+=" ==========================\n"
#curl -s -X POST $urlBOT -d chat_id=$ID -d text="$(echo -e "$MENSAJE")" &>/dev/null
MENSAJE+='&reply_markup={"inline_keyboard":[[{"text":"KEY DNX","callback_data":"/keygen"},{"text":" SOPORTE ","url":"https://t.me/darnix0"}]]}'
#curl -s -X POST $urlBOT -d chat_id=$ID -d text="$(echo -e "$MENSAJE")" &>/dev/null
#curl -s --max-time 10 -d "chat_id=$ID&disable_web_page_preview=1&text=$(echo -e "$MENSAJE")&parse_mode=html" $urlBOT &>/dev/null
curl -s --max-time 10 -d "chat_id=$ID&disable_web_page_preview=1&text=$(echo -e "$MENSAJE")" ${urlBOT} &>/dev/null
}
rm -rf $FILE2
rm -f ${FILE2}.name
fi
num=$(cat ${IVAR})
 if [[ $num = "" ]]; then
 num=0
 fi
let num++
echo $num > $IVAR
fi
) & > /dev/null
fi
}

server_func () {
meu_ip_func

PORTA="8888"
DIR="/etc/http-shell" #DIRETORIO DAS KEYS ARMAZENADAS
unset ENV_ARQ
	if [[ ! -d $DIR ]]; then mkdir $DIR; fi
read URL
	
	
KEY=$(echo $URL|cut -d' ' -f2|cut -d'/' -f2) && [[ ! $KEY ]] && KEY="ERRO" #KEY
ARQ=$(echo $URL|cut -d' ' -f2|cut -d'/' -f3)  && [[ ! $ARQ ]] && ARQ="ERRO" #LISTA INSTALACAO
USRIP=$(echo $URL|cut -d' ' -f2|cut -d'/' -f4) && [[ ! $USRIP ]] && USRIP="ERRO" #IP Del USUARIO
REQ=$(echo $URL|cut -d' ' -f2|cut -d'/' -f5) && [[ ! $REQ ]] && REQ="ERRO"
	
FILE2="${DIR}/${KEY}"
FILE="${DIR}/${KEY}/$ARQ"
	

	
echo "KEY: $KEY" >&2
echo "LISTA: $ARQ" >&2
echo "IP: $USRIP" >&2
echo "REQ: $REQ" >&2
DIRETORIOKEY="$DIR/$KEY" # DIRETORIO DA KEY
LISTADEARQUIVOS="$DIRETORIOKEY/$ARQ" # LISTA DE ARQUIVOS
if [[ -d "$DIRETORIOKEY" ]]; then #VERIFICANDO SE A CHAVE EXISTE
  if [[ -e "$DIRETORIOKEY/$ARQ" ]]; then #VERIFICANDO LISTA DE ARQUIVOS
  #ENVIA LISTA DE DOWLOADS
  FILE="$DIRETORIOKEY/$ARQ" 
  STATUS_NUMBER="200"
  STATUS_NAME="Found"
  ENV_ARQ="True"
  fi
  if [[ -e "$DIRETORIOKEY/FERRAMENTA" ]]; then #VERIFICA SE A KEY E FERRAMETA
   if [[ ${USRIP} != "ERRO" ]]; then #SE FOR FERRAMENTA O IP NAO DEVE SER ENVIADO
    FILE="${DIR}/ERROR-KEY"
    echo "FERRAMENTA KEY!" > ${FILE}
    ENV_ARQ="False"
   fi
 else
   if [[ ${USRIP} = "ERRO" ]]; then #VERIFICA SE FOR INSTALACAO O IP DEVE SER ENVIADO
    FILE="${DIR}/ERROR-KEY"
    echo "KEY DE INSTALACION!" > ${FILE}
    ENV_ARQ="False"
   fi
 fi
else
# KEY INVALIDA
  FILE="${DIR}/ERROR-KEY"
  echo "KEY INVALIDA!" > ${FILE}
  STATUS_NUMBER="200"
  STATUS_NAME="Found"
  ENV_ARQ="False"
fi
#ENVIA DADOS AO USUARIO
cat << EOF
HTTP/1.1 $STATUS_NUMBER - $STATUS_NAME
Date: $(date)
Server: ShellHTTP
Content-Length: $(wc --bytes "$FILE" | cut -d " " -f1)
Connection: close
Content-Type: text/html; charset=utf-8

$(cat "$FILE")
EOF
if [[ $ENV_ARQ = "True" ]]; then
(
mkdir /var/www/html/$KEY
mkdir /var/www/$KEY
TIME="20+"
  for arqs in `cat $FILE`; do
  cp ${FILE2}/$arqs /var/www/html/$KEY/
  cp ${FILE2}/$arqs /var/www/$KEY/
  TIME+="1+"
  done
#_key="$(ofus ${IP}:${PORTA}/${KEY}/${LIST})"
_key="$(ofusc ${IP}:${PORTA}/${KEY}/${LIST})"
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" > /var/www/html/$KEY/checkIP.log
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" > /var/www/$KEY/checkIP.log
RESELL="$(cat /var/www/$KEY/message.txt)"
TIME=$(echo "${TIME}0"|bc)
sleep ${TIME}s
rm -rf /var/www/html/$KEY
rm -rf /var/www/$KEY
log="/etc/gerar-sh-log"
_hora=$(printf '%(%D-%H:%M:%S)T') 
if [[ -d $FILE2 ]]; then
PERM="${DIR}/${KEY}/keyfixa" 
if [[ -e $PERM ]]; then
  if [[ $(cat $PERM) != "$USRIP" ]]; then
  log="/etc/gerar-sh-log"
  echo "$(cat ${FILE2}.name) | IP-FIJA:$USRIP | ${_key} | $_hora" >> $log
  echo "$(cat ${FILE2}.name) | IP-FIJA:$USRIP | ${_key} | $_hora" >> ${onliCHECK}/checkIP.log && chmod +x ${onliCHECK}/checkIP.log
  #cat /etc/gerar-sh-log > ${onliCHECK}/checkIP.log
  rm -rf $FILE2
  rm -f ${FILE2}.name
  fi
else
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" >> $log
echo "$(cat ${FILE2}.name) | $USRIP | ${_key} | $_hora" >> ${onliCHECK}/checkIP.log && chmod +x ${onliCHECK}/checkIP.log
[[ -e /etc/adm-db/token ]] && {
ID="$(cat ${FILE2}.name)" && ID="$(echo $ID | awk '{print $1}' | sed -e 's/[^0-9]//ig')"
[[ ${ID} -lt '999' ]] && ID='7570680285'
TOKEN="$(cat /etc/adm-db/token)"
urlBOT="https://api.telegram.org/bot$TOKEN/sendMessage"
#MENSAJE="  =======================================\n"
MENSAJE+="     ❗️𝗞𝗘𝗬 𝗔𝗖𝗧𝗜𝗩𝗔𝗗𝗔❗️ \n"
#MENSAJE+=" ❯ ══━━━━⎊⎊━━━━══ ❮\n"
MENSAJE+="🔑 ${_key}\n"
#MENSAJE+=" =========== ☝️ USADA ☝ ============\n"
#MENSAJE+="            ☝️ USADA ☝️ \n"
MENSAJE+=" 👤 ${RESELL}\n"
MENSAJE+=" 🆔 ${ID} \n"
#MENSAJE+=" =======================================\n"
MENSAJE+=" 🌐 : $USRIP \n"
MENSAJE+=" 🕐 $_hora \n"
MENSAJE+=" INSTALACION N° $(cat ${onliCHECK}/checkIP.log  | wc -l)\n"
MENSAJE+=' ===========▫️NotiBotC▫️======\n'
#MENSAJE+='           ⚜ By @ChumoGH ⚜ \n'
#MENSAJE+=" ==========================\n"
#curl -s -X POST $urlBOT -d chat_id=$ID -d text="$(echo -e "$MENSAJE")" &>/dev/null
MENSAJE+='&reply_markup={"inline_keyboard":[[{"text":"KEY DNX","callback_data":"/keygen"},{"text":" SOPORTE ","url":"https://t.me/darnix0"}]]}'
#curl -s -X POST $urlBOT -d chat_id=$ID -d text="$(echo -e "$MENSAJE")" &>/dev/null
#curl -s --max-time 10 -d "chat_id=$ID&disable_web_page_preview=1&text=$(echo -e "$MENSAJE")&parse_mode=html" $urlBOT &>/dev/null
curl -s --max-time 10 -d "chat_id=$ID&disable_web_page_preview=1&text=$(echo -e "$MENSAJE")" ${urlBOT} &>/dev/null
}
rm -rf $FILE2
rm -f ${FILE2}.name
fi
num=$(cat ${IVAR})
 if [[ $num = "" ]]; then
 num=0
 fi
let num++
echo $num > $IVAR
fi
) & > /dev/null
fi
}

[[ $1 = @(-[Ss]tart|-[Ss]|-[Ii]niciar) ]] && listen_fun && exit
[[ $1 = @(-[Ii]stall|-[Ii]|-[Ii]stalar) ]] && listen_fun && exit
server_fun
server_func
