| 1 |
root |
1.8 |
package conn; |
| 2 |
root |
1.1 |
|
| 3 |
root |
1.8 |
our %blockuri; |
| 4 |
|
|
our $blockref; |
| 5 |
root |
1.1 |
|
| 6 |
root |
1.6 |
sub read_blockuri { |
| 7 |
root |
1.1 |
local *B; |
| 8 |
|
|
my %group; |
| 9 |
root |
1.8 |
%blockuri = (); |
| 10 |
root |
1.6 |
if (open B, "<blockuri") { |
| 11 |
root |
1.1 |
while (<B>) { |
| 12 |
|
|
chomp; |
| 13 |
|
|
if (/^group\s+(\S+)\s+(.*)/i) { |
| 14 |
|
|
$group{$1} = [split /\s+/, $2]; |
| 15 |
|
|
} elsif (/^!([^\t]*)\t\s*(.*)/) { |
| 16 |
|
|
my $g = $1; |
| 17 |
|
|
my @r; |
| 18 |
|
|
for (split /\s+/, $2) { |
| 19 |
|
|
push @r, $group{$_} ? @{$group{$_}} : $_; |
| 20 |
|
|
} |
| 21 |
|
|
print "not($g) => (@r)\n"; |
| 22 |
root |
1.8 |
push @{$blockuri{$_}}, $g for @r; |
| 23 |
root |
1.6 |
push @blockuri, [qr/$g/i, \@r]; |
| 24 |
root |
1.1 |
} elsif (/\S/) { |
| 25 |
root |
1.6 |
print "blockuri: unparsable line: $_\n"; |
| 26 |
root |
1.1 |
} |
| 27 |
|
|
} |
| 28 |
root |
1.8 |
for (keys %blockuri) { |
| 29 |
|
|
my $qr = join ")|(?:", @{$blockuri{$_}}; |
| 30 |
|
|
$blockuri{$_} = qr{(?:$qr)}i; |
| 31 |
|
|
} |
| 32 |
root |
1.1 |
} else { |
| 33 |
root |
1.6 |
print "no blockuri\n"; |
| 34 |
root |
1.1 |
} |
| 35 |
|
|
} |
| 36 |
|
|
|
| 37 |
root |
1.6 |
sub read_blockref { |
| 38 |
|
|
local *B; |
| 39 |
root |
1.8 |
my @blockref; |
| 40 |
root |
1.6 |
if (open B, "<blockreferer") { |
| 41 |
|
|
while (<B>) { |
| 42 |
|
|
chomp; |
| 43 |
|
|
if (/^([^\t]*)\t\s*(.*)/) { |
| 44 |
root |
1.8 |
push @blockref, $1; |
| 45 |
root |
1.6 |
} elsif (/\S/) { |
| 46 |
|
|
print "blockref: unparsable line: $_\n"; |
| 47 |
|
|
} |
| 48 |
|
|
} |
| 49 |
root |
1.8 |
$blockref = join ")|(?:", @blockref; |
| 50 |
|
|
$blockref = qr{^(?:$blockref)}i; |
| 51 |
root |
1.6 |
} else { |
| 52 |
|
|
print "no blockref\n"; |
| 53 |
root |
1.8 |
$blockref = qr{^x^}; |
| 54 |
root |
1.6 |
} |
| 55 |
|
|
} |
| 56 |
|
|
|
| 57 |
|
|
read_blockuri; |
| 58 |
|
|
read_blockref; |
| 59 |
root |
1.1 |
|
| 60 |
root |
1.5 |
use Tie::Cache; |
| 61 |
root |
1.8 |
tie %whois_cache, Tie::Cache::, $::MAX_CONNECTS * 1.5; |
| 62 |
root |
1.1 |
|
| 63 |
root |
1.8 |
sub access_check { |
| 64 |
root |
1.6 |
my $self = shift; |
| 65 |
|
|
|
| 66 |
|
|
my $ref = $self->{h}{referer}; |
| 67 |
|
|
my $uri = $self->{path}; |
| 68 |
|
|
my %disallow; |
| 69 |
|
|
|
| 70 |
root |
1.8 |
$self->err_block_referer |
| 71 |
|
|
if $self->{h}{referer} =~ $blockref; |
| 72 |
root |
1.6 |
|
| 73 |
|
|
my $whois = $whois_cache{$self->{remote_addr}} |
| 74 |
|
|
||= ::ip_request($self->{remote_addr}); |
| 75 |
|
|
|
| 76 |
|
|
my $country = "XX"; |
| 77 |
|
|
|
| 78 |
|
|
if ($whois =~ /^\*cy: (\S+)/m) { |
| 79 |
|
|
$country = uc $1; |
| 80 |
|
|
} else { |
| 81 |
|
|
$self->slog(9, "no country($whois)"); |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
|
$self->{country} = $country; |
| 85 |
|
|
|
| 86 |
root |
1.8 |
$self->err_block_country($whois) |
| 87 |
|
|
if $self->{path} =~ $blockuri{$country}; |
| 88 |
root |
1.1 |
} |
| 89 |
|
|
|
| 90 |
|
|
1; |