<?php
if(phpversion() >= "4.2.0") {
extract($_SERVER);
}
?>
<html>
<head>
<title>Bad Bot!</title>
</head>
<body>
<span style="font-weight: bold;">There is nothing here to see. So what are you doing here?</span><br />
<a href="../">Go home</a><br />
<?php
$badbot = 0;
/* scan the blacklist.dat file for addresses of SPAM robots to prevent filling it up with duplicates */
$filename = "../blacklist.dat";
$fp = fopen($filename, "r") or die ("Error opening file ... <br />\n");
while ($line = fgets($fp,255)) {
$u = explode(" ",$line);
if(ereg($u[0],$REMOTE_ADDR)) { $badbot++; }
}
fclose($fp);
if ($badbot == 0) {
/* we just see a new bad bot not yet listed ! */
/* send a mail to hostmaster */
$tmestamp = time();
$datum = date("Y-m-d (D) H:i:s",$tmestamp);
$from = "badbot-watch@domain.tld";
$to = "hostmaster@domain.tld";
$subject = "domain-tld alert: bad robot";
$msg = "A bad robot hit $REQUEST_URI $datum \n";
$msg .= "address is $REMOTE_ADDR, agent is $HTTP_USER_AGENT\n";
/* See, I don't want mail; so lets disable it...
mail($to, $subject, $msg, "From: $from");
*/
/* append bad bot address data to blacklist log file: */
$fp = fopen($filename,'a+');
fwrite($fp,"$REMOTE_ADDR - - [$datum] \"$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL\" $HTTP_REFERER $HTTP_USER_AGENT\n");
fclose($fp);
}
?>
</body>
</html>