xh+=3J*的形式指定参数,默认接收到的参数类型是string
+
+# 检测安装
+if f.Had("data/config/panel.json"):
+ print("已安装")
+
+
+ @app.route("/index/", )
+ def index(id):
+ if id == 1:
+ return 'first'
+ elif id == 2:
+ return 'second'
+ elif id == 3:
+ return 'thrid'
+ else:
+ return 'hello world!'
+
+
+ if __name__ == '__main__':
+ app.run()
+else:
+ print("未安装面板")
+ install = input("是否安装面板(y/n):")
+ if install == "y":
+ # 安装面板
+ print("开始安装面板...")
+ print(paninstall.install())
+ else:
+ print("退出程序")
+
+
+
--
Gitee
From 95be88f350905ffb66425d5b6faab18bb1463956 Mon Sep 17 00:00:00 2001
From: Codepy <1942171924@qq.com>
Date: Tue, 9 Apr 2024 12:40:51 +0000
Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20data?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
data/.keep | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 data/.keep
diff --git a/data/.keep b/data/.keep
new file mode 100644
index 0000000..e69de29
--
Gitee
From 12b74f3415b605fbe648a3c9377f337f4fa37515 Mon Sep 17 00:00:00 2001
From: Codepy <1942171924@qq.com>
Date: Tue, 9 Apr 2024 12:41:05 +0000
Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20config?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
data/config/.keep | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 data/config/.keep
diff --git a/data/config/.keep b/data/config/.keep
new file mode 100644
index 0000000..e69de29
--
Gitee
From f0fa609aeeb39cb7a63109002a57fb67be7b381d Mon Sep 17 00:00:00 2001
From: Codepy <1942171924@qq.com>
Date: Tue, 9 Apr 2024 12:41:14 +0000
Subject: [PATCH 5/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20data?=
=?UTF-8?q?/.keep?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
data/.keep | 0
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 data/.keep
diff --git a/data/.keep b/data/.keep
deleted file mode 100644
index e69de29..0000000
--
Gitee
From c1b76ce79c9dd303cca59a6ffb93cb8d6368b6d3 Mon Sep 17 00:00:00 2001
From: Codepy <1942171924@qq.com>
Date: Tue, 9 Apr 2024 21:06:03 +0800
Subject: [PATCH 6/7] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=AE=89?=
=?UTF-8?q?=E8=A3=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controller/install.py | 29 ++++++++++++++++++++++++++++-
app/utils/System.py | 4 ++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/app/controller/install.py b/app/controller/install.py
index 284cc0b..c399637 100644
--- a/app/controller/install.py
+++ b/app/controller/install.py
@@ -1,4 +1,31 @@
import app.utils.System as sy
+import os
+import json
+import random
+import string
+import hashlib
+
def install():
system = sy.get_system_name()
- return system
\ No newline at end of file
+ print("正在安装", system, "系统版本的面板...")
+
+ # 生成数据
+ # 生成随机字母
+ username = ''.join(random.choices(string.ascii_letters, k=5))
+ pw = ''.join(random.choices(string.ascii_letters + string.digits, k=8))
+ port = random.randint(8888, 8900)
+ ip = sy.get_system_ip()
+ print("用户名:", username, "\n密码:", pw, "\n端口:", port)
+ print("面板访问地址: http://" + ip + ":" + str(port) + "/")
+
+ # 写入文件
+ json_data = {username: hashlib.sha256(pw.encode()).hexdigest(), "port": port}
+ with open("./data/config/panel.json", 'w') as file:
+ json.dump(json_data, file)
+
+ if system == "Windows":
+ pass
+ else:
+ # 设置文件权限为root可读写,其它用户无法读写
+ os.chmod("./data/config/panel.json", 0o600)
+ print("安装完成")
diff --git a/app/utils/System.py b/app/utils/System.py
index 8546683..2867ccc 100644
--- a/app/utils/System.py
+++ b/app/utils/System.py
@@ -1,4 +1,8 @@
import platform
+import socket
def get_system_name():
return platform.system()
+
+def get_system_ip():
+ return socket.gethostbyname(socket.gethostname())
\ No newline at end of file
--
Gitee
From aa798c0987d0eb2e550f3a33cb4dcfb0b21590b3 Mon Sep 17 00:00:00 2001
From: Codepy <1942171924@qq.com>
Date: Tue, 9 Apr 2024 21:16:43 +0800
Subject: [PATCH 7/7] =?UTF-8?q?upd=EF=BC=9A=E6=96=B0=E5=A2=9Ewin=E4=B8=8B?=
=?UTF-8?q?=E6=9D=83=E9=99=90=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controller/install.py | 14 +++++++++++++-
main.py | 2 +-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/app/controller/install.py b/app/controller/install.py
index c399637..442989f 100644
--- a/app/controller/install.py
+++ b/app/controller/install.py
@@ -24,7 +24,19 @@ def install():
json.dump(json_data, file)
if system == "Windows":
- pass
+ import subprocess
+ # 构建命令
+ command = ['icacls', "./data/config/panel.json", '/grant', '*S-1-5-32-544:(OI)(CI)F']
+
+ # 执行命令
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ output, error = process.communicate()
+
+ # 打印输出结果
+ if process.returncode == 0:
+ print("文件权限设置成功")
+ else:
+ print("文件权限设置失败:", error.decode('utf-8'))
else:
# 设置文件权限为root可读写,其它用户无法读写
os.chmod("./data/config/panel.json", 0o600)
diff --git a/main.py b/main.py
index 23e69d0..9426731 100644
--- a/main.py
+++ b/main.py
@@ -31,7 +31,7 @@ else:
if install == "y":
# 安装面板
print("开始安装面板...")
- print(paninstall.install())
+ paninstall.install()
else:
print("退出程序")
--
Gitee