1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2009 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/licenses/old-licenses/gpl-2.0.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 }}}
49 package RT::Interface::Web::Handler;
51 use CGI qw/-private_tempfiles/;
59 use RT::Interface::Web::Handler;
60 use RT::Interface::Web::Request;
61 use File::Path qw( rmtree );
62 use File::Glob qw( bsd_glob );
65 sub DefaultHandlerArgs { (
67 [ local => $RT::MasonLocalComponentRoot ],
68 (map {[ "plugin-".$_->Name => $_->ComponentRoot ]} @{RT->Plugins}),
69 [ standard => $RT::MasonComponentRoot ]
71 default_escape_flags => 'h',
72 data_dir => "$RT::MasonDataDir",
73 allow_globals => [qw(%session)],
74 # Turn off static source if we're in developer mode.
75 static_source => (RT->Config->Get('DevelMode') ? '0' : '1'),
76 use_object_files => (RT->Config->Get('DevelMode') ? '0' : '1'),
78 error_format => (RT->Config->Get('DevelMode') ? 'html': 'brief'),
79 request_class => 'RT::Interface::Web::Request',
80 named_component_subs => $INC{'Devel/Cover.pm'} ? 1 : 0,
87 Constructs a web handler of the appropriate class.
88 Takes options to pass to the constructor.
94 $class->InitSessionDir;
96 if ( ($mod_perl::VERSION && $mod_perl::VERSION >= 1.9908) || $CGI::MOD_PERL) {
97 goto &NewApacheHandler;
105 # Activate the following if running httpd as root (the normal case).
106 # Resets ownership of all files created by Mason at startup.
107 # Note that mysql uses DB for sessions, so there's no need to do this.
108 unless ( RT->Config->Get('DatabaseType') =~ /(?:mysql|Pg)/ ) {
110 # Clean up our umask to protect session files
113 if ($CGI::MOD_PERL and $CGI::MOD_PERL < 1.9908 ) {
115 chown( Apache->server->uid, Apache->server->gid,
116 $RT::MasonSessionDir )
117 if Apache->server->can('uid');
120 # Die if WebSessionDir doesn't exist or we can't write to it
121 stat($RT::MasonSessionDir);
122 die "Can't read and write $RT::MasonSessionDir"
123 unless ( ( -d _ ) and ( -r _ ) and ( -w _ ) );
130 # {{{ sub NewApacheHandler
132 =head2 NewApacheHandler
134 Takes extra options to pass to HTML::Mason::ApacheHandler->new
135 Returns a new Mason::ApacheHandler object
139 sub NewApacheHandler {
140 require HTML::Mason::ApacheHandler;
141 return NewHandler('HTML::Mason::ApacheHandler', args_method => "CGI", @_);
146 # {{{ sub NewCGIHandler
150 Returns a new Mason::CGIHandler object
155 require HTML::Mason::CGIHandler;
156 return NewHandler('HTML::Mason::CGIHandler', @_);
161 my $handler = $class->new(
162 DefaultHandlerArgs(),
166 $handler->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
167 $handler->interp->set_escape( u => \&RT::Interface::Web::EscapeURI );
171 =head2 CleanupRequest
173 Clean ups globals, caches and other things that could be still
174 there from previous requests:
178 =item Rollback any uncommitted transaction(s)
180 =item Flush the ACL cache
182 =item Flush records cache of the L<DBIx::SearchBuilder> if
183 WebFlushDbCacheEveryRequest option is enabled, what is true by default
184 and is not recommended to change.
186 =item Clean up state of RT::Action::SendEmail using 'CleanSlate' method
188 =item Flush tmp GnuPG key preferences
196 if ( $RT::Handle && $RT::Handle->TransactionDepth ) {
197 $RT::Handle->ForceRollback;
199 "Transaction not committed. Usually indicates a software fault."
200 . "Data loss may have occurred" );
203 # Clean out the ACL cache. the performance impact should be marginal.
204 # Consistency is imprived, too.
205 RT::Principal->InvalidateACLCache();
206 DBIx::SearchBuilder::Record::Cachable->FlushCache
207 if ( RT->Config->Get('WebFlushDbCacheEveryRequest')
209 'DBIx::SearchBuilder::Record::Cachable' => 'FlushCache' ) );
211 # cleanup global squelching of the mails
212 require RT::Action::SendEmail;
213 RT::Action::SendEmail->CleanSlate;
215 if (RT->Config->Get('GnuPG')->{'Enable'}) {
216 require RT::Crypt::GnuPG;
217 RT::Crypt::GnuPG::UseKeyForEncryption();
218 RT::Crypt::GnuPG::UseKeyForSigning( undef );