User Name
Password
AppleNova Forums » Programmer's Nook »

Need help getting my sandtrap working again


Register Members List Calendar Search FAQ Posting Guidelines
Need help getting my sandtrap working again
Thread Tools
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Tidewater Virginia
Send a message via AIM to turtle Send a message via Yahoo to turtle  
Old 2011-08-03, 00:16

New host and things are working quite right. This used to work with an old host but haven't been able to get it working. My idea came from this post on a really old host's forum. So the basic idea is some bot crawls my site and ignores my do not enter sign in the robots.txt. In doing so they follow a link to a php function that gets their IP address and adds it to a txt file. That file is referenced in the .htaccess where if your number is in there you are 403'd out of the site.

So my .htaccess looks like this only with more bad_bot entries
Code:
SetEnvIfNoCase User-Agent "^Wildsoft Surfer" bad_bot SetEnvIfNoCase User-Agent "^WWWOFFLE" bad_bot SetEnvIfNoCase User-Agent "^Xaldon WebSpider" bad_bot SetEnvIfNoCase User-Agent "^ZBot" bad_bot <Limit GET POST> Order Allow,Deny Allow from all Deny from env=bad_bot </Limit> SetEnvIfNoCase Request_URI ban-ip\.txt ban <Files ~ "^.*$"> order allow,deny allow from all deny from env=ban </Files>
My sandtrap URL in my main index.html is
Code:
<div style="display:none;"><a href="http://mydomain.com/sandtrap">Sandtrap, I wouldn't click here if I were you. You need to allow Java Script on this site. :) </a></div>
robots.txt is this plus a few more things
Code:
User-agent: * Disallow: /sandtrap Disallow: /ban-ip
My sandtrap/index.php has this in it
PHP Code:
<?php 
$ip 
"$REMOTE_ADDR\n" 
$banip '/home/username/public_html/ban-ip/ban-ip.txt'
$fp fopen($banip"a"); 
$write fputs($fp$ip); 
fclose($fp); 
?>
List of banned IPs in /home/username/public_html/ban-ip/ban-ip.txt

Problem being is it's not working on my new server. Two issues. One is that the users IP isn't being added to the ban-ip.txt. It is adding a new line to the file, but not an IP. Then, even after manually adding my IP to the list I'm not being blocked at all. Can anyone with some better guidance step in here and help me out with this?

Louis L'Amour, “To make democracy work, we must be a notion of participants, not simply observers. One who does not vote has no right to complain.”
MineCraft? mc.applenova.com | Visit us! | Maybe someday I'll proof read, until then deal with it.
turtle is offline   quote
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Tidewater Virginia
Send a message via AIM to turtle Send a message via Yahoo to turtle  
Old 2011-08-03, 00:36

I found this function/script that seems to work well in getting the IP and would love to see if incorporated if someone who know php far better than me wouldn't mind help out with this. I'd love the page to display their IP and add it to the ban-ip.txt file.
PHP Code:
<?php 
if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
$ip=$_SERVER["REMOTE_ADDR"] . ' '
} else if ( isset(
$_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
$ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' '
} else if ( isset(
$_SERVER["HTTP_CLIENT_IP"]) )    { 
$ip=$_SERVER["HTTP_CLIENT_IP"] . ' '

echo 
'Clients IP  Address: ' $ip
?>
Edit: So in messing around I came up with this:
PHP Code:
<?php 
if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
$ip=$_SERVER["REMOTE_ADDR"] . ' '
} else if ( isset(
$_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
$ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' '
} else if ( isset(
$_SERVER["HTTP_CLIENT_IP"]) )    { 
$ip=$_SERVER["HTTP_CLIENT_IP"] . ' '

$banip '/home/turtle24/public_html/ban-ip/ban-ip.txt'
$fp fopen($banip"a"); 
$write fputs($fp$ip); 
fclose($fp); 
echo 
'Clients IP  Address: ' $ip
?>
</center>
This adds the IP to the file, but it doesn't return to the next line meaning it just stacks one after the other.


Also, if there is a way to do the same thing with HTML that would be awesome. I don't think I need it, but it'd be cool to have. I only need this code in the sandtrap folder so it's not going to be viewed or anything. Just be cool if it were available.

Louis L'Amour, “To make democracy work, we must be a notion of participants, not simply observers. One who does not vote has no right to complain.”
MineCraft? mc.applenova.com | Visit us! | Maybe someday I'll proof read, until then deal with it.

Last edited by turtle : 2011-08-03 at 00:52.
turtle is offline   quote
turtle
Lord of the Rant.
Formerly turtle2472
 
Join Date: Mar 2005
Location: Tidewater Virginia
Send a message via AIM to turtle Send a message via Yahoo to turtle  
Old 2011-08-03, 10:24

PHP Code:
<center>
<?php 
if ( isset($_SERVER["REMOTE_ADDR"]) )    { 
$ip=$_SERVER["REMOTE_ADDR"] . " \n"
} else if ( isset(
$_SERVER["HTTP_X_FORWARDED_FOR"]) )    { 
$ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . " \n"
} else if ( isset(
$_SERVER["HTTP_CLIENT_IP"]) )    { 
$ip=$_SERVER["HTTP_CLIENT_IP"] . " \n"

$banip '/home/turtle24/public_html/ban-ip/ban-ip.txt'
$fp fopen($banip"a"); 
$write fputs($fp$ip); 
fclose($fp); 
echo 
'Your IP Address: ' $ip
?>
</center>
Got the writing of the ban-ip.txt working right. Now I just need to get .htaccess to read and use the file properly. So who here knows .htaccess really well? As best I understand it should be something with this part of the file:
Code:
SetEnvIfNoCase Request_URI ban-ip\.txt ban <Files ~ "^.*$"> order allow,deny allow from all deny from env=ban </Files>
Also, all files are in or in subfolders of the public_html. .htaccess resides in the public_html directly. ban-ip and sandtrap folders a child folders of public_html.

Louis L'Amour, “To make democracy work, we must be a notion of participants, not simply observers. One who does not vote has no right to complain.”
MineCraft? mc.applenova.com | Visit us! | Maybe someday I'll proof read, until then deal with it.
turtle is offline   quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh not working through Terminal kieran Genius Bar 7 2007-08-18 10:52
USB not working right sweattyc Genius Bar 4 2007-05-26 20:59
Working on My Car drewprops AppleOutsider 15 2006-07-01 22:16
onclick not working in firefox, but working on IE/netscape sri_kon Programmer's Nook 3 2006-04-20 10:13
Fan not working at all Myst Genius Bar 4 2005-06-08 01:23


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 02:28.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2012, AppleNova
AppleNova Slim