gdias 5 dní pred
rodič
commit
3f1d7d1922
1 zmenil súbory, kde vykonal 34 pridanie a 0 odobranie
  1. 34 0
      controllers/TshieldWebhookController.php

+ 34 - 0
controllers/TshieldWebhookController.php

@@ -27,6 +27,8 @@ class TshieldWebhookController
             $rawBody = (string)file_get_contents('php://input');
         }
 
+        $this->logReceipt($request, $requestId, $rawBody);
+
         $body = json_decode($rawBody, true);
 
         try {
@@ -150,6 +152,38 @@ class TshieldWebhookController
         error_log('[TShieldWebhook] ' . $encoded);
     }
 
+    private function logReceipt(ServerRequestInterface $request, string $requestId, string $rawBody): void
+    {
+        $ts = (new \DateTimeImmutable())->format('c');
+        $serverParams = $request->getServerParams();
+        $ip = $serverParams['REMOTE_ADDR'] ?? null;
+        $method = $request->getMethod();
+        $uri = (string)$request->getUri();
+
+        $entry = [
+            'ts' => $ts,
+            'service' => 'tshield_webhook',
+            'event' => 'received',
+            'request_id' => $requestId,
+            'method' => $method,
+            'uri' => $uri,
+            'ip' => $ip,
+            'request_raw' => $rawBody,
+        ];
+
+        $encoded = json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
+        if ($encoded === false) {
+            $encoded = '{"ts":"' . $ts . '","service":"tshield_webhook","event":"received","request_id":"' . $requestId . '","error":"unable_to_encode_log"}';
+        }
+
+        try {
+            @file_put_contents($this->logFilePath, $encoded . "\n", FILE_APPEND | LOCK_EX);
+        } catch (\Throwable $e) {
+        }
+
+        error_log('[TShieldWebhook] ' . $encoded);
+    }
+
     private function getResponseBodyForLog(ResponseInterface $response): ?string
     {
         try {