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 return '' if $command =~ /^\s*$/;
37 my $stdin = $self->option($action."_stdin");
42 ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
45 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
47 $email = ( grep { $_ ne 'POST' } $cust_pkg->cust_main->invoicing_list )[0];
52 $finger = shell_quote $finger;
53 $quoted_password = shell_quote $_password;
54 $domain = $svc_acct->domain;
55 $crypt_password = ''; #surpress "used only once" warnings
56 $crypt_password = crypt( $svc_acct->_password,
57 $saltset[int(rand(64))].$saltset[int(rand(64))] );
59 $self->shellcommands_queue( $svc_acct->svcnum,
60 user => $self->option('user')||'root',
61 host => $self->machine,
62 command => eval(qq("$command")),
63 stdin_string => eval(qq("$stdin")),
68 my($self, $new, $old ) = (shift, shift, shift);
69 my $command = $self->option('usermod');
70 my $stdin = $self->option('usermod_stdin');
74 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
75 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
77 $new_finger = shell_quote $new_finger;
78 $quoted_new__password = shell_quote $new__password;
79 $old_domain = $old->domain;
80 $new_domain = $new->domain;
81 $new_crypt_password = ''; #surpress "used only once" warnings
82 $new_crypt_password = crypt( $new->_password,
83 $saltset[int(rand(64))].$saltset[int(rand(64))]);
84 $self->shellcommands_queue( $new->svcnum,
85 user => $self->option('user')||'root',
86 host => $self->machine,
87 command => eval(qq("$command")),
88 stdin_string => eval(qq("$stdin")),
92 #a good idea to queue anything that could fail or take any time
93 sub shellcommands_queue {
94 my( $self, $svcnum ) = (shift, shift);
95 my $queue = new FS::queue {
97 'job' => "FS::part_export::shellcommands::ssh_cmd",
102 sub ssh_cmd { #subroutine, not method
104 &Net::SSH::ssh_cmd( { @_ } );
107 #sub shellcommands_insert { #subroutine, not method
109 #sub shellcommands_replace { #subroutine, not method
111 #sub shellcommands_delete { #subroutine, not method