|
Warning: Page Restrictor not installed correctly - Headers already sent!';
return;
}
define('PRES_CLIENT_IP', @$_SERVER['REMOTE_ADDR']);
define('PRES_CLIENT_IP_LONG', ip2long(PRES_CLIENT_IP));
define('PRES_CLIENT_UA', htmlspecialchars(@$_SERVER['HTTP_USER_AGENT']));
define('PRES_CLIENT_REF', (isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : '')); // topic 36673
define('PRES_BASEPATH', str_replace('\\','/', @dirname(__FILE__)));
define('PRES_BASEFILE', PRES_BASEPATH . '/' . @basename(__FILE__));
if (!defined('PRES_LOG_FILE')) define('PRES_LOG_FILE', PRES_BASEPATH.'/page.restrictor.log');
define('PRES_OKT', intval(substr(PRES_CLIENT_IP, 0, strpos(PRES_CLIENT_IP, '.')))); // topic 37379
define('PRES_REQUEST', htmlspecialchars(@$_SERVER['HTTP_HOST']).@$_SERVER['REQUEST_URI']); // runtime wasting, should be used later if really needed!
// check for googlebot, if it's "real real" return = do nothing anymore
if (defined('PRES_CHECK_GOOGLEBOT') && stristr(PRES_CLIENT_UA, 'googlebot')) { // is strpos on "Googlebot/" faster?
$presRDNS = @gethostbyaddr(PRES_CLIENT_IP);
if (strpos($presRDNS,'.googlebot.com') === strlen($presRDNS)-14 && @gethostbyname($presRDNS) == PRES_CLIENT_IP) { // topic 30365
return; // optional: log here the gbot visit
} else {
outRestrictMessage('botfake', PRES_CLIENT_UA); // optional: msg not to fake gbot
}
}
// throw HTTP 403 message to forbidden/bad bots
function outRestrictMessage($reason, $data) {
global $sig;
if (!defined('PRES_LOCK_MSG')) {//if (!isset($forbiddenCustomMessage)) {
$forbiddenCustomMessage =
'
Page Restrictor Ping
*** WEB SPAM PROTECTION / SCHUTZMASSNAHME GEGEN WEB SPAM ***
Sorry for the inconvenience! Entschuldigen Sie bitte diese Unannehmlichkeit!
Obviously your access to this site has been suspended by mistake.
Offensichtlich wurde Ihnen der Zugang zu dieser Site fälschlicherweise verweigert.
By solving the arithmetical problem you can visit this website temporarily (Cookies needed).
Durch Lösung der Rechenaufgabe können Sie diese WebSite temporär besuchen (Cookies benötigt).
{PRES_CAPTCHA}
Please tell us here to remove the lock restriction:
Bitte melden Sie sich hier um die Sperrung aufzuheben:
Complaint Board Beschwerde Forum
';
} else {
$forbiddenCustomMessage = PRES_LOCK_MSG;
}
if(session_id() == '') session_start();
if(!isset($_SESSION['pres_unlock'])) {
//if(strpos(PRES_CLIENT_REF, '.ebesucher.de') === false && strpos(PRES_CLIENT_REF, '.jamalo.de') === false) { // dont log log spammers ;)
if (PRES_LOG_FILE != '') {
$fp = @fopen(PRES_LOG_FILE, 'a+');
if($fp) { // log only iffile available
$thisHost = (!empty($_SERVER['REMOTE_HOST'])) ? htmlspecialchars(@$_SERVER['REMOTE_HOST']) : @gethostbyaddr(PRES_CLIENT_IP);
$log = date('d.m.Y H:i:s').' - '.PRES_CLIENT_IP." $thisHost - ".PRES_CLIENT_UA.' - '.PRES_CLIENT_REF.' - '.PRES_REQUEST." - $reason - $data\n";
fwrite($fp, $log);
fclose($fp);
}
}
//}
pres_captcha($forbiddenCustomMessage, $reason, $data);
}
} // end of function outRestrictMessage
function pres_captcha($forbiddenCustomMessage, $reason, $data) {
global $sig; // workaround to detect castrated pres
$pres_numbers = array(1,2,3,4,5,6,7,8,9);
$pres_operands = array('+', '-', '*');
$pres_number1 = $pres_numbers[array_rand($pres_numbers)];
$pres_number2 = $pres_numbers[array_rand($pres_numbers)];
$pres_operand_key = array_rand($pres_operands);
$pres_operand = $pres_operands[$pres_operand_key];
if(isset($_POST['pres_submit']) && $_POST['pres_submit'] == 'go') {
$pres_code = $_POST['pres_code'];
$pres_number1 = (int)$pres_code{0};
$pres_operand = (int)$pres_code{1};
$pres_number2 = (int)$pres_code{2};
switch ($pres_operand) {
case 0: if($pres_number1 + $pres_number2 == -(int)$_POST['pres_captcha']) $pres_unlock = 1; break;
case 1: if($pres_number1 - $pres_number2 == -(int)$_POST['pres_captcha']) $pres_unlock = 1; break;
case 2: if($pres_number1 * $pres_number2 == -(int)$_POST['pres_captcha']) $pres_unlock = 1; break;
default: die('PRES error (CAPTCHA-Check)');
}
if(isset($_POST['email']) && $_POST['email'] != '') { // extra bot trap (bots may fill this field)
unset($pres_unlock);
header ("Location: http://www.bot-trap.de/spam.php?reason=$reason&data=$data&request=".PRES_REQUEST);
die ("NEARLY OK!");
}
if(isset($pres_unlock)) {
if(session_id() == '') session_start(); // avoid notice
$_SESSION['pres_unlock'] = true;
die (str_pad("OK! click", 1024));
}
else
die (str_pad('NOT OK!', 1024)); // fillup to avoid IE BUG
}
else {
header("HTTP/1.0 403 Forbidden");
$presCAPTCHA = '';
// for korizon detection whether pres lock works
if (strpos($forbiddenCustomMessage, '') === false) {
$forbiddenCustomMessage .= '';
}
if (strpos($forbiddenCustomMessage, '{PRES_CAPTCHA}') === false) {
$forbiddenCustomMessage .= $presCAPTCHA;
} else {
$forbiddenCustomMessage = str_replace('{PRES_CAPTCHA}', $presCAPTCHA, $forbiddenCustomMessage);
}
die ($forbiddenCustomMessage);
}
}
// AUTO UPDATER with possibility guess
$rndNr = rand(1,1000);
if(isset($_GET['pres'])) { // && @basename($_SERVER['PHP_SELF']) == @basename(PRES_BASEFILE)) {
if($_GET['pres'] == 'update') $rndNr = 64; // force update
if($_GET['pres'] == 'check') {
$rightsPres = (@is_writable(PRES_BASEFILE)) ? 'YES' : 'NO';
$canUpdate = (@is_callable('fsockopen')) ? 'YES' : 'NO';
$rightsLog = (@is_writable(PRES_LOG_FILE)) ? 'YES' : 'NO';
$isLogged = (@file_exists(PRES_LOG_FILE)) ? 'YES, is writable: '.$rightsLog : 'NO';
// BEGIN new from 1.7.08 this replaces some old configs
$presConsts = array(
'PRES_BLACKLIST_IP', 'PRES_WHITELIST_IP',
'PRES_BLACKLIST_IPR', 'PRES_WHITELIST_IPR',
'PRES_BLACKLIST_UA', 'PRES_WHITELIST_UA',
'PRES_BLACKLIST_URI',
'PRES_LOCK_MSG',
'PRES_LOG_FILE',
'PRES_CHECK_GOOGLEBOT'
);
$presDefinedConsts = '';
foreach ($presConsts as $presConst) {
if (defined($presConst)) $presDefinedConsts .= "$presConst ";
}
// END new
die("Page Restrictor v$ver - Signatures $sig - Last modified: ".date ('d.m.Y H:i:s', filemtime(PRES_BASEFILE)).'
local (request_uri): '.@$_SERVER['REQUEST_URI'].' uri (php_self): '.@$_SERVER['PHP_SELF'].' server: '.@$_SERVER['HTTP_HOST'].'
is writable: '.$rightsPres.' does fsockopen() work: '.$canUpdate.'
LogFile exists: '.$isLogged.'
Constants defined: '.$presDefinedConsts
);
}
}
if($rndNr == 64 && @is_callable('fsockopen')) {
$fp = @fsockopen("www.bot-trap.de", 80, $errno, $errstr, 10);
if(!$fp) {
die("AutoUpdater failed: $errstr ($errno)");
}
$thisHost = htmlspecialchars(@$_SERVER['HTTP_HOST']);
$thisServerName = htmlspecialchars(@$_SERVER['SERVER_NAME']);
if(@function_exists('stream_set_timeout')) @stream_set_timeout($fp,10);
@fwrite($fp,
"GET /download.php?do=update&sig=$sig&server=$thisHost&servername=$thisServerName&nocache=0 HTTP/1.0\r\n".
"Host: www.bot-trap.de\r\n".
"User-Agent: PRES AutoUpdater\r\n".
"Referer: .\r\n".
"Connection: close\r\n".
"\r\n"
);
$response = '';
while (!feof($fp)) {
$response .= @fread($fp,10240);
}
@fclose($fp);
$content = trim((string)strstr($response,"\r\n\r\n"));
unset($response);
if(substr($content, -2) == '?>') { // overwrite only if file could be downloaded completely
$fp = @fopen(PRES_BASEFILE, 'wb');
@fwrite($fp, $content);
@fclose($fp);
}
elseif(isset($_GET['pres']) && $_GET['pres'] == 'update') {
if($content == 'You have the latest Version!')
die('Unable to Update: Already up-to-date!');
elseif($content == 'You are not allowed to Update!')
die('Unable to Update: Not allowed');
else
die('Unable to Update: Incomplete file transfer or other error');
}
if(isset($_GET['pres']) && $_GET['pres'] == 'update')
die("Page Restrictor Update tried. Check and compare against old Version here: click"); // to v$ver with signatures from $sig
}
// new
if (PRES_CLIENT_IP == @$_SERVER['SERVER_ADDR']) return; // if ip is own server ip leave this script immediately ## todo: restructure code respecting its order!!
// forbidden referer spammers, LINE ENDS HAVE TO BE \n
$forbiddenReferers = << | | | | |