4 use vars qw( @ISA @EXPORT_OK $addl_handler_use );
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 @ISA = qw( Exporter );
13 @EXPORT_OK = qw( mason_interps );
17 FS::Mason - Initialize the Mason environment
21 use FS::Mason qw( mason_interps );
23 my( $fs_interp, $rt_interp ) = mason_interps('apache');
27 my( $fs_interp, $rt_interp ) = mason_interps('standalone'); #XXX name?
31 Initializes the Mason environment, loads all Freeside and RT libraries, etc.
35 $addl_handler_use = '';
36 my $addl_handler_use_file = '%%%FREESIDE_CONF%%%/addl_handler_use.pl';
37 if ( -e $addl_handler_use_file ) {
38 $addl_handler_use = slurp( $addl_handler_use_file );
41 # List of modules that you want to use from components (see Admin
44 package HTML::Mason::Commands;
47 use vars qw( %session );
48 use CGI 3.29 qw(-private_tempfiles); #3.29 to fix RT attachment problems
50 #breaks quick payment entry
51 #http://rt.cpan.org/Public/Bug/Display.html?id=37365
52 die "CGI.pm v3.38 is broken, use any other version >= 3.29".
53 " (Debian 5.0? aptitude remove libcgi-pm-perl)"
54 if $CGI::VERSION == 3.38;
56 #use CGI::Carp qw(fatalsToBrowser);
58 use List::Util qw( max min sum );
59 use List::MoreUtils qw( first_index uniq );
60 use Scalar::Util qw( blessed looks_like_number );
67 use DateTime::Format::Strptime;
68 use FS::Misc::DateTime qw( parse_datetime );
69 use FS::Misc::Geo qw( get_district );
70 use Lingua::EN::Inflect qw(PL);
71 Lingua::EN::Inflect::classical names=>0; #Categorys
76 use HTML::TreeBuilder;
77 use HTML::TableExtract qw(tree);
81 # use XMLRPC::Transport::HTTP;
82 # use XMLRPC::Lite; # for XMLRPC::Serializer
88 use File::Slurp qw( slurp );
89 #not actually using this yet anyway...# use IPC::Run3 0.036;
90 use Net::Whois::Raw qw(whois);
92 eval "use Net::Whois::Raw 0.32 qw(whois)";
97 use Spreadsheet::WriteExcel;
98 use Spreadsheet::WriteExcel::Utility;
99 use OLE::Storage_Lite;
100 use Excel::Writer::XLSX;
101 #use Excel::Writer::XLSX::Utility; #redundant with above
103 use Business::CreditCard 0.35; #for new mastercard ranges and visa lengths
105 use Net::MAC::Vendor;
107 use Net::Ping::External;
108 #if CPAN #7815 ever gets fixed# if ( $Net::Ping::External::VERSION <= 0.12 )
110 no warnings 'redefine';
111 eval 'sub Net::Ping::External::_ping_linux {
113 my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}";
114 return Net::Ping::External::_ping_system($command, 0);
119 use String::Approx qw(amatch);
120 use Chart::LinesPoints;
124 use HTML::Widgets::SelectLayers 0.07; #should go away in favor of
127 use Number::Phone::Country qw( noexport );
128 use Business::US::USPS::WebTools::AddressStandardization;
129 use Geo::GoogleEarth::Pluggable 0.16;
132 use Geo::JSON::FeatureCollection;
134 use Storable qw( nfreeze thaw );
136 use FS::UID qw( getotaker dbh datasrc driver_name );
137 use FS::Record qw( qsearch qsearchs fields dbdef
138 str2time_sql str2time_sql_closing
139 midnight_sql regexp_sql
142 use FS::CGI qw(header menubar table itable ntable idiot
143 eidiot myexit http_header);
144 use FS::UI::Web qw(svc_url random_id
145 get_page_pref set_page_pref);
146 use FS::UI::Web::small_custview qw(small_custview);
147 use FS::UI::bytecount;
148 use FS::Msgcat qw(gettext geterror);
149 use FS::Misc qw( send_email send_fax ocr_image
150 states_hash counties cities state_label
153 use FS::Misc::eps2png qw( eps2png );
154 use FS::Report::FCC_477;
155 use FS::Report::Table;
156 use FS::Report::Table::Monthly;
157 use FS::Report::Table::Daily;
158 use FS::Report::Tax::ByName;
159 use FS::Report::Tax::All;
160 use FS::TicketSystem;
161 use FS::NetworkMonitoringSystem;
162 use FS::Tron qw( tron_lint );
164 use FS::Maketext qw( mt emt js_mt );
170 use FS::domain_record;
172 use FS::cust_bill_pay;
174 use FS::cust_credit_bill;
177 use FS::cust_main::Search qw(smart_search);
178 use FS::cust_main::Import;
179 use FS::cust_main::Import_Charges;
180 use FS::cust_main_county;
181 use FS::cust_location;
184 use FS::cust_pkg::Import;
185 use FS::part_pkg_taxclass;
186 use FS::cust_pkg_reason;
188 use FS::cust_credit_refund;
189 use FS::cust_pay_refund;
192 use FS::part_bill_event;
194 use FS::part_event_condition;
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);
208 use FS::acct_rt_transaction;
214 use FS::svc_broadband;
215 use FS::svc_external;
218 use FS::part_export_option;
220 use FS::export_device;
227 use FS::payment_gateway;
228 use FS::agent_payment_gateway;
233 use FS::inventory_class;
234 use FS::inventory_item;
235 use FS::pkg_category;
238 use FS::access_user_pref;
239 use FS::access_group;
240 use FS::access_usergroup;
241 use FS::access_groupagent;
242 use FS::access_right;
245 use FS::phone_device;
249 use FS::cust_main_note;
251 use FS::cust_tax_location;
252 use FS::part_pkg_taxproduct;
253 use FS::part_pkg_taxoverride;
254 use FS::part_pkg_taxrate;
256 use FS::part_pkg_report_option;
257 use FS::cust_attachment;
259 use FS::h_inventory_item;
261 use FS::h_svc_broadband;
262 use FS::h_svc_domain;
263 #use FS::h_domain_record;
264 use FS::h_svc_external;
265 use FS::h_svc_forward;
267 #use FS::h_phone_device;
269 use FS::cust_statement;
271 use FS::cust_category;
272 use FS::prospect_main;
277 use FS::cust_pkg_discount;
278 use FS::cust_bill_pkg_discount;
279 use FS::svc_mailinglist;
281 use FS::cgp_rule_condition;
282 use FS::cgp_rule_action;
284 use FS::cust_bill_batch;
286 use FS::rate_time_interval;
287 use FS::msg_template;
290 use FS::part_pkg_discount;
296 use FS::part_pkg_vendor;
297 use FS::cust_note_class;
302 use FS::torrus_srvderive;
303 use FS::torrus_srvderive_component;
307 use FS::svc_hardware;
308 use FS::h_svc_hardware;
309 use FS::hardware_class;
310 use FS::hardware_type;
311 use FS::hardware_status;
312 use FS::did_order_item;
316 use FS::radius_group;
317 use FS::template_content;
322 use FS::legacy_cust_bill;
324 use FS::rate_tier_detail;
326 use FS::discount_plan;
328 use FS::tower_sector;
330 use FS::contact_class;
331 use FS::part_svc_class;
332 use FS::upload_target;
334 use FS::quotation_pkg;
335 use FS::quotation_pkg_discount;
336 use FS::cust_bill_void;
337 use FS::cust_bill_pkg_void;
338 use FS::cust_bill_pkg_detail_void;
339 use FS::cust_bill_pkg_display_void;
340 use FS::cust_bill_pkg_tax_location_void;
341 use FS::cust_bill_pkg_tax_rate_location_void;
342 use FS::cust_tax_exempt_pkg_void;
343 use FS::cust_bill_pkg_discount_void;
344 use FS::agent_pkg_class;
345 use FS::svc_export_machine;
346 use FS::GeocodeCache;
349 use FS::part_pkg_usage_class;
350 use FS::cust_pkg_usage;
351 use FS::part_pkg_usage_class;
352 use FS::part_pkg_usage;
353 use FS::cdr_cust_pkg_usage;
354 use FS::part_pkg_msgcat;
356 use FS::sales_pkg_class;
359 use FS::invoice_mode;
360 use FS::invoice_conf;
361 use FS::cable_provider;
362 use FS::cust_credit_void;
363 use FS::discount_class;
364 use FS::alarm_system;
366 use FS::alarm_station;
368 use FS::pbx_extension;
369 use FS::cust_event_fee;
371 use FS::cust_bill_pkg_fee;
372 use FS::part_fee_msgcat;
373 use FS::part_fee_usage;
376 use FS::export_batch;
377 use FS::export_batch_item;
378 use FS::part_pkg_fcc_option;
382 use FS::deploy_zone_block;
383 use FS::deploy_zone_vertex;
384 use FS::circuit_type;
385 use FS::circuit_provider;
386 use FS::circuit_termination;
388 use FS::legacy_cust_history;
389 use FS::quotation_pkg_tax;
390 use FS::cust_pkg_reason_fee;
391 use FS::access_user_log;
392 use FS::report_batch;
393 use FS::report_batch;
394 use FS::report_batch;
395 use FS::report_batch;
396 use FS::password_history;
400 use FS::access_user_page_pref;
401 use FS::part_svc_msgcat;
402 use FS::saved_search;
405 if ( $FS::Mason::addl_handler_use ) {
406 eval $FS::Mason::addl_handler_use;
410 if ( %%%RT_ENABLED%%% ) {
412 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
413 use vars qw($Nobody $SystemUser);
417 use RT::Transactions;
422 use RT::ScripActions;
423 use RT::ScripConditions;
426 use RT::GroupMembers;
427 use RT::CustomFields;
428 use RT::CustomFieldValues;
429 use RT::ObjectCustomFieldValues;
431 #blah. manually updated from RT::Interface::Web::Handler
432 use RT::Interface::Web;
439 #blah. not even in RT::Interface::Web::Handler, just in
440 #html/NoAuth/css/dhandler and rt-test-dependencies. ask for it here
441 #to throw a real error instead of just a mysterious unstyled RT
442 use CSS::Squish 0.06;
444 use RT::Interface::Web::Request;
446 #another undeclared web UI dep (for ticket links graph)
447 use IPC::Run::SafeHandles;
449 #slow, unreliable, segfaults and is optional
450 #see rt/html/Ticket/Elements/ShowTransactionAttachments
453 #?#use File::Path qw( rmtree );
454 #?#use File::Glob qw( bsd_glob );
455 #?#use File::Spec::Unix;
461 no warnings 'redefine';
462 *CGI::redirect = sub {
465 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
466 (my $x, $cookie) = (shift, shift);
467 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
469 my $location = shift;
473 # false laziness w/below
474 if ( @DBIx::Profile::ISA ) {
476 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
481 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
483 ( UNIVERSAL::can(dbh, 'sprintProfile')
484 ? encode_entities(dbh->sprintProfile())
485 : 'DBIx::Profile missing sprintProfile method;'.
486 'unpatched or too old?' ).
487 #"\n\n". &sprintAutoProfile(). '</PRE>'.
492 dbh->{'private_profile'} = {};
497 #clear db profile, but normal redirect
498 dbh->{'private_profile'} = {};
499 $m->redirect($location);
504 } else { #normal redirect
506 $m->redirect($location);
515 #carp #should just switch to <& &> syntax
521 $m->comp('/elements/errorpage.html', @_);
524 sub errorpage_popup {
526 $m->comp('/elements/errorpage-popup.html', @_);
530 my( $location ) = @_;
533 #false laziness w/above
534 if ( @DBIx::Profile::ISA ) {
536 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
541 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
543 ( UNIVERSAL::can(dbh, 'sprintProfile')
544 ? encode_entities(dbh->sprintProfile())
545 : 'DBIx::Profile missing sprintProfile method;'.
546 'unpatched or too old?' ).
547 #"\n\n". &sprintAutoProfile(). '</PRE>'.
552 dbh->{'private_profile'} = {};
556 #clear db profile, but normal redirect
557 dbh->{'private_profile'} = {};
558 $m->redirect($location);
562 } else { #normal redirect
564 $m->redirect($location);
570 } # end package HTML::Mason::Commands;
576 =item mason_interps [ MODE [ OPTION => VALUE ... ] ]
578 Returns a list consisting of two HTML::Mason::Interp objects, the first for
579 Freeside pages, and the second for RT pages.
581 MODE can be 'apache' or 'standalone'. If not specified, defaults to 'apache'.
583 Options and values can be passed following mode. Currently available options
586 I<outbuf> should be set to a scalar reference in standalone mode.
590 my %defang_opts = ( attribs_to_callback => ['src'], attribs_callback => sub { 1 });
593 my $mode = shift || 'apache';
596 #my $request_class = 'HTML::Mason::Request'.
597 #( $mode eq 'apache' ? '::ApacheHandler' : '' );
598 my $request_class = $mode eq 'standalone' ? 'FS::Mason::StandaloneRequest'
599 : 'FS::Mason::Request';
601 #not entirely sure it belongs here, but what the hey
602 if ( %%%RT_ENABLED%%% && $mode ne 'standalone' ) {
606 my $fs_comp_root = '%%%FREESIDE_DOCUMENT_ROOT%%%';
609 request_class => $request_class,
610 data_dir => '%%%MASONDATA%%%',
611 error_mode => 'output',
612 error_format => 'html',
613 ignore_warnings_expr => '.',
616 $interp{out_method} = $opt{outbuf} if $mode eq 'standalone' && $opt{outbuf};
618 my $html_defang = new HTML::Defang (%defang_opts);
620 #false laziness w/ FS::Maketext js_mt
621 my $js_string_sub = sub {
622 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
623 ${$_[0]} =~ s/(['\\])/\\$1/g;
624 ${$_[0]} =~ s/\r/\\r/g;
625 ${$_[0]} =~ s/\n/\\n/g;
626 # prevent premature termination of the script
627 ${$_[0]} =~ s[</script>][<\\/script>]ig;
628 ${$_[0]} = "'". ${$_[0]}. "'";
631 my $defang_sub = sub {
632 ${$_[0]} = $html_defang->defang(${$_[0]});
635 my $fs_interp = new HTML::Mason::Interp (
637 comp_root => $fs_comp_root,
638 escape_flags => { 'js_string' => $js_string_sub,
639 'defang' => $defang_sub,
641 compiler => HTML::Mason::Compiler::ToObject->new(
642 allow_globals => [qw(%session)],
646 my $rt_interp = new HTML::Mason::Interp (
649 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
650 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
652 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8,
653 'u' => \&RT::Interface::Web::EscapeURI,
654 'j' => \&RT::Interface::Web::EscapeJS,
655 'js_string' => $js_string_sub,
657 compiler => HTML::Mason::Compiler::ToObject->new(
658 default_escape_flags => 'h',
659 allow_globals => [qw(%session $DECODED_ARGS)],
663 ( $fs_interp, $rt_interp );
669 Per-process Apache child initialization code.
671 Calls srand() to re-seed Perl's PRNG so that multiple children do not generate
672 the same "random" numbers.
674 Works around a Net::SSLeay connection error by creating and deleting an SSL
675 context, so subsequent connections do not error out with a CTX_new (900 NET OR
676 SSL ERROR). See http://bugs.debian.org/830152
681 #my ($pool, $server) = @_; #the child process pool (APR::Pool) and the server object (Apache2::ServerRec).
689 my $bad_ctx = new_x_ctx();
690 while ( ERR_get_error() ) {}; #print_errs('CTX_new');
700 Lurking in the darkness...
704 L<HTML::Mason>, L<FS>, L<RT>