diff --git a/admin/v1/WpWebhook.php b/admin/v1/WpWebhook.php index 73ed46b..5bc82a6 100644 --- a/admin/v1/WpWebhook.php +++ b/admin/v1/WpWebhook.php @@ -27,6 +27,8 @@ class WpWebhook */ public static function verify(): void { + self::debugLog('GET', $_SERVER['QUERY_STRING'] ?? ''); + $mode = $_GET['hub_mode'] ?? $_GET['hub.mode'] ?? ''; $verifyToken = $_GET['hub_verify_token'] ?? $_GET['hub.verify_token'] ?? ''; $challenge = $_GET['hub_challenge'] ?? $_GET['hub.challenge'] ?? ''; @@ -52,8 +54,12 @@ class WpWebhook public static function receive(): void { - // 1. Leer body raw + // 0. Log raw request first (before any validation) $rawBody = file_get_contents('php://input'); + $headers = getallheaders(); + self::debugLog('POST', json_encode(['headers' => $headers, 'body' => $rawBody], JSON_UNESCAPED_UNICODE)); + + // 1. Validar body if ($rawBody === false || $rawBody === '') { self::respond(400, ['error' => 'Body vacío']); } @@ -465,6 +471,12 @@ class WpWebhook } } + private static function debugLog(string $method, string $data): void + { + $log = '[' . date('Y-m-d H:i:s') . "] {$method}\n{$data}\n" . str_repeat('-', 60) . "\n"; + @file_put_contents('/tmp/wp-debug.log', $log, FILE_APPEND); + } + private static function respond(int $code, array $body): void { http_response_code($code); diff --git a/public/index.php b/public/index.php index c2ce9e0..303ebc5 100644 --- a/public/index.php +++ b/public/index.php @@ -13,6 +13,12 @@ require_once __DIR__ . '/../services/Settings.php'; if ($r['value'] !== null && $r['value'] !== '') { $_ENV[$r['key']] = $r['value']; putenv("{$r['key']}={$r['value']}"); + // Also set uppercase version for env() lookups + $upper = strtoupper($r['key']); + if ($upper !== $r['key']) { + $_ENV[$upper] = $r['value']; + putenv("{$upper}={$r['value']}"); + } } } } catch (\Throwable $e) { @@ -407,11 +413,34 @@ $routes = [ foreach ($pairs as $k => $v) { $_ENV[$k] = $v; putenv("{$k}={$v}"); + $upper = strtoupper($k); + if ($upper !== $k) { + $_ENV[$upper] = $v; + putenv("{$upper}={$v}"); + } } header('Location: /admin/settings?msg=saved'); exit; })()], + // ─── Debug: captura cruda de webhooks (loguea todo sin validar) ─────── + ['GET', '/admin/v1/wp-webhook-debug', fn() => (function () { + $log = '[' . date('Y-m-d H:i:s') . "] GET " . ($_SERVER['QUERY_STRING'] ?? '') . "\n"; + file_put_contents('/tmp/wp-debug.log', $log, FILE_APPEND); + jsonResponse(200, ['logged' => true, 'query' => $_GET]); + })()], + ['POST', '/admin/v1/wp-webhook-debug', fn() => (function () { + $raw = file_get_contents('php://input'); + $headers = getallheaders(); + $log = '[' . date('Y-m-d H:i:s') . "] POST\n"; + $log .= "Headers: " . json_encode($headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n"; + $log .= "Body: {$raw}\n"; + $log .= str_repeat('-', 60) . "\n"; + file_put_contents('/tmp/wp-debug.log', $log, FILE_APPEND); + $decoded = json_decode($raw, true); + jsonResponse(200, ['logged' => true, 'headers' => $headers, 'body' => $decoded ?? $raw]); + })()], + // ─── Admin: estado de salud de los ERP ────────────────────────────────── ['GET', '/admin/erp-health', fn() => (function () { SessionAuth::require();