fix unlinked svc browse!
[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 my $parser = new HTML::Mason::Parser;
32 my $interp = new HTML::Mason::Interp (parser=>$parser,
33                                       comp_root=>'/var/www/masondocs',
34                                       data_dir=>'/home/ivan/freeside_current/masondata',
35                                       out_mode=>'stream',
36                                      );
37 my $ah = new HTML::Mason::ApacheHandler ( interp => $interp,
38                                           #auto_send_headers => 0,
39                                         );
40
41 # Activate the following if running httpd as root (the normal case).
42 # Resets ownership of all files created by Mason at startup.
43 #
44 chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
45
46 sub handler
47 {
48     my ($r) = @_;
49
50     # If you plan to intermix images in the same directory as
51     # components, activate the following to prevent Mason from
52     # evaluating image files as components.
53     #
54     #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
55
56     #rar
57     { package HTML::Mason::Commands;
58       use strict;
59       use vars qw( $cgi $p );
60       use CGI;
61       #use CGI::Carp qw(fatalsToBrowser);
62       use Date::Format;
63       use Date::Parse;
64       use Tie::IxHash;
65       use HTML::Entities;
66       use IO::Handle;
67       use IO::File;
68       use String::Approx qw(amatch);
69       use HTML::Widgets::SelectLayers;
70       use FS::UID qw(cgisuidsetup dbh getotaker datasrc driver_name);
71       use FS::Record qw(qsearch qsearchs fields dbdef);
72       use FS::Conf;
73       use FS::CGI qw(header menubar popurl table itable ntable idiot eidiot
74                      small_custview myexit);
75
76       use FS::agent;
77       use FS::agent_type;
78       use FS::domain_record;
79       use FS::cust_bill;
80       use FS::cust_bill_pay;
81       use FS::cust_credit;
82       use FS::cust_credit_bill;
83       use FS::cust_main;
84       use FS::cust_main_county;
85       use FS::cust_pay;
86       use FS::cust_pkg;
87       use FS::cust_refund;
88       use FS::cust_svc;
89       use FS::nas;
90       use FS::part_bill_event;
91       use FS::part_pkg;
92       use FS::part_referral;
93       use FS::part_svc;
94       use FS::pkg_svc;
95       use FS::port;
96       use FS::queue qw(joblisting);
97       use FS::raddb;
98       use FS::session;
99       use FS::svc_acct;
100       use FS::svc_acct_pop qw(popselector);
101       use FS::svc_acct_sm;
102       use FS::svc_domain;
103       use FS::svc_forward;
104       use FS::svc_www;
105       use FS::type_pkgs;
106       use FS::part_export;
107       use FS::part_export_option;
108
109       *CGI::redirect = sub {
110         my( $self, $location ) = @_;
111
112         #http://www.masonhq.com/docs/faq/#how_do_i_do_an_external_redirect
113         $m->clear_buffer;
114         # The next two lines are necessary to stop Apache from re-reading
115         # POSTed data.
116         $r->method('GET');
117         $r->headers_in->unset('Content-length');
118         $r->content_type('text/html');
119         #$r->err_header_out('Location' => $location);
120         $r->header_out('Location' => $location);
121          $r->header_out('Content-Type' => 'text/html');
122          $m->abort(302);
123
124         '';
125       };
126
127       $cgi = new CGI;
128       &cgisuidsetup($cgi);
129       #&cgisuidsetup($r);
130       $p = popurl(2);
131     }
132
133     $r->content_type('text/html');
134     #eorar
135
136     my $headers = $r->headers_out;
137     $headers->{'Pragma'} = $headers->{'Cache-control'} = 'no-cache';
138     #$r->no_cache(1);
139     $headers->{'Expires'} = '0';
140
141 #    $r->send_http_header;
142
143     my $status = $ah->handle_request($r);
144
145     $status;
146 }
147
148 1;