Add root terminal
This commit is contained in:
22
app.py
22
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"})
|
||||
|
||||
Reference in New Issue
Block a user