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