CrashTest.pl
author Vincent Tondellier <tonton+hg@team1664.org>
Fri, 08 Aug 2014 23:05:03 +0200
changeset 41 f2292404519a
parent 37 013953be0f3b
child 42 604ffca3aec1
permissions -rwxr-xr-x
Display more crashs in the Atom feed than on the webpage There is a better way to sniff content type, but it's only available in newer mojolicious versions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     1
#!/usr/bin/env perl
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     2
12
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     3
# This program is free software: you can redistribute it and/or modify
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     4
# it under the terms of the GNU General Public License as published by
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     5
# the Free Software Foundation, either version 3 of the License, or
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     6
# (at your option) any later version.
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     7
#
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     8
# This program is distributed in the hope that it will be useful,
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    11
# GNU General Public License for more details.
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    12
#
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    13
# You should have received a copy of the GNU General Public License
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
c98d3fa4a948 Add licence
Vincent Tondellier <tonton+hg@team1664.org>
parents: 11
diff changeset
    15
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    16
use Mojolicious::Lite;
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    17
use UUID;
11
0bef3b8087c1 Move filesystem access to lib/
Vincent Tondellier <tonton+hg@team1664.org>
parents: 6
diff changeset
    18
use lib 'lib';
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    19
37
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    20
use CrashTest::Models::Frame;
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    21
use CrashTest::Models::Thread;
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    22
use CrashTest::StackFilter;
29
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    23
17
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    24
app->attr(storage => sub {
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    25
    my $self = shift;
34
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    26
    my $loader = Mojo::Loader->new;
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    27
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    28
    my $storage_class = $self->app->config->{Storage}->{Type};
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    29
    if (my $e = $loader->load($storage_class)) {
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    30
        die ref $e ? "Exception: $e" : 'Not found!';
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    31
    }
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    32
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    33
    return $storage_class->new(config => $self->app->config->{Storage});
17
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    34
});
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    35
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    36
app->attr(decode_queue => sub {
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    37
    my $self = shift;
34
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    38
    my $loader = Mojo::Loader->new;
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    39
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    40
    my $decode_class = $self->app->config->{DecodeQueue}->{Type};
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    41
    if (my $e = $loader->load($decode_class)) {
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    42
        die ref $e ? "Exception: $e" : 'Not found!';
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    43
    }
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    44
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    45
    return $decode_class->new(
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    46
        config => $self->app->config->{DecodeQueue},
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    47
        dumper_config => $self->app->config->{Dumper},
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    48
        storage => $self->app->storage
e0d6597078a5 Cleanup: Mojo-ize old code, simplifying perl OO code
Vincent Tondellier <tonton+hg@team1664.org>
parents: 32
diff changeset
    49
    );
17
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
    50
});
3
2ff78fe4abda Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents: 1
diff changeset
    51
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    52
get '/' => sub {
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    53
    my $self = shift;
29
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    54
    my $page = 1;
41
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    55
    my $crashs_per_page = 25;
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    56
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    57
    if($self->req->url =~ qr{.*\.atom$}) {
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    58
        $crashs_per_page = 100;
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    59
    }
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    60
29
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    61
    $self->validation->required('page')->like(qr/^[0-9]+$/);
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    62
    $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    63
41
f2292404519a Display more crashs in the Atom feed than on the webpage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 37
diff changeset
    64
    my $result = $self->app->storage->index($page, $crashs_per_page);
29
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    65
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    66
    $self->stash(files => $result->{crashs});
006e82a1bcd0 Add pagination
Vincent Tondellier <tonton+hg@team1664.org>
parents: 24
diff changeset
    67
    $self->stash(pager => $result->{pager});
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    68
    $self->render('index');
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    69
} => 'index';
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    70
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    71
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    72
    my $self = shift;
37
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    73
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    74
    my $data = $self->app->storage->get_processed_data($self->param('uuid'));
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    75
    $self->stash(processed_data => $data);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    76
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    77
    my $stackfilter = CrashTest::StackFilter->new(config => $self->app->config, app => $self->app);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    78
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    79
    my $crashing_thread = CrashTest::Models::Thread->new($data->{crashing_thread});
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    80
    $crashing_thread = $stackfilter->apply($crashing_thread);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    81
    $self->stash(crashing_thread => $crashing_thread);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    82
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    83
    my $threads = [];
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    84
    foreach my $raw_thread(@{$data->{threads}}) {
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    85
        my $thread = CrashTest::Models::Thread->new($raw_thread);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    86
        $thread = $stackfilter->apply($thread);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    87
        push $threads, $thread;
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    88
    }
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    89
    $self->stash(threads => $threads);
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    90
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    91
    $self->render('report/crash');
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    92
} => 'report';
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    93
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    94
post '/submit' => sub {
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    95
    my $self = shift;
3
2ff78fe4abda Create helper to shorten signatures and create links to the repository
Vincent Tondellier <tonton+hg@team1664.org>
parents: 1
diff changeset
    96
37
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    97
    #my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
    98
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    99
    # save the dump in a file
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   100
    my $file = $self->req->upload('upload_file_minidump');
17
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
   101
    my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
c91535b1db3e Move the decoding to a module, and had config to choose which module
Vincent Tondellier <tonton+hg@team1664.org>
parents: 16
diff changeset
   102
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   103
    my ($uuid, $uuidstr);
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   104
    UUID::generate($uuid);
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   105
    UUID::unparse($uuid, $uuidstr);
23
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   106
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   107
    $self->render_later();
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   108
23
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   109
    $self->app->decode_queue->decode($file, \%paramshash, $uuidstr, sub {
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   110
            my $pjson = shift;
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   111
            # reply
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   112
            $self->render(text => $pjson->{status});
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   113
        }
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   114
    );
37
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   115
} => 'submit';
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   116
23
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   117
app->secrets([
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   118
    'My secret passphrase here'
e621317229f7 Async submit.
Vincent Tondellier <tonton+hg@team1664.org>
parents: 19
diff changeset
   119
]);
24
b69b7aa98a1d Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 23
diff changeset
   120
b69b7aa98a1d Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents: 23
diff changeset
   121
push @{app->commands->namespaces}, 'CrashTest::Commands';
37
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   122
push @{app->plugins->namespaces}, 'CrashTest::Helpers';
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   123
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   124
plugin 'Config';
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   125
plugin 'TagHelpers::BootstrapPagination';
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   126
plugin 'CrashTestHelpers';
013953be0f3b Add a new backtrace-processing filter stack
Vincent Tondellier <tonton+hg@team1664.org>
parents: 34
diff changeset
   127
0
5b78b8c79d9c Initial commit
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
   128
app->start;