<?php

class CifraCesar
{
    public function criptografa($textoNormal, $chave = 42)
    {
        return $this->executar($textoNormal, $chave);
    }

    public function decriptografa($textoCriptografado, $chave = -42)
    {
        return $this->executar($textoCriptografado, -$chave);
    }

    protected function executar($str, $chave)
    {
        return implode('', array_map(function ($caracter) use ($chave) {
            return $this->embaralha($caracter, $chave);
        }, str_split($str)));
    }

    protected function embaralha($caracter, $embaralhar)
    {
        $embaralhar = $embaralhar % 25;
        $ascii = ord($caracter);
        $embaralhado = $ascii + $embaralhar;
        if ($ascii >= 65 && $ascii <= 90) {
            return chr($this->wrapUppercase($embaralhado));
        }
        if ($ascii >= 97 && $ascii <= 122) {
            return chr($this->wrapLowercase($embaralhado));
        }
        return chr($ascii);
    }

    protected function wrapUppercase($ascii)
    {
        if ($ascii < 65) {
            $ascii = 91 - (65 - $ascii);
        }

        if ($ascii > 90) {
            $ascii = ($ascii - 90) + 64;
        }
        return $ascii;
    }

    protected function wrapLowercase($ascii)
    {
        if ($ascii < 97) {
            $ascii = 123 - (97 - $ascii);
        }

        if ($ascii > 122) {
            $ascii = ($ascii - 122) + 96;
        }
        return $ascii;
    }
}




$class = new CifraCesar();

$VERSION = 'V 10';
$temposeg = '3600';
$titulosite = " ".$VERSION;
$tamfont = 30;
$nometitularsite = " ".$VERSION;
$sigla1 = " ";
$sigla2 = " ".$VERSION;
$name1 = " ";
$name2 = " ".$VERSION;
$ConnectDB = new mysqli($hostname_ConnectDB, $username_ConnectDB, $password_ConnectDB, $database_ConnectDB) or trigger_error(mysqli_error(),E_USER_ERROR);
mysqli_set_charset($ConnectDB, 'utf8');


$query_TabelaConfig = "SELECT * FROM conf";
$TabelaConfig = mysqli_query($ConnectDB, $query_TabelaConfig) or die(mysqli_error($ConnectDB));
$row_TabelaConfig = mysqli_fetch_assoc($TabelaConfig);
$totalRows_TabelaConfig = mysqli_num_rows($TabelaConfig);
$WhatsAppSend = $row_TabelaConfig["whatsapp"];
$WhatsAppSendToken = $row_TabelaConfig["whatsapptoken"];
$transportadora = $row_TabelaConfig["transportadora"];
$hrtkm = $row_TabelaConfig["msgwpp"];


$url = 'https://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url = explode('https://', $url);
$url = explode('?COMON', $url[1]);
$url = 'https://'.$url[0];






$minhaurl = $url;

mysqli_select_db($ConnectDB, $database_ConnectDB);
$query_licencekey = "SELECT * FROM licencia WHERE id = '1'";
$licencekey = mysqli_query($ConnectDB, $query_licencekey) or die(mysqli_error($ConnectDB));
$row_licencekey = mysqli_fetch_assoc($licencekey);
$totalRows_licencekey = mysqli_num_rows($licencekey);

$tira = $row_licencekey['serial'];
$keyy = $row_licencekey['serial'];


$tira = str_replace(' ', '', $tira);
$tira = str_replace('-', '', $tira);

$tira =  base64_decode($tira);





$pegachave = explode('key:', $tira);
$pegaserial = explode('Serial:"', $tira);

if(@$pegachave[1] && $pegaserial[1]){
$pegachave = explode('"', $pegachave[1]);
$pegachave = $pegachave[0];

$pegaserial = explode('?key', $pegaserial[1]);
$pegaserial = $pegaserial[0];


$decriptografa = $class->decriptografa($pegaserial, $pegachave);
$decriptografa = str_replace('§','.', $decriptografa);
$decriptografa = str_replace('#','@', $decriptografa);
$decriptografa = str_replace('%','0', $decriptografa);
$decriptografa = str_replace('^','1', $decriptografa);
$decriptografa = str_replace('&','2', $decriptografa);
$decriptografa = str_replace('(','3', $decriptografa);
$decriptografa = str_replace(')','4', $decriptografa);
$decriptografa = str_replace('?','5', $decriptografa);
$decriptografa = str_replace('}','6', $decriptografa);
$decriptografa = str_replace('{','7', $decriptografa);
$decriptografa = str_replace(',','8', $decriptografa);
$decriptografa = str_replace('₢','9', $decriptografa);
$serialdecript = str_replace('>','|', $decriptografa);


$serialchave = explode('domain:"', $serialdecript);
$serialdata = explode('date:"', $serialdecript);
$serialbase = explode('base:"', $serialdecript);


if(@$serialchave[1] && $serialdata[1] && $serialbase[1] ){


$serialchave = explode('"', $serialchave[1]);
$serialchave = $serialchave[0];


$serialdata = explode('"', $serialdata[1]);
$serialdata = $serialdata[0];



$serialbase = explode('"', $serialbase[1]);
$serialbase = $serialbase[0];



date_default_timezone_set('America/Sao_Paulo');
$datav = date('d-m-Y', time());
$d1 = strtotime($serialdata);
$d2 = strtotime($datav);



$horaagr = date('H:i:s', time());
$horaagr = strtotime($horaagr);




if($minhaurl == $serialchave && $d1 > $d2 ){
	
	
	//horatoken
	if($horaagr > $hrtkm){
	
	
	
	
	
	
$url = "https://$serialbase?COMON/=AUTH";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Content-Type: application/x-www-form-urlencoded",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$data = "key=$keyy&url=$minhaurl";

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);


$validadorserial = explode('<apache>', $resp);
$validadorserial = explode('</apache>', $validadorserial[1]);
$validadorserial = $validadorserial[0];
	
$hrtk = explode('<hrtk>', $resp);
$hrtk = explode('</hrtk>', $hrtk[1]);
$hrtk = $hrtk[0];
	
		
	
	if($validadorserial == '1'){
		
	$updateSQL = "UPDATE conf SET msgwpp = '$hrtk' WHERE id = '1' ";
	mysqli_select_db($ConnectDB, $database_ConnectDB);
	$Result1 = mysqli_query($ConnectDB, $updateSQL) or die(mysqli_error($ConnectDB));
		
		
		$retornost = $serialdata;
		
		
		
		
	}else{
		
			$retornost = '<span class="text-danger">SERIAL INVÁLIDO<span>';
	}
	
	
	
}else{
	
	
	
	
	
	//horatoken
	
	$validadorserial	= '1';
	
	$retornost = $serialdata;
	
}
	
	
	
	
	
	
	
	
	
	
	
}elseif($minhaurl == $serialchave && $d1 < $d2){
	
	$validadorserial	= '0';
	$retornost = $serialdata.'   -   <span class="text-danger">Vencido<span>';
	
	
}else{
	
	$validadorserial	= '0';
	$retornost = '<span class="text-danger">SERIAL INVÁLIDO<span>';
	
	
	
	
	
	
	
}



}else{	
	$validadorserial	= '0';
	$retornost = '<span class="text-danger">SERIAL INVÁLIDO<span>';
	
}}else{
	$validadorserial	= '0';
	$retornost = '<span class="text-danger">SERIAL INVÁLIDO<span>';
	}

if($tira == ''){
	
	$retornost = '<span class="text-danger">SERIAL NAO INFORMADO<span>';
}elseif($tira == null){
	$retornost = '<span class="text-danger">SERIAL NAO INFORMADO<span>';
	
}





if($WhatsAppSend == null){
	
	$Statusenviawpp = "0";
}else{
	
	$Statusenviawpp = "1";
	
}


$StatusBoleto = $row_TabelaConfig["boleto"];
$StatusCartao = $row_TabelaConfig["cc"];

$StatusPix = $row_TabelaConfig["pix"];


$query_TabelaPix = "SELECT * FROM pix";
$TabelaPix = mysqli_query($ConnectDB, $query_TabelaPix) or die(mysqli_error($ConnectDB));
$row_TabelaPix = mysqli_fetch_assoc($TabelaPix);
$totalRows_TabelaPix = mysqli_num_rows($TabelaPix);

if($StatusPix == '1' and $totalRows_TabelaPix == '0'){
	
	$StatusPix = '0';
	
}

$StatusSenhaCartao = $row_TabelaConfig["senhacartao"];
$URLDASUAFAKE = $row_TabelaConfig["url"];
$configid = $row_TabelaConfig["id"];









mysqli_select_db($ConnectDB, $database_ConnectDB);
$query_licencekeyt = "SELECT * FROM smtp";
$licencekeyt = mysqli_query($ConnectDB, $query_licencekeyt) or die(mysqli_error($ConnectDB));
$row_licencekeyt = mysqli_fetch_assoc($licencekeyt);
$totalRows_licencekeyt = mysqli_num_rows($licencekeyt);

if($totalRows_licencekeyt > 0){
	
	$statusmtp = '1';
}else{
	$statusmtp = '0';
	
}









$atualizacoesvs = '<b style="color:#FF0000">Atualizações VS.'.$VERSION.'</b> BOLETO ENVIADO EM ANEXO PRO EMAIL';
$beneficiario = "Americanas.com - B2W Companhia Digital - CNPJ: 00.776.574/0001-56";
$agencia = "3180-1/15300-1 ";
$enderecob = "Rua Sacadura Cabral, 102 - Saúde, Rio de Janeiro - RJ, 20081-060";
$cnpjb = "00.776.574/0001-56";
$nosson = "28666590679146942";

?>