Table of Contents
This server provides two main routes, shell and status, for script executing and status inquires.
- Route
shell:- Function: Allow user to execute specific shell script by sending HTTP request.
- Method: GET
- Query string:
name(required): Specify the name of the script to be executed.opts(optional): Provide additional option parameters for script execution.
- Response:
- Type: JSON
- Properties:
result: Describe the outcome of the script execution, indicating whether it's still running, completed, or failed. - Stringlogs: Contain the logs generated by the script execution. - Array of Strings
- Route
status:- Function: Allow user to query the status of specific script executions.
- Method: GET
- Query string:
name(required): Specify the name of the script execition to be checked.
- Response: Same as route
shellfor consistency and ease of use.
-
No script is allowed to execute multiple times at the same time.
-
When a script is progress, the other execution requests for that script are ignored until the current execution finishes and the cooldown period elapses.
-
Initiating a script execution during the cooldown period resets the cooldown timer.
-
For security reason, only the scripts under the directory of the server artifact are permitted to execute.
nameexample:- script -> ✔
- folder1/folder2/script -> ✔
- ../folder/script -> ✘
- folder/../../script -> ✘
To streamline the logic implementation, all of string
..innamehave been removed. Although the pathfolder/../folder/scriptis equivalent tofolder/script, it will be treated asfolder/folder/script
- Create and start the docker container
docker-compose up --build
- Make some requests for executing the example shell scripts.
curl 'localhost:8080/shell?name=f1/test1&opts=p1&opts=p2'curl 'localhost:8080/shell?name=test2' - Check the status of the execution
curl 'localhost:8080/status?name=f1/test1'curl 'localhost:8080/status?name=test2' - Exit the demo project.
docker-compose down --rmi all
Customize the icon of the executable file on windows.
- Prepare one ico file (exe.ico).
- Create rc file with the following content.
#include "winuser.h" #define IDR_MYICON 101 IDR_MYICON ICON "./exe.ico" - Build syso file.
windres -o file fileinfo.syso fileinfo.rc
- Build artifact.
go build