Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 19 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")],
Expand All @@ -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":
Expand Down