#!/bin/bash

# COLOR VALIDATION
RED='\033[0;31m'
NC='\033[0m'
gray="\e[1;30m"
Blue="\033[36m"
GREEN='\033[0;32m'
grenbo="\e[92;1m"
yellow='\033[0;33m'
ISP=$(cat /etc/xray/isp)
CITY=$(cat /etc/xray/city)
domain=$(cat /etc/xray/domain)
WKT=$(curl -s ipinfo.io/timezone)
IPVPS=$(curl -s ipv4.icanhazip.com)
tram=$(free -m | awk 'NR==2 {print $2}')
swap=$(free -m | awk 'NR==4 {print $2}')

Open_SSH=$(systemctl status ssh | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Dropbear=$(systemctl status dropbear | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Dropbear_Websocket=$(systemctl status dropbear | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
SSH_Websocket=$(systemctl status ws | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
OpenVPN=$(systemctl status openvpn | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Nginx_Webserver=$(systemctl status nginx | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Haproxy=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
DNS_Server=$(systemctl status server | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
DNS_Client=$(systemctl status client | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
OpenVPN_Websocket=$(systemctl status ws | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vmess_TLS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vmess_gRPC=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vmess_None_TLS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vless_TLS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vless_gRPC=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
XRAY_Vless_None_TLS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Trojan_gRPC=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Trojan_WS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Shadowsocks_WS=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Shadowsocks_gRPC=$(systemctl status haproxy | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Iptables=$(systemctl status netfilter-persistent | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Squid=$(systemctl status udp-mini-2 | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
BadVPN=$(systemctl status udp-mini-1 | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
RClocal=$(systemctl status rc-local | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
Autorebot=$(systemctl status rc-local | grep active | awk '{print $3}' | sed 's/(//g' | sed 's/)//g')
OSSSS=$(cat /etc/os-release | grep -w PRETTY_NAME | head -n1 | sed 's/=//g' | sed 's/"//g' | sed 's/PRETTY_NAME//g')
if [[ $Open_SSH == "running" ]]; then
    status_1="🟢 Online"
else
    status_1="🔴 Offline"
fi

if [[ $Dropbear == "running" ]]; then
    status_2="🟢 Online"
else
    status_2="🔴 Offline"
fi

if [[ $Dropbear_Websocket == "running" ]]; then
    status_3="🟢 Online"
else
    status_3="🔴 Offline"
fi

if [[ $SSH_Websocket == "running" ]]; then
    status_4="🟢 Online"
else
    status_4="🔴 Offline"
fi

if [[ $OpenVPN == "exited" ]]; then
    status_5="🟢 Online"
else
    status_5="🔴 Offline"
fi

if [[ $Nginx_Webserver == "running" ]]; then
    status_6="🟢 Online"
else
    status_6="🔴 Offline"
fi

if [[ $Haproxy == "running" ]]; then
    status_7="🟢 Online"
else
    status_7="🔴 Offline"
fi

if [[ $DNS_Server == "running" ]]; then
    status_8="🟢 Online"
else
    status_8="🔴 Offline"
fi

if [[ $DNS_Client == "running" ]]; then
    status_9="🟢 Online"
else
    status_9="🔴 Offline"
fi

if [[ $OpenVPN_Websocket == "running" ]]; then
    status_10="🟢 Online"
else
    status_10="🔴 Offline"
fi

if [[ $XRAY_Vmess_TLS == "running" ]]; then
    status_11="🟢 Online"
else
    status_11="🔴 Offline"
fi

if [[ $XRAY_Vmess_gRPC == "running" ]]; then
    status_12="🟢 Online"
else
    status_12="🔴 Offline"
fi

if [[ $XRAY_Vmess_None_TLS == "running" ]]; then
    status_13="🟢 Online"
else
    status_13="🔴 Offline"
fi

if [[ $XRAY_Vless_TLS == "running" ]]; then
    status_14="🟢 Online"
else
    status_14="🔴 Offline"
fi

if [[ $XRAY_Vless_gRPC == "running" ]]; then
    status_15="🟢 Online"
else
    status_15="🔴 Offline"
fi

if [[ $XRAY_Vless_None_TLS == "running" ]]; then
    status_16="🟢 Online"
else
    status_16="🔴 Offline"
fi

if [[ $Trojan_gRPC == "running" ]]; then
    status_17="🟢 Online"
else
    status_17="🔴 Offline"
fi

if [[ $Trojan_WS == "running" ]]; then
    status_18="🟢 Online"
else
    status_18="🔴 Offline"
fi

if [[ $Shadowsocks_WS == "running" ]]; then
    status_19="🟢 Online"
else
    status_19="🔴 Offline"
fi

if [[ $Shadowsocks_gRPC == "running" ]]; then
    status_20="🟢 Online"
else
    status_20="🔴 Offline"
fi

if [[ $Iptables == "exited" ]]; then
    status_21="🟢 Online"
else
    status_21="🔴 Offline"
fi

if [[ $Squid == "running" ]]; then
    status_22="🟢 Online"
else
    status_22="🔴 Offline"
fi

if [[ $BadVPN == "running" ]]; then
    status_23="🟢 Online"
else
    status_23="🔴 Offline"
fi

if [[ $RClocal == "exited" ]]; then
    status_24="🟢 Online"
else
    status_24="🔴 Offline"
fi

if [[ $Autorebot == "exited" ]]; then
    status_25="🟢 Online"
else
    status_25="🔴 Offline"
fi

# // Information user
myip=$(curl -sS ipv4.icanhazip.com)
url_izin="https://raw.githubusercontent.com/FdlyMots/izin/main/ip"
username=$(curl -sS $url_izin | grep $myip | awk '{print $2}')
exp=$(curl -sS $url_izin | grep $myip | awk '{print $3}')
# CERTIFICATE STATUS
d1=$(date -d "$exp" +%s)
d2=$(date -d "$today" +%s)
certifacate=$(((d1 - d2) / 86400))
# VPS Information
DATE=$(date +'%Y-%m-%d')
datediff() {
    d1=$(date -d "$1" +%s)
    d2=$(date -d "$2" +%s)
    echo -e "$COLOR1 $NC Expiry In   : $(( (d1 - d2) / 86400 )) Days"
}
mai="datediff "$Exp" "$DATE""


printf "
━━━━━━━━━━━━━━━━━━━━━━━ 
   👨‍💻PREMIUM PANEL MENU👨‍💻
━━━━━━━━━━━━━━━━━━━━━━━ 
🔰 » Client Name  : $username
🔰 » Total RAM    : $tram MB
🔰 » City Server  : $CITY
🔰 » Domain       : $(cat /etc/xray/domain)
🔰 » Exp Script   : $exp ( $certifacate )
🔰 » Version BOT  : Version 2.0.1
━━━━━━━━━━━━━━━━━━━━━━━
   👨‍💻 SERVICE VPS INFO 👨‍💻
━━━━━━━━━━━━━━━━━━━━━━━
Open_SSH        : $status_1
Dropbear        : $status_2
SSH_Websocket   : $status_4
OpenVPN         : $status_5
Nginx_Webserver : $status_6
Haproxy         : $status_7
OpenVPN_WS      : $status_10
Xray_Vmess      : $status_11
Xray_Vless      : $status_14
Trojan_WS       : $status_18
Shadowsocks     : $status_19
Iptables        : $status_21
Squid           : $status_22
BadVPN          : $status_23
RClocal         : $status_24
Autoreboot      : $status_25
━━━━━━━━━━━━━━━━━━━━━━━
"

