#!/bin/bash

# Host WAN IP (normal internet)
REAL_IP=$(curl -s --max-time 5 https://ifconfig.me/ip)

# SAB VPN container WAN IP
VPN_IP=$(timeout 10 docker exec sab curl -s --max-time 5 https://ifconfig.me/ip)

if [[ -z "$VPN_IP" ]]; then
    LABEL="VPN Down"
    STATUS="red"

elif [[ "$VPN_IP" == "$REAL_IP" ]]; then
    LABEL="VPN LEAK"
    STATUS="red"

else
    LABEL="VPN Protected"
    STATUS="green"
fi

cat > /mnt/user/appdata/homepage/vpn-status.json <<EOF
{
  "label": "$LABEL",
  "status": "$STATUS",
  "vpn_ip": "$VPN_IP",
  "real_ip": "$REAL_IP"
}
EOF
