| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Sat, 12 Sep 2015 00:00:43 +0200 | |
| changeset 72 | ec517ae81b39 |
| parent 70 | dfc2f094a04f |
| permissions | -rwxr-xr-x |
| 0 | 1 |
#!/usr/bin/env perl |
2 |
||
| 12 | 3 |
# This program is free software: you can redistribute it and/or modify |
4 |
# it under the terms of the GNU General Public License as published by |
|
5 |
# the Free Software Foundation, either version 3 of the License, or |
|
6 |
# (at your option) any later version. |
|
7 |
# |
|
8 |
# This program is distributed in the hope that it will be useful, |
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
# GNU General Public License for more details. |
|
12 |
# |
|
13 |
# You should have received a copy of the GNU General Public License |
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
||
|
42
604ffca3aec1
Fix warnings with perl 5.20
Vincent Tondellier <tonton+hg@team1664.org>
parents:
41
diff
changeset
|
16 |
# ABSTRACT: Web interface for breakpad |
|
604ffca3aec1
Fix warnings with perl 5.20
Vincent Tondellier <tonton+hg@team1664.org>
parents:
41
diff
changeset
|
17 |
|
| 0 | 18 |
use Mojolicious::Lite; |
|
70
dfc2f094a04f
Fix compatibility with Mojolicious > 6
Vincent Tondellier <tonton+hg@team1664.org>
parents:
68
diff
changeset
|
19 |
use Mojo::Loader qw/load_class/; |
| 0 | 20 |
use UUID; |
|
11
0bef3b8087c1
Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents:
6
diff
changeset
|
21 |
use lib 'lib'; |
| 0 | 22 |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
23 |
use CrashTest::Models::Frame; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
24 |
use CrashTest::Models::Thread; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
25 |
use CrashTest::StackFilter; |
| 29 | 26 |
|
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
27 |
app->attr(storage => sub {
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
28 |
my $self = shift; |
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
29 |
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
30 |
my $storage_class = $self->app->config->{Storage}->{Type};
|
|
70
dfc2f094a04f
Fix compatibility with Mojolicious > 6
Vincent Tondellier <tonton+hg@team1664.org>
parents:
68
diff
changeset
|
31 |
if (my $e = load_class($storage_class)) {
|
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
32 |
die ref $e ? "Exception: $e" : 'Not found!'; |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
33 |
} |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
34 |
|
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
35 |
state $storage = $storage_class->new( |
|
67
9e95be0b1b8c
Make the index columns configurable
Vincent Tondellier <tonton@team1664.org>
parents:
57
diff
changeset
|
36 |
config => $self->app->config->{Storage},
|
|
9e95be0b1b8c
Make the index columns configurable
Vincent Tondellier <tonton@team1664.org>
parents:
57
diff
changeset
|
37 |
extra_columns => $self->app->config->{WebInterface}->{ExtraColumns},
|
|
9e95be0b1b8c
Make the index columns configurable
Vincent Tondellier <tonton@team1664.org>
parents:
57
diff
changeset
|
38 |
); |
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
39 |
return $storage; |
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
40 |
}); |
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
41 |
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
42 |
app->attr(decode_queue => sub {
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
43 |
my $self = shift; |
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
44 |
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
45 |
my $decode_class = $self->app->config->{DecodeQueue}->{Type};
|
|
70
dfc2f094a04f
Fix compatibility with Mojolicious > 6
Vincent Tondellier <tonton+hg@team1664.org>
parents:
68
diff
changeset
|
46 |
if (my $e = load_class($decode_class)) {
|
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
47 |
die ref $e ? "Exception: $e" : 'Not found!'; |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
48 |
} |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
49 |
|
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
50 |
state $decode = $decode_class->new( |
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
51 |
config => $self->app->config->{DecodeQueue},
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
52 |
dumper_config => $self->app->config->{Dumper},
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
53 |
storage => $self->app->storage |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
54 |
); |
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
55 |
return $decode; |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
56 |
}); |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
57 |
|
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
58 |
app->attr(stackfilter => sub {
|
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
59 |
my $self = shift; |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
60 |
|
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
61 |
state $stackfilter = CrashTest::StackFilter->new( |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
62 |
config => $self->app->config, |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
63 |
app => $self->app |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
64 |
); |
|
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
65 |
return $stackfilter; |
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
66 |
}); |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
67 |
|
| 0 | 68 |
get '/' => sub {
|
69 |
my $self = shift; |
|
| 29 | 70 |
my $page = 1; |
|
41
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
71 |
my $crashs_per_page = 25; |
|
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
72 |
|
|
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
73 |
if($self->req->url =~ qr{.*\.atom$}) {
|
|
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
74 |
$crashs_per_page = 100; |
|
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
75 |
} |
|
f2292404519a
Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
37
diff
changeset
|
76 |
|
| 29 | 77 |
$self->validation->required('page')->like(qr/^[0-9]+$/);
|
78 |
$page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
|
|
79 |
||
|
57
cebbfcd7deff
Add search box, using perl Search::Query syntax
Vincent Tondellier <tonton+hg@team1664.org>
parents:
47
diff
changeset
|
80 |
my $result = $self->app->storage->index($page, $crashs_per_page, $self->req->param('search'));
|
| 29 | 81 |
|
82 |
$self->stash(files => $result->{crashs});
|
|
83 |
$self->stash(pager => $result->{pager});
|
|
|
67
9e95be0b1b8c
Make the index columns configurable
Vincent Tondellier <tonton@team1664.org>
parents:
57
diff
changeset
|
84 |
$self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});
|
| 0 | 85 |
$self->render('index');
|
86 |
} => 'index'; |
|
87 |
||
88 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
|
89 |
my $self = shift; |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
90 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
91 |
my $data = $self->app->storage->get_processed_data($self->param('uuid'));
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
92 |
$self->stash(processed_data => $data); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
93 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
94 |
my $crashing_thread = CrashTest::Models::Thread->new($data->{crashing_thread});
|
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
95 |
$crashing_thread = $self->app->stackfilter->apply($crashing_thread); |
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
96 |
$self->stash(crashing_thread => $crashing_thread); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
97 |
|
|
42
604ffca3aec1
Fix warnings with perl 5.20
Vincent Tondellier <tonton+hg@team1664.org>
parents:
41
diff
changeset
|
98 |
my @threads = (); |
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
99 |
foreach my $raw_thread(@{$data->{threads}}) {
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
100 |
my $thread = CrashTest::Models::Thread->new($raw_thread); |
|
68
c810480b2c37
Avoid creating a new class for each stack frame: use helpers and state variables
Vincent Tondellier <tonton@team1664.org>
parents:
67
diff
changeset
|
101 |
$thread = $self->app->stackfilter->apply($thread); |
|
42
604ffca3aec1
Fix warnings with perl 5.20
Vincent Tondellier <tonton+hg@team1664.org>
parents:
41
diff
changeset
|
102 |
push @threads, $thread; |
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
103 |
} |
|
42
604ffca3aec1
Fix warnings with perl 5.20
Vincent Tondellier <tonton+hg@team1664.org>
parents:
41
diff
changeset
|
104 |
$self->stash(threads => \@threads); |
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
105 |
|
| 0 | 106 |
$self->render('report/crash');
|
107 |
} => 'report'; |
|
108 |
||
109 |
post '/submit' => sub {
|
|
110 |
my $self = shift; |
|
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
111 |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
112 |
#my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
113 |
|
| 0 | 114 |
# save the dump in a file |
115 |
my $file = $self->req->upload('upload_file_minidump');
|
|
|
57
cebbfcd7deff
Add search box, using perl Search::Query syntax
Vincent Tondellier <tonton+hg@team1664.org>
parents:
47
diff
changeset
|
116 |
|
|
cebbfcd7deff
Add search box, using perl Search::Query syntax
Vincent Tondellier <tonton+hg@team1664.org>
parents:
47
diff
changeset
|
117 |
# TODO check for authorised values ... |
|
17
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
118 |
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
119 |
|
| 0 | 120 |
my ($uuid, $uuidstr); |
121 |
UUID::generate($uuid); |
|
122 |
UUID::unparse($uuid, $uuidstr); |
|
| 23 | 123 |
|
124 |
$self->render_later(); |
|
| 0 | 125 |
|
| 23 | 126 |
$self->app->decode_queue->decode($file, \%paramshash, $uuidstr, sub {
|
127 |
my $pjson = shift; |
|
128 |
# reply |
|
129 |
$self->render(text => $pjson->{status});
|
|
130 |
} |
|
131 |
); |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
132 |
} => 'submit'; |
| 0 | 133 |
|
| 23 | 134 |
app->secrets([ |
135 |
'My secret passphrase here' |
|
136 |
]); |
|
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
23
diff
changeset
|
137 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
23
diff
changeset
|
138 |
push @{app->commands->namespaces}, 'CrashTest::Commands';
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
139 |
push @{app->plugins->namespaces}, 'CrashTest::Helpers';
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
140 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
141 |
plugin 'Config'; |
|
47
b8a7a5ec6461
Replace the modified pagination plugin with a cleaner one that supports bootstrap natively
Vincent Tondellier <tonton+hg@team1664.org>
parents:
42
diff
changeset
|
142 |
plugin 'bootstrap_pagination'; |
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
143 |
plugin 'CrashTestHelpers'; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
144 |
|
| 0 | 145 |
app->start; |