Dislocker/dislocker_client.py

136 lines
5.2 KiB
Python

import psycopg2
import os
import json
import customtkinter
from winotify import Notification, audio
import keyboard
import subprocess
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("Dislocker ロック中")
self.attributes('-fullscreen', True)
self.frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
self.frame.grid(row=0, column=0, sticky='nsew')
self.restore_button = customtkinter.CTkButton(self.frame, text='認証ウィンドウを再表示', command=self.handler_close, width=240)
self.restore_button.grid(row=0, column=0)
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.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)
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 auth(self):
self.db = psycopg2.connect(f"host={db_config["host"]} dbname={db_config["db"]} port={db_config["port"]} user={db_config["username"]} password={db_config["password"]}")
cursor = self.db.cursor()
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (10,))
pc_info = cursor.fetchall()
auth_password = str(self.password_entry.get())
if pc_info[0][2] == auth_password:
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (10,))
self.db.commit()
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/"
db_config_path = config_dir_path + "db.json"
if not os.path.isfile(db_config_path):
if not os.path.isdir(config_dir_path):
os.mkdir(config_dir_path)
db_config = {
"host": "localhost",
"db": "dislocker",
"username": "user",
"password": "example_pass",
"port": "5432"
}
with open(db_config_path, "w") as w:
json.dump(db_config, w, indent=4)
elif os.path.isfile(db_config_path):
with open(db_config_path, "r") as r:
db_config = json.load(r)
if __name__ == '__main__':
app = App()
app.protocol("WM_DELETE_WINDOW", app.handler_close)
app.mainloop()