line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Controller::Image; |
2
|
|
|
|
|
|
|
|
3
|
35
|
|
|
35
|
|
16930
|
use strict; |
|
35
|
|
|
|
|
88
|
|
|
35
|
|
|
|
|
1076
|
|
4
|
35
|
|
|
35
|
|
248
|
use parent 'Catalyst::Controller'; |
|
35
|
|
|
|
|
243
|
|
|
35
|
|
|
|
|
4134
|
|
5
|
35
|
|
|
35
|
|
2316
|
use IO::File; |
|
35
|
|
|
|
|
499
|
|
|
35
|
|
|
|
|
5064
|
|
6
|
35
|
|
|
35
|
|
239
|
use URI::Escape (); |
|
35
|
|
|
|
|
76
|
|
|
35
|
|
|
|
|
2821
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
MojoMojo::Controller::Image - Image controller |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This controller is used to see images in particular url |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Formatter::Dir must be configured in mojomojo.conf. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
If url begin with 'prefix_url', so images can be displayed. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Images are stored in 'whitelisting' directory. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
View usage with 'script/util/dir2mojomojo.pl' |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 file_not_found |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Private action to return a 404 not found page. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub file_not_found : Private { |
35
|
0
|
|
|
0
|
|
0
|
my ( $self, $c ) = @_; |
36
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'message.tt'; |
37
|
0
|
|
|
|
|
0
|
$c->stash->{message} = $c->loc("file not found."); |
38
|
0
|
|
|
|
|
0
|
return ( $c->res->status(404) ); |
39
|
35
|
|
|
35
|
|
230
|
} |
|
35
|
|
|
|
|
214
|
|
|
35
|
|
|
|
|
4320
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 png |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub png : Global { |
46
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $path ) = @_; |
47
|
0
|
|
|
|
|
0
|
$c->forward('view'); |
48
|
|
|
|
|
|
|
|
49
|
35
|
|
|
35
|
|
1307005
|
} |
|
35
|
|
|
|
|
99
|
|
|
35
|
|
|
|
|
186
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 jpg |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub jpg : Global { |
56
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
$c->forward('view'); |
59
|
35
|
|
|
35
|
|
32857
|
} |
|
35
|
|
|
|
|
81
|
|
|
35
|
|
|
|
|
169
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 gif |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub gif : Global { |
66
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $path ) = @_; |
67
|
0
|
|
|
|
|
0
|
$c->forward('view'); |
68
|
|
|
|
|
|
|
|
69
|
35
|
|
|
35
|
|
31588
|
} |
|
35
|
|
|
|
|
146
|
|
|
35
|
|
|
|
|
185
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 tiff |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub tiff : Global { |
76
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $path ) = @_; |
77
|
0
|
|
|
|
|
0
|
$c->forward('view'); |
78
|
|
|
|
|
|
|
|
79
|
35
|
|
|
35
|
|
30655
|
} |
|
35
|
|
|
|
|
92
|
|
|
35
|
|
|
|
|
710
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 view |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
png/jpg/gif are forwarded here. This action is used to see images |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub view : Private { |
88
|
0
|
|
|
0
|
1
|
|
my ( $self, $c, $path ) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
$c->detach('unauthorized', ['view']) if not $c->check_view_permission; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
0
|
|
|
|
if ( ! defined $c->config->{'Formatter::Dir'}{prefix_url} || |
94
|
|
|
|
|
|
|
! defined $c->config->{'Formatter::Dir'}{whitelisting} ){ |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$c->stash->{message} = "Formatter::Dir is not configured"; |
97
|
0
|
|
|
|
|
|
$c->stash->{template} = 'message.tt'; |
98
|
0
|
|
|
|
|
|
return ( $c->res->status(404) ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Show image only if url start by prefix_url configured |
102
|
|
|
|
|
|
|
# in mojomojo.conf with Formatter::Dir |
103
|
0
|
|
|
|
|
|
my $prefix_url = $c->config->{'Formatter::Dir'}{prefix_url}; |
104
|
0
|
|
|
|
|
|
$prefix_url =~ s|\/$||; |
105
|
0
|
|
|
|
|
|
$prefix_url .= '/'; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $file = $c->stash->{path}; |
109
|
0
|
|
|
|
|
|
my $suffix = $c->req->uri->path; |
110
|
0
|
|
|
|
|
|
$suffix =~ s|^\/||; |
111
|
0
|
0
|
|
|
|
|
if ( $file !~ s/^$prefix_url// ){ |
112
|
0
|
|
|
|
|
|
$c->stash->{message} = $c->loc( |
113
|
|
|
|
|
|
|
'The requested URL was not found: x', |
114
|
|
|
|
|
|
|
"$file.$suffix"); |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$c->stash->{template} = 'message.tt'; |
117
|
0
|
|
|
|
|
|
return ( $c->res->status(404) ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $filename = "$file.$suffix"; |
122
|
0
|
|
|
|
|
|
my $dir = $c->config->{'Formatter::Dir'}{whitelisting}; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
my $io_file = IO::File->new("$dir/$filename") |
125
|
|
|
|
|
|
|
or $c->detach('file_not_found'); |
126
|
0
|
|
|
|
|
|
$io_file->binmode; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$c->res->output( $io_file ); |
129
|
0
|
|
|
|
|
|
$c->res->header( 'content-type', $c->action ); |
130
|
0
|
|
|
|
|
|
$c->res->header( |
131
|
|
|
|
|
|
|
"Content-Disposition" => "inline; filename=" . URI::Escape::uri_escape_utf8( $filename ) ); |
132
|
0
|
|
|
|
|
|
$c->res->header( 'Cache-Control', 'max-age=86400, must-revalidate' ); |
133
|
35
|
|
|
35
|
|
40850
|
} |
|
35
|
|
|
|
|
86
|
|
|
35
|
|
|
|
|
303
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Daniel Brosseau <dab@catapulse.org> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
143
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |