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.
10 use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
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);
96 use List::Util qw( max min );
103 use DateTime::Format::Strptime;
104 use Lingua::EN::Inflect qw(PL);
113 #not actually using this yet anyway...# use IPC::Run3 0.036;
114 use Net::Whois::Raw qw(whois);
116 eval "use Net::Whois::Raw 0.32 qw(whois)";
120 use Spreadsheet::WriteExcel;
121 use Business::CreditCard 0.30; #for mask-aware cardtype()
122 use String::Approx qw(amatch);
123 use Chart::LinesPoints;
126 use HTML::Widgets::SelectLayers 0.07;
129 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
130 use FS::Record qw(qsearch qsearchs fields dbdef);
132 use FS::CGI qw(header menubar popurl rooturl table itable ntable idiot
133 eidiot small_custview myexit http_header);
134 use FS::UI::Web qw(svc_url);
135 use FS::UI::bytecount;
136 use FS::Msgcat qw(gettext geterror);
137 use FS::Misc qw( send_email send_fax states_hash counties state_label );
138 use FS::Report::Table::Monthly;
139 use FS::TicketSystem;
143 use FS::domain_record;
145 use FS::cust_bill_pay;
147 use FS::cust_credit_bill;
148 use FS::cust_main qw(smart_search);
149 use FS::cust_main_county;
152 use FS::cust_pkg_reason;
156 use FS::part_bill_event;
158 use FS::part_event_condition;
160 use FS::part_referral;
162 use FS::part_svc_router;
163 use FS::part_virtual_field;
167 use FS::queue qw(joblisting);
171 use FS::svc_acct_pop qw(popselector);
172 use FS::acct_rt_transaction;
178 use FS::svc_broadband;
179 use FS::svc_external;
182 use FS::part_export_option;
188 use FS::payment_gateway;
189 use FS::agent_payment_gateway;
193 use FS::inventory_class;
194 use FS::inventory_item;
197 use FS::access_user_pref;
198 use FS::access_group;
199 use FS::access_usergroup;
200 use FS::access_groupagent;
201 use FS::access_right;
206 use FS::cust_main_note;
208 if ( %%%RT_ENABLED%%% ) {
211 use RT::Transactions;
216 use RT::ScripActions;
217 use RT::ScripConditions;
220 use RT::GroupMembers;
221 use RT::CustomFields;
222 use RT::CustomFieldValues;
223 use RT::ObjectCustomFieldValues;
225 use RT::Interface::Web;
235 *CGI::redirect = sub {
238 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
239 (my $x, $cookie) = (shift, shift);
240 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
242 my $location = shift;
246 # false laziness w/below
247 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
250 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
252 ( UNIVERSAL::can(dbh, 'sprintProfile')
253 ? encode_entities(dbh->sprintProfile())
254 : 'DBIx::Profile missing sprintProfile method;'.
255 'unpatched or too old?' ).
256 #"\n\n". &sprintAutoProfile(). '</PRE>'.
259 dbh->{'private_profile'} = {};
262 } else { #normal redirect
264 $m->redirect($location);
271 unless ( $HTML::Mason::r->filename =~ /\/rt\/.*NoAuth/ ) { #RT
286 $m->comp('/elements/errorpage.html', @_);
290 my( $location ) = @_;
293 #false laziness w/above
294 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
297 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
299 ( UNIVERSAL::can(dbh, 'sprintProfile')
300 ? encode_entities(dbh->sprintProfile())
301 : 'DBIx::Profile missing sprintProfile method;'.
302 'unpatched or too old?' ).
303 #"\n\n". &sprintAutoProfile(). '</PRE>'.
307 dbh->{'private_profile'} = {};
309 #whew. removing this is all that's needed to fix the annoying
310 #blank-page-instead-of-profiling-redirect-when-called-from-an-include
311 #bug triggered by mason 1.32
312 #my $rv = $m->abort(200);
314 } else { #normal redirect
316 $m->redirect($location);
322 } # end package HTML::Mason::Commands;
324 ###Module::Refresh->refresh;###
326 $r->content_type('text/html');
329 my $headers = $r->headers_out;
330 $headers->{'Cache-control'} = 'no-cache';
332 $headers->{'Expires'} = '0';
334 # $r->send_http_header;
336 #$ah->interp->remove_escape('h');
338 if ( $r->filename =~ /\/rt\// ) { #RT
339 #warn "processing RT file". $r->filename. "; escaping for RT\n";
341 # MasonX::Request::ExtendedCompRoot
342 #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
344 $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
346 local $SIG{__WARN__};
351 # We don't need to handle non-text, non-xml items
352 return -1 if defined( $r->content_type ) && $r->content_type !~ m!(^text/|\bxml\b)!io;
355 #$ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
356 $ah->interp->set_escape( 'h' => sub {} );
358 $ah->interp->set_escape( 'js_string' => sub {
359 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
360 ${$_[0]} =~ s/(['\\])/\\$1/g;
361 ${$_[0]} =~ s/\n/\\n/g;
362 ${$_[0]} = "'". ${$_[0]}. "'";
366 $ah->interp->ignore_warnings_expr('.');
370 eval { $status = $ah->handle_request($r); };
373 # $RT::Logger->crit($@);
379 # if ($RT::Handle->TransactionDepth) {
380 # $RT::Handle->ForceRollback;
382 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"