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

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=$(curl -sS ipv4.icanhazip.com)
domain=$(cat /etc/xray/domain)
date=$(date +"%Y-%m-%d")
clear
function notif_restore() {
sleep 2
CHATID="$CHATID"
KEY="$KEY"
TIME="$TIME"
URL="$URL"
TEXT="
<code>☉────────────────────────☉</code>
🧿Restore Vps Server Success🧿
<code>☉────────────────────────☉</code>
<code>Subdomain vps :</code> <code>$domain</code>
<code>IP Server vps :</code> <code>$IP</code>
<code>Date Restoree :</code> <code>$date</code>
<code>☉────────────────────────☉</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 "▒█▀▀█ ▒█▀▀▀ ▒█▀▀▀█ ▀▀█▀▀ ▒█▀▀▀█ ▒█▀▀█ ▒█▀▀▀\033[0m" 
echo -e "▒█▄▄▀ ▒█▀▀▀ ░▀▀▀▄▄ ░▒█░░ ▒█░░▒█ ▒█▄▄▀ ▒█▀▀▀\033[0m" 
echo -e "▒█░▒█ ▒█▄▄▄ ▒█▄▄▄█ ░▒█░░ ▒█▄▄▄█ ▒█░▒█ ▒█▄▄▄\033[0m"
echo -e "\e[33m───────────────────────────────────────────\033[0m"
echo -e "Please Enter A Backup Link"
read -rp "Link File : " -e url
echo -e "\e[33m───────────────────────────────────────────\033[0m"
cd /root
rm -rf /root/backup
wget -O backup.zip "$url"
unzip backup.zip
rm -f backup.zip
echo -e "Start Restore In Process"
sleep 3
mkdir -p /etc/xray/ > /dev/null 2>&1
cd /root/backup/ > /dev/null 2>&1
cp -f /root/backup/passwd /etc/
cp -f /root/backup/group /etc/
cp -f /root/backup/shadow /etc/
cp -f /root/backup/gshadow /etc/
cp -r /root/backup/limit/ssh/ip/* /etc/kyt/limit/ssh/ip > /dev/null 2>&1
cp -r /root/backup/limit/vmess/ip/* /etc/kyt/limit/vmess/ip > /dev/null 2>&1
cp -r /root/backup/limit/vless/ip/* /etc/kyt/limit/vless/ip > /dev/null 2>&1
cp -r /root/backup/limit/trojan/ip/* /etc/kyt/limit/trojan/ip > /dev/null 2>&1
cp -r /root/backup/quota/vmess/* /etc/vmess/ > /dev/null 2>&1
cp -r /root/backup/quota/vless/* /etc/vless/ > /dev/null 2>&1
cp -r /root/backup/quota/trojan/* /etc/trojan/ > /dev/null 2>&1
cp -r /root/backup/quotax/vmess/* /etc/limit/vmess/ > /dev/null 2>&1
cp -r /root/backup/quotax/vless/* /etc/limit/vless/ > /dev/null 2>&1
cp -r /root/backup/quotax/trojan/* /etc/limit/trojan/ > /dev/null 2>&1
cp -f /root/backup/xray/* /etc/xray/
cp -f /root/backup/html/* /var/www/html/ > /dev/null 2>&1
cp -f /root/backup/.ssh.db /etc/ssh/ > /dev/null 2>&1
cp -f /root/backup/.vmess.db /etc/vmess/ > /dev/null 2>&1
cp -f /root/backup/.vless.db /etc/vless/ > /dev/null 2>&1
cp -f /root/backup/.trojan.db /etc/trojan/ > /dev/null 2>&1
systemctl restart xray
systemctl restart ssh
notif_restore
rm -rf /root/backup
rm -f backup.zip

clear
echo -e "\e[33m──────────────────────────────────────────\033[0m"
echo -e "\E[40;1;37m        RESTORE VPS SERVER SUCCESS        \E[0m"
echo -e "\e[33m──────────────────────────────────────────\033[0m"
echo -e "Subdomain vps : $domain"
echo -e "IP Server vps : $IP"
echo -e "Date Restoree : $date"
echo -e "\e[33m──────────────────────────────────────────\033[0m"
echo -e ""
read -n 1 -s -r -p "Press any key to back"
menu