Forum Moderators: phranque

Message Too Old, No Replies

htaccess and a banlist

         

jaeysson

9:43 am on Dec 11, 2006 (gmt 0)

10+ Year Member



Trying to get htaccess to deny by using a banlist that has IP's in a text file on the server. I am not very good with coding htaccess yet. Does anyone know what I should put in the SetEnvIfNoCase so that it can get the IPs in ban-ip.txt?

Here is the code I have tried in my htaccess file:

SetEnvIfNoCase Request_URI ^/ban-ip/ban-ip.txt$ ban

deny from env=ban

*If you need my full htaccess file I can post it if it will be helpful.

Thanks

jdMorgan

5:35 pm on Dec 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no support for "including" an external file in mod_setenvif, or in .htaccess itself.

If you have server configuration-level privileges so that you can modify httpd.conf or conf.d, for example, then you can define a RewriteMap function in mod_rewrite in the config file, and access that map from .htaccess using the rewritemap-access method of RewriteCond and RewriteRule.

Otherwise, I'd suggest implementing your access controls as a script included on your pages, or writing a script to serve your pages by checking access controls and then reading and sending their content.

Another possibility is to write a script that takes your ban-list text file as input, and creates or prepends mod_setenvif directives to your existing .htaccess file, based on manual invocation or a periodic cron job.

Jim

jaeysson

6:27 pm on Dec 11, 2006 (gmt 0)

10+ Year Member



I got it. I created a php script on every one of my pages that checks the banlist.txt file. If the IP address is in the list it opens a page that goes no where and emails me.

I like this method rather than filling up my htaccess file with deny from IPs.

Thanks for the advice/response.

Now I just need a way to catch the spam bots that try to post to my PHPBB forum. Any ideas?

jdMorgan

8:33 pm on Dec 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of posting directly to the PHPbb forum script, have the POST go to a script that implements the filters you need, and then posts the data to the forum. I'd suggest filtering for REMOTE_ADDR, REMOTE_HOST, and X_FORWARDED_FOR, as well as filtering all 'special characters' out of the post data itself, such as HTML tags and redirection pipes (this latter may already be done by PHPbb -- I'm not a forum owner, so I'm not sure).

Jim