This commit is contained in:
Lizandro Guarnizo
2026-05-12 11:11:45 -05:00
parent 4f5147ab51
commit 848cb1fcf5
3 changed files with 231 additions and 17 deletions
+28 -4
View File
@@ -372,6 +372,8 @@ func GetCloudflareDNS(c *fiber.Ctx) error {
}
// GetCloudflareSSL devuelve los certificados SSL de una zona (:zone_id).
// Intenta primero certificate_packs?status=all; si falla (plan Free o sin ACM)
// devuelve el estado de Universal SSL como fallback.
func GetCloudflareSSL(c *fiber.Ctx) error {
zoneID := c.Params("zone_id")
if zoneID == "" {
@@ -383,11 +385,33 @@ func GetCloudflareSSL(c *fiber.Ctx) error {
"error": "No se encontró configuración activa de Cloudflare",
})
}
data, err := client.GetSSLCertificates(zoneID)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
// 1. Intentar certificate_packs?status=all
packs, packsErr := client.GetSSLCertificates(zoneID)
if packsErr == nil {
return c.JSON(fiber.Map{"data": packs, "zone_id": zoneID, "source": "certificate_packs"})
}
return c.JSON(fiber.Map{"data": data, "zone_id": zoneID})
// 2. Fallback: Universal SSL settings (disponible en todos los planes)
universal, uErr := client.GetUniversalSSLSettings(zoneID)
if uErr != nil {
// Devolver ambos errores para diagnóstico
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": packsErr.Error(),
"universal_error": uErr.Error(),
"hint": "El endpoint ssl/certificate_packs requiere permiso 'SSL and Certificates:Read'. Si usas API Token, asegúrate de que tenga ese permiso.",
})
}
return c.JSON(fiber.Map{
"data": nil,
"zone_id": zoneID,
"source": "universal_ssl",
"universal_ssl": fiber.Map{
"enabled": universal.Enabled,
"note": "Plan actual no expone certificate_packs. Universal SSL: " + func() string { if universal.Enabled { return "ACTIVO" }; return "INACTIVO" }(),
},
"packs_error": packsErr.Error(),
})
}
// GetCloudflareFirewall devuelve las reglas de firewall de una zona (:zone_id).