7 use FS::Mason qw( mason_interps );
9 use FS::access_user_log;
11 if ( %%%RT_ENABLED%%% ) {
15 $> = scalar(getpwnam('freeside'));
20 # disconnect DB before fork:
21 # (avoid 'prepared statement "dbdpg_p\d+_\d+" already exists' errors?)
22 $RT::Handle->dbh(undef);
30 # Bring in ApacheHandler, necessary for mod_perl integration.
31 # Uncomment the second line (and comment the first) to use
32 # Apache::Request instead of CGI.pm to parse arguments.
33 use HTML::Mason::ApacheHandler;
34 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
36 ###use Module::Refresh;###
38 # Create Mason objects
40 my( $fs_interp, $rt_interp ) = mason_interps('apache');
42 my $ah = new HTML::Mason::ApacheHandler (
44 request_class => 'FS::Mason::Request',
45 args_method => 'CGI', #(and FS too)
48 # Activate the following if running httpd as root (the normal case).
49 # Resets ownership of all files created by Mason at startup.
51 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
60 FS::Trace->log('protecting fds');
62 #from rt/bin/webmux.pl(.in)
63 if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
64 && $ENV{'MOD_PERL_API_VERSION'} >= 2
66 # under mod_perl2, STDIN and STDOUT get closed and re-opened,
67 # however they are not on FD 0 and 1. In this case, the next
68 # socket that gets opened will occupy one of these FDs, and make
69 # all system() and open "|-" calls dangerous; for example, the
70 # DBI handle can get this FD, which later system() calls will
71 # close by putting garbage into the socket.
73 push @{$protect_fds}, IO::Handle->new_from_fd(0, "r")
74 if fileno(STDIN) != 0;
75 push @{$protect_fds}, IO::Handle->new_from_fd(1, "w")
76 if fileno(STDOUT) != 1;
79 # If you plan to intermix images in the same directory as
80 # components, activate the following to prevent Mason from
81 # evaluating image files as components.
83 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
85 ###Module::Refresh->refresh;###
87 FS::Trace->log('setting content_type / headers');
89 $r->content_type('text/html; charset=utf-8');
90 #$r->content_type('text/html; charset=iso-8859-1');
93 my $headers = $r->headers_out;
94 $headers->{'Cache-control'} = 'no-cache';
96 $headers->{'Expires'} = '0';
98 # $r->send_http_header;
100 if ( $r->filename =~ /\/rt\// ) { #RT
102 FS::Trace->log('handling RT file');
104 # We don't need to handle non-text, non-xml items
105 return -1 if defined( $r->content_type )
106 && $r->content_type !~ m!(^text/|\bxml\b)!io;
108 local $SIG{__WARN__};
111 FS::Trace->log('initializing RT');
114 FS::Trace->log('setting RT interpreter');
115 $ah->interp($rt_interp);
119 FS::Trace->log('handling Freeside file');
121 local $SIG{__WARN__};
124 FS::Trace->log('initializing RT');
127 #we don't want the RT error handlers under FS
129 no warnings 'uninitialized';
130 undef($SIG{__WARN__}) if defined($SIG{__WARN__});
131 undef($SIG{__DIE__}) if defined($SIG{__DIE__} );
134 FS::Trace->log('setting Freeside interpreter');
135 $ah->interp($fs_interp);
139 FS::access_user_log->insert_new_path( $r->uri );
141 FS::Trace->log('handling request');
144 eval { $status = $ah->handle_request($r); };
147 # $RT::Logger->crit($@);
154 # if ($RT::Handle->TransactionDepth) {
155 # $RT::Handle->ForceRollback;
157 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
161 FS::Trace->log('done');
163 FS::Trace->dumpfile( "%%%FREESIDE_EXPORT%%%/profile/$$.".time,
164 FS::Trace->total. ' '. $r->filename
166 if FS::Trace->total > 5; #10?
174 return unless $RT::VERSION;
175 RT::ConnectToDatabase();
176 RT::InitSignalHandlers();