| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::Shell::Base; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
18
|
use v5.12.5; |
|
|
1
|
|
|
|
|
4
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
523
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
14
|
0
|
|
|
|
|
|
my $self = {}; |
|
15
|
0
|
|
|
|
|
|
$self->{path} = undef; |
|
16
|
0
|
|
|
|
|
|
$self->{__inner_shell__} = undef; |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
bless( $self, $class ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub name { |
|
24
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
25
|
0
|
|
|
|
|
|
my $class_name = ref $self; |
|
26
|
0
|
|
|
|
|
|
my @parts = split( /::/, $class_name ); |
|
27
|
0
|
|
|
|
|
|
return lc( $parts[-1] ); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub set_environment { |
|
31
|
0
|
|
|
0
|
0
|
|
my ( $self, $env ) = @_; |
|
32
|
0
|
|
|
|
|
|
$self->{__env__} = $env; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub set_inner_shell { |
|
36
|
0
|
|
|
0
|
0
|
|
my ( $self, $use_inner_shell ) = @_; |
|
37
|
0
|
|
|
|
|
|
$self->{__inner_shell__} = $use_inner_shell; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub set_locale { |
|
41
|
0
|
|
|
0
|
0
|
|
my ( $self, $locale ) = @_; |
|
42
|
0
|
|
|
|
|
|
$self->{locale} = $locale; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set_sudo_env { |
|
46
|
0
|
|
|
0
|
0
|
|
my ( $self, $sudo_env ) = @_; |
|
47
|
0
|
|
|
|
|
|
$self->{__sudo_env__} = $sudo_env; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub detect { |
|
51
|
0
|
|
|
0
|
0
|
|
my ( $self, $con ) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
0
|
|
|
|
my $shell_class = ref $self || $self; # $self might be only the classname |
|
54
|
0
|
|
|
|
|
|
my @parts = split /::/, $shell_class; |
|
55
|
0
|
|
0
|
|
|
|
my $last_part = lc( $parts[-1] || "" ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my ($shell_path) = $con->_exec("echo \$SHELL"); |
|
58
|
0
|
0
|
|
|
|
|
if ( !$shell_path ) { |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# try it a second time |
|
61
|
|
|
|
|
|
|
# we need this sometimes because the tty allocation is too slow, or |
|
62
|
|
|
|
|
|
|
# doesn't work, or ??? |
|
63
|
|
|
|
|
|
|
# it seems that this happens only for the very first command with |
|
64
|
|
|
|
|
|
|
# Net::OpenSSH when using a tty. |
|
65
|
0
|
|
|
|
|
|
Rex::Logger::debug( |
|
66
|
|
|
|
|
|
|
"Failed detecting shell in the first try. Trying again."); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
($shell_path) = $con->_exec("echo \$SHELL"); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$shell_path =~ s/(\r?\n)//gms; # remove unnecessary newlines |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
0
|
|
|
|
if ( $shell_path && $shell_path =~ m/\/\Q$last_part\E$/ ) { |
|
74
|
0
|
|
|
|
|
|
return 1; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return 0; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |