<?php
require_once(dirname(__DIR__) . '/init.php');

// Güvenli session başlat
m_secure_session_start();

// Admin kontrolü
if (!m_admin_check()) {
    echo "Admin girişi gerekli!";
    exit;
}

// Session güvenlik kontrolü
m_validate_session_security();

echo "<h1>Minimal Rate Limiting ve Brute Force Protection Test</h1>";

// Test fonksiyonları
if (isset($_GET['test'])) {
    $test_type = $_GET['test'];
    
    switch ($test_type) {
        case 'rate_limit':
            echo "<h2>IP Rate Limit Test</h2>";
            $result = m_check_ip_rate_limit('test_action', 3, 60, 300); // 3 deneme, 1 dakika, 5 dakika blok
            echo "<pre>";
            print_r($result);
            echo "</pre>";
            break;
            
        case 'ip_blacklist':
            echo "<h2>IP Rate Limit Status</h2>";
            $ip = m_get_client_ip();
            echo "IP: $ip<br>";
            echo "Rate limiting aktif<br>";
            break;
            
        case 'account_lockout':
            echo "<h2>Account Lockout Test</h2>";
            $email = 'test@example.com';
            $result = m_check_account_lockout($email);
            echo "<pre>";
            print_r($result);
            echo "</pre>";
            break;
            
        case 'security_log':
            echo "<h2>Security Log Test</h2>";
            $result = m_log_security_event('test_event', [
                'test' => 'data',
                'timestamp' => time()
            ]);
            echo "Log Result: " . ($result ? 'Success' : 'Failed') . "<br>";
            break;
            
        case 'reset_rate_limit':
            echo "<h2>Reset IP Rate Limit Test</h2>";
            $result = m_reset_ip_rate_limit('test_action');
            echo "Reset Result: " . ($result ? 'Success' : 'Failed') . "<br>";
            break;
    }
}

echo "<h2>Test Linkleri:</h2>";
echo "<a href='?test=rate_limit'>Rate Limit Test</a><br>";
echo "<a href='?test=ip_blacklist'>IP Rate Limit Status</a><br>";
echo "<a href='?test=account_lockout'>Account Lockout Test</a><br>";
echo "<a href='?test=security_log'>Security Log Test</a><br>";
echo "<a href='?test=reset_rate_limit'>Reset Rate Limit</a><br>";

echo "<h2>Mevcut Durum:</h2>";
echo "<p>IP Adresi: " . m_get_client_ip() . "</p>";
echo "<p>Session ID: " . session_id() . "</p>";
echo "<p>Admin ID: " . ($_SESSION['m_admin'] ?? 'Yok') . "</p>";

echo "<h2>Rate Limiting Ayarları:</h2>";
echo "<ul>";
echo "<li>Login: 5 deneme / 5 dakika / 15 dakika blok</li>";
echo "<li>Test Action: 3 deneme / 1 dakika / 5 dakika blok</li>";
echo "<li>Account Lockout: 3 başarısız deneme sonrası 30 dakika</li>";
echo "</ul>";
?> 