# !/bin/bash
# ████████╗░█████╗░██╗░░██╗░█████╗░██╗░░░██╗██████╗░███╗░░██╗
# ╚══██╔══╝██╔══██╗██║░██╔╝██╔══██╗██║░░░██║██╔══██╗████╗░██║
# ░░░██║░░░██║░░██║█████═╝░██║░░██║╚██╗░██╔╝██████╔╝██╔██╗██║
# ░░░██║░░░██║░░██║██╔═██╗░██║░░██║░╚████╔╝░██╔═══╝░██║╚████║
# ░░░██║░░░╚█████╔╝██║░╚██╗╚█████╔╝░░╚██╔╝░░██║░░░░░██║░╚███║
# ░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝░╚════╝░░░░╚═╝░░░╚═╝░░░░░╚═╝░░╚══╝

BICyan='\033[1;96m'       # Cyan
BIWhite='\033[1;97m'      # White
UWhite='\033[4;37m'       # White
BIYellow='\033[1;93m'     # Yellow
BGWHITE='\E[40;1;37m'     # Bgwhite

RED="\033[31m"
NC='\e[0m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
YELL='\033[0;33m'

# Getting
CHATID=$(grep -E "^#bot# " "/etc/bot/.bot.db" | cut -d ' ' -f 3)
KEY=$(grep -E "^#bot# " "/etc/bot/.bot.db" | cut -d ' ' -f 2)
TIME="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
IP=$(cat /etc/xray/ipvps)
ISP=$(cat /etc/xray/isp)
CITY=$(cat /etc/xray/city)
domain=$(cat /etc/xray/domain)

clear
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${BGWHITE}    CREATE SSH & OPENVPN ACCOUNT   ${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
read -p "Username : " Login
read -p "Password : " Pass
read -p "Limit IP : " iplimit
read -p "Expired  : " masaaktif
echo -e "${BIYellow}───────────────────────────────────${NC}"

if grep -qiw "$Login" /etc/passwd; then
clear
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${BGWHITE}    CREATE SSH & OPENVPN ACCOUNT   ${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e ""
echo -e "Username has been used."
echo -e ""
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e ""
read -n 1 -s -r -p "Press any key to back"
m-sshws
fi

# limitip
if [[ $iplimit -gt 0 ]]; then
mkdir -p /etc/kyt/limit/ssh/ip
echo -e "$iplimit" > /etc/kyt/limit/ssh/ip/$Login
else
echo > /dev/null
fi

tgl=$(date -d "$masaaktif days" +"%d")
bln=$(date -d "$masaaktif days" +"%b")
bln1=$(date -d "$masaaktif days" +"%m")
thn=$(date -d "$masaaktif days" +"%Y")
expe="$tgl $bln, $thn"
exp_formatted="$thn-$bln1-$tgl"
tgl2=$(date +"%d")
bln2=$(date +"%b")
thn2=$(date +"%Y")
tnggl="$tgl2 $bln2, $thn2"
useradd -e `date -d "$masaaktif days" +"%Y-%m-%d"` -s /bin/false -M $Login
exp="$(chage -l $Login | grep "Account expires" | awk -F": " '{print $2}')"
echo -e "$Pass\n$Pass\n"| passwd $Login &> /dev/null
hariini=`date -d "0 days" +"%Y-%m-%d"`
expi=`date -d "$masaaktif days" +"%Y-%m-%d"`

DATADB=$(cat /etc/ssh/.ssh.db | grep "^###" | grep -w "${Login}" | awk '{print $2}')
if [[ "${DATADB}" != '' ]]; then
  sed -i "/\b${Login}\b/d" /etc/ssh/.ssh.db
fi
echo "### ${Login} ${expi} ${Pass}" >> /etc/ssh/.ssh.db

cat > /var/www/html/ssh-$Login.txt <<-END
----------------------
Status Create SSHWS Success
----------------------
ISP   : $ISP
City  : $CITY
----------------------
Host  : $domain
User  : $Login
pw    : $Pass
Max   : $iplimit IP
Port  : 443, 80, 1-65535
----------------------
SSL   : $domain:443@$Login:$Pass
----------------------
WS    : $domain:80@$Login:$Pass
----------------------
UDP   : $domain:1-65535@$Login:$Pass
----------------------
Exp   : $exp_formatted
----------------------
END

clear

TEXT="
──────────────────────
Status Create SSHWS Success
──────────────────────
<code>✧ ISP   :</code> <code>$ISP</code>
<code>✧ City  :</code> <code>$CITY</code>
──────────────────────
<code>✧ Host  :</code> <code>$domain</code>
<code>✧ IP    :</code> <code>$IP</code>
<code>✧ User  :</code> <code>$Login</code>
<code>✧ pw    :</code> <code>$Pass</code>
<code>✧ Max   :</code> <code>$iplimit IP</code>
<code>✧ Port  :</code> <code>443, 80, 1-65535</code>
──────────────────────
<code>✧ SSL   :</code> <code>$domain:443@$Login:$Pass</code>
──────────────────────
<code>✧ WS    :</code> <code>$domain:80@$Login:$Pass</code>
──────────────────────
<code>✧ UDP   :</code> <code>$domain:1-65535@$Login:$Pass</code>
──────────────────────
<code>✧ Doc   :</code> https://${domain}:81/ssh-$Login.txt
──────────────────────
<code>✧ Exp   :</code> <code>$exp_formatted</code>
────────────────────── "

curl -s --max-time $TIME -d "chat_id=$CHATID&disable_web_page_preview=1&text=$TEXT&parse_mode=html" $URL >/dev/null

clear
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}Status Create SSHWS Success${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ ISP   : $ISP"
echo -e "${NC}✧ City  : $CITY"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ Host  : $domain${NC}"
echo -e "${NC}✧ IP    : $IP${NC}"
echo -e "${NC}✧ User  : $Login${NC}"
echo -e "${NC}✧ Pw    : $Pass${NC}"
echo -e "${NC}✧ Max   : $iplimit User${NC}"
echo -e "${NC}✧ Port  : 443, 80, 1-65535${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ SSL   : $domain:443@$Login:$Pass${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ WS    : $domain:80@$Login:$Pass${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ UDP   : $domain:1-65535@$Login:$Pass${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ Doc   : https://${domain}:81/ssh-$Login.txt${NC}"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e "${NC}✧ Exp   : $exp_formatted"
echo -e "${BIYellow}───────────────────────────────────${NC}"
echo -e ""
read -n 1 -s -r -p "Press any key to back"
m-sshws