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 4.08 qw(-private_tempfiles); #4.08 for multi_param
50 #use CGI::Carp qw(fatalsToBrowser);
52 use List::Util qw( max min sum );
53 use List::MoreUtils qw( first_index uniq );
54 use Scalar::Util qw( blessed looks_like_number );
61 use DateTime::Format::Strptime;
62 use FS::Misc::DateTime qw( parse_datetime );
63 use FS::Misc::Geo qw( get_district );
64 use Lingua::EN::Inflect qw(PL);
65 Lingua::EN::Inflect::classical names=>0; #Categorys
70 use HTML::TreeBuilder;
71 use HTML::TableExtract qw(tree);
80 use File::Slurp qw( slurp );
81 #not actually using this yet anyway...# use IPC::Run3 0.036;
82 use Net::Whois::Raw qw(whois);
84 eval "use Net::Whois::Raw 0.32 qw(whois)";
89 use Spreadsheet::WriteExcel;
90 use Spreadsheet::WriteExcel::Utility;
91 use OLE::Storage_Lite;
92 use Excel::Writer::XLSX;
93 #use Excel::Writer::XLSX::Utility; #redundant with above
95 use Business::CreditCard 0.36; #for best-effort cardtype() (60xx as Discover)
99 use Net::Ping::External;
100 #if CPAN #7815 ever gets fixed# if ( $Net::Ping::External::VERSION <= 0.12 )
102 no warnings 'redefine';
103 eval 'sub Net::Ping::External::_ping_linux {
105 my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}";
106 return Net::Ping::External::_ping_system($command, 0);
111 use String::Approx qw(amatch);
112 use Chart::LinesPoints;
116 use HTML::Widgets::SelectLayers 0.07; #should go away in favor of
119 #use FS::geocode_Mixin; #for its code2country
120 use Locale::Currency;
121 use Locale::Currency::Format;
122 use Number::Phone::Country qw( noexport );
123 use Business::US::USPS::WebTools::AddressStandardization;
124 use Geo::GoogleEarth::Pluggable 0.16;
127 use Geo::JSON::FeatureCollection;
129 use Storable qw( nfreeze thaw );
131 use FS::UID qw( dbh datasrc driver_name );
132 use FS::Record qw( qsearch qsearchs fields dbdef
133 str2time_sql str2time_sql_closing
134 midnight_sql regexp_sql
137 use FS::ConfDefaults;
138 use FS::CGI qw(header menubar table itable ntable idiot
139 eidiot myexit http_header);
140 use FS::UI::Web qw(svc_url random_id
141 get_page_pref set_page_pref);
142 use FS::UI::Web::small_custview qw(small_custview);
143 use FS::UI::bytecount;
144 use FS::UI::REST qw( rest_auth rest_uri_remain encode_rest );
145 use FS::Msgcat qw(gettext geterror);
146 use FS::Misc qw( send_email send_fax ocr_image
147 states_hash counties cities state_label
150 use FS::Misc::eps2png qw( eps2png );
151 use FS::Report::FCC_477;
152 use FS::Report::Table;
153 use FS::Report::Table::Monthly;
154 use FS::Report::Table::Daily;
155 use FS::Report::Tax::ByName;
156 use FS::Report::Tax::All;
157 use FS::TicketSystem;
158 use FS::NetworkMonitoringSystem;
159 use FS::Tron qw( tron_lint );
161 use FS::Maketext qw( mt emt js_mt );
167 use FS::domain_record;
169 use FS::cust_bill_pay;
171 use FS::cust_credit_bill;
174 use FS::cust_main::Search qw(smart_search);
175 use FS::cust_main::Import;
176 use FS::cust_main::Import_Charges;
177 use FS::cust_main_county;
178 use FS::cust_location;
181 use FS::cust_pkg::Import;
182 use FS::part_pkg_taxclass;
183 use FS::cust_pkg_reason;
185 use FS::cust_credit_refund;
186 use FS::cust_pay_refund;
190 use FS::part_event_condition;
192 use FS::part_referral;
194 use FS::part_svc_router;
195 use FS::part_virtual_field;
199 use FS::queue qw(joblisting);
203 use FS::svc_acct_pop qw(popselector);
204 use FS::acct_rt_transaction;
210 use FS::svc_broadband;
211 use FS::svc_external;
214 use FS::part_export_option;
216 use FS::export_device;
223 use FS::payment_gateway;
224 use FS::agent_payment_gateway;
228 use FS::inventory_class;
229 use FS::inventory_item;
230 use FS::pkg_category;
233 use FS::access_user_pref;
234 use FS::access_group;
235 use FS::access_usergroup;
236 use FS::access_groupagent;
237 use FS::access_right;
240 use FS::phone_device;
244 use FS::cust_main_note;
246 use FS::cust_tax_location;
247 use FS::part_pkg_taxproduct;
248 use FS::part_pkg_taxoverride;
249 use FS::part_pkg_taxrate;
251 use FS::part_pkg_report_option;
252 use FS::cust_attachment;
254 use FS::h_inventory_item;
256 use FS::h_svc_broadband;
257 use FS::h_svc_domain;
258 #use FS::h_domain_record;
259 use FS::h_svc_external;
260 use FS::h_svc_forward;
262 #use FS::h_phone_device;
264 use FS::cust_statement;
266 use FS::cust_category;
267 use FS::prospect_main;
269 use FS::contact::Import;
273 use FS::cust_pkg_discount;
274 use FS::cust_bill_pkg_discount;
275 use FS::svc_mailinglist;
277 use FS::cgp_rule_condition;
278 use FS::cgp_rule_action;
280 use FS::cust_bill_batch;
282 use FS::rate_time_interval;
283 use FS::msg_template;
286 use FS::part_pkg_discount;
292 use FS::part_pkg_vendor;
293 use FS::cust_note_class;
298 use FS::torrus_srvderive;
299 use FS::torrus_srvderive_component;
303 use FS::svc_hardware;
304 use FS::h_svc_hardware;
305 use FS::hardware_class;
306 use FS::hardware_type;
307 use FS::hardware_status;
308 use FS::did_order_item;
312 use FS::radius_group;
313 use FS::template_content;
318 use FS::legacy_cust_bill;
320 use FS::rate_tier_detail;
322 use FS::discount_plan;
324 use FS::tower_sector;
326 use FS::contact_class;
327 use FS::part_svc_class;
328 use FS::upload_target;
330 use FS::quotation_pkg;
331 use FS::quotation_pkg_discount;
332 use FS::cust_bill_void;
333 use FS::cust_bill_pkg_void;
334 use FS::cust_bill_pkg_detail_void;
335 use FS::cust_bill_pkg_display_void;
336 use FS::cust_bill_pkg_tax_location_void;
337 use FS::cust_bill_pkg_tax_rate_location_void;
338 use FS::cust_tax_exempt_pkg_void;
339 use FS::cust_bill_pkg_discount_void;
340 use FS::agent_pkg_class;
341 use FS::svc_export_machine;
342 use FS::GeocodeCache;
345 use FS::part_pkg_usage_class;
346 use FS::cust_pkg_usage;
347 use FS::part_pkg_usage_class;
348 use FS::part_pkg_usage;
349 use FS::cdr_cust_pkg_usage;
350 use FS::part_pkg_msgcat;
352 use FS::agent_currency;
353 use FS::currency_exchange;
354 use FS::part_pkg_currency;
360 use FS::vend_bill_pay;
361 use FS::sales_pkg_class;
364 use FS::invoice_mode;
365 use FS::invoice_conf;
366 use FS::cable_provider;
367 use FS::cust_credit_void;
368 use FS::discount_class;
369 use FS::alarm_system;
371 use FS::alarm_station;
373 use FS::svc_conferencing;
374 use FS::conferencing_type;
375 use FS::conferencing_quality;
377 use FS::part_pkg_usageprice;
378 use FS::cust_pkg_usageprice;
379 use FS::pbx_extension;
381 use FS::extension_device;
382 use FS::cust_main_credit_limit;
383 use FS::cust_event_fee;
385 use FS::cust_bill_pkg_fee;
386 use FS::part_fee_msgcat;
387 use FS::part_fee_usage;
390 use FS::export_batch;
391 use FS::export_batch_item;
392 use FS::part_pkg_fcc_option;
396 use FS::deploy_zone_block;
397 use FS::deploy_zone_vertex;
400 use FS::circuit_type;
401 use FS::circuit_provider;
402 use FS::circuit_termination;
404 use FS::cust_credit_source_bill_pkg;
405 use FS::prospect_contact;
406 use FS::cust_contact;
407 use FS::legacy_cust_history;
408 use FS::quotation_pkg_tax;
409 use FS::cust_pkg_reason_fee;
410 use FS::part_svc_link;
411 use FS::access_user_log;
412 use FS::report_batch;
413 use FS::report_batch;
414 use FS::report_batch;
415 use FS::report_batch;
416 use FS::password_history;
420 use FS::access_user_page_pref;
421 use FS::part_svc_msgcat;
422 use FS::commission_schedule;
423 use FS::commission_rate;
424 use FS::realestate_location;
425 use FS::realestate_unit;
426 use FS::svc_realestate;
427 use FS::saved_search;
428 use FS::sector_coverage;
430 use FS::Misc::DepositSlip qw( deposit_slip_pdf );
433 if ( $FS::Mason::addl_handler_use ) {
434 eval $FS::Mason::addl_handler_use;
438 if ( %%%RT_ENABLED%%% ) {
440 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
441 use vars qw($Nobody $SystemUser);
445 use RT::Transactions;
450 use RT::ScripActions;
451 use RT::ScripConditions;
454 use RT::GroupMembers;
455 use RT::CustomFields;
456 use RT::CustomFieldValues;
457 use RT::ObjectCustomFieldValues;
459 use RT::Interface::Web::Handler;
461 #blah. not even in RT::Interface::Web::Handler, just in
462 #html/NoAuth/css/dhandler and rt-test-dependencies. ask for it here
463 #to throw a real error instead of just a mysterious unstyled RT
464 use CSS::Squish 0.06;
466 #another undeclared web UI dep (for ticket links graph)
467 use IPC::Run::SafeHandles;
469 #slow, unreliable, segfaults and is optional
470 #see rt/html/Ticket/Elements/ShowTransactionAttachments
473 #?#use File::Path qw( rmtree );
474 #?#use File::Glob qw( bsd_glob );
475 #?#use File::Spec::Unix;
481 no warnings 'redefine';
482 *CGI::redirect = sub {
488 if ( $_[0] =~ /^-/ ) {
490 $location = $opt{'-uri'};
491 my $cookie = $opt{'-cookie'};
492 $m->apache_req->err_headers_out->{'Set-cookie'} = $cookie if $cookie;
497 # false laziness w/below
498 if ( @DBIx::Profile::ISA ) {
500 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
505 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
507 ( UNIVERSAL::can(dbh, 'sprintProfile')
508 ? encode_entities(dbh->sprintProfile())
509 : 'DBIx::Profile missing sprintProfile method;'.
510 'unpatched or too old?' ).
511 #"\n\n". &sprintAutoProfile(). '</PRE>'.
516 dbh->{'private_profile'} = {};
521 #clear db profile, but normal redirect
522 dbh->{'private_profile'} = {};
523 $m->redirect($location);
528 } else { #normal redirect
530 $m->redirect($location);
539 #warn 'include deprecated; use an HTML::Mason <& &> style include (or $m->scomp) at '. $m->callers(0)->path. "\n";
545 $m->comp('/elements/errorpage.html', @_);
548 sub errorpage_popup {
550 $m->comp('/elements/errorpage-popup.html', @_);
554 my( $location ) = @_;
557 #false laziness w/above
558 if ( @DBIx::Profile::ISA ) {
560 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
565 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
567 ( UNIVERSAL::can(dbh, 'sprintProfile')
568 ? encode_entities(dbh->sprintProfile())
569 : 'DBIx::Profile missing sprintProfile method;'.
570 'unpatched or too old?' ).
571 #"\n\n". &sprintAutoProfile(). '</PRE>'.
576 dbh->{'private_profile'} = {};
580 #clear db profile, but normal redirect
581 dbh->{'private_profile'} = {};
582 $m->redirect($location);
586 } else { #normal redirect
588 $m->redirect($location);
594 } # end package HTML::Mason::Commands;
600 =item mason_interps [ MODE [ OPTION => VALUE ... ] ]
602 Returns a list consisting of two HTML::Mason::Interp objects, the first for
603 Freeside pages, and the second for RT pages.
605 MODE can be 'apache' or 'standalone'. If not specified, defaults to 'apache'.
607 Options and values can be passed following mode. Currently available options
610 I<outbuf> should be set to a scalar reference in standalone mode.
614 my %defang_opts = ( attribs_to_callback => ['src'], attribs_callback => sub { 1 });
617 my $mode = shift || 'apache';
620 #my $request_class = 'HTML::Mason::Request'.
621 #( $mode eq 'apache' ? '::ApacheHandler' : '' );
622 my $request_class = $mode eq 'standalone' ? 'FS::Mason::StandaloneRequest'
623 : 'FS::Mason::Request';
625 #not entirely sure it belongs here, but what the hey
626 if ( %%%RT_ENABLED%%% && $mode ne 'standalone' ) {
630 my $fs_comp_root = '%%%FREESIDE_DOCUMENT_ROOT%%%';
633 request_class => $request_class,
634 data_dir => '%%%MASONDATA%%%',
635 error_mode => 'output',
636 error_format => 'html',
637 ignore_warnings_expr => '.',
640 $interp{out_method} = $opt{outbuf} if $mode eq 'standalone' && $opt{outbuf};
642 my $html_defang = new HTML::Defang (%defang_opts);
644 #false laziness w/ FS::Maketext js_mt
645 my $js_string_sub = sub {
646 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
647 ${$_[0]} =~ s/(['\\])/\\$1/g;
648 ${$_[0]} =~ s/\r/\\r/g;
649 ${$_[0]} =~ s/\n/\\n/g;
650 # prevent premature termination of the script
651 ${$_[0]} =~ s[</script>][<\\/script>]ig;
652 ${$_[0]} = "'". ${$_[0]}. "'";
655 my $defang_sub = sub {
656 ${$_[0]} = $html_defang->defang(${$_[0]});
659 my $fs_interp = new HTML::Mason::Interp (
661 comp_root => $fs_comp_root,
662 escape_flags => { 'js_string' => $js_string_sub,
663 'defang' => $defang_sub,
665 compiler => HTML::Mason::Compiler::ToObject->new(
666 allow_globals => [qw(%session)],
670 my $rt_interp = new HTML::Mason::Interp (
673 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
674 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
676 escape_flags => { 'h' => \&RT::Interface::Web::EscapeHTML,
677 #u and j aren't used anymore? :/
678 'u' => \&RT::Interface::Web::EscapeURI,
679 'j' => \&RT::Interface::Web::EscapeJS,
680 'js_string' => $js_string_sub,
682 compiler => HTML::Mason::Compiler::ToObject->new(
683 default_escape_flags => 'h',
684 allow_globals => [qw(%session $DECODED_ARGS)],
688 ( $fs_interp, $rt_interp );
694 Per-process Apache child initialization code.
696 Calls srand() to re-seed Perl's PRNG so that multiple children do not generate
697 the same "random" numbers.
699 Works around a Net::SSLeay connection error by creating and deleting an SSL
700 context, so subsequent connections do not error out with a CTX_new (900 NET OR
701 SSL ERROR). See http://bugs.debian.org/830152
706 #my ($pool, $server) = @_; #the child process pool (APR::Pool) and the server object (Apache2::ServerRec).
714 my $bad_ctx = new_x_ctx();
715 while ( ERR_get_error() ) {}; #print_errs('CTX_new');
725 Lurking in the darkness...
729 L<HTML::Mason>, L<FS>, L<RT>