main
SundayEnglish 5 months ago
parent 44593717b4
commit 1938a9d733
  1. 27
      app.py
  2. 66
      output.log
  3. 2
      servermanagement.pid

@ -20,11 +20,13 @@ USERS = {
SERVICES_FILE = os.path.join(os.path.dirname(__file__), "data", "services.json")
def load_services():
"""Đọc danh sách services từ file JSON"""
with open(SERVICES_FILE, "r", encoding="utf-8") as file:
return json.load(file)
@app.route("/")
def home():
"""Trang chủ: Hiển thị danh sách service (yêu cầu đăng nhập)"""
if "user" not in session:
return redirect(url_for("login"))
@ -33,6 +35,7 @@ def home():
@app.route("/login", methods=["GET", "POST"])
def login():
"""Xử lý đăng nhập"""
if request.method == "POST":
username = request.form.get("username")
password = request.form.get("password")
@ -48,14 +51,12 @@ def login():
@app.route("/logout")
def logout():
"""Đăng xuất"""
session.pop("user", None)
return redirect(url_for("login"))
# Streaming real-time output của lệnh
def generate_output(command_list):
# Chuyển danh sách thành chuỗi để chạy trong shell
command_str = " ".join(command_list)
def run_shell_command(command_str):
"""Chạy một lệnh shell và gửi output theo thời gian thực"""
process = subprocess.Popen(command_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, executable="/bin/bash")
for line in iter(process.stdout.readline, ''):
@ -63,7 +64,7 @@ def generate_output(command_list):
time.sleep(0.1)
for line in iter(process.stderr.readline, ''):
yield f"data: {line.strip()}\n\n"
yield f"data: [ERROR] {line.strip()}\n\n"
time.sleep(0.1)
process.wait()
@ -72,8 +73,22 @@ def generate_output(command_list):
else:
yield f"data: ERROR\n\n"
def generate_output(command_list):
"""Chạy command từ JSON, sau đó restart Nginx"""
# Chuyển danh sách command thành chuỗi
command_str = " ".join(command_list)
yield from run_shell_command(command_str) # Chạy command chính
# Sau khi chạy command xong, restart Nginx
nginx_command = "cd /projects/nginx && docker compose down && docker compose up -d"
yield f"data: === Restarting Nginx ===\n\n"
yield from run_shell_command(nginx_command) # Chạy lệnh restart Nginx
@app.route("/run-command", methods=["GET"])
def run_command():
"""API chạy command từ frontend"""
if "user" not in session:
return jsonify({"error": "Unauthorized"}), 401

@ -9,47 +9,25 @@ Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 104-926-898
14.231.189.200 - - [19/Feb/2025 14:42:45] "GET / HTTP/1.1" 302 -
14.231.189.200 - - [19/Feb/2025 14:42:45] "GET /login HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:42:46] "GET /favicon.ico HTTP/1.1" 404 -
14.231.189.200 - - [19/Feb/2025 14:42:54] "POST /login HTTP/1.1" 302 -
14.231.189.200 - - [19/Feb/2025 14:42:54] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:42:54] "GET /static/style.css HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:42:54] "GET /static/script.js HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:43:18] "GET /run-command?command[]=cd&command[]=/projects/julius&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:43:52] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:43:52] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:43:52] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:43:56] "GET /run-command?command[]=cd&command[]=/projects/julius&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:34] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:34] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:34] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:35] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /logout HTTP/1.1" 302 -
14.231.189.200 - - [19/Feb/2025 14:45:36] "GET /login HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:38] "GET / HTTP/1.1" 302 -
14.231.189.200 - - [19/Feb/2025 14:45:38] "GET /login HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:40] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:40] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:40] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:41] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:42] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 14:45:42] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:42] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 14:45:48] "GET /run-command?command[]=cd&command[]=/projects/julius&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:01:48] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:01:48] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:01:49] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:01:55] "GET /run-command?command[]=cd&command[]=/projects/julius&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:06:43] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:06:43] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:06:43] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:06:43] "GET /favicon.ico HTTP/1.1" 404 -
14.231.189.200 - - [19/Feb/2025 16:06:47] "GET /run-command?command[]=cd&command[]=/projects/julius&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:11:08] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:11:08] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:11:08] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:11:12] "GET /run-command?command[]=cd&command[]=/projects/exercise-se&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:12:16] "GET /run-command?command[]=cd&command[]=/projects/exercise-se&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:13:11] "GET /run-command?command[]=cd&command[]=/projects/exercise-se&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:13:16] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:13:16] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:13:16] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:15:55] "GET / HTTP/1.1" 200 -
14.231.189.200 - - [19/Feb/2025 16:15:55] "GET /static/style.css HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:15:55] "GET /static/script.js HTTP/1.1" 304 -
14.231.189.200 - - [19/Feb/2025 16:16:02] "GET /run-command?command[]=cd&command[]=/projects/service-se&command[]=%26%26&command[]=docker&command[]=compose&command[]=down&command[]=%26%26&command[]=docker&command[]=compose&command[]=up&command[]=-d HTTP/1.1" 200 -

@ -1 +1 @@
1349970
1364291

Loading…
Cancel
Save