初回起動時の処理を追加

This commit is contained in:
suti7yk5032 2024-06-10 13:27:21 +09:00
parent 0c4da769ac
commit d8f9717304

View file

@ -1,16 +1,20 @@
import os import os
import json import json
import tkinter.messagebox
import customtkinter import customtkinter
from winotify import Notification, audio from winotify import Notification, audio
import keyboard import keyboard
import subprocess import subprocess
import requests import requests
import hashlib import hashlib
import string
import random
import tkinter
class App(customtkinter.CTk): class App(customtkinter.CTk):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.title("Dislocker ロック中") self.title(f"{app_name} | ロック中")
self.attributes('-fullscreen', True) self.attributes('-fullscreen', True)
self.attributes('-topmost', True) self.attributes('-topmost', True)
@ -57,7 +61,7 @@ class App(customtkinter.CTk):
class Lock(customtkinter.CTkToplevel): class Lock(customtkinter.CTkToplevel):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.title('Dislocker | PC番号 10 | ロックされています') self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | ロックされています')
self.geometry('400x200') self.geometry('400x200')
self.resizable(height=False, width=False) self.resizable(height=False, width=False)
self.attributes('-topmost', True) self.attributes('-topmost', True)
@ -112,6 +116,14 @@ class Lock(customtkinter.CTkToplevel):
def exit(self): def exit(self):
self.destroy() 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/" config_dir_path = "./config/"
client_config_path = config_dir_path + "client.json" 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) os.mkdir(config_dir_path)
client_config = { client_config = {
"initial": 0,
"auth_host_url": "http://localhost", "auth_host_url": "http://localhost",
"pc_number": "" "pc_number": 1,
"master_password_hash": "",
} }
with open(client_config_path, "w") as w: with open(client_config_path, "w") as w:
json.dump(client_config, w, indent=4) json.dump(client_config, w, indent=4)
elif os.path.isfile(client_config_path): elif os.path.isfile(client_config_path):
with open(client_config_path, "r") as r: with open(client_config_path, "r") as r:
client_config = json.load(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__': else:
app = App() if __name__ == '__main__':
app.protocol("WM_DELETE_WINDOW", app.handler_close) app = App()
app.mainloop() app.protocol("WM_DELETE_WINDOW", app.handler_close)
app.mainloop()