#!/bin/bash
echo "=== Guajiritos Dev Company + V2 APIs ==="
echo "Started: $(date)"

# V2 Tourism API (dev/staging)
echo "========== apiturismov2.guajiritos.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://apiturismov2.guajiritos.com/v1/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://apiturismov2.guajiritos.com/v1/" 2>/dev/null | head -c 1000
echo ""
for ep in "/v1/version" "/v1/help" "/v1/config" "/v1/hotels" "/v1/destinations" "/v1/search" "/v1/auth/login" "/v1/province" "/v1/municipality" "/v1/payment" "/health" "/docs" "/swagger"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 12 "https://apiturismov2.guajiritos.com${ep}" 2>/dev/null)
  code=$(echo $status | cut -d'|' -f1)
  size=$(echo $status | cut -d'|' -f2)
  if [ "$code" != "000" ] && [ "$code" != "404" ]; then
    echo "  [$code] $ep (${size}B)"
    if [ "$code" = "200" ] && [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      proxychains4 -q curl -ks --connect-timeout 8 -m 12 "https://apiturismov2.guajiritos.com${ep}" 2>/dev/null | head -c 500
      echo ""
    fi
  fi
done

# V2 Custom API
echo ""
echo "========== apicustomv2.guajiritos.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://apicustomv2.guajiritos.com/v1/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://apicustomv2.guajiritos.com/v1/" 2>/dev/null | head -c 1000
echo ""
for ep in "/v1/version" "/v1/help" "/v1/config" "/v1/auth/login" "/v1/packages" "/v1/products" "/v1/search" "/health" "/docs"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 12 "https://apicustomv2.guajiritos.com${ep}" 2>/dev/null)
  code=$(echo $status | cut -d'|' -f1)
  size=$(echo $status | cut -d'|' -f2)
  if [ "$code" != "000" ] && [ "$code" != "404" ]; then
    echo "  [$code] $ep (${size}B)"
    if [ "$code" = "200" ] && [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      proxychains4 -q curl -ks --connect-timeout 8 -m 12 "https://apicustomv2.guajiritos.com${ep}" 2>/dev/null | head -c 500
      echo ""
    fi
  fi
done

# Guajiritos main site
echo ""
echo "========== guajiritos.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://www.guajiritos.com/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://www.guajiritos.com/" 2>/dev/null | head -c 1000
echo ""

# Guajisoft
echo ""
echo "========== guajisoft.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://www.guajisoft.com/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://www.guajisoft.com/" 2>/dev/null | head -c 500

# Blue Diamond hotel test environment
echo ""
echo "========== probluediamond.guajisoft.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://probluediamond.guajisoft.com/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://probluediamond.guajisoft.com/" 2>/dev/null | head -c 500

# Paradiso events
echo ""
echo "========== eventos.agenciaparadiso.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://eventos.agenciaparadiso.com/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://eventos.agenciaparadiso.com/" 2>/dev/null | head -c 500

# FIT Cuba
echo ""
echo "========== fitcuba.net =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://www.fitcuba.net/" 2>/dev/null | head -15

# V2 Frontend
echo ""
echo "========== frontv2.guajiritos.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://frontv2.guajiritos.com/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://frontv2.guajiritos.com/" 2>/dev/null | head -c 500

# More guajiritos subdomains
echo ""
echo "========== Guajiritos Subdomain Discovery =========="
for sub in "api" "admin" "staging" "dev" "test" "git" "gitlab" "jenkins" "ci" "soporte" "mail" "webmail" "tienda" "cdn" "db" "monitoring" "grafana" "kibana"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 6 -m 10 "https://${sub}.guajiritos.com/" 2>/dev/null)
  code=$(echo $status | cut -d'|' -f1)
  size=$(echo $status | cut -d'|' -f2)
  if [ "$code" != "000" ]; then
    echo "  [$code] ${sub}.guajiritos.com (${size}B)"
  fi
done

echo ""
echo "--- SSL Certs ---"
for domain in "guajiritos.com" "guajisoft.com" "apiturismov2.guajiritos.com" "probluediamond.guajisoft.com"; do
  echo "--- $domain ---"
  echo | openssl s_client -connect "$domain:443" -servername "$domain" 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName 2>/dev/null
done

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