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