149 lines
5.5 KiB
Python
149 lines
5.5 KiB
Python
import psycopg2
|
|
import os
|
|
import json
|
|
import customtkinter
|
|
from winotify import Notification, audio
|
|
import keyboard
|
|
import wmi
|
|
import subprocess
|
|
import asyncio
|
|
|
|
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)
|
|
|
|
asyncio.run(self.task_watcher_run())
|
|
self.block_key()
|
|
lock = Lock()
|
|
|
|
def exit(self):
|
|
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 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()
|
|
|
|
async def task_watcher_run(self):
|
|
taskmgr_killer = asyncio.create_task(self.task_watcher())
|
|
|
|
async def task_watcher(self):
|
|
c=wmi.WMI()
|
|
cre_process_watcher=c.Win32_Process.watch_for("creation")
|
|
del_process_watcher=c.Win32_Process.watch_for("deletion")
|
|
|
|
self.i = 1
|
|
|
|
while self.i == 1:
|
|
new_cre_process=cre_process_watcher()
|
|
new_del_process=del_process_watcher()
|
|
print(new_cre_process.Caption+" has been created")
|
|
if new_cre_process.Caption == "Taskmgr.exe":
|
|
taskmgr_kill = subprocess.run(['taskkill', '/im', 'Taskmgr.exe'])
|
|
print(new_del_process.Caption+" has been deleted ")
|
|
|
|
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()
|