First.. This is my first post to the list.. I hope that I'm not asking something thats already been answered. If I have, please point me in the right direction, and I'll gratefully go where needed. And sorry for the length of the email.. I tried to be as verbose as I could so if someone could help, they'd have as much info as I could give them. If I shouldve done otherwise, let me know.

Next, the obligatory verions and whatnot..

[EMAIL PROTECTED] conf]# /usr/sbin/httpd -v
Server version: Apache/2.0.40

[EMAIL PROTECTED] conf]# /usr/sbin/httpd -l
Compiled in modules:
 core.c
 prefork.c
 http_core.c
 mod_so.c
(so mod_perl is not compiled in)

A look through httpd.conf does not do a LoadModule *perl* .. and a ps -ex does not show mod_perl being loaded on the command line, but a <IfModule mod_perl.c> ... </IfModule> works.. So I know mod_perl is installed.

What version of mod_perl? Not sure. CPAN wants me to upgrade to 1.29 (though I cant currently without destroying Plesk)

Okay. So, now on to my question..

I'm wanting to do a server-wide "bad referer" check.. If any one of x keywords is in the referer, then return a 404 or 500 or something.

In my httpd.conf I added:

<IfModule mod_perl.c>
<LocationMatch "^/+?">
      PerlTransHandler Apache::BadRefs;
</LocationMatch>
</IfModule>

The module I've written

package Apache::BadRefs;

use strict;

my $badwords = join "|", qw{sex viagra ambien anzwers};

# declare these here since I dont have an Apache::Constants
use constant OK => "200";
use constant DECLINED => "404";

sub handler {
       my $r = shift;

       return OK unless $r->header_in('Referer') ne '';

       return OK unless $r->header_in('Referer') ne '-';

       if ($r->header_in('Referer') =~ /$badwords/i) {
               return DECLINED;
       } else {
               return OK;
       }
}

1;

Now.. All seems right.. To me at least.. But whenever I restart apache, it errors out (and Ive yet to find anything in the logs saying why or what is causing the problem)

Anyone have any ideas?

Reply via email to