-# }}}
-
-# {{{ 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');
-
-
-# }}}
-
-
-
-
-# {{{ Deal with cookies
-
-my %cookies = fetch CGI::Cookie();
-eval {
- tie %HTML::Mason::Commands::session, 'Apache::Session::File',
- ( $cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef );
-};
-
-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'};
- }
-}
-
-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";
-}
-
-# }}}
-
-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";
- }
- }
-
-# }}}