Add root terminal

This commit is contained in:
Peter Stockings
2025-12-24 11:03:44 +11:00
parent 0c89a0f745
commit 4f34696c72
2 changed files with 91 additions and 1 deletions

22
app.py
View File

@@ -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"})