Forum Moderators: coopster
The email the script sends is not delivering the IP address of the intruding bot. My error logs give the following - which seems to indicate the problem:
PHP Notice: Undefined variable: bot_ip in /var/www/vhosts/mydomain/httpdocs/trap/get_lost.php on line 33
line 33 of the script reads:
msg = "address is " . $bot_ip . "\nagent is " . $_SERVER['HTTP_USER_AGENT'] . "\n";
the resulting bad bot email reads: (there is a blank after "address is" instead of the IP)
************************************
A bad bot hit /WebCalendar/any.file
at 2007-09-28-(Fri)-15:14:40
address is
agent is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7
*************************************
the get_lost script is here: the "$bot_ip" string seems to work when applied to writing to .htaccess but doesn't seem to return a result when writing the email
*********************************
<?php
function userIP(){
switch ($_SERVER){
case 'HTTP_CLIENT_IP':
$userip = $_SERVER['HTTP_CLIENT_IP'];
break;
case 'HTTP_X_FORWARDED_FOR':
$userip = $_SERVER['HTTP_X_FORWARDED_FOR'];
break;
case 'HTTP_X_FORWARDED':
$userip = $_SERVER['HTTP_X_FORWARDED'];
break;
case 'HTTP_FORWARDED_FOR':
$userip = $_SERVER['HTTP_FORWARDED_FOR'];
break;
case 'HTTP_FORWARDED':
$userip = $_SERVER['HTTP_FORWARDED'];
break;
default:
$userip = $_SERVER['REMOTE_ADDR'];
break;
}
return $userip;
}
function tel_me(){
$day = date("Y-m-d-(D)-H:i:s",time());
$from = "badbots@mydomain\r\n"; //edit for the right email address
$to = "badbots@mydomain"; //edit for the right email address
$subject = "Alert: bad robot";
$msg = "A bad bot hit ". $_SERVER['REQUEST_URI'] ."\nat ". $day . " \n";
msg = "address is " . $bot_ip . "\nagent is " . $_SERVER['HTTP_USER_AGENT'] . "\n";
$msg = wordwrap($msg, 70);
mail($to, $subject, $msg, "From: $from");
}
function block_bot($t, $f){
$fh = fopen($f, 'ab');// open in binary mode just in case
fwrite($fh, $t);
fclose($fh);
}
$bot_ip = userIP();
// block the bot
$txt = "deny from $bot_ip\n";
$file = '/var/www/vhosts/mydomain/httpdocs/.htaccess'; //edit for path to your htaccess file
block_bot($txt, $file);
tel_me();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>That was a silly thing to do!</title>
</head>
<body>
<h1>Congratulations</h1>
<p>You have succeeded in getting your self blocked from this site.<br />
You were warned about coming here. Have a nice life.</p>
<p>Bye</p>
</body>
</html>
****************************************
Any ideas why the IP isn't getting into the email?
Many thanks.
without the statement - email says:
A bad bot hit /WebCalendar/anyfilem.kjh
at 2007-09-29-(Sat)-16:37:04
address is
agent is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7
with the statement - email says:
A bad bot hit /WebCalendar/anyfilem.kjh
at 2007-09-29-(Sat)-16:35:41
address is **.***.249.9
agent is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.7)
Gecko/20070914 Firefox/2.0.0.7