add framework for running Mason components standalone
[freeside.git] / FS / FS / Mason / Request.pm
1 package FS::Mason::Request;
2
3 use strict;
4 use warnings;
5 use vars qw( $FSURL $QUERY_STRING );
6 use base 'HTML::Mason::Request';
7
8 $FSURL = 'http://Set/FS_Mason_Request_FSURL/in_standalone_mode/';
9 $QUERY_STRING = '';
10
11 sub new {
12     my $class = shift;
13
14     my $superclass = $HTML::Mason::ApacheHandler::VERSION ?
15                      'HTML::Mason::Request::ApacheHandler' :
16                      $HTML::Mason::CGIHandler::VERSION ?
17                      'HTML::Mason::Request::CGI' :
18                      'HTML::Mason::Request';
19
20     $class->alter_superclass( $superclass );
21
22     #huh... shouldn't alter_superclass take care of this for us?
23     __PACKAGE__->valid_params( %{ $superclass->valid_params() } );
24
25     my %opt = @_;
26     my $mode = $superclass =~ /Apache/i ? 'apache' : 'standalone';
27     freeside_setup($opt{'comp'}, $mode);
28
29     $class->SUPER::new(@_);
30
31 }
32
33 sub freeside_setup {
34
35     my( $filename, $mode ) = @_;
36
37     #warn "initializing for $filename\n";
38
39     if ( $filename !~ /\/rt\/.*NoAuth/ ) { #not RT images/JS
40
41       package HTML::Mason::Commands;
42       use vars qw( $cgi $p $fsurl );
43       use FS::UID qw( cgisuidsetup );
44       use FS::CGI qw( popurl rooturl );
45
46       if ( $mode eq 'apache' ) {
47         $cgi = new CGI;
48         &cgisuidsetup($cgi);
49         #&cgisuidsetup($r);
50         $fsurl = rooturl();
51         $p = popurl(2);
52       } elsif ( $mode eq 'standalone' ) {
53         $cgi = new CGI $FS::Mason::Request::QUERY_STRING; #better keep setting
54                                                           #if you set it once
55         $FS::UID::cgi = $cgi;
56         $fsurl = $FS::Mason::Request::FSURL; #kludgy, but what the hell
57         $p = popurl(2, "$fsurl$filename");
58       } else {
59         die "unknown mode $mode";
60       }
61
62     } elsif ( $filename =~ /\/rt\/REST\/.*NoAuth/ ) {
63
64       package HTML::Mason::Commands; #?
65       use FS::UID qw( adminsuidsetup );
66
67       #need to log somebody in for the mail gw
68
69       ##old installs w/fs_selfs or selfserv??
70       #&adminsuidsetup('fs_selfservice');
71
72       &adminsuidsetup('fs_queue');
73
74     }
75
76 }
77
78 1;