#!/bin/bash
echo "=== GDS Turismo Admin Panel Deep Probe ==="
echo "Started: $(date)"

# Extract JS bundles from admin panels
echo "========== admin.havanatursa.com JS Bundles =========="
html=$(proxychains4 -q curl -ks --connect-timeout 15 -m 30 "https://admin.havanatursa.com/" 2>/dev/null)
echo "$html" | grep -oP 'src="[^"]*"' | head -20
echo "$html" | grep -oP 'href="[^"]*\.css"' | head -10
echo ""

# Get main JS bundle
mainjs=$(echo "$html" | grep -oP 'src="([^"]*main[^"]*\.js)"' | head -1 | grep -oP '"[^"]*"' | tr -d '"')
if [ -n "$mainjs" ]; then
  echo "--- Main JS: $mainjs ---"
  proxychains4 -q curl -ks --connect-timeout 15 -m 60 "https://admin.havanatursa.com/${mainjs}" > /tmp/gds-admin-main.js 2>/dev/null
  echo "Size: $(wc -c < /tmp/gds-admin-main.js) bytes"

  # Extract API URLs
  echo "--- API URLs in main.js ---"
  grep -oP 'https?://[a-zA-Z0-9._/-]+' /tmp/gds-admin-main.js | sort -u
  echo ""

  # Extract route patterns
  echo "--- Routes ---"
  grep -oP '"/(api|v1|auth|admin|dashboard|users|hotels|bookings|payments|config|settings)[^"]*"' /tmp/gds-admin-main.js | sort -u | head -30
  echo ""

  # Extract environment/config
  echo "--- Environment vars ---"
  grep -oP '(apiUrl|baseUrl|API_URL|BASE_URL|environment|production|apiEndpoint)[^,}]*' /tmp/gds-admin-main.js | head -20
fi

echo ""
echo "========== admin.cubanacansa.com (Different App) =========="
html2=$(proxychains4 -q curl -ks --connect-timeout 15 -m 30 "https://admin.cubanacansa.com/" 2>/dev/null)
echo "$html2" | grep -oP 'src="[^"]*"' | head -20
mainjs2=$(echo "$html2" | grep -oP 'src="([^"]*main[^"]*\.js)"' | head -1 | grep -oP '"[^"]*"' | tr -d '"')
if [ -n "$mainjs2" ]; then
  echo "--- Main JS: $mainjs2 ---"
  proxychains4 -q curl -ks --connect-timeout 15 -m 60 "https://admin.cubanacansa.com/${mainjs2}" > /tmp/gds-cubanacan-main.js 2>/dev/null
  echo "Size: $(wc -c < /tmp/gds-cubanacan-main.js) bytes"
  echo "--- API URLs ---"
  grep -oP 'https?://[a-zA-Z0-9._/-]+' /tmp/gds-cubanacan-main.js | sort -u
fi

echo ""
echo "========== admin.cislapradera.com (Different App) =========="
html3=$(proxychains4 -q curl -ks --connect-timeout 15 -m 30 "https://admin.cislapradera.com/" 2>/dev/null)
echo "$html3" | grep -oP 'src="[^"]*"' | head -20
mainjs3=$(echo "$html3" | grep -oP 'src="([^"]*main[^"]*\.js)"' | head -1 | grep -oP '"[^"]*"' | tr -d '"')
if [ -n "$mainjs3" ]; then
  echo "--- Main JS: $mainjs3 ---"
  proxychains4 -q curl -ks --connect-timeout 15 -m 60 "https://admin.cislapradera.com/${mainjs3}" > /tmp/gds-pradera-main.js 2>/dev/null
  echo "Size: $(wc -c < /tmp/gds-pradera-main.js) bytes"
  echo "--- API URLs ---"
  grep -oP 'https?://[a-zA-Z0-9._/-]+' /tmp/gds-pradera-main.js | sort -u
fi

# Probe common admin API paths
echo ""
echo "========== Admin API Path Discovery =========="
for domain in "admin.havanatursa.com" "admin.grupocubanacan.com"; do
  echo "--- $domain ---"
  for path in "/api" "/api/v1" "/api/login" "/api/auth" "/api/users" "/api/config" "/api/dashboard" "/api/hotels" "/api/bookings" "/api/payments" "/api/agencies" "/graphql" "/auth/login" "/auth/token"; do
    status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 15 "https://${domain}${path}" 2>/dev/null)
    code=$(echo $status | cut -d'|' -f1)
    size=$(echo $status | cut -d'|' -f2)
    if [ "$code" != "000" ] && [ "$code" != "404" ]; then
      echo "  [$code] $path (${size}B)"
    fi
  done
done

# Check PeopleGoTo (tienda platform)
echo ""
echo "========== tienda.peoplegoto.com Deep =========="
html4=$(proxychains4 -q curl -ks --connect-timeout 15 -m 30 "https://tienda.peoplegoto.com/" 2>/dev/null)
echo "$html4" | grep -oP 'src="[^"]*\.js"' | head -10
mainjs4=$(echo "$html4" | grep -oP 'src="([^"]*main[^"]*\.js)"' | head -1 | grep -oP '"[^"]*"' | tr -d '"')
if [ -n "$mainjs4" ]; then
  echo "--- Main JS: $mainjs4 ---"
  proxychains4 -q curl -ks --connect-timeout 15 -m 60 "https://tienda.peoplegoto.com/${mainjs4}" > /tmp/peoplegoto-main.js 2>/dev/null
  echo "Size: $(wc -c < /tmp/peoplegoto-main.js) bytes"
  echo "--- API URLs ---"
  grep -oP 'https?://[a-zA-Z0-9._/-]+' /tmp/peoplegoto-main.js | sort -u
fi

echo ""
echo "Completed: $(date)"
