This project provides a simple web interface to execute predefined bash scripts on the server where it's hosted.
- Lists available bash scripts from a designated
scriptsdirectory. - Allows users to select a script to run.
- Provides an option to execute the selected script with
sudoprivileges (requires server-side configuration). - Streams the script's standard output and standard error directly to the web page in real-time using Server-Sent Events (SSE).
- Clone/Download: Get the project files onto your Ubuntu machine.
- Create
scriptsDirectory: If it doesn't exist, create thescriptsdirectory insidewebapp. - Add Scripts: Place your bash scripts inside the
webapp/scripts/directory. Make sure they are executable:chmod +x webapp/scripts/*.sh - Install Dependencies: Navigate to the
webappdirectory and install Flask:cd webapp pip install Flask # or: python3 -m pip install Flask
- (Optional) Configure Sudo: If any of your scripts require
sudoand you want to allow running them with elevated privileges via the web interface:- Identify User: Determine the user running the Flask app (e.g.,
your_user,www-data). - Edit Sudoers: Run
sudo visudo. - Add Rules: Add a specific
NOPASSWDrule for each script you want to allow sudo access for. Never use a wildcard. Replace<user>and the path accordingly.# Example: Allow 'www-data' user to run 'script_needs_sudo.sh' without password <user> ALL=(ALL) NOPASSWD: /full/path/to/your/webapp/scripts/script_needs_sudo.sh - Configure
app.py: EnsureALLOW_SUDO_FROM_UI = Trueinapp.pyif you want the checkbox to attempt usingsudo. Set it toFalseto disable this feature regardless ofsudoersconfiguration.
- Identify User: Determine the user running the Flask app (e.g.,
- Navigate to the
webappdirectory in your terminal:cd /path/to/your/webapp - Run the Flask application:
python app.py # or: python3 app.py - Access the web interface in your browser, typically at
http://<your_server_ip>:5000.
Allowing web services to execute scripts, especially with sudo, is inherently dangerous.
- Ensure the
scriptsdirectory and the scripts themselves are not writable by the user running the web server (e.g.,www-data). - Only grant
sudo NOPASSWDaccess to the specific, necessary scripts. - Thoroughly vet any script placed in the
scriptsdirectory. - Consider running the web service as a non-privileged user.
- Set
ALLOW_SUDO_FROM_UI = Falseinapp.pyif you don't need the sudo feature or want maximum safety.
