7 use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
8 use HTML::Mason::Interp;
9 use HTML::Mason::Compiler::ToObject;
11 # Bring in ApacheHandler, necessary for mod_perl integration.
12 # Uncomment the second line (and comment the first) to use
13 # Apache::Request instead of CGI.pm to parse arguments.
14 use HTML::Mason::ApacheHandler;
15 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
17 ###use Module::Refresh;###
19 # List of modules that you want to use from components (see Admin
21 #{ package HTML::Mason::Commands;
25 if ( %%%RT_ENABLED%%% ) {
27 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
29 use vars qw($Nobody $SystemUser);
35 # Create Mason objects
38 request_class => 'HTML::Mason::Request::ApacheHandler',
39 data_dir => '%%%MASONDATA%%%',
40 error_mode => 'output',
41 error_format => 'html',
42 ignore_warnings_expr => '.',
44 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
45 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
49 my $fs_interp = new HTML::Mason::Interp (
51 escape_flags => { 'js_string' => sub {
52 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
53 ${$_[0]} =~ s/(['\\])/\\$1/g;
54 ${$_[0]} =~ s/\n/\\n/g;
55 ${$_[0]} = "'". ${$_[0]}. "'";
60 my $rt_interp = new HTML::Mason::Interp (
62 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
63 compiler => HTML::Mason::Compiler::ToObject->new(
64 default_escape_flags => 'h',
65 allow_globals => [qw(%session)],
69 my $ah = new HTML::Mason::ApacheHandler (
71 args_method => 'CGI', #(and FS too)
74 # Activate the following if running httpd as root (the normal case).
75 # Resets ownership of all files created by Mason at startup.
77 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
83 # If you plan to intermix images in the same directory as
84 # components, activate the following to prevent Mason from
85 # evaluating image files as components.
87 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
90 { package HTML::Mason::Commands;
92 use vars qw( $cgi $p $fsurl);
93 use vars qw( %session );
94 use CGI 2.47 qw(-private_tempfiles);
95 #use CGI::Carp qw(fatalsToBrowser);
97 use List::Util qw( max min );
104 use DateTime::Format::Strptime;
105 use Lingua::EN::Inflect qw(PL);
114 #not actually using this yet anyway...# use IPC::Run3 0.036;
115 use Net::Whois::Raw qw(whois);
117 eval "use Net::Whois::Raw 0.32 qw(whois)";
121 use Spreadsheet::WriteExcel;
122 use Business::CreditCard 0.30; #for mask-aware cardtype()
124 use String::Approx qw(amatch);
125 use Chart::LinesPoints;
128 use HTML::Widgets::SelectLayers 0.07;
131 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
132 use FS::Record qw(qsearch qsearchs fields dbdef str2time_sql);
134 use FS::CGI qw(header menubar popurl rooturl table itable ntable idiot
135 eidiot small_custview myexit http_header);
136 use FS::UI::Web qw(svc_url);
137 use FS::UI::bytecount;
138 use FS::Msgcat qw(gettext geterror);
139 use FS::Misc qw( send_email send_fax states_hash counties state_label );
140 use FS::Report::Table::Monthly;
141 use FS::TicketSystem;
145 use FS::domain_record;
147 use FS::cust_bill_pay;
149 use FS::cust_credit_bill;
150 use FS::cust_main qw(smart_search);
151 use FS::cust_main_county;
152 use FS::part_pkg_taxclass;
155 use FS::cust_pkg_reason;
159 use FS::part_bill_event;
161 use FS::part_event_condition;
163 use FS::part_referral;
165 use FS::part_svc_router;
166 use FS::part_virtual_field;
170 use FS::queue qw(joblisting);
174 use FS::svc_acct_pop qw(popselector);
175 use FS::acct_rt_transaction;
181 use FS::svc_broadband;
182 use FS::svc_external;
185 use FS::part_export_option;
191 use FS::payment_gateway;
192 use FS::agent_payment_gateway;
196 use FS::inventory_class;
197 use FS::inventory_item;
200 use FS::access_user_pref;
201 use FS::access_group;
202 use FS::access_usergroup;
203 use FS::access_groupagent;
204 use FS::access_right;
209 use FS::cust_main_note;
211 if ( %%%RT_ENABLED%%% ) {
214 use RT::Transactions;
219 use RT::ScripActions;
220 use RT::ScripConditions;
223 use RT::GroupMembers;
224 use RT::CustomFields;
225 use RT::CustomFieldValues;
226 use RT::ObjectCustomFieldValues;
228 #blah. manually updated from RT::Interface::Web::Handler
229 use RT::Interface::Web;
236 #slow, unreliable, segfaults and is optional
237 #see rt/html/Ticket/Elements/ShowTransactionAttachments
240 #?#use File::Path qw( rmtree );
241 #?#use File::Glob qw( bsd_glob );
242 #?#use File::Spec::Unix;
248 *CGI::redirect = sub {
251 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
252 (my $x, $cookie) = (shift, shift);
253 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
255 my $location = shift;
259 # false laziness w/below
260 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
263 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
265 ( UNIVERSAL::can(dbh, 'sprintProfile')
266 ? encode_entities(dbh->sprintProfile())
267 : 'DBIx::Profile missing sprintProfile method;'.
268 'unpatched or too old?' ).
269 #"\n\n". &sprintAutoProfile(). '</PRE>'.
272 dbh->{'private_profile'} = {};
275 } else { #normal redirect
277 $m->redirect($location);
284 unless ( $HTML::Mason::r->filename =~ /\/rt\/.*NoAuth/ ) { #RT
299 $m->comp('/elements/errorpage.html', @_);
303 my( $location ) = @_;
306 #false laziness w/above
307 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
310 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
312 ( UNIVERSAL::can(dbh, 'sprintProfile')
313 ? encode_entities(dbh->sprintProfile())
314 : 'DBIx::Profile missing sprintProfile method;'.
315 'unpatched or too old?' ).
316 #"\n\n". &sprintAutoProfile(). '</PRE>'.
320 dbh->{'private_profile'} = {};
322 #whew. removing this is all that's needed to fix the annoying
323 #blank-page-instead-of-profiling-redirect-when-called-from-an-include
324 #bug triggered by mason 1.32
325 #my $rv = $m->abort(200);
327 } else { #normal redirect
329 $m->redirect($location);
335 } # end package HTML::Mason::Commands;
337 ###Module::Refresh->refresh;###
339 $r->content_type('text/html');
342 my $headers = $r->headers_out;
343 $headers->{'Cache-control'} = 'no-cache';
345 $headers->{'Expires'} = '0';
347 # $r->send_http_header;
349 if ( $r->filename =~ /\/rt\// ) { #RT
351 $ah->interp($rt_interp);
353 local $SIG{__WARN__};
358 # We don't need to handle non-text, non-xml items
359 return -1 if defined( $r->content_type )
360 && $r->content_type !~ m!(^text/|\bxml\b)!io;
364 $ah->interp($fs_interp);
370 eval { $status = $ah->handle_request($r); };
373 # $RT::Logger->crit($@);
380 # if ($RT::Handle->TransactionDepth) {
381 # $RT::Handle->ForceRollback;
383 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"