blob: 85bd68a2f5ed63fd4a9b9a168a9151ca9ba0713a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/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 = <PIDFILE> );
my $old_pid = <PIDFILE>;
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 = <Client> );
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 = <STDIN>;
warn "[fs_signupd] sending error to local client...\n" if $Debug;
print Client $error;
Client->flush;
} else {
die "unexpected command from client: $command";
}
}
|