signup w/globalpops DID selection via mason components pass-through
[freeside.git] / FS / FS / ClientAPI / MasonComponent.pm
1 package FS::ClientAPI::MasonComponent;
2
3 use strict;
4 use vars qw($DEBUG $me);
5 use FS::Mason qw( mason_interps );
6 use FS::Conf;
7
8 $DEBUG = 0;
9 $me = '[FS::ClientAPI::MasonComponent]';
10
11 my %allowed_comps = map { $_=>1 } qw(
12   /elements/select-did.html
13   /misc/areacodes.cgi
14   /misc/exchanges.cgi
15   /misc/phonenums.cgi
16 );
17
18 my $outbuf;
19 my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
20
21 sub mason_comp {
22   my $packet = shift;
23
24   warn "$me mason_comp called on $packet\n" if $DEBUG;
25
26   my $comp = $packet->{'comp'};
27   unless ( $allowed_comps{$comp} ) {
28     return { 'error' => 'Illegal component' };
29   }
30
31   my @args = $packet->{'args'} ? @{ $packet->{'args'} } : ();
32
33   my $conf = new FS::Conf;
34   $FS::Mason::Request::FSURL = $conf->config('selfservice_server-base_url');
35   $FS::Mason::Request::QUERY_STRING = $packet->{'query_string'} || '';
36
37   $outbuf = '';
38   $fs_interp->exec($comp, @args); #only FS for now alas...
39
40   #errors? (turn off in-line error reporting?)
41
42   return { 'output' => $outbuf };
43
44 }
45
46 1;