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