import rt 3.8.10
[freeside.git] / rt / bin / mason_handler.scgi
index b9846c8..83649ed 100755 (executable)
-#!!!PERL!! -w
-
-#!/usr/bin/speedy -- -t600 -M8
-# $Header: /home/cvs/cvsroot/freeside/rt/bin/mason_handler.scgi,v 1.1 2002-08-12 06:17:07 ivan Exp $
-# RT is (c) 1996-2001 Jesse Vincent (jesse@fsck.com);
+#!/usr/local/bin/speedy
+# BEGIN BPS TAGGED BLOCK {{{
 #
-# Contains code derived from mason.cgi
-# mason.cgi is Copyright December 2000 Joshua Kronengold (mneme@io.com, 
-# mneme@cyberspace.org).  All Rights Reserved.
-
-use strict;
-# {{{ Clean out the environment a little bit
-$ENV{'PATH'} = '/bin:/usr/bin';    # or whatever you need
-$ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'};
-$ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
-$ENV{'ENV'} = '' if defined $ENV{'ENV'};
-$ENV{'IFS'} = ''          if defined $ENV{'IFS'};
-# }}}
-
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+#                                          <sales@bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
 package RT::Mason;
-use HTML::Mason;  # brings in subpackages: Parser, Interp, etc.
-use vars qw($VERSION %session $Nobody $SystemUser);
-
-# List of modules that you want to use from components (see Admin
-# manual for details)
-
-$VERSION="!!RT_VERSION!!";
-
-use lib "!!RT_LIB_PATH!!";
-use lib "!!RT_ETC_PATH!!";
-
-
-#This drags in  RT's config.pm
-use config;
-use Carp;
-
-use HTML::Mason::FakeApache;
-use CGI;
-
-# {{{ Set up CGI environment and grab CGI params:
 
-my $r=new HTML::Mason::FakeApache;
-
-$|=1; # set output to non-buffered.
-
-my %cgi;
-CGI::ReadParse(\%cgi); # %cgi is now a tied hash containing our params.
-
-my $q=$cgi{CGI}; # $q now contains the object tied to %cgi.
-# }}}
-
-# {{{ require what we need
-{  
-    package HTML::Mason::Commands;
-
-    use vars qw(%session);
-
-    use RT::Ticket;
-    use RT::Tickets;
-    use RT::Transaction;
-    use RT::Transactions;
-    use RT::User;
-    use RT::Users;
-    use RT::CurrentUser;
-    use RT::Template;
-    use RT::Templates;
-    use RT::Queue;
-    use RT::Queues;
-    use RT::ScripAction;
-    use RT::ScripActions;
-    use RT::ScripCondition;
-    use RT::ScripConditions;
-    use RT::Scrip;
-    use RT::Scrips;
-    use RT::Group;
-    use RT::Groups;
-    use RT::Keyword;
-    use RT::Keywords;
-    use RT::ObjectKeyword;
-    use RT::ObjectKeywords;
-    use RT::KeywordSelect;
-    use RT::KeywordSelects;
-    use RT::GroupMember;
-    use RT::GroupMembers;
-    use RT::Watcher;
-    use RT::Watchers;
-    use RT::Handle;
-    use RT::Interface::Web;    
-    use MIME::Entity;
-    use CGI::Cookie;
-    use Date::Parse;
-    use HTML::Entities;
-
-    
-    use Apache::Session::File;
-
-    
-}
-# }}}
-
-# {{{ RT Database setup
-    $RT::Handle = new RT::Handle;
-    
-    $RT::Handle->Connect;
-   
-    use RT::CurrentUser;
-    
-    #RT's system user is a genuine database user. its id lives here
-    $RT::SystemUser = new RT::CurrentUser();
-    $RT::SystemUser->LoadByName('RT_System');
-
-    #RT's "nobody user" is a genuine database user. its ID lives here.
-    $RT::Nobody = new RT::CurrentUser();
-    $RT::Nobody->LoadByName('Nobody'); 
-     
-
-# }}}
+use strict;
+use vars '$Handler';
+use File::Basename;
 
+require (dirname(__FILE__) . '/webmux.pl');
 
+require CGI;
 
+my $cgi = CGI->new;
 
-# {{{ Deal with cookies
+# Each environment has its own way of handling .. and so on in paths,
+# so RT consistently forbids such paths.
+if ( $cgi->path_info =~ m{/\.} ) {
+    $RT::Logger->crit("Invalid request for ".$cgi->path_info." aborting");
+    print STDOUT "HTTP/1.0 400\r\n\r\n";
 
-my %cookies = fetch CGI::Cookie();
-eval { 
-    tie %HTML::Mason::Commands::session, 'Apache::Session::File',
-      ( $cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef );
-};
+    RT::Interface::Web::Handler->CleanupRequest();
 
-if ( $@ ) {
-    # If the session is invalid, create a new session.
-    if ( $@ =~ m#^Object does not exist in the data store# ) {
-        tie %HTML::Mason::Commands::session, 'Apache::Session::File', undef;
-        undef $cookies{'AF_SID'};
-    }
+    return 0;
 }
 
-if ( !$cookies{'AF_SID'} ) {
-    my $cookie = new CGI::Cookie(
-        -name=>'AF_SID', 
-        -value=>$HTML::Mason::Commands::session{_session_id}, 
-         -path => '/');
-    print 'Set-Cookie: '. $cookie."\r\n";
+if ( ( !$Handler->interp->comp_exists( $cgi->path_info ) )
+    && ( $Handler->interp->comp_exists( $cgi->path_info . "/index.html" ) ) ) {
+    $cgi->path_info( $cgi->path_info . "/index.html" );
 }
 
-# }}}
-
-my $path=$ENV{PATH_INFO} || "/"; $path=~s/\'/\\\'/g;
-
-my $type=`/usr/bin/file '$RT::MasonComponentRoot/$path'`;
-
-# {{{ if it's a text file, handle it with mason.
-if($type=~/text|directory/) { 
-       my ($out, %mason_params);
-        my $parser = RT::Interface::Web::NewParser(allow_globals=>[qw($r)]);
-       $mason_params{parser}=$parser;
-       $r->content_type('text/html');
-       # (get cookies line) ...
-       $r->access_hash('headers_in','Cookie',$ENV{HTTP_COOKIE});
-       $r->{'args@'}=[];
-       $mason_params{out_method}=\$out;
-
-       my $interp = RT::Interface::Web::NewInterp(%mason_params);
-
-       $interp->set_global(r=>$r);
-       $interp->exec($path,%cgi);
-       $r->send_http_header();
-        print $out;
-} 
-# }}} 
-
-# {{{ if it's not a text file, just stream it out.
-
-else { # file is binary, damn it
-       my $mime_type;
-       if ( $mime_type=
-            eval{ use MIME::Types;
-                  my($type,$encoding)=MIME::Types::by_suffix($path);
-                  $type; }) {
-           print $q->header($mime_type);       
-           $path=~s/[\|\>\<\&]//g;
-           open F,"$RT::MasonComponentRoot/$path" or 
-             die "couldn't open $path -- $!";
-           print while <F>; 
-           close F;
-       } else {
-           die "couldn't resolve type of non-text file (!@; $type) -- install Mime::Types\n";
-       }
-    }
-
-# }}}
-
-untie %HTML::Mason::Commands::session;
+RT::ConnectToDatabase();
+$Handler->handle_cgi_object($cgi);
+RT::Interface::Web::Handler->CleanupRequest();
+1;