| 1 | package Apache::LogIgnore; | ||
| 2 | |||
| 3 | $Apache::LogIgnore::VERSION = 0.03; | ||
| 4 | |||
| 5 | use 5.006; | ||
| 6 | use strict; | ||
| 7 | use Apache::Constants qw(:common); | ||
| 8 | |||
| 9 | sub handler { | ||
| 10 | my $r = shift; | ||
| 11 | my $debugflag = $r->dir_config("DebugFlag"); | ||
| 12 | my ($marker, $host, $referer, $agent, $from, $status, $type, $minsize, $maxsize); | ||
| 13 | #Remote Host | ||
| 14 | my $ignorehost = $r->dir_config("IgnoreHost"); | ||
| 15 | ($marker,$host) = $ignorehost =~ /^(\!)?(.*)$/; | ||
| 16 | return DONE if $r->get_remote_host eq $host && !$marker; | ||
| 17 | return DONE if $r->get_remote_host ne $host && $marker; | ||
| 18 | warn "Checked Remote Host" if $debugflag; | ||
| 19 | |||
| 20 | #User Agent | ||
| 21 | my $ignoreagent = $r->dir_config("IgnoreAgent"); | ||
| 22 | ($marker,$agent) = $ignoreagent =~ /^(\!)?(.*)$/; | ||
| 23 | return DONE if $r->header_in("User-Agent") =~ /$agent/i && $r->header_in("User-Agent") && $r->dir_config("IgnoreAgent") && !$marker; | ||
| 24 | return DONE if $r->header_in("User-Agent") !~ /$agent/i && $r->header_in("User-Agent") && $r->dir_config("IgnoreAgent") && $marker; | ||
| 25 | warn "Checked User Agent" if $debugflag; | ||
| 26 | |||
| 27 | #Referer | ||
| 28 | my $ignorereferer = $r->dir_config("IgnoreReferer"); | ||
| 29 | ($marker,$referer) = $ignorereferer =~ /^(\!)?(.*)$/; | ||
| 30 | return DONE if $r->header_in("Referer") =~ /$referer/i && $r->header_in("Referer") && $r->dir_config("IgnoreReferer") && !$marker; | ||
| 31 | return DONE if $r->header_in("Referer") !~ /$referer/i && $r->header_in("Referer") && $r->dir_config("IgnoreReferer") && $marker; | ||
| 32 | warn "Checked Referer" if $debugflag; | ||
| 33 | |||
| 34 | #From | ||
| 35 | my $ignorefrom = $r->dir_config("IgnoreFrom"); | ||
| 36 | ($marker,$from) = $ignorefrom =~ /^(\!)?(.*)$/; | ||
| 37 | return DONE if $r->header_in("From") =~ /$from/i && $r->header_in("From") && $r->dir_config("IgnoreFrom") && !$marker; | ||
| 38 | return DONE if $r->header_in("From") !~ /$from/i && $r->header_in("From") && $r->dir_config("IgnoreFrom") && $marker; | ||
| 39 | warn "Checked From" if $debugflag; | ||
| 40 | |||
| 41 | #Minimum Size | ||
| 42 | my $filesize = -s $r->filename; | ||
| 43 | my $ignoreminsize = $r->dir_config("IgnoreMinSize"); | ||
| 44 | ($marker,$minsize) = $ignoreminsize =~ /^(\!)?(.*)$/; | ||
| 45 | return DONE if $filesize <= $minsize && $filesize && $r->dir_config("IgnoreMinSize") && !$marker; | ||
| 46 | return DONE if $filesize > $minsize && $filesize && $r->dir_config("IgnoreMinSize") && $marker; | ||
| 47 | warn "Checked Minimum Size" if $debugflag; | ||
| 48 | |||
| 49 | #Maximum Size | ||
| 50 | my $ignoremaxsize = $r->dir_config("IgnoreMaxSize"); | ||
| 51 | ($marker,$maxsize) = $ignoremaxsize =~ /^(\!)?(.*)$/; | ||
| 52 | return DONE if $filesize >= $maxsize && $filesize && $r->dir_config("IgnoreMaxSize") && !$marker; | ||
| 53 | return DONE if $filesize < $maxsize && $filesize && $r->dir_config("IgnoreMaxSize") && $marker; | ||
| 54 | warn "Checked Maximum Size" if $debugflag; | ||
| 55 | |||
| 56 | #Type | ||
| 57 | my $ignoretype = $r->dir_config("IgnoreType"); | ||
| 58 | ($marker,$type) = $ignoretype =~ /^(\!)?(.*)$/; | ||
| 59 | return DONE if $r->content_type =~ /$type/i && $r->content_type && $r->dir_config("IgnoreType") && !$marker; | ||
| 60 | return DONE if $r->content_type !~ /$type/i && $r->content_type && $r->dir_config("IgnoreType") && $marker; | ||
| 61 | warn "Checked Content Type" if $debugflag; | ||
| 62 | |||
| 63 | #Status | ||
| 64 | my $ignorestatus = $r->dir_config("IgnoreStatus"); | ||
| 65 | ($marker,$status) = $ignorestatus =~ /^(\!)?(.*)$/; | ||
| 66 | return DONE if $r->status eq $status && $r->status && $r->dir_config("IgnoreStatus") && !$marker; | ||
| 67 | return DONE if $r->status ne $status && $r->status && $r->dir_config("IgnoreStatus") && $marker; | ||
| 68 | warn "Checked Status" if $debugflag; | ||
| 69 | return OK; | ||
| 70 | } | ||
| 71 | |||
| 72 | 1; | ||
| 73 | __END__ |