import os import json import customtkinter from winotify import Notification, audio import keyboard import subprocess import requests import hashlib class App(customtkinter.CTk): def __init__(self): super().__init__() self.title("Dislocker ロック中") self.attributes('-fullscreen', True) self.attributes('-topmost', True) self.frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') self.frame.grid(row=0, column=0, sticky='nsew') self.block_taskmgr() self.block_key() lock = Lock() def exit(self): self.unlock_taskmgr() self.toast() self.destroy() def block_key(self): block_keys = ['ctrl', 'alt', 'windows', 'shift', 'delete'] for i in block_keys: 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', '1']) print(block) def unlock_taskmgr(self): unlock = subprocess.run(['reg', 'delete', 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', '/v', 'DisableTaskMgr', '/f']) print(unlock) def toast(self): resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource") success = Notification( app_id='Dislocker', title='ご協力ありがとうございます!', msg='パスワード認証に成功しました。\n現在使われたパスワードは削除されます。', icon=resource_path + r'\success.png' ) success.set_audio(audio.Default, loop=False) success.show() def handler_close(self): pass class Lock(customtkinter.CTkToplevel): def __init__(self): super().__init__() self.title('Dislocker | PC番号 10 | ロックされています') self.geometry('400x200') self.resizable(height=False, width=False) self.attributes('-topmost', True) self.grab_set() self.lift() self.protocol("WM_DELETE_WINDOW", self.handler_close) self.msg_title_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') self.msg_title_frame.grid(row=0, column=0, sticky="nsew") self.msg_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text='ちょっと待って!!') self.msg_title_1.grid(row=0, column=0, padx=10, pady=10) self.msg_subtitle_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') self.msg_subtitle_frame.grid(row=1, column=0, sticky="nsew") self.msg_subtitle_1 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='サインインするには、パスワードが必要です。') self.msg_subtitle_1.grid(row=0, column=0, padx=10, pady=10) self.input_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') self.input_frame.grid(row=2, column=0, sticky="nsew") self.password_entry = customtkinter.CTkEntry(self.input_frame, placeholder_text='パスワード', width=380, show='*') self.password_entry.grid(row=0, column=0, padx=10, pady=10) self.button_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent') self.button_frame.grid(row=3, column=0, sticky="nsew") self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth) self.signin_button.grid(row=0, column=0, padx=10, pady=10) def hash_genarate(self, source): hashed = hashlib.md5(source.encode()) return hashed.hexdigest() def auth(self): auth_url = client_config["auth_host_url"] + "/verify" auth_json = { "pc_number": int(client_config["pc_number"]), "password": self.hash_genarate(str(self.password_entry.get())) } responce = requests.post(auth_url, json=auth_json) if responce.status_code == 200: self.destroy() app.exit() else: self.msg_subtitle_1.configure(text='サインインするには、パスワードが必要です。\nパスワードが違います!') def handler_close(self): pass def exit(self): self.destroy() 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 = { "auth_host_url": "http://localhost", "pc_number": "" } 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 __name__ == '__main__': app = App() app.protocol("WM_DELETE_WINDOW", app.handler_close) app.mainloop()