File size: 22,822 Bytes
3c7eec5
96c5973
 
 
 
 
 
3c7eec5
 
 
3af1cb3
414ae53
5242158
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
3c7eec5
 
 
 
96c5973
 
3c7eec5
96c5973
3c7eec5
 
96c5973
 
 
3c7eec5
 
 
 
96c5973
 
3c7eec5
96c5973
3c7eec5
 
5242158
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
 
3c7eec5
 
 
96c5973
3c7eec5
 
 
 
 
96c5973
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
3c7eec5
 
 
96c5973
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
3c7eec5
96c5973
3c7eec5
96c5973
3c7eec5
96c5973
3c7eec5
 
 
 
 
 
 
3af1cb3
3c7eec5
 
 
96c5973
 
3c7eec5
96c5973
3c7eec5
 
 
 
 
 
96c5973
3c7eec5
96c5973
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414ae53
 
 
 
 
 
 
 
 
 
 
 
 
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414ae53
 
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414ae53
3c7eec5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
from flask import Flask, render_template, request, jsonify, redirect, url_for
import requests
from bs4 import BeautifulSoup
import random
import string
import json
import threading
import os
import time
from datetime import datetime

app = Flask(__name__)

# Configuration globale
config = {
    'base_url': "https://ivoire-startup-tracker-edithbrou.replit.app",
    'accounts_file': "accounts_data.json",
    'is_running': False,
    'progress': {
        'total': 0,
        'current': 0,
        'success': 0,
        'failed': 0,
        'last_username': '',
        'last_status': '',
        'start_time': None,
        'end_time': None
    }
}

# Fonction pour générer un nom d'utilisateur aléatoire (min 80 caractères)
def generate_random_username(min_length=80, max_length=100):
    """Génère un nom d'utilisateur aléatoire d'au moins 80 caractères"""
    length = random.randint(min_length, max_length)
    return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))

# Fonction pour générer une adresse email aléatoire
def generate_random_email():
    """Génère une adresse email aléatoire"""
    username = ''.join(random.choice(string.ascii_lowercase) for _ in range(12))
    domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
    return f"{username}@{random.choice(domains)}"

# Fonction pour générer un mot de passe aléatoire
def generate_random_password(length=12):
    """Génère un mot de passe aléatoire"""
    chars = string.ascii_letters + string.digits + "!@#$%^&*"
    return ''.join(random.choice(chars) for _ in range(length))

# Fonction pour créer un compte
def create_account(is_startup_rep=False):
    """Crée un compte sur le site web"""
    register_url = f"{config['base_url']}/register"
    
    # Première requête pour récupérer le token CSRF
    session = requests.Session()
    try:
        response = session.get(register_url)
        
        if response.status_code != 200:
            return {'success': False, 'error': f"Erreur lors de l'accès à la page: {response.status_code}"}
        
        # Extraire le token CSRF
        soup = BeautifulSoup(response.text, 'html.parser')
        csrf_token = soup.find('input', {'id': 'csrf_token'}).get('value')
        
        if not csrf_token:
            return {'success': False, 'error': "Impossible de trouver le token CSRF"}
        
        # Générer des informations de compte aléatoires
        username = generate_random_username()
        email = generate_random_email()
        password = generate_random_password()
        
        # Préparer les données du formulaire
        form_data = {
            'csrf_token': csrf_token,
            'username': username,
            'email': email,
            'password': password,
            'confirm_password': password,
            'submit': 'Register'
        }
        
        # Ajouter l'option startup rep si nécessaire
        if is_startup_rep:
            form_data['is_startup_rep'] = 'y'
        
        # Envoyer le formulaire
        headers = {
            'Referer': register_url,
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
        }
        
        response = session.post(register_url, data=form_data, headers=headers)
        
        result = {
            'success': response.status_code == 200 or response.status_code == 302,
            'username': username,
            'email': email,
            'password': password,
            'is_startup_rep': is_startup_rep,
            'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            'status_code': response.status_code
        }
        
        return result
    
    except Exception as e:
        return {'success': False, 'error': str(e)}

# Fonction pour créer plusieurs comptes en arrière-plan
def create_accounts_background(num_accounts, startup_ratio=0.3):
    config['progress'] = {
        'total': num_accounts,
        'current': 0,
        'success': 0,
        'failed': 0,
        'last_username': '',
        'last_status': 'Démarrage...',
        'start_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        'end_time': None
    }
    
    # Charger les comptes existants
    accounts = []
    if os.path.exists(config['accounts_file']):
        try:
            with open(config['accounts_file'], 'r') as f:
                accounts = json.load(f)
        except:
            accounts = []
    
    for i in range(num_accounts):
        if not config['is_running']:
            break
            
        is_startup = random.random() < startup_ratio
        
        config['progress']['current'] = i + 1
        config['progress']['last_status'] = f"Création du compte {i+1}/{num_accounts}..."
        
        result = create_account(is_startup_rep=is_startup)
        
        if result.get('success', False):
            config['progress']['success'] += 1
            config['progress']['last_username'] = result['username']
            config['progress']['last_status'] = f"Compte {i+1} créé avec succès"
            accounts.append(result)
        else:
            config['progress']['failed'] += 1
            config['progress']['last_status'] = f"Échec de la création du compte {i+1}: {result.get('error', 'Erreur inconnue')}"
        
        # Enregistrer les données régulièrement
        with open(config['accounts_file'], 'w') as f:
            json.dump(accounts, f, indent=2)
            
        # Petite pause pour éviter de surcharger le serveur
        time.sleep(1)
    
    config['is_running'] = False
    config['progress']['end_time'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    config['progress']['last_status'] = "Terminé"
    
    # Enregistrement final
    with open(config['accounts_file'], 'w') as f:
        json.dump(accounts, f, indent=2)

# Routes Flask
@app.route('/')
def index():
    return render_template('index.html', config=config)

@app.route('/start', methods=['POST'])
def start():
    if config['is_running']:
        return jsonify({"status": "error", "message": "Une génération est déjà en cours"})
    
    num_accounts = int(request.form.get('num_accounts', 10))
    startup_ratio = float(request.form.get('startup_ratio', 0.3))
    
    config['is_running'] = True
    
    # Démarrer le processus en arrière-plan
    thread = threading.Thread(target=create_accounts_background, args=(num_accounts, startup_ratio))
    thread.daemon = True
    thread.start()
    
    return jsonify({"status": "success", "message": "Génération démarrée"})

@app.route('/stop', methods=['POST'])
def stop():
    config['is_running'] = False
    return jsonify({"status": "success", "message": "Arrêt demandé"})

@app.route('/progress')
def progress():
    return jsonify(config['progress'])

@app.route('/accounts')
def view_accounts():
    page = int(request.args.get('page', 1))
    per_page = 20
    
    accounts = []
    if os.path.exists(config['accounts_file']):
        try:
            with open(config['accounts_file'], 'r') as f:
                accounts = json.load(f)
        except:
            accounts = []
            
    total_accounts = len(accounts)
    total_pages = (total_accounts + per_page - 1) // per_page
    
    start_idx = (page - 1) * per_page
    end_idx = start_idx + per_page
    
    current_accounts = accounts[start_idx:end_idx]
    
    return render_template(
        'accounts.html',
        accounts=current_accounts,
        page=page,
        total_pages=total_pages,
        total_accounts=total_accounts
    )

if __name__ == '__main__':
    # Get the directory of the current script
    current_dir = os.path.dirname(os.path.abspath(__file__))

    # Create the templates directory if it doesn't exist
    templates_dir = os.path.join(current_dir, 'templates')
    if not os.path.exists(templates_dir):
        os.makedirs(templates_dir)

    # Create the HTML template files using absolute paths
    index_html_path = os.path.join(templates_dir, 'index.html')
    accounts_html_path = os.path.join(templates_dir, 'accounts.html')

    with open(index_html_path, 'w') as f:
        f.write('''
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Générateur de comptes automatique</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { background-color: #f5f5f5; }
        .card { box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
        .progress { height: 25px; }
        #status-display { height: 200px; overflow-y: auto; }
    </style>
</head>
<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12 mb-4">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h3 class="card-title mb-0">Générateur de comptes - Startup Côte d'Ivoire</h3>
                    </div>
                    <div class="card-body">
                        <form id="generator-form">
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label for="num_accounts" class="form-label">Nombre de comptes à créer</label>
                                    <input type="number" class="form-control" id="num_accounts" name="num_accounts" min="1" max="1000" value="10">
                                </div>
                                <div class="col-md-6">
                                    <label for="startup_ratio" class="form-label">Ratio de représentants de startup (%)</label>
                                    <input type="number" class="form-control" id="startup_ratio" name="startup_ratio" min="0" max="100" value="30">
                                </div>
                            </div>
                            <div class="d-grid gap-2 d-md-flex justify-content-md-center">
                                <button type="submit" id="start-btn" class="btn btn-success btn-lg">
                                    <i class="fas fa-play"></i> Démarrer
                                </button>
                                <button type="button" id="stop-btn" class="btn btn-danger btn-lg">
                                    <i class="fas fa-stop"></i> Arrêter
                                </button>
                                <a href="/accounts" class="btn btn-primary btn-lg">
                                    <i class="fas fa-list"></i> Voir les comptes
                                </a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header bg-info text-white">
                        <h4 class="card-title mb-0">Progression</h4>
                    </div>
                    <div class="card-body">
                        <div class="progress mb-3">
                            <div id="progress-bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%">0%</div>
                        </div>
                        
                        <div class="row text-center mb-3">
                            <div class="col">
                                <div class="card bg-light">
                                    <div class="card-body">
                                        <h5>Total</h5>
                                        <h3 id="total-count">0</h3>
                                    </div>
                                </div>
                            </div>
                            <div class="col">
                                <div class="card bg-success text-white">
                                    <div class="card-body">
                                        <h5>Réussis</h5>
                                        <h3 id="success-count">0</h3>
                                    </div>
                                </div>
                            </div>
                            <div class="col">
                                <div class="card bg-danger text-white">
                                    <div class="card-body">
                                        <h5>Échecs</h5>
                                        <h3 id="failed-count">0</h3>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="card mb-3">
                            <div class="card-header">
                                <h5>Dernier statut</h5>
                            </div>
                            <div class="card-body">
                                <p id="last-status">-</p>
                                <p>Dernier compte créé: <span id="last-username" class="text-primary fw-bold">-</span></p>
                            </div>
                        </div>
                        
                        <div class="row">
                            <div class="col-md-6">
                                <p>Heure de début: <span id="start-time">-</span></p>
                            </div>
                            <div class="col-md-6 text-end">
                                <p>Heure de fin: <span id="end-time">-</span></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Formulaire de génération
            document.getElementById('generator-form').addEventListener('submit', function(e) {
                e.preventDefault();
                
                const numAccounts = document.getElementById('num_accounts').value;
                const startupRatio = document.getElementById('startup_ratio').value / 100;
                
                fetch('/start', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: `num_accounts=${numAccounts}&startup_ratio=${startupRatio}`
                })
                .then(response => response.json())
                .then(data => {
                    if (data.status === 'success') {
                        startProgressUpdates();
                    } else {
                        alert(data.message);
                    }
                });
            });
            
            // Bouton d'arrêt
            document.getElementById('stop-btn').addEventListener('click', function() {
                fetch('/stop', {
                    method: 'POST'
                })
                .then(response => response.json())
                .then(data => {
                    alert(data.message);
                });
            });
            
            // Mettre à jour la progression
            function updateProgress() {
                fetch('/progress')
                .then(response => response.json())
                .then(data => {
                    const progressPercent = data.total > 0 ? Math.round((data.current / data.total) * 100) : 0;
                    
                    document.getElementById('progress-bar').style.width = `${progressPercent}%`;
                    document.getElementById('progress-bar').textContent = `${progressPercent}%`;
                    
                    document.getElementById('total-count').textContent = data.total;
                    document.getElementById('success-count').textContent = data.success;
                    document.getElementById('failed-count').textContent = data.failed;
                    
                    document.getElementById('last-status').textContent = data.last_status;
                    document.getElementById('last-username').textContent = data.last_username || '-';
                    
                    document.getElementById('start-time').textContent = data.start_time || '-';
                    document.getElementById('end-time').textContent = data.end_time || '-';
                });
            }
            
            let progressInterval;
            
            function startProgressUpdates() {
                // Arrêter l'intervalle précédent s'il existe
                if (progressInterval) {
                    clearInterval(progressInterval);
                }
                
                // Mettre à jour immédiatement
                updateProgress();
                
                // Puis toutes les 2 secondes
                progressInterval = setInterval(updateProgress, 2000);
            }
            
            // Vérifier si une génération est déjà en cours au chargement de la page
            updateProgress();
        });
    </script>
</body>
</html>
        ''')

    with open(accounts_html_path, 'w') as f:
        f.write('''
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Liste des comptes générés</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { background-color: #f5f5f5; }
        .card { box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
        .username-cell {
            max-width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .pagination { margin-bottom: 0; }
    </style>
</head>
<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12 mb-4">
                <div class="card">
                    <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
                        <h3 class="mb-0">Liste des comptes générés</h3>
                        <a href="/" class="btn btn-light">Retour au générateur</a>
                    </div>
                    <div class="card-body">
                        <div class="alert alert-info">
                            Total des comptes générés: {{ total_accounts }}
                        </div>
                        
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>Nom d'utilisateur</th>
                                        <th>Email</th>
                                        <th>Mot de passe</th>
                                        <th>Startup Rep</th>
                                        <th>Date de création</th>
                                        <th>Statut</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for account in accounts %}
                                    <tr>
                                        <td>{{ (page - 1) * 20 + loop.index }}</td>
                                        <td class="username-cell" title="{{ account.username }}">{{ account.username }}</td>
                                        <td>{{ account.email }}</td>
                                        <td>{{ account.password }}</td>
                                        <td>{% if account.is_startup_rep %}Oui{% else %}Non{% endif %}</td>
                                        <td>{{ account.created_at }}</td>
                                        <td>
                                            {% if account.success %}
                                            <span class="badge bg-success">Succès</span>
                                            {% else %}
                                            <span class="badge bg-danger">Échec</span>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                        
                        {% if total_pages > 1 %}
                        <div class="d-flex justify-content-center mt-4">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    <li class="page-item {% if page == 1 %}disabled{% endif %}">
                                        <a class="page-link" href="{{ url_for('view_accounts', page=page-1) if page > 1 else '#' }}">Précédent</a>
                                    </li>
                                    
                                    {% for p in range(1, total_pages + 1) %}
                                        {% if p == page %}
                                        <li class="page-item active"><span class="page-link">{{ p }}</span></li>
                                        {% else %}
                                        <li class="page-item"><a class="page-link" href="{{ url_for('view_accounts', page=p) }}">{{ p }}</a></li>
                                        {% endif %}
                                    {% endfor %}
                                    
                                    <li class="page-item {% if page == total_pages %}disabled{% endif %}">
                                        <a class="page-link" href="{{ url_for('view_accounts', page=page+1) if page < total_pages else '#' }}">Suivant</a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
        ''')

    app.run(debug=True)