8 use Storable qw(nstore_fd fd_retrieve);
10 use Net::SSH qw(sshopen2);
11 use FS::UID qw(adminsuidsetup);
13 use FS::Record qw( qsearch qsearchs );
14 use FS::cust_main_county;
16 use FS::msgcat qw(gettext);
18 use vars qw( $opt $Debug );
22 my $user = shift or die &usage;
23 &adminsuidsetup( $user );
25 my $conf = new FS::Conf;
27 #my @payby = qw(CARD PREPAY);
28 my @payby = $conf->config('signup_server-payby');
30 my $machine = shift or die &usage;
32 my $agentnum = shift or die &usage;
33 my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } ) or die &usage;
34 my $pkgpart_href = $agent->pkgpart_hashref;
36 my $refnum = shift or die &usage;
38 #causing trouble for some folks
39 #$SIG{CHLD} = sub { wait() };
41 my($fs_signupd)="/usr/local/sbin/fs_signupd";
44 my($reader,$writer)=(new IO::Handle, new IO::Handle);
45 #seems to be broken - calling ->flush explicitly# $writer->autoflush(1);
46 warn "[fs_signup_server] Connecting to $machine...\n" if $Debug;
47 sshopen2($machine,$reader,$writer,$fs_signupd);
51 #'_protocol' => 'signup',
56 [ map { $_->hashref } qsearch('cust_main_county', {}) ],
61 grep { $_->svcpart('svc_acct') && $pkgpart_href->{ $_->pkgpart } }
62 qsearch( 'part_pkg', { 'disabled' => '' } )
65 'svc_acct_pop' => [ map { $_->hashref } qsearch ('svc_acct_pop',{} ) ],
67 'security_phrase' => $conf->exists('security_phrase'),
69 'payby' => [ $conf->config('signup_server-payby') ],
71 'msgcat' => { map { $_=>gettext($_) } qw(
72 passwords_dont_match invalid_card unknown_card_type not_a
77 warn "[fs_signup_server] Sending init data...\n" if $Debug;
78 nstore_fd($init_data, $writer) or die "can't send init data: $!";
81 warn "[fs_signup_server] Entering main loop...\n" if $Debug;
83 warn "[fs_signup_server] Reading (waiting for) signup data...\n" if $Debug;
84 my $signup_data = fd_retrieve($reader);
88 map { " $_ => ". $signup_data->{$_}. "\n" } keys %$signup_data );
91 warn "[fs_signup_server] Processing signup...\n" if $Debug;
95 #things that aren't necessary in base class, but are for signup server
96 #return "Passwords don't match"
97 # if $hashref->{'_password'} ne $hashref->{'_password2'}
98 $error ||= "Empty password" unless $signup_data->{'_password'};
99 $error ||= "No POP selected" unless $signup_data->{'popnum'};
101 #shares some stuff with htdocs/edit/process/cust_main.cgi... take any
102 # common that are still here and library them.
103 my $cust_main = new FS::cust_main ( {
105 'agentnum' => $agentnum,
108 map { $_ => $signup_data->{$_} } qw(
109 last first ss company address1 address2 city county state zip country
110 daytime night fax payby payinfo paydate payname referral_custnum
115 $error ||= "Illegal payment type"
116 unless grep { $_ eq $signup_data->{'payby'} } @payby;
118 my @invoicing_list = split( /\s*\,\s*/, $signup_data->{'invoicing_list'} );
121 qsearchs( 'part_pkg', { 'pkgpart' => $signup_data->{'pkgpart'} } )
122 or $error ||= "WARNING: unknown pkgpart ". $signup_data->{pkgpart};
123 my $svcpart = $part_pkg->svcpart unless $error;
125 # this should wind up in FS::cust_pkg!
126 my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } );
127 #my $pkgpart_href = $agent->pkgpart_hashref;
128 $error ||= "WARNING: agent $agentnum can't purchase pkgpart ".
129 $signup_data->{pkgpart}
130 unless $pkgpart_href->{ $signup_data->{pkgpart} };
132 my $cust_pkg = new FS::cust_pkg ( {
133 #later#'custnum' => $custnum,
134 'pkgpart' => $signup_data->{'pkgpart'},
136 $error ||= $cust_pkg->check;
138 my $svc_acct = new FS::svc_acct ( {
139 'svcpart' => $svcpart,
140 map { $_ => $signup_data->{$_} }
141 qw( username _password sec_phrase popnum ),
144 my $y = $svc_acct->setdefault; # arguably should be in new method
145 $error ||= $y unless ref($y);
147 $error ||= $svc_acct->check;
150 tie my %hash, 'Tie::RefHash';
151 %hash = ( $cust_pkg => [ $svc_acct ] );
152 $error ||= $cust_main->insert( \%hash, \@invoicing_list );
154 warn "[fs_signup_server] Sending results...\n" if $Debug;
155 print $writer $error, "\n";
160 warn "connection to $machine lost! waiting 60 seconds...\n";
162 warn "reconnecting...\n";
166 die "Usage:\n\n fs_signup_server user machine agentnum refnum\n";