CrashTest.pl
changeset 78 0ebef32c34af
parent 77 e408da1419cd
child 79 4ae8bb6f8a96
equal deleted inserted replaced
77:e408da1419cd 78:0ebef32c34af
     1 #!/usr/bin/env perl
       
     2 
       
     3 # This program is free software: you can redistribute it and/or modify
       
     4 # it under the terms of the GNU General Public License as published by
       
     5 # the Free Software Foundation, either version 3 of the License, or
       
     6 # (at your option) any later version.
       
     7 #
       
     8 # This program is distributed in the hope that it will be useful,
       
     9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    11 # GNU General Public License for more details.
       
    12 #
       
    13 # You should have received a copy of the GNU General Public License
       
    14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    15 
       
    16 # ABSTRACT: Web interface for breakpad
       
    17 
       
    18 use Mojolicious::Lite;
       
    19 use Mojo::Loader qw/load_class/;
       
    20 use UUID;
       
    21 use lib 'lib';
       
    22 
       
    23 use CrashTest::Models::Frame;
       
    24 use CrashTest::Models::Thread;
       
    25 use CrashTest::StackFilter;
       
    26 
       
    27 app->attr(storage => sub {
       
    28     my $self = shift;
       
    29 
       
    30     my $storage_class = $self->app->config->{Storage}->{Type};
       
    31     if (my $e = load_class($storage_class)) {
       
    32         die ref $e ? "Exception: $e" : 'Not found!';
       
    33     }
       
    34 
       
    35     state $storage = $storage_class->new(
       
    36         config => $self->app->config->{Storage},
       
    37         extra_columns => $self->app->config->{WebInterface}->{ExtraColumns},
       
    38     );
       
    39     return $storage;
       
    40 });
       
    41 
       
    42 app->attr(decode_queue => sub {
       
    43     my $self = shift;
       
    44 
       
    45     my $decode_class = $self->app->config->{DecodeQueue}->{Type};
       
    46     if (my $e = load_class($decode_class)) {
       
    47         die ref $e ? "Exception: $e" : 'Not found!';
       
    48     }
       
    49 
       
    50     state $decode = $decode_class->new(
       
    51         config => $self->app->config->{DecodeQueue},
       
    52         dumper_config => $self->app->config->{Dumper},
       
    53         storage => $self->app->storage
       
    54     );
       
    55     return $decode;
       
    56 });
       
    57 
       
    58 app->attr(stackfilter => sub {
       
    59     my $self = shift;
       
    60 
       
    61     state $stackfilter = CrashTest::StackFilter->new(
       
    62         config => $self->app->config,
       
    63         app => $self->app
       
    64     );
       
    65     return $stackfilter;
       
    66 });
       
    67 
       
    68 get '/' => sub {
       
    69     my $self = shift;
       
    70     my $page = 1;
       
    71     my $crashs_per_page = 25;
       
    72 
       
    73     if($self->req->url =~ qr{.*\.atom$}) {
       
    74         $crashs_per_page = 100;
       
    75     }
       
    76 
       
    77     $self->validation->required('page')->like(qr/^[0-9]+$/);
       
    78     $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
       
    79 
       
    80     my $result = $self->app->storage->index($page, $crashs_per_page, $self->req->param('search'));
       
    81 
       
    82     $self->stash(files => $result->{crashs});
       
    83     $self->stash(pager => $result->{pager});
       
    84     $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});
       
    85     $self->render('index');
       
    86 } => 'index';
       
    87 
       
    88 get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
       
    89     my $self = shift;
       
    90 
       
    91     my $data = $self->app->storage->get_processed_data($self->param('uuid'));
       
    92     $self->stash(processed_data => $data);
       
    93 
       
    94     my $crashing_thread = CrashTest::Models::Thread->new($data->{crashing_thread});
       
    95     $crashing_thread = $self->app->stackfilter->apply($crashing_thread);
       
    96     $self->stash(crashing_thread => $crashing_thread);
       
    97 
       
    98     my @threads = ();
       
    99     foreach my $raw_thread(@{$data->{threads}}) {
       
   100         my $thread = CrashTest::Models::Thread->new($raw_thread);
       
   101         $thread = $self->app->stackfilter->apply($thread);
       
   102         push @threads, $thread;
       
   103     }
       
   104     $self->stash(threads => \@threads);
       
   105 
       
   106     $self->render('report/crash');
       
   107 } => 'report';
       
   108 
       
   109 post '/submit' => sub {
       
   110     my $self = shift;
       
   111 
       
   112     #my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
       
   113 
       
   114     # save the dump in a file
       
   115     my $file = $self->req->upload('upload_file_minidump');
       
   116 
       
   117     # TODO check for authorised values ...
       
   118     my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
       
   119 
       
   120     my ($uuid, $uuidstr);
       
   121     UUID::generate($uuid);
       
   122     UUID::unparse($uuid, $uuidstr);
       
   123 
       
   124     $self->render_later();
       
   125 
       
   126     $self->app->decode_queue->decode($file, \%paramshash, $uuidstr, sub {
       
   127             my $pjson = shift;
       
   128             # reply
       
   129             $self->render(text => $pjson->{status});
       
   130         }
       
   131     );
       
   132 } => 'submit';
       
   133 
       
   134 app->secrets([
       
   135     'My secret passphrase here'
       
   136 ]);
       
   137 
       
   138 push @{app->commands->namespaces}, 'CrashTest::Commands';
       
   139 push @{app->plugins->namespaces}, 'CrashTest::Helpers';
       
   140 
       
   141 plugin 'Config';
       
   142 plugin 'bootstrap_pagination';
       
   143 plugin 'CrashTestHelpers';
       
   144 
       
   145 app->start;