<?php
/**
 * THE HONEYPOT TRAP - BOT BURNER
 */

// 1. Prevent Caching so the bot actually hits the server
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

require_once 'fingerprint_wrapper.php';

$ip = getClientIP();
$ua = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown';

// 2. Lock them in Redis (Instantaneous Ban)
$redis = get_redis_connection();
if ($redis) {
    // Set a permanent ban key in RAM
    $redis->set("gatekeeper:honeypot:" . $ip, "1");
}

// 3. Lock them in MySQL (Permanent Storage)
$pdo = get_db_connection();
if ($pdo) {
    try {
        // Generate the honeypot table if it doesn't exist
        $pdo->exec("CREATE TABLE IF NOT EXISTS honeypot_bans (
            ip_address VARCHAR(45) PRIMARY KEY,
            user_agent TEXT,
            caught_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        ) ENGINE=InnoDB");

        // Permanently burn the IP
        $stmt = $pdo->prepare("INSERT IGNORE INTO honeypot_bans (ip_address, user_agent) VALUES (?, ?)");
        $stmt->execute([$ip, $ua]);
    } catch (Exception $e) { /* Fail silently */ }
}

// 4. Play Dumb
header("HTTP/1.1 404 Not Found");
?>
<!DOCTYPE html>
<html>
<head><title>404 Not Found</title></head>
<body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body>
</html>