line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Charon::Web; |
2
|
|
|
|
|
|
|
$App::Charon::Web::VERSION = '0.001002'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Internal (for now) Plack app behind charon |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
16054
|
use utf8; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
500
|
use Web::Simple; |
|
1
|
|
|
|
|
42317
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
3505
|
use warnings NONFATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
453
|
use Plack::App::Directory; |
|
1
|
|
|
|
|
81034
|
|
|
1
|
|
|
|
|
40
|
|
10
|
1
|
|
|
1
|
|
8
|
use Plack::App::File; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
380
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has _quit => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
init_arg => 'quit', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has _root => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
default => '.', |
21
|
|
|
|
|
|
|
init_arg => 'root', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has _query_param_auth => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
default => sub { |
27
|
|
|
|
|
|
|
require App::Genpass; |
28
|
|
|
|
|
|
|
[auth => scalar App::Genpass->new->generate] |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
init_arg => 'query_param_auth', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has _show_index => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
default => 1, |
36
|
|
|
|
|
|
|
init_arg => 'show_index', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub BUILDARGS { |
40
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
$params{query_param_auth} = [split m/=/, $params{query_param_auth}, 2] |
43
|
|
|
|
|
|
|
if exists $params{query_param_auth}; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
\%params |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has _root_server => ( |
49
|
|
|
|
|
|
|
is => 'ro', |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
builder => sub { |
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($self->_show_index) { |
55
|
0
|
|
|
|
|
|
my $ret = Plack::App::Directory->new( root => $self->_root ); |
56
|
0
|
|
|
|
|
|
$ret = Plack::Middleware::FixLinks->new( |
57
|
0
|
|
|
|
|
|
suffix => '?' . join('=', @{$self->_query_param_auth}), |
58
|
0
|
0
|
|
|
|
|
)->wrap($ret) if @{$self->_query_param_auth}; |
59
|
0
|
|
|
|
|
|
return $ret |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
return Plack::App::File->new( root => $self->_root ) |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub dispatch_request { |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my @qpa = @{$self->_query_param_auth}; |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
(@qpa ? ( "?$qpa[0]~" => sub { |
71
|
0
|
|
|
0
|
|
|
my ($self, $value) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
0
|
|
|
|
return [403, ['Content-Type' => 'text/plain'], ['nice try']] |
74
|
|
|
|
|
|
|
if !$value || $value ne $qpa[1]; |
75
|
0
|
|
|
|
|
|
return; |
76
|
|
|
|
|
|
|
}) : ()), |
77
|
0
|
|
|
0
|
|
|
'/quit' => sub { shift->_quit->done(1); [200, [], ''] }, |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
0
|
|
|
'/_/...' => sub { $self->_root_server }, |
79
|
0
|
0
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
BEGIN { |
84
|
|
|
|
|
|
|
package Plack::Middleware::FixLinks; |
85
|
1
|
|
|
1
|
|
3
|
$Plack::Middleware::FixLinks::VERSION = '0.001002'; |
86
|
1
|
|
|
1
|
|
5
|
use parent qw(Plack::Middleware); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
1
|
|
51
|
use Plack::Util; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
89
|
1
|
|
|
1
|
|
455
|
use HTML::Zoom; |
|
1
|
|
|
|
|
7153
|
|
|
1
|
|
|
|
|
33
|
|
90
|
1
|
|
|
1
|
|
6
|
use Plack::Util::Accessor qw(suffix); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
8
|
|
91
|
1
|
|
|
1
|
|
437
|
use Plack::Response; |
|
1
|
|
|
|
|
971
|
|
|
1
|
|
|
|
|
187
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub call { |
94
|
0
|
|
|
0
|
|
|
my($self, $env) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $res = $self->app->($env); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $response = Plack::Response->new(@$res); |
99
|
0
|
0
|
|
|
|
|
return $res unless $response->content_type eq 'text/html'; |
100
|
|
|
|
|
|
|
return $self->response_cb($res, sub { |
101
|
0
|
|
|
0
|
|
|
my $res = shift; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $hz; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (ref $res->[2] eq 'ARRAY') { |
106
|
0
|
|
|
|
|
|
$hz = HTML::Zoom->from_html($res->[2][0]) |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
|
local $/ = undef; |
109
|
0
|
|
|
|
|
|
my $fh = $res->[2]; |
110
|
0
|
|
|
|
|
|
$hz = HTML::Zoom->from_html(<$fh>) |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$res->[2] = $hz |
114
|
|
|
|
|
|
|
->select('a') |
115
|
0
|
|
|
|
|
|
->transform_attribute(href => sub { $_[0] . $self->suffix }) |
116
|
0
|
|
|
|
|
|
->to_fh; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return; |
119
|
0
|
|
|
|
|
|
}); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
26
|
1 |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |