2 # $Header: /home/cvs/cvsroot/freeside/rt/bin/mason_handler.fcgi,v 1.1 2002-08-12 06:17:07 ivan Exp $
3 # RT is (c) 1996-2001 Jesse Vincent (jesse@fsck.com);
6 $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need
7 $ENV{'CDPATH'} = '' if defined $ENV{'CDPATH'};
8 $ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
9 $ENV{'ENV'} = '' if defined $ENV{'ENV'};
10 $ENV{'IFS'} = '' if defined $ENV{'IFS'};
13 # We really don't want apache to try to eat all vm
14 # see http://perl.apache.org/guide/control.html#Preventing_mod_perl_Processes_Fr
18 #use CGI qw(-private_tempfiles); # pull in CGI with the private tempfiles
20 use HTML::Mason; # brings in subpackages: Parser, Interp, etc.
22 use vars qw($VERSION %session $Nobody $SystemUser $cgi);
24 # List of modules that you want to use from components (see Admin
27 #Clean up our umask...so that the session files aren't world readable, writable or executable
32 $VERSION="!!RT_VERSION!!";
34 use lib "!!RT_LIB_PATH!!";
35 use lib "!!RT_ETC_PATH!!";
37 #This drags in RT's config.pm
42 package HTML::Mason::Commands;
43 use vars qw(%session $ContentType);
59 use RT::ScripCondition;
60 use RT::ScripConditions;
67 use RT::ObjectKeyword;
68 use RT::ObjectKeywords;
69 use RT::KeywordSelect;
70 use RT::KeywordSelects;
76 use RT::Interface::Web;
83 #TODO: make this use DBI
84 use Apache::Session::File;
87 # set the page's content type.
88 # In this case, just save it to a variable that we can pull later;
93 return $RT::Mason::cgi;
98 my ($output, $parser, $interp);
99 if ($HTML::Mason::VERSION < 1.0902) {
100 require HTML::Mason::ApacheHandler;
102 $parser = &RT::Interface::Web::NewParser(allow_globals => [%session]);
104 $interp = &RT::Interface::Web::NewInterp(parser=>$parser,
105 allow_recursive_autohandlers => 1,
106 out_method => \$output);
109 $interp = &RT::Interface::Web::NewInterp(
110 allow_globals => [%session],
111 default_escape_flags => 'h',
113 out_method => \$output);
115 # 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 _ ));
125 while ($RT::Mason::cgi = new CGI::Fast) {
127 $HTML::Mason::Commands::ContentType = 'text/html';
129 # This routine comes from ApacheHandler.pm:
131 foreach my $key ( $cgi->param ) {
132 foreach my $value ( $cgi->param($key) ) {
133 if (exists($args{$key})) {
134 if (ref($args{$key})) {
135 $args{$key} = [@{$args{$key}}, $value];
137 $args{$key} = [$args{$key}, $value];
140 $args{$key} = $value;
148 my $comp = $ENV{'PATH_INFO'};
150 if ($comp =~ /^(.*)$/) { # untaint the path info. apache should
151 # never hand us a bogus path.
152 # We should be more careful here.
156 if ($comp =~ /\/$/) {
157 $comp .= "index.html";
160 #This is all largely cut and pasted from mason's session_handler.pl
163 my %cookies = fetch CGI::Cookie();
166 my $session_id = undef;
168 #Get the session id and untaint it
169 if ($cookies{'AF_SID'} && $cookies{'AF_SID'}->value() =~ /^(.*)$/) {
173 tie %HTML::Mason::Commands::session, 'Apache::Session::File',
175 { Directory => $RT::MasonSessionDir,
176 LockDirectory => $RT::MasonSessionDir,
181 # If the session is invalid, create a new session.
182 if ( $@ =~ m#^Object does not exist in the data store# ) {
183 tie %HTML::Mason::Commands::session, 'Apache::Session::File', undef,
184 { Directory => $RT::MasonSessionDir,
185 LockDirectory => $RT::MasonSessionDir,
187 undef $cookies{'AF_SID'};
190 die "$@ \nProbably means that RT Couldn't write to session directory '$RT::MasonSessionDir'. Check that this directory's permissions are correct.";
194 if ( !$cookies{'AF_SID'} ) {
195 $cookie = new CGI::Cookie
197 -value=>$HTML::Mason::Commands::session{_session_id},
208 my $status = $interp->exec($comp, %args);
212 $output = "<PRE>$@</PRE>";
215 print "Content-Type: $HTML::Mason::Commands::ContentType\r\n";
216 print "Set-Cookie: $cookie\r\n" if ($cookie);
219 untie %HTML::Mason::Commands::session;