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