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 foreach my $acct_snarf ( $svc_acct->acct_snarf ) {
46 ${"snarf_$_$count"} = shell_quote( $acct_snarf->get($_) )
47 foreach qw( machine username _password );
52 my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
54 $email = ( grep { $_ ne 'POST' } $cust_pkg->cust_main->invoicing_list )[0];
59 $finger = shell_quote $finger;
60 $quoted_password = shell_quote $_password;
61 $domain = $svc_acct->domain;
63 #eventually should check a "password-encoding" field
64 if ( length($svc_acct->_password) == 13
65 || $svc_acct->_password =~ /^\$(1|2a?)\$/ ) {
66 $crypt_password = $svc_acct->_password;
68 $crypt_password = crypt( $svc_acct->_password,
69 $saltset[int(rand(64))].$saltset[int(rand(64))] );
72 $self->shellcommands_queue( $svc_acct->svcnum,
73 user => $self->option('user')||'root',
74 host => $self->machine,
75 command => eval(qq("$command")),
76 stdin_string => eval(qq("$stdin")),
81 my($self, $new, $old ) = (shift, shift, shift);
82 my $command = $self->option('usermod');
83 my $stdin = $self->option('usermod_stdin');
87 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
88 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
90 $new_finger = shell_quote $new_finger;
91 $quoted_new__password = shell_quote $new__password; #old, wrong?
92 $new_quoted_password = shell_quote $new__password; #new, better?
93 $old_domain = $old->domain;
94 $new_domain = $new->domain;
95 $new_crypt_password = ''; #surpress "used only once" warnings
96 $new_crypt_password = crypt( $new->_password,
97 $saltset[int(rand(64))].$saltset[int(rand(64))]);
98 if ( $self->option('usermod_pwonly') ) {
100 if ( $old_username ne $new_username ) {
101 $error ||= "can't change username";
103 if ( $old_domain ne $new_domain ) {
104 $error ||= "can't change domain";
106 if ( $old_uid != $new_uid ) {
107 $error ||= "can't change uid";
109 if ( $old_dir ne $new_dir ) {
110 $error ||= "can't change dir";
112 return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
115 $self->shellcommands_queue( $new->svcnum,
116 user => $self->option('user')||'root',
117 host => $self->machine,
118 command => eval(qq("$command")),
119 stdin_string => eval(qq("$stdin")),
123 #a good idea to queue anything that could fail or take any time
124 sub shellcommands_queue {
125 my( $self, $svcnum ) = (shift, shift);
126 my $queue = new FS::queue {
128 'job' => "FS::part_export::shellcommands::ssh_cmd",
130 $queue->insert( @_ );
133 sub ssh_cmd { #subroutine, not method
135 &Net::SSH::ssh_cmd( { @_ } );
138 #sub shellcommands_insert { #subroutine, not method
140 #sub shellcommands_replace { #subroutine, not method
142 #sub shellcommands_delete { #subroutine, not method