line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Ident; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
378114
|
use strict; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
287
|
|
4
|
8
|
|
|
8
|
|
50
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
235
|
|
5
|
8
|
|
|
8
|
|
133
|
use v5.10; |
|
8
|
|
|
|
|
43
|
|
|
8
|
|
|
|
|
418
|
|
6
|
8
|
|
|
8
|
|
752
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
8
|
|
|
|
|
10782
|
|
|
8
|
|
|
|
|
84
|
|
7
|
8
|
|
|
8
|
|
4391
|
use AnyEvent; |
|
8
|
|
|
|
|
5690
|
|
|
8
|
|
|
|
|
247
|
|
8
|
8
|
|
|
8
|
|
8194
|
use AnyEvent::Ident::Client; |
|
8
|
|
|
|
|
48550
|
|
|
8
|
|
|
|
|
272
|
|
9
|
8
|
|
|
8
|
|
834
|
use Mojo::Exception; |
|
8
|
|
|
|
|
2336
|
|
|
8
|
|
|
|
|
100
|
|
10
|
8
|
|
|
8
|
|
6416
|
use Mojolicious::Plugin::Ident::Response; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
8005
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Mojolicious plugin to interact with a remote ident service |
13
|
|
|
|
|
|
|
our $VERSION = '0.30'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register |
17
|
|
|
|
|
|
|
{ |
18
|
7
|
|
|
7
|
1
|
492
|
my($self, $app, $conf) = @_; |
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
|
|
37
|
Mojolicious::Plugin::Ident::Response->_setup; |
21
|
|
|
|
|
|
|
|
22
|
7
|
|
100
|
|
|
71
|
my $default_timeout = $conf->{timeout} // 2; |
23
|
7
|
|
50
|
|
|
31
|
my $port = $conf->{port} // 113; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->helper(ident => sub { |
26
|
13
|
|
|
13
|
|
92665
|
my $callback; |
27
|
13
|
100
|
|
|
|
275
|
$callback = pop if ref($_[-1]) eq 'CODE'; |
28
|
13
|
|
|
|
|
34
|
my($controller, $tx, $timeout) = @_; |
29
|
13
|
|
66
|
|
|
251
|
$tx //= $controller->tx; |
30
|
13
|
|
66
|
|
|
110
|
$timeout //= $default_timeout; |
31
|
|
|
|
|
|
|
|
32
|
13
|
100
|
|
|
|
43
|
if($callback) |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
AnyEvent::Ident::Client |
35
|
|
|
|
|
|
|
->new( response_class => 'Mojolicious::Plugin::Ident::Response', hostname => $tx->remote_address, port => $port ) |
36
|
|
|
|
|
|
|
->ident($tx->remote_port, $tx->local_port, sub { |
37
|
7
|
|
|
|
|
17209
|
my $ident_response = shift; |
38
|
7
|
|
|
|
|
54
|
$ident_response->{remote_address} = $tx->remote_address; |
39
|
7
|
|
|
|
|
670
|
$callback->($ident_response) |
40
|
|
|
|
|
|
|
} |
41
|
7
|
|
|
|
|
46
|
); |
42
|
7
|
|
|
|
|
5366
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
249
|
my $done = AnyEvent->condvar; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $w = AnyEvent->timer(after => $timeout // $default_timeout, cb => sub { |
48
|
1
|
|
|
|
|
992881
|
$done->croak("ident timeout"); |
49
|
6
|
|
33
|
|
|
136
|
}); |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
101
|
my $ident_response; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
AnyEvent::Ident::Client |
54
|
|
|
|
|
|
|
->new( response_class => 'Mojolicious::Plugin::Ident::Response', hostname => $tx->remote_address, port => $port ) |
55
|
|
|
|
|
|
|
->ident($tx->remote_port, $tx->local_port, sub { |
56
|
5
|
|
|
|
|
5633
|
$ident_response = shift; |
57
|
5
|
|
|
|
|
28
|
$ident_response->{remote_address} = $tx->remote_address; |
58
|
5
|
|
|
|
|
472
|
$done->send(1); |
59
|
|
|
|
|
|
|
} |
60
|
6
|
|
|
|
|
45
|
); |
61
|
|
|
|
|
|
|
|
62
|
6
|
|
|
|
|
4886
|
$done->recv; |
63
|
5
|
|
|
|
|
216
|
undef $w; |
64
|
|
|
|
|
|
|
|
65
|
5
|
100
|
|
|
|
66
|
if($ident_response->is_success) |
66
|
|
|
|
|
|
|
{ |
67
|
3
|
|
|
|
|
72
|
return $ident_response; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
else |
70
|
|
|
|
|
|
|
{ |
71
|
2
|
|
|
|
|
26
|
my $error = 'ident error: ' . $ident_response->error_type; |
72
|
2
|
|
|
|
|
59
|
$controller->app->log->error($error); |
73
|
2
|
|
|
|
|
130
|
die Mojo::Exception->new($error); |
74
|
|
|
|
|
|
|
} |
75
|
7
|
|
|
|
|
120
|
}); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$app->helper(ident_same_user => sub { |
78
|
15
|
|
|
15
|
|
720918
|
my $callback; |
79
|
15
|
100
|
|
|
|
103
|
$callback = pop if ref($_[-1]) eq 'CODE'; |
80
|
15
|
|
|
|
|
31
|
my $controller = shift; |
81
|
|
|
|
|
|
|
|
82
|
15
|
100
|
|
|
|
63
|
if($callback) |
83
|
|
|
|
|
|
|
{ |
84
|
10
|
|
|
|
|
25
|
my($tx, $timeout) = @_; |
85
|
10
|
|
33
|
|
|
242
|
$tx //= $controller->tx; |
86
|
10
|
|
33
|
|
|
112
|
$timeout //= $default_timeout; |
87
|
|
|
|
|
|
|
|
88
|
10
|
100
|
|
|
|
56
|
if(defined $controller->session('ident_same_user')) |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
Mojo::IOLoop->timer(0 => sub { |
91
|
4
|
|
|
|
|
8508
|
$callback->($controller->session('ident_same_user')); |
92
|
4
|
|
|
|
|
117
|
}); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
$controller->ident($tx, $timeout, sub { |
97
|
6
|
|
|
|
|
15
|
my $res = shift; |
98
|
6
|
100
|
|
|
|
39
|
if($res->is_success) |
99
|
|
|
|
|
|
|
{ |
100
|
4
|
|
|
|
|
95
|
my $same_user = $res->same_user; |
101
|
4
|
|
|
|
|
30
|
$controller->session('ident_same_user' => $same_user); |
102
|
4
|
|
|
|
|
107
|
$callback->($same_user); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else |
105
|
|
|
|
|
|
|
{ |
106
|
2
|
|
|
|
|
15
|
$callback->(0); |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
279
|
}); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else |
112
|
|
|
|
|
|
|
{ |
113
|
5
|
|
66
|
|
|
29
|
$controller->session('ident_same_user') // do { |
114
|
3
|
|
|
|
|
141
|
my $same_user = eval { $controller->ident(@_)->same_user }; |
|
3
|
|
|
|
|
35
|
|
115
|
3
|
100
|
|
|
|
230
|
return if $@; |
116
|
2
|
|
|
|
|
9
|
$controller->session('ident_same_user' => $same_user); |
117
|
2
|
|
|
|
|
50
|
$same_user; |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
} |
120
|
7
|
|
|
|
|
1023
|
}); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |