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