0.32 (and then some) released
[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;
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 Net::Whois::Raw qw(whois);
75       if ( $] < 5.006 ) {
76         eval "use Net::Whois::Raw 0.32 qw(whois)";
77         die $@ if $@;
78       }
79       use Business::CreditCard;
80       use String::Approx qw(amatch);
81       use HTML::Widgets::SelectLayers 0.03;
82       use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
83       use FS::Record qw(qsearch qsearchs fields dbdef);
84       use FS::Conf;
85       use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
86                      small_custview myexit http_header);
87       use FS::Msgcat qw(gettext geterror);
88       use FS::Misc qw( send_email );
89
90       use FS::agent;
91       use FS::agent_type;
92       use FS::domain_record;
93       use FS::cust_bill;
94       use FS::cust_bill_pay;
95       use FS::cust_credit;
96       use FS::cust_credit_bill;
97       use FS::cust_main;
98       use FS::cust_main_county;
99       use FS::cust_pay;
100       use FS::cust_pkg;
101       use FS::cust_refund;
102       use FS::cust_svc;
103       use FS::nas;
104       use FS::part_bill_event;
105       use FS::part_pkg;
106       use FS::part_referral;
107       use FS::part_svc;
108       use FS::pkg_svc;
109       use FS::port;
110       use FS::queue qw(joblisting);
111       use FS::raddb;
112       use FS::session;
113       use FS::svc_acct;
114       use FS::svc_acct_pop qw(popselector);
115       use FS::svc_acct_sm;
116       use FS::svc_domain;
117       use FS::svc_forward;
118       use FS::svc_www;
119       use FS::type_pkgs;
120       use FS::part_export;
121       use FS::part_export_option;
122       use FS::export_svc;
123       use FS::msgcat;
124
125       *CGI::redirect = sub {
126         my( $self, $location ) = @_;
127         use vars qw($m);
128         #http://www.masonhq.com/docs/faq/#how_do_i_do_an_external_redirect
129         $m->clear_buffer;
130         # The next two lines are necessary to stop Apache from re-reading
131         # POSTed data.
132         $r->method('GET');
133         $r->headers_in->unset('Content-length');
134         $r->content_type('text/html');
135         #$r->err_header_out('Location' => $location);
136         $r->header_out('Location' => $location);
137          $r->header_out('Content-Type' => 'text/html');
138          $m->abort(302);
139
140         '';
141       };
142
143       $cgi = new CGI;
144       &cgisuidsetup($cgi);
145       #&cgisuidsetup($r);
146       $p = popurl(2);
147     }
148
149     $r->content_type('text/html');
150     #eorar
151
152     my $headers = $r->headers_out;
153     $headers->{'Cache-control'} = 'no-cache';
154     #$r->no_cache(1);
155     $headers->{'Expires'} = '0';
156
157 #    $r->send_http_header;
158
159     my $status = $ah->handle_request($r);
160
161     $status;
162 }
163
164 1;