line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Whim::Controller::Listen; |
2
|
2
|
|
|
2
|
|
1402
|
use Mojo::Base 'Mojolicious::Controller'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
22
|
|
3
|
2
|
|
|
2
|
|
420
|
use Whim::Mention; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
4
|
2
|
|
|
2
|
|
14
|
use Try::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Readonly; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
1169
|
|
7
|
|
|
|
|
|
|
Readonly my $OK => 200; |
8
|
|
|
|
|
|
|
Readonly my $ACCEPTED => 202; |
9
|
|
|
|
|
|
|
Readonly my $BAD_REQUEST => 400; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub default { |
12
|
1
|
|
|
1
|
0
|
19824
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
25
|
$self->render( |
15
|
|
|
|
|
|
|
status => $OK, |
16
|
|
|
|
|
|
|
text => 'OK (listening for webmentions)' |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub receive { |
21
|
7
|
|
|
7
|
0
|
96968
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
12
|
my $webmention; |
24
|
|
|
|
|
|
|
try { |
25
|
7
|
|
|
7
|
|
348
|
$webmention = Whim::Mention->new_from_request($self); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
catch { |
28
|
0
|
|
|
0
|
|
0
|
$self->render( |
29
|
|
|
|
|
|
|
status => $BAD_REQUEST, |
30
|
|
|
|
|
|
|
text => "Malformed webmention: $_" |
31
|
|
|
|
|
|
|
); |
32
|
0
|
|
|
|
|
0
|
$self->log->info('Rejected a malformed webmention.'); |
33
|
7
|
|
|
|
|
62
|
}; |
34
|
7
|
50
|
|
|
|
19856
|
return unless $webmention; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Pull out the source and target params, mostly for logging |
37
|
7
|
|
|
|
|
28
|
my $source = $self->param('source'); |
38
|
7
|
|
|
|
|
558
|
my $target = $self->param('target'); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# XXX For the present, naively accept all webmentions. |
41
|
|
|
|
|
|
|
# This is technically legal under section 3.2.1 of the spec. |
42
|
|
|
|
|
|
|
# But it SHOULD check against some stored config about whether |
43
|
|
|
|
|
|
|
# it cares about the target URL at all. |
44
|
7
|
|
|
|
|
388
|
unless (1) { |
45
|
|
|
|
|
|
|
my $error_text = "Unrecognized target URL: $target"; |
46
|
|
|
|
|
|
|
$self->render( |
47
|
|
|
|
|
|
|
status => $BAD_REQUEST, |
48
|
|
|
|
|
|
|
text => $error_text |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
$self->log->info($error_text); |
51
|
|
|
|
|
|
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
7
|
|
|
|
|
12
|
my $success_text = |
55
|
|
|
|
|
|
|
"Webmention accepted, and queued for verification and " |
56
|
|
|
|
|
|
|
. "processing. Thank you!"; |
57
|
|
|
|
|
|
|
|
58
|
7
|
|
|
|
|
11
|
my $return_link_text = 'Return to previous page.'; |
59
|
7
|
|
|
|
|
28
|
$success_text .= qq{ <a href="$target">$return_link_text</a>}; |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
56
|
$self->render( status => $ACCEPTED, text => $success_text ); |
62
|
|
|
|
|
|
|
|
63
|
7
|
|
|
|
|
2768
|
$self->log->info("Accepted: $source -> $target"); |
64
|
|
|
|
|
|
|
|
65
|
7
|
|
|
|
|
215
|
$self->whim->receive_webmention($webmention); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |