#!/bin/bash

# Cloudflare Tunnel Script for BukidBounty App
# This script uses Docker to create a temporary Cloudflare tunnel for port 9522

echo "🚀 Starting Cloudflare Tunnel for localhost:9522..."
echo "----------------------------------------------------"

# Check if Docker is installed
if ! command -v docker &> /dev/null
then
    echo "❌ Error: Docker is not installed. Please install Docker to run this tunnel."
    exit 1
fi

# Check if a token was provided as an argument
if [ -z "$1" ]; then
    echo "ℹ️ No token provided. Creating a temporary 'trycloudflare.com' tunnel..."
    docker run --rm -it --network host cloudflare/cloudflared tunnel --url http://localhost:9522
else
    echo "ℹ️ Using provided Cloudflare Tunnel token..."
    docker run --rm -it --network host cloudflare/cloudflared tunnel --no-autoupdate run --token "$1"
fi
