#!/bin/bash
# AUTOSCRIPT INTERFLAZZ ID

# Getting
CHATID=$(cat /root/telebotvpn/idteleowner 2>/dev/null)
KEY=$(cat /root/telebotvpn/tokentelebotserver 2>/dev/null)
TIME="10"
URL="https://api.telegram.org/bot$KEY/sendMessage"
IP=$(cat /etc/xray/ipvps 2>/dev/null || wget -qO- ipv4.icanhazip.com)
ISP=$(cat /etc/xray/isp 2>/dev/null || echo "Unknown ISP")
CITY=$(cat /etc/xray/city 2>/dev/null || echo "Unknown City")
domain=$(cat /etc/xray/domain 2>/dev/null || hostname -f)

read -p "Input Username Account : " User

if ! grep -qiw "$User" /etc/passwd; then
    echo -e "Username tidak ada."
    exit 0
fi

STATUS=$(passwd -S "$User" 2>/dev/null | awk '{print $2}')
if [ "$STATUS" != "L" ]; then
    echo -e "Username unlocked."
    exit 0
fi

current_exp=$(chage -l $User | grep "Account expires" | awk -F": " '{print $2}')
formatted_date=$(date -d "$current_exp" +"%Y-%m-%d" 2>/dev/null || date +"%Y-%m-%d")
passwd -u $User &> /dev/null

TEXT="
──────────────────────
Unlocked Account SSHWS Success
──────────────────────
<code>✧ Host  :</code> <code>$domain</code>
<code>✧ User  :</code> <code>$User</code>
<code>✧ Exp   :</code> <code>$formatted_date</code>
────────────────────── "

curl -s --max-time $TIME -d "chat_id=$CHATID&disable_web_page_preview=1&text=$TEXT&parse_mode=html" $URL >/dev/null
atq | awk '{print $1}' | while read job; do at -c "$job" | grep -q "autobackupbot" && atrm "$job"; done &> /dev/null
echo "autobackupbot" | at now + 30 minutes &> /dev/null

echo "$User"
echo "$formatted_date"