<!doctype html>
<html lang="en">
<head>
	<title>Unauthorized Access</title>
	<meta charset="UTF-8">
	<script src="https://www.google.com/recaptcha/api.js" async defer></script>
	<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
	<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
	<?php require('../recaptcha.php'); ?>
	<?php
		$lang = "en";
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
			$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
		}
		if(file_exists('../'.$lang.'.php')) {
			require('../'.$lang.'.php');
		}else{
			require('../en.php');
		}
	?>

<div class="container-fluid">
	<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAA8CAYAAACEhkNqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
[encoded data, 13783 characters]
m1hngnebTLMxlxQ8W6k4u5zzZHp7+H9AvfLOjcU5DwAAAABJRU5ErkJggg==" />
	<div class="alert alert-warning"><h2><?php echo $lang["warning"]; ?></h2></div>
	<p><?php echo $lang["contact"]; ?></p>
	<p><?php echo $lang["blocked ip"]; ?> <b><?php echo $_SERVER['REMOTE_ADDR'] ?></b></p>
	<p><?php echo $lang["hostname"]; ?> <b><?php echo php_uname('n'); ?></b></p>

	<br />
	<p><?php echo $lang["recaptcha title"]; ?></p>

	<form action="" method="POST">
		<div class="row">
			<div class="col-md-4 col-md-offset-4">
				<div class="panel panel-default">
					<div class="panel-body">
						<div class="g-recaptcha" data-sitekey="<?php echo $sitekey; ?>"></div>
					</div>
					<div class="panel-footer text-center">
						<button class='btn btn-primary' type="submit" name="submit"><?php echo $lang["unblock submit"]; ?></button>
					</div>
				</div>
			</div>
		</div>
	</form>

	<br />
	<?php
		if (!empty($_POST)) {
			$alert = '';
			$message = '';
			$pieces = explode(".", php_uname('n'));
			$date = @date('M j H:i:s'). " " . $pieces[0] . " ";
			if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
				$data = array('secret' => $secret,'response' => $_POST['g-recaptcha-response']);
				$verify = curl_init();
				curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
				curl_setopt($verify, CURLOPT_POST, true);
				curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
				curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
				$verifyResponse = curl_exec($verify);
				$responseData = json_decode($verifyResponse);
				if($responseData->success) {
					if ($responseData->hostname == $_SERVER['SERVER_NAME']) {
						$alert = 'success';
						$message = $lang["recaptcha success"] . "<br /><a href='" . $_SERVER['REQUEST_URI'] . "'>" . $_SERVER['REQUEST_URI'] . "</a>";
						file_put_contents($unblockfile, $_SERVER['REMOTE_ADDR'].";".$_SERVER['SERVER_NAME'].";".$_SERVER['SERVER_ADDR']."\n", FILE_APPEND | LOCK_EX);
						file_put_contents($logfile,$date . "*Success*, ReCaptcha (" . $_SERVER['REMOTE_ADDR'].": [".$_SERVER['SERVER_NAME']." (".$_SERVER['SERVER_ADDR'].")] requested unblock\n", FILE_APPEND | LOCK_EX);
					} else {
						$alert = "danger";
						$message = $lang["recaptcha hostfail"] . ' ['.$responseData->hostname.' != '.$_SERVER['SERVER_NAME'].']';
						file_put_contents($logfile,$date . "*Failed*, ReCaptcha (" . $_SERVER['REMOTE_ADDR'].": [".$_SERVER['SERVER_NAME']." (".$_SERVER['SERVER_ADDR'].")] does not appear to be hosted on this server\n", FILE_APPEND | LOCK_EX);
					}
				} else {
					$alert = "danger";
					$message = $lang["recaptcha failure"];
					file_put_contents($logfile,$date . "*Error*, ReCaptcha (" . $_SERVER['REMOTE_ADDR'].": $responseData\n", FILE_APPEND | LOCK_EX);
				}
			} else {
				$alert = "danger";
				$message = $lang["recaptcha error"];
			}
			echo '<div class="alert alert-' . $alert . '"><h4>' . $message . '</h4></div>';
		}
	?>

	<div class="alert alert-info"><?php echo $lang["recaptcha note"]; ?></div>
</div>
</body>
</html>
