From 6db9765a5d659d3df3276bbb5d1f92d16eb26bf6 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 13 Apr 2024 21:02:34 +0800 Subject: [PATCH 01/12] =?UTF-8?q?upd=EF=BC=9A=E4=BC=98=E5=8C=96=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/index.py | 5 ++++- app/utils/Config.py | 1 + app/utils/Route.py | 2 -- app/utils/Service.py | 3 ++- main.py | 2 ++ public/static/css/index.css | 30 ++++++++++++++++++++++++++++++ public/static/css/login.css | 4 ++++ public/static/img/ico.png | Bin 0 -> 3216 bytes public/static/img/panel.png | Bin 0 -> 6682 bytes templates/index.html | 18 ++++++++++++++++++ templates/login.html | 1 + 11 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 public/static/css/index.css create mode 100644 public/static/img/ico.png create mode 100644 public/static/img/panel.png diff --git a/app/controller/index.py b/app/controller/index.py index 15c3bd3..b88fc39 100644 --- a/app/controller/index.py +++ b/app/controller/index.py @@ -1,4 +1,6 @@ -from flask import Flask, Response +import os + +from flask import Flask from app.utils import Route from app.utils import Config @@ -9,6 +11,7 @@ def service_start(): # 获取配置文件 cfg = Config.get_config() app.secret_key = cfg["secret_key"] + print(os.getcwd()) print(cfg) # 可以在路径内以/<参数名>的形式指定参数,默认接收到的参数类型是string Route.get_route(app,cfg) diff --git a/app/utils/Config.py b/app/utils/Config.py index 95a5439..091c8fb 100644 --- a/app/utils/Config.py +++ b/app/utils/Config.py @@ -1,5 +1,6 @@ import json + # JSON 文件路径 def get_config(): file_path = "./data/config/panel.json" diff --git a/app/utils/Route.py b/app/utils/Route.py index c9e0ffe..81f34f3 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -5,8 +5,6 @@ from app.controller import api def get_route(app, cfg): @app.before_request def before_request_func(): - # 打印出所有路径参数及其值 - print(request.path) if "username"in session and "pw" in session: if cfg[session.get('username')] != session.get('pw'): if request.path != "/" + cfg["safe_entry"]: diff --git a/app/utils/Service.py b/app/utils/Service.py index 6f3bc3c..0d5ed29 100644 --- a/app/utils/Service.py +++ b/app/utils/Service.py @@ -36,7 +36,8 @@ def create_systemd_service(service_name): # 打开指定路径下的注册表项 key_handle = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key, 0, winreg.KEY_WRITE) # 设置注册表项的值 - winreg.SetValueEx(key_handle, "QPanel面板", 0, winreg.REG_SZ, "C:\Program Files\QPanel\main.exe") + + winreg.SetValueEx(key_handle, "QPanel面板", 0, winreg.REG_SZ, os.getcwd()+"\main.exe") # 关闭注册表项 winreg.CloseKey(key_handle) return True diff --git a/main.py b/main.py index 2f362a1..63343c1 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,8 @@ import sys # 检测安装 if f.Had("data/config/panel.json"): print("已安装") + print("开始启动面板...") + print("------------------------------------") index.service_start() else: print("未安装面板") diff --git a/public/static/css/index.css b/public/static/css/index.css new file mode 100644 index 0000000..dbae031 --- /dev/null +++ b/public/static/css/index.css @@ -0,0 +1,30 @@ +body, html { + height: 100%; + margin: 0; + padding: 0; +} + +.container { + display: flex; + height: 100%; +} + +.menu { + min-width:80px; + width: 10%; + max-width:120px; + background-color: #e8f0ff; + color: #fff; + padding: 20px; + box-sizing: border-box; +} +.menu img{ + width:90%; + padding-inline: 5%; +} + +.content { + width: 90%; + height: 100%; + border: none; +} \ No newline at end of file diff --git a/public/static/css/login.css b/public/static/css/login.css index 2f5f060..4af1861 100644 --- a/public/static/css/login.css +++ b/public/static/css/login.css @@ -23,6 +23,10 @@ .form-group label { display: block; margin-bottom: 5px; + } + .img { + width:30%; + text-align: center; } .form-group input { width: 100%; diff --git a/public/static/img/ico.png b/public/static/img/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..a1acfa18f33abf13bbf7b3ca8217f48c8d158ff7 GIT binary patch literal 3216 zcmV;B3~%#^P)Px#1am@3R0s$N2z&@+hyVZ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j);g$c=F5@`ukcVDW%8Q&pXR~u{QzS6!m*&Fx=<_bzI|=yzD; y3vjuA@RQ&nN8n^U^1^j?7EFNrzalK+R1%}Fg4`Y+W5&&Q07`PIvenXNA^!vaO_5Rn literal 0 HcmV?d00001 diff --git a/templates/index.html b/templates/index.html index e69de29..99af1cd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -0,0 +1,18 @@ + + + + + + QPanel + + + +
+ + +
+ + diff --git a/templates/login.html b/templates/login.html index c2e00d5..bd7bf9c 100644 --- a/templates/login.html +++ b/templates/login.html @@ -9,6 +9,7 @@
+ QPanel Logo

QPanel登录

-- Gitee From 07ef62f3bd7baa818ff758b6ca14e5fa0b0dfb75 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 13 Apr 2024 21:21:06 +0800 Subject: [PATCH 02/12] =?UTF-8?q?test=EF=BC=9A=E5=89=8D=E7=AB=AF=E5=BC=80?= =?UTF-8?q?=E5=B7=A5=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/Route.py | 4 +++ public/static/css/index.css | 58 ++++++++++++++++++++++--------------- templates/index.html | 1 + templates/p/home.html | 13 +++++++++ 4 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 templates/p/home.html diff --git a/app/utils/Route.py b/app/utils/Route.py index 81f34f3..463c2a2 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -26,6 +26,10 @@ def get_route(app, cfg): def home(): return render_template('index.html') + @app.route("/p/") + def page(path): + return render_template("/p/" + path + '.html') + @app.route("/" + cfg["safe_entry"]) def login(): return render_template('login.html') diff --git a/public/static/css/index.css b/public/static/css/index.css index dbae031..9c9dec0 100644 --- a/public/static/css/index.css +++ b/public/static/css/index.css @@ -1,30 +1,42 @@ -body, html { - height: 100%; - margin: 0; - padding: 0; +body,html { + height:100%; + margin:0; + padding:0; } - .container { - display: flex; - height: 100%; + display:flex; + height:100%; } - .menu { - min-width:80px; - width: 10%; - max-width:120px; - background-color: #e8f0ff; - color: #fff; - padding: 20px; - box-sizing: border-box; + min-width:80px; + width:10%; + max-width:120px; + background-color:#D5E2FF; + color:#fff; + padding: 1%; + box-sizing:border-box; } -.menu img{ - width:90%; - padding-inline: 5%; +.menu-item { + padding: 0px; + margin-top:10px; + /* 矩形 2 */ + left:32px; + top:142px; + color:#000000; + width:85px; + height:41px; + border-radius:5px; + opacity:1; + background:rgba(228,236,255,0.85); + box-shadow:0px 1px 7px 0px rgba(205,205,205,0.3); +} +.menu img { + width:90%; + padding-inline:5%; + margin-bottom:10px; } - .content { - width: 90%; - height: 100%; - border: none; -} \ No newline at end of file + width:90%; + height:100%; + border:none; +} diff --git a/templates/index.html b/templates/index.html index 99af1cd..a65bd4a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,6 +11,7 @@
diff --git a/templates/p/home.html b/templates/p/home.html new file mode 100644 index 0000000..60ca61b --- /dev/null +++ b/templates/p/home.html @@ -0,0 +1,13 @@ + + + + + + + QPanel + + + + + \ No newline at end of file -- Gitee From 21bf6a09303e87f4de7b9ffb8e727b55b6c79972 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sun, 14 Apr 2024 10:09:57 +0800 Subject: [PATCH 03/12] =?UTF-8?q?bugfix=EF=BC=9ATraceback=20(most=20recent?= =?UTF-8?q?=20call=20last):=20=20=20File=20"/sec/root/quick-panel/bin/quic?= =?UTF-8?q?k-panel/./main.py",=20line=2018,=20in=20=20=20=20=20=20?= =?UTF-8?q?if=20paninstall.install():=20=20=20=20=20=20=20=20^^^^^^^^^^^^^?= =?UTF-8?q?^^^^^^^=20=20=20File=20"/sec/root/quick-panel/bin/quick-panel/a?= =?UTF-8?q?pp/controller/install.py",=20line=2058,=20in=20install=20=20=20?= =?UTF-8?q?=20=20service=5Ffile=20=3D=20Service.create=5Fsystemd=5Fservice?= =?UTF-8?q?(service=5Fname)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^=20?= =?UTF-8?q?=20=20File=20"/sec/root/quick-panel/bin/quick-panel/app/utils/S?= =?UTF-8?q?ervice.py",=20line=208,=20in=20create=5Fsystemd=5Fservice=20=20?= =?UTF-8?q?=20=20=20username=20=3D=20os.getlogin()=20=20#=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E5=90=8D=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20=20=20^^^^^^^^^^^^^=20OSError:?= =?UTF-8?q?=20[Errno=206]=20No=20such=20device=20or=20address?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/Service.py | 6 +++--- public/static/css/index.css | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/utils/Service.py b/app/utils/Service.py index 0d5ed29..844e935 100644 --- a/app/utils/Service.py +++ b/app/utils/Service.py @@ -1,11 +1,11 @@ import os from app.utils import System - +import pwd def create_systemd_service(service_name): if System.get_system_name() == "Linux": - print(1) - username = os.getlogin() # 获取当前用户名 + print("设置开机自启动") + username = pwd.getpwuid(os.getuid()).pw_name # 获取当前用户名 script_path = "/home/quick-panel/" service_content = f"""\ [Unit] diff --git a/public/static/css/index.css b/public/static/css/index.css index 9c9dec0..f1726d3 100644 --- a/public/static/css/index.css +++ b/public/static/css/index.css @@ -17,6 +17,7 @@ body,html { box-sizing:border-box; } .menu-item { + display: flex; padding: 0px; margin-top:10px; /* 矩形 2 */ @@ -29,6 +30,8 @@ body,html { opacity:1; background:rgba(228,236,255,0.85); box-shadow:0px 1px 7px 0px rgba(205,205,205,0.3); + align-items: center; + justify-content: center; } .menu img { width:90%; -- Gitee From 753fc5ee8c1b2b5b547335b3a64b1147709ebbcf Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sun, 14 Apr 2024 13:44:23 +0800 Subject: [PATCH 04/12] =?UTF-8?q?upd=EF=BC=9A=E4=BC=98=E5=8C=96=E5=90=84?= =?UTF-8?q?=E6=96=B9=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api.py | 40 +++++++++++++++++++++++++++++++++++-- app/utils/Route.py | 7 +++---- app/utils/Service.py | 3 ++- public/static/css/index.css | 5 +++++ templates/p/home.html | 2 ++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/app/controller/api.py b/app/controller/api.py index 32edff5..9839f4a 100644 --- a/app/controller/api.py +++ b/app/controller/api.py @@ -1,8 +1,8 @@ from flask import jsonify, session import hashlib -import json +import psutil def service(path, cfg, data): - if path == "login": + if path == "post/login": print(data) if data["username"] in cfg: # 登录用户名正确 @@ -16,3 +16,39 @@ def service(path, cfg, data): return jsonify({'code': 401, 'msg': 'Wrong password'}) else: return jsonify({'code': 404, 'msg': 'User not found'}) + elif path == "get/runtime_state": + # 获取CPU信息 + cpu_count = psutil.cpu_count() + cpu_percent = psutil.cpu_percent(interval=1) + + # 获取内存信息 + memory_info = psutil.virtual_memory() + total_memory = memory_info.total + memory_percent = memory_info.percent + + # 获取CPU占比前三的进程 + cpu_top_processes = sorted( + [(p.name(), p.cpu_percent()) for p in psutil.process_iter(attrs=['name', 'cpu_percent'])], + key=lambda x: x[1], + reverse=True + )[:3] + + # 获取内存占比前三的进程 + memory_top_processes = sorted( + [(p.name(), p.memory_percent()) for p in psutil.process_iter(attrs=['name', 'memory_percent'])], + key=lambda x: x[1], + reverse=True + )[:3] + + + data = { + "cpu_core": cpu_count, + "cpu_usage": cpu_percent, + "memory_total": total_memory, + "memory_usage": memory_percent, + "top_processes": { + "cpu": cpu_top_processes, + "memory": memory_top_processes + } + } + return jsonify(data) diff --git a/app/utils/Route.py b/app/utils/Route.py index 463c2a2..d44522d 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -5,7 +5,7 @@ from app.controller import api def get_route(app, cfg): @app.before_request def before_request_func(): - if "username"in session and "pw" in session: + if "username" in session and "pw" in session: if cfg[session.get('username')] != session.get('pw'): if request.path != "/" + cfg["safe_entry"]: if "/static" not in request.path and "/api/post/login" not in request.path: @@ -17,9 +17,8 @@ def get_route(app, cfg): # 未登录 abort(404) - @app.errorhandler(404) - def page_not_found(error): + def page_not_found(): return render_template('404.html'), 404 @app.route("/") @@ -39,6 +38,6 @@ def get_route(app, cfg): # 使用send_from_directory函数来发送静态文件 return send_from_directory(app.static_folder, path) - @app.route('/api/post/', methods=['POST']) + @app.route('/api/', methods=['POST', 'GET']) def api_controller(path): return api.service(path, cfg, request.json) diff --git a/app/utils/Service.py b/app/utils/Service.py index 844e935..0ebd26b 100644 --- a/app/utils/Service.py +++ b/app/utils/Service.py @@ -1,10 +1,11 @@ import os from app.utils import System -import pwd + def create_systemd_service(service_name): if System.get_system_name() == "Linux": print("设置开机自启动") + import pwd username = pwd.getpwuid(os.getuid()).pw_name # 获取当前用户名 script_path = "/home/quick-panel/" service_content = f"""\ diff --git a/public/static/css/index.css b/public/static/css/index.css index f1726d3..a8cb3d5 100644 --- a/public/static/css/index.css +++ b/public/static/css/index.css @@ -33,6 +33,11 @@ body,html { align-items: center; justify-content: center; } + +.menu-item:hover { + background-color:#eff7ff; +} + .menu img { width:90%; padding-inline:5%; diff --git a/templates/p/home.html b/templates/p/home.html index 60ca61b..a598d25 100644 --- a/templates/p/home.html +++ b/templates/p/home.html @@ -9,5 +9,7 @@ + + \ No newline at end of file -- Gitee From 3fa9f8fb0b391d00f712970b88c57172d14d3237 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Wed, 17 Apr 2024 22:18:18 +0800 Subject: [PATCH 05/12] =?UTF-8?q?upd=EF=BC=9A=E4=BC=98=E5=8C=96=E5=90=84?= =?UTF-8?q?=E6=96=B9=E9=9D=A2=E5=92=8C=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/utils/Route.py | 18 ++--- install.sh | 27 +++++++ main.py | 186 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 200 insertions(+), 31 deletions(-) diff --git a/app/utils/Route.py b/app/utils/Route.py index d44522d..72d8ea4 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -5,16 +5,16 @@ from app.controller import api def get_route(app, cfg): @app.before_request def before_request_func(): - if "username" in session and "pw" in session: - if cfg[session.get('username')] != session.get('pw'): - if request.path != "/" + cfg["safe_entry"]: - if "/static" not in request.path and "/api/post/login" not in request.path: - # 未登录 + if cfg["safe_entry"] not in str(request.path): + + if "username" in session and "pw" in session: + if cfg[session.get('username')] != session.get('pw'): + print(1) + if cfg["safe_entry"] not in str(request.referrer): abort(404) - else: - if request.path != "/" + cfg["safe_entry"]: - if "/static" not in request.path and "/api/post/login" not in request.path: - # 未登录 + else: + if cfg["safe_entry"] not in str(request.referrer): + print(str(request.referrer)) abort(404) @app.errorhandler(404) diff --git a/install.sh b/install.sh index e69de29..812219f 100644 --- a/install.sh +++ b/install.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# 克隆代码库 +git clone https://gitee.com/codekpy/quick-panel.git /home/quick-panel + +# 进入项目目录 +cd /home/quick-panel + +# 创建Python虚拟环境 +python3 -m venv venv + +# 激活虚拟环境 +source venv/bin/activate + +# 安装flask库和pyinstaller库 +pip install flask pyinstaller + +# 退出虚拟环境 +deactivate + +# 打包main.py +cd /home/quick-panel +source venv/bin/activate +pyinstaller --onefile main.py + +# 退出虚拟环境 +deactivate diff --git a/main.py b/main.py index 63343c1..6cade17 100644 --- a/main.py +++ b/main.py @@ -3,32 +3,174 @@ import subprocess import app.utils.File as f import app.controller.install as paninstall from app.controller import index +from app.utils import System +import os import sys -# 检测安装 -if f.Had("data/config/panel.json"): - print("已安装") - print("开始启动面板...") - print("------------------------------------") - index.service_start() +LOCK_FILE = "running.lock" + + +def main(): + if f.Had("data/config/panel.json"): + print("已安装") + print("开始启动面板...") + print("------------------------------------") + index.service_start() + else: + print("未安装面板") + install = input("是否安装面板(y/n):") + if install == "y": + # 安装面板 + print("开始安装面板...") + if paninstall.install(): + print("安装成功") + # 获取当前可执行文件的路径 + executable = sys.executable + # 重新启动当前程序 + subprocess.Popen([executable] + sys.argv) + # 退出当前程序 + sys.exit() + else: + print("安装失败") + else: + print("退出程序") + + +if System.get_system_name() == "Linux": + pass else: - print("未安装面板") - install = input("是否安装面板(y/n):") - if install == "y": - # 安装面板 - print("开始安装面板...") - if paninstall.install(): - print("安装成功") - # 获取当前可执行文件的路径 - executable = sys.executable - # 重新启动当前程序 - subprocess.Popen([executable] + sys.argv) - # 退出当前程序 - sys.exit() + import win32file + import win32con + import pywintypes + import winerror + import sys + + + class SingleInstanceGuardian: + def __init__(self, lock_file_path): + self._lock_file_path = lock_file_path + self._lock_file = None + + def _acquire_lock(self): + try: + # 创建一个文件用于锁定 + self._lock_file = win32file.CreateFile( + self._lock_file_path, + win32file.GENERIC_WRITE, + 0, + None, + win32file.CREATE_ALWAYS, + win32file.FILE_ATTRIBUTE_NORMAL, + None + ) + # 尝试获取文件锁 + win32file.LockFileEx(self._lock_file, + win32con.LOCKFILE_EXCLUSIVE_LOCK | win32con.LOCKFILE_FAIL_IMMEDIATELY, 0, + -0x10000, pywintypes.OVERLAPPED()) + return True + except pywintypes.error as e: + if e.winerror == winerror.ERROR_LOCK_VIOLATION: + return False + else: + raise + + def _release_lock(self): + if self._lock_file: + win32file.UnlockFileEx(self._lock_file, 0, -0x10000, pywintypes.OVERLAPPED()) + win32file.CloseHandle(self._lock_file) + + def is_already_running(self): + return not self._acquire_lock() + + def run_task(self): + if self.is_already_running(): + print("Another instance is already running.") + sys.exit(1) + + # 执行任务代码 + if f.Had("data/config/panel.json"): + print("已安装") + print("开始启动面板...") + print("------------------------------------") + index.service_start() + else: + print("未安装面板") + install = input("是否安装面板(y/n):") + if install == "y": + # 安装面板 + print("开始安装面板...") + if paninstall.install(): + print("安装成功") + # 获取当前可执行文件的路径 + executable = sys.executable + # 重新启动当前程序 + subprocess.Popen([executable] + sys.argv) + # 退出当前程序 + sys.exit() + else: + print("安装失败") + else: + print("退出程序") + # 任务完成后释放锁 + self._release_lock() + + + # 使用示例 + lock_file_path = LOCK_FILE + print("启动Windows文件锁") + guardian = SingleInstanceGuardian(lock_file_path) + +# 检查命令行参数 +if len(sys.argv) > 1: + if sys.argv[1] == "start": + # 启动程序 + if System.get_system_name() == "Linux": + import fcntl + + lockfile = open(LOCK_FILE, "w") + try: + fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError: + print("程序已经在运行中") + sys.exit(1) + lockfile.close() + os.unlink(LOCK_FILE) + main() else: - print("安装失败") - else: - print("退出程序") + guardian.run_task() + elif sys.argv[1] == "stop": + # 停止程序 + if System.get_system_name() == "Linux": + if os.path.exists(LOCK_FILE): + os.unlink(LOCK_FILE) + print("停止程序") + else: + print("程序未在运行中") + else: + # Windows + guardian._release_lock() + else: + print("无效的命令") +else: + # 启动程序 + if System.get_system_name() == "Linux": + # 启动程序 + if System.get_system_name() == "Linux": + import fcntl + lockfile = open(LOCK_FILE, "w") + try: + fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError: + print("程序已经在运行中") + sys.exit(1) + lockfile.close() + os.unlink(LOCK_FILE) + main() + else: + guardian.run_task() + else: + print("启动项目") + guardian.run_task() -- Gitee From 0623f2cbcd85627c41299ea529df2894e19538b7 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 20 Apr 2024 11:15:02 +0800 Subject: [PATCH 06/12] =?UTF-8?q?upd=EF=BC=9A=E4=BC=98=E5=8C=96=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/utils/Route.py | 7 ++++++- public/favicon.ico | Bin 0 -> 9278 bytes public/static/css/home.css | 20 ++++++++++++++++++++ public/static/css/index.css | 24 +++++++++++++++++------- public/static/js/index.js | 30 ++++++++++++++++++++++++++++++ templates/index.html | 6 ++++-- templates/p/home.html | 6 +++++- 8 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 public/favicon.ico create mode 100644 public/static/css/home.css create mode 100644 public/static/js/index.js diff --git a/.gitignore b/.gitignore index d7db213..cbea666 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ bin-release/ main.spec .build/ .dist/ +/running.lock # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # should NOT be excluded as they contain compiler settings and other important # information for Eclipse / Flash Builder. diff --git a/app/utils/Route.py b/app/utils/Route.py index 72d8ea4..5975cbc 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -1,4 +1,4 @@ -from flask import render_template, send_from_directory, request, session, abort +from flask import render_template, send_from_directory, request, session, abort, send_file from app.controller import api @@ -38,6 +38,11 @@ def get_route(app, cfg): # 使用send_from_directory函数来发送静态文件 return send_from_directory(app.static_folder, path) + @app.route('/favicon.ico') + def favicon(): + # 使用send_from_directory函数来发送静态文件 + return send_file('../../public/favicon.ico', mimetype='image/vnd.microsoft.icon') + @app.route('/api/', methods=['POST', 'GET']) def api_controller(path): return api.service(path, cfg, request.json) diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..d86dafa53ef50462557e3f769943b7f6ff236217 GIT binary patch literal 9278 zcmeI1e~esJ6~|}W3Z=wau&kv*K?H29t`#dSNXnbpZFlD_R8uYC4@{~?!G@5A@Us#+ zlW43&;V;t&A`wxfq6PsgCR!@gZhs8>V-``{=W@cx% zl9;&7>AmmVbMO70bI(2Z+&h^}6aVJV&+z|+nYkBdGR>JxW-bIPvl3E%^hewO|K1r3 z1UuzJL64mAPRu5SV6qhQ=SZ=0o)p7{&|)bpxdvJWW%*tNeOL+|??ZM{Jxtj?xwN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cc5MHHyd5O+7AGH_UwyJEmQ#Cg zrtdc?tqyzetq;0Bwgmsp9yZRY{3nt!;R;XY2)V-*R>rUAy5uY{{MO*=voT-gx^~)5?D;78-I@F&*T{@r75>VIDla1Gv1h>X{7o_4r+fKR%e6z;mC6X%Jg4^=0)Ntjm%0;#7El zy>meO5?|(m^_3AFD);gM_Z|6FwKKU}nrS~<$FYA>Sb7n720Z-T_{1n#?MDong>2cA ze+&MY?qAqY-!5G)FcR0{?b5rj#a6G5&884z)`7*ofl$xiTdOZvH4pOczxq~H|Gg)E zM_UhGcfV2{qB}sXIn&zkkpLX~JzEawnxx4)9{6X|r`PK@M7+9JZQ|srmDu@Qa>y=l zJNrNG?f}*L_j|C{%p>*=dGo{dGsfc6{4v=>UU1pJ!YyurR` z@yDu1D}Mf-zbh9w9Ts3*R`>BQ<486z1%C3E|V9?JW^6mnrQojRQ1FePb Z!Z%jKUkT}5wuQ5*>fQQOVESJg<3B;W9>o9v literal 0 HcmV?d00001 diff --git a/public/static/css/home.css b/public/static/css/home.css new file mode 100644 index 0000000..8da16a2 --- /dev/null +++ b/public/static/css/home.css @@ -0,0 +1,20 @@ +* { + box-sizing: border-box; + margin: 0 +} + +.box-content{ + display:flex; + flex-direction: column; + background-color:#FFFFFF; + width:95%; + box-shadow: 0px 4px 10px 0px rgba(223, 223, 223, 0.3); + margin-top:1rem; + padding: 8px 10px +} + +body{ + background-color:#F4F8FF; + display: flex; + flex-wrap: nowrap; +} \ No newline at end of file diff --git a/public/static/css/index.css b/public/static/css/index.css index a8cb3d5..a0b9de6 100644 --- a/public/static/css/index.css +++ b/public/static/css/index.css @@ -5,37 +5,47 @@ body,html { } .container { display:flex; + width:100%; height:100%; } .menu { min-width:80px; width:10%; max-width:120px; - background-color:#D5E2FF; + background-color:#233E79; color:#fff; padding: 1%; box-sizing:border-box; + display: flex; + flex-wrap: nowrap; + justify-content: flex-start; + flex-direction: column; + align-content: center; + align-items: baseline; } .menu-item { display: flex; padding: 0px; margin-top:10px; + margin-left:5%; /* 矩形 2 */ left:32px; top:142px; - color:#000000; - width:85px; + color:#FFFFFF; + width:90%; height:41px; border-radius:5px; opacity:1; - background:rgba(228,236,255,0.85); - box-shadow:0px 1px 7px 0px rgba(205,205,205,0.3); + background:#233E79; + align-items: center; justify-content: center; + } .menu-item:hover { - background-color:#eff7ff; + background-color:#335192; + box-shadow:0px 1px 7px 0px rgba(205,205,205,0.3); } .menu img { @@ -44,7 +54,7 @@ body,html { margin-bottom:10px; } .content { - width:90%; + width:100%; height:100%; border:none; } diff --git a/public/static/js/index.js b/public/static/js/index.js new file mode 100644 index 0000000..7720551 --- /dev/null +++ b/public/static/js/index.js @@ -0,0 +1,30 @@ +//当页面完全加载时 +window.onload = function() { + if (localStorage.getItem('page')){ + turn(localStorage.getItem('page')) + }else{ + turn('1') + } +} + +function turn (id) { + // 设置所有 class 为 .menu-item 的元素背景为 #233E79 + var menuItems = document.getElementsByClassName('menu-item'); + for (var i = 0; i < menuItems.length; i++) { + menuItems[i].style.backgroundColor = '#233E79'; + } + + var elementWithId1 = document.getElementById(id); + if (elementWithId1) { + elementWithId1.style.backgroundColor = '#407AFF'; + } + + // 设置页面中 +
diff --git a/templates/p/home.html b/templates/p/home.html index a598d25..56a6fbb 100644 --- a/templates/p/home.html +++ b/templates/p/home.html @@ -6,10 +6,14 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> QPanel + - +
+

系统:

+

获取中

+
\ No newline at end of file -- Gitee From 3dedabb05ea417eea5fcd745ad17cfd809ad97ae Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 20 Apr 2024 11:37:52 +0800 Subject: [PATCH 07/12] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9E=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api.py | 11 ++++++++++- public/static/css/home.css | 17 +++++++++++------ public/static/js/home.js | 32 ++++++++++++++++++++++++++++++++ public/static/js/index.js | 6 ++++++ templates/index.html | 2 ++ templates/p/db.html | 15 +++++++++++++++ templates/p/home.html | 5 +++-- templates/p/safe.html | 15 +++++++++++++++ templates/p/site.html | 15 +++++++++++++++ 9 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 public/static/js/home.js create mode 100644 templates/p/db.html create mode 100644 templates/p/safe.html create mode 100644 templates/p/site.html diff --git a/app/controller/api.py b/app/controller/api.py index 9839f4a..5af1c20 100644 --- a/app/controller/api.py +++ b/app/controller/api.py @@ -1,6 +1,9 @@ from flask import jsonify, session import hashlib import psutil +import platform + + def service(path, cfg, data): if path == "post/login": print(data) @@ -40,7 +43,6 @@ def service(path, cfg, data): reverse=True )[:3] - data = { "cpu_core": cpu_count, "cpu_usage": cpu_percent, @@ -52,3 +54,10 @@ def service(path, cfg, data): } } return jsonify(data) + elif path == "get/system_info": + data = { + "code": 200, + "data": platform.platform() + } + print(data) + return jsonify(data) diff --git a/public/static/css/home.css b/public/static/css/home.css index 8da16a2..98f9050 100644 --- a/public/static/css/home.css +++ b/public/static/css/home.css @@ -4,17 +4,22 @@ } .box-content{ - display:flex; - flex-direction: column; - background-color:#FFFFFF; - width:95%; + display: flex; + flex-direction: row; + background-color: #FFFFFF; + width: 95%; + margin-left: 2.5%; box-shadow: 0px 4px 10px 0px rgba(223, 223, 223, 0.3); - margin-top:1rem; - padding: 8px 10px + margin-top: 1rem; + padding: 8px 10px; } body{ background-color:#F4F8FF; display: flex; flex-wrap: nowrap; +} + +#system{ + color:#69A0FF; } \ No newline at end of file diff --git a/public/static/js/home.js b/public/static/js/home.js new file mode 100644 index 0000000..6b23025 --- /dev/null +++ b/public/static/js/home.js @@ -0,0 +1,32 @@ +window.onload = function() { + // 使用 Fetch API 发起 GET 请求 + fetch('/api/get/runtime_state') + .then(function(response) { + // 当收到响应时,将其转换为 JSON + return response.json(); + }) + .then(function(data) { + // 处理获取到的数据 + console.log(data); + }) + .catch(function(error) { + // 处理错误 + console.error('发生错误:', error); + }); + + fetch('/api/get/system_info') + .then(function(response) { + // 当收到响应时,将其转换为 JSON + return response.json(); + }) + .then(function(data) { + // 处理获取到的数据 + // 获取 id 为 system 的元素 + var systemElement = document.getElementById('system'); + systemElement.textContent = data.data; + }) + .catch(function(error) { + // 处理错误 + console.error('发生错误:', error); + }); +} \ No newline at end of file diff --git a/public/static/js/index.js b/public/static/js/index.js index 7720551..f68e6b0 100644 --- a/public/static/js/index.js +++ b/public/static/js/index.js @@ -24,6 +24,12 @@ function turn (id) { if (iframeElement) { if (id == '1') { iframeElement.src = '/p/home'; + }else if(id == '2'){ + iframeElement.src = '/p/site'; + }else if(id == '3'){ + iframeElement.src = '/p/db'; + }else if(id == '4'){ + iframeElement.src = '/p/safe'; } } localStorage.setItem('page', id) diff --git a/templates/index.html b/templates/index.html index bda8409..89eba62 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,8 @@ + + diff --git a/templates/p/db.html b/templates/p/db.html new file mode 100644 index 0000000..fd5c7ba --- /dev/null +++ b/templates/p/db.html @@ -0,0 +1,15 @@ + + + + + + + QPanel + + + + + + + \ No newline at end of file diff --git a/templates/p/home.html b/templates/p/home.html index 56a6fbb..a2c1537 100644 --- a/templates/p/home.html +++ b/templates/p/home.html @@ -6,12 +6,13 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> QPanel - + +
-

系统:

+

系统:

获取中

diff --git a/templates/p/safe.html b/templates/p/safe.html new file mode 100644 index 0000000..fd5c7ba --- /dev/null +++ b/templates/p/safe.html @@ -0,0 +1,15 @@ + + + + + + + QPanel + + + + + + + \ No newline at end of file diff --git a/templates/p/site.html b/templates/p/site.html new file mode 100644 index 0000000..fd5c7ba --- /dev/null +++ b/templates/p/site.html @@ -0,0 +1,15 @@ + + + + + + + QPanel + + + + + + + \ No newline at end of file -- Gitee From 4b48cabc9d92ff4d390266102ce3db14237bd18c Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 20 Apr 2024 11:52:40 +0800 Subject: [PATCH 08/12] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.bat | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 install.bat diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..047d035 --- /dev/null +++ b/install.bat @@ -0,0 +1,17 @@ +@echo off +set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.3.zip +set DOWNLOAD_PATH=C:\Program Files\win_0.0.3.zip +set EXTRACT_PATH=C:\Program Files\quick-panel + +echo 正在下载面板文件... +curl -o "%DOWNLOAD_PATH%" %DOWNLOAD_URL% + +echo 正在解压文件... +mkdir "%EXTRACT_PATH%" +tar -xf "%DOWNLOAD_PATH%" -C "%EXTRACT_PATH%" + +echo 正在安装面板... +cd "%EXTRACT_PATH%" +start main.exe + +echo 执行完毕! -- Gitee From 80a28f9e5aa75645617a94ca32f841e16d245772 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 20 Apr 2024 11:57:33 +0800 Subject: [PATCH 09/12] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=86=85=E7=BD=91=E6=97=A0=E6=B3=95=E8=AE=BF=E9=97=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/index.py | 2 +- install.bat | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controller/index.py b/app/controller/index.py index b88fc39..32274fd 100644 --- a/app/controller/index.py +++ b/app/controller/index.py @@ -16,4 +16,4 @@ def service_start(): # 可以在路径内以/<参数名>的形式指定参数,默认接收到的参数类型是string Route.get_route(app,cfg) - app.run(port=cfg["port"]) + app.run(host='0.0.0.0', port=cfg["port"]) diff --git a/install.bat b/install.bat index 047d035..e29cab5 100644 --- a/install.bat +++ b/install.bat @@ -1,6 +1,6 @@ @echo off -set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.3.zip -set DOWNLOAD_PATH=C:\Program Files\win_0.0.3.zip +set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.4.zip +set DOWNLOAD_PATH=C:\Program Files\win_0.0.4.zip set EXTRACT_PATH=C:\Program Files\quick-panel echo 正在下载面板文件... -- Gitee From 4ac5b7f37342933a8540fac89420873085e6fafa Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sat, 20 Apr 2024 17:11:26 +0800 Subject: [PATCH 10/12] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8DInvalid?= =?UTF-8?q?=20unit=20name=20"QPanel=E9=9D=A2=E6=9D=BF=E6=9C=8D=E5=8A=A1.se?= =?UTF-8?q?rvice"=20escaped=20as=20"QPanel\xe9\x9d\xa2\xe6\x9d\xbf\xe6\x9c?= =?UTF-8?q?\x8d\xe5\x8a\xa1.service"=20(maybe=20you=20should=20use=20syste?= =?UTF-8?q?md-escape=3F).=20Failed=20to=20enable=20unit:=20Unit=20file=20Q?= =?UTF-8?q?Panel\xe9\x9d\xa2\xe6\x9d\xbf\xe6\x9c\x8d\xe5\x8a\xa1.service?= =?UTF-8?q?=20does=20not=20exist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/install.py | 2 +- install.bat | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controller/install.py b/app/controller/install.py index cf329d9..4ef248e 100644 --- a/app/controller/install.py +++ b/app/controller/install.py @@ -53,7 +53,7 @@ def install(): os.chmod("./data/config/panel.json", 0o600) # 设置开机自启动 - service_name = "QPanel面板服务" + service_name = "QPanel_Service" service_file = Service.create_systemd_service(service_name) if service_file: diff --git a/install.bat b/install.bat index e29cab5..232aeb4 100644 --- a/install.bat +++ b/install.bat @@ -2,16 +2,17 @@ set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.4.zip set DOWNLOAD_PATH=C:\Program Files\win_0.0.4.zip set EXTRACT_PATH=C:\Program Files\quick-panel +set MAIN_EXE_PATH=%EXTRACT_PATH%\main.exe -echo 正在下载面板文件... +echo 正在下载文件... curl -o "%DOWNLOAD_PATH%" %DOWNLOAD_URL% echo 正在解压文件... mkdir "%EXTRACT_PATH%" tar -xf "%DOWNLOAD_PATH%" -C "%EXTRACT_PATH%" -echo 正在安装面板... -cd "%EXTRACT_PATH%" -start main.exe +echo 正在以管理员权限运行 main.exe... +cd /d "%EXTRACT_PATH%" +powershell Start-Process "%MAIN_EXE_PATH%" -Verb RunAs echo 执行完毕! -- Gitee From 1377890eba510cc6cf1a9c4ef2859ed0466920c9 Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sun, 21 Apr 2024 13:34:40 +0800 Subject: [PATCH 11/12] =?UTF-8?q?upd=EF=BC=9A=E7=BE=8E=E5=8C=96=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .idea/quick-panel.iml | 2 +- app/utils/Waf.py | 0 install.bat | 4 +- main.py | 18 ++++++- public/static/css/home.css | 19 ++++++- public/static/css/safe.css | 48 +++++++++++++++++ public/static/js/home.js | 107 ++++++++++++++++++++++++++++++++----- templates/p/home.html | 5 ++ templates/p/safe.html | 16 +++++- 10 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 app/utils/Waf.py create mode 100644 public/static/css/safe.css diff --git a/.idea/misc.xml b/.idea/misc.xml index 3fe72cc..9d64926 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/quick-panel.iml b/.idea/quick-panel.iml index 74d515a..44acbbd 100644 --- a/.idea/quick-panel.iml +++ b/.idea/quick-panel.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/app/utils/Waf.py b/app/utils/Waf.py new file mode 100644 index 0000000..e69de29 diff --git a/install.bat b/install.bat index 232aeb4..0793d3e 100644 --- a/install.bat +++ b/install.bat @@ -1,6 +1,6 @@ @echo off -set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.4.zip -set DOWNLOAD_PATH=C:\Program Files\win_0.0.4.zip +set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.5.zip +set DOWNLOAD_PATH=C:\Program Files\win_0.0.5.zip set EXTRACT_PATH=C:\Program Files\quick-panel set MAIN_EXE_PATH=%EXTRACT_PATH%\main.exe diff --git a/main.py b/main.py index 6cade17..b901725 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import ctypes import subprocess import app.utils.File as f @@ -18,6 +19,17 @@ def main(): index.service_start() else: print("未安装面板") + if System.get_system_name() == "Linux": + if os.getuid() != 0: + sys.exit("请使用root用户运行此程序") + else: + try: + # 使用 ctypes.windll.shell32.IsUserAnAdmin 来检查当前用户是否是管理员 + if ctypes.windll.shell32.IsUserAnAdmin() == 0: + sys.exit("请使用管理员用户运行此程序") + except AttributeError: + # 如果 IsUserAnAdmin 函数不可用,则当前系统不支持该方法,因此返回 False + sys.exit("请使用管理员用户运行此程序") install = input("是否安装面板(y/n):") if install == "y": # 安装面板 @@ -26,8 +38,12 @@ def main(): print("安装成功") # 获取当前可执行文件的路径 executable = sys.executable - # 重新启动当前程序 + if System.get_system_name() == "Linux": + input("请及时保留您的登录信息(按下任意键结束进程并重启)") + else: + input("请及时保留您的登录信息(按下任意键结束进程并手动重启)") subprocess.Popen([executable] + sys.argv) + # 退出当前程序 sys.exit() else: diff --git a/public/static/css/home.css b/public/static/css/home.css index 98f9050..70b7740 100644 --- a/public/static/css/home.css +++ b/public/static/css/home.css @@ -15,11 +15,28 @@ } body{ - background-color:#F4F8FF; + background-color: #F4F8FF; display: flex; flex-wrap: nowrap; + flex-direction: column; } #system{ color:#69A0FF; +} + + +.box-content div{ + min-height: 1rem; + display: flex; + flex-direction: column; + align-content: center; + flex-wrap: nowrap; + justify-content: center; + align-items: center; +} + +.box-content div svg{ + width:50%; + height:50%; } \ No newline at end of file diff --git a/public/static/css/safe.css b/public/static/css/safe.css new file mode 100644 index 0000000..02dde10 --- /dev/null +++ b/public/static/css/safe.css @@ -0,0 +1,48 @@ +* { + box-sizing: border-box; + margin: 0 +} + +.box-content{ + display: flex; + flex-direction: row; + background-color: #FFFFFF; + width: 95%; + margin-left: 2.5%; + box-shadow: 0px 4px 10px 0px rgba(223, 223, 223, 0.3); + margin-top: 1rem; + padding: 8px 10px; +} + +body{ + background-color: #F4F8FF; + display: flex; + flex-wrap: nowrap; + flex-direction: column; +} + +#system{ + color:#69A0FF; +} + +.round{ + padding-top: 2.4rem; + padding-bottom: 2.4rem; +} + + .safe_tabs__nav.top { + display: flex; + justify-content: space-between; /* 使选项之间有间隔 */ + gap: 10px; /* 设置选项之间的间隔大小 */ + } + + .safe_tabs__item { + padding: 10px 20px; /* 设置选项的内边距 */ + cursor: pointer; /* 将鼠标悬停样式设置为手型 */ + transition: background-color 0.3s; /* 添加过渡效果 */ + } + + .safe_tabs__item:hover { + background-color: #EDEDED; /* 悬停时的背景色 */ + color:#69A0FF; + } \ No newline at end of file diff --git a/public/static/js/home.js b/public/static/js/home.js index 6b23025..99a9549 100644 --- a/public/static/js/home.js +++ b/public/static/js/home.js @@ -1,18 +1,99 @@ window.onload = function() { // 使用 Fetch API 发起 GET 请求 - fetch('/api/get/runtime_state') - .then(function(response) { - // 当收到响应时,将其转换为 JSON - return response.json(); - }) - .then(function(data) { - // 处理获取到的数据 - console.log(data); - }) - .catch(function(error) { - // 处理错误 - console.error('发生错误:', error); - }); + function runtime_state(){ + + fetch('/api/get/runtime_state') + .then(function(response) { + // 当收到响应时,将其转换为 JSON + return response.json(); + }) + .then(function(data) { + // 处理获取到的数据 + console.log(data); + //在这处理 + + //循环4次 + var injectedHTML = "

状态

" + let number = 0; + for (let i = 0; i < 2; i++) { + if (i==0){ + cpu_core = data.cpu_core; + cpu_usage = data.cpu_usage; + cpu = cpu_usage / cpu_core; + proportion = cpu; + console.log("CPU使用率:" + cpu); + number = parseInt(cpu * 100); + text = "CPU占用" + }else{ + memory_total = data.memory_total; + memory_usage = data.memory_usage; + memory = memory_usage / memory_total; + proportion = memory; + console.log("内存使用率:" + memory_usage); + number = parseInt(memory_usage); + text = "内存占用" + } + injectedHTML += `
+ + + + + + +
+ +
+ ` + number + `% +
+ +
+ ` + text + ` +
+
+
+
+
` + } + + + // 获取 id 为 "status" 的元素 + var statusElement = document.getElementById('status'); + + // 将 HTML 注入到元素中 + if (statusElement) { + statusElement.innerHTML = ''; + statusElement.innerHTML += injectedHTML; + } else { + console.error('找不到id为"status"的元素'); + } + + }) + .catch(function(error) { + // 处理错误 + console.error('发生错误:', error); + }); + } + runtime_state() + setInterval(runtime_state, 5000) fetch('/api/get/system_info') .then(function(response) { diff --git a/templates/p/home.html b/templates/p/home.html index a2c1537..fc379c3 100644 --- a/templates/p/home.html +++ b/templates/p/home.html @@ -16,5 +16,10 @@

获取中

+
+

状态

+ + +
\ No newline at end of file diff --git a/templates/p/safe.html b/templates/p/safe.html index fd5c7ba..77a63d7 100644 --- a/templates/p/safe.html +++ b/templates/p/safe.html @@ -6,10 +6,24 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> QPanel - + +
+
+
+
+
+
系统防火墙
+
SSH管理
+
安全检测
+
+
+
+
+
+ \ No newline at end of file -- Gitee From e537493fa95a74f7b4194c9b27260948fe47848d Mon Sep 17 00:00:00 2001 From: Codepy <1942171924@qq.com> Date: Sun, 21 Apr 2024 19:30:46 +0800 Subject: [PATCH 12/12] =?UTF-8?q?bugfix=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/{api.py => Api.py} | 7 +++++++ app/controller/index.py | 8 ++++---- app/utils/Route.py | 8 ++++---- install.bat | 4 ++-- main.py | 28 ++++++++++++++++++++-------- 5 files changed, 37 insertions(+), 18 deletions(-) rename app/controller/{api.py => Api.py} (94%) diff --git a/app/controller/api.py b/app/controller/Api.py similarity index 94% rename from app/controller/api.py rename to app/controller/Api.py index 5af1c20..8cdc7c9 100644 --- a/app/controller/api.py +++ b/app/controller/Api.py @@ -1,3 +1,5 @@ +import json + from flask import jsonify, session import hashlib import psutil @@ -7,6 +9,10 @@ import platform def service(path, cfg, data): if path == "post/login": print(data) + print(cfg) + + data = data.decode('utf-8') + data = json.loads(data) if data["username"] in cfg: # 登录用户名正确 print(hashlib.sha256(data["pw"].encode()).hexdigest()) @@ -53,6 +59,7 @@ def service(path, cfg, data): "memory": memory_top_processes } } + print(data) return jsonify(data) elif path == "get/system_info": data = { diff --git a/app/controller/index.py b/app/controller/index.py index 32274fd..940a240 100644 --- a/app/controller/index.py +++ b/app/controller/index.py @@ -5,15 +5,15 @@ from app.utils import Route from app.utils import Config -def service_start(): - app = Flask(__name__, template_folder='../../templates') - app.static_folder = "../../public/static" +def service_start(ROOT_PATH): + app = Flask(__name__, template_folder=ROOT_PATH + '/templates') + app.static_folder = ROOT_PATH + "/public/static" # 获取配置文件 cfg = Config.get_config() app.secret_key = cfg["secret_key"] print(os.getcwd()) print(cfg) # 可以在路径内以/<参数名>的形式指定参数,默认接收到的参数类型是string - Route.get_route(app,cfg) + Route.get_route(app, cfg, ROOT_PATH) app.run(host='0.0.0.0', port=cfg["port"]) diff --git a/app/utils/Route.py b/app/utils/Route.py index 5975cbc..6d24403 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -1,8 +1,8 @@ from flask import render_template, send_from_directory, request, session, abort, send_file -from app.controller import api +from app.controller import Api -def get_route(app, cfg): +def get_route(app, cfg, ROOT_PATH): @app.before_request def before_request_func(): if cfg["safe_entry"] not in str(request.path): @@ -41,8 +41,8 @@ def get_route(app, cfg): @app.route('/favicon.ico') def favicon(): # 使用send_from_directory函数来发送静态文件 - return send_file('../../public/favicon.ico', mimetype='image/vnd.microsoft.icon') + return send_file(ROOT_PATH + '/public/favicon.ico', mimetype='image/vnd.microsoft.icon') @app.route('/api/', methods=['POST', 'GET']) def api_controller(path): - return api.service(path, cfg, request.json) + return Api.service(path, cfg, request.data) diff --git a/install.bat b/install.bat index 0793d3e..b8e9c52 100644 --- a/install.bat +++ b/install.bat @@ -1,6 +1,6 @@ @echo off -set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.5.zip -set DOWNLOAD_PATH=C:\Program Files\win_0.0.5.zip +set DOWNLOAD_URL=https://cn-sy1.rains3.com/stardream/windows/win_0.0.6.zip +set DOWNLOAD_PATH=C:\Program Files\win_0.0.6.zip set EXTRACT_PATH=C:\Program Files\quick-panel set MAIN_EXE_PATH=%EXTRACT_PATH%\main.exe diff --git a/main.py b/main.py index b901725..f1c00ec 100644 --- a/main.py +++ b/main.py @@ -10,13 +10,14 @@ import sys LOCK_FILE = "running.lock" +ROOT_PATH = os.getcwd() def main(): if f.Had("data/config/panel.json"): print("已安装") print("开始启动面板...") print("------------------------------------") - index.service_start() + index.service_start(ROOT_PATH) else: print("未安装面板") if System.get_system_name() == "Linux": @@ -99,18 +100,24 @@ else: return not self._acquire_lock() def run_task(self): - if self.is_already_running(): - print("Another instance is already running.") - sys.exit(1) - - # 执行任务代码 if f.Had("data/config/panel.json"): print("已安装") print("开始启动面板...") print("------------------------------------") - index.service_start() + index.service_start(ROOT_PATH) else: print("未安装面板") + if System.get_system_name() == "Linux": + if os.getuid() != 0: + sys.exit("请使用root用户运行此程序") + else: + try: + # 使用 ctypes.windll.shell32.IsUserAnAdmin 来检查当前用户是否是管理员 + if ctypes.windll.shell32.IsUserAnAdmin() == 0: + sys.exit("请使用管理员用户运行此程序") + except AttributeError: + # 如果 IsUserAnAdmin 函数不可用,则当前系统不支持该方法,因此返回 False + sys.exit("请使用管理员用户运行此程序") install = input("是否安装面板(y/n):") if install == "y": # 安装面板 @@ -119,14 +126,19 @@ else: print("安装成功") # 获取当前可执行文件的路径 executable = sys.executable - # 重新启动当前程序 + if System.get_system_name() == "Linux": + input("请及时保留您的登录信息(按下任意键结束进程并重启)") + else: + input("请及时保留您的登录信息(按下任意键结束进程并手动重启)") subprocess.Popen([executable] + sys.argv) + # 退出当前程序 sys.exit() else: print("安装失败") else: print("退出程序") + # 任务完成后释放锁 self._release_lock() -- Gitee