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);
96 use List::Util qw( max min );
102 use DateTime::Format::Strptime;
103 use Lingua::EN::Inflect qw(PL);
111 use Net::Whois::Raw qw(whois);
113 eval "use Net::Whois::Raw 0.32 qw(whois)";
117 use Spreadsheet::WriteExcel;
118 use Business::CreditCard 0.30; #for mask-aware cardtype()
120 use String::Approx qw(amatch);
121 use Chart::LinesPoints;
124 use HTML::Widgets::SelectLayers 0.07;
127 use FS::UID qw( adminsuidsetup cgisuidsetup getotaker
128 dbh datasrc driver_name
130 use FS::Record qw(qsearch qsearchs fields dbdef str2time_sql);
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;
150 use FS::part_pkg_taxclass;
153 use FS::cust_pkg_reason;
157 use FS::part_bill_event;
159 use FS::part_referral;
161 use FS::part_svc_router;
162 use FS::part_virtual_field;
166 use FS::queue qw(joblisting);
170 use FS::svc_acct_pop qw(popselector);
176 use FS::svc_broadband;
177 use FS::svc_external;
180 use FS::part_export_option;
186 use FS::payment_gateway;
187 use FS::agent_payment_gateway;
191 use FS::inventory_class;
192 use FS::inventory_item;
195 use FS::access_group;
196 use FS::access_usergroup;
197 use FS::access_groupagent;
198 use FS::access_right;
203 use FS::cust_main_note;
205 if ( %%%RT_ENABLED%%% ) {
208 use RT::Transactions;
213 use RT::ScripActions;
214 use RT::ScripConditions;
217 use RT::GroupMembers;
218 use RT::CustomFields;
219 use RT::CustomFieldValues;
220 use RT::ObjectCustomFieldValues;
222 use RT::Interface::Web;
228 #use Text::Quoted; #slow, unreliable, segfaults and is optional
234 *CGI::redirect = sub {
235 my( $self, $location ) = @_;
238 # false laziness w/below
239 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
242 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
244 ( UNIVERSAL::can(dbh, 'sprintProfile')
245 ? encode_entities(dbh->sprintProfile())
246 : 'DBIx::Profile missing sprintProfile method;'.
247 'unpatched or too old?' ).
248 #"\n\n". &sprintAutoProfile(). '</PRE>'.
251 dbh->{'private_profile'} = {};
254 } else { #normal redirect
256 $m->redirect($location);
263 if ( $HTML::Mason::r->filename !~ /\/rt\/.*NoAuth/ ) { #not RT images/JS
271 } elsif ( $HTML::Mason::r->filename =~ /\/rt\/REST\/.*NoAuth/ ) {
273 #need to log somebody in for the mail gw
275 ##old installs w/fs_selfs or selfserv??
276 #&adminsuidsetup('fs_selfservice');
278 &adminsuidsetup('fs_queue');
289 $m->comp('/elements/errorpage.html', @_);
293 my( $location ) = @_;
296 #false laziness w/above
297 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
300 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
302 ( UNIVERSAL::can(dbh, 'sprintProfile')
303 ? encode_entities(dbh->sprintProfile())
304 : 'DBIx::Profile missing sprintProfile method;'.
305 'unpatched or too old?' ).
306 #"\n\n". &sprintAutoProfile(). '</PRE>'.
310 dbh->{'private_profile'} = {};
312 #whew. removing this is all that's needed to fix the annoying
313 #blank-page-instead-of-profiling-redirect-when-called-from-an-include
314 #bug triggered by mason 1.32
315 #my $rv = $m->abort(200);
317 } else { #normal redirect
319 $m->redirect($location);
325 } # end package HTML::Mason::Commands;
327 ###Module::Refresh->refresh;###
329 $r->content_type('text/html');
332 my $headers = $r->headers_out;
333 $headers->{'Cache-control'} = 'no-cache';
335 $headers->{'Expires'} = '0';
337 # $r->send_http_header;
339 if ( $r->filename =~ /\/rt\// ) { #RT
341 $ah->interp($rt_interp);
343 local $SIG{__WARN__};
348 # We don't need to handle non-text, non-xml items
349 return -1 if defined( $r->content_type )
350 && $r->content_type !~ m!(^text/|\bxml\b)!io;
354 $ah->interp($fs_interp);
360 eval { $status = $ah->handle_request($r); };
363 # $RT::Logger->crit($@);
370 # if ($RT::Handle->TransactionDepth) {
371 # $RT::Handle->ForceRollback;
373 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"