cambios importantes

This commit is contained in:
Lizandro Guarnizo
2026-06-13 09:19:36 -05:00
parent a6595862ec
commit 774cd829d9
2 changed files with 42 additions and 1 deletions
+13 -1
View File
@@ -27,6 +27,8 @@ class WpWebhook
*/ */
public static function verify(): void public static function verify(): void
{ {
self::debugLog('GET', $_SERVER['QUERY_STRING'] ?? '');
$mode = $_GET['hub_mode'] ?? $_GET['hub.mode'] ?? ''; $mode = $_GET['hub_mode'] ?? $_GET['hub.mode'] ?? '';
$verifyToken = $_GET['hub_verify_token'] ?? $_GET['hub.verify_token'] ?? ''; $verifyToken = $_GET['hub_verify_token'] ?? $_GET['hub.verify_token'] ?? '';
$challenge = $_GET['hub_challenge'] ?? $_GET['hub.challenge'] ?? ''; $challenge = $_GET['hub_challenge'] ?? $_GET['hub.challenge'] ?? '';
@@ -52,8 +54,12 @@ class WpWebhook
public static function receive(): void public static function receive(): void
{ {
// 1. Leer body raw // 0. Log raw request first (before any validation)
$rawBody = file_get_contents('php://input'); $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 === '') { if ($rawBody === false || $rawBody === '') {
self::respond(400, ['error' => 'Body vacío']); 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 private static function respond(int $code, array $body): void
{ {
http_response_code($code); http_response_code($code);
+29
View File
@@ -13,6 +13,12 @@ require_once __DIR__ . '/../services/Settings.php';
if ($r['value'] !== null && $r['value'] !== '') { if ($r['value'] !== null && $r['value'] !== '') {
$_ENV[$r['key']] = $r['value']; $_ENV[$r['key']] = $r['value'];
putenv("{$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) { } catch (\Throwable $e) {
@@ -407,11 +413,34 @@ $routes = [
foreach ($pairs as $k => $v) { foreach ($pairs as $k => $v) {
$_ENV[$k] = $v; $_ENV[$k] = $v;
putenv("{$k}={$v}"); putenv("{$k}={$v}");
$upper = strtoupper($k);
if ($upper !== $k) {
$_ENV[$upper] = $v;
putenv("{$upper}={$v}");
}
} }
header('Location: /admin/settings?msg=saved'); header('Location: /admin/settings?msg=saved');
exit; 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 ────────────────────────────────── // ─── Admin: estado de salud de los ERP ──────────────────────────────────
['GET', '/admin/erp-health', fn() => (function () { ['GET', '/admin/erp-health', fn() => (function () {
SessionAuth::require(); SessionAuth::require();