diff --git a/README.md b/README.md index 6b3e88ad3e7dc2157fdb74d0244da98d0f98aae8..872689546dade77968624855e6a353e3f90c2782 100644 --- a/README.md +++ b/README.md @@ -4,34 +4,21 @@ 使用Python+flask框架搭建的服务器管理面板 #### 软件架构 -软件架构说明 +使用Python 3.6.8环境,flask作为后端框架开发。 #### 安装教程 -1. xxxx -2. xxxx -3. xxxx +##### Linux版本 +1. 下载master分支的`install.sh`并执行,然后根据输出信息登录面板 -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx +##### Windows版本 +1. 下载软件的Windows发行版,并运行main.exe即可(绿色软件,放哪儿都可以) +2. 请注意⚠️该面板对Windows版本的兼容性较差。(主要体现在后台运行方面) #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +4. 新建 Pull Request \ No newline at end of file diff --git a/app/controller/api.py b/app/controller/api.py index 32edff5725d30ce01bf6df441bcb2fd2330c06c7..9839f4af586a856a17b962a557c8b05322a22d31 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/controller/index.py b/app/controller/index.py index 15c3bd36d2916d07f57f6bea2c4da7e03cc34485..b88fc39bd2fefe25509bf0f05fa7ee20294d132f 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 95a543977e8c868c8bc3c9831f642b8464629f82..091c8fb4fa278548da57ebdfc4747b7c2a58d426 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 c9e0ffeb4020b89046e902f9002e20ee2a2dec64..d44522da89c9282f14b769a8af49da855086a6bc 100644 --- a/app/utils/Route.py +++ b/app/utils/Route.py @@ -5,9 +5,7 @@ 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 "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: @@ -19,15 +17,18 @@ 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("/") 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') @@ -37,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 6f3bc3ca1df042cb2f989192b79dba5e2df678bb..0ebd26b05f3d7c43cf42476bfc613a2c3282a991 100644 --- a/app/utils/Service.py +++ b/app/utils/Service.py @@ -4,8 +4,9 @@ from app.utils import System def create_systemd_service(service_name): if System.get_system_name() == "Linux": - print(1) - username = os.getlogin() # 获取当前用户名 + print("设置开机自启动") + import pwd + username = pwd.getpwuid(os.getuid()).pw_name # 获取当前用户名 script_path = "/home/quick-panel/" service_content = f"""\ [Unit] @@ -36,7 +37,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 2f362a1913cf19fb9bd69a4013a5ffb75ff5259b..63343c1781c128e6777d013b49455ea5f18e4f2e 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 0000000000000000000000000000000000000000..a8cb3d5769a92c7d0abeaf58b53a38d2568567c7 --- /dev/null +++ b/public/static/css/index.css @@ -0,0 +1,50 @@ +body,html { + height:100%; + margin:0; + padding:0; +} +.container { + display:flex; + height:100%; +} +.menu { + min-width:80px; + width:10%; + max-width:120px; + background-color:#D5E2FF; + color:#fff; + padding: 1%; + box-sizing:border-box; +} +.menu-item { + display: flex; + 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); + align-items: center; + justify-content: center; +} + +.menu-item:hover { + background-color:#eff7ff; +} + +.menu img { + width:90%; + padding-inline:5%; + margin-bottom:10px; +} +.content { + width:90%; + height:100%; + border:none; +} diff --git a/public/static/css/login.css b/public/static/css/login.css index 2f5f060390a8c5f849cbbe57a14a683e47cc5143..4af186110f3e7e30a78fb94f3442c655e74b32a0 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 Binary files /dev/null and b/public/static/img/ico.png differ diff --git a/public/static/img/panel.png b/public/static/img/panel.png new file mode 100644 index 0000000000000000000000000000000000000000..a9c4da70cb09295d427b12b2f9106e4deb8cadc6 Binary files /dev/null and b/public/static/img/panel.png differ diff --git a/templates/index.html b/templates/index.html index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a65bd4ad8582b7b813874a04a19305b2c23a2dd9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -0,0 +1,19 @@ + + + + + + QPanel + + + +
+ + +
+ + diff --git a/templates/login.html b/templates/login.html index c2e00d517712e070a93161191031c2450c099fdd..bd7bf9c380a340de87ab9e3e8ab9c98a2660ff81 100644 --- a/templates/login.html +++ b/templates/login.html @@ -9,6 +9,7 @@
+ QPanel Logo

QPanel登录

diff --git a/templates/p/home.html b/templates/p/home.html new file mode 100644 index 0000000000000000000000000000000000000000..a598d25f94f18b5026bf316a7343bb9383672aff --- /dev/null +++ b/templates/p/home.html @@ -0,0 +1,15 @@ + + + + + + + QPanel + + + + + + + \ No newline at end of file