initial checkin of signup server
[freeside.git] / fs_signup / FS-SignupClient / fs_signupd
1 #!/usr/bin/perl -Tw
2 #
3 # fs_signupd
4 #
5 # This is run REMOTELY over ssh by fs_signup_server.
6 #
7
8 use strict;
9 use Socket;
10
11 use vars qw( $Debug );
12
13 $Debug = 0;
14
15 my($fs_signupd_socket)="/usr/local/freeside/fs_signupd_socket";
16
17 $ENV{'PATH'} ='/usr/local/bin:/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 $|=1;
25
26 warn "[fs_signupd] Reading locales...\n" if $Debug;
27 chomp( my $n_cust_main_county = <STDIN> );
28 my @cust_main_county = map {
29   chomp( my $taxnum = <STDIN> );
30   chomp( my $state = <STDIN> );
31   chomp( my $county = <STDIN> );
32   chomp( my $country = <STDIN> );
33   {
34     'taxnum'  => $taxnum,
35     'state'   => $state,
36     'county'  => $county,
37     'country' => $country,
38   };
39 } ( 1 .. $n_cust_main_county );
40
41 warn "[fs_signupd] Reading package definitions...\n" if $Debug;
42 chomp( my $n_part_pkg = <STDIN> );
43 my @part_pkg = map {
44   chomp( my $pkgpart = <STDIN> );
45   chomp( my $pkg = <STDIN> );
46   {
47     'pkgpart' => $pkgpart,
48     'pkg'     => $pkg,
49   };
50 } ( 1 .. $n_part_pkg );
51
52 warn "[fs_signupd] Reading POPs...\n" if $Debug;
53 chomp( my $n_svc_acct_pop = <STDIN> );
54 my @svc_acct_pop = map {
55   chomp( my $popnum = <STDIN> );
56   chomp( my $city = <STDIN> );
57   chomp( my $state = <STDIN> );
58   chomp( my $ac = <STDIN> );
59   chomp( my $exch = <STDIN> );
60   {
61     'popnum' => $popnum,
62     'city'   => $city,
63     'state'  => $state,
64     'ac'     => $ac,
65     'exch'   => $exch,
66   };
67 } ( 1 .. $n_svc_acct_pop );
68
69 warn "[fs_signupd] Creating $fs_signupd_socket\n" if $Debug;
70 my $uaddr = sockaddr_un($fs_signupd_socket);
71 my $proto = getprotobyname('tcp');
72 socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!";
73 unlink($fs_signupd_socket);
74 bind(Server, $uaddr) or die "bind: $!";
75 listen(Server,SOMAXCONN) or die "listen: $!";
76
77 warn "[fs_signupd] Entering main loop...\n" if $Debug;
78 my $paddr;
79 for ( ; $paddr = accept(Client,Server); close Client) {
80
81   chop( my $command = <Client> );
82
83   if ( $command eq "signup_info" ) {
84     warn "[fs_signupd] sending signup info...\n" if $Debug; 
85     print Client join("\n", $n_cust_main_county,
86       map {
87         $_->{taxnum},
88         $_->{state},
89         $_->{county},
90         $_->{country},
91       } @cust_main_county
92     ), "\n";
93
94     print Client join("\n", $n_part_pkg,
95       map {
96         $_->{pkgpart},
97         $_->{pkg},
98       } @part_pkg
99     ), "\n";
100
101     print Client join("\n", $n_svc_acct_pop,
102       map {
103         $_->{popnum},
104         $_->{city},
105         $_->{state},
106         $_->{ac},
107         $_->{exch},
108       } @svc_acct_pop
109     ), "\n";
110
111   } elsif ( $command eq "new_customer" ) {
112     warn "[fs_signupd] reading customer signup...\n" if $Debug;
113     my(
114       $first, $last, $ss, $company, $address1, $address2, $city, $county,
115       $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
116       $paydate, $payname, $invoicing_list, $pkgpart, $username, $password,
117       $popnum,
118     ) = map { scalar(<Client>) } ( 1 .. 23 );
119
120     warn "[fs_signupd] sending customer data to remote server...\n" if $Debug;
121     print 
122       $first, $last, $ss, $company, $address1, $address2, $city, $county,
123       $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
124       $paydate, $payname, $invoicing_list, $pkgpart, $username, $password,
125       $popnum,
126     ;
127
128     warn "[fs_signupd] reading error from remote server...\n" if $Debug;
129     my $error = <STDIN>;
130
131     warn "[fs_signupd] sending error to local client...\n" if $Debug;
132     print Client $error;
133
134   } else {
135     die "unexpected command from client: $command";
136   }
137
138 }
139