From 7b4b8d2ae7416441fc20f0ecfee3ef7c9b055c45 Mon Sep 17 00:00:00 2001 From: lavrov08 <5452894@gmail.com> Date: Tue, 16 Sep 2025 19:23:20 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D0=B0=D0=B9=D0=BB=20LICENSE=20=D1=81=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D1=82=D0=BE=D0=BC=20MIT=20=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D0=B5=D0=BD=D0=B7=D0=B8=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dba807f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 andywork + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 13b93dd425be6ed2f0f3a6af60eae7fbfa1530a9 Mon Sep 17 00:00:00 2001 From: lavrov08 <5452894@gmail.com> Date: Sun, 2 Nov 2025 19:23:25 +0300 Subject: [PATCH 2/3] Add .gitignore file to exclude common Python, environment, and IDE artifacts --- .gitignore | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bf45e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Virtual Environment +venv/ +env/ +ENV/ + +# Environment variables +.env + +# Database +*.db +data/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store + +# Logs +*.log + From 6e7a966eef2402da3d8d1dc01f528109a840cc6e Mon Sep 17 00:00:00 2001 From: lavrov08 <5452894@gmail.com> Date: Sun, 2 Nov 2025 19:23:44 +0300 Subject: [PATCH 3/3] Implement user access control in DockerBot: update allowed_users initialization and add access check methods for /start and callback queries. --- bot.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index 248d28f..19396ec 100644 --- a/bot.py +++ b/bot.py @@ -11,7 +11,8 @@ class DockerBot: def __init__(self): self.bot_token = os.getenv('BOT_TOKEN') # Опционально: ограничить доступ определенным пользователям - # self.allowed_users = [int(user_id) for user_id in os.getenv('ALLOWED_USERS', '').split(',') if user_id] + allowed_users_str = os.getenv('ALLOWED_USERS', '') + self.allowed_users = [int(user_id) for user_id in allowed_users_str.split(',') if user_id.strip()] if allowed_users_str else [] # Настройка Docker клиента для работы с socket try: # Проверяем доступность socket @@ -125,13 +126,19 @@ async def get_container_logs(self, container_name, lines=20): print(f"Ошибка при получении логов: {e}") return f"Ошибка при получении логов: {e}" + def _check_access(self, user_id): + """Проверить доступ пользователя""" + if self.allowed_users and user_id not in self.allowed_users: + return False + return True + async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE): """Команда /start""" - # Опционально: проверка доступа - # user_id = update.effective_user.id - # if hasattr(self, 'allowed_users') and self.allowed_users and user_id not in self.allowed_users: - # await update.message.reply_text("❌ У вас нет доступа к этому боту.") - # return + # Проверка доступа + user_id = update.effective_user.id + if not self._check_access(user_id): + await update.message.reply_text("❌ У вас нет доступа к этому боту.") + return keyboard = [ [InlineKeyboardButton("📋 Список контейнеров", callback_data="list")], @@ -149,6 +156,12 @@ async def button_handler(self, update: Update, context: ContextTypes.DEFAULT_TYP query = update.callback_query await query.answer() + # Проверка доступа + user_id = query.from_user.id + if not self._check_access(user_id): + await query.edit_message_text("❌ У вас нет доступа к этому боту.") + return + if query.data == "list": await self.show_containers(query) elif query.data == "stats":