#!/usr/bin/perl -Tw # # fs_signupd # # This is run REMOTELY over ssh by fs_signup_server. use strict; use Socket; use Storable qw(nstore_fd fd_retrieve); use IO::Handle; use vars qw( $Debug ); $Debug = 1; my $fs_signupd_socket = "/usr/local/freeside/fs_signupd_socket"; my $pid_file = "$fs_signupd_socket.pid"; $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin'; $ENV{'SHELL'} = '/bin/sh'; $ENV{'IFS'} = " \t\n"; $ENV{'CDPATH'} = ''; $ENV{'ENV'} = ''; $ENV{'BASH_ENV'} = ''; $|=1; warn "[fs_signupd] Reading init data...\n" if $Debug; my $init_data = fd_retrieve(\*STDIN); warn "[fs_signupd] Creating $fs_signupd_socket\n" if $Debug; my $uaddr = sockaddr_un($fs_signupd_socket); my $proto = getprotobyname('tcp'); socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!"; unlink($fs_signupd_socket); bind(Server, $uaddr) or die "bind: $!"; listen(Server,SOMAXCONN) or die "listen: $!"; if ( -e $pid_file ) { open(PIDFILE,"<$pid_file"); #chomp( my $old_pid = ); my $old_pid = ; close PIDFILE; $old_pid =~ /^(\d+)$/; kill 'TERM', $1; } open(PIDFILE,">$pid_file"); print PIDFILE "$$\n"; close PIDFILE; warn "[fs_signupd] Entering main loop...\n" if $Debug; my $paddr; for ( ; $paddr = accept(Client,Server); close Client) { chop( my $command = ); if ( $command eq "signup_info" ) { warn "[fs_signupd] sending signup info...\n" if $Debug; nstore_fd($init_data, \*Client) or die "can't send init data: $!"; Client->flush; } elsif ( $command eq "new_customer" ) { #inefficient... warn "[fs_signupd] reading customer signup...\n" if $Debug; my $signup_data = fd_retrieve(\*Client); warn "[fs_signupd] sending customer data to remote server...\n" if $Debug; nstore_fd($signup_data, \*STDOUT) or die "can't send signup data: $!"; STDOUT->flush; warn "[fs_signupd] reading error from remote server...\n" if $Debug; my $error = ; warn "[fs_signupd] sending error to local client...\n" if $Debug; print Client $error; Client->flush; } else { die "unexpected command from client: $command"; } }