bilp5cxgcu / api.php
dsdfd34's picture
Initial deploy via automation script
a273d04 verified
Raw History Blame Contribute Delete
2.01 kB
<?php
// ==========================================
// API ПРОКСИ ДЛЯ GITHUB PAGES
// Возвращает свежую ссылку в JSON формате
// ==========================================
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
define("CACHE_FILE", __DIR__ . "/domain_cache.txt");
define("XOR_KEY", "ui-sess-v4-8921-xb-log"); // Должен совпадать с get.php
// Функция дешифрования
function xor_decode($base64_string, $key) {
$string = base64_decode($base64_string);
$out = '';
for ($i = 0; $i < strlen($string); $i++) {
$out .= $string[$i] ^ $key[$i % strlen($key)];
}
return $out;
}
$cache_file = CACHE_FILE;
$api_response = "";
// Безопасное чтение файла с защитой от гонки процессов
if (file_exists($cache_file)) {
$fp = fopen($cache_file, "r");
if (flock($fp, LOCK_SH)) {
$fsize = filesize($cache_file);
if ($fsize > 0) {
$content = fread($fp, $fsize);
if (!empty($content)) {
$api_response = trim($content);
}
}
flock($fp, LOCK_UN);
}
fclose($fp);
}
if (!empty($api_response)) {
$url = xor_decode($api_response, XOR_KEY);
if (strpos($url, 'http') === 0) {
echo json_encode([
"success" => true,
"url" => $url
], JSON_UNESCAPED_SLASHES);
} else {
http_response_code(500);
echo json_encode([
"success" => false,
"error" => "Invalid decoded URL. Make sure get.php is running."
]);
}
} else {
http_response_code(404);
echo json_encode([
"success" => false,
"error" => "No cache available. Wait for get.php to run."
]);
}
?>