![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/gocodeme.com/public_html/BACKUP/ |
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 0);
// Set proper headers
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit(0);
}
// Log callback data for debugging
$logFile = 'callback_log.txt';
$timestamp = date('Y-m-d H:i:s');
$input = file_get_contents('php://input');
$headers = getallheaders();
// Log the callback
$logEntry = "[$timestamp] Callback received\n";
$logEntry .= "Headers: " . json_encode($headers) . "\n";
$logEntry .= "Body: " . $input . "\n";
$logEntry .= "Method: " . $_SERVER['REQUEST_METHOD'] . "\n";
$logEntry .= "----------------------------------------\n";
file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);
try {
// Parse the callback data
$data = json_decode($input, true);
if (!$data) {
throw new Exception('Invalid JSON data received');
}
// Log the parsed data
file_put_contents($logFile, "Parsed data: " . json_encode($data, JSON_PRETTY_PRINT) . "\n", FILE_APPEND | LOCK_EX);
// Handle different types of callbacks
if (isset($data['task_id'])) {
$taskId = $data['task_id'];
$status = $data['status'] ?? 'unknown';
// Store the task result for later retrieval
$resultFile = "task_results/{$taskId}.json";
// Ensure the directory exists
if (!is_dir('task_results')) {
mkdir('task_results', 0755, true);
}
// Save the result
file_put_contents($resultFile, json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// Log the saved result
file_put_contents($logFile, "Task result saved to: $resultFile\n", FILE_APPEND | LOCK_EX);
// Return success response
echo json_encode([
'success' => true,
'message' => 'Callback processed successfully',
'task_id' => $taskId,
'status' => $status
]);
} elseif (isset($data['id'])) {
// Alternative format with 'id' instead of 'task_id'
$taskId = $data['id'];
$status = $data['status'] ?? 'unknown';
// Store the task result for later retrieval
$resultFile = "task_results/{$taskId}.json";
// Ensure the directory exists
if (!is_dir('task_results')) {
mkdir('task_results', 0755, true);
}
// Save the result
file_put_contents($resultFile, json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// Log the saved result
file_put_contents($logFile, "Task result saved to: $resultFile\n", FILE_APPEND | LOCK_EX);
// Return success response
echo json_encode([
'success' => true,
'message' => 'Callback processed successfully',
'task_id' => $taskId,
'status' => $status
]);
} else {
// Unknown callback format
file_put_contents($logFile, "Unknown callback format\n", FILE_APPEND | LOCK_EX);
echo json_encode([
'success' => true,
'message' => 'Callback received (unknown format)',
'data' => $data
]);
}
} catch (Exception $e) {
// Log the error
file_put_contents($logFile, "Error: " . $e->getMessage() . "\n", FILE_APPEND | LOCK_EX);
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>