| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Unix::RPasswd::Connection; |
|
2
|
|
|
|
|
|
|
# This is an internal module of App::Unix::RPasswd |
|
3
|
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
23833
|
use feature ':5.10'; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
290
|
|
|
5
|
3
|
|
|
3
|
|
900
|
use Moo; |
|
|
3
|
|
|
|
|
17757
|
|
|
|
3
|
|
|
|
|
19
|
|
|
6
|
3
|
|
|
3
|
|
5893
|
use Expect; |
|
|
3
|
|
|
|
|
97688
|
|
|
|
3
|
|
|
|
|
1357
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.53'; |
|
9
|
|
|
|
|
|
|
our $AUTHOR = 'Claudio Ramirez '; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'user' => ( |
|
12
|
|
|
|
|
|
|
is => 'ro', |
|
13
|
|
|
|
|
|
|
#isa => 'Str', |
|
14
|
|
|
|
|
|
|
required => 1, |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'ssh_args' => ( |
|
18
|
|
|
|
|
|
|
is => 'ro', |
|
19
|
|
|
|
|
|
|
#isa => 'ArrayRef[Str]', |
|
20
|
|
|
|
|
|
|
required => 1, |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub run { |
|
24
|
0
|
|
|
0
|
0
|
|
my ( $self, $server, $new_pass, $debug ) = @_; |
|
25
|
0
|
|
|
|
|
|
my $success = 0; |
|
26
|
0
|
|
|
|
|
|
my $exp = Expect->new(); |
|
27
|
0
|
|
|
|
|
|
$exp->raw_pty(1); |
|
28
|
0
|
0
|
|
|
|
|
$exp->log_stdout(0) if !$debug; |
|
29
|
0
|
0
|
|
|
|
|
$exp->spawn( $self->_construct_cmd($server) ) |
|
30
|
|
|
|
|
|
|
or warn 'Cannot change the password of ' |
|
31
|
|
|
|
|
|
|
. $self->user |
|
32
|
|
|
|
|
|
|
. "\@$server: $!\n"; |
|
33
|
|
|
|
|
|
|
$exp->expect( |
|
34
|
|
|
|
|
|
|
"10", |
|
35
|
|
|
|
|
|
|
[ |
|
36
|
|
|
|
|
|
|
qr/password:/i => sub { |
|
37
|
0
|
|
|
0
|
|
|
my $exp = shift; |
|
38
|
0
|
|
|
|
|
|
$exp->send( $new_pass . "\r" ); |
|
39
|
0
|
|
|
|
|
|
exp_continue; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
0
|
|
|
|
|
|
] |
|
42
|
|
|
|
|
|
|
); |
|
43
|
0
|
|
|
|
|
|
$exp->soft_close(); |
|
44
|
0
|
0
|
|
|
|
|
$success = ( $exp->exitstatus == 0 ) ? 1 : 0; # shell -> perl status |
|
45
|
0
|
0
|
|
|
|
|
if ( $success == 1 ) { |
|
46
|
0
|
|
|
|
|
|
say "Password changed on $server."; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
else { |
|
49
|
0
|
|
|
|
|
|
warn "Failed to change the password on $server.\n"; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
0
|
|
|
|
|
|
return $success; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _construct_cmd { |
|
55
|
0
|
|
|
0
|
|
|
my ( $self, $server ) = @_; |
|
56
|
0
|
|
|
|
|
|
my @command = ( |
|
57
|
0
|
|
|
|
|
|
@{ $self->ssh_args }, |
|
58
|
|
|
|
|
|
|
$server, '/usr/bin/passwd', $self->user |
|
59
|
|
|
|
|
|
|
); |
|
60
|
0
|
|
|
|
|
|
return @command; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |