3 # This is a basic, fairly fuctional Mason handler.pl.
5 # For something a little more involved, check out session_handler.pl
9 # Bring in main Mason package.
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 # Uncomment the next line if you plan to use the Mason previewer.
19 #use HTML::Mason::Preview;
23 # List of modules that you want to use from components (see Admin
25 #{ package HTML::Mason::Commands;
29 # Create Mason objects
32 #my $parser = new HTML::Mason::Parser;
33 #my $interp = new HTML::Mason::Interp (parser=>$parser,
34 # comp_root=>'/var/www/masondocs',
35 # data_dir=>'/usr/local/etc/freeside/masondata',
41 if ( %%%RT_ENABLED%%% ) {
43 use lib ("/opt/rt3/local/lib", "/opt/rt3/lib");
45 use vars qw($Nobody $SystemUser);
54 my $ah = new HTML::Mason::ApacheHandler (
56 #auto_send_headers => 0,
58 [ 'freeside' => '%%%FREESIDE_DOCUMENT_ROOT%%%' ],
59 [ 'rt' => '%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
61 data_dir=>'/usr/local/etc/freeside/masondata',
66 default_escape_flags => 'h',
67 allow_globals => [qw(%session)],
71 # Activate the following if running httpd as root (the normal case).
72 # Resets ownership of all files created by Mason at startup.
74 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
80 # If you plan to intermix images in the same directory as
81 # components, activate the following to prevent Mason from
82 # evaluating image files as components.
84 #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
87 { package HTML::Mason::Commands;
89 use vars qw( $cgi $p );
90 use vars qw( %session );
91 use CGI 2.47 qw(-private_tempfiles);
92 #use CGI::Carp qw(fatalsToBrowser);
100 use Net::Whois::Raw qw(whois);
102 eval "use Net::Whois::Raw 0.32 qw(whois)";
105 use Business::CreditCard;
106 use String::Approx qw(amatch);
107 use Chart::LinesPoints;
108 use HTML::Widgets::SelectLayers 0.03;
109 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
110 use FS::Record qw(qsearch qsearchs fields dbdef);
112 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
113 small_custview myexit http_header);
114 use FS::Msgcat qw(gettext geterror);
115 use FS::Misc qw( send_email );
116 use FS::Report::Table::Monthly;
120 use FS::domain_record;
122 use FS::cust_bill_pay;
124 use FS::cust_credit_bill;
126 use FS::cust_main_county;
132 use FS::part_bill_event;
134 use FS::part_referral;
136 use FS::part_svc_router;
137 use FS::part_virtual_field;
140 use FS::queue qw(joblisting);
144 use FS::svc_acct_pop qw(popselector);
150 use FS::svc_broadband;
151 use FS::svc_external;
154 use FS::part_export_option;
158 if ( %%%RT_ENABLED%%% ) {
161 use RT::Transactions;
166 use RT::ScripActions;
167 use RT::ScripConditions;
170 use RT::GroupMembers;
171 use RT::CustomFields;
172 use RT::CustomFieldValues;
173 use RT::TicketCustomFieldValues;
175 use RT::Interface::Web;
184 *CGI::redirect = sub {
185 my( $self, $location ) = @_;
188 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
191 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
193 ( UNIVERSAL::can(dbh, 'sprintProfile')
194 ? encode_entities(dbh->sprintProfile())
195 : 'DBIx::Profile missing sprintProfile method;'.
196 'unpatched or too old?' ).
197 #"\n\n". &sprintAutoProfile(). '</PRE>'.
200 dbh->{'private_profile'} = {};
203 } else { #normal redirect
205 $m->redirect($location);
223 my( $location ) = @_;
226 #false laziness w/above
227 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
230 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
232 ( UNIVERSAL::can(dbh, 'sprintProfile')
233 ? encode_entities(dbh->sprintProfile())
234 : 'DBIx::Profile missing sprintProfile method;'.
235 'unpatched or too old?' ).
236 #"\n\n". &sprintAutoProfile(). '</PRE>'.
240 dbh->{'private_profile'} = {};
244 } else { #normal redirect
246 $m->redirect($location);
252 } # end package HTML::Mason::Commands;
254 $r->content_type('text/html');
257 my $headers = $r->headers_out;
258 $headers->{'Cache-control'} = 'no-cache';
260 $headers->{'Expires'} = '0';
262 # $r->send_http_header;
264 #$ah->interp->remove_escape('h');
266 if ( $r->filename =~ /\/rt\// ) { #RT
267 #warn "processing RT file". $r->filename. "; escaping for RT\n";
269 # MasonX::Request::ExtendedCompRoot
270 #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
272 $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
274 local $SIG{__WARN__};
279 # We don't need to handle non-text items
280 return -1 if defined( $r->content_type ) && $r->content_type !~ m|^text/|io;
283 $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
288 eval { $status = $ah->handle_request($r); };
291 # $RT::Logger->crit($@);
297 # if ($RT::Handle->TransactionDepth) {
298 # $RT::Handle->ForceRollback;
299 # $RT::Logger->crit("Transaction not committed. Usually indicates a software fault. Data loss may have occurred") ;