line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::Remote; |
2
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
1590
|
use Net::OpenSSH; |
|
2
|
|
|
|
|
46866
|
|
|
2
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
951
|
use Cinnamon::HandleManager; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
64
|
|
7
|
2
|
|
|
2
|
|
15
|
use Cinnamon::Logger; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
578
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
11
|
0
|
|
|
|
|
|
bless \%args, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub connection { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
return Net::OpenSSH->new( |
17
|
|
|
|
|
|
|
$self->{host}, user => $self->{user}, |
18
|
0
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
|
sub host { $_[0]->{host} } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub execute { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $opt, @cmd) = @_; |
25
|
0
|
|
0
|
|
|
|
my $host = $self->host || ''; |
26
|
0
|
|
|
|
|
|
my $conn = $self->connection; |
27
|
0
|
|
|
|
|
|
my $exec_opt = {}; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
|
|
|
if (defined $opt && $opt->{sudo}) { |
30
|
0
|
|
|
|
|
|
@cmd = ('sudo', '-Sk', @cmd); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my ($stdin, $stdout, $stderr, $pid) = $conn->open3({ |
34
|
|
|
|
|
|
|
tty => $opt->{tty}, |
35
|
0
|
|
|
|
|
|
}, join ' ', @cmd); |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if ($opt->{password}) { |
38
|
0
|
|
|
|
|
|
print $stdin "$opt->{password}\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $hm = Cinnamon::HandleManager->new(host => $self->{host}); |
42
|
0
|
|
|
|
|
|
$hm->register_fh(stdout => $stdout); |
43
|
0
|
|
|
|
|
|
$hm->register_fh(stderr => $stderr); |
44
|
0
|
|
|
|
|
|
$hm->start_async_read(); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $stdout_str = $hm->captured_str('stdout'); |
47
|
0
|
|
|
|
|
|
my $stderr_str = $hm->captured_str('stderr'); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
local $? = 0; |
50
|
0
|
|
|
|
|
|
waitpid($pid, 0); |
51
|
0
|
|
|
|
|
|
my $exitcode = $?; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
+{ |
54
|
0
|
|
|
|
|
|
stdout => $stdout_str, |
55
|
|
|
|
|
|
|
stderr => $stderr_str, |
56
|
|
|
|
|
|
|
has_error => $exitcode > 0, |
57
|
|
|
|
|
|
|
error => $exitcode, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DESTROY { |
62
|
0
|
|
|
0
|
|
|
my $self = shift; |
63
|
0
|
|
|
|
|
|
$self->{connection} = undef; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
!!1; |