#!/bin/bash
echo "=== New API Endpoints Probe ==="
echo "Started: $(date)"

# Cubanacan Custom API
echo "========== apicustom.cubanacansa.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://apicustom.cubanacansa.com/v1/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://apicustom.cubanacansa.com/v1/" 2>/dev/null | head -c 500
echo ""
for ep in "/v1/version" "/v1/help" "/v1/config" "/v1/auth/login" "/v1/packages" "/v1/products" "/v1/search" "/v1/categories" "/v1/destinations" "/v1/offers"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 12 "https://apicustom.cubanacansa.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://apicustom.cubanacansa.com${ep}" 2>/dev/null | head -c 300
      echo ""
    fi
  fi
done

# La Pradera Custom API
echo ""
echo "========== apicustom.cislapradera.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://apicustom.cislapradera.com/v1/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://apicustom.cislapradera.com/v1/" 2>/dev/null | head -c 500
echo ""
for ep in "/v1/version" "/v1/help" "/v1/config" "/v1/auth/login" "/v1/services" "/v1/treatments" "/v1/doctors" "/v1/patients" "/v1/appointments" "/v1/packages" "/v1/search"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 12 "https://apicustom.cislapradera.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://apicustom.cislapradera.com${ep}" 2>/dev/null | head -c 300
      echo ""
    fi
  fi
done

# PymesBulevar API (PeopleGoTo backend)
echo ""
echo "========== api.pymesbulevar.com =========="
proxychains4 -q curl -ksI --connect-timeout 10 -m 20 "https://api.pymesbulevar.com/v1/" 2>/dev/null | head -15
echo "--- Content ---"
proxychains4 -q curl -ks --connect-timeout 10 -m 20 "https://api.pymesbulevar.com/v1/" 2>/dev/null | head -c 500
echo ""
for ep in "/v1/version" "/v1/help" "/v1/config" "/v1/auth/login" "/v1/products" "/v1/stores" "/v1/categories" "/v1/search" "/v1/users" "/v1/orders" "/health" "/docs" "/swagger"; do
  status=$(proxychains4 -q curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 8 -m 12 "https://api.pymesbulevar.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://api.pymesbulevar.com${ep}" 2>/dev/null | head -c 300
      echo ""
    fi
  fi
done

# Guajiritos (developer company)
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 | grep -oP '<title>[^<]+</title>'
echo ""

# SSL cert check on new domains
echo ""
echo "========== SSL Certs =========="
for domain in "apicustom.cubanacansa.com" "apicustom.cislapradera.com" "api.pymesbulevar.com" "guajiritos.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

# Cubanacan Cars API (same as havanatur?)
echo ""
echo "========== apiautos.cubanacansa.com =========="
proxychains4 -q curl -ks --connect-timeout 10 -m 15 "https://apiautos.cubanacansa.com/" 2>/dev/null | head -c 200
echo ""
proxychains4 -q curl -ks --connect-timeout 10 -m 15 "https://apiautos.cubanacansa.com/vehicles" 2>/dev/null | head -c 300
echo ""
proxychains4 -q curl -ks --connect-timeout 10 -m 15 "https://apiautos.cubanacansa.com/brands" 2>/dev/null | head -c 300
echo ""
proxychains4 -q curl -ks --connect-timeout 10 -m 15 "https://apiautos.cubanacansa.com/version" 2>/dev/null

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