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.
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.
- Go (Golang) must be installed. You can download it from here.
- Ensure your
GOPATHandGOROOTenvironment variables are set correctly.
go install github.com/eefahd/shell-gateway@latestEnsure that your Go environment variables are set:
- Add the Go bin directory to your
PATH:
export PATH=$PATH:$(go env GOPATH)/binCreate 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"
//...
]
}- 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.
Start the server by running the binary:
shell-gatewayTo execute a command or script, send an HTTP POST request with the Authorization header and, if needed, a JSON body.
curl -X POST "http://localhost:9090/echo" -H "Authorization: Bearer YOUR_TOKEN" -d '{"arguments": "Hello, World!"}'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"}'This project is licensed under the MIT License. See the LICENSE file for details.