Compare commits
No commits in common. "570f15001e874a4d3454279531843d5a6384130d" and "b10b1fe2b3af1c3ac88dc4e3063a80dda66b5769" have entirely different histories.
570f15001e
...
b10b1fe2b3
@ -13,6 +13,9 @@ RUN adduser -u 1000 --disabled-password --gecos "" appuser && chown -R appuser /
|
|||||||
|
|
||||||
# Install deps
|
# Install deps
|
||||||
RUN apt update && apt full-upgrade -y
|
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
|
# Install pip requirements
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
bcrypt
|
bcrypt
|
||||||
cryptography
|
cryptography
|
||||||
pymysql
|
mariadb
|
||||||
python-dotenv
|
python-dotenv
|
||||||
pyTelegramBotAPI
|
pyTelegramBotAPI
|
||||||
sqlmodel
|
sqlmodel
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import functools
|
import functools
|
||||||
|
|
||||||
from sqlalchemy.future import Engine
|
import mariadb
|
||||||
import telebot
|
import telebot
|
||||||
|
|
||||||
from . import handlers, utils
|
from . import handlers, utils
|
||||||
@ -8,7 +8,7 @@ from . import handlers, utils
|
|||||||
__all__ = ["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 = telebot.TeleBot(token)
|
||||||
bot.register_message_handler(
|
bot.register_message_handler(
|
||||||
functools.partial(handlers.set_master_password, bot, engine),
|
functools.partial(handlers.set_master_password, bot, engine),
|
||||||
|
@ -83,8 +83,8 @@ def _set_master_pass2(
|
|||||||
if text == "/cancel":
|
if text == "/cancel":
|
||||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
||||||
|
|
||||||
hash_pass, master_salt = cryptography.master_pass.encrypt_master_pass(text)
|
hash_, salt = cryptography.master_pass.encrypt_master_pass(text)
|
||||||
database.add.add_master_pass(engine, mes.from_user.id, master_salt, hash_pass)
|
database.add.add_master_pass(engine, mes.from_user.id, salt, hash_)
|
||||||
send_tmp_message(bot, mes.chat.id, "Успех")
|
send_tmp_message(bot, mes.chat.id, "Успех")
|
||||||
del mes, text
|
del mes, text
|
||||||
gc.collect()
|
gc.collect()
|
||||||
@ -242,11 +242,6 @@ def _add_account5(
|
|||||||
def get_account(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
|
def get_account(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
|
||||||
base_handler(bot, mes)
|
base_handler(bot, mes)
|
||||||
bot_mes = bot.send_message(mes.chat.id, "Отправьте название аккаунта")
|
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(
|
bot.register_next_step_handler(
|
||||||
mes, functools.partial(_get_account2, bot, engine, bot_mes)
|
mes, functools.partial(_get_account2, bot, engine, bot_mes)
|
||||||
)
|
)
|
||||||
@ -277,7 +272,11 @@ def _get_account3(
|
|||||||
if text == "/cancel":
|
if text == "/cancel":
|
||||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
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:
|
if cryptography.master_pass.encrypt_master_pass(text, master_salt) != hash_pass:
|
||||||
return send_tmp_message(bot, mes.chat.id, "Не подходит мастер пароль")
|
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:
|
def delete_account(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
|
||||||
base_handler(bot, mes)
|
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(
|
bot_mes = bot.send_message(
|
||||||
mes.chat.id, "Отправьте название аккаунта, который вы хотите удалить"
|
mes.chat.id, "Отправьте название аккаунта, который вы хотите удалить"
|
||||||
)
|
)
|
||||||
@ -413,16 +407,14 @@ def _import2(
|
|||||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
||||||
|
|
||||||
if mes.document is None:
|
if mes.document is None:
|
||||||
return send_tmp_message(bot, mes.chat.id, "Вы должны отправить документ")
|
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, "Файл слишком большой")
|
|
||||||
|
|
||||||
file_info = bot.get_file(mes.document.file_id)
|
file_info = bot.get_file(mes.document.file_id)
|
||||||
downloaded_file = bot.download_file(file_info.file_path)
|
downloaded_file = bot.download_file(file_info.file_path)
|
||||||
try:
|
try:
|
||||||
accounts = json_to_accounts(downloaded_file.decode("utf-8"))
|
accounts = json_to_accounts(downloaded_file.decode("utf-8"))
|
||||||
except Exception:
|
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_mes = bot.send_message(mes.chat.id, "Отправьте мастер пароль")
|
||||||
bot.register_next_step_handler(
|
bot.register_next_step_handler(
|
||||||
|
@ -5,7 +5,9 @@ from . import models
|
|||||||
|
|
||||||
|
|
||||||
def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
|
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
|
return engine
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user