config->load(); $configUrls = $this->config->get('urls_results_batch', '[]'); $configUrls = json_decode($configUrls, true); $expectedToken = isset($configUrls[$testId]['token']) ? (string)$configUrls[$testId]['token'] : ''; $providedToken = (string)Security::getVar('cmd', 'acyc_token', ''); if ($expectedToken === '' || $providedToken === '' || !hash_equals($expectedToken, $providedToken)) { DebugService::logMessage('callback_controller.log', 'Rejected callback for batch '.$testId.': missing or invalid authentication token'); exit; } $testService = new TestService(); $decodedResult = $testService->decodeResult($result); if ($decodedResult === null) { DebugService::logMessage('callback_controller.log', 'Error decoding the received data for '.$testId); // We received the results but couldn't decode them, this means that the content may have been truncated by the server in $_POST // We can let the client's server call our API to get the results instead, which has less risk of having this issue if (!empty($configUrls[$testId])) { $configUrls[$testId]['last_check'] = 0; $this->config->save(['urls_results_batch' => json_encode($configUrls)]); } exit; } if (!empty($configUrls[$testId])) { unset($configUrls[$testId]); $this->config->save(['urls_results_batch' => json_encode($configUrls)]); } DebugService::logMessage('callback_controller.log', 'Received results for the batch '.$testId.' containing details for '.count($decodedResult).' email addresses.'); $testService->handleBatchResults($testId, $decodedResult); exit; } }