line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::Remote; |
2
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
3
|
2
|
|
|
2
|
|
19
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
3629
|
use Net::OpenSSH; |
|
2
|
|
|
|
|
59611
|
|
|
2
|
|
|
|
|
36
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1270
|
use Cinnamon::HandleManager; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
28
|
|
10
|
2
|
|
|
2
|
|
67
|
use Cinnamon::Logger; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
764
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub connection { |
13
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
14
|
0
|
|
|
|
|
0
|
return Net::OpenSSH->new( |
15
|
|
|
|
|
|
|
$self->{host}, user => $self->{user}, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
0
|
10
|
sub host { $_[0]->{host} } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub execute { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $commands, $opts) = @_; |
23
|
0
|
|
0
|
|
|
|
my $host = $self->host || ''; |
24
|
0
|
|
|
|
|
|
my $conn = $self->connection; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ($opts->{sudo}) { |
27
|
0
|
|
|
|
|
|
@$commands = ('sudo', '-Sk', @$commands); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
my ($stdin, $stdout, $stderr, $pid) = $conn->open3({ |
31
|
|
|
|
|
|
|
tty => $opts->{tty}, |
32
|
|
|
|
|
|
|
}, join ' ', @$commands) or die "open3 failed: " . $conn->error; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ($opts->{password}) { |
35
|
0
|
|
|
|
|
|
print $stdin "$opts->{password}\n"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $hm = Cinnamon::HandleManager->new(host => $self->{host}); |
39
|
0
|
|
|
|
|
|
$hm->register_fh(stdout => $stdout); |
40
|
0
|
|
|
|
|
|
$hm->register_fh(stderr => $stderr); |
41
|
0
|
|
|
|
|
|
$hm->start_async_read(); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $stdout_str = $hm->captured_str('stdout'); |
44
|
0
|
|
|
|
|
|
my $stderr_str = $hm->captured_str('stderr'); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
local $? = 0; |
47
|
0
|
|
|
|
|
|
waitpid($pid, 0); |
48
|
0
|
|
|
|
|
|
my $exitcode = $?; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
+{ |
51
|
0
|
|
|
|
|
|
stdout => $stdout_str, |
52
|
|
|
|
|
|
|
stderr => $stderr_str, |
53
|
|
|
|
|
|
|
has_error => $exitcode > 0, |
54
|
|
|
|
|
|
|
error => $exitcode, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
!!1; |