Compare commits

..

No commits in common. "570f15001e874a4d3454279531843d5a6384130d" and "b10b1fe2b3af1c3ac88dc4e3063a80dda66b5769" have entirely different histories.

5 changed files with 18 additions and 21 deletions

View File

@ -13,6 +13,9 @@ RUN adduser -u 1000 --disabled-password --gecos "" appuser && chown -R appuser /
# Install deps
RUN apt update && apt full-upgrade -y
RUN apt install curl gcc g++ -y
RUN curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash
RUN apt install libmariadb3 libmariadb-dev -y
# Install pip requirements
COPY requirements.txt .

View File

@ -1,6 +1,6 @@
bcrypt
cryptography
pymysql
mariadb
python-dotenv
pyTelegramBotAPI
sqlmodel

View File

@ -1,6 +1,6 @@
import functools
from sqlalchemy.future import Engine
import mariadb
import telebot
from . import handlers, utils
@ -8,7 +8,7 @@ from . import handlers, utils
__all__ = ["handlers", "utils"]
def create_bot(token: str, engine: Engine) -> telebot.TeleBot:
def create_bot(token: str, engine: mariadb.Connection) -> telebot.TeleBot:
bot = telebot.TeleBot(token)
bot.register_message_handler(
functools.partial(handlers.set_master_password, bot, engine),

View File

@ -83,8 +83,8 @@ def _set_master_pass2(
if text == "/cancel":
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
hash_pass, master_salt = cryptography.master_pass.encrypt_master_pass(text)
database.add.add_master_pass(engine, mes.from_user.id, master_salt, hash_pass)
hash_, salt = cryptography.master_pass.encrypt_master_pass(text)
database.add.add_master_pass(engine, mes.from_user.id, salt, hash_)
send_tmp_message(bot, mes.chat.id, "Успех")
del mes, text
gc.collect()
@ -242,11 +242,6 @@ def _add_account5(
def get_account(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
base_handler(bot, mes)
bot_mes = bot.send_message(mes.chat.id, "Отправьте название аккаунта")
master_pass = database.get.get_master_pass(engine, mes.from_user.id)
if master_pass is None:
return send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
bot.register_next_step_handler(
mes, functools.partial(_get_account2, bot, engine, bot_mes)
)
@ -277,7 +272,11 @@ def _get_account3(
if text == "/cancel":
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
master_salt, hash_pass = database.get.get_master_pass(engine, mes.from_user.id)
master_pass = database.get.get_master_pass(engine, mes.from_user.id)
if master_pass is None:
return send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
master_salt, hash_pass = master_pass
if cryptography.master_pass.encrypt_master_pass(text, master_salt) != hash_pass:
return send_tmp_message(bot, mes.chat.id, "Не подходит мастер пароль")
@ -301,11 +300,6 @@ def _get_account3(
def delete_account(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
base_handler(bot, mes)
master_pass = database.get.get_master_pass(engine, mes.from_user.id)
if master_pass is None:
return send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
bot_mes = bot.send_message(
mes.chat.id, "Отправьте название аккаунта, который вы хотите удалить"
)
@ -413,16 +407,14 @@ def _import2(
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
if mes.document is None:
return send_tmp_message(bot, mes.chat.id, "Вы должны отправить документ")
if mes.document.file_size > 102_400: # If file size is bigger that 100 MB
return send_tmp_message(bot, mes.chat.id, "Файл слишком большой")
send_tmp_message(bot, mes.chat.id, "Вы должны отправить документ")
file_info = bot.get_file(mes.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
try:
accounts = json_to_accounts(downloaded_file.decode("utf-8"))
except Exception:
return send_tmp_message(bot, mes.chat.id, "Ошибка во время работы с файлом")
send_tmp_message(bot, mes.chat.id, "Ошибка во время работы с файлом")
bot_mes = bot.send_message(mes.chat.id, "Отправьте мастер пароль")
bot.register_next_step_handler(

View File

@ -5,7 +5,9 @@ from . import models
def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
engine = sqlmodel.create_engine(f"mariadb+pymysql://{user}:{passwd}@{host}/{db}")
engine = sqlmodel.create_engine(
f"mariadb+mariadbconnector://{user}:{passwd}@{host}/{db}"
)
return engine