#!/bin/bash

# Function to display network information
show_network_info() {
    echo "=== Exploit Seek v1.2 ==="
    echo "=== Starting services... ==="
    date "+%Y-%m-%d %H:%M:%S"
    echo "=== Available addresses ==="
    echo "Container IP addresses:"
    hostname -I | tr ' ' '\n' | while read ip; do
        if [ ! -z "$ip" ]; then
            echo "  http://$ip:5000 - Server API"
            echo "  http://$ip:8080 - Client Interface"
        fi
    done
    
    echo "Host addresses:"
    # Try different methods to get host IP
    HOST_IP=$(ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K\S+' || hostname -I | awk '{print $1}')
    if [ ! -z "$HOST_IP" ]; then
        echo "  http://$HOST_IP:5000 - Server API (Host)"
        echo "  http://$HOST_IP:8080 - Client Interface (Host)"
    fi
    
    echo "Local addresses:"
    echo "  http://localhost:5000 - Server API"
    echo "  http://localhost:8080 - Client Interface"
    echo "  http://127.0.0.1:5000 - Server API"
    echo "  http://127.0.0.1:8080 - Client Interface"
    echo "=========================="
}

# Show network information
show_network_info

# Start the Python server in the background
cd /app
gunicorn --worker-class gevent \
         --workers 2 \
         --timeout 300 \
         --max-requests 1000 \
         --max-requests-jitter 50 \
         --keep-alive 5 \
         --log-level info \
         --bind 0.0.0.0:5000 server:app &

# Start the client server with all interfaces
cd /app/client
serve -s dist -l tcp://0.0.0.0:8080 