Docfile commited on
Commit
687de48
·
verified ·
1 Parent(s): c95a228

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +234 -0
app.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify, redirect, url_for
2
+ import asyncio
3
+ import aiohttp
4
+ import os
5
+ import json
6
+ import random
7
+ import string
8
+ from datetime import datetime
9
+ from concurrent.futures import ThreadPoolExecutor
10
+ from threading import Lock
11
+
12
+ app = Flask(__name__)
13
+
14
+ # Variables globales pour stocker l'état
15
+ creation_in_progress = False
16
+ accounts_being_created = []
17
+ progress_counter = 0
18
+ total_accounts = 0
19
+ accounts_lock = Lock()
20
+ event_loop = None
21
+ background_task = None
22
+
23
+ def create_random_username(length=8):
24
+ chars = string.ascii_lowercase + string.digits
25
+ return ''.join(random.choice(chars) for _ in range(length))
26
+
27
+ def create_random_password(length=10):
28
+ chars = string.ascii_letters + string.digits
29
+ return ''.join(random.choice(chars) for _ in range(length))
30
+
31
+ async def check_username_availability(session, username):
32
+ check_url = "https://gabaohub.alwaysdata.net/assets/functions.php"
33
+ data = {"ajaxCall": "isUsernameTaken", "u": username}
34
+ headers = {
35
+ "X-Forwarded-For": "41.158.0.1",
36
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
37
+ "Referer": "https://gabaohub.alwaysdata.net/register/"
38
+ }
39
+ async with session.post(check_url, data=data, headers=headers) as response:
40
+ result = await response.text()
41
+ return result == "0"
42
+
43
+ async def get_register_page(session):
44
+ url = "https://gabaohub.alwaysdata.net/register/"
45
+ headers = {
46
+ "X-Forwarded-For": "41.158.0.1",
47
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
48
+ }
49
+ async with session.get(url, headers=headers) as response:
50
+ return await response.text()
51
+
52
+ async def register_account(session, account_info):
53
+ register_url = "https://gabaohub.alwaysdata.net/register/register.php"
54
+ headers = {
55
+ "X-Forwarded-For": "41.158.0.1",
56
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
57
+ "Referer": "https://gabaohub.alwaysdata.net/register/",
58
+ "Content-Type": "application/x-www-form-urlencoded"
59
+ }
60
+ await get_register_page(session)
61
+ async with session.post(register_url, data=account_info, headers=headers, allow_redirects=True) as response:
62
+ text = await response.text()
63
+ successful_urls = ["index.php", "dashboard.php", "home", "/"]
64
+ success = any(url in str(response.url) for url in successful_urls) or "success" in text.lower()
65
+ return response, success
66
+
67
+ async def create_single_account(session, account_index, semaphore):
68
+ global progress_counter, accounts_being_created
69
+
70
+ async with semaphore:
71
+ provinces_villes = {"1": ["1", "2", "3"], "2": ["7", "8"]}
72
+ try:
73
+ username = create_random_username(random.randint(6, 10))
74
+ retries = 0
75
+ available = False
76
+ # Retente la vérification sans délai excessif
77
+ while not available and retries < 3:
78
+ try:
79
+ available = await check_username_availability(session, username)
80
+ if not available:
81
+ username = create_random_username(random.randint(6, 10))
82
+ retries += 1
83
+ except Exception as e:
84
+ print(f"Erreur lors de la vérification du nom d'utilisateur: {str(e)}")
85
+ retries += 1
86
+
87
+ if not available:
88
+ with accounts_lock:
89
+ accounts_being_created[account_index].update({
90
+ "status": "failed",
91
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
92
+ "error": "Nom d'utilisateur indisponible"
93
+ })
94
+ progress_counter += 1
95
+ return
96
+
97
+ password = create_random_password()
98
+ province = random.choice(list(provinces_villes.keys()))
99
+ ville = random.choice(provinces_villes[province])
100
+ account_info = {
101
+ "visitorCountry": "Gabon",
102
+ "username": username,
103
+ "password": password,
104
+ "password2": password,
105
+ "province": province,
106
+ "ville": ville
107
+ }
108
+ with accounts_lock:
109
+ accounts_being_created[account_index].update(account_info)
110
+
111
+ try:
112
+ response, success = await register_account(session, account_info)
113
+ with accounts_lock:
114
+ accounts_being_created[account_index].update({
115
+ "status": "success" if success else "failed",
116
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
117
+ })
118
+ if not success:
119
+ accounts_being_created[account_index]["error"] = "Échec de l'enregistrement"
120
+ progress_counter += 1
121
+ except Exception as e:
122
+ with accounts_lock:
123
+ accounts_being_created[account_index].update({
124
+ "status": "failed",
125
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
126
+ "error": str(e)
127
+ })
128
+ progress_counter += 1
129
+
130
+ except Exception as e:
131
+ with accounts_lock:
132
+ accounts_being_created[account_index].update({
133
+ "status": "failed",
134
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
135
+ "error": str(e)
136
+ })
137
+ progress_counter += 1
138
+
139
+ async def create_accounts_async(num_accounts, concurrency=50):
140
+ global creation_in_progress, accounts_being_created, progress_counter, total_accounts
141
+ progress_counter = 0
142
+ with accounts_lock:
143
+ accounts_being_created = [{"status": "pending"} for _ in range(num_accounts)]
144
+
145
+ # Augmenter la limite du connecteur selon la concurrence souhaitée
146
+ conn = aiohttp.TCPConnector(limit=concurrency, ssl=False)
147
+ timeout = aiohttp.ClientTimeout(total=30)
148
+
149
+ semaphore = asyncio.Semaphore(concurrency)
150
+ try:
151
+ async with aiohttp.ClientSession(connector=conn, timeout=timeout) as session:
152
+ tasks = [
153
+ create_single_account(session, i, semaphore)
154
+ for i in range(num_accounts)
155
+ ]
156
+ await asyncio.gather(*tasks, return_exceptions=True)
157
+ except Exception as e:
158
+ print(f"Erreur principale pendant la création des comptes: {str(e)}")
159
+ finally:
160
+ with open("comptes_gabaohub.json", "w", encoding="utf-8") as f:
161
+ json.dump(accounts_being_created, f, indent=4, ensure_ascii=False)
162
+ creation_in_progress = False
163
+
164
+ def start_background_task(num_accounts, concurrency=50):
165
+ global event_loop, background_task, creation_in_progress, total_accounts
166
+ creation_in_progress = True
167
+ total_accounts = num_accounts
168
+
169
+ def run_async_loop():
170
+ loop = asyncio.new_event_loop()
171
+ asyncio.set_event_loop(loop)
172
+ global event_loop
173
+ event_loop = loop
174
+ try:
175
+ loop.run_until_complete(create_accounts_async(num_accounts, concurrency))
176
+ finally:
177
+ loop.close()
178
+
179
+ executor = ThreadPoolExecutor(max_workers=1)
180
+ background_task = executor.submit(run_async_loop)
181
+
182
+ @app.route('/')
183
+ def index():
184
+ accounts_data = []
185
+ if os.path.exists("comptes_gabaohub.json"):
186
+ try:
187
+ with open("comptes_gabaohub.json", "r", encoding="utf-8") as f:
188
+ accounts_data = json.load(f)
189
+ except json.JSONDecodeError:
190
+ accounts_data = []
191
+ return render_template('index.html',
192
+ creation_in_progress=creation_in_progress,
193
+ accounts=accounts_data,
194
+ progress=progress_counter,
195
+ total=total_accounts)
196
+
197
+ @app.route('/start', methods=['POST'])
198
+ def start_creation():
199
+ global creation_in_progress
200
+ if not creation_in_progress:
201
+ # Récupère les paramètres ou forcez des valeurs pour tester de grosses requêtes
202
+ num_accounts = int(request.form.get('num_accounts', 5))
203
+ concurrency = int(request.form.get('concurrency', 5))
204
+ num_accounts = 1000000 # Pour tester une charge très importante
205
+ concurrency = 50
206
+ start_background_task(num_accounts, concurrency)
207
+ return redirect(url_for('index'))
208
+
209
+ @app.route('/progress')
210
+ def get_progress():
211
+ return jsonify({
212
+ 'creation_in_progress': creation_in_progress,
213
+ 'progress': progress_counter,
214
+ 'total': total_accounts,
215
+ 'accounts': accounts_being_created
216
+ })
217
+
218
+ @app.route('/reset', methods=['POST'])
219
+ def reset():
220
+ global creation_in_progress, accounts_being_created, progress_counter, total_accounts
221
+ if not creation_in_progress:
222
+ with accounts_lock:
223
+ accounts_being_created = []
224
+ progress_counter = 0
225
+ total_accounts = 0
226
+ if os.path.exists("comptes_gabaohub.json"):
227
+ os.remove("comptes_gabaohub.json")
228
+ return redirect(url_for('index'))
229
+
230
+ if __name__ == '__main__':
231
+ if not os.path.exists("comptes_gabaohub.json"):
232
+ with open("comptes_gabaohub.json", "w", encoding="utf-8") as f:
233
+ json.dump([], f)
234
+ app.run(debug=True, threaded=True)