#!/bin/bash
echo "=== Supreme Court API + Tourism + Media Deep Probe ==="
echo "Started: $(date)"

echo ""
echo "========== apixejel.tsp.gob.cu (HTTPS) =========="
for path in "/" "/api" "/api/v1" "/api/v2" "/swagger" "/docs" "/graphql" "/health" "/status" "/version" "/v1" "/v2" "/xejel" "/consulta" "/expediente" "/sentencia"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "https://apixejel.tsp.gob.cu$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)"
    if [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      curl -ks --connect-timeout 10 -m 20 "https://apixejel.tsp.gob.cu$path" 2>/dev/null | head -c 1000
      echo ""
    fi
  fi
done

echo ""
echo "========== apixejelprueba.tsp.gob.cu (HTTPS) =========="
for path in "/" "/api" "/swagger" "/docs" "/health"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "https://apixejelprueba.tsp.gob.cu$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)"
    if [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      curl -ks --connect-timeout 10 -m 20 "https://apixejelprueba.tsp.gob.cu$path" 2>/dev/null | head -c 1000
      echo ""
    fi
  fi
done

echo ""
echo "========== monitoreo.tsp.gob.cu (HTTPS) =========="
for path in "/" "/login" "/dashboard" "/api" "/health" "/status"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "https://monitoreo.tsp.gob.cu$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)"
    if [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      curl -ks --connect-timeout 10 -m 20 "https://monitoreo.tsp.gob.cu$path" 2>/dev/null | head -c 1000
      echo ""
    fi
  fi
done

echo ""
echo "========== havanatur.cu API =========="
curl -ks --connect-timeout 15 -m 30 "https://www.havanatur.cu/" 2>/dev/null | grep -oP 'src="[^"]*\.js"' | head -5
echo ""
for path in "/api/v1" "/api/hotels" "/api/destinations" "/api/auth/login" "/api/config" "/assets/config.json" "/assets/env.json" "/ngsw.json" "/manifest.webmanifest"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}|%{content_type}" --connect-timeout 10 -m 20 "https://www.havanatur.cu$path" 2>/dev/null)
  code=$(echo $status | cut -d'|' -f1)
  size=$(echo $status | cut -d'|' -f2)
  ctype=$(echo $status | cut -d'|' -f3)
  echo "  [$code] $path (${size}B) $ctype"
  if [ "$code" != "200" ] || [ "$size" != "44294" ]; then
    if [ "$size" -gt 0 ] && [ "$size" -lt 5000 ]; then
      curl -ks --connect-timeout 10 -m 20 "https://www.havanatur.cu$path" 2>/dev/null
      echo ""
    fi
  fi
done

echo ""
echo "========== www.granma.cu =========="
curl -ksI --connect-timeout 15 -m 20 "https://www.granma.cu/" 2>/dev/null | head -20
echo "--- Content ---"
curl -ks --connect-timeout 15 -m 30 "https://www.granma.cu/" 2>/dev/null | head -c 500
echo ""
echo "--- WP-JSON ---"
curl -ks --connect-timeout 10 -m 20 "https://www.granma.cu/wp-json/wp/v2/posts" 2>/dev/null | head -c 500
echo ""

echo ""
echo "========== www.acn.cu =========="
curl -ksI --connect-timeout 15 -m 20 "https://www.acn.cu/" 2>/dev/null | head -20
echo "--- Content ---"
curl -ks --connect-timeout 15 -m 30 "https://www.acn.cu/" 2>/dev/null | head -c 500

echo ""
echo "========== sso.bienestar.gobiernocav.co.cu =========="
for proto in "https" "http"; do
  for path in "/" "/login" "/auth" "/.well-known/openid-configuration"; do
    status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "$proto://sso.bienestar.gobiernocav.co.cu$path" 2>/dev/null)
    echo "  [$status] $proto $path"
  done
done

echo ""
echo "========== bandec.cu =========="
for prefix in "https://www.bandec.cu" "https://bandec.cu" "http://bandec.cu"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "$prefix/" 2>/dev/null)
  echo "  $prefix: $status"
done
curl -ksI --connect-timeout 10 -m 20 "https://www.bandec.cu/" 2>/dev/null | head -15

echo ""
echo "========== correos.cu =========="
curl -ksI --connect-timeout 15 -m 20 "https://www.correos.cu/" 2>/dev/null | head -15
echo "--- Content ---"
curl -ks --connect-timeout 15 -m 30 "https://www.correos.cu/" 2>/dev/null | head -c 300

echo ""
echo "========== cubana.cu =========="
curl -ksI --connect-timeout 15 -m 20 "https://www.cubana.cu/" 2>/dev/null | head -15

echo ""
echo "========== ftp.onat.gob.cu =========="
for path in "/" "/pub" "/upload"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "http://ftp.onat.gob.cu$path" 2>/dev/null)
  echo "  [$status] http $path"
done
echo "  FTP test:"
curl -s --connect-timeout 10 -m 15 "ftp://ftp.onat.gob.cu/" 2>/dev/null | head -20

echo ""
echo "========== vuceregulaciones-admin.mincex.gob.cu (IIS 8.5) =========="
for path in "/Default.aspx" "/login.aspx" "/web.config" "/elmah.axd" "/trace.axd" "/WebResource.axd" "/ScriptResource.axd"; do
  status=$(curl -ks -o /dev/null -w "%{http_code}|%{size_download}" --connect-timeout 10 -m 20 "https://vuceregulaciones-admin.mincex.gob.cu$path" 2>/dev/null)
  echo "  [$status] $path"
done
curl -ksI --connect-timeout 10 -m 20 "https://vuceregulaciones-admin.mincex.gob.cu/" 2>/dev/null

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