diff --git a/.gitignore b/.gitignore index 5d947ca8879f8a9072fe485c566204e3c2929e80..09664631dcf2a71e6f8733a332fa3748092a60ca 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ bin-release/ *.air *.ipa *.apk - +.venv/ # 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/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..359bb5307e8535ab7d59faf27a7377033291821e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..d72b3f9c6425e5ad077406ef2dbe8f19ba10daac --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..0dfac631eed9d2382853092b0af9e49e94f6f564 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/quick-panel.iml b/.idea/quick-panel.iml new file mode 100644 index 0000000000000000000000000000000000000000..74d515a027de98657e9d3d5f0f1831882fd81374 --- /dev/null +++ b/.idea/quick-panel.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/controller/__pycache__/install.cpython-36.pyc b/app/controller/__pycache__/install.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..50118b4a59d76f26e43e8ea6096d1cdaf015c848 Binary files /dev/null and b/app/controller/__pycache__/install.cpython-36.pyc differ diff --git a/app/controller/install.py b/app/controller/install.py new file mode 100644 index 0000000000000000000000000000000000000000..442989fd41755ffd468ad4d14bb9c9fb864152ed --- /dev/null +++ b/app/controller/install.py @@ -0,0 +1,43 @@ +import app.utils.System as sy +import os +import json +import random +import string +import hashlib + +def install(): + system = sy.get_system_name() + 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": + 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) + print("安装完成") diff --git a/app/utils/File.py b/app/utils/File.py new file mode 100644 index 0000000000000000000000000000000000000000..a4f7ca3c78c1f84ee6e4012e302ce8876829f7fc --- /dev/null +++ b/app/utils/File.py @@ -0,0 +1,9 @@ +import os + +def Had(path): + file_path = path + + if os.path.exists(file_path): + return True + else: + return False \ No newline at end of file diff --git a/app/utils/System.py b/app/utils/System.py new file mode 100644 index 0000000000000000000000000000000000000000..2867cccde23bb78d0470594295f5011cffd9cfb4 --- /dev/null +++ b/app/utils/System.py @@ -0,0 +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 diff --git a/app/utils/__pycache__/File.cpython-36.pyc b/app/utils/__pycache__/File.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c7f40b307d40e6fe32b23b39e67780569408306 Binary files /dev/null and b/app/utils/__pycache__/File.cpython-36.pyc differ diff --git a/app/utils/__pycache__/System.cpython-36.pyc b/app/utils/__pycache__/System.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..edad6602355ff96ebf8b49996e0315bb9f75c7bb Binary files /dev/null and b/app/utils/__pycache__/System.cpython-36.pyc differ diff --git a/data/config/.keep b/data/config/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..9426731f4904d7afb187bad0e29d25370d4aaae7 --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +from flask import Flask, Response +import app.utils.File as f +import app.controller.install as paninstall + +app = Flask(__name__) + +# 可以在路径内以/<参数名>的形式指定参数,默认接收到的参数类型是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("开始安装面板...") + paninstall.install() + else: + print("退出程序") + + +