| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Rex::Interface::Exec::HTTP; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Rex::Commands; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 14 | 0 | my $that = shift; | |||||||||||||||||||
| 15 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 16 | 0 | my $self = {@_}; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | bless( $self, $proto ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | return $self; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub exec { | ||||||||||||||||||
|
Subroutine
exec: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 24 | 0 | my ( $self, $cmd, $path, $option ) = @_; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | Rex::Logger::debug("Executing: $cmd"); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | if ( exists $option->{path} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | $path = $option->{path}; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | if ($path) { $path = "PATH=$path" } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | ▶ | $path ||= ""; | ||||||||||||||||||
|
Condition0%0/2
$path ||= ""
MC/DC0%0/1
$path ||= ""
$path
Truth table0%0/2
A
A= $path
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # let the other side descide if LC_ALL=C should be used | ||||||||||||||||||||
| 36 | # for example, this will not work on windows | ||||||||||||||||||||
| 37 | #$cmd = "LC_ALL=C $path " . $cmd; | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | Rex::Commands::profiler()->start("exec: $cmd"); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | my $new_cmd = $cmd; | |||||||||||||||||||
| 42 | 0 | ▶ | if ( Rex::Config->get_source_global_profile ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | $new_cmd = ". /etc/profile >/dev/null 2>&1; $new_cmd"; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | my $resp = | |||||||||||||||||||
| 47 | connection->post( "/execute", { exec => $new_cmd, options => $option } ); | ||||||||||||||||||||
| 48 | 0 | Rex::Commands::profiler()->end("exec: $cmd"); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | if ( $resp->{ok} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | $? = $resp->{retval}; | |||||||||||||||||||
| 52 | 0 | my ( $out, $err ) = ( $resp->{output}, "" ); | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | Rex::Logger::debug($out); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | ▶ | if ($err) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | Rex::Logger::debug("========= ERR ============"); | |||||||||||||||||||
| 58 | 0 | Rex::Logger::debug($err); | |||||||||||||||||||
| 59 | 0 | Rex::Logger::debug("========= ERR ============"); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | if (wantarray) { return ( $out, $err ); } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | return $out; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||
| 67 | 0 | $? = 1; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 1 | 1; | |||||||||||||||||||