<?php
// Sadmin erişim kontrolü
if(!isset($_COOKIE['login_token']) OR $_COOKIE['login_token']!="cankat"){
    echo "Erişim izniniz yok";
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>HeySen Sistem Durumu</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
        .container { max-width: 1000px; margin: 0 auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
        h1 { color: #333; border-bottom: 3px solid #4CAF50; padding-bottom: 10px; }
        h2 { color: #666; margin-top: 30px; border-left: 4px solid #2196F3; padding-left: 10px; }
        .status { padding: 10px; margin: 10px 0; border-radius: 5px; }
        .good { background: #d4edda; color: #155724; border-left: 4px solid #28a745; }
        .warning { background: #fff3cd; color: #856404; border-left: 4px solid #ffc107; }
        .bad { background: #f8d7da; color: #721c24; border-left: 4px solid #dc3545; }
        table { width: 100%; border-collapse: collapse; margin: 15px 0; }
        table td { padding: 8px; border-bottom: 1px solid #ddd; }
        table td:first-child { font-weight: bold; width: 300px; }
        .value { font-family: monospace; background: #f8f9fa; padding: 2px 6px; border-radius: 3px; }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔍 HeySen Sistem Durumu</h1>
        
        <h2>1️⃣ PHP Durumu</h2>
        <table>
            <tr>
                <td>PHP Versiyonu</td>
                <td><span class="value"><?= phpversion() ?></span></td>
            </tr>
            <tr>
                <td>OPcache Durumu</td>
                <td>
                    <?php if (function_exists('opcache_get_status') && opcache_get_status()): ?>
                        <span class="status good">✅ AKTİF</span>
                    <?php else: ?>
                        <span class="status bad">❌ KAPALI</span>
                    <?php endif; ?>
                </td>
            </tr>
            <?php if (function_exists('opcache_get_status') && $opcache = opcache_get_status()): ?>
            <tr>
                <td>OPcache Memory Usage</td>
                <td><span class="value"><?= round($opcache['memory_usage']['used_memory'] / 1024 / 1024, 2) ?> MB / <?= round($opcache['memory_usage']['free_memory'] / 1024 / 1024, 2) ?> MB boş</span></td>
            </tr>
            <tr>
                <td>Cached Scripts</td>
                <td><span class="value"><?= $opcache['opcache_statistics']['num_cached_scripts'] ?> dosya</span></td>
            </tr>
            <tr>
                <td>Hit Rate</td>
                <td><span class="value"><?= round($opcache['opcache_statistics']['opcache_hit_rate'], 2) ?>%</span></td>
            </tr>
            <?php endif; ?>
        </table>

        <?php
        $opcache_settings = [
            'opcache.enable',
            'opcache.memory_consumption',
            'opcache.max_accelerated_files',
            'opcache.revalidate_freq',
            'opcache.validate_timestamps'
        ];
        ?>
        
        <h2>2️⃣ OPcache Ayarları</h2>
        <table>
            <?php foreach ($opcache_settings as $setting): ?>
            <tr>
                <td><?= $setting ?></td>
                <td><span class="value"><?= ini_get($setting) ?: 'Ayarlanmamış' ?></span></td>
            </tr>
            <?php endforeach; ?>
        </table>

        <h2>3️⃣ PHP Genel Ayarları</h2>
        <table>
            <tr>
                <td>memory_limit</td>
                <td><span class="value"><?= ini_get('memory_limit') ?></span></td>
            </tr>
            <tr>
                <td>max_execution_time</td>
                <td><span class="value"><?= ini_get('max_execution_time') ?> saniye</span></td>
            </tr>
            <tr>
                <td>upload_max_filesize</td>
                <td><span class="value"><?= ini_get('upload_max_filesize') ?></span></td>
            </tr>
            <tr>
                <td>post_max_size</td>
                <td><span class="value"><?= ini_get('post_max_size') ?></span></td>
            </tr>
        </table>

        <h2>4️⃣ Veritabanı Durumu</h2>
        <?php
        include '../config.php';
        
        // MySQL Versiyonu
        $mysqlVersion = $db->query("SELECT VERSION()")->fetchColumn();
        
        // Query Cache
        $queryCache = $db->query("SHOW VARIABLES LIKE 'query_cache%'")->fetchAll(PDO::FETCH_KEY_PAIR);
        
        // InnoDB Buffer Pool
        $bufferPool = $db->query("SHOW VARIABLES LIKE 'innodb_buffer_pool_size'")->fetchColumn(1);
        ?>
        
        <table>
            <tr>
                <td>MySQL/MariaDB Versiyonu</td>
                <td><span class="value"><?= $mysqlVersion ?></span></td>
            </tr>
            <tr>
                <td>Query Cache Type</td>
                <td>
                    <span class="value"><?= $queryCache['query_cache_type'] ?? 'N/A' ?></span>
                    <?php if (($queryCache['query_cache_type'] ?? 'OFF') == 'OFF'): ?>
                        <span class="status warning">⚠️ Kapalı - Açılmalı</span>
                    <?php endif; ?>
                </td>
            </tr>
            <tr>
                <td>Query Cache Size</td>
                <td>
                    <span class="value"><?= round(($queryCache['query_cache_size'] ?? 0) / 1024 / 1024, 2) ?> MB</span>
                    <?php if (($queryCache['query_cache_size'] ?? 0) < 64*1024*1024): ?>
                        <span class="status warning">⚠️ Düşük - 64MB yapılmalı</span>
                    <?php endif; ?>
                </td>
            </tr>
            <tr>
                <td>InnoDB Buffer Pool Size</td>
                <td>
                    <span class="value"><?= round($bufferPool / 1024 / 1024, 2) ?> MB</span>
                    <?php if ($bufferPool < 512*1024*1024): ?>
                        <span class="status bad">❌ ÇOK DÜŞÜK - En az 2GB yapılmalı</span>
                    <?php endif; ?>
                </td>
            </tr>
        </table>

        <h2>5️⃣ Sunucu Bilgileri</h2>
        <table>
            <tr>
                <td>Sunucu Yazılımı</td>
                <td><span class="value"><?= $_SERVER['SERVER_SOFTWARE'] ?? 'Bilinmiyor' ?></span></td>
            </tr>
            <tr>
                <td>Sunucu IP</td>
                <td><span class="value"><?= $_SERVER['SERVER_ADDR'] ?? 'Bilinmiyor' ?></span></td>
            </tr>
            <tr>
                <td>PHP.ini Dosyası</td>
                <td><span class="value" style="font-size: 11px;"><?= php_ini_loaded_file() ?></span></td>
            </tr>
        </table>

        <h2>🎯 ÖNERİLER</h2>
        
        <?php if (!function_exists('opcache_get_status') || !opcache_get_status()): ?>
        <div class="status bad">
            <strong>❌ OPcache Kapalı</strong><br>
            WHM → Software → MultiPHP INI Editor → opcache.enable = On yapın
        </div>
        <?php endif; ?>

        <?php if (($queryCache['query_cache_type'] ?? 'OFF') == 'OFF'): ?>
        <div class="status warning">
            <strong>⚠️ Query Cache Kapalı</strong><br>
            SSH: <code>nano /etc/my.cnf</code> → <code>query_cache_type = 1</code> ve <code>query_cache_size = 64M</code>
        </div>
        <?php endif; ?>

        <?php if ($bufferPool < 2*1024*1024*1024): ?>
        <div class="status bad">
            <strong>❌ InnoDB Buffer Pool Çok Küçük</strong><br>
            SSH: <code>nano /etc/my.cnf</code> → <code>innodb_buffer_pool_size = 2G</code> (62GB RAM'iniz var!)
        </div>
        <?php endif; ?>

        <div style="margin-top: 30px; padding: 15px; background: #e3f2fd; border-radius: 5px;">
            <strong>📌 NOT:</strong> Bu sayfa hassas bilgiler içeriyor. İşiniz bitince silin veya erişimi kapatın.
        </div>
    </div>
</body>
</html>

