1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # CONTRIBUTION SUBMISSION POLICY:
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
45 # END BPS TAGGED BLOCK }}}
47 package RT::Interface::Web::Handler;
49 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 # require Apache::RequestUtil;
92 # no warnings 'redefine';
93 # my $sub = *Apache::request{CODE};
94 # *Apache::request = sub {
96 # eval { $r = $sub->('Apache'); };
101 goto &NewApacheHandler;
103 elsif ($CGI::MOD_PERL) {
104 goto &NewApacheHandler;
112 # Activate the following if running httpd as root (the normal case).
113 # Resets ownership of all files created by Mason at startup.
114 # Note that mysql uses DB for sessions, so there's no need to do this.
115 unless ( $RT::DatabaseType =~ /(?:mysql|Pg)/ ) {
117 # Clean up our umask to protect session files
120 if ($CGI::MOD_PERL) {
121 chown( Apache->server->uid, Apache->server->gid,
122 $RT::MasonSessionDir )
123 if Apache->server->can('uid');
126 # Die if WebSessionDir doesn't exist or we can't write to it
127 stat($RT::MasonSessionDir);
128 die "Can't read and write $RT::MasonSessionDir"
129 unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
136 # {{{ sub NewApacheHandler
138 =head2 NewApacheHandler
140 Takes extra options to pass to HTML::Mason::ApacheHandler->new
141 Returns a new Mason::ApacheHandler object
145 sub NewApacheHandler {
146 require HTML::Mason::ApacheHandler;
147 return NewHandler('HTML::Mason::ApacheHandler', args_method => "CGI", @_);
152 # {{{ sub NewApache2Handler
154 =head2 NewApache2Handler
156 Takes extra options to pass to MasonX::Apache2Handler->new
157 Returns a new MasonX::Apache2Handler object
161 sub NewApache2Handler {
162 require MasonX::Apache2Handler;
163 return NewHandler('MasonX::Apache2Handler', args_method => "CGI", @_);
168 # {{{ sub NewCGIHandler
172 Returns a new Mason::CGIHandler object
177 require HTML::Mason::CGIHandler;
178 return NewHandler('HTML::Mason::CGIHandler', @_);
183 my $handler = $class->new(
184 DefaultHandlerArgs(),
188 $handler->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
189 $handler->interp->set_escape( u => \&RT::Interface::Web::EscapeURI );
193 =head2 CleanupRequest
195 Rollback any uncommitted transaction.
197 Flush the searchbuilder query cache
203 if ( $RT::Handle->TransactionDepth ) {
204 $RT::Handle->ForceRollback;
206 "Transaction not committed. Usually indicates a software fault."
207 . "Data loss may have occurred" );
210 # Clean out the ACL cache. the performance impact should be marginal.
211 # Consistency is imprived, too.
212 RT::Principal->InvalidateACLCache();
213 DBIx::SearchBuilder::Record::Cachable->FlushCache
214 if ( $RT::WebFlushDbCacheEveryRequest
216 'DBIx::SearchBuilder::Record::Cachable' => 'FlushCache' ) );