| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tapper::Reports::Web::Controller::Tapper::ReportFile::Id; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
|
3
|
|
|
|
|
|
|
$Tapper::Reports::Web::Controller::Tapper::ReportFile::Id::VERSION = '5.0.13'; |
|
4
|
10
|
|
|
10
|
|
5393
|
use parent 'Tapper::Reports::Web::Controller::Base'; |
|
|
10
|
|
|
|
|
14
|
|
|
|
10
|
|
|
|
|
61
|
|
|
5
|
10
|
|
|
10
|
|
4802
|
use HTML::FromANSI (); |
|
|
10
|
|
|
|
|
101296
|
|
|
|
10
|
|
|
|
|
224
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
75
|
use common::sense; |
|
|
10
|
|
|
|
|
19
|
|
|
|
10
|
|
|
|
|
93
|
|
|
8
|
|
|
|
|
|
|
## no critic (RequireUseStrict) |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#use HTML::FromANSI (); # avoid exports if using OO |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $ANSI2HTML_PRE = '<link rel="stylesheet" type="text/css" title="Red" href="/tapper/static/css/style_red.css" /><body style="background: black;">'; |
|
13
|
|
|
|
|
|
|
our $ANSI2HTML_POST = '</body>'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub index :Path :CaptureArgs(2) |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
0
|
|
|
0
|
|
|
my ( $self, $c, $file_id, $viewmode ) = @_; |
|
18
|
0
|
|
|
|
|
|
$c->stash->{reportfile} = $c->model('TestrunDB')->resultset('ReportFile')->find($file_id); |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
if (not $c->stash->{reportfile}) |
|
|
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
|
22
|
0
|
|
|
|
|
|
$c->response->content_type ("text/plain"); |
|
23
|
0
|
|
|
|
|
|
$c->response->header ("Content-Disposition" => 'inline; filename="nonexistent.reportfile.'.$file_id.'"'); |
|
24
|
0
|
|
|
|
|
|
$c->response->body ("Error: File with id $file_id does not exist."); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
elsif (not $c->stash->{reportfile}->filecontent) |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
0
|
|
|
|
|
|
$c->response->content_type ("text/plain"); |
|
29
|
0
|
|
|
|
|
|
$c->response->header ("Content-Disposition" => 'inline; filename="empty.reportfile.'.$file_id.'"'); |
|
30
|
0
|
|
|
|
|
|
$c->response->body ("Error: File with id $file_id is empty."); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
0
|
0
|
|
|
|
|
my $contenttype = $c->stash->{reportfile}->contenttype eq 'plain' ? 'text/plain' : $c->stash->{reportfile}->contenttype; |
|
35
|
0
|
0
|
|
|
|
|
my $disposition = $contenttype =~ /plain/ ? 'inline' : 'attachment'; |
|
36
|
0
|
|
0
|
|
|
|
$c->response->content_type ($contenttype || 'application/octet-stream'); |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $filename = $c->stash->{reportfile}->filename; |
|
39
|
0
|
|
|
|
|
|
my @filecontent; |
|
40
|
|
|
|
|
|
|
my $content_disposition; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ( $viewmode eq 'ansi2txt' ) { |
|
|
|
0
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
$filename =~ s,[./],_,g if $disposition eq 'inline'; |
|
44
|
0
|
|
|
|
|
|
$filename .= '.txt'; |
|
45
|
0
|
|
|
|
|
|
@filecontent = ansi_to_txt($c->stash->{reportfile}->filecontent); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} elsif ( $viewmode eq 'ansi2html' ) { |
|
48
|
0
|
0
|
|
|
|
|
$filename =~ s,[./],_,g if $disposition eq 'inline'; |
|
49
|
0
|
|
|
|
|
|
$filename .= '.html'; |
|
50
|
0
|
|
|
|
|
|
my $a2h = HTML::FromANSI->new(style => '', font_face => ''); |
|
51
|
0
|
|
|
|
|
|
@filecontent = $ANSI2HTML_PRE.$a2h->ansi_to_html($c->stash->{reportfile}->filecontent).$ANSI2HTML_POST; |
|
52
|
0
|
|
|
|
|
|
$c->response->content_type('text/html'); |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
0
|
|
|
|
|
|
@filecontent = $c->stash->{reportfile}->filecontent; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
|
|
|
|
|
my $filecontent = join '', @filecontent; |
|
57
|
0
|
0
|
0
|
|
|
|
$filecontent =~ s/ +$//mg if $viewmode eq 'ansi2html' or $viewmode eq 'ansi2txt'; |
|
58
|
0
|
|
|
|
|
|
$c->response->header ("Content-Disposition" => qq($disposition; filename="$filename")); |
|
59
|
0
|
|
|
|
|
|
$c->response->body ($filecontent); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
10
|
|
|
10
|
|
5325
|
} |
|
|
10
|
|
|
|
|
18
|
|
|
|
10
|
|
|
|
|
85
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# strip known ANSI sequences and special characters |
|
64
|
|
|
|
|
|
|
# usually used in console output |
|
65
|
|
|
|
|
|
|
sub ansi_to_txt { |
|
66
|
0
|
|
|
0
|
0
|
|
my ($filecontent) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$filecontent =~ s/\e\[?.*?[\@-~](?:\?\d\d[hl])?//g; |
|
69
|
0
|
|
|
|
|
|
$filecontent =~ s,(?:\n\r)+,\n,g; |
|
70
|
0
|
|
|
|
|
|
$filecontent =~ s,\r(?!\n), ,g; |
|
71
|
0
|
|
|
|
|
|
$filecontent =~ s,[]+, ,g; |
|
72
|
0
|
|
|
|
|
|
return $filecontent; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub filter |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
0
|
0
|
|
my @retval; |
|
78
|
0
|
|
|
|
|
|
foreach my $line (@_) { |
|
79
|
0
|
|
|
|
|
|
$line =~ s/\000//g; |
|
80
|
0
|
|
|
|
|
|
$line =~ s/\015//g; |
|
81
|
0
|
|
|
|
|
|
$line =~ s/\033\[.*?[mH]//g; |
|
82
|
0
|
|
|
|
|
|
$line =~ s/\033\d+/\t/g; |
|
83
|
0
|
|
|
|
|
|
$line =~ s/\017//g; |
|
84
|
0
|
|
|
|
|
|
$line =~ s/\033\[\?25h//g; |
|
85
|
0
|
|
|
|
|
|
push @retval, $line; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
0
|
|
|
|
|
|
return @retval; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding UTF-8 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Tapper::Reports::Web::Controller::Tapper::ReportFile::Id |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHORS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over 4 |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Advanced Micro Devices, Inc.. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software, licensed under: |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |