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 $finger = shell_quote $finger;
43 $quoted_password = shell_quote $_password;
44 $domain = $svc_acct->domain;
45 $crypt_password = ''; #surpress "used only once" warnings
46 $crypt_password = crypt( $svc_acct->_password,
47 $saltset[int(rand(64))].$saltset[int(rand(64))] );
48 $self->shellcommands_queue( $svc_acct->svcnum,
49 user => $self->option('user')||'root',
50 host => $self->machine,
51 command => eval(qq("$command")),
52 stdin_string => eval(qq("$stdin")),
57 my($self, $new, $old ) = (shift, shift, shift);
58 my $command = $self->option('usermod');
59 my $stdin = $self->option('usermod_stdin');
63 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
64 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
66 $new_finger = shell_quote $new_finger;
67 $quoted_new__password = shell_quote $new__password;
68 $old_domain = $old->domain;
69 $new_domain = $new->domain;
70 $new_crypt_password = ''; #surpress "used only once" warnings
71 $new_crypt_password = crypt( $new->_password,
72 $saltset[int(rand(64))].$saltset[int(rand(64))]);
73 $self->shellcommands_queue( $new->svcnum,
74 user => $self->option('user')||'root',
75 host => $self->machine,
76 command => eval(qq("$command")),
77 stdin_string => eval(qq("$stdin")),
81 #a good idea to queue anything that could fail or take any time
82 sub shellcommands_queue {
83 my( $self, $svcnum ) = (shift, shift);
84 my $queue = new FS::queue {
86 'job' => "FS::part_export::shellcommands::ssh_cmd",
91 sub ssh_cmd { #subroutine, not method
93 &Net::SSH::ssh_cmd( { @_ } );
96 #sub shellcommands_insert { #subroutine, not method
98 #sub shellcommands_replace { #subroutine, not method
100 #sub shellcommands_delete { #subroutine, not method