diff --git a/main.py b/main.py index b177d0f..3e0e4f2 100755 --- a/main.py +++ b/main.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 -# Key Master v1.04 -# 04/12/2023 -# https://t.me/ssleg © 2020 – 2023 +# Key Master v1.05 +# 03/03/2024 +# https://t.me/ssleg © 2020 – 2024 +import logging import sqlite3 +from datetime import datetime from hashlib import md5, sha256 from os import path, getppid, kill from random import randint @@ -13,6 +15,14 @@ from signal import SIGKILL import PySimpleGUI as Sg import cryptocode +log_file = logging.FileHandler('key_master.log', 'w', 'utf-8') +log_file.setFormatter(logging.Formatter('%(levelname)s %(module)-13s [%(asctime)s] %(message)s')) +logging.basicConfig(level=logging.INFO, handlers=[log_file]) + +cc1 = 0 +cc2 = 0 +cc3 = 0 + class LoginCard: """Класс хранения карточки логина/пароля""" @@ -20,6 +30,8 @@ class LoginCard: __slots__ = ['__row_id', '__encrypt_key', '__hash', '__name', '__login', '__password'] def __init__(self, encrypt_key, row_id=None, name=None, login=None, password=None): + global cc1, cc2, cc3 + self.__row_id = row_id self.__encrypt_key = encrypt_key @@ -31,15 +43,27 @@ class LoginCard: self.__hash = md5(control_string.encode()).hexdigest() self.__write_card_to_db(mode=0) else: + start = datetime.now() cursor.execute('select * from logins where row_id=?', (row_id,)) row = cursor.fetchone() db_name = row[1] db_login = row[2] db_password = row[3] self.__hash = row[4] + end = datetime.now() + delta = end - start + if row_id != 1: + cc1 += delta.microseconds + cc3 += 1 + + start = datetime.now() self.__name = cryptocode.decrypt(db_name, encrypt_key) self.__login = cryptocode.decrypt(db_login, encrypt_key) self.__password = cryptocode.decrypt(db_password, encrypt_key) + end = datetime.now() + delta = end - start + if row_id != 1: + cc2 += delta.microseconds def is_valid(self): control_string = self.__name + self.__login + self.__password @@ -391,6 +415,8 @@ def add_or_edit_card(used_list, popular_list, mode, name='', login='', password= # главное окно def main(): + global cc1, cc2, cc3 + keys_disabled = True my_cards = AllCards(master_key) valid, error_numbers = my_cards.validate() @@ -411,6 +437,10 @@ def main(): [Sg.Button('Удалить', disabled=True, key='delete'), Sg.Text(' '), Sg.Button('Скопировать логин', disabled=True, key='copy_login')]] window = Sg.Window("KeyMaster - главная", layout) + + logging.info( + f'\nзагружено {cc3} карточек.\nвремя чтения {cc1} мкс.\nвремя расшифровки {round(cc2 / 1000000, 2)} секунд.\n' + 'программа запущена.') while True: event, values = window.read() if event == Sg.WIN_CLOSED: @@ -485,6 +515,7 @@ def main(): window.Element('list').Update(my_cards.get_names_list()) window.close() + logging.info('программа завершена.') # начало исполнения кода. @@ -513,7 +544,9 @@ if __name__ == '__main__': else: con = sqlite3.connect('base.sqlite') cursor = con.cursor() + logging.info('соединение с бд установлено, ожидаем пароль...') login_status, master_key = system_login() if login_status: + logging.info('логин - ок. запуск...') main()