| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Fri, 08 Aug 2014 00:02:55 +0200 | |
| changeset 38 | 6fa3cf9cf915 |
| parent 37 | 013953be0f3b |
| child 41 | f2292404519a |
| 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 |
||
| 0 | 16 |
use Mojolicious::Lite; |
17 |
use UUID; |
|
|
11
0bef3b8087c1
Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents:
6
diff
changeset
|
18 |
use lib 'lib'; |
| 0 | 19 |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
20 |
use CrashTest::Models::Frame; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
21 |
use CrashTest::Models::Thread; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
22 |
use CrashTest::StackFilter; |
| 29 | 23 |
|
|
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
|
24 |
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
|
25 |
my $self = shift; |
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
26 |
my $loader = Mojo::Loader->new; |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
27 |
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
28 |
my $storage_class = $self->app->config->{Storage}->{Type};
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
29 |
if (my $e = $loader->load($storage_class)) {
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
30 |
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
|
31 |
} |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
32 |
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
33 |
return $storage_class->new(config => $self->app->config->{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
|
34 |
}); |
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
35 |
|
|
c91535b1db3e
Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents:
16
diff
changeset
|
36 |
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
|
37 |
my $self = shift; |
|
34
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
38 |
my $loader = Mojo::Loader->new; |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
39 |
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
40 |
my $decode_class = $self->app->config->{DecodeQueue}->{Type};
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
41 |
if (my $e = $loader->load($decode_class)) {
|
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
42 |
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
|
43 |
} |
|
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 |
return $decode_class->new( |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
storage => $self->app->storage |
|
e0d6597078a5
Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents:
32
diff
changeset
|
49 |
); |
|
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
|
50 |
}); |
|
3
2ff78fe4abda
Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents:
1
diff
changeset
|
51 |
|
| 0 | 52 |
get '/' => sub {
|
53 |
my $self = shift; |
|
| 29 | 54 |
my $page = 1; |
55 |
$self->validation->required('page')->like(qr/^[0-9]+$/);
|
|
56 |
$page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
|
|
57 |
||
58 |
my $result = $self->app->storage->index($page, 20); |
|
59 |
||
60 |
$self->stash(files => $result->{crashs});
|
|
61 |
$self->stash(pager => $result->{pager});
|
|
| 0 | 62 |
$self->render('index');
|
63 |
} => 'index'; |
|
64 |
||
65 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
|
66 |
my $self = shift; |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
67 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
68 |
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
|
69 |
$self->stash(processed_data => $data); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
70 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
71 |
my $stackfilter = CrashTest::StackFilter->new(config => $self->app->config, app => $self->app); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
72 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
73 |
my $crashing_thread = CrashTest::Models::Thread->new($data->{crashing_thread});
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
74 |
$crashing_thread = $stackfilter->apply($crashing_thread); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
75 |
$self->stash(crashing_thread => $crashing_thread); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
76 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
77 |
my $threads = []; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
78 |
foreach my $raw_thread(@{$data->{threads}}) {
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
79 |
my $thread = CrashTest::Models::Thread->new($raw_thread); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
80 |
$thread = $stackfilter->apply($thread); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
81 |
push $threads, $thread; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
82 |
} |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
83 |
$self->stash(threads => $threads); |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
84 |
|
| 0 | 85 |
$self->render('report/crash');
|
86 |
} => 'report'; |
|
87 |
||
88 |
post '/submit' => sub {
|
|
89 |
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
|
90 |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
91 |
#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
|
92 |
|
| 0 | 93 |
# save the dump in a file |
94 |
my $file = $self->req->upload('upload_file_minidump');
|
|
|
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
|
95 |
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
|
96 |
|
| 0 | 97 |
my ($uuid, $uuidstr); |
98 |
UUID::generate($uuid); |
|
99 |
UUID::unparse($uuid, $uuidstr); |
|
| 23 | 100 |
|
101 |
$self->render_later(); |
|
| 0 | 102 |
|
| 23 | 103 |
$self->app->decode_queue->decode($file, \%paramshash, $uuidstr, sub {
|
104 |
my $pjson = shift; |
|
105 |
# reply |
|
106 |
$self->render(text => $pjson->{status});
|
|
107 |
} |
|
108 |
); |
|
|
37
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
109 |
} => 'submit'; |
| 0 | 110 |
|
| 23 | 111 |
app->secrets([ |
112 |
'My secret passphrase here' |
|
113 |
]); |
|
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
23
diff
changeset
|
114 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
23
diff
changeset
|
115 |
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
|
116 |
push @{app->plugins->namespaces}, 'CrashTest::Helpers';
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
117 |
|
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
118 |
plugin 'Config'; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
119 |
plugin 'TagHelpers::BootstrapPagination'; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
120 |
plugin 'CrashTestHelpers'; |
|
013953be0f3b
Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents:
34
diff
changeset
|
121 |
|
| 0 | 122 |
app->start; |