Giter Site home page Giter Site logo

lenosi / gorestcmd Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5 KB

GoRESTCmd is a straightforward web application that enables remote execution of shell commands through HTTP API requests. This web service offers multiple API endpoints for executing, monitoring the status, and retrieving output from executed commands.

Go 100.00%

gorestcmd's Introduction

GoRESTCmd

GoRESTCmd is a straightforward web application that enables remote execution of shell commands through HTTP API requests. This web service offers multiple API endpoints for executing, monitoring the status, and retrieving output from executed commands.

Features

  • Execute shell commands remotely via HTTP API
  • Retrieve the command output (stdout and stderr)
  • Check the status of executed commands
  • Limit concurrent command executions
  • API key authentication

Configuration

Create a config.json file in the root of the project with the following contents:

api_key: "your-api-key",
concurrent_limit: 5,
port: 8080,
server_tls: false
server_cert_path: server.cert
server_key_path: server.key
allowed_commands: ["echo", "ping", "ls", "mkdir"]

Replace your-api-key with the actual API key you want to use. You can also adjust the concurrent_limit and port settings.

Getting Started

Prerequisites

  • Go (1.20 or later)

Building and Running

To build and run the Remote Executor, execute the following commands in the project root:

go build -o gorestcmd main.go
./gorestcmd

The Remote Executor service will start and listen on the configured port (default: 8080).

API Endpoints

POST /execute

Execute a shell command.

Request body:

{
  "command": "your-command",
  "args": ["arg1", "arg2", "arg3"]
}

Response:

Execution ID

GET /execution/ID/result

Get the result of an executed command.

Response:

{
  "stdout": "Command output",
  "stderr": "Command error output",
  "returnCode": 0,
  "startTime": "2023-04-01T00:00:00Z",
  "endTime": "2023-04-01T00:00:05Z",
  "elapsed": "5s",
  "status": "completed"
}

GET /execution/ID/stdout

Get the stdout output of an executed command.

Response:

Command output

GET /execution/ID/stderr

Get the stderr output of an executed command.

Response:

Command error output

GET /execution/list

Get a list of executed commands and their statuses.

Response:

{
  "1": "completed",
  "2": "running",
  "3": "canceled"
}

POST /execution/cancel/ID

Cancel a running command.

Response:

Execution canceled

Tests

To run the tests, execute the following command in the project root:

go test -v

License

This project is licensed under the MIT License

gorestcmd's People

Contributors

lenosi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.