You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Michael Preslar <mi...@lordlegacy.com> on 2005/11/03 00:19:09 UTC

[Question / Newbie]

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..

[root@apollo conf]# /usr/sbin/httpd -v
Server version: Apache/2.0.40

[root@apollo 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?

Re: [Question / Newbie]

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Michael Preslar wrote:
> [root@apollo 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)
I assume that means it Dynamic.
Check your AddModule/LoadModule lines and be sure it _IS_ loaded.

> <IfModule mod_perl.c> ... </IfModule> works.. So I know mod_perl is 
> installed.
Not neccessarily, it may never actually go in the if because mod_perl is not 
really installed.

> What version of mod_perl? Not sure. CPAN wants me to upgrade to 1.29 
> (though I cant currently without destroying Plesk)
perl -Mmod_perl -e 'print $mod_perl::VERSION'

if that doesn't work

find /path/to/perl5/lib -type -f -name "mod_perl.pm"
find /path/to/perl5/lib -type -f -name "Constants.pm"


> <IfModule mod_perl.c>
> <LocationMatch "^/+?">
>       PerlTransHandler Apache::BadRefs;
> </LocationMatch>
> </IfModule>
In and of its self, this section is fine.
> # declare these here since I dont have an Apache::Constants
> use constant OK => "200";
> use constant DECLINED => "404";
Pardon the phrasing, but why the hell not? Its part of mp1 core ?


> 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;
>        }
> }
syntacitally, thats correct, though I would have sooner shot myself before the 
constant hack.

> 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)
cd /usr/local/apache/bin
gdb
run -X httpd -d ..

example of the above with comments here:
http://httpd.apache.org/dev/debugging.html#gdb



-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com

Re: [Question / Newbie]

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Perrin Harkins wrote:
> On Wed, 2005-11-02 at 17:19 -0600, Michael Preslar wrote:
> 
>>Server version: Apache/2.0.40
> 
> [...]
> 
>>What version of mod_perl? Not sure. CPAN wants me to upgrade to 1.29
> 
> 
> Nothing in the 1.x mp series will run on the 2.x apache series.  You can
> find out what version you have by printing $ENV{MOD_PERL} or looking at
> the startup message in your error_log. 

Good call, read right over that.


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com

Re: [Question / Newbie]

Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2005-11-02 at 17:19 -0600, Michael Preslar wrote:
> Server version: Apache/2.0.40
[...]
> What version of mod_perl? Not sure. CPAN wants me to upgrade to 1.29

Nothing in the 1.x mp series will run on the 2.x apache series.  You can
find out what version you have by printing $ENV{MOD_PERL} or looking at
the startup message in your error_log. 

> # declare these here since I dont have an Apache::Constants

Those are in Apache2::Const now.  See the 2.0 migration documentation.

> 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;
>         }

Those are not supposed to be HTTP codes.  They are apache internal
codes.  The values 200 and 404 are not correct.

> Now.. All seems right.. To me at least.. But whenever I restart apache, 
> it errors out

I think the above should explain what the problem is, but in the future,
please explain what happens more specifically than "it errors out."
That could mean practically anything.

- Perrin