| 1 | package Rex::Endpoint::HTTP::Execute; | ||
| 2 | use Mojo::Base 'Mojolicious::Controller'; | ||
| 3 | |||
| 4 | use Mojo::JSON; | ||
| 5 | |||
| 6 | use Rex::Endpoint::HTTP::Interface::Exec; | ||
| 7 | |||
| 8 | # This action will render a template | ||
| 9 | sub index { | ||
| 10 | my $self = shift; | ||
| 11 | |||
| 12 | my $ref = $self->req->json; | ||
| 13 | my $cmd = $ref->{exec}; | ||
| 14 | |||
| 15 | my ($out); | ||
| 16 | eval { | ||
| 17 | my $iface = Rex::Endpoint::HTTP::Interface::Exec->create; | ||
| 18 | $out = $iface->exec($cmd); | ||
| 19 | }; | ||
| 20 | |||
| 21 | if($@) { | ||
| 22 | return $self->render_json({ok => Mojo::JSON->false, output => "$@", retval => 1}); | ||
| 23 | } | ||
| 24 | |||
| 25 | $self->render_json({ok => Mojo::JSON->true, output => $out, retval => $?}); | ||
| 26 | } | ||
| 27 | |||
| 28 | 1; |