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=>'%%%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 $fsurl);
92 use vars qw( %session );
93 use CGI 2.47 qw(-private_tempfiles);
94 #use CGI::Carp qw(fatalsToBrowser);
95 use List::Util qw( max min );
101 use DateTime::Format::Strptime;
102 use Lingua::EN::Inflect qw(PL);
110 use Net::Whois::Raw qw(whois);
112 eval "use Net::Whois::Raw 0.32 qw(whois)";
116 use Spreadsheet::WriteExcel;
117 use Business::CreditCard 0.30; #for mask-aware cardtype()
118 use String::Approx qw(amatch);
119 use Chart::LinesPoints;
122 use HTML::Widgets::SelectLayers 0.07;
125 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
126 use FS::Record qw(qsearch qsearchs fields dbdef);
128 use FS::CGI qw(header menubar popurl rooturl table itable ntable idiot
129 eidiot small_custview myexit http_header);
131 use FS::Msgcat qw(gettext geterror);
132 use FS::Misc qw( send_email send_fax states_hash counties state_label );
133 use FS::Report::Table::Monthly;
134 use FS::TicketSystem;
138 use FS::domain_record;
140 use FS::cust_bill_pay;
142 use FS::cust_credit_bill;
143 use FS::cust_main qw(smart_search);
144 use FS::cust_main_county;
147 use FS::cust_pkg_reason;
151 use FS::part_bill_event;
153 use FS::part_referral;
155 use FS::part_svc_router;
156 use FS::part_virtual_field;
160 use FS::queue qw(joblisting);
164 use FS::svc_acct_pop qw(popselector);
170 use FS::svc_broadband;
171 use FS::svc_external;
174 use FS::part_export_option;
180 use FS::payment_gateway;
181 use FS::agent_payment_gateway;
185 use FS::inventory_class;
186 use FS::inventory_item;
189 use FS::access_group;
190 use FS::access_usergroup;
191 use FS::access_groupagent;
192 use FS::access_right;
197 use FS::cust_main_note;
199 if ( %%%RT_ENABLED%%% ) {
202 use RT::Transactions;
207 use RT::ScripActions;
208 use RT::ScripConditions;
211 use RT::GroupMembers;
212 use RT::CustomFields;
213 use RT::CustomFieldValues;
214 use RT::ObjectCustomFieldValues;
216 use RT::Interface::Web;
227 *CGI::redirect = sub {
228 my( $self, $location ) = @_;
231 # false laziness w/below
232 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
235 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
237 ( UNIVERSAL::can(dbh, 'sprintProfile')
238 ? encode_entities(dbh->sprintProfile())
239 : 'DBIx::Profile missing sprintProfile method;'.
240 'unpatched or too old?' ).
241 #"\n\n". &sprintAutoProfile(). '</PRE>'.
244 dbh->{'private_profile'} = {};
247 } else { #normal redirect
249 $m->redirect($location);
256 unless ( $HTML::Mason::r->filename =~ /\/rt\/.*NoAuth/ ) { #RT
270 my( $location ) = @_;
273 #false laziness w/above
274 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
277 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
279 ( UNIVERSAL::can(dbh, 'sprintProfile')
280 ? encode_entities(dbh->sprintProfile())
281 : 'DBIx::Profile missing sprintProfile method;'.
282 'unpatched or too old?' ).
283 #"\n\n". &sprintAutoProfile(). '</PRE>'.
287 dbh->{'private_profile'} = {};
289 #whew. removing this is all that's needed to fix the annoying
290 #blank-page-instead-of-profiling-redirect-when-called-from-an-include
291 #bug triggered by mason 1.32
292 #my $rv = $m->abort(200);
294 } else { #normal redirect
296 $m->redirect($location);
302 } # end package HTML::Mason::Commands;
304 ###Module::Refresh->refresh;###
306 $r->content_type('text/html');
309 my $headers = $r->headers_out;
310 $headers->{'Cache-control'} = 'no-cache';
312 $headers->{'Expires'} = '0';
314 # $r->send_http_header;
316 #$ah->interp->remove_escape('h');
318 if ( $r->filename =~ /\/rt\// ) { #RT
319 #warn "processing RT file". $r->filename. "; escaping for RT\n";
321 # MasonX::Request::ExtendedCompRoot
322 #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
324 $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
326 local $SIG{__WARN__};
331 # We don't need to handle non-text, non-xml items
332 return -1 if defined( $r->content_type ) && $r->content_type !~ m!(^text/|\bxml\b)!io;
335 $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
338 $ah->interp->ignore_warnings_expr('.');
342 eval { $status = $ah->handle_request($r); };
345 # $RT::Logger->crit($@);
351 # if ($RT::Handle->TransactionDepth) {
352 # $RT::Handle->ForceRollback;
354 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"