This is a lightweight Python-based HTTP server that listens for incoming HTTP requests and executes predefined bash scripts based on the request URL and authenticated headers.
- Simple HTTP server using Python's built-in
socketmodule - Executes bash scripts mapped to URL endpoints
- Authenticates requests using
Client-IDandClient-Secretheaders - Uses a
.envfile to configure allowed endpoints and secrets
- Client sends HTTP request with a
Client-IDandClient-Secretin the headers - URL is matched with a bash script path defined in
.env - If authenticated, the server executes the bash script using
subprocess - Returns HTTP response confirming script execution
Create a .env file in the same directory with the following format:
ClientId=your_client_id ClientSecret=your_client_secret # Script URLs and paths (use index numbers consistently) ScriptUrl1=/deploy-service-a ScriptPath1=/path/to/deploy-service-a.sh ScriptUrl2=/restart-db ScriptPath2=/path/to/restart-db.sh # Add more as needed🔐 The index numbers must match (e.g.,
ScriptUrl3corresponds toScriptPath3)
python3 server.pyThe server will start on 127.0.0.1:8080.
POST /deploy-service-a HTTP/1.1 Host: localhost:8080 Client-ID: your_client_id Client-Secret: your_client_secretHTTP/1.1 200 OK Content-Type: text/html Deployment done!HTTP/1.1 400 Bad Request Content-Type: text/html Client ID or Client Secret missingHTTP/1.1 400 Bad Request Content-Type: text/html Page missing-
This server does not use HTTPS. Use only on trusted networks.
-
Keep
.envsafe and secure with strong credentials. -
For production:
- Place the server behind an HTTPS reverse proxy like Nginx
- Use firewall/IP whitelisting
- Consider adding token-based or OAuth authentication
To run this with Docker:
Dockerfile
FROM python:3.10-slim WORKDIR /app COPY server.py ./ COPY .env ./ CMD ["python", "server.py"]Build and run
docker build -t bash-trigger-server . docker run -p 8080:8080 bash-trigger-serverMIT License