17 use UUID; |
17 use UUID; |
18 use Mojo::JSON; |
18 use Mojo::JSON; |
19 use Mojo::ByteStream 'b'; |
19 use Mojo::ByteStream 'b'; |
20 use Mojo::UserAgent; |
20 use Mojo::UserAgent; |
21 use lib 'lib'; |
21 use lib 'lib'; |
22 use CrashTest::Storage::FileSystem; |
|
23 |
22 |
24 my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
23 my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/; |
25 my $config = plugin 'Config'; |
24 my $config = plugin 'Config'; |
26 my $storage = CrashTest::Storage::FileSystem->new($config->{DataDir}); |
|
27 |
25 |
|
26 app->attr(storage => sub { |
|
27 my $self = shift; |
|
28 eval "require $config->{Storage}"; |
|
29 return $config->{Storage}->new($config->{DataDir}); |
|
30 }); |
|
31 |
|
32 app->attr(decode_queue => sub { |
|
33 my $self = shift; |
|
34 eval "require $config->{DecodeQueue}"; |
|
35 return $config->{DecodeQueue}->new($config); |
|
36 }); |
28 |
37 |
29 helper scm_file_link => sub { |
38 helper scm_file_link => sub { |
30 my ($self, $file, $line) = @_; |
39 my ($self, $file, $line) = @_; |
31 |
40 |
32 return "" unless(defined($file)); |
41 return "" unless(defined($file)); |
68 }; |
77 }; |
69 |
78 |
70 # Upload form in DATA section |
79 # Upload form in DATA section |
71 get '/' => sub { |
80 get '/' => sub { |
72 my $self = shift; |
81 my $self = shift; |
73 $self->stash(files => $storage->index()); |
82 $self->stash(files => $self->app->storage->index()); |
74 $self->render('index'); |
83 $self->render('index'); |
75 } => 'index'; |
84 } => 'index'; |
76 |
85 |
77 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub { |
86 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub { |
78 my $self = shift; |
87 my $self = shift; |
79 $self->stash(processed_data => $storage->get_processed_data($self->param('uuid'))); |
88 $self->stash(processed_data => $self->app->storage->get_processed_data($self->param('uuid'))); |
80 $self->render('report/crash'); |
89 $self->render('report/crash'); |
81 } => 'report'; |
90 } => 'report'; |
82 |
91 |
83 post '/submit' => sub { |
92 post '/submit' => sub { |
84 my $self = shift; |
93 my $self = shift; |
85 |
94 |
86 # save the dump in a file |
95 # save the dump in a file |
87 my $file = $self->req->upload('upload_file_minidump'); |
96 my $file = $self->req->upload('upload_file_minidump'); |
|
97 my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; |
|
98 |
|
99 my $pjson = $self->app->decode_queue->decode($file, \%paramshash); |
|
100 |
88 my ($uuid, $uuidstr); |
101 my ($uuid, $uuidstr); |
89 UUID::generate($uuid); |
102 UUID::generate($uuid); |
90 UUID::unparse($uuid, $uuidstr); |
103 UUID::unparse($uuid, $uuidstr); |
91 my $dmp_file = "/tmp/$uuidstr.dmp"; |
|
92 $file->move_to($dmp_file); |
|
93 |
104 |
94 my $out = qx($config->{MinidumpStackwalkJSON} "$dmp_file" $config->{SymbolsPath} 2>/dev/null) or die $!; |
105 $self->app->storage->store_dump($uuidstr, $file); |
95 |
106 $self->app->storage->store_processed_data($uuidstr, $pjson); |
96 my $json = Mojo::JSON->new; |
|
97 my $pjson = $json->decode($out); |
|
98 |
|
99 # Create json for the params |
|
100 my %paramshash = map { $_ => $self->req->param($_) } $self->req->param; |
|
101 $pjson->{client_info} = \%paramshash; |
|
102 |
|
103 $storage->store_dump($uuidstr, $file); |
|
104 $storage->store_processed_data($uuidstr, $pjson); |
|
105 unlink $dmp_file if -w $dmp_file; |
|
106 |
107 |
107 # reply |
108 # reply |
108 $self->render_text($pjson->{status}); |
109 $self->render_text($pjson->{status}); |
109 }; |
110 }; |
110 |
111 |