-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsgi.patch
799 lines (761 loc) · 28.9 KB
/
psgi.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
diff -ruN bugzilla-4.0.2/.backup~/app.psgi~ bugzilla-patched/.backup~/app.psgi~
--- bugzilla-4.0.2/.backup~/app.psgi~ 1969-12-31 16:00:00.000000000 -0800
+++ bugzilla-patched/.backup~/app.psgi~ 2011-11-21 11:48:46.000000000 -0800
@@ -0,0 +1,87 @@
+#!/usr/bin/env plackup
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+# vim: set filetype=perl expandtab tabstop=4 shiftwidth=4:
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Hans Dieter Pearcey.
+# Portions created by the Initial Developer are Copyright (C) 2010 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Hans Dieter Pearcey <[email protected]>
+# Max Kanat-Alexander <[email protected]>
+
+use strict;
+use warnings;
+use File::Basename;
+use lib dirname(__FILE__);
+use Bugzilla::Constants ();
+use lib Bugzilla::Constants::bz_locations()->{'ext_libpath'};
+
+# This is an array of regular expressions describing paths that
+# can be served statically by plackup if it is asked to do so.
+use constant ALLOWED_STATIC => qw(
+ docs
+ extensions/[^/]+/web
+ graphs
+ images
+ js
+ skins
+);
+
+# All Plack modules must be loaded before any Bugzilla modules,
+# in case they want to override built-in Perl functions.
+# For example, WrapCGI loads CGI::Compile, which overrides
+# "exit", and Bugzilla won't work properly unless exit has
+# already been overridden.
+#
+# Bugzilla::Constants doesn't call "exit", so it can safely
+# be loaded above.
+use Plack;
+use Plack::Builder;
+use Plack::App::WrapCGI;
+use Plack::App::URLMap;
+
+use Bugzilla::Install::Requirements qw(compilable_cgis);
+
+BEGIN { $ENV{PLACK_VERSION} = 'Plack/' . Plack->VERSION; }
+
+builder {
+ my $cgi_path = Bugzilla::Constants::bz_locations->{'cgi_path'};
+
+ my $static_paths = join('|', ALLOWED_STATIC);
+ enable 'Static',
+ path => qr{.*/($static_paths)/},
+ root => $cgi_path;
+
+ my $map = Plack::App::URLMap->new;
+ no warnings 'redefine';
+ local *lib::import = sub {};
+ use warnings;
+ foreach my $cgi (compilable_cgis()) {
+ my $base_name = basename($cgi);
+ my $app = Plack::App::WrapCGI->new(script => $cgi)->to_app;
+ my $wrapped = sub {
+ # These CGI variables aren't correct sometimes, unless
+ # we fix them here.
+ Bugzilla::init_page();
+ my $res = $app->(@_);
+ Bugzilla::_cleanup();
+ return $res;
+ };
+ $map->mount('/' => $wrapped) if $base_name eq 'index.cgi';
+ $map->mount("/$base_name" => $wrapped);
+ }
+ $map->to_app;
+};
diff -ruN bugzilla-4.0.2/.htaccess bugzilla-patched/.htaccess
--- bugzilla-4.0.2/.htaccess 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/.htaccess 2011-11-21 11:48:46.000000000 -0800
@@ -1,7 +1,10 @@
# Don't allow people to retrieve non-cgi executable files or our private data
-<FilesMatch ^(.*\.pm|.*\.pl|.*localconfig.*)$>
+<FilesMatch ^(.*\.pm|.*\.pl|.*\.psgi|.*localconfig.*)$>
deny from all
</FilesMatch>
+<Files 'fastcgi.pl'>
+ allow from all
+</Files>
<IfModule mod_expires.c>
<IfModule mod_headers.c>
<IfModule mod_env.c>
diff -ruN bugzilla-4.0.2/Bugzilla/Config.pm bugzilla-patched/Bugzilla/Config.pm
--- bugzilla-4.0.2/Bugzilla/Config.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Config.pm 2011-11-21 11:48:46.000000000 -0800
@@ -36,6 +36,7 @@
use Bugzilla::Constants;
use Bugzilla::Hook;
use Bugzilla::Install::Filesystem qw(fix_file_permissions);
+use Bugzilla::Install::Util qw(i_am_cgi i_am_persistent);
use Data::Dumper;
use File::Temp;
@@ -326,14 +327,17 @@
# Now read the param back out from the sandbox
%params = %{$s->varglob('param')};
}
- elsif ($ENV{'SERVER_SOFTWARE'}) {
- # We're in a CGI, but the params file doesn't exist. We can't
+ elsif (i_am_cgi()) {
+ # We're in a CGI, but the params file doesn't exist. We can't use
# Template Toolkit, or even install_string, since checksetup
- # might not have thrown an error. Bugzilla::CGI->new
+ # might not have set those up yet. Bugzilla::CGI->new
# hasn't even been called yet, so we manually use CGI::Carp here
- # so that the user sees the error.
- require CGI::Carp;
- CGI::Carp->import('fatalsToBrowser');
+ # so that the user sees the error, except under mod_perl and Plack,
+ # which don't support CGI::Carp.
+ if (!i_am_persistent()) {
+ require CGI::Carp;
+ CGI::Carp->import('fatalsToBrowser');
+ }
die "The $datadir/params file does not exist."
. ' You probably need to run checksetup.pl.',
}
diff -ruN bugzilla-4.0.2/Bugzilla/Error.pm bugzilla-patched/Bugzilla/Error.pm
--- bugzilla-4.0.2/Bugzilla/Error.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Error.pm 2011-11-21 11:48:46.000000000 -0800
@@ -37,14 +37,17 @@
use Date::Format;
# We cannot use $^S to detect if we are in an eval(), because mod_perl
-# already eval'uates everything, so $^S = 1 in all cases under mod_perl!
+# and Plack already eval'uate everything, so $^S = 1 always under those!
sub _in_eval {
- my $in_eval = 0;
for (my $stack = 1; my $sub = (caller($stack))[3]; $stack++) {
- last if $sub =~ /^ModPerl/;
- $in_eval = 1 if $sub =~ /^\(eval\)/;
+ last if $sub =~ /^(?:ModPerl|Plack|CGI::Compile)/;
+ return 1 if $sub =~ /^\(eval\)/
+ # If the very next stack item is CGI::Compile, then
+ # we're not in a real eval, we're in CGI::Compile's
+ # top-level eval while running under Plack.
+ && (caller($stack + 1))[3] !~ /^CGI::Compile/;
}
- return $in_eval;
+ return 0;
}
sub _throw_error {
diff -ruN bugzilla-4.0.2/Bugzilla/Install/Filesystem.pm bugzilla-patched/Bugzilla/Install/Filesystem.pm
--- bugzilla-4.0.2/Bugzilla/Install/Filesystem.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Install/Filesystem.pm 2011-11-21 11:48:46.000000000 -0800
@@ -153,6 +153,8 @@
'whine.pl' => { perms => WS_EXECUTE },
'email_in.pl' => { perms => WS_EXECUTE },
'sanitycheck.pl' => { perms => WS_EXECUTE },
+ 'fastcgi.pl' => { perms => WS_EXECUTE },
+ 'app.psgi' => { perms => OWNER_EXECUTE | WS_SERVE },
'checksetup.pl' => { perms => OWNER_EXECUTE },
'runtests.pl' => { perms => OWNER_EXECUTE },
'jobqueue.pl' => { perms => OWNER_EXECUTE },
diff -ruN bugzilla-4.0.2/Bugzilla/Install/Requirements.pm bugzilla-patched/Bugzilla/Install/Requirements.pm
--- bugzilla-4.0.2/Bugzilla/Install/Requirements.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Install/Requirements.pm 2011-11-21 11:48:46.000000000 -0800
@@ -42,7 +42,11 @@
check_graphviz
have_vers
install_command
- map_files_to_features
+);
+
+our @EXPORT_OK = qw(
+ compilable_cgis
+ feature_available
);
# This is how many *'s are in the top of each "box" message printed
@@ -312,6 +316,13 @@
feature => ['jobqueue'],
},
+ {
+ package => 'Plack',
+ module => 'Plack',
+ version => 0,
+ feature => ['fastcgi'],
+ },
+
# mod_perl
{
package => 'mod_perl',
@@ -354,6 +365,7 @@
# This maps features to the files that require that feature in order
# to compile. It is used by t/001compile.t and mod_perl.pl.
use constant FEATURE_FILES => (
+ fastcgi => ['app.psgi'],
jsonrpc => ['Bugzilla/WebService/Server/JSONRPC.pm', 'jsonrpc.cgi'],
xmlrpc => ['Bugzilla/WebService/Server/XMLRPC.pm', 'xmlrpc.cgi',
'Bugzilla/WebService.pm', 'Bugzilla/WebService/*.pm'],
@@ -739,7 +751,69 @@
return sprintf $command, $package;
}
-# This does a reverse mapping for FEATURE_FILES.
+######################################
+# Functions Related to FEATURE_FILES #
+######################################
+
+# Used by mod_perl and FastCGI to know which CGI scripts
+# can be compiled, based on which features are available.
+sub compilable_cgis {
+ my $cgi_path = bz_locations()->{'cgi_path'};
+ my $feature_files = map_files_to_features();
+
+ my @compilable;
+ foreach my $file (glob "$cgi_path/*.cgi") {
+ my $base_filename = File::Basename::basename($file);
+ if (my $feature = $feature_files->{$base_filename}) {
+ next if !feature_available($feature);
+ }
+ push(@compilable, $file);
+ }
+
+ return @compilable;
+}
+
+sub _feature_requirements {
+ my %feature_map;
+ my $optional_modules = OPTIONAL_MODULES;
+ foreach my $package (@$optional_modules) {
+ foreach my $feature (@{ $package->{feature} }) {
+ $feature_map{$feature} ||= [];
+ push(@{ $feature_map{$feature} }, $package->{module});
+ }
+ }
+ return \%feature_map;
+}
+
+sub feature_available {
+ my ($feature) = @_;
+
+ my $cache = Bugzilla::Install::Util::_cache();
+ return $cache->{feature}->{$feature}
+ if exists $cache->{feature}->{$feature};
+
+ $cache->{feature_map} ||= _feature_requirements();
+ my $feature_map = $cache->{feature_map};
+
+ if (!$feature_map->{$feature}) {
+ die install_string('invalid_feature', { feature => $feature });
+ }
+
+ my $success = 1;
+ foreach my $module (@{ $feature_map->{$feature} }) {
+ # We can't use a string eval and "use" here (it kills Template-Toolkit,
+ # see https://rt.cpan.org/Public/Bug/Display.html?id=47929), so we have
+ # to do a block eval.
+ $module =~ s{::}{/}g;
+ $module .= ".pm";
+ eval { require $module; 1; } or $success = 0;
+ }
+ $cache->{feature}->{$feature} = $success;
+ return $success;
+}
+
+# This says which files are associated with which features.
+# Basically, it returns a reverse mapping of FEATURE_FILES.
sub map_files_to_features {
my %features = FEATURE_FILES;
my %files;
diff -ruN bugzilla-4.0.2/Bugzilla/Install/Util.pm bugzilla-patched/Bugzilla/Install/Util.pm
--- bugzilla-4.0.2/Bugzilla/Install/Util.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Install/Util.pm 2011-11-21 11:53:44.000000000 -0800
@@ -46,12 +46,16 @@
extension_package_directory
extension_requirement_packages
extension_template_directory
+ i_am_cgi
+ i_am_persistent
indicate_progress
install_string
include_languages
template_include_path
vers_cmp
init_console
+ trick_taint
+ trim
);
sub bin_loc {
@@ -301,8 +305,7 @@
sub _wanted_languages {
my ($requested, @wanted);
- # Checking SERVER_SOFTWARE is the same as i_am_cgi() in Bugzilla::Util.
- if (exists $ENV{'SERVER_SOFTWARE'}) {
+ if (i_am_cgi()) {
my $cgi = Bugzilla->cgi;
$requested = $cgi->http('Accept-Language') || '';
my $lang = $cgi->cookie('LANG');
@@ -672,9 +675,28 @@
return $_cache;
}
-###############################
-# Copied from Bugzilla::Util #
-##############################
+#############################################
+# Documented and Exported in Bugzilla::Util #
+#############################################
+
+# These are functions that are used everywhere in Bugzilla, but are
+# needed during times when we can't load Bugzilla::Util. Bugzilla::Util
+# imports them from here and then re-exports them, so you can get them
+# from here or from there.
+
+sub i_am_cgi {
+ # I use SERVER_SOFTWARE because it's required to be defined for all
+ # requests in the CGI spec.
+ #
+ # Also, under mod_perl and FastCGI, when we are compiling the CGIs,
+ # SERVER_SOFTWARE many not be defined, but we still need to act like
+ # we are in a webserver environment.
+ return (exists $ENV{'SERVER_SOFTWARE'} or i_am_persistent()) ? 1 : 0;
+}
+
+sub i_am_persistent {
+ return $ENV{MOD_PERL} || $ENV{PLACK_VERSION};
+}
sub trick_taint {
require Carp;
diff -ruN bugzilla-4.0.2/Bugzilla/Template.pm bugzilla-patched/Bugzilla/Template.pm
--- bugzilla-4.0.2/Bugzilla/Template.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Template.pm 2011-11-21 11:48:46.000000000 -0800
@@ -587,13 +587,13 @@
PRE_CHOMP => 1,
TRIM => 1,
- # Bugzilla::Template::Plugin::Hook uses the absolute (in mod_perl)
- # or relative (in mod_cgi) paths of hook files to explicitly compile
- # a specific file. Also, these paths may be absolute at any time
- # if a packager has modified bz_locations() to contain absolute
- # paths.
+ # Bugzilla::Template::Plugin::Hook uses the absolute
+ # (in mod_perl/FastCGI) or relative (in mod_cgi) paths of hook files to
+ # explicitly compile a specific file. Also, these paths may be absolute
+ # at any time if a packager has modified bz_locations() to contain
+ # absolute paths.
ABSOLUTE => 1,
- RELATIVE => $ENV{MOD_PERL} ? 0 : 1,
+ RELATIVE => i_am_persistent() ? 0 : 1,
COMPILE_DIR => bz_locations()->{'datadir'} . "/template",
diff -ruN bugzilla-4.0.2/Bugzilla/Util.pm bugzilla-patched/Bugzilla/Util.pm
--- bugzilla-4.0.2/Bugzilla/Util.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla/Util.pm 2011-11-21 11:48:46.000000000 -0800
@@ -35,7 +35,7 @@
detaint_signed
html_quote url_quote xml_quote
css_class_quote html_light_quote url_decode
- i_am_cgi correct_urlbase remote_ip
+ i_am_cgi i_am_persistent correct_urlbase remote_ip
do_ssl_redirect_if_required use_attachbase
diff_arrays on_main_db
trim wrap_hard wrap_comment find_wrap_point
@@ -47,6 +47,11 @@
get_text template_var disable_utf8);
use Bugzilla::Constants;
+# We import these so that we can re-export them again, because historically
+# many modules imported these from Bugzilla::Util. However, they are
+# in Bugzilla::Install::Util because they are needed during times when
+# we can't load Bugzilla::Util.
+use Bugzilla::Install::Util qw(i_am_cgi i_am_persistent trick_taint trim);
use Date::Parse;
use Date::Format;
@@ -59,14 +64,6 @@
use Template::Filters;
use Text::Wrap;
-sub trick_taint {
- require Carp;
- Carp::confess("Undef to trick_taint") unless defined $_[0];
- my $match = $_[0] =~ /^(.*)$/s;
- $_[0] = $match ? $1 : undef;
- return (defined($_[0]));
-}
-
sub detaint_natural {
my $match = $_[0] =~ /^(\d+)$/;
$_[0] = $match ? int($1) : undef;
@@ -248,12 +245,6 @@
return $todecode;
}
-sub i_am_cgi {
- # I use SERVER_SOFTWARE because it's required to be
- # defined for all requests in the CGI spec.
- return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
-}
-
# This exists as a separate function from Bugzilla::CGI::redirect_to_https
# because we don't want to create a CGI object during XML-RPC calls
# (doing so can mess up XML-RPC).
@@ -326,15 +317,6 @@
return (\@removed, \@added);
}
-sub trim {
- my ($str) = @_;
- if ($str) {
- $str =~ s/^\s+//g;
- $str =~ s/\s+$//g;
- }
- return $str;
-}
-
sub wrap_comment {
my ($comment, $cols) = @_;
my $wrappedcomment = "";
@@ -731,6 +713,7 @@
# Functions that tell you about your environment
my $is_cgi = i_am_cgi();
my $urlbase = correct_urlbase();
+ my $is_mod_perl_or_fastcgi = i_am_persistent();
# Data manipulation
($removed, $added) = diff_arrays(\@old, \@new);
@@ -863,6 +846,10 @@
server. For example, it would return false if the caller is running
in a command-line script.
+=item C<i_am_persistent>
+
+Returns a true value if you are running under mod_perl or FastCGI.
+
=item C<correct_urlbase()>
Returns either the C<sslbase> or C<urlbase> parameter, depending on the
diff -ruN bugzilla-4.0.2/Bugzilla.pm bugzilla-patched/Bugzilla.pm
--- bugzilla-4.0.2/Bugzilla.pm 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/Bugzilla.pm 2011-11-21 11:48:46.000000000 -0800
@@ -26,10 +26,16 @@
use strict;
-# We want any compile errors to get to the browser, if possible.
BEGIN {
- # This makes sure we're in a CGI.
- if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL}) {
+ # We want any compile errors to get to the browser, if possible.
+ # This only affects mod_cgi, though--it doesn't work under mod_perl,
+ # and under Plack we have different ways of accomplishing this.
+ #
+ # Checking these ENV variables is like calling
+ # i_am_cgi() && !i_am_persistent(), but we can't use those here yet,
+ # because we want to even catch errors in compiling
+ # Bugzilla::Install::Util.
+ if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL} && !$ENV{PLACK_VERSION}) {
require CGI::Carp;
CGI::Carp->import('fatalsToBrowser');
}
@@ -43,7 +49,7 @@
use Bugzilla::Extension;
use Bugzilla::DB;
use Bugzilla::Install::Localconfig qw(read_localconfig);
-use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES);
+use Bugzilla::Install::Requirements qw(feature_available);
use Bugzilla::Install::Util qw(init_console);
use Bugzilla::Template;
use Bugzilla::User;
@@ -199,6 +205,8 @@
return $class->request_cache->{"template_inner_$lang"};
}
+# Also see the bottom of this file, where extension packages are
+# pre-loaded in persistent environments.
our $extension_packages;
sub extensions {
my ($class) = @_;
@@ -222,36 +230,7 @@
sub feature {
my ($class, $feature) = @_;
- my $cache = $class->request_cache;
- return $cache->{feature}->{$feature}
- if exists $cache->{feature}->{$feature};
-
- my $feature_map = $cache->{feature_map};
- if (!$feature_map) {
- foreach my $package (@{ OPTIONAL_MODULES() }) {
- foreach my $f (@{ $package->{feature} }) {
- $feature_map->{$f} ||= [];
- push(@{ $feature_map->{$f} }, $package->{module});
- }
- }
- $cache->{feature_map} = $feature_map;
- }
-
- if (!$feature_map->{$feature}) {
- ThrowCodeError('invalid_feature', { feature => $feature });
- }
-
- my $success = 1;
- foreach my $module (@{ $feature_map->{$feature} }) {
- # We can't use a string eval and "use" here (it kills Template-Toolkit,
- # see https://rt.cpan.org/Public/Bug/Display.html?id=47929), so we have
- # to do a block eval.
- $module =~ s{::}{/}g;
- $module .= ".pm";
- eval { require $module; 1; } or $success = 0;
- }
- $cache->{feature}->{$feature} = $success;
- return $success;
+ return feature_available($feature);
}
sub cgi {
@@ -606,15 +585,27 @@
$dbh->bz_rollback_transaction() if $dbh->bz_in_transaction;
$dbh->disconnect;
}
- undef $_request_cache;
+ # We set this to an empty hashref instead of undefining it because
+ # this allows FastCGI to use it again for the next request.
+ $Bugzilla::Install::Util::_cache = {};
+ $_request_cache = $Bugzilla::Install::Util::_cache;
}
sub END {
- # Bugzilla.pm cannot compile in mod_perl.pl if this runs.
- _cleanup() unless $ENV{MOD_PERL};
+ # FastCGI and mod_perl both run this themselves.
+ _cleanup() unless i_am_persistent();
}
-init_page() if !$ENV{MOD_PERL};
+if (i_am_persistent()) {
+ # If we are running under mod_perl or FastCGI, preload all the
+ # Extension packages. This has to be done down here so that
+ # $_request_cache is initialized (and any other default values
+ # are set up).
+ $extension_packages = Bugzilla::Extension->load_all() if i_am_persistent();
+}
+else {
+ init_page();
+}
1;
diff -ruN bugzilla-4.0.2/app.psgi bugzilla-patched/app.psgi
--- bugzilla-4.0.2/app.psgi 1969-12-31 16:00:00.000000000 -0800
+++ bugzilla-patched/app.psgi 2011-11-21 12:42:43.000000000 -0800
@@ -0,0 +1,89 @@
+#!/usr/bin/env plackup
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+# vim: set filetype=perl expandtab tabstop=4 shiftwidth=4:
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Hans Dieter Pearcey.
+# Portions created by the Initial Developer are Copyright (C) 2010 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Hans Dieter Pearcey <[email protected]>
+# Max Kanat-Alexander <[email protected]>
+
+use strict;
+use warnings;
+use File::Basename;
+use lib dirname(__FILE__);
+use Bugzilla::Constants ();
+use lib Bugzilla::Constants::bz_locations()->{'ext_libpath'};
+
+# This is an array of regular expressions describing paths that
+# can be served statically by plackup if it is asked to do so.
+use constant ALLOWED_STATIC => qw(
+ docs
+ extensions/[^/]+/web
+ graphs
+ images
+ js
+ skins
+);
+
+# All Plack modules must be loaded before any Bugzilla modules,
+# in case they want to override built-in Perl functions.
+# For example, WrapCGI loads CGI::Compile, which overrides
+# "exit", and Bugzilla won't work properly unless exit has
+# already been overridden.
+#
+# Bugzilla::Constants doesn't call "exit", so it can safely
+# be loaded above.
+use Plack;
+use Plack::Builder;
+use Plack::App::WrapCGI;
+use Plack::App::URLMap;
+
+use Bugzilla::Install::Requirements qw(compilable_cgis);
+
+BEGIN { $ENV{PLACK_VERSION} = 'Plack/' . Plack->VERSION; }
+
+builder {
+ enable 'Plack::Middleware::ContentLength';
+
+ my $cgi_path = Bugzilla::Constants::bz_locations->{'cgi_path'};
+
+ my $static_paths = join('|', ALLOWED_STATIC);
+ enable 'Static',
+ path => qr{.*/($static_paths)/},
+ root => $cgi_path;
+
+ my $map = Plack::App::URLMap->new;
+ no warnings 'redefine';
+ local *lib::import = sub {};
+ use warnings;
+ foreach my $cgi (compilable_cgis()) {
+ my $base_name = basename($cgi);
+ my $app = Plack::App::WrapCGI->new(script => $cgi)->to_app;
+ my $wrapped = sub {
+ # These CGI variables aren't correct sometimes, unless
+ # we fix them here.
+ Bugzilla::init_page();
+ my $res = $app->(@_);
+ Bugzilla::_cleanup();
+ return $res;
+ };
+ $map->mount('/' => $wrapped) if $base_name eq 'index.cgi';
+ $map->mount("/$base_name" => $wrapped);
+ }
+ $map->to_app;
+};
diff -ruN bugzilla-4.0.2/checksetup.pl bugzilla-patched/checksetup.pl
--- bugzilla-4.0.2/checksetup.pl 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/checksetup.pl 2011-11-21 12:00:23.000000000 -0800
@@ -53,7 +53,7 @@
use lib qw(. lib);
use Bugzilla::Constants;
use Bugzilla::Install::Requirements;
-use Bugzilla::Install::Util qw(install_string get_version_and_os init_console);
+use Bugzilla::Install::Util qw(install_string get_version_and_os init_console i_am_cgi);
######################################################################
# Live Code
diff -ruN bugzilla-4.0.2/fastcgi.pl bugzilla-patched/fastcgi.pl
--- bugzilla-4.0.2/fastcgi.pl 1969-12-31 16:00:00.000000000 -0800
+++ bugzilla-patched/fastcgi.pl 2011-11-21 11:48:46.000000000 -0800
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use File::Basename;
+use lib dirname(__FILE__);
+use Bugzilla::Constants;
+my $cgi_dir = bz_locations()->{'cgi_path'};
+
+my @args = @ARGV;
+if ($ENV{PLACK_ENV} and $ENV{PLACK_ENV} eq 'development') {
+ # XXX Plack daemonizes when you add this argument, which
+ # doesn't work under mod_fcgid
+ # push(@args, '-R', "$cgi_dir,$cgi_dir/Bugzilla,$lib_dir");
+}
+else {
+ push(@args, '--env=deployment');
+}
+
+my $psgi = "$cgi_dir/app.psgi";
+exec('plackup', '--server=FCGI', '--host=localhost', @args, $psgi)
+ or die "Couldn't exec $psgi: $!";
diff -ruN bugzilla-4.0.2/install-module.pl bugzilla-patched/install-module.pl
--- bugzilla-4.0.2/install-module.pl 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/install-module.pl 2011-11-21 11:48:46.000000000 -0800
@@ -99,6 +99,9 @@
# --all shouldn't include mod_perl2, because it can have some complex
# configuration, and really should be installed on its own.
next if $cpan_name eq 'mod_perl2';
+ # For working FastCGI support, we need the "plackup" binary
+ # installed somewhere in the system path.
+ next if $cpan_name eq 'Plack';
next if $cpan_name eq 'DBD::Oracle' and !$ENV{ORACLE_HOME};
next if $cpan_name eq 'DBD::Pg' and !bin_loc('pg_config');
install_module($cpan_name);
diff -ruN bugzilla-4.0.2/mod_perl.pl bugzilla-patched/mod_perl.pl
--- bugzilla-4.0.2/mod_perl.pl 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/mod_perl.pl 2011-11-21 11:48:46.000000000 -0800
@@ -88,15 +88,11 @@
$server->add_config([split("\n", $conf)]);
-# Pre-load all extensions
-$Bugzilla::extension_packages = Bugzilla::Extension->load_all();
-
# Have ModPerl::RegistryLoader pre-compile all CGI scripts.
my $rl = new ModPerl::RegistryLoader();
# If we try to do this in "new" it fails because it looks for a
# Bugzilla/ModPerl/ResponseHandler.pm
$rl->{package} = 'Bugzilla::ModPerl::ResponseHandler';
-my $feature_files = Bugzilla::Install::Requirements::map_files_to_features();
# Prevent "use lib" from doing anything when the .cgi files are compiled.
# This is important to prevent the current directory from getting into
@@ -105,11 +101,7 @@
local *lib::import = sub {};
use warnings;
-foreach my $file (glob "$cgi_path/*.cgi") {
- my $base_filename = File::Basename::basename($file);
- if (my $feature = $feature_files->{$base_filename}) {
- next if !Bugzilla->feature($feature);
- }
+foreach my $file (compilable_cgis()) {
Bugzilla::Util::trick_taint($file);
$rl->handler($file, $file);
}
diff -ruN bugzilla-4.0.2/template/en/default/global/code-error.html.tmpl bugzilla-patched/template/en/default/global/code-error.html.tmpl
--- bugzilla-4.0.2/template/en/default/global/code-error.html.tmpl 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/template/en/default/global/code-error.html.tmpl 2011-11-21 11:48:46.000000000 -0800
@@ -223,12 +223,6 @@
[% title = "Invalid Dimensions" %]
The width or height specified is not a positive integer.
- [% ELSIF error == "invalid_feature" %]
- [% title = "Invalid Feature Name" %]
- [% feature FILTER html %] is not a valid feature name. See
- <code>OPTIONAL_MODULES</code> in
- <code>Bugzilla::Install::Requirements</code> for valid names.
-
[% ELSIF error == "invalid_flag_association" %]
[% title = "Invalid Flag Association" %]
Some flags do not belong to
diff -ruN bugzilla-4.0.2/template/en/default/setup/strings.txt.pl bugzilla-patched/template/en/default/setup/strings.txt.pl
--- bugzilla-4.0.2/template/en/default/setup/strings.txt.pl 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/template/en/default/setup/strings.txt.pl 2011-11-21 12:00:01.000000000 -0800
@@ -57,6 +57,7 @@
END
feature_auth_ldap => 'LDAP Authentication',
feature_auth_radius => 'RADIUS Authentication',
+ feature_fastcgi => 'FastCGI Support',
feature_graphical_reports => 'Graphical Reports',
feature_html_desc => 'More HTML in Product/Group Descriptions',
feature_inbound_email => 'Inbound Email',
@@ -94,6 +95,10 @@
EOT
install_module => 'Installing ##module## version ##version##...',
installation_failed => '*** Installation aborted. Read the messages above. ***',
+ invalid_feature => <<'END',
+'##feature##' is not a valid feature name. See OPTIONAL_MODULES in
+Bugzilla::Install::Requirements for valid names.
+END
max_allowed_packet => <<EOT,
WARNING: You need to set the max_allowed_packet parameter in your MySQL
configuration to at least ##needed##. Currently it is set to ##current##.
diff -ruN bugzilla-4.0.2/testagent.cgi bugzilla-patched/testagent.cgi
--- bugzilla-4.0.2/testagent.cgi 2011-08-04 19:25:35.000000000 -0700
+++ bugzilla-patched/testagent.cgi 2011-11-21 11:48:46.000000000 -0800
@@ -19,6 +19,10 @@
use strict;
print "content-type:text/plain\n\n";
-print "OK " . ($::ENV{MOD_PERL} || "mod_cgi") . "\n";
+print "OK";
+my @info = ($ENV{MOD_PERL}, $ENV{PLACK_VERSION});
+@info = grep { defined($_) } @info;
+my $info_string = join(' ', @info) || 'mod_cgi';
+print ' ', $info_string, "\n";
exit;