7 use File::Slurp qw( slurp );
8 use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
9 use HTML::Mason::Interp;
10 use HTML::Mason::Compiler::ToObject;
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 ###use Module::Refresh;###
20 # List of modules that you want to use from components (see Admin
22 #{ package HTML::Mason::Commands;
26 if ( %%%RT_ENABLED%%% ) {
28 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
30 use vars qw($Nobody $SystemUser);
36 # Some hooks supporting strange legacy ways people have added stuff on
38 my @addl_comp_root = ();
39 my $addl_comp_root_file = '%%%FREESIDE_CONF%%%/addl_comp_root.pl';
40 if ( -e $addl_comp_root_file ) {
41 my $text = slurp( $addl_comp_root_file );
42 my @addl = eval $text;
43 if ( @addl && ! $@ ) {
44 @addl_comp_root = @addl;
46 warn "error parsing $addl_comp_root_file: $@\n";
50 $FS::Mason::addl_handler_use = '';
51 my $addl_handler_use_file = '%%%FREESIDE_CONF%%%/addl_handler_use.pl';
52 if ( -e $addl_handler_use_file ) {
53 $FS::Mason::addl_handler_use = slurp( $addl_handler_use_file );
56 # Create Mason objects
59 request_class => 'HTML::Mason::Request::ApacheHandler',
60 data_dir => '%%%MASONDATA%%%',
61 error_mode => 'output',
62 error_format => 'html',
63 ignore_warnings_expr => '.',
65 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
66 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
71 my $fs_interp = new HTML::Mason::Interp (
73 escape_flags => { 'js_string' => sub {
74 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
75 ${$_[0]} =~ s/(['\\])/\\$1/g;
76 ${$_[0]} =~ s/\n/\\n/g;
77 ${$_[0]} = "'". ${$_[0]}. "'";
82 my $rt_interp = new HTML::Mason::Interp (
84 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
85 compiler => HTML::Mason::Compiler::ToObject->new(
86 default_escape_flags => 'h',
87 allow_globals => [qw(%session)],
91 my $ah = new HTML::Mason::ApacheHandler (
93 args_method => 'CGI', #(and FS too)
96 # Activate the following if running httpd as root (the normal case).
97 # Resets ownership of all files created by Mason at startup.
99 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
105 # If you plan to intermix images in the same directory as
106 # components, activate the following to prevent Mason from
107 # evaluating image files as components.
109 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
112 { package HTML::Mason::Commands;
114 use vars qw( $cgi $p $fsurl);
115 use vars qw( %session );
116 use CGI 3.29 qw(-private_tempfiles); #3.29 to fix RT attachment problems
118 #breaks quick payment entry
119 #http://rt.cpan.org/Public/Bug/Display.html?id=37365
120 die "CGI.pm v3.38 is broken, use any other version >= 3.29".
121 " (Debian 5.0? aptitude remove libcgi-pm-perl)"
122 if $CGI::VERSION == 3.38;
124 #use CGI::Carp qw(fatalsToBrowser);
125 use List::Util qw( max min );
131 use DateTime::Format::Strptime;
132 use Lingua::EN::Inflect qw(PL);
137 use HTML::TreeBuilder;
138 use HTML::FormatText;
143 use Net::Whois::Raw qw(whois);
145 eval "use Net::Whois::Raw 0.32 qw(whois)";
149 use Spreadsheet::WriteExcel;
150 use Business::CreditCard 0.30; #for mask-aware cardtype()
152 use String::Approx qw(amatch);
153 use Chart::LinesPoints;
156 use HTML::Widgets::SelectLayers 0.07;
159 use FS::UID qw( adminsuidsetup cgisuidsetup getotaker
160 dbh datasrc driver_name
162 use FS::Record qw( qsearch qsearchs fields dbdef
163 str2time_sql str2time_sql_closing
166 use FS::CGI qw(header menubar popurl rooturl table itable ntable idiot
167 eidiot myexit http_header);
168 use FS::UI::Web qw(svc_url);
169 use FS::UI::Web::small_custview qw(small_custview);
170 use FS::UI::bytecount;
171 use FS::Msgcat qw(gettext geterror);
172 use FS::Misc qw( send_email send_fax states_hash counties state_label );
173 use FS::Report::Table::Monthly;
174 use FS::TicketSystem;
178 use FS::domain_record;
180 use FS::cust_bill_pay;
182 use FS::cust_credit_bill;
183 use FS::cust_main qw(smart_search);
184 use FS::cust_main_county;
185 use FS::part_pkg_taxclass;
188 use FS::cust_pkg_reason;
190 use FS::cust_credit_refund;
191 use FS::cust_pay_refund;
194 use FS::part_bill_event;
196 use FS::part_referral;
198 use FS::part_svc_router;
199 use FS::part_virtual_field;
203 use FS::queue qw(joblisting);
207 use FS::svc_acct_pop qw(popselector);
213 use FS::svc_broadband;
214 use FS::svc_external;
217 use FS::part_export_option;
223 use FS::payment_gateway;
224 use FS::agent_payment_gateway;
228 use FS::inventory_class;
229 use FS::inventory_item;
232 use FS::access_group;
233 use FS::access_usergroup;
234 use FS::access_groupagent;
235 use FS::access_right;
240 use FS::cust_main_note;
242 if ( $FS::Mason::addl_handler_use ) {
243 eval $FS::Mason::addl_handler_use;
247 if ( %%%RT_ENABLED%%% ) {
250 use RT::Transactions;
255 use RT::ScripActions;
256 use RT::ScripConditions;
259 use RT::GroupMembers;
260 use RT::CustomFields;
261 use RT::CustomFieldValues;
262 use RT::ObjectCustomFieldValues;
264 use RT::Interface::Web;
270 #use Text::Quoted; #slow, unreliable, segfaults and is optional
276 *CGI::redirect = sub {
277 my( $self, $location ) = @_;
280 # false laziness w/below
281 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
284 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
286 ( UNIVERSAL::can(dbh, 'sprintProfile')
287 ? encode_entities(dbh->sprintProfile())
288 : 'DBIx::Profile missing sprintProfile method;'.
289 'unpatched or too old?' ).
290 #"\n\n". &sprintAutoProfile(). '</PRE>'.
293 dbh->{'private_profile'} = {};
296 } else { #normal redirect
298 $m->redirect($location);
305 if ( $HTML::Mason::r->filename !~ /\/rt\/.*NoAuth/ ) { #not RT images/JS
313 } elsif ( $HTML::Mason::r->filename =~ /\/rt\/REST\/.*NoAuth/ ) {
315 #need to log somebody in for the mail gw
317 ##old installs w/fs_selfs or selfserv??
318 #&adminsuidsetup('fs_selfservice');
320 &adminsuidsetup('fs_queue');
331 $m->comp('/elements/errorpage.html', @_);
335 my( $location ) = @_;
338 #false laziness w/above
339 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
342 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
344 ( UNIVERSAL::can(dbh, 'sprintProfile')
345 ? encode_entities(dbh->sprintProfile())
346 : 'DBIx::Profile missing sprintProfile method;'.
347 'unpatched or too old?' ).
348 #"\n\n". &sprintAutoProfile(). '</PRE>'.
352 dbh->{'private_profile'} = {};
354 #whew. removing this is all that's needed to fix the annoying
355 #blank-page-instead-of-profiling-redirect-when-called-from-an-include
356 #bug triggered by mason 1.32
357 #my $rv = $m->abort(200);
359 } else { #normal redirect
361 $m->redirect($location);
367 } # end package HTML::Mason::Commands;
369 ###Module::Refresh->refresh;###
371 #$r->content_type('text/html; charset=utf-8');
372 $r->content_type('text/html; charset=iso-8859-1');
375 my $headers = $r->headers_out;
376 $headers->{'Cache-control'} = 'no-cache';
378 $headers->{'Expires'} = '0';
380 # $r->send_http_header;
382 if ( $r->filename =~ /\/rt\// ) { #RT
384 $ah->interp($rt_interp);
386 local $SIG{__WARN__};
391 # We don't need to handle non-text, non-xml items
392 return -1 if defined( $r->content_type )
393 && $r->content_type !~ m!(^text/|\bxml\b)!io;
397 $ah->interp($fs_interp);
403 eval { $status = $ah->handle_request($r); };
406 # $RT::Logger->crit($@);
413 # if ($RT::Handle->TransactionDepth) {
414 # $RT::Handle->ForceRollback;
416 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"