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', @_);
24 my ( $self, $action, $svc_acct) = (shift, shift, shift);
25 my $command = $self->option($action);
26 my $stdin = $self->option($action."_stdin");
29 ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
31 $finger = shell_quote $finger;
32 $crypt_password = ''; #surpress "used only once" warnings
33 $crypt_password = crypt( $svc_acct->_password,
34 $saltset[int(rand(64))].$saltset[int(rand(64))] );
35 $self->shellcommands_queue( $svc_acct->svcnum,
36 user => $self->option('user')||'root',
37 host => $self->machine,
38 command => eval(qq("$command")),
39 stdin_string => eval(qq("$stdin")),
44 my($self, $new, $old ) = (shift, shift, shift);
45 my $command = $self->option('usermod');
46 my $stdin = $self->option('usermod_stdin');
49 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
50 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
52 $new_finger = shell_quote $new_finger;
53 $new_crypt_password = ''; #surpress "used only once" warnings
54 $new_crypt_password = crypt( $new->_password,
55 $saltset[int(rand(64))].$saltset[int(rand(64))]);
56 $self->shellcommands_queue( $new->svcnum,
57 user => $self->option('user')||'root',
58 host => $self->machine,
59 command => eval(qq("$command")),
60 stdin_string => eval(qq("$stdin")),
64 #a good idea to queue anything that could fail or take any time
65 sub shellcommands_queue {
66 my( $self, $svcnum ) = (shift, shift);
67 my $queue = new FS::queue {
69 'job' => "FS::part_export::shellcommands::ssh_cmd",
74 sub ssh_cmd { #subroutine, not method
76 &Net::SSH::ssh_cmd( { @_ } );
79 #sub shellcommands_insert { #subroutine, not method
81 #sub shellcommands_replace { #subroutine, not method
83 #sub shellcommands_delete { #subroutine, not method