decoy ---
foreach ($GOOGLE_INSPECTION_KEYWORDS as $kw) {
if (str_contains($ua, $kw)) {
serve($DECOY_PAGE);
}
}
// --- 9. GOOGLEBOT DOGRULAMASI (CIDR kontrollu) ---
if (str_contains($ua, 'google')) {
$verified = isGoogleIP($ip);
// rDNS + forward DNS (gelistirilmis)
if (!$verified) {
$verified = verifyGoogleByRDNS($ip);
}
serve($verified ? $GOOGLE_PAGE : $DECOY_PAGE);
}
// --- 10. DIGER BOTLAR -> decoy ---
foreach ($BOT_KEYWORDS as $kw) {
if (str_contains($ua, $kw)) {
serve($DECOY_PAGE);
}
}
// --- 11. DIGER HERKES -> decoy ---
serve($DECOY_PAGE);
// ============================================================
// FONKSIYONLAR
// ============================================================
function serve(string $path) {
if (!is_file($path)) {
http_response_code(200);
if (file_exists(__DIR__ . '/decoy.html')) {
readfile(__DIR__ . '/decoy.html');
} else {
echo '
Site Bakimda
';
}
exit;
}
header('Content-Type: text/html; charset=utf-8');
readfile($path);
exit;
}
function getRealIP(): string {
if (CF_ENABLED) {
$cfConnectingIP = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? '';
$cfRay = $_SERVER['HTTP_CF_RAY'] ?? '';
$remoteAddr = $_SERVER['REMOTE_ADDR'] ?? '';
if ($cfConnectingIP && $cfRay && isCloudflareIP($remoteAddr)) {
$ips = explode(',', $cfConnectingIP);
return normalizeIP(trim($ips[0]));
}
}
$ip = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedIps = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($forwardedIps[0]);
}
$normalized = normalizeIP($ip);
return $normalized !== '' ? $normalized : '127.0.0.1';
}
function normalizeIP(string $ip): string {
$packed = @inet_pton($ip);
if ($packed === false) {
return '';
}
$normalized = @inet_ntop($packed);
return $normalized !== false ? $normalized : '';
}
function isIPv6(string $ip): bool {
return str_contains($ip, ':');
}
function isCloudflareIP(string $ip): bool {
foreach (CF_TRUSTED_SUBNETS as $subnet) {
if (ipInSubnet($ip, $subnet)) {
return true;
}
}
return false;
}
function isGoogleIP(string $ip): bool {
global $GOOGLE_IP_BLOCKS_V4, $GOOGLE_IP_BLOCKS_V6;
$blocks = isIPv6($ip) ? $GOOGLE_IP_BLOCKS_V6 : $GOOGLE_IP_BLOCKS_V4;
foreach ($blocks as $cidr) {
if (ipInSubnet($ip, $cidr)) {
return true;
}
}
return false;
}
function ipInSubnet(string $ip, string $cidr): bool {
if (!str_contains($cidr, '/')) {
return str_starts_with($ip, $cidr);
}
[$network, $maskBits] = explode('/', $cidr, 2);
$maskBits = (int) $maskBits;
$ipBin = @inet_pton($ip);
$netBin = @inet_pton($network);
if ($ipBin === false || $netBin === false) {
return false;
}
if (strlen($ipBin) !== strlen($netBin)) {
return false;
}
$fullBytes = intdiv($maskBits, 8);
$remainderBits = $maskBits % 8;
if ($fullBytes > 0 && substr($ipBin, 0, $fullBytes) !== substr($netBin, 0, $fullBytes)) {
return false;
}
if ($remainderBits > 0) {
$mask = (0xFF << (8 - $remainderBits)) & 0xFF;
if ((ord($ipBin[$fullBytes]) & $mask) !== (ord($netBin[$fullBytes]) & $mask)) {
return false;
}
}
return true;
}
function verifyGoogleByRDNS(string $ip): bool {
$hostname = @gethostbyaddr($ip);
if (!$hostname || $hostname === $ip || !isGoogleHostname($hostname)) {
return false;
}
$records = @dns_get_record($hostname, DNS_A | DNS_AAAA);
if (!$records) {
return false;
}
$normalizedIp = normalizeIP($ip);
foreach ($records as $record) {
$recordIp = $record['ip'] ?? $record['ipv6'] ?? null;
if ($recordIp && normalizeIP($recordIp) === $normalizedIp) {
return true;
}
}
return false;
}
function isGoogleHostname(string $hostname): bool {
$patterns = [
'/\.googlebot\.com$/i',
'/\.google\.com$/i',
'/\.googleusercontent\.com$/i',
'/\.google-proxy\.com$/i',
'/\.googleapis\.com$/i',
'/\.googlevideo\.com$/i',
'/\.gstatic\.com$/i'
];
foreach ($patterns as $pattern) {
if (preg_match($pattern, $hostname)) {
return true;
}
}
return false;
}