1 #!/usr/bin/env perl |
1 #!/usr/bin/env perl |
2 |
2 |
3 use Mojolicious::Lite; |
3 use Mojolicious::Lite; |
4 use UUID; |
4 use UUID; |
5 use Mojo::JSON; |
5 use Mojo::JSON; |
|
6 use Mojo::UserAgent; |
6 |
7 |
7 my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
8 my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
8 my $config = plugin 'Config'; |
9 my $config = plugin 'Config'; |
9 my $data_path = $config->{DataDir}; |
10 my $data_path = $config->{DataDir}; |
|
11 |
|
12 |
|
13 helper scm_file_link => sub { |
|
14 my ($self, $file, $line) = @_; |
|
15 |
|
16 return "" unless(defined($file)); |
|
17 |
|
18 if($file =~ qr{([a-z]+):([a-z/.]+):(.+):(\d+)}) |
|
19 { |
|
20 my ($scm, $repo, $scmpath, $rev) = ($1, $2, $3, $4); |
|
21 my $filename = File::Spec->splitpath($scmpath); |
|
22 my $scmrepo = "$scm:$repo"; |
|
23 if(exists($config->{ScmLinks}->{$scmrepo})) { |
|
24 return Mojo::ByteStream->new($self->link_to("$filename:$line" => |
|
25 $self->render(inline => $config->{ScmLinks}->{$scmrepo}, repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1) |
|
26 )); |
|
27 } |
|
28 #return $file; |
|
29 } |
|
30 my $filebase = (File::Spec->splitpath($file))[-1]; |
|
31 if(defined($line) && $line ne "") { |
|
32 return "$filebase:$line"; |
|
33 } |
|
34 return $filebase; |
|
35 }; |
|
36 |
|
37 helper shorten_signature => sub { |
|
38 my ($self, $signature) = @_; |
|
39 |
|
40 return "" if(!defined($signature) || $signature eq ""); |
|
41 |
|
42 my $short_signature = $signature; |
|
43 if($signature =~ qr{([^<]+)<.+>::([^()]+)\(.*\)(.*)}) { |
|
44 # c++ with template |
|
45 $short_signature = "$1<>::$2()$3"; |
|
46 } elsif($signature =~ qr{([^()]+)\(.*\)(.*)}) { |
|
47 # c/c++ |
|
48 $short_signature = "$1()$2"; |
|
49 } |
|
50 return Mojo::ByteStream->new($self->t(span => (title => $signature, class => "shortened-signature") => $short_signature)); |
|
51 }; |
10 |
52 |
11 # Upload form in DATA section |
53 # Upload form in DATA section |
12 get '/' => sub { |
54 get '/' => sub { |
13 my $self = shift; |
55 my $self = shift; |
14 |
56 |
15 my @files; |
57 my @files; |
16 opendir my ($dh), $data_path; |
58 opendir my ($dh), $data_path; |
17 while(readdir $dh) { |
59 while(readdir $dh) { |
18 if($_ =~ /(.*)\.pjson$/) { |
60 if($_ =~ /(.*)\.json$/) { |
19 my $filename = File::Spec->catfile($data_path, $_); |
61 my $filename = File::Spec->catfile($data_path, $_); |
20 push @files, { |
62 push @files, { |
21 file => $filename, |
63 file => $filename, |
22 uuid => $1, |
64 uuid => $1, |
|
65 signature => $1, |
|
66 product => "", |
23 date => (stat $filename)[9], |
67 date => (stat $filename)[9], |
24 }; |
68 }; |
25 } |
69 } |
26 } |
70 } |
27 closedir $dh; |
71 closedir $dh; |
35 } => 'index'; |
79 } => 'index'; |
36 |
80 |
37 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub { |
81 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub { |
38 my $self = shift; |
82 my $self = shift; |
39 |
83 |
40 open JSON, '<', $data_path . '/' . $self->param('uuid') . '.pjson'; |
84 open JSON, '<', File::Spec->catfile($data_path, $self->param('uuid') . '.json') or die $!; |
41 my @json_content_lines = <JSON>; |
85 my @json_content_lines = <JSON>; |
42 my $json_content = join('', @json_content_lines); |
86 my $json_content = join('', @json_content_lines); |
|
87 close JSON; |
|
88 |
43 my $json = Mojo::JSON->new; |
89 my $json = Mojo::JSON->new; |
44 my $processed_data = $json->decode($json_content); |
90 my $processed_data = $json->decode($json_content); |
45 close JSON; |
|
46 |
91 |
47 $self->stash(processed_data => $processed_data); |
92 $self->stash(processed_data => $processed_data); |
48 |
93 |
49 $self->render('report/crash'); |
94 $self->render('report/crash'); |
50 } => 'report'; |
95 } => 'report'; |
51 |
96 |
52 # Streaming multipart upload (invoked twice, due to early "request" event) |
|
53 post '/submit' => sub { |
97 post '/submit' => sub { |
54 my $self = shift; |
98 my $self = shift; |
55 |
99 |
56 # save the dump in a file |
100 # save the dump in a file |
57 my $file = $self->req->upload('upload_file_minidump'); |
101 my $file = $self->req->upload('upload_file_minidump'); |
58 my ($uuid, $uuidstr); |
102 my ($uuid, $uuidstr); |
59 UUID::generate($uuid); |
103 UUID::generate($uuid); |
60 UUID::unparse($uuid, $uuidstr); |
104 UUID::unparse($uuid, $uuidstr); |
61 $file->move_to($data_path . '/' . $uuidstr . '.dmp'); |
105 my $dmp_file = File::Spec->catfile($data_path, "$uuidstr.dmp"); |
|
106 $file->move_to($dmp_file); |
62 |
107 |
63 # Create json for the params |
108 # Create json for the params |
64 #my @par = $self->req->param; |
|
65 my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; |
109 my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; |
66 |
110 |
|
111 my $out = qx($config->{MinidumpStackwalkJSON} "$dmp_file" $config->{SymbolsPath} 2>/dev/null) or die $!; |
|
112 |
67 my $json = Mojo::JSON->new; |
113 my $json = Mojo::JSON->new; |
68 my $j = $json->encode(\%paramshash); |
114 my $pjson = $json->decode($out); |
69 open JSON, '>', $data_path . '/' . $uuidstr . '.json' or die $!; |
115 $pjson->{client_info} = \%paramshash; |
|
116 |
|
117 my $j = $json->encode($pjson); |
|
118 open JSON, '>', File::Spec->catfile($data_path, "$uuidstr.json") or die $!; |
70 print JSON $j; |
119 print JSON $j; |
71 close JSON; |
120 close JSON; |
72 |
121 |
73 system($config->{MinidumpStackwalkJSON} . " " . $data_path . '/' . $uuidstr . '.dmp' . " " . $config->{SymbolsPath} . " > " . $data_path . '/' . $uuidstr . '.pjson' . " 2>/dev/null"); |
|
74 |
|
75 # reply |
122 # reply |
76 $self->render_text($j); |
123 $self->render_text($pjson->{status}); |
77 }; |
124 }; |
78 |
125 |
|
126 app->secret('My secret passphrase here'); |
79 app->start; |
127 app->start; |