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);
102 use Net::Whois::Raw qw(whois);
104 eval "use Net::Whois::Raw 0.32 qw(whois)";
108 use Spreadsheet::WriteExcel;
109 use Business::CreditCard;
110 use String::Approx qw(amatch);
111 use Chart::LinesPoints;
112 use HTML::Widgets::SelectLayers 0.03;
114 use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
115 use FS::Record qw(qsearch qsearchs fields dbdef);
117 use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
118 small_custview myexit http_header);
120 use FS::Msgcat qw(gettext geterror);
121 use FS::Misc qw( send_email send_fax );
122 use FS::Report::Table::Monthly;
123 use FS::TicketSystem;
127 use FS::domain_record;
129 use FS::cust_bill_pay;
131 use FS::cust_credit_bill;
132 use FS::cust_main qw(smart_search);
133 use FS::cust_main_county;
139 use FS::part_bill_event;
141 use FS::part_referral;
143 use FS::part_svc_router;
144 use FS::part_virtual_field;
147 use FS::queue qw(joblisting);
151 use FS::svc_acct_pop qw(popselector);
157 use FS::svc_broadband;
158 use FS::svc_external;
161 use FS::part_export_option;
169 if ( %%%RT_ENABLED%%% ) {
172 use RT::Transactions;
177 use RT::ScripActions;
178 use RT::ScripConditions;
181 use RT::GroupMembers;
182 use RT::CustomFields;
183 use RT::CustomFieldValues;
184 use RT::TicketCustomFieldValues;
186 use RT::Interface::Web;
197 *CGI::redirect = sub {
198 my( $self, $location ) = @_;
201 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
204 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
206 ( UNIVERSAL::can(dbh, 'sprintProfile')
207 ? encode_entities(dbh->sprintProfile())
208 : 'DBIx::Profile missing sprintProfile method;'.
209 'unpatched or too old?' ).
210 #"\n\n". &sprintAutoProfile(). '</PRE>'.
213 dbh->{'private_profile'} = {};
216 } else { #normal redirect
218 $m->redirect($location);
225 unless ( $HTML::Mason::r->filename =~ /\/rt\/.*NoAuth/ ) { #RT
239 my( $location ) = @_;
242 #false laziness w/above
243 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
246 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
248 ( UNIVERSAL::can(dbh, 'sprintProfile')
249 ? encode_entities(dbh->sprintProfile())
250 : 'DBIx::Profile missing sprintProfile method;'.
251 'unpatched or too old?' ).
252 #"\n\n". &sprintAutoProfile(). '</PRE>'.
256 dbh->{'private_profile'} = {};
260 } else { #normal redirect
262 $m->redirect($location);
268 } # end package HTML::Mason::Commands;
270 $r->content_type('text/html');
273 my $headers = $r->headers_out;
274 $headers->{'Cache-control'} = 'no-cache';
276 $headers->{'Expires'} = '0';
278 # $r->send_http_header;
280 #$ah->interp->remove_escape('h');
282 if ( $r->filename =~ /\/rt\// ) { #RT
283 #warn "processing RT file". $r->filename. "; escaping for RT\n";
285 # MasonX::Request::ExtendedCompRoot
286 #$ah->interp->comp_root( '/rt'. $ah->interp->comp_root() );
288 $ah->interp->set_escape( h => \&RT::Interface::Web::EscapeUTF8 );
290 local $SIG{__WARN__};
295 # We don't need to handle non-text, non-xml items
296 return -1 if defined( $r->content_type ) && $r->content_type !~ m!(^text/|\bxml\b)!io;
299 $ah->interp->set_escape( 'h' => sub { ${$_[0]}; } );
304 eval { $status = $ah->handle_request($r); };
307 # $RT::Logger->crit($@);
313 # if ($RT::Handle->TransactionDepth) {
314 # $RT::Handle->ForceRollback;
316 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"