8 use FS::SSH qw(sshopen2);
9 use FS::UID qw(adminsuidsetup);
10 use FS::Record qw(qsearchs);
11 use FS::cust_main_county;
16 my $user = shift or die &usage;
19 my $machine = shift or die &usage;
21 my $agentnum = shift or die &usage;
22 my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } ) or die &usage;
23 my $pkgpart = $agent->pkgpart_hashref;
25 my $refnum = shift or die &usage;
27 $SIG{CHLD} = sub { wait() };
29 my($fs_signupd)="/usr/local/sbin/fs_signupd";
32 my($reader,$writer)=(new IO::Handle, new IO::Handle);
33 $writer->autoflush(1);
34 sshopen2($shellmachine,$reader,$writer,$fs_signupd);
36 #send fs_signupd state/county/country
37 @my cust_main_county = qsearch('cust_main_county', {} );
38 print $writer join("\n",
39 scalar(@cust_main_county) || die "no tax rates (cust_main_county records)",
48 #send fs_signupd package definitions
49 my @part_pkg = grep { $_->svcpart('svc_acct') && $pkgpart->{ $_->pkgpart } }
50 qsearch( 'part_pkg', {} );
51 print $writer join("\n",
52 scalar(@part_pkg) || die "no usable package definitions, agent $agentnum",
60 my @svc_acct_pop = qsearch ('svc_acct_pop',{} );
61 print $writer join("\n",
62 scalar(@svc_acct_pop) || die "No points of presence (svc_acct_pop records)",
74 $first, $last, $ss, $company, $address1, $address2, $city, $county,
75 $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
76 $paydate, $payname, $invoicing_list, $pkgpart, $username, $password,
82 #shares some stuff with htdocs/edit/process/cust_main.cgi... take any
83 # common that are still here and library them.
84 my $cust_main = new FS::cust_main ( {
86 'agentnum' => $agentnum,
91 'company' => $company,
92 'address1' => $address1,
93 'address2' => $address2,
98 'country' => $country,
99 'daytime' => $daytime,
103 'payinfo' => $payinfo,
104 'paydate' => $paydate,
105 'payname' => $payname,
108 my @invoicing_list = split( /\s*\,\s*/, $invoicing_list );
110 $error ||= $cust_main->check_invoicing_list( \@invoicing_list );
112 my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } )
113 or die "unknown pkgpart $pkgpart";
114 my $svcpart = $part_pkg->svcpart;
116 # this should wind up in FS::cust_pkg!
117 die "agent $agentnum can't purchase pkgpart $pkgpart"
118 unless $pkgpart->{ $pkgpart };
120 my $cust_pkg = new FS::cust_pkg ( {
121 #later#'custnum' => $custnum,
122 'pkgpart' => $pkgpart,
124 $error ||= $cust_pkg->check;
126 $svc_acct = new FS::svc_acct ( {
127 'svcpart' => $svcpart,
128 'username' => $username,
129 '_password' => $password,
133 my $y = $svc_acct->setdefault; # arguably should be in new method
134 $error ||= $y unless ref($y);
135 #and just in case you were silly
136 $svc_acct->svcpart($svcpart);
137 $svc_acct->username($username);
138 $svc_acct->_password($password);
139 $svc_acct->popnum($popnum);
141 $error ||= $svc_acct->check;
143 $error ||= $cust_main->insert;
144 if ( $cust_pkg && ! $error ) { #in this case, $cust_pkg should always
145 #be definied, but....
146 $cust_pkg->custnum( $new->custnum );
147 $error ||= $cust_pkg->insert;
148 warn "WARNING: $error on pre-checked cust_pkg record!" if $error;
149 $svc_acct->pkgnum( $cust_pkg->pkgnum );
150 $error ||= $svc_acct->insert;
151 warn "WARNING: $error on pre-checked svc_acct record!" if $error;
154 print $writer $error, "\n";
156 $cust_main->invoicing_list( \@invoicing_list ) unless $error;
161 warn "connection to $shellmachine lost! waiting 60 seconds...\n";
163 warn "reconnecting...\n";
167 die "Usage:\n\n fs_signup_server user machine agentnum refnum\n";