#!/bin/bash
# https://t.me/gemilangkinasih

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)

# SSH count
if [ -f "/etc/ssh/.ssh.db" ]; then
    ssh1=$(grep -c -E "^### " "/etc/ssh/.ssh.db" 2>/dev/null)
else
    ssh1="$(awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd | wc -l)"
fi
ssh1=${ssh1:-0}

# VMess count
if [ -f "/etc/xray/vmess/.vmess.db" ]; then
    vma=$(grep -c -E "^### " "/etc/xray/vmess/.vmess.db" 2>/dev/null)
elif [ -f "/etc/xray/vmess/config.json" ]; then
    vmc=$(grep -c -E "^### " "/etc/xray/vmess/config.json" 2>/dev/null)
    vma=$((vmc / 2))
else
    vma=0
fi
vma=${vma:-0}

# VLess count
if [ -f "/etc/xray/vless/.vless.db" ]; then
    vla=$(grep -c -E "^### " "/etc/xray/vless/.vless.db" 2>/dev/null)
elif [ -f "/etc/xray/vless/config.json" ]; then
    vlx=$(grep -c -E "^### " "/etc/xray/vless/config.json" 2>/dev/null)
    vla=$((vlx / 2))
else
    vla=0
fi
vla=${vla:-0}

# Trojan count
if [ -f "/etc/xray/trojan/.trojan.db" ]; then
    trb=$(grep -c -E "^### " "/etc/xray/trojan/.trojan.db" 2>/dev/null)
elif [ -f "/etc/xray/trojan/config.json" ]; then
    trx=$(grep -c -E "^### " "/etc/xray/trojan/config.json" 2>/dev/null)
    trb=$((trx / 2))
else
    trb=0
fi
trb=${trb:-0}

clear

echo "$ISP"
echo "$CITY"
echo "$domain"
echo "$ssh1" 
echo "$vma" 
echo "$vla" 
echo "$trb"
