Code:
<?php
if (stripos($_SERVER['HTTP_USER_AGENT'], 'google') !== false) { // don't block googlebot
define('NEO_SEND_SOME_BOTS_TO_403', false);
} else {
define('NEO_SEND_SOME_BOTS_TO_403', true);
}
if (strlen($_SERVER['REMOTE_ADDR']) < 8) {
$ip = '0.0.0.0';
} else {
$ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_SANITIZE_STRING,FILTER_FLAG_STRIP_HIGH);
}
$checkbot = "SELECT bot_flag, country_iso2 FROM session WHERE country_iso2 IN ('RU','CN','KR','KP','UA','TW') AND userid = 0 AND host ='" . $ip . "' LIMIT 1";
$session_info = $vbulletin->db->query_first($checkbot);
if ($session_info['bot_flag'] == '1' && $session_info && NEO_SEND_SOME_BOTS_TO_403) {
$file = '/var/log/apache2/debug/neo_global_country_bot_block_403.log';
if ($neo_global['debug_block_with_403']) {
error_log(date(DATE_RFC822) . ' SEND 403 Page: ' . $_SERVER['REMOTE_ADDR'] . ' Country: ' . $session_info['country_iso2'] . "\n", 3, $file);
}
header($_SERVER["SERVER_PROTOCOL"] . " 403 Forbidden", true, 403);
include '/var/www/status/403.html';
die;
}