From d8f971730457638bc0bb0380d5d506409fe8e3e7 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Mon, 10 Jun 2024 13:27:21 +0900 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=9B=9E=E8=B5=B7=E5=8B=95=E6=99=82?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index 772bd8a..aec99a4 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -1,16 +1,20 @@ import os import json +import tkinter.messagebox import customtkinter from winotify import Notification, audio import keyboard import subprocess import requests import hashlib +import string +import random +import tkinter class App(customtkinter.CTk): def __init__(self): super().__init__() - self.title("Dislocker ロック中") + self.title(f"{app_name} | ロック中") self.attributes('-fullscreen', True) self.attributes('-topmost', True) @@ -57,7 +61,7 @@ class App(customtkinter.CTk): class Lock(customtkinter.CTkToplevel): def __init__(self): super().__init__() - self.title('Dislocker | PC番号 10 | ロックされています') + self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | ロックされています') self.geometry('400x200') self.resizable(height=False, width=False) self.attributes('-topmost', True) @@ -112,6 +116,14 @@ class Lock(customtkinter.CTkToplevel): def exit(self): self.destroy() +def master_password_gen(): + numbers = string.digits # (1) + password = ''.join(random.choice(numbers) for _ in range(10)) # (2) + password_hash = hashlib.md5(password.encode()).hexdigest() + result = {"password": password, "password_hash": password_hash} + return result + +app_name = "Dislocker" config_dir_path = "./config/" client_config_path = config_dir_path + "client.json" @@ -120,17 +132,28 @@ if not os.path.isfile(client_config_path): os.mkdir(config_dir_path) client_config = { + "initial": 0, "auth_host_url": "http://localhost", - "pc_number": "" + "pc_number": 1, + "master_password_hash": "", + } with open(client_config_path, "w") as w: json.dump(client_config, w, indent=4) elif os.path.isfile(client_config_path): with open(client_config_path, "r") as r: client_config = json.load(r) + + +if client_config["initial"] == 0: + master_password = master_password_gen() + msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 初回起動を検出", message=f"初回起動のようです。\nマスターパスワードを記録しておいてください。\nこれ以降二度と表示されることはないでしょう。\n\n{master_password["password"]}\n\n") + client_config["master_password_hash"] = master_password["password_hash"] + with open(client_config_path, "w") as w: + json.dump(client_config, w, indent=4) -if __name__ == '__main__': - app = App() - app.protocol("WM_DELETE_WINDOW", app.handler_close) - app.mainloop() - +else: + if __name__ == '__main__': + app = App() + app.protocol("WM_DELETE_WINDOW", app.handler_close) + app.mainloop()