5769c18fcf27f6828097654481e18178076e26f8
[freeside.git] / fs_signup / FS-SignupClient / SignupClient.pm
1 package FS::SignupClient;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT_OK $fs_signupd_socket);
5 use Exporter;
6 use Socket;
7 use FileHandle;
8 use IO::Handle;
9
10 $VERSION = '0.01';
11
12 @ISA = qw( Exporter );
13 @EXPORT_OK = qw( signup_info new_customer );
14
15 $fs_signupd_socket = "/usr/local/freeside/fs_signupd_socket";
16
17 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
18 $ENV{'SHELL'} = '/bin/sh';
19 $ENV{'IFS'} = " \t\n";
20 $ENV{'CDPATH'} = '';
21 $ENV{'ENV'} = '';
22 $ENV{'BASH_ENV'} = '';
23
24 my $freeside_uid = scalar(getpwnam('freeside'));
25 die "not running as the freeside user\n" if $> != $freeside_uid;
26
27 =head1 NAME
28
29 FS::SignupClient - Freeside signup client API
30
31 =head1 SYNOPSIS
32
33   use FS::SignupClient qw( signup_info new_customer );
34
35   ( $locales, $packages, $pops ) = signup_info;
36
37   $error = new_customer ( {
38     'first'          => $first,
39     'last'           => $last,
40     'ss'             => $ss,
41     'comapny'        => $company,
42     'address1'       => $address1,
43     'address2'       => $address2,
44     'city'           => $city,
45     'county'         => $county,
46     'state'          => $state,
47     'zip'            => $zip,
48     'country'        => $country,
49     'daytime'        => $daytime,
50     'night'          => $night,
51     'fax'            => $fax,
52     'payby'          => $payby,
53     'payinfo'        => $payinfo,
54     'paydate'        => $paydate,
55     'payname'        => $payname,
56     'invoicing_list' => $invoicing_list,
57     'pkgpart'        => $pkgpart,
58     'username'       => $username,
59     '_password'       => $password,
60     'popnum'         => $popnum,
61   } );
62
63 =head1 DESCRIPTION
64
65 This module provides an API for a remote signup server.
66
67 It needs to be run as the freeside user.  Because of this, the program which
68 calls these subroutines should be written very carefully.
69
70 =head1 SUBROUTINES
71
72 =over 4
73
74 =item signup_info
75
76 Returns three array references of hash references.
77
78 The first set of hash references is of allowable locales.  Each hash reference
79 has the following keys:
80   taxnum
81   state
82   county
83   country
84
85 The second set of hash references is of allowable packages.  Each hash
86 reference has the following keys:
87   pkgpart
88   pkg
89
90 The third set of hash references is of allowable POPs (Points Of Presence).
91 Each hash reference has the following keys:
92   popnum
93   city
94   state
95   ac
96   exch
97
98 =cut
99
100 sub signup_info {
101   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
102   connect(SOCK, sockaddr_un($fs_signupd_socket)) or die "connect: $!";
103   print SOCK "signup_info\n";
104   SOCK->flush;
105
106   chop ( my $n_cust_main_county = <SOCK> );
107   my @cust_main_county = map {
108     chop ( my $taxnum  = <SOCK> ); 
109     chop ( my $state   = <SOCK> ); 
110     chop ( my $county  = <SOCK> ); 
111     chop ( my $country = <SOCK> );
112     {
113       'taxnum'  => $taxnum,
114       'state'   => $state,
115       'county'  => $county,
116       'country' => $country,
117     };
118   } 1 .. $n_cust_main_county;
119
120   chop ( my $n_part_pkg = <SOCK> );
121   my @part_pkg = map {
122     chop ( my $pkgpart = <SOCK> ); 
123     chop ( my $pkg     = <SOCK> ); 
124     {
125       'pkgpart' => $pkgpart,
126       'pkg'     => $pkg,
127     };
128   } 1 .. $n_part_pkg;
129
130   chop ( my $n_svc_acct_pop = <SOCK> );
131   my @svc_acct_pop = map {
132     chop ( my $popnum = <SOCK> ); 
133     chop ( my $city   = <SOCK> ); 
134     chop ( my $state  = <SOCK> ); 
135     chop ( my $ac     = <SOCK> );
136     chop ( my $exch   = <SOCK> );
137     chop ( my $loc    = <SOCK> );
138     {
139       'popnum' => $popnum,
140       'city'   => $city,
141       'state'  => $state,
142       'ac'     => $ac,
143       'exch'   => $exch,
144       'loc'    => $loc,
145     };
146   } 1 .. $n_svc_acct_pop;
147
148   close SOCK;
149
150   \@cust_main_county, \@part_pkg, \@svc_acct_pop;
151 }
152
153 =item new_customer HASHREF
154
155 Adds a customer to the remote Freeside system.  Requires a hash reference as
156 a paramater with the following keys:
157   first
158   last
159   ss
160   comapny
161   address1
162   address2
163   city
164   county
165   state
166   zip
167   country
168   daytime
169   night
170   fax
171   payby
172   payinfo
173   paydate
174   payname
175   invoicing_list
176   pkgpart
177   username
178   _password
179   popnum
180
181 Returns a scalar error message, or the empty string for success.
182
183 =cut
184
185 sub new_customer {
186   my $hashref = shift;
187
188   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
189   connect(SOCK, sockaddr_un($fs_signupd_socket)) or die "connect: $!";
190   print SOCK "new_customer\n";
191
192   print SOCK join("\n", map { $hashref->{$_} } qw(
193     first last ss company address1 address2 city county state zip country
194     daytime night fax payby payinfo paydate payname invoicing_list
195     pkgpart username _password popnum
196   ) ), "\n";
197   SOCK->flush;
198
199   chop( my $error = <SOCK> );
200   $error;
201 }
202
203 =back
204
205 =head1 VERSION
206
207 $Id: SignupClient.pm,v 1.3 2000-02-02 07:44:00 ivan Exp $
208
209 =head1 BUGS
210
211 =head1 SEE ALSO
212
213 L<fs_signupd>, L<FS::SignupServer>, L<FS::cust_main>
214
215 =cut
216
217 1;
218