remove Pragma:no-cache header, and set Content-Length and Cache-Control for viewing...
[freeside.git] / htetc / handler.pl
1 #!/usr/bin/perl
2 #
3 # This is a basic, fairly fuctional Mason handler.pl.
4 #
5 # For something a little more involved, check out session_handler.pl
6
7 package HTML::Mason;
8
9 # Bring in main Mason package.
10 use HTML::Mason 1.1;
11
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');
17
18 # Uncomment the next line if you plan to use the Mason previewer.
19 #use HTML::Mason::Preview;
20
21 use strict;
22
23 # List of modules that you want to use from components (see Admin
24 # manual for details)
25 #{  package HTML::Mason::Commands;
26 #   use CGI;
27 #}
28
29 # Create Mason objects
30 #
31
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',
36 #                                      out_mode=>'stream',
37 #                                     );
38 my $ah = new HTML::Mason::ApacheHandler (
39   #interp => $interp,
40   #auto_send_headers => 0,
41   comp_root=>'%%%FREESIDE_DOCUMENT_ROOT%%%',
42   data_dir=>'/usr/local/etc/freeside/masondata',
43   #out_mode=>'stream',
44 );
45
46 # Activate the following if running httpd as root (the normal case).
47 # Resets ownership of all files created by Mason at startup.
48 #
49 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
50
51 sub handler
52 {
53     my ($r) = @_;
54
55     # If you plan to intermix images in the same directory as
56     # components, activate the following to prevent Mason from
57     # evaluating image files as components.
58     #
59     #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
60
61     #rar
62     { package HTML::Mason::Commands;
63       use strict;
64       use vars qw( $cgi $p );
65       use CGI 2.47;
66       #use CGI::Carp qw(fatalsToBrowser);
67       use Date::Format;
68       use Date::Parse;
69       use Time::Local;
70       use Tie::IxHash;
71       use HTML::Entities;
72       use IO::Handle;
73       use IO::File;
74       use Business::CreditCard;
75       use String::Approx qw(amatch);
76       use Chart::LinesPoints;
77       use HTML::Widgets::SelectLayers 0.03;
78       use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
79       use FS::Record qw(qsearch qsearchs fields dbdef);
80       use FS::Conf;
81       use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
82                      small_custview myexit http_header);
83       use FS::Msgcat qw(gettext geterror);
84       use FS::Misc qw( send_email );
85       use FS::Report::Table::Monthly;
86
87       use FS::agent;
88       use FS::agent_type;
89       use FS::domain_record;
90       use FS::cust_bill;
91       use FS::cust_bill_pay;
92       use FS::cust_credit;
93       use FS::cust_credit_bill;
94       use FS::cust_main;
95       use FS::cust_main_county;
96       use FS::cust_pay;
97       use FS::cust_pkg;
98       use FS::cust_refund;
99       use FS::cust_svc;
100       use FS::nas;
101       use FS::part_bill_event;
102       use FS::part_pkg;
103       use FS::part_referral;
104       use FS::part_svc;
105       use FS::part_svc_router;
106       use FS::part_virtual_field;
107       use FS::pkg_svc;
108       use FS::port;
109       use FS::queue qw(joblisting);
110       use FS::raddb;
111       use FS::session;
112       use FS::svc_acct;
113       use FS::svc_acct_pop qw(popselector);
114       use FS::svc_domain;
115       use FS::svc_forward;
116       use FS::svc_www;
117       use FS::router;
118       use FS::addr_block;
119       use FS::svc_broadband;
120       use FS::svc_external;
121       use FS::type_pkgs;
122       use FS::part_export;
123       use FS::part_export_option;
124       use FS::export_svc;
125       use FS::msgcat;
126
127       *CGI::redirect = sub {
128         my( $self, $location ) = @_;
129         use vars qw($m);
130
131         if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
132
133           my $page =
134             qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
135             '<BR><BR><PRE>'.
136               ( UNIVERSAL::can(dbh, 'sprintProfile')
137                   ? encode_entities(dbh->sprintProfile())
138                   : 'DBIx::Profile missing sprintProfile method;'.
139                     'unpatched or too old?'                        ).
140             #"\n\n". &sprintAutoProfile().  '</PRE>'.
141             "\n\n".                         '</PRE>'.
142             '</BODY></HTML>';
143           dbh->{'private_profile'} = {};
144           return $page;
145
146         } else { #normal redirect
147
148           $m->redirect($location);
149           '';
150
151         }
152
153       };
154
155       $cgi = new CGI;
156       &cgisuidsetup($cgi);
157       #&cgisuidsetup($r);
158       $p = popurl(2);
159
160       sub include {
161         use vars qw($m);
162         $m->scomp(@_);
163       }
164
165       sub redirect {
166         my( $location ) = @_;
167         use vars qw($m);
168         $m->clear_buffer;
169         #false laziness w/above
170         if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
171
172           $m->print(
173             qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
174             '<BR><BR><PRE>'.
175               ( UNIVERSAL::can(dbh, 'sprintProfile')
176                   ? encode_entities(dbh->sprintProfile())
177                   : 'DBIx::Profile missing sprintProfile method;'.
178                     'unpatched or too old?'                        ).
179             #"\n\n". &sprintAutoProfile().  '</PRE>'.
180             "\n\n".                         '</PRE>'.
181             '</BODY></HTML>'
182           );
183           dbh->{'private_profile'} = {};
184
185           $m->abort(200);
186
187         } else { #normal redirect
188
189           $m->redirect($location);
190
191         }
192
193       }
194
195     } # end package HTML::Mason::Commands;
196
197     $r->content_type('text/html');
198     #eorar
199
200     my $headers = $r->headers_out;
201     $headers->{'Cache-control'} = 'no-cache';
202     #$r->no_cache(1);
203     $headers->{'Expires'} = '0';
204
205 #    $r->send_http_header;
206
207     my $status = $ah->handle_request($r);
208
209     $status;
210 }
211
212 1;