#!/bin/bash
# Get Cloudflare Tunnel ID from container
# Run this to find your tunnel ID for DNS configuration

VMID=5000
PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.10}"

echo "Getting Cloudflare Tunnel ID from container $VMID..."
echo ""

# Try to get tunnel ID from config
TUNNEL_ID=$(ssh -o StrictHostKeyChecking=no root@"$PROXMOX_HOST" \
    "pct exec $VMID -- grep -i '^tunnel:' /etc/cloudflared/config.yml 2>/dev/null | awk '{print \$2}' | head -1" 2>/dev/null || echo "")

if [ -n "$TUNNEL_ID" ]; then
    echo "✓ Tunnel ID found: $TUNNEL_ID"
    echo ""
    echo "DNS Configuration:"
    echo "  Type: CNAME"
    echo "  Name: explorer"
    echo "  Target: $TUNNEL_ID.cfargotunnel.com"
    echo "  Proxy: 🟠 Proxied (orange cloud)"
    echo ""
else
    echo "✗ Tunnel ID not found in config"
    echo ""
    echo "To find your tunnel ID:"
    echo "  1. Go to: https://one.dash.cloudflare.com/"
    echo "  2. Navigate to: Zero Trust → Networks → Tunnels"
    echo "  3. Your tunnel ID will be displayed"
    echo ""
    echo "Or check in container:"
    echo "  ssh root@$PROXMOX_HOST"
    echo "  pct exec $VMID -- cat /etc/cloudflared/config.yml | grep tunnel"
fi

