summaryrefslogtreecommitdiff
path: root/fs_signup/fs_signup_server
blob: 5feed4cb624c9585d4a893c7778da4d62bfbb6a0 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl -Tw
#
# fs_signup_server
#

use strict;
use IO::Handle;
use FS::SSH qw(sshopen2);
use FS::UID qw(adminsuidsetup);
use FS::Record qw(qsearchs);
use FS::cust_main_county;
use FS::cust_main;

use vars qw( $opt );

my $user = shift or die &usage;
adminsuidsetup $user; 

my $machine = shift or die &usage;

my $agentnum = shift or die &usage;
my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } ) or die &usage;
#my %part_pkg = %{ $agent->pkgpart_hashref };

my $refnum = shift or die &usage;

$SIG{CHLD} = sub { wait() };

my($fs_signupd)="/usr/local/sbin/fs_signupd";

while (1) {
  my($reader,$writer)=(new IO::Handle, new IO::Handle);
  $writer->autoflush(1);
  sshopen2($shellmachine,$reader,$writer,$fs_signupd);

  #send fs_signupd state/county/country
  @cust_main_county = qsearch('cust_main_county', {} );
  print $writer join("\n",
    scalar(@cust_main_county),
    map {
      $_->taxnum,
      $_->state,
      $_->county,
      $_->country,
    } @cust_main_county
  ),"\n";

  #send fs_signupd package definitions

  #send fs_signupd POPs



  while (1) {
    my( $first, $last, $ss, $company, $address1, $address2, $city, $county,
        $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
        $paydate, $payname, $username, $password, $popnum,
    );



    my($username,$old_password,$new_password,$new_gecos,$new_shell);
    defined($username=<$reader>) or last;
    defined($old_password=<$reader>) or last; 
    defined($new_password=<$reader>) or last; 
    defined($new_gecos=<$reader>) or last; 
    defined($new_shell=<$reader>) or last; 
    chop($username);
    chop($old_password);
    chop($new_password);
    chop($new_gecos);
    chop($new_shell);
    my($svc_acct);

    #need to try both $old_password and encrypted $old_password
    #maybe the crypt function in svc_acct.export needs to be a library?
    my $salt = substr($old_password,0,2);
    my $cold_password = crypt($old_password,$salt);
    $svc_acct=qsearchs('svc_acct',{'username'=>$username,
                                   '_password'=>$old_password,
    } )
           || qsearchs('svc_acct',{'username'=>$username,
                                   '_password'=>$cold_password,
    } );
    unless ( $svc_acct ) { print $writer "Incorrect password.\n"; next; }

    my(%hash)=$svc_acct->hash;
    my($new_svc_acct) = new FS::svc_acct ( \%hash );
    $new_svc_acct->setfield('_password',$new_password) 
      if $new_password && $new_password ne $old_password;
    $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
    $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
    my($error)=$new_svc_acct->replace($svc_acct);
    print $writer $error,"\n";
  }
  close $writer;
  close $reader;
  sleep 60;
  warn "Connection to $shellmachine lost!  Reconnecting...\n";
}

sub usage {
  die "Usage:\n\n  fs_signup_server user machine agentnum refnum\n";
}