line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::RemoteAddr; |
2
|
1
|
|
|
1
|
|
492
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub register { |
7
|
1
|
|
|
1
|
1
|
33
|
my ($self, $app, $conf) = @_; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
50
|
|
|
11
|
$conf->{order} ||= ['x-real-ip', 'x-forwarded-for', 'tx']; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$app->helper( remote_addr => sub { |
12
|
2
|
|
|
2
|
|
12880
|
my $c = shift; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
1
|
foreach my $place ( @{ $conf->{order} } ) { |
|
2
|
|
|
|
|
9
|
|
15
|
4
|
100
|
|
|
|
14
|
if ( $place eq 'x-real-ip' ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
16
|
2
|
|
|
|
|
3
|
my $ip = $c->req->headers->header('X-Real-IP'); |
17
|
2
|
100
|
|
|
|
37
|
return $ip if $ip; |
18
|
|
|
|
|
|
|
} elsif ( $place eq 'x-forwarded-for' ) { |
19
|
1
|
|
|
|
|
3
|
my $ip = $c->req->headers->header('X-Forwarded-For'); |
20
|
1
|
50
|
|
|
|
21
|
return $ip if $ip; |
21
|
|
|
|
|
|
|
} elsif ( $place eq 'tx' ) { |
22
|
1
|
|
|
|
|
4
|
my $ip = $c->tx->remote_address; |
23
|
1
|
50
|
|
|
|
24
|
return $ip if $ip; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return; |
28
|
1
|
|
|
|
|
7
|
}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
__END__ |