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