1 package FS::part_export::shellcommands;
3 use vars qw(@ISA @saltset);
4 use String::ShellQuote;
7 @ISA = qw(FS::part_export);
9 @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' );
11 sub rebless { shift; }
15 $self->_export_command('useradd', @_);
20 $self->_export_command('userdel', @_);
25 $self->_export_command('suspend', @_);
28 sub _export_unsuspend {
30 $self->_export_command('unsuspend', @_);
34 my ( $self, $action, $svc_acct) = (shift, shift, shift);
35 my $command = $self->option($action);
36 my $stdin = $self->option($action."_stdin");
40 ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
42 $email = ( grep { $_ ne 'POST' }
43 $svc_acct->cust_svc->cust_pkg->cust_main->invoicing_list
45 $finger = shell_quote $finger;
46 $quoted_password = shell_quote $_password;
47 $domain = $svc_acct->domain;
48 $crypt_password = ''; #surpress "used only once" warnings
49 $crypt_password = crypt( $svc_acct->_password,
50 $saltset[int(rand(64))].$saltset[int(rand(64))] );
51 $self->shellcommands_queue( $svc_acct->svcnum,
52 user => $self->option('user')||'root',
53 host => $self->machine,
54 command => eval(qq("$command")),
55 stdin_string => eval(qq("$stdin")),
60 my($self, $new, $old ) = (shift, shift, shift);
61 my $command = $self->option('usermod');
62 my $stdin = $self->option('usermod_stdin');
66 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
67 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
69 $new_finger = shell_quote $new_finger;
70 $quoted_new__password = shell_quote $new__password;
71 $old_domain = $old->domain;
72 $new_domain = $new->domain;
73 $new_crypt_password = ''; #surpress "used only once" warnings
74 $new_crypt_password = crypt( $new->_password,
75 $saltset[int(rand(64))].$saltset[int(rand(64))]);
76 $self->shellcommands_queue( $new->svcnum,
77 user => $self->option('user')||'root',
78 host => $self->machine,
79 command => eval(qq("$command")),
80 stdin_string => eval(qq("$stdin")),
84 #a good idea to queue anything that could fail or take any time
85 sub shellcommands_queue {
86 my( $self, $svcnum ) = (shift, shift);
87 my $queue = new FS::queue {
89 'job' => "FS::part_export::shellcommands::ssh_cmd",
94 sub ssh_cmd { #subroutine, not method
96 &Net::SSH::ssh_cmd( { @_ } );
99 #sub shellcommands_insert { #subroutine, not method
101 #sub shellcommands_replace { #subroutine, not method
103 #sub shellcommands_delete { #subroutine, not method