7 use FS::Mason qw( mason_interps );
9 use FS::access_user_log;
12 $FS::Conf::conf_cache_enabled = 1; # enable FS::Conf caching for performance
14 # Preload to share in mod_perl parent for performance
15 use FS::UID qw(load_schema);
17 use FS::Record qw(fk_methods_init);
20 if ( %%%RT_ENABLED%%% ) {
24 $> = scalar(getpwnam('freeside'));
29 # disconnect DB before fork:
30 # (avoid 'prepared statement "dbdpg_p\d+_\d+" already exists' errors?)
31 $RT::Handle->dbh(undef);
39 # Bring in ApacheHandler, necessary for mod_perl integration.
40 # Uncomment the second line (and comment the first) to use
41 # Apache::Request instead of CGI.pm to parse arguments.
42 use HTML::Mason::ApacheHandler;
43 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
45 ###use Module::Refresh;###
47 # Create Mason objects
49 my( $fs_interp, $rt_interp ) = mason_interps('apache');
51 my $ah = new HTML::Mason::ApacheHandler (
53 request_class => 'FS::Mason::Request',
54 args_method => 'CGI', #(and FS too)
57 # Activate the following if running httpd as root (the normal case).
58 # Resets ownership of all files created by Mason at startup.
60 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
69 my $start_time = time;
71 FS::Trace->log('protecting fds');
73 #from rt/bin/webmux.pl(.in)
74 if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
75 && $ENV{'MOD_PERL_API_VERSION'} >= 2
77 # under mod_perl2, STDIN and STDOUT get closed and re-opened,
78 # however they are not on FD 0 and 1. In this case, the next
79 # socket that gets opened will occupy one of these FDs, and make
80 # all system() and open "|-" calls dangerous; for example, the
81 # DBI handle can get this FD, which later system() calls will
82 # close by putting garbage into the socket.
84 push @{$protect_fds}, IO::Handle->new_from_fd(0, "r")
85 if fileno(STDIN) != 0;
86 push @{$protect_fds}, IO::Handle->new_from_fd(1, "w")
87 if fileno(STDOUT) != 1;
90 # If you plan to intermix images in the same directory as
91 # components, activate the following to prevent Mason from
92 # evaluating image files as components.
94 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
96 ###Module::Refresh->refresh;###
98 FS::Trace->log('setting content_type / headers');
100 $r->content_type('text/html; charset=utf-8');
101 #$r->content_type('text/html; charset=iso-8859-1');
104 my $headers = $r->headers_out;
105 $headers->{'Cache-control'} = 'no-cache';
107 $headers->{'Expires'} = '0';
109 # $r->send_http_header;
111 if ( $r->filename =~ /\/rt\// ) { #RT
113 FS::Trace->log('handling RT file');
115 # We don't need to handle non-text, non-xml items
116 return -1 if defined( $r->content_type )
117 && $r->content_type !~ m!(^text/|\bxml\b)!io;
119 local $SIG{__WARN__};
122 FS::Trace->log('initializing RT');
125 FS::Trace->log('setting RT interpreter');
126 $ah->interp($rt_interp);
130 FS::Trace->log('handling Freeside file');
132 local $SIG{__WARN__};
135 FS::Trace->log('initializing RT');
138 #we don't want the RT error handlers under FS
140 no warnings 'uninitialized';
141 undef($SIG{__WARN__}) if defined($SIG{__WARN__});
142 undef($SIG{__DIE__}) if defined($SIG{__DIE__} );
145 FS::Trace->log('setting Freeside interpreter');
146 $ah->interp($fs_interp);
150 FS::Trace->log('handling request');
153 eval { $status = $ah->handle_request($r); };
156 # $RT::Logger->crit($@);
163 # if ($RT::Handle->TransactionDepth) {
164 # $RT::Handle->ForceRollback;
166 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
170 FS::access_user_log->insert_new_path( $r->filename, time-$start_time );
172 FS::Trace->log('done');
174 FS::Trace->dumpfile( "%%%FREESIDE_EXPORT%%%/profile/$$.".time,
175 FS::Trace->total. ' '. $r->filename
177 if FS::Trace->total > 5; #10?
185 return unless $RT::VERSION;
186 RT::ConnectToDatabase();
187 RT::InitSignalHandlers();