#!/usr/bin/env perl
use Mojolicious::Lite;
use UUID;
use Mojo::JSON;
use Mojo::UserAgent;
use lib 'lib';
use CrashTest::Storage::FileSystem;
my @valid_params = qw/Add-ons Distributor ProductName ReleaseChannel StartupTime UserID Version BuildID CrashTime Comments/;
my $config = plugin 'Config';
my $storage = CrashTest::Storage::FileSystem->new($config->{DataDir});
helper scm_file_link => sub {
my ($self, $file, $line) = @_;
return "" unless(defined($file));
if($file =~ qr{([a-z]+):([a-z/.]+):(.+):(\d+)})
{
my ($scm, $repo, $scmpath, $rev) = ($1, $2, $3, $4);
my $filename = File::Spec->splitpath($scmpath);
my $scmrepo = "$scm:$repo";
if(exists($config->{ScmLinks}->{$scmrepo})) {
return Mojo::ByteStream->new($self->link_to("$filename:$line" =>
$self->render(inline => $config->{ScmLinks}->{$scmrepo},
repo => $repo, scmpath => $scmpath, rev => $rev, line => $line, partial => 1)
));
}
#return $file;
}
my $filebase = (File::Spec->splitpath($file))[-1];
if(defined($line) && $line ne "") {
return "$filebase:$line";
}
return $filebase;
};
helper shorten_signature => sub {
my ($self, $signature) = @_;
return "" if(!defined($signature) || $signature eq "");
my $short_signature = $signature;
if($signature =~ qr{([^<]+)<.+>::([^()]+)\(.*\)(.*)}) {
# c++ with template
$short_signature = "$1<>::$2()$3";
} elsif($signature =~ qr{([^()]+)\(.*\)(.*)}) {
# c/c++
$short_signature = "$1()$2";
}
return Mojo::ByteStream->new($self->t(span => (title => $signature, class => "shortened-signature") => $short_signature));
};
# Upload form in DATA section
get '/' => sub {
my $self = shift;
$self->stash(files => $storage->index());
$self->render('index');
} => 'index';
get '/report/:uuid' => [ uuid => qr/[0-9a-fA-F-]+/ ] => sub {
my $self = shift;
$self->stash(processed_data => $storage->get_processed_data($self->param('uuid')));
$self->render('report/crash');
} => 'report';
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);
my $dmp_file = "/tmp/$uuidstr.dmp";
$file->move_to($dmp_file);
my $out = qx($config->{MinidumpStackwalkJSON} "$dmp_file" $config->{SymbolsPath} 2>/dev/null) or die $!;
my $json = Mojo::JSON->new;
my $pjson = $json->decode($out);
# Create json for the params
my %paramshash = map { $_ => $self->req->param($_) } $self->req->param;
$pjson->{client_info} = \%paramshash;
$storage->store_dump($uuidstr, $file);
$storage->store_processed_data($uuidstr, $pjson);
unlink $dmp_file if -w $dmp_file;
# reply
$self->render_text($pjson->{status});
};
app->secret('My secret passphrase here');
app->start;