summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-05-19 06:34:01 +0200
committerDylan William Hardison <dylan@hardison.net>2018-06-28 22:41:55 +0200
commit10918f3336863623020a6d73e63a0f0a5eebb306 (patch)
treea496e36a1f149e193a4ceed41531034a6b2ae888
parent215f1021948b63cad29094e7847b52c256ec9974 (diff)
downloadbugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.gz
bugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.xz
mojo all the things
-rw-r--r--Bugzilla/CGI/Role.pm (renamed from Bugzilla/CGI/ContentSecurityPolicyAttr.pm)0
-rw-r--r--Bugzilla/Constants.pm3
-rw-r--r--Bugzilla/Error.pm2
-rw-r--r--Bugzilla/ModPerl.pm7
-rw-r--r--Bugzilla/PSGI.pm3
-rw-r--r--Bugzilla/Quantum.pm59
-rw-r--r--Bugzilla/Quantum/CGI.pm28
-rw-r--r--Bugzilla/Quantum/Legacy.pm63
-rw-r--r--Bugzilla/Quantum/Plugin/Glue.pm3
-rw-r--r--Bugzilla/Quantum/Static.pm32
-rwxr-xr-xMakefile.PL1
11 files changed, 155 insertions, 46 deletions
diff --git a/Bugzilla/CGI/ContentSecurityPolicyAttr.pm b/Bugzilla/CGI/Role.pm
index c94b3815c..c94b3815c 100644
--- a/Bugzilla/CGI/ContentSecurityPolicyAttr.pm
+++ b/Bugzilla/CGI/Role.pm
diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm
index 127f1bd58..f679fe0d2 100644
--- a/Bugzilla/Constants.pm
+++ b/Bugzilla/Constants.pm
@@ -15,6 +15,7 @@ use base qw(Exporter);
# For bz_locations
use File::Basename;
+use Cwd qw(realpath);
use Memoize;
@Bugzilla::Constants::EXPORT = qw(
@@ -651,7 +652,7 @@ sub _bz_locations {
#
# On mod_cgi this will be a relative path. On mod_perl it will be an
# absolute path.
- my $libpath = dirname(dirname($INC{'Bugzilla/Constants.pm'}));
+ my $libpath = realpath(dirname(dirname(__FILE__)));
# We have to detaint $libpath, but we can't use Bugzilla::Util here.
$libpath =~ /(.*)/;
$libpath = $1;
diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm
index 9fcd16386..bd2442410 100644
--- a/Bugzilla/Error.pm
+++ b/Bugzilla/Error.pm
@@ -128,7 +128,6 @@ sub _throw_error {
# of JSON::RPC. So, in that circumstance, instead of exiting,
# we die with no message. JSON::RPC checks raise_error before
# it checks $@, so it returns the proper error.
- die if _in_eval();
$server->response($server->error_response_header);
}
}
@@ -258,7 +257,6 @@ sub ThrowErrorPage {
message => $message,
id => $server->{_bz_request_id},
version => $server->version);
- die if _in_eval();
$server->response($server->error_response_header);
}
} else {
diff --git a/Bugzilla/ModPerl.pm b/Bugzilla/ModPerl.pm
index b4ba36934..19cd1128f 100644
--- a/Bugzilla/ModPerl.pm
+++ b/Bugzilla/ModPerl.pm
@@ -109,13 +109,6 @@ ErrorDocument 500 /errors/500.html
require valid-user
</Location>
-<Location /quantum>
- SetHandler perl-script
- PerlResponseHandler Plack::Handler::Apache2
- PerlSetEnv MOJO_HOME [% cgi_path %]
- PerlSetVar psgi_app [% cgi_path %]/scripts/bugzilla_quantum
-</Location>
-
# directory rules for all the other places we have .htaccess files
[% FOREACH htaccess IN htaccess_files %]
# from [% htaccess.file %]
diff --git a/Bugzilla/PSGI.pm b/Bugzilla/PSGI.pm
index 46352b319..e2963ff7a 100644
--- a/Bugzilla/PSGI.pm
+++ b/Bugzilla/PSGI.pm
@@ -24,6 +24,7 @@ sub compile_cgi {
my $app = CGI::Emulate::PSGI->handler(
sub {
Bugzilla::init_page();
+ $ENV{PATH_INFO} = '' if $ENV{PATH_INFO} eq '/';
$cgi->();
}
);
@@ -39,4 +40,4 @@ sub compile_cgi {
}
-1; \ No newline at end of file
+1;
diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm
index 20050131f..bb7f06b55 100644
--- a/Bugzilla/Quantum.pm
+++ b/Bugzilla/Quantum.pm
@@ -8,43 +8,86 @@
package Bugzilla::Quantum;
use Mojo::Base 'Mojolicious';
+use CGI::Compile; # Primarily for its exit overload.
use Bugzilla::Quantum::CGI;
use Bugzilla::Quantum::Template;
use Bugzilla::Quantum::Legacy;
+use Bugzilla::Quantum::Static;
use Bugzilla::PSGI qw(compile_cgi);
use Bugzilla ();
-use Bugzilla::Constants ();
+use Bugzilla::Constants qw(bz_locations);
use Bugzilla::BugMail ();
use Bugzilla::CGI ();
use Bugzilla::Extension ();
use Bugzilla::Install::Requirements ();
use Bugzilla::Util ();
use Bugzilla::RNG ();
+use Cwd qw(realpath);
+
+has 'static' => sub { Bugzilla::Quantum::Static->new };
sub startup {
my ($self) = @_;
- Bugzilla::Extension->load_all();
+ my $extensions = Bugzilla::Extension->load_all();
Bugzilla->preload_features();
Bugzilla->template;
+ my $rest = compile_cgi('rest.cgi');
$self->plugin('Bugzilla::Quantum::Plugin::Glue');
-
$self->plugin(
'MountPSGI' => {
rewrite => 1,
'/rest' => $rest,
+ }
+ );
+ $self->plugin(
+ 'MountPSGI' => {
+ rewrite => 1,
'/rest.cgi' => $rest,
- '/jsonrpc.cgi' => compile_cgi('jsonrpc.cgi'),
+ }
+ );
+ $self->plugin(
+ 'MountPSGI' => {
+ rewrite => 1,
'/xmlrpc.cgi' => compile_cgi('xmlrpc.cgi'),
}
);
+ $self->plugin(
+ 'MountPSGI' => {
+rewrite => 1,
+ '/jsonrpc.cgi' => compile_cgi('jsonrpc.cgi'),
+ }
+ );
my $r = $self->routes;
+ Bugzilla::Quantum::Legacy->expose_routes($r);
+
+ $r->any('/')->to('Legacy#index_cgi');
- $r->any( '/' )->to('legacy#index_cgi');
- $r->any( '/show_bug.cgi' )->to('legacy#show_bug');
- $r->any('/bug/:id')->to('legacy#show_bug');
+ my $urlbase = Bugzilla->localconfig->{urlbase};
+ $r->get(
+ '/quicksearch.html' => sub {
+ my $c = shift;
+ $c->res->code(301);
+ $c->redirect_to( $urlbase . 'page.cgi?id=quicksearch.html' );
+ }
+ );
+ $r->get(
+ '/bugwritinghelp.html' => sub {
+ my $c = shift;
+ $c->res->code(301);
+ $c->redirect_to( $urlbase . 'page.cgi?id=bug-writing.html', 301 );
+ }
+ );
+ $r->get(
+ '/<bug_id:num>' => sub {
+ my $c = shift;
+ $c->res->code(301);
+ my $bug_id = $c->param('bug_id');
+ $c - redirect_to( $urlbase . "show_bug.cgi?id=$bug_id" );
+ }
+ );
}
-1; \ No newline at end of file
+1;
diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm
index 34db9a46f..e5db4123f 100644
--- a/Bugzilla/Quantum/CGI.pm
+++ b/Bugzilla/Quantum/CGI.pm
@@ -63,4 +63,32 @@ sub Vars {
return $self->controller->req->query_params->to_hash;
}
+sub query_string {
+ my ($self) = @_;
+
+ return $self->controller->req->query_params->to_string;
+}
+
+sub send_cookie {
+ my ($self, %params) = @_;
+ my $name = delete $params{'-name'};
+ my $value = delete $params{'-value'} or ThrowCodeError('cookies_need_value');
+ state $uri = URI->new( Bugzilla->localconfig->{urlbase} );
+ my %attrs = (
+ path => $uri->path,
+ secure => lc( $uri->scheme ) eq 'https',
+ samesite => 'Lax',
+ );
+ my $expires = delete $params{'-expires'};
+ $attrs{expires} = $expires if $expires;
+ $attrs{httponly} = 1 if delete $params{'-httponly'};
+
+ if (keys %params) {
+ die "Unknown keys: " . join(", ", keys %params);
+ }
+
+ $self->controller->cookie($name, $value, \%params);
+}
+
1;
+
diff --git a/Bugzilla/Quantum/Legacy.pm b/Bugzilla/Quantum/Legacy.pm
index 73e877af3..d093d76a0 100644
--- a/Bugzilla/Quantum/Legacy.pm
+++ b/Bugzilla/Quantum/Legacy.pm
@@ -7,41 +7,52 @@
package Bugzilla::Quantum::Legacy;
use Mojo::Base 'Mojolicious::Controller';
+use CGI::Compile;
use File::Spec::Functions qw(catfile);
use Bugzilla::Constants qw(bz_locations);
use Taint::Util qw(untaint);
use Sub::Name qw(subname);
-use autodie;
+use File::Slurper qw(read_text);
+use Sub::Quote 2.005000;
+use Try::Tiny;
-_load_cgi(index_cgi => 'index.cgi');
-_load_cgi(show_bug => 'show_bug.cgi');
+my %CGIS;
+my %SKIP = ( 'xmlrpc.cgi' => 1, 'jsonrpc.cgi' => 1, 'rest.cgi' => 1);
-sub _load_cgi {
- my ($name, $file) = @_;
- my $content;
- {
- local $/ = undef;
- open my $fh, '<', catfile(bz_locations->{cgi_path}, $file);
- $content = <$fh>;
- untaint($content);
- close $fh;
+_load_all();
+
+sub expose_routes {
+ my ($class, $r) = @_;
+ foreach my $cgi (keys %CGIS) {
+ $r->any("/$cgi")->to("Legacy#$CGIS{$cgi}");
}
- my $pkg = __PACKAGE__ . '::' . $name;
- my @lines = (
- qq{package $pkg;},
- qq{#line 1 "$file"},
- "sub { my (\$self) = \@_; $content };"
- );
- my $code = join "\n", @lines;
- my $sub = _eval($code);
- {
- no strict 'refs'; ## no critic (strict)
- *{ $name } = subname($name, $sub);
+}
+
+sub _load_all {
+ foreach my $script (glob '*.cgi') {
+ next if $SKIP{$script};
+ my $name = _load_cgi($script);
+ $CGIS{ $script } = $name;
}
}
-sub _eval { ## no critic (unpack)
- return eval $_[0]; ## no critic (eval)
+sub _load_cgi {
+ my ($file) = @_;
+ my $name = $file;
+ $name =~ s/\./_/g;
+ $name =~ s/\W+/_/g;
+ my $content = read_text(catfile(bz_locations->{cgi_path}, $file));
+ untaint($content);
+ $content = 'my ($self) = @_; ' . $content;
+ my %options = (
+ package => __PACKAGE__ . "::$name",
+ file => $file,
+ line => 1,
+ no_defer => 1,
+ );
+ quote_sub $name, $content, {}, \%options;
+ return $name;
}
-1; \ No newline at end of file
+
+1;
diff --git a/Bugzilla/Quantum/Plugin/Glue.pm b/Bugzilla/Quantum/Plugin/Glue.pm
index d689f598a..6c20d87f7 100644
--- a/Bugzilla/Quantum/Plugin/Glue.pm
+++ b/Bugzilla/Quantum/Plugin/Glue.pm
@@ -47,12 +47,13 @@ sub register {
my ($next, $c) = @_;
try {
local %{ Bugzilla->request_cache } = ();
+ local $CGI::Compile::USE_REAL_EXIT = 0;
Bugzilla->usage_mode(USAGE_MODE_QUANTUM);
Bugzilla->cgi( Bugzilla::Quantum::CGI->new(controller => $c) );
Bugzilla->template( Bugzilla::Quantum::Template->new( controller => $c, template => $template ) );
$next->();
} catch {
- die $_ unless /\bModPerl::Util::exit\b/;
+ die $_ unless ref $_ eq 'ARRAY' && $_->[0] eq "EXIT\n" || /\bModPerl::Util::exit\b/;
};
}
);
diff --git a/Bugzilla/Quantum/Static.pm b/Bugzilla/Quantum/Static.pm
new file mode 100644
index 000000000..2a4ed1988
--- /dev/null
+++ b/Bugzilla/Quantum/Static.pm
@@ -0,0 +1,32 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Quantum::Static;
+use Mojo::Base 'Mojolicious::Static';
+use Bugzilla::Constants qw(bz_locations);
+
+my $LEGACY_RE = qr{
+ ^ (?:static/v[0-9]+\.[0-9]+/) ?
+ ( (?:extensions/[^/]+/web|(?:image|skin|j)s)/.+)
+ $
+}xs;
+
+sub file {
+ my ($self, $rel) = @_;
+
+ if (my ($legacy_rel) = $rel =~ $LEGACY_RE) {
+ local $self->{paths} = [ bz_locations->{cgi_path} ];
+ warn "legacy $legacy_rel\n";
+ return $self->SUPER::file($legacy_rel);
+ }
+ else {
+ warn "legacy $rel\n";
+ return $self->SUPER::file($rel);
+ }
+}
+
+1; \ No newline at end of file
diff --git a/Makefile.PL b/Makefile.PL
index 5c3e9257c..f173d68fe 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -79,6 +79,7 @@ my %requires = (
'Template' => '2.24',
'Text::CSV_XS' => '1.26',
'Throwable' => '0.200013',
+ 'Sub::Quote' => '2.005000',
'Type::Tiny' => '1.000005',
'URI' => '1.55',
'URI::Escape::XS' => '0.14',