Skip to content

eefahd/shell-gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShellGateway

ShellGateway is a minimal HTTP-based command execution service for local use. This tool allows you to execute command-line programs and shell scripts over HTTP requests. It's intended for internal use only, primarily to facilitate communication with local applications that only support frontend plugin development.

Disclaimer: This script is provided "as is" with no guarantees. Use it at your own risk.

Design Philosophy

ShellGateway is designed to be a minimal, straightforward solution with minimal configuration requirements:

  • Simplified Script Management: All scripts are expected to reside in the specified scripts directory.
  • Direct URL Mapping: The request URL corresponds directly to the script or command name, eliminating the need for mapping dictionaries.
  • Simple Argument Passing: All arguments are passed as a single string, maintaining simplicity.
  • No Unnecessary Complexity: There are no plans to add advanced features or complications, preserving its lightweight nature.

Installation

Prerequisites

  • Go (Golang) must be installed. You can download it from here.
  • Ensure your GOPATH and GOROOT environment variables are set correctly.

Installation with go install

go install github.com/eefahd/shell-gateway@latest

Environment Setup

Ensure that your Go environment variables are set:

  • Add the Go bin directory to your PATH:
export PATH=$PATH:$(go env GOPATH)/bin

Configuration

Create a config.json file in the .config/shell-gateway/ directory under your home directory with the following content:

{
  "port": "9090",
  "api_token": "YOUR_TOKEN",
  "scripts_directory": "YOUR_SCRIPTS_DIR_PATH",
  "allowed_commands": [
    "YOUR_COMMAND", // example: echo
    "YOUR_COMMAND2"
    //...
  ]
}

Note

  • Allowed Commands: A list of commands that are allowed to be executed. This setting is only needed to restrict command execution for more security, and does not apply to scripts.

Running the Server

Start the server by running the binary:

shell-gateway

Making Requests

To execute a command or script, send an HTTP POST request with the Authorization header and, if needed, a JSON body.

Example: Executing a Command

curl -X POST "http://localhost:9090/echo" -H "Authorization: Bearer YOUR_TOKEN" -d '{"arguments": "Hello, World!"}'

Example: Executing a Script

Assuming you have a script named test.sh in your scripts directory:

curl -X POST "http://localhost:9090/test" -H "Authorization: Bearer YOUR_TOKEN" -d '{"arguments": "arg1 arg2"}'

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Minimal HTTP service for executing shell scripts and commands locally via HTTP requests.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages