7 use FS::Mason qw( mason_interps );
11 $FS::Conf::conf_cache_enabled = 1; # enable FS::Conf caching for performance
13 # Preload to share in mod_perl parent for performance
14 use FS::UID qw(load_schema);
16 use FS::Record qw(fk_methods_init);
19 if ( %%%RT_ENABLED%%% ) {
23 $> = scalar(getpwnam('freeside'));
28 # disconnect DB before fork:
29 # (avoid 'prepared statement "dbdpg_p\d+_\d+" already exists' errors?)
30 $RT::Handle->dbh(undef);
38 # Bring in ApacheHandler, necessary for mod_perl integration.
39 # Uncomment the second line (and comment the first) to use
40 # Apache::Request instead of CGI.pm to parse arguments.
41 use HTML::Mason::ApacheHandler;
42 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
44 ###use Module::Refresh;###
46 # Create Mason objects
48 my( $fs_interp, $rt_interp ) = mason_interps('apache');
50 my $ah = new HTML::Mason::ApacheHandler (
52 request_class => 'FS::Mason::Request',
53 args_method => 'CGI', #(and FS too)
56 # Activate the following if running httpd as root (the normal case).
57 # Resets ownership of all files created by Mason at startup.
59 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
68 FS::Trace->log('protecting fds');
70 #from rt/bin/webmux.pl(.in)
71 if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
72 && $ENV{'MOD_PERL_API_VERSION'} >= 2
74 # under mod_perl2, STDIN and STDOUT get closed and re-opened,
75 # however they are not on FD 0 and 1. In this case, the next
76 # socket that gets opened will occupy one of these FDs, and make
77 # all system() and open "|-" calls dangerous; for example, the
78 # DBI handle can get this FD, which later system() calls will
79 # close by putting garbage into the socket.
81 push @{$protect_fds}, IO::Handle->new_from_fd(0, "r")
82 if fileno(STDIN) != 0;
83 push @{$protect_fds}, IO::Handle->new_from_fd(1, "w")
84 if fileno(STDOUT) != 1;
87 # If you plan to intermix images in the same directory as
88 # components, activate the following to prevent Mason from
89 # evaluating image files as components.
91 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
93 ###Module::Refresh->refresh;###
95 FS::Trace->log('setting content_type / headers');
97 $r->content_type('text/html; charset=utf-8');
98 #$r->content_type('text/html; charset=iso-8859-1');
101 my $headers = $r->headers_out;
102 $headers->{'Cache-control'} = 'no-cache';
104 $headers->{'Expires'} = '0';
106 # $r->send_http_header;
108 if ( $r->filename =~ /\/rt\// ) { #RT
110 FS::Trace->log('handling RT file');
112 # We don't need to handle non-text, non-xml items
113 return -1 if defined( $r->content_type )
114 && $r->content_type !~ m!(^text/|\bxml\b)!io;
116 local $SIG{__WARN__};
119 FS::Trace->log('initializing RT');
122 FS::Trace->log('setting RT interpreter');
123 $ah->interp($rt_interp);
127 FS::Trace->log('handling Freeside file');
129 local $SIG{__WARN__};
132 FS::Trace->log('initializing RT');
135 #we don't want the RT error handlers under FS
137 no warnings 'uninitialized';
138 undef($SIG{__WARN__}) if defined($SIG{__WARN__});
139 undef($SIG{__DIE__}) if defined($SIG{__DIE__} );
142 FS::Trace->log('setting Freeside interpreter');
143 $ah->interp($fs_interp);
147 FS::Trace->log('handling request');
150 eval { $status = $ah->handle_request($r); };
153 # $RT::Logger->crit($@);
160 # if ($RT::Handle->TransactionDepth) {
161 # $RT::Handle->ForceRollback;
163 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
167 FS::Trace->log('done');
169 FS::Trace->dumpfile( "%%%FREESIDE_EXPORT%%%/profile/$$.".time,
170 FS::Trace->total. ' '. $r->filename
172 if FS::Trace->total > 5; #10?
180 return unless $RT::VERSION;
181 RT::ConnectToDatabase();
182 RT::InitSignalHandlers();