0
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/env perl
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
2 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
3 |
use Mojolicious::Lite;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
4 |
use UUID;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
5 |
use Mojo::JSON;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
6 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
7 |
my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
8 |
my $config = plugin 'Config';
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
9 |
my $data_path = $config->{DataDir};
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
10 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
11 |
# Upload form in DATA section
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
12 |
get '/' => sub {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
13 |
my $self = shift;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
14 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
15 |
my @files;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
16 |
opendir my ($dh), $data_path;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
17 |
while(readdir $dh) {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
18 |
if($_ =~ /(.*)\.pjson$/) {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
19 |
my $filename = File::Spec->catfile($data_path, $_);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
20 |
push @files, {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
21 |
file => $filename,
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
22 |
uuid => $1,
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
23 |
date => (stat $filename)[9],
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
24 |
};
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
25 |
}
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
26 |
}
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
27 |
closedir $dh;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
28 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
29 |
my @sorted_files = ( sort { $b->{date} <=> $a->{date} } @files );
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
30 |
@sorted_files = @sorted_files[0..19] if scalar(@sorted_files) > 20;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
31 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
32 |
$self->stash(files => \@sorted_files);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
33 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
34 |
$self->render('index');
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
35 |
} => 'index';
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
36 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
37 |
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
38 |
my $self = shift;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
39 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
40 |
open JSON, '<', $data_path . '/' . $self->param('uuid') . '.pjson';
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
41 |
my @json_content_lines = <JSON>;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
42 |
my $json_content = join('', @json_content_lines);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
43 |
my $json = Mojo::JSON->new;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
44 |
my $processed_data = $json->decode($json_content);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
45 |
close JSON;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
46 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
47 |
$self->stash(processed_data => $processed_data);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
48 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
49 |
$self->render('report/crash');
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
50 |
} => 'report';
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
51 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
52 |
# Streaming multipart upload (invoked twice, due to early "request" event)
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
53 |
post '/submit' => sub {
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
54 |
my $self = shift;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
55 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
56 |
# save the dump in a file
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
57 |
my $file = $self->req->upload('upload_file_minidump');
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
58 |
my ($uuid, $uuidstr);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
59 |
UUID::generate($uuid);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
60 |
UUID::unparse($uuid, $uuidstr);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
61 |
$file->move_to($data_path . '/' . $uuidstr . '.dmp');
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
62 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
63 |
# Create json for the params
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
64 |
#my @par = $self->req->param;
|
|
1
|
65 |
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
|
0
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
66 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
67 |
my $json = Mojo::JSON->new;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
68 |
my $j = $json->encode(\%paramshash);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
69 |
open JSON, '>', $data_path . '/' . $uuidstr . '.json' or die $!;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
70 |
print JSON $j;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
71 |
close JSON;
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
72 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
73 |
system($config->{MinidumpStackwalkJSON} . " " . $data_path . '/' . $uuidstr . '.dmp' . " " . $config->{SymbolsPath} . " > " . $data_path . '/' . $uuidstr . '.pjson' . " 2>/dev/null");
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
74 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
75 |
# reply
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
76 |
$self->render_text($j);
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
77 |
};
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
78 |
|
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
79 |
app->start;
|