|
@@ -27,6 +27,8 @@ class TshieldWebhookController
|
|
|
$rawBody = (string)file_get_contents('php://input');
|
|
$rawBody = (string)file_get_contents('php://input');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->logReceipt($request, $requestId, $rawBody);
|
|
|
|
|
+
|
|
|
$body = json_decode($rawBody, true);
|
|
$body = json_decode($rawBody, true);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -150,6 +152,38 @@ class TshieldWebhookController
|
|
|
error_log('[TShieldWebhook] ' . $encoded);
|
|
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
|
|
private function getResponseBodyForLog(ResponseInterface $response): ?string
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|