7 use FS::Mason qw( mason_interps );
12 # Bring in ApacheHandler, necessary for mod_perl integration.
13 # Uncomment the second line (and comment the first) to use
14 # Apache::Request instead of CGI.pm to parse arguments.
15 use HTML::Mason::ApacheHandler;
16 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
18 ###use Module::Refresh;###
20 # Create Mason objects
22 my( $fs_interp, $rt_interp ) = mason_interps('apache');
24 my $ah = new HTML::Mason::ApacheHandler (
26 request_class => 'FS::Mason::Request',
27 args_method => 'CGI', #(and FS too)
30 # Activate the following if running httpd as root (the normal case).
31 # Resets ownership of all files created by Mason at startup.
33 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
42 FS::Trace->log('protecting fds');
44 #from rt/bin/webmux.pl(.in)
45 if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
46 && $ENV{'MOD_PERL_API_VERSION'} >= 2
48 # under mod_perl2, STDIN and STDOUT get closed and re-opened,
49 # however they are not on FD 0 and 1. In this case, the next
50 # socket that gets opened will occupy one of these FDs, and make
51 # all system() and open "|-" calls dangerous; for example, the
52 # DBI handle can get this FD, which later system() calls will
53 # close by putting garbage into the socket.
55 push @{$protect_fds}, IO::Handle->new_from_fd(0, "r")
56 if fileno(STDIN) != 0;
57 push @{$protect_fds}, IO::Handle->new_from_fd(1, "w")
58 if fileno(STDOUT) != 1;
61 # If you plan to intermix images in the same directory as
62 # components, activate the following to prevent Mason from
63 # evaluating image files as components.
65 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
67 ###Module::Refresh->refresh;###
69 FS::Trace->log('setting content_type / headers');
71 $r->content_type('text/html; charset=utf-8');
72 #$r->content_type('text/html; charset=iso-8859-1');
75 my $headers = $r->headers_out;
76 $headers->{'Cache-control'} = 'no-cache';
78 $headers->{'Expires'} = '0';
80 # $r->send_http_header;
82 if ( $r->filename =~ /\/rt\// ) { #RT
84 FS::Trace->log('handling RT file');
86 # We don't need to handle non-text, non-xml items
87 return -1 if defined( $r->content_type )
88 && $r->content_type !~ m!(^text/|\bxml\b)!io;
94 FS::Trace->log('initializing RT');
97 FS::Trace->log('setting RT interpreter');
98 $ah->interp($rt_interp);
102 FS::Trace->log('handling Freeside file');
104 local $SIG{__WARN__};
107 FS::Trace->log('initializing RT');
110 #we don't want the RT error handlers under FS
112 no warnings 'uninitialized';
113 undef($SIG{__WARN__}) if defined($SIG{__WARN__});
114 undef($SIG{__DIE__}) if defined($SIG{__DIE__} );
117 FS::Trace->log('setting Freeside interpreter');
118 $ah->interp($fs_interp);
122 FS::Trace->log('handling request');
125 eval { $status = $ah->handle_request($r); };
128 # $RT::Logger->crit($@);
135 # if ($RT::Handle->TransactionDepth) {
136 # $RT::Handle->ForceRollback;
138 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
142 FS::Trace->log('done');
144 FS::Trace->dumpfile("%%%FREESIDE_EXPORT%%%/profile/$$.".time, $r->filename)
145 if FS::Trace->total > 5; #10?
152 my $rt_initialized = 0;
155 return unless $RT::VERSION;
157 if ( $rt_initialized ) {
158 RT::ConnectToDatabase();
159 RT::InitSignalHandlers();