From 4f34696c72c7d06b3a019addb1cd5ff736617e72 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Wed, 24 Dec 2025 11:03:44 +1100 Subject: [PATCH] Add root terminal --- app.py | 22 ++++++++++++++ templates/admin.html | 70 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) 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:~$
+ +
+
+
Dokku Terminal initialized. Ready for commands.
+
+
+ $ + +
+
+