初回起動時の処理を追加
This commit is contained in:
parent
0c4da769ac
commit
d8f9717304
1 changed files with 31 additions and 8 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue