diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-07-23 17:16:47 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-07-31 18:57:17 +0200 |
commit | 29c7ca6bb526ce2cc9eb99815b6fc1252b7870cf (patch) | |
tree | a9064e0a1f3fd5a8d399cf94b89701c8d99039e1 /Bugzilla | |
parent | f7c2f14988dc1638cb68f4a96cae4bc387688809 (diff) | |
download | bugzilla-29c7ca6bb526ce2cc9eb99815b6fc1252b7870cf.tar.gz bugzilla-29c7ca6bb526ce2cc9eb99815b6fc1252b7870cf.tar.xz |
some cleanups
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Quantum.pm | 169 | ||||
-rw-r--r-- | Bugzilla/Quantum/CGI.pm | 71 |
2 files changed, 58 insertions, 182 deletions
diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm index b5ee83d8e..1f6dce8da 100644 --- a/Bugzilla/Quantum.pm +++ b/Bugzilla/Quantum.pm @@ -8,22 +8,22 @@ package Bugzilla::Quantum; use Mojo::Base 'Mojolicious'; -use CGI::Compile; # Needed for its exit() overload +# Needed for its exit() overload, must happen early in execution. +use CGI::Compile; + +use Bugzilla (); +use Bugzilla::BugMail (); +use Bugzilla::CGI (); +use Bugzilla::Constants qw(bz_locations); +use Bugzilla::Extension (); +use Bugzilla::Install::Requirements (); use Bugzilla::Logging; -use Bugzilla::Quantum::Template; use Bugzilla::Quantum::CGI; use Bugzilla::Quantum::SES; use Bugzilla::Quantum::Static; - -use Bugzilla (); -use Bugzilla::Constants qw(bz_locations); -use Bugzilla::BugMail (); -use Bugzilla::CGI (); -use Bugzilla::Extension (); -use Bugzilla::Install::Requirements (); +use Bugzilla::Quantum::Template; use Bugzilla::Util (); use Cwd qw(realpath); - use MojoX::Log::Log4perl::Tiny; has 'static' => sub { Bugzilla::Quantum::Static->new }; @@ -31,7 +31,7 @@ has 'static' => sub { Bugzilla::Quantum::Static->new }; sub startup { my ($self) = @_; - DEBUG("Starting up"); + DEBUG('Starting up'); $self->plugin('Bugzilla::Quantum::Plugin::Glue'); $self->plugin('Bugzilla::Quantum::Plugin::Hostage'); $self->plugin('Bugzilla::Quantum::Plugin::BlockIP'); @@ -48,12 +48,12 @@ sub startup { my $r = $self->routes; Bugzilla::Quantum::CGI->load_all($r); - Bugzilla::Quantum::CGI->load_one('bzapi_cgi', 'extensions/BzAPI/bin/rest.cgi'); + Bugzilla::Quantum::CGI->load_one( 'bzapi_cgi', 'extensions/BzAPI/bin/rest.cgi' ); $r->any('/')->to('CGI#index_cgi'); $r->any('/rest')->to('CGI#rest_cgi'); - $r->any('/rest.cgi/*PATH_INFO')->to('CGI#rest_cgi' => { PATH_INFO => '' }); - $r->any('/rest/*PATH_INFO')->to( 'CGI#rest_cgi' => { PATH_INFO => '' }); + $r->any('/rest.cgi/*PATH_INFO')->to( 'CGI#rest_cgi' => { PATH_INFO => '' } ); + $r->any('/rest/*PATH_INFO')->to( 'CGI#rest_cgi' => { PATH_INFO => '' } ); $r->any('/bug/:id')->to('CGI#show_bug_cgi'); $r->any('/extensions/BzAPI/bin/rest.cgi/*PATH_INFO')->to('CGI#bzapi_cgi'); @@ -64,16 +64,16 @@ sub startup { }, ); - $r->get('/__heartbeat__')->to( 'CGI#heartbeat_cgi'); - $r->get('/robots.txt')->to( 'CGI#robots_cgi' ); + $r->get('/__heartbeat__')->to('CGI#heartbeat_cgi'); + $r->get('/robots.txt')->to('CGI#robots_cgi'); - $r->any('/review')->to( 'CGI#page_cgi' => {'id' => 'splinter.html'}); - $r->any('/user_profile')->to( 'CGI#page_cgi' => {'id' => 'user_profile.html'}); - $r->any('/userprofile')->to( 'CGI#page_cgi' => {'id' => 'user_profile.html'}); - $r->any('/request_defer')->to( 'CGI#page_cgi' => {'id' => 'request_defer.html'}); - $r->any('/login')->to( 'CGI#index_cgi' => { 'GoAheadAndLogIn' => '1' }); + $r->any('/review')->to( 'CGI#page_cgi' => { 'id' => 'splinter.html' } ); + $r->any('/user_profile')->to( 'CGI#page_cgi' => { 'id' => 'user_profile.html' } ); + $r->any('/userprofile')->to( 'CGI#page_cgi' => { 'id' => 'user_profile.html' } ); + $r->any('/request_defer')->to( 'CGI#page_cgi' => { 'id' => 'request_defer.html' } ); + $r->any('/login')->to( 'CGI#index_cgi' => { 'GoAheadAndLogIn' => '1' } ); - $r->any('/:new_bug' => [new_bug => qr{new[-_]bug}])->to( 'CGI#new_bug_cgi'); + $r->any( '/:new_bug' => [ new_bug => qr{new[-_]bug} ] )->to('CGI#new_bug_cgi'); my $ses_auth = $r->under( '/ses' => sub { @@ -85,130 +85,7 @@ sub startup { ); $ses_auth->any('/index.cgi')->to('SES#main'); - $r->any('/:REWRITE_itrequest' => [REWRITE_itrequest => qr{form[\.:]itrequest}])->to( - 'CGI#enter_bug_cgi' => { 'product' => 'Infrastructure & Operations', 'format' => 'itrequest' } - ); - $r->any('/:REWRITE_mozlist' => [REWRITE_mozlist => qr{form[\.:]mozlist}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'mozlist'} - ); - $r->any('/:REWRITE_poweredby' => [REWRITE_poweredby => qr{form[\.:]poweredby}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'poweredby'} - ); - $r->any('/:REWRITE_presentation' => [REWRITE_presentation => qr{form[\.:]presentation}])->to( - 'cgi#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'presentation'} - ); - $r->any('/:REWRITE_trademark' => [REWRITE_trademark => qr{form[\.:]trademark}])->to( - 'cgi#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'trademark'} - ); - $r->any('/:REWRITE_recoverykey' => [REWRITE_recoverykey => qr{form[\.:]recoverykey}])->to( - 'cgi#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'recoverykey'} - ); - $r->any('/:REWRITE_legal' => [REWRITE_legal => qr{form[\.:]legal}])->to( - 'CGI#enter_bug_cgi' => { 'product' => 'Legal', 'format' => 'legal' }, - ); - $r->any('/:REWRITE_recruiting' => [REWRITE_recruiting => qr{form[\.:]recruiting}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Recruiting', 'format' => 'recruiting'} - ); - $r->any('/:REWRITE_intern' => [REWRITE_intern => qr{form[\.:]intern}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Recruiting', 'format' => 'intern'} - ); - $r->any('/:REWRITE_mozpr' => [REWRITE_mozpr => qr{form[\.:]mozpr}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Mozilla PR', 'format' => 'mozpr' }, - ); - $r->any('/:REWRITE_reps_mentorship' => [REWRITE_reps_mentorship => qr{form[\.:]reps[\.:]mentorship}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Mozilla Reps','format' => 'mozreps' }, - ); - $r->any('/:REWRITE_reps_budget' => [REWRITE_reps_budget => qr{form[\.:]reps[\.:]budget}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Mozilla Reps','format' => 'remo-budget'} - ); - $r->any('/:REWRITE_reps_swag' => [REWRITE_reps_swag => qr{form[\.:]reps[\.:]swag}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Mozilla Reps','format' => 'remo-swag'} - ); - $r->any('/:REWRITE_reps_it' => [REWRITE_reps_it => qr{form[\.:]reps[\.:]it}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Mozilla Reps','format' => 'remo-it'} - ); - $r->any('/:REWRITE_reps_payment' => [REWRITE_reps_payment => qr{form[\.:]reps[\.:]payment}])->to( - 'CGI#page_cgi' => {'id' => 'remo-form-payment.html'} - ); - $r->any('/:REWRITE_csa_discourse' => [REWRITE_csa_discourse => qr{form[\.:]csa[\.:]discourse}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Infrastructure & Operations', 'format' => 'csa-discourse'} - ); - $r->any('/:REWRITE_employee_incident' => [REWRITE_employee_incident => qr{form[\.:]employee[\.\-:]incident}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'mozilla.org', 'format' => 'employee-incident'} - ); - $r->any('/:REWRITE_brownbag' => [REWRITE_brownbag => qr{form[\.:]brownbag}])->to( - 'CGI#https_air_mozilla_org_requests' => {} - ); - $r->any('/:REWRITE_finance' => [REWRITE_finance => qr{form[\.:]finance}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Finance','format' => 'finance'} - ); - $r->any('/:REWRITE_moz_project_review' => [REWRITE_moz_project_review => qr{form[\.:]moz[\.\-:]project[\.\-:]review}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'mozilla.org','format' => 'moz-project-review'} - ); - $r->any('/:REWRITE_docs' => [REWRITE_docs => qr{form[\.:]docs?}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Developer Documentation','format' => 'doc'} - ); - $r->any('/:REWRITE_mdn' => [REWRITE_mdn => qr{form[\.:]mdn?}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'mdn','product' => 'developer.mozilla.org'} - ); - $r->any('/:REWRITE_swag_gear' => [REWRITE_swag_gear => qr{form[\.:](swag|gear)}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'swag','product' => 'Marketing'} - ); - $r->any('/:REWRITE_costume' => [REWRITE_costume => qr{form[\.:]costume}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Marketing','format' => 'costume'} - ); - $r->any('/:REWRITE_ipp' => [REWRITE_ipp => qr{form[\.:]ipp}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Internet Public Policy','format' => 'ipp'} - ); - $r->any('/:REWRITE_creative' => [REWRITE_creative => qr{form[\.:]creative}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'creative','product' => 'Marketing'} - ); - $r->any('/:REWRITE_user_engagement' => [REWRITE_user_engagement => qr{form[\.:]user[\.\-:]engagement}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'user-engagement','product' => 'Marketing'} - ); - $r->any('/:REWRITE_dev_engagement_event' => [REWRITE_dev_engagement_event => qr{form[\.:]dev[\.\-:]engagement[\.\-\:]event}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Developer Engagement','format' => 'dev-engagement-event'} - ); - $r->any('/:REWRITE_mobile_compat' => [REWRITE_mobile_compat => qr{form[\.:]mobile[\.\-:]compat}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Tech Evangelism','format' => 'mobile-compat'} - ); - $r->any('/:REWRITE_web_bounty' => [REWRITE_web_bounty => qr{form[\.:]web[\.:]bounty}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'web-bounty','product' => 'mozilla.org'} - ); - $r->any('/:REWRITE_automative' => [REWRITE_automative => qr{form[\.:]automative}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Testing','format' => 'automative'} - ); - $r->any('/:REWRITE_comm_newsletter' => [REWRITE_comm_newsletter => qr{form[\.:]comm[\.:]newsletter}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'comm-newsletter','product' => 'Marketing'} - ); - $r->any('/:REWRITE_screen_share_whitelist' => [REWRITE_screen_share_whitelist => qr{form[\.:]screen[\.:]share[\.:]whitelist}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'screen-share-whitelist','product' => 'Firefox'} - ); - $r->any('/:REWRITE_data_compliance' => [REWRITE_data_compliance => qr{form[\.:]data[\.\-:]compliance}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Data Compliance','format' => 'data-compliance'} - ); - $r->any('/:REWRITE_fsa_budget' => [REWRITE_fsa_budget => qr{form[\.:]fsa[\.:]budget}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'FSA','format' => 'fsa-budget'} - ); - $r->any('/:REWRITE_triage_request' => [REWRITE_triage_request => qr{form[\.:]triage[\.\-]request}])->to( - 'CGI#page_cgi' => {'id' => 'triage_request.html'} - ); - $r->any('/:REWRITE_crm_CRM' => [REWRITE_crm_CRM => qr{form[\.:](crm|CRM)}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'crm','product' => 'Marketing'} - ); - $r->any('/:REWRITE_nda' => [REWRITE_nda => qr{form[\.:]nda}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Legal','format' => 'nda'} - ); - $r->any('/:REWRITE_name_clearance' => [REWRITE_name_clearance => qr{form[\.:]name[\.:]clearance}])->to( - 'CGI#enter_bug_cgi' => {'format' => 'name-clearance','product' => 'Legal'} - ); - $r->any('/:REWRITE_shield_studies' => [REWRITE_shield_studies => qr{form[\.:]shield[\.:]studies}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Shield','format' => 'shield-studies'} - ); - $r->any('/:REWRITE_client_bounty' => [REWRITE_client_bounty => qr{form[\.:]client[\.:]bounty}])->to( - 'CGI#enter_bug_cgi' => {'product' => 'Firefox','format' => 'client-bounty'} - ); - + Bugzilla::Hook::process( 'app_startup', { app => $self } ); } 1; diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm index ba09dded6..ab092140c 100644 --- a/Bugzilla/Quantum/CGI.pm +++ b/Bugzilla/Quantum/CGI.pm @@ -25,40 +25,39 @@ our $C; my %SEEN; sub load_all { - my ($class, $r) = @_; + my ( $class, $r ) = @_; - foreach my $file (glob '*.cgi') { - my $name = _file_to_method($file); - $class->load_one($name, $file); + foreach my $file ( glob '*.cgi' ) { + my $name = _file_to_method($file); + $class->load_one( $name, $file ); $r->any("/$file")->to("CGI#$name"); } } sub load_one { - my ($class, $name, $file) = @_; - my $package = __PACKAGE__ . "::$name", - my $inner_name = "_$name"; - my $content = read_text( catfile( bz_locations->{cgi_path}, $file ) ); + my ( $class, $name, $file ) = @_; + my $package = __PACKAGE__ . "::$name", my $inner_name = "_$name"; + my $content = read_text( catfile( bz_locations->{cgi_path}, $file ) ); $content = "package $package; $content"; untaint($content); my %options = ( - package => $package, - file => $file, - line => 1, + package => $package, + file => $file, + line => 1, no_defer => 1, ); die "Tried to load $file more than once" if $SEEN{$file}++; my $inner = quote_sub $inner_name, $content, {}, \%options; my $wrapper = sub { my ($c) = @_; - my $stdin = $c->_STDIN; - local $C = $c; - local %ENV = $c->_ENV($file); - local *STDIN; ## no critic (local) + my $stdin = $c->_STDIN; + local $C = $c; + local %ENV = $c->_ENV($file); local $CGI::Compile::USE_REAL_EXIT = 0; - local $PROGRAM_NAME = $file; + local $PROGRAM_NAME = $file; + local *STDIN; ## no critic (local) open STDIN, '<', $stdin->path or die "STDIN @{[$stdin->path]}: $!" if -s $stdin->path; - tie *STDOUT, 'Bugzilla::Quantum::Stdout', controller => $c; ## no critic (tie) + tie *STDOUT, 'Bugzilla::Quantum::Stdout', controller => $c; ## no critic (tie) try { Bugzilla->init_page(); $inner->(); @@ -69,23 +68,24 @@ sub load_one { finally { untie *STDOUT; $c->finish; - Bugzilla->_cleanup; ## no critic (private) + Bugzilla->cleanup; CGI::initialize_globals(); }; }; - no strict 'refs'; ## no critic (strict) - *{$name} = subname($name, $wrapper); + no strict 'refs'; ## no critic (strict) + *{$name} = subname( $name, $wrapper ); return 1; } + sub _ENV { - my ($c, $script_name) = @_; - my $tx = $c->tx; - my $req = $tx->req; - my $headers = $req->headers; + my ( $c, $script_name ) = @_; + my $tx = $c->tx; + my $req = $tx->req; + my $headers = $req->headers; my $content_length = $req->content->is_multipart ? $req->body_size : $headers->content_length; - my %env_headers = ( HTTP_COOKIE => '', HTTP_REFERER => '' ); + my %env_headers = ( HTTP_COOKIE => '', HTTP_REFERER => '' ); for my $name ( @{ $headers->names } ) { my $key = uc "http_$name"; @@ -103,13 +103,13 @@ sub _ENV { } my $path_info = $c->stash->{'mojo.captures'}{'PATH_INFO'}; my %captures = %{ $c->stash->{'mojo.captures'} // {} }; - foreach my $key (keys %captures) { - if ($key eq 'controller' || $key eq 'action' || $key eq 'PATH_INFO' || $key =~ /^REWRITE_/) { + foreach my $key ( keys %captures ) { + if ( $key eq 'controller' || $key eq 'action' || $key eq 'PATH_INFO' || $key =~ /^REWRITE_/ ) { delete $captures{$key}; } } my $cgi_query = Mojo::Parameters->new(%captures); - $cgi_query->append($req->url->query); + $cgi_query->append( $req->url->query ); my $prefix = $c->stash->{bmo_prefix} ? '/bmo/' : '/'; return ( @@ -119,17 +119,17 @@ sub _ENV { GATEWAY_INTERFACE => 'CGI/1.1', HTTPS => $req->is_secure ? 'YES' : 'NO', %env_headers, - QUERY_STRING => $cgi_query->to_string, - PATH_INFO => $path_info ? "/$path_info" : '', - REMOTE_ADDR => $tx->original_remote_address, - REMOTE_HOST => $tx->original_remote_address, - REMOTE_PORT => $tx->remote_port, - REMOTE_USER => $remote_user || '', + QUERY_STRING => $cgi_query->to_string, + PATH_INFO => $path_info ? "/$path_info" : '', + REMOTE_ADDR => $tx->original_remote_address, + REMOTE_HOST => $tx->original_remote_address, + REMOTE_PORT => $tx->remote_port, + REMOTE_USER => $remote_user || '', REQUEST_METHOD => $req->method, SCRIPT_NAME => "$prefix$script_name", SERVER_NAME => hostname, SERVER_PORT => $tx->local_port, - SERVER_PROTOCOL => $req->is_secure ? 'HTTPS' : 'HTTP', # TODO: Version is missing + SERVER_PROTOCOL => $req->is_secure ? 'HTTPS' : 'HTTP', # TODO: Version is missing SERVER_SOFTWARE => __PACKAGE__, ); } @@ -157,5 +157,4 @@ sub _file_to_method { return $name; } - 1; |