diff --git a/app.py b/app.py index e158e28..a782290 100644 --- a/app.py +++ b/app.py @@ -526,3 +526,25 @@ def api_sql_query(): result = run_sql_query(container, query) return jsonify(result) + +# API endpoint for shell commands +@app.post("/api/terminal/exec") +@login_required +def api_terminal_exec(): + data = request.json + command = data.get("command") + + if not command: + return jsonify({"error": "No command provided"}), 400 + + try: + # Use shell execution via sh() + # sh() uses subprocess.check_output with shell=False by default (list of strings) + # However, to support pipe/redirection for the user, we should allow shell=True-like behavior + # Let's wrap it in ['sh', '-c', command] + output = sh(["sh", "-c", command]) + return jsonify({"output": output, "status": "success"}) + except subprocess.CalledProcessError as e: + return jsonify({"output": e.output or str(e), "error": True, "status": "error"}) + except Exception as e: + return jsonify({"output": str(e), "error": True, "status": "error"}) diff --git a/templates/admin.html b/templates/admin.html index e537709..e8dc5d5 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -591,6 +591,33 @@ + + + + + Server Shell Access + [^ BACK_TO_TOP] + + + + + ROOT@DOKKU:~$ + COPY BUFFER + + + Dokku Terminal initialized. Ready for commands. + + + $ + + + +