line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Control::C::Access; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1193
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
33
|
|
|
99
|
use constant MP2 => ( |
6
|
|
|
|
|
|
|
exists $ENV{MOD_PERL_API_VERSION} and |
7
|
|
|
|
|
|
|
$ENV{MOD_PERL_API_VERSION} >= 2 |
8
|
1
|
|
|
1
|
|
5
|
); |
|
1
|
|
|
|
|
2
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# must explicitly import for mod_perl2 |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
1139
|
if (MP2) { |
13
|
|
|
|
|
|
|
require Gantry::Engine::MP20; |
14
|
|
|
|
|
|
|
Gantry::Engine::MP20->import(); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
############################################################ |
19
|
|
|
|
|
|
|
# Functions # |
20
|
|
|
|
|
|
|
############################################################ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
###################################################################### |
23
|
|
|
|
|
|
|
# Main Execution Begins Here # |
24
|
|
|
|
|
|
|
###################################################################### |
25
|
|
|
|
|
|
|
sub handler : method { |
26
|
0
|
|
|
0
|
1
|
0
|
my( $self, $r ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $remote_ip = $self->remote_ip( $r ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Range, or specfic ips. |
31
|
0
|
|
|
|
|
0
|
my $ranges = $r->dir_config( 'AuthAllowRanges' ); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
0
|
if ( defined $r->dir_config( 'auth_allow_ranges' ) ) { |
34
|
0
|
|
|
|
|
0
|
$ranges = $r->dir_config( 'auth_allow_ranges' ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my $ips = $r->dir_config( 'AuthAllowIps' ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
0
|
if ( defined $r->dir_config( 'auth_allow_ips' ) ) { |
40
|
0
|
|
|
|
|
0
|
$ips = $r->dir_config( 'auth_allow_ips' ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
my $ignore = $r->dir_config( 'AccessNoOverRide' ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
0
|
if ( defined $r->dir_config( 'ignore_access_handler' ) ) { |
46
|
0
|
0
|
|
|
|
0
|
if ( $r->dir_config( 'ignore_access_handler' ) =~/^y/i ) { |
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
$ignore = 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( $r->dir_config( 'ignore_access_handler' ) =~ /^n/i ) { |
50
|
0
|
|
|
|
|
0
|
$ignore = 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
0
|
$ignore = 0 if ( ! defined $ignore ); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
0
|
if ( defined $ranges ) { |
57
|
|
|
|
|
|
|
# make the decimal version of the ip. |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my @remote = split( '\.', $remote_ip ); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $dip = ip2bin( $remote[0] ); |
62
|
0
|
|
|
|
|
0
|
$dip .= ip2bin( $remote[1] ); |
63
|
0
|
|
|
|
|
0
|
$dip .= ip2bin( $remote[2] ); |
64
|
0
|
|
|
|
|
0
|
$dip .= ip2bin( $remote[3] ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# This is broken in 5.05 |
67
|
|
|
|
|
|
|
#my $dip1 = sprintf( "%08b %08b %08b %08b", split( '\.', $remote_ip )); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
for my $range ( split( ',', $ranges ) ) { |
70
|
0
|
|
|
|
|
0
|
my ( $ranged, $slash ) = $range =~ /^(.*)\/(\d+)$/; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
my @ranger = split( '\.', $ranged ); |
73
|
0
|
|
|
|
|
0
|
my $drng = ip2bin( $ranger[0] ); |
74
|
0
|
|
|
|
|
0
|
$drng .= ip2bin( $ranger[1] ); |
75
|
0
|
|
|
|
|
0
|
$drng .= ip2bin( $ranger[2] ); |
76
|
0
|
|
|
|
|
0
|
$drng .= ip2bin( $ranger[3] ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# This is broken in 5.05 |
79
|
|
|
|
|
|
|
#my $drng = sprintf( "%08b%08b%08b%08b", split( '\.', $ranged ) ); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
0
|
if ( substr( $dip, 0, $slash) eq substr( $drng, 0, $slash ) ) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
if ( ! $r->user ) { |
84
|
0
|
|
|
|
|
0
|
$r->user( 'anoymous_ip_user' ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
0
|
if ( ! $ignore ) { |
88
|
|
|
|
|
|
|
$r->set_handlers( PerlAuthenHandler => [ |
89
|
0
|
|
|
0
|
|
0
|
sub{ $self->status_const( 'OK' ) } |
90
|
0
|
|
|
|
|
0
|
] ); |
91
|
|
|
|
|
|
|
$r->set_handlers( PerlAuthzHandler => [ |
92
|
0
|
|
|
0
|
|
0
|
sub{ $self->status_const( 'OK' ) } ] ); |
|
0
|
|
|
|
|
0
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
if ( defined $ips ) { |
101
|
0
|
|
|
|
|
0
|
for my $ip ( split( ',', $ips ) ) { |
102
|
0
|
0
|
|
|
|
0
|
if ( $ip =~ /^\s?$remote_ip\s?$/ ) { |
103
|
0
|
0
|
|
|
|
0
|
if ( ! $r->user ) { |
104
|
0
|
|
|
|
|
0
|
$r->user( 'anoymous_ip_user' ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
0
|
if ( ! $ignore ) { |
108
|
|
|
|
|
|
|
$r->set_handlers( PerlAuthenHandler => [ |
109
|
0
|
|
|
0
|
|
0
|
sub{ $self->status_const( 'OK' ) } |
110
|
0
|
|
|
|
|
0
|
] ); |
111
|
|
|
|
|
|
|
$r->set_handlers( PerlAuthzHandler => [ |
112
|
0
|
|
|
0
|
|
0
|
sub{ $self->status_const( 'OK' ) } ] ); |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'DECLINED' ) ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} # END handler |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#------------------------------------------------- |
125
|
|
|
|
|
|
|
# ip2bin( $ip ) |
126
|
|
|
|
|
|
|
#------------------------------------------------- |
127
|
|
|
|
|
|
|
# dec 2 bin for the ip address. |
128
|
|
|
|
|
|
|
#------------------------------------------------- |
129
|
|
|
|
|
|
|
sub ip2bin { |
130
|
0
|
|
|
0
|
1
|
0
|
my $dec = shift; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
my $bin = unpack( "B32", pack( "N", $dec ) ); |
133
|
0
|
|
|
|
|
0
|
$bin =~ s/^0+(?=\d)//; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
0
|
if ( length( $bin ) < 8 ) { |
136
|
0
|
|
|
|
|
0
|
return( '0' x ( 8 - length( $bin ) ) . $bin ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
0
|
|
|
|
|
0
|
return( $bin ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} # END ip2bin |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#------------------------------------------------- |
144
|
|
|
|
|
|
|
# $self->import( @options ) |
145
|
|
|
|
|
|
|
#------------------------------------------------- |
146
|
|
|
|
|
|
|
sub import { |
147
|
1
|
|
|
1
|
|
10
|
my ( $self, @options ) = @_; |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
3
|
my( $engine, $tplugin ); |
150
|
|
|
|
|
|
|
|
151
|
1
|
|
|
|
|
10
|
foreach (@options) { |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Import the proper engine |
154
|
0
|
0
|
|
|
|
|
if (/^-Engine=(.*)$/) { |
155
|
0
|
|
|
|
|
|
$engine = "Gantry::Engine::$1"; |
156
|
0
|
|
|
|
|
|
eval "use $engine"; |
157
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
158
|
0
|
|
|
|
|
|
die "unable to load engine $1 ($@)"; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} # end: import |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# EOF |
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__END__ |