3 # This is a basic, fairly fuctional Mason handler.pl.
5 # For something a little more involved, check out session_handler.pl
9 # Bring in main Mason package.
12 # Bring in ApacheHandler, necessary for mod_perl integration.
13 # Uncomment the second line (and comment the first) to use
14 # Apache::Request instead of CGI.pm to parse arguments.
15 use HTML::Mason::ApacheHandler;
16 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
18 # Uncomment the next line if you plan to use the Mason previewer.
19 #use HTML::Mason::Preview;
23 ###use Module::Refresh;###
25 # List of modules that you want to use from components (see Admin
27 #{ package HTML::Mason::Commands;
31 # Create Mason objects
34 #my $parser = new HTML::Mason::Parser;
35 #my $interp = new HTML::Mason::Interp (parser=>$parser,
36 # comp_root=>'/var/www/masondocs',
37 # data_dir=>'/usr/local/etc/freeside/masondata',
43 if ( %%%RT_ENABLED%%% ) {
45 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
47 use vars qw($Nobody $SystemUser);
56 my $ah = new HTML::Mason::ApacheHandler (
58 #auto_send_headers => 0,
60 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
61 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
63 data_dir=>'/usr/local/etc/freeside/masondata',
68 default_escape_flags => 'h',
69 allow_globals => [qw(%session)],
73 # Activate the following if running httpd as root (the normal case).
74 # Resets ownership of all files created by Mason at startup.
76 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
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;
89 { package HTML::Mason::Commands;
91 use vars qw( $cgi $p );
92 use vars qw( %session );
93 use CGI 2.47 qw(-private_tempfiles);
94 #use CGI::Carp qw(fatalsToBrowser);
106 use Net::Whois::Raw qw(whois);
108 eval "use Net::Whois::Raw 0.32 qw(whois)";
112 use Spreadsheet::WriteExcel;
113 use Business::CreditCard;
114 use String::Approx qw(amatch);
115 use Chart::LinesPoints;
116 use HTML::Widgets::SelectLayers 0.05;
118 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
119 use FS::Record qw(qsearch qsearchs fields dbdef);
121 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
122 small_custview myexit http_header);
124 use FS::Msgcat qw(gettext geterror);
125 use FS::Misc qw( send_email send_fax );
126 use FS::Report::Table::Monthly;
127 use FS::TicketSystem;
131 use FS::domain_record;
133 use FS::cust_bill_pay;
135 use FS::cust_credit_bill;
136 use FS::cust_main qw(smart_search);
137 use FS::cust_main_county;
143 use FS::part_bill_event;
145 use FS::part_referral;
147 use FS::part_svc_router;
148 use FS::part_virtual_field;
151 use FS::queue qw(joblisting);
155 use FS::svc_acct_pop qw(popselector);
161 use FS::svc_broadband;
162 use FS::svc_external;
165 use FS::part_export_option;
171 use FS::payment_gateway;
172 use FS::agent_payment_gateway;
175 if ( %%%RT_ENABLED%%% ) {
178 use RT::Transactions;
183 use RT::ScripActions;
184 use RT::ScripConditions;
187 use RT::GroupMembers;
188 use RT::CustomFields;
189 use RT::CustomFieldValues;
190 use RT::ObjectCustomFieldValues;
192 use RT::Interface::Web;
203 *CGI::redirect = sub {
204 my( $self, $location ) = @_;
207 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
210 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
212 ( UNIVERSAL::can(dbh, 'sprintProfile')
213 ? encode_entities(dbh->sprintProfile())
214 : 'DBIx::Profile missing sprintProfile method;'.
215 'unpatched or too old?' ).
216 #"\n\n". &sprintAutoProfile(). '</PRE>'.
219 dbh->{'private_profile'} = {};
222 } else { #normal redirect
224 $m->redirect($location);
231 unless ( $HTML::Mason::r->filename =~ /\/rt\/.*NoAuth/ ) { #RT
245 my( $location ) = @_;
248 #false laziness w/above
249 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
252 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
254 ( UNIVERSAL::can(dbh, 'sprintProfile')
255 ? encode_entities(dbh->sprintProfile())
256 : 'DBIx::Profile missing sprintProfile method;'.
257 'unpatched or too old?' ).
258 #"\n\n". &sprintAutoProfile(). '</PRE>'.
262 dbh->{'private_profile'} = {};
266 } else { #normal redirect
268 $m->redirect($location);
274 } # end package HTML::Mason::Commands;
276 ###Module::Refresh->refresh;###
278 $r->content_type('text/html');
281 my $headers = $r->headers_out;
282 $headers->{'Cache-control'} = 'no-cache';
284 $headers->{'Expires'} = '0';
286 # $r->send_http_header;
288 #$ah->interp->remove_escape('h');
290 if ( $r->filename =~ /\/rt\// ) { #RT
291 #warn "processing RT file". $r->filename. "; escaping for RT\n";
293 # MasonX::Request::ExtendedCompRoot
294 #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
296 $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
298 local $SIG{__WARN__};
303 # We don't need to handle non-text, non-xml items
304 return -1 if defined( $r->content_type ) && $r->content_type !~ m!(^text/|\bxml\b)!io;
307 $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
312 eval { $status = $ah->handle_request($r); };
315 # $RT::Logger->crit($@);
321 # if ($RT::Handle->TransactionDepth) {
322 # $RT::Handle->ForceRollback;
324 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"