5 # This is run REMOTELY over ssh by fs_signup_server.
9 use Storable qw(nstore_fd fd_retrieve);
12 use vars qw( $Debug );
16 my $fs_signupd_socket = "/usr/local/freeside/fs_signupd_socket";
17 my $pid_file = "$fs_signupd_socket.pid";
19 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
20 $ENV{'SHELL'} = '/bin/sh';
21 $ENV{'IFS'} = " \t\n";
24 $ENV{'BASH_ENV'} = '';
28 warn "[fs_signupd] Reading init data...\n" if $Debug;
29 my $init_data = fd_retrieve(\*STDIN);
31 warn "[fs_signupd] Creating $fs_signupd_socket\n" if $Debug;
32 my $uaddr = sockaddr_un($fs_signupd_socket);
33 my $proto = getprotobyname('tcp');
34 socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!";
35 unlink($fs_signupd_socket);
36 bind(Server, $uaddr) or die "bind: $!";
37 listen(Server,SOMAXCONN) or die "listen: $!";
40 open(PIDFILE,"<$pid_file");
41 #chomp( my $old_pid = <PIDFILE> );
42 my $old_pid = <PIDFILE>;
44 $old_pid =~ /^(\d+)$/;
47 open(PIDFILE,">$pid_file");
51 warn "[fs_signupd] Entering main loop...\n" if $Debug;
53 for ( ; $paddr = accept(Client,Server); close Client) {
55 chop( my $command = <Client> );
57 if ( $command eq "signup_info" ) {
59 warn "[fs_signupd] sending signup info...\n" if $Debug;
60 nstore_fd($init_data, \*Client) or die "can't send init data: $!";
63 } elsif ( $command eq "new_customer" ) {
67 warn "[fs_signupd] reading customer signup...\n" if $Debug;
68 my $signup_data = fd_retrieve(\*Client);
70 warn "[fs_signupd] sending customer data to remote server...\n" if $Debug;
71 nstore_fd($signup_data, \*STDOUT) or die "can't send signup data: $!";
74 warn "[fs_signupd] reading error from remote server...\n" if $Debug;
77 warn "[fs_signupd] sending error to local client...\n" if $Debug;
82 die "unexpected command from client: $command";