7 use FS::Mason qw( mason_interps );
10 if ( %%%RT_ENABLED%%% ) {
14 $> = scalar(getpwnam('freeside'));
19 # disconnect DB before fork:
20 # (avoid 'prepared statement "dbdpg_p\d+_\d+" already exists' errors?)
21 $RT::Handle->dbh(undef);
29 # Bring in ApacheHandler, necessary for mod_perl integration.
30 # Uncomment the second line (and comment the first) to use
31 # Apache::Request instead of CGI.pm to parse arguments.
32 use HTML::Mason::ApacheHandler;
33 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
35 ###use Module::Refresh;###
37 # Create Mason objects
39 my( $fs_interp, $rt_interp ) = mason_interps('apache');
41 my $ah = new HTML::Mason::ApacheHandler (
43 request_class => 'FS::Mason::Request',
44 args_method => 'CGI', #(and FS too)
47 # Activate the following if running httpd as root (the normal case).
48 # Resets ownership of all files created by Mason at startup.
50 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
59 FS::Trace->log('protecting fds');
61 #from rt/bin/webmux.pl(.in)
62 if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
63 && $ENV{'MOD_PERL_API_VERSION'} >= 2
65 # under mod_perl2, STDIN and STDOUT get closed and re-opened,
66 # however they are not on FD 0 and 1. In this case, the next
67 # socket that gets opened will occupy one of these FDs, and make
68 # all system() and open "|-" calls dangerous; for example, the
69 # DBI handle can get this FD, which later system() calls will
70 # close by putting garbage into the socket.
72 push @{$protect_fds}, IO::Handle->new_from_fd(0, "r")
73 if fileno(STDIN) != 0;
74 push @{$protect_fds}, IO::Handle->new_from_fd(1, "w")
75 if fileno(STDOUT) != 1;
78 # If you plan to intermix images in the same directory as
79 # components, activate the following to prevent Mason from
80 # evaluating image files as components.
82 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
84 ###Module::Refresh->refresh;###
86 FS::Trace->log('setting content_type / headers');
88 $r->content_type('text/html; charset=utf-8');
89 #$r->content_type('text/html; charset=iso-8859-1');
92 my $headers = $r->headers_out;
93 $headers->{'Cache-control'} = 'no-cache';
95 $headers->{'Expires'} = '0';
97 # $r->send_http_header;
99 if ( $r->filename =~ /\/rt\// ) { #RT
101 FS::Trace->log('handling RT file');
103 # We don't need to handle non-text, non-xml items
104 return -1 if defined( $r->content_type )
105 && $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::Trace->log('handling request');
142 eval { $status = $ah->handle_request($r); };
145 # $RT::Logger->crit($@);
152 # if ($RT::Handle->TransactionDepth) {
153 # $RT::Handle->ForceRollback;
155 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
159 FS::Trace->log('done');
161 FS::Trace->dumpfile( "%%%FREESIDE_EXPORT%%%/profile/$$.".time,
162 FS::Trace->total. ' '. $r->filename
164 if FS::Trace->total > 5; #10?
172 return unless $RT::VERSION;
173 RT::ConnectToDatabase();
174 RT::InitSignalHandlers();