You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
1.3 KiB

from flask import Flask, render_template, request, jsonify
import subprocess
import json
import os
app = Flask(__name__)
# Định nghĩa đường dẫn file JSON chứa danh sách service
SERVICES_FILE = os.path.join(os.path.dirname(__file__), "data", "services.json")
# Load danh sách dịch vụ từ file JSON
def load_services():
with open(SERVICES_FILE, "r", encoding="utf-8") as file:
return json.load(file)
@app.route("/")
def home():
listService = load_services() # Đọc danh sách service từ file
return render_template("index.html", listService=listService)
@app.route("/run-command", methods=["POST"])
def run_command():
data = request.json
command = data.get("command")
if not command:
return jsonify({"error": "No command provided"}), 400
try:
# Chạy lệnh trong shell và lấy kết quả đầu ra
result = subprocess.run(command, shell=True, capture_output=True, text=True, executable="/bin/bash")
output = result.stdout.strip() if result.returncode == 0 else result.stderr.strip()
return jsonify({"status": "success" if result.returncode == 0 else "error", "output": output})
except Exception as e:
return jsonify({"status": "error", "output": str(e)}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)