1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/copyleft/gpl.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
48 package RT::Interface::Web::Handler;
50 use CGI qw/-private_tempfiles/;
58 use RT::Interface::Web::Handler;
59 use File::Path qw( rmtree );
60 use File::Glob qw( bsd_glob );
63 sub DefaultHandlerArgs { (
65 [ local => $RT::MasonLocalComponentRoot ],
66 [ standard => $RT::MasonComponentRoot ]
68 default_escape_flags => 'h',
69 data_dir => "$RT::MasonDataDir",
70 allow_globals => [qw(%session)],
71 # Turn off static source if we're in developer mode.
72 static_source => ($RT::DevelMode ? '0' : '1'),
73 use_object_files => ($RT::DevelMode ? '0' : '1'),
81 Constructs a web handler of the appropriate class.
82 Takes options to pass to the constructor.
88 $class->InitSessionDir;
90 if ( $mod_perl::VERSION && $mod_perl::VERSION >= 1.9908 ) {
91 goto &NewApacheHandler;
93 elsif ($CGI::MOD_PERL) {
94 goto &NewApacheHandler;
102 # Activate the following if running httpd as root (the normal case).
103 # Resets ownership of all files created by Mason at startup.
104 # Note that mysql uses DB for sessions, so there's no need to do this.
105 unless ( $RT::DatabaseType =~ /(?:mysql|Pg)/ ) {
107 # Clean up our umask to protect session files
110 if ($CGI::MOD_PERL) { local $@; eval {
112 chown( Apache->server->uid, Apache->server->gid,
113 $RT::MasonSessionDir )
116 # Die if WebSessionDir doesn't exist or we can't write to it
117 stat($RT::MasonSessionDir);
118 die "Can't read and write $RT::MasonSessionDir"
119 unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
126 # {{{ sub NewApacheHandler
128 =head2 NewApacheHandler
130 Takes extra options to pass to HTML::Mason::ApacheHandler->new
131 Returns a new Mason::ApacheHandler object
135 sub NewApacheHandler {
136 require HTML::Mason::ApacheHandler;
137 return NewHandler('HTML::Mason::ApacheHandler', args_method => "CGI", @_);
142 # {{{ sub NewApache2Handler
144 =head2 NewApache2Handler
146 Takes extra options to pass to MasonX::Apache2Handler->new
147 Returns a new MasonX::Apache2Handler object
151 sub NewApache2Handler {
152 require MasonX::Apache2Handler;
153 return NewHandler('MasonX::Apache2Handler', args_method => "CGI", @_);
158 # {{{ sub NewCGIHandler
162 Returns a new Mason::CGIHandler object
167 require HTML::Mason::CGIHandler;
168 return NewHandler('HTML::Mason::CGIHandler', @_);
173 my $handler = $class->new(
174 DefaultHandlerArgs(),
178 $handler->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
179 $handler->interp->set_escape( u => \&RT::Interface::Web::EscapeURI );
183 =head2 CleanupRequest
185 Rollback any uncommitted transaction.
187 Flush the searchbuilder query cache
193 if ( $RT::Handle->TransactionDepth ) {
194 $RT::Handle->ForceRollback;
196 "Transaction not committed. Usually indicates a software fault."
197 . "Data loss may have occurred" );
200 # Clean out the ACL cache. the performance impact should be marginal.
201 # Consistency is imprived, too.
202 RT::Principal->InvalidateACLCache();
203 DBIx::SearchBuilder::Record::Cachable->FlushCache
204 if ( $RT::WebFlushDbCacheEveryRequest
206 'DBIx::SearchBuilder::Record::Cachable' => 'FlushCache' ) );