<?php
$log_file = __DIR__ . '/visitors_log.txt';
$blocked_file = __DIR__ . '/blocked_ips.txt';

// ✅ حظر IP
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!empty($_POST['block_ip']) && filter_var($_POST['block_ip'], FILTER_VALIDATE_IP)) {
        file_put_contents($blocked_file, $_POST['block_ip'] . "\n", FILE_APPEND);
        echo "<p style='color:red;'>🔒 IP محظور: {$_POST['block_ip']}</p>";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>لوحة تحكم الزوار</title>
    <style>
        body { font-family: Arial; background: #f2f2f2; padding: 20px; }
        table { width: 100%; background: white; border-collapse: collapse; margin-top: 20px; }
        th, td { border: 1px solid #ccc; padding: 8px; }
        th { background: #eee; }
        .block { margin-bottom: 10px; }
    </style>
</head>
<body>

<h2>📋 لائحة الزوار</h2>

<form method="POST" class="block">
    <input type="text" name="block_ip" placeholder="IP لحظره" required>
    <button type="submit">حظر</button>
</form>

<table>
    <thead>
        <tr><th>⏱️ الوقت</th><th>IP</th><th>الدولة</th><th>ISP</th><th>ORG</th><th>الحالة</th></tr>
    </thead>
    <tbody>
        <?php
        if (file_exists($log_file)) {
            $lines = array_reverse(file($log_file));
            foreach ($lines as $line) {
                echo "<tr><td>" . str_replace("|", "</td><td>", htmlspecialchars($line)) . "</td></tr>";
            }
        }
        ?>
    </tbody>
</table>

</body>
</html>