// ==================== REFRESH/REPLACE ENDPOINT ==================== if ($uri === '/camera/refresh') { header('Content-Type: application/json'); $input_raw = file_get_contents('php://input'); parse_str($input_raw, $post_data); $serialno = $post_data['serialno'] ?? ''; $c = $post_data['c'] ?? ''; if (empty($serialno)) { echo json_encode(['code' => -1, 'expiredTime' => 0]); exit; } $conn = new mysqli("localhost", "vcamekma_vc4m_user", "Kohanshin@0542512567890", "vcamekma_vc4m_license"); if ($conn->connect_error) { echo json_encode(['code' => -1, 'expiredTime' => 0]); exit; } // Check if device exists and has active expiry $stmt = $conn->prepare("SELECT * FROM devices WHERE device_id = ? AND expiry_date > NOW()"); $stmt->bind_param("s", $serialno); $stmt->execute(); $device = $stmt->get_result()->fetch_assoc(); if (!$device) { echo json_encode(['code' => -1, 'expiredTime' => 0]); exit; } // Calculate remaining minutes $expiry_seconds = strtotime($device['expiry_date']); $remain_minutes = max(0, ceil(($expiry_seconds - time()) / 60)); $now = time(); // Generate tokens (matching xbye.xyz format exactly) $rc = base64_encode(random_bytes(96)); // 96 bytes = 128 characters base64 $otp = base64_encode(random_bytes(96)); $salt = "**"; // Return exact response matching xbye.xyz echo json_encode([ 'code' => 200, 'allow' => '', 'rc' => $rc, 'salt' => $salt, 'remain' => $remain_minutes, 'now' => $now, 'otp' => $otp ]); exit; }