CrashTest.pl
changeset 0 5b78b8c79d9c
child 1 c3726f733704
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CrashTest.pl	Tue May 01 23:34:48 2012 +0200
@@ -0,0 +1,79 @@
+#!/usr/bin/env perl
+
+use Mojolicious::Lite;
+use UUID;
+use Mojo::JSON;
+
+my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
+my $config = plugin 'Config';
+my $data_path = $config->{DataDir};
+
+# Upload form in DATA section
+get '/' => sub {
+    my $self = shift;
+
+    my @files;
+    opendir my ($dh), $data_path;
+    while(readdir $dh) {
+        if($_ =~ /(.*)\.pjson$/) {
+            my $filename = File::Spec->catfile($data_path, $_);
+            push @files, {
+                file => $filename,
+                uuid => $1,
+                date => (stat $filename)[9],
+            };
+        }
+    }
+    closedir $dh;
+
+    my @sorted_files = ( sort { $b->{date} <=> $a->{date} } @files );
+    @sorted_files = @sorted_files[0..19] if scalar(@sorted_files) > 20;
+
+    $self->stash(files => \@sorted_files);
+
+    $self->render('index');
+} => 'index';
+
+get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
+    my $self = shift;
+
+    open JSON, '<', $data_path . '/' . $self->param('uuid') . '.pjson';
+    my @json_content_lines = <JSON>;
+    my $json_content = join('', @json_content_lines);
+    my $json = Mojo::JSON->new;
+    my $processed_data = $json->decode($json_content);
+    close JSON;
+
+    $self->stash(processed_data => $processed_data);
+
+    $self->render('report/crash');
+} => 'report';
+
+# Streaming multipart upload (invoked twice, due to early "request" event)
+post '/submit' => sub {
+    my $self = shift;
+    
+    # save the dump in a file
+    my $file = $self->req->upload('upload_file_minidump');
+    my ($uuid, $uuidstr);
+    UUID::generate($uuid);
+    UUID::unparse($uuid, $uuidstr);
+    $file->move_to($data_path . '/' . $uuidstr . '.dmp');
+
+    # Create json for the params
+    #my @par = $self->req->param;
+    my %paramshash = map { $_ => $self->req->param($_) } @valid_params;
+
+    my $json = Mojo::JSON->new;
+    my $j = $json->encode(\%paramshash);
+    open JSON, '>', $data_path . '/' . $uuidstr . '.json' or die $!;
+    print JSON $j;
+    close JSON;
+
+    system($config->{MinidumpStackwalkJSON} . " " . $data_path . '/' . $uuidstr . '.dmp' . " " . $config->{SymbolsPath} . " > " . $data_path . '/' . $uuidstr . '.pjson' . " 2>/dev/null");
+
+    # reply
+    $self->render_text($j);
+};
+
+app->start;