<?php
if(!isset($ab_version)) die('access denied');

$color_base64['RED'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg=='; // красный
$color_base64['BLACK'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII='; // черный
$color_base64['YELLOW'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5/hPwAIAgL/4d1j8wAAAABJRU5ErkJggg=='; // желтый
$color_base64['GRAY'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNs+A8AAgUBgQvw1B0AAAAASUVORK5CYII='; // серый
$color_base64['BLUE'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg=='; // синий
$color_base64['GREEN'] = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkaGD4DwACiQGBU29HsgAAAABJRU5ErkJggg=='; // зеленый

// проверка цветными кнопками:
shuffle($ab_config['colors']);
$color = $ab_config['colors'][0]; // оригинал названия цвета
$colorhash = hash('sha256', $ab_config['salt'].$color.$ab_config['time'].$ab_config['pass'].$ab_config['ip']); // хэш правильного цвета

echo '<script>var adb = 1; var score = 0;</script>
<script id="adblock-blocker" src="'.$ab_config['webdir'].'static/peel.js?bannerid='.$ab_config['time'].'"></script>
'; // adblock detect

$cloud_test_func_name = 'f'.md5($ab_config['ip'].$ab_config['time']);

if ($ab_config['re_check'] == 1) {
echo '<script src="https://www.google.com/recaptcha/api.js?render='.$ab_config['recaptcha_key'].'"></script>';
}

$ab_output = array();
$ab_parse_url = parse_url($ab_config['uri']); // текущий урл
if ($ab_config['utm_referrer'] == 1 AND $ab_config['referer'] != '') {
if (isset($ab_parse_url['query'])) {
parse_str($ab_parse_url['query'], $ab_output);
}

$ab_output['utm_referrer'] = isset($_GET['utm_referrer']) ? trim(strip_tags($_GET['utm_referrer'])) : $ab_config['referer'];
if (!isset($ab_parse_url['path']) OR $ab_parse_url['path'] == '') {$ab_parse_url['path'] = '/';}
$ab_new_url = $ab_parse_url['path'].'?'.http_build_query($ab_output);
} else {
$ab_new_url = $ab_config['uri'];
}

?>

<script>
if (window.location.hostname !== window.atob("<?php echo base64_encode($ab_config['host']); ?>") && window.location.hostname !== window.atob("<?php echo base64_encode(strstr($ab_config['host'], ':', true)); ?>")) {
window.location = window.atob("<?php echo base64_encode('http://'.$ab_config['host'].$ab_config['uri']); ?>");
throw "stop";
}
   
function b64_to_utf8(str) {
str = str.replace(/\s/g, '');    
return decodeURIComponent(escape(window.atob(str)));
}

document.getElementById("content").innerHTML = "<?php echo abTranslate('Loading...'); ?>"; //
setTimeout(Button, <?php echo $ab_config['timer']; ?>000);

var country = '<?php echo $ab_config['country']; ?>';
var h1 = '<?php echo hash('sha256', $ab_config['email'].$ab_config['pass'].$ab_config['host'].$ab_config['useragent'].$ab_config['accept_lang'].$ab_config['ip'].'1'.$ab_config['time']); ?>';
var h2 = '<?php echo md5('Antibot:'.$ab_config['email']); ?>';
var ip = '<?php echo $ab_config['ip']; ?>';
var v = '<?php echo $ab_version; ?>';
var cid = '<?php echo $ab_config['cid']; ?>';
var ptr = '<?php echo $ab_config['ptr']; ?>';
var width = screen.width;
var height = screen.height;
var cwidth = document.documentElement.clientWidth;
var cheight = document.documentElement.clientHeight;
var colordepth = screen.colorDepth;
var pixeldepth = screen.pixelDepth;
var referrer = '<?php echo $ab_config['refhost']; ?>';
var scheme = '<?php echo $ab_config['refhost_scheme']; ?>';
var date = '<?php echo $ab_config['time']; ?>';
var hdc = '<?php echo $ab_config['hosting']; ?>';

<?php if ($ab_config['re_check'] == 1) { ?>
grecaptcha.ready(function() {
// receiving token
grecaptcha.execute('<?php echo $ab_config['recaptcha_key']; ?>', {action: '<?php echo $ab_config['country']; ?>'}).then(function(token) {
console.log(token);
var script = document.createElement('script');
script.src = '<?php echo $ab_config['webdir']; ?>re.php?token='+token+'&ip=<?php echo $ab_config['ip']; ?>&rand=<?php echo $ab_config['cid']; ?>';
document.body.appendChild(script);
// token received
script.onload = function() {
data = 'hdc='+hdc+'&scheme='+scheme+'&a='+adb+'&score='+score+'&date='+date+'&country='+country+'&h1='+h1+'&h2='+h2+'&ip='+ip+'&v='+v+'&cid='+cid+'&ptr='+ptr+'&w='+width+'&h='+height+'&cw='+cwidth+'&ch='+cheight+'&co='+colordepth+'&pi='+pixeldepth+'&ref='+referrer;
<?php echo $cloud_test_func_name; ?>(window.atob('<?php echo base64_encode($ab_config['check_url']); ?>'), data, '');
}
});
});      
<?php } else { ?>
var data = 'hdc='+hdc+'&scheme='+scheme+'&a='+adb+'&date='+date+'&country='+country+'&h1='+h1+'&h2='+h2+'&ip='+ip+'&v='+v+'&cid='+cid+'&ptr='+ptr+'&w='+width+'&h='+height+'&cw='+cwidth+'&ch='+cheight+'&co='+colordepth+'&pi='+pixeldepth+'&ref='+referrer;
<?php echo $cloud_test_func_name; ?>(window.atob('<?php echo base64_encode($ab_config['check_url']); ?>'), data, '');
<?php } ?>


function Button() {
<?php if ($ab_config['input_button'] != 1) { 
if ($ab_config['buttons'] == 1 AND function_exists('imagecreatetruecolor')) {
shuffle($ab_config['colors']);
$tags = array('div', 'span', 'b', 'strong', 'i', 'em');
shuffle($tags);
$buttons = '<p>';
foreach ($ab_config['colors'] as $ab_config['color']) {
// background:'.$ab_config['color'].';
$buttons .= '<'.$tags[0].' style=\"background-image: url(data:image/png;base64,'.$color_base64[$ab_config['color']].');\" class=\"'.'s'.md5('antibot-btn-color'.$ab_config['time']).'\" onclick=\"'.$cloud_test_func_name.'(window.atob(\''.base64_encode($ab_config['webdir'].'post.php').'\'), data, \''.$ab_config['color'].'|'.$colorhash.'\')\"></'.$tags[0].'> ';
}
$buttons .= '</p>';

$im = imagecreatetruecolor(rand(1,30), rand(1,30));

$color_code['RED'] = imagecolorallocate($im, rand(220,255), rand(0,30), rand(0,30)); // красный
$color_code['BLACK'] = imagecolorallocate($im, rand(0,15), rand(0,25), rand(0,25)); // черный
$color_code['YELLOW'] = imagecolorallocate($im, rand(245,255), rand(220,255), rand(0,25)); // желтый
$color_code['GRAY'] = imagecolorallocate($im, rand(120,130), rand(125,135), rand(125,135)); // серый
$color_code['BLUE'] = imagecolorallocate($im, rand(0,30), rand(0,30), rand(155,255)); // синий
$color_code['GREEN'] = imagecolorallocate($im, rand(0,30), rand(125,250), rand(0,30)); // зеленый

imagefill($im, 0, 0, $color_code[$color]);
ob_start(); 
imagepng($im);
imagedestroy($im);
$image_data = ob_get_contents(); 
ob_end_clean(); 
?>
document.getElementById("content").innerHTML = "<div class=\"<?php echo 's'.md5('antibot-btn-color'.$ab_config['time']); ?>\" style=\"cursor: none; pointer-events: none; background-image: url(data:image/png;base64,<?php echo base64_encode($image_data); ?>);\" /></div><p><?php echo abTranslate('Antispam:'); ?> <?php echo abTranslate('Choose a similar color.'); ?> <?php echo ($ab_config['time_ban'] > 0) ? abTranslate('You have one try.') : ''; ?></p><?php echo $buttons; ?>";
<?php } else { ?>
document.getElementById("content").innerHTML = b64_to_utf8('<?php echo base64_encode('<p>'.abTranslate('Antispam:').'</p><div style="cursor: pointer;" class="'.'s'.md5('antibot-btn-success'.$ab_config['time']).'" onclick="'.$cloud_test_func_name.'(\''.$ab_config['webdir'].'post.php\', data, \'секрет\')">'.abTranslate('I\'m not a robot.').'</div>'); ?>');
<?php }} ?>
}

function <?php echo $cloud_test_func_name; ?>(s, d, x){
d = d + '&xxx=' + x;
var cloud = new XMLHttpRequest();
cloud.open("POST", s, true)
cloud.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;');

cloud.onload = function () {
if(cloud.status == 200) {
// облако успешно ответило
console.log('good: '+cloud.status);
var obj = JSON.parse(this.responseText);
if (typeof(obj.error) == "string") {
<?php if(!defined('ANTIBOT_ADMIN')) { ?>
if (obj.error == "Account Not Found." || obj.error == "This domain is not licensed." || obj.error == "Subscription has expired." || obj.error == "This domain is blacklisted.") {
const ErrorMsg = document.createElement('div');
ErrorMsg.innerHTML = '<div style="text-align:center; color:red;">'+obj.error+'</div>';
document.body.insertAdjacentElement('afterbegin', ErrorMsg);

document.getElementById("content").style.visibility = "hidden";
}
<?php } ?>
var script = document.createElement("script");
script.src = "<?php echo $ab_config['webdir']; ?>upd.php?cid=<?php echo $ab_config['cid']; ?>&w="+width+"&h="+height+"&cw="+cwidth+"&ch="+cheight+"&co="+colordepth+"&pi="+pixeldepth+"&a="+adb+"&score="+score+"&result="+encodeURIComponent(obj.error)+"&newurl=0&xxx="+x;
script.async = true;
document.head.appendChild(script);
}
if (typeof(obj.cookie) == "string") {
var d = new Date();
d.setTime(d.getTime() + (7 * 24 * 60 * 60 * 1000));
var expires = "expires="+ d.toUTCString();
document.cookie = "antibot_<?php echo $ab_config['uid']; ?>="+obj.cookie+"-<?php echo $ab_config['time']; ?>; SameSite=Lax;; " + expires + "; path=/;";
document.getElementById("content").innerHTML = "<?php echo abTranslate('Loading...'); ?>";
var script = document.createElement("script");
script.src = "<?php echo $ab_config['webdir']; ?>upd.php?cid=<?php echo $ab_config['cid']; ?>&w="+width+"&h="+height+"&cw="+cwidth+"&ch="+cheight+"&co="+colordepth+"&pi="+pixeldepth+"&a="+adb+"&score="+score+"&result=&newurl=<?php
if ($ab_config['utm_referrer'] == 1) {
echo '"+encodeURIComponent("'.$ab_new_url.'")+"';
} else {
echo '1';
}
?>&xxx="+x;
script.async = true;
document.head.appendChild(script);
} else {
Button();
console.log('bad bot');
}
} else {
console.log('other error');
Button();
// код ответа не 200, это не должно было произойти
var script = document.createElement("script");
script.src = "<?php echo $ab_config['webdir']; ?>upd.php?cid=<?php echo $ab_config['cid']; ?>&w="+width+"&h="+height+"&cw="+cwidth+"&ch="+cheight+"&co="+colordepth+"&pi="+pixeldepth+"&a="+adb+"&score="+score+"&result=Server+Error&newurl=0&xxx=";
script.async = true;
document.head.appendChild(script);

}
};
cloud.onerror = function(){
	console.log("error: "+cloud.status);
	Button();
// до облака не достучались или не пытались (код ответа не 200)
var script = document.createElement("script");
script.src = "<?php echo $ab_config['webdir']; ?>upd.php?cid=<?php echo $ab_config['cid']; ?>&w="+width+"&h="+height+"&cw="+cwidth+"&ch="+cheight+"&co="+colordepth+"&pi="+pixeldepth+"&a="+adb+"&score="+score+"&result=No+Answer+from+Cloud&newurl=0&xxx=";
script.async = true;
document.head.appendChild(script);
}
cloud.ontimeout = function () {
  console.log('timeout');
  Button();
};
cloud.send(d);
}

</script>
