From ad5f84d238f63fe487c45263c04108e8227bbc37 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 25 Jul 2024 19:25:47 +0900 Subject: [PATCH] =?UTF-8?q?init=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 91 ++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index 2867c89..5c0ec5b 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -14,6 +14,39 @@ import threading import signal import sys +def init(**kwargs): + app_name = "Dislocker" + if "pc_number" in kwargs: + pc_number = int(kwargs["pc_number"]) + else: + pc_number = 1 + config_dir_path = "./config/" + client_config_path = config_dir_path + "client.json" + if not os.path.isfile(client_config_path): + if not os.path.isdir(config_dir_path): + os.mkdir(config_dir_path) + + client_config = { + "initial": 1, + "auth_host_url": "http://localhost", + "pc_number": 1, + "master_password_hash": "", + "testing": 0 + } + + elif os.path.isfile(client_config_path): + with open(client_config_path, "r") as r: + client_config = json.load(r) + + if client_config["initial"] == 1: + 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"] + client_config["initial"] = 0 + client_config["pc_number"] = pc_number + with open(client_config_path, "w") as w: + json.dump(client_config, w, indent=4) + class App(customtkinter.CTk): def __init__(self): super().__init__() @@ -42,7 +75,7 @@ class App(customtkinter.CTk): keyboard.block_key(i) def block_taskmgr(self): - block = subprocess.run(['reg', 'add', 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', '/v', 'DisableTaskMgr', '/t', 'REG_DWORD', '/d', 'f', '1']) + block = subprocess.run(['reg', 'add', 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', '/v', 'DisableTaskMgr', '/t', 'REG_DWORD', '/d', '1', '/f']) print(block) def unlock_taskmgr(self): @@ -289,47 +322,19 @@ def master_password_gen(): result = {"password": password, "password_hash": password_hash} return result -app_name = "Dislocker" -config_dir_path = "./config/" -client_config_path = config_dir_path + "client.json" -if not os.path.isfile(client_config_path): - if not os.path.isdir(config_dir_path): - os.mkdir(config_dir_path) - - client_config = { - "initial": 1, - "auth_host_url": "http://localhost", - "pc_number": 1, - "master_password_hash": "", - "testing": 0 - - } - 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"] == 1: - 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"] - client_config["initial"] = 0 - with open(client_config_path, "w") as w: - json.dump(client_config, w, indent=4) - -else: - if __name__ == '__main__': - args = sys.argv - if len(args) >= 2: - if args[1] == "stop": - monitor = Monitor() - monitor.signal_handler() - else: - print("引数エラー。") +if __name__ == '__main__': + args = sys.argv + if len(args) >= 2: + if args[1] == "stop": + monitor = Monitor() + monitor.signal_handler() + elif args[1] == "setup": + init(pc_number=args[2]) else: - app = App() - app.protocol("WM_DELETE_WINDOW", app.handler_close) - app.mainloop() + print("引数エラー。") + else: + init() + app = App() + app.protocol("WM_DELETE_WINDOW", app.handler_close) + app.mainloop()