summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Quantum
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 /Bugzilla/Quantum
parent215f1021948b63cad29094e7847b52c256ec9974 (diff)
downloadbugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.gz
bugzilla-10918f3336863623020a6d73e63a0f0a5eebb306.tar.xz
mojo all the things
Diffstat (limited to 'Bugzilla/Quantum')
-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
4 files changed, 99 insertions, 27 deletions
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