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");
41 ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
44 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
46 $email = ( grep { $_ ne 'POST' } $cust_pkg->cust_main->invoicing_list )[0];
51 $finger = shell_quote $finger;
52 $quoted_password = shell_quote $_password;
53 $domain = $svc_acct->domain;
54 $crypt_password = ''; #surpress "used only once" warnings
55 $crypt_password = crypt( $svc_acct->_password,
56 $saltset[int(rand(64))].$saltset[int(rand(64))] );
58 $self->shellcommands_queue( $svc_acct->svcnum,
59 user => $self->option('user')||'root',
60 host => $self->machine,
61 command => eval(qq("$command")),
62 stdin_string => eval(qq("$stdin")),
67 my($self, $new, $old ) = (shift, shift, shift);
68 my $command = $self->option('usermod');
69 my $stdin = $self->option('usermod_stdin');
73 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
74 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
76 $new_finger = shell_quote $new_finger;
77 $quoted_new__password = shell_quote $new__password;
78 $old_domain = $old->domain;
79 $new_domain = $new->domain;
80 $new_crypt_password = ''; #surpress "used only once" warnings
81 $new_crypt_password = crypt( $new->_password,
82 $saltset[int(rand(64))].$saltset[int(rand(64))]);
83 $self->shellcommands_queue( $new->svcnum,
84 user => $self->option('user')||'root',
85 host => $self->machine,
86 command => eval(qq("$command")),
87 stdin_string => eval(qq("$stdin")),
91 #a good idea to queue anything that could fail or take any time
92 sub shellcommands_queue {
93 my( $self, $svcnum ) = (shift, shift);
94 my $queue = new FS::queue {
96 'job' => "FS::part_export::shellcommands::ssh_cmd",
101 sub ssh_cmd { #subroutine, not method
103 &Net::SSH::ssh_cmd( { @_ } );
106 #sub shellcommands_insert { #subroutine, not method
108 #sub shellcommands_replace { #subroutine, not method
110 #sub shellcommands_delete { #subroutine, not method