FreshPixels commited on
Commit
a0621c3
·
verified ·
1 Parent(s): b154238

Delete server/notification_system.py

Browse files
Files changed (1) hide show
  1. server/notification_system.py +0 -85
server/notification_system.py DELETED
@@ -1,85 +0,0 @@
1
- """Система уведомлений"""
2
-
3
- import re
4
- from datetime import datetime
5
- from typing import Dict, Any
6
-
7
- class NotificationSystem:
8
- CRITICAL_ACTIONS = [
9
- 'delete', 'remove', 'kill', 'stop', 'shutdown',
10
- 'format', 'clear', 'reset', 'purge',
11
- 'upload', 'publish', 'deploy', 'push',
12
- 'change_password', 'add_user', 'remove_user',
13
- 'grant_access', 'revoke_access',
14
- 'install', 'uninstall', 'update',
15
- 'execute', 'run', 'start', 'stop',
16
- 'create_file', 'delete_file', 'modify_file',
17
- ]
18
-
19
- HIGH_RISK_PATTERNS = [
20
- r'rm\s+-rf', r'del\s+/f', r'format\s+', r'mkfs',
21
- r'drop\s+database', r'truncate\s+', r'delete\s+from',
22
- r'ALTER\s+TABLE', r'DROP\s+TABLE',
23
- r'chmod\s+777', r'chown\s+root',
24
- r'sudo\s+', r'admin\s+',
25
- ]
26
-
27
- def __init__(self, chat_id: str = None):
28
- self.chat_id = chat_id
29
- self.notification_history = []
30
- self.enabled = True
31
-
32
- def set_chat_id(self, chat_id: str):
33
- self.chat_id = chat_id
34
-
35
- def set_enabled(self, enabled: bool):
36
- self.enabled = enabled
37
-
38
- def check_action(self, action: str, context: Dict[str, Any] = None) -> bool:
39
- action_lower = action.lower()
40
- context = context or {}
41
- for critical in self.CRITICAL_ACTIONS:
42
- if critical in action_lower:
43
- return True
44
- for pattern in self.HIGH_RISK_PATTERNS:
45
- if re.search(pattern, action_lower, re.IGNORECASE):
46
- return True
47
- if context.get('important', False):
48
- return True
49
- if context.get('files_changed', 0) > 3:
50
- return True
51
- return False
52
-
53
- def notify(self, action: str, details: str = "", severity: str = "info") -> str:
54
- if not self.enabled:
55
- return "🔇 Уведомления отключены"
56
- if not self.chat_id:
57
- return "⚠️ Chat ID не установлен"
58
-
59
- emoji_map = {'critical': '🚨', 'warning': '⚠️', 'info': 'ℹ️', 'success': '✅', 'error': '❌'}
60
- emoji = emoji_map.get(severity, 'ℹ️')
61
-
62
- message = f"{emoji} *УВЕДОМЛЕНИЕ*\n\n🔹 *Действие:* `{action}`\n"
63
- if details:
64
- message += f"📝 *Детали:*\n```\n{details[:500]}\n```\n"
65
- message += f"🕐 *Время:* {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
66
-
67
- self.notification_history.append({
68
- 'action': action, 'details': details,
69
- 'severity': severity, 'timestamp': datetime.now().isoformat()
70
- })
71
-
72
- from .telegram_utils import send_tg
73
- send_tg(self.chat_id, message)
74
- return f"✅ Уведомление отправлено: {action}"
75
-
76
- def get_history(self, limit: int = 10) -> str:
77
- if not self.notification_history:
78
- return "📋 Нет уведомлений"
79
- result = "📋 *История уведомлений:*\n\n"
80
- for entry in self.notification_history[-limit:]:
81
- emoji = {'critical': '🚨', 'warning': '⚠️', 'info': 'ℹ️'}.get(entry['severity'], 'ℹ️')
82
- result += f"{emoji} `{entry['action']}` — {entry['timestamp']}\n"
83
- return result
84
-
85
- NOTIFICATIONS = NotificationSystem()