Aktualizuj app/routes.py

This commit is contained in:
Andus 2025-05-09 10:28:18 +02:00
parent b873e71385
commit 137177efc4

View file

@ -4,6 +4,8 @@ import random
from flask import Blueprint, render_template, jsonify
from .auth import oidc
from .port_utils import get_user_ports
from .docker_utils import client
from docker.errors import NotFound
from dotenv import load_dotenv
main = Blueprint('main', __name__, static_folder='static')
@ -12,7 +14,6 @@ load_dotenv()
@main.route("/")
@oidc.require_login
def home():
username = oidc.user_getfield("preferred_username")
server_path = f"./servers/mc-{username}"
@ -57,6 +58,32 @@ def list_ads():
return jsonify(files)
@main.route("/servers")
def server_list():
servers_dir = "./servers"
server_dirs = [
d for d in os.listdir(servers_dir)
if os.path.isdir(os.path.join(servers_dir, d)) and d.startswith('mc-')
]
server_data = []
for server_dir in server_dirs:
server_name = server_dir
server_status = "stopped"
try:
container = client.containers.get(server_name)
if container.status == "running":
server_status = "running"
except NotFound:
pass
server_data.append({"name": server_name, "status": server_status})
return render_template('server_list.html', servers=server_data)
@main.app_errorhandler(404)
def page_not_found(e):
return render_template("404.html"), 404