From 942ce73975750ee5ead3cda576e58c9db77143fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sun, 9 Mar 2025 14:17:17 +0100 Subject: [PATCH] NEW MODAL informacje o serwerze --- app.py | 30 ++++++++++++++++ templates/clear_servers.html | 45 ++++++++++++++++++++++++ templates/server_list.html | 67 ++++++++++++++++++++++++++++++------ 3 files changed, 131 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index d122a03..e112250 100644 --- a/app.py +++ b/app.py @@ -1621,6 +1621,36 @@ def scheduled_deployments(): setting.last_deploy_time = now db.session.commit() +@app.route('/server-info/', methods=['GET']) +def server_info(id): + if 'user_id' not in session: + return {"error": "Unauthorized"}, 401 + host = db.session.get(Host, id) + if not host or host.user_id != session['user_id']: + return {"error": "Host not found or unauthorized"}, 404 + + if host.use_daemon and host.type == 'linux': + import requests + headers = {"Authorization": host.daemon_token} + sysinfo_url = host.daemon_url.rstrip('/') + '/system-info' + try: + resp = requests.get(sysinfo_url, headers=headers, verify=False, timeout=5) + if resp.status_code == 200: + data = resp.json() + return { + "hostname": format_host(host), + "ip": host.raw_ip, + "cpu": data.get('cpu_percent'), + "mem": data.get('memory_percent'), + "disk": data.get('disk_percent'), + "uptime_seconds": data.get('uptime_seconds') + } + else: + return {"error": f"Błąd demona: {resp.status_code}"}, 500 + except Exception as e: + return {"error": str(e)}, 500 + else: + return {"error": "This server does not use daemon."}, 400 @app.errorhandler(404) def page_not_found(error): diff --git a/templates/clear_servers.html b/templates/clear_servers.html index 3426411..9f6a05d 100644 --- a/templates/clear_servers.html +++ b/templates/clear_servers.html @@ -74,4 +74,49 @@ this.submit(); }); + + + {% endblock %} diff --git a/templates/server_list.html b/templates/server_list.html index d977130..7dc98ea 100644 --- a/templates/server_list.html +++ b/templates/server_list.html @@ -109,17 +109,26 @@ - - -
- Edytuj - Testuj - Backup -
- -
-
- + +
+ Edytuj + + {% if h.use_daemon and h.type == 'linux' %} + + + {% else %} + + Testuj + {% endif %} + + Backup +
+ +
+
+ {% endfor %} @@ -128,6 +137,42 @@ + + + +