File size: 8,715 Bytes
3c7eec5
96c5973
 
 
 
3c7eec5
 
 
3af1cb3
aa1978a
 
 
 
 
 
 
 
414ae53
5242158
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
aa1978a
 
 
3c7eec5
96c5973
 
3c7eec5
96c5973
aa1978a
 
96c5973
aa1978a
96c5973
3c7eec5
aa1978a
 
 
 
96c5973
aa1978a
3c7eec5
96c5973
aa1978a
3c7eec5
aa1978a
 
 
 
 
 
 
 
 
 
3c7eec5
aa1978a
 
 
 
 
 
 
 
3c7eec5
 
 
aa1978a
 
 
 
 
 
 
3c7eec5
aa1978a
 
 
 
 
 
 
 
 
 
 
3c7eec5
aa1978a
 
 
 
 
 
 
 
3c7eec5
aa1978a
96c5973
 
 
3c7eec5
 
96c5973
aa1978a
3c7eec5
aa1978a
3c7eec5
aa1978a
3c7eec5
aa1978a
 
96c5973
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
 
3c7eec5
 
 
96c5973
3c7eec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5973
aa1978a
96c5973
3c7eec5
96c5973
3c7eec5
96c5973
3c7eec5
96c5973
3c7eec5
 
aa1978a
3c7eec5
 
aa1978a
3c7eec5
aa1978a
3c7eec5
 
 
96c5973
aa1978a
3c7eec5
96c5973
3c7eec5
 
 
 
 
 
96c5973
3c7eec5
96c5973
3c7eec5
 
 
 
aa1978a
3c7eec5
 
 
 
 
 
 
aa1978a
3c7eec5
 
aa1978a
3c7eec5
 
aa1978a
3c7eec5
aa1978a
3c7eec5
 
 
 
 
 
 
 
414ae53
e5b0946
 
 
414ae53
e5b0946
aa1978a
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
from flask import Flask, render_template, request, jsonify, redirect, url_for
import random
import string
import json
import threading
import os
import time
from datetime import datetime

# --- Selenium Imports ---
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

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 3 caractères)
def generate_random_username(min_length=3, max_length=10):  # Adjusted min_length
    """Génère un nom d'utilisateur aléatoire d'au moins 3 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 au format plus standard"""
    username = ''.join(random.choice(string.ascii_lowercase) for _ in range(7))
    domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
    return f"{username}+{int(time.time())}@{random.choice(domains)}" # Added timestamp

# Fonction pour générer un mot de passe aléatoire
def generate_random_password(min_length=6, max_length=12):  # Adjusted min_length
    """Génère un mot de passe aléatoire"""
    chars = string.ascii_letters + string.digits + "!@#$%^&*"
    length = random.randint(min_length, max_length)
    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 en utilisant Selenium"""
    register_url = f"{config['base_url']}/register"

    # Use webdriver_manager to handle ChromeDriver
    service = ChromeService(executable_path=ChromeDriverManager().install())
    options = webdriver.ChromeOptions()
    options.add_argument('--headless') # Run in headless mode (no GUI)
    options.add_argument('--no-sandbox') # Needed for Replit/containers
    options.add_argument('--disable-dev-shm-usage') # Also for Replit

    driver = webdriver.Chrome(service=service, options=options)

    try:
        driver.get(register_url)

        # Wait for the form to be present (important for dynamic pages)
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, "username"))
        )

        # Generate random account data
        username = generate_random_username()
        email = generate_random_email()
        password = generate_random_password()

        # Fill out the form fields
        driver.find_element(By.ID, "username").send_keys(username)
        driver.find_element(By.ID, "email").send_keys(email)
        driver.find_element(By.ID, "password").send_keys(password)
        driver.find_element(By.ID, "confirm_password").send_keys(password)

        if is_startup_rep:
            driver.find_element(By.ID, "is_startup_rep").click()

        # Submit the form
        driver.find_element(By.ID, "submit").click()

        # Wait for a result (either success or failure) - Adjust the wait time as needed
        # We'll check for redirection as an indicator of success.  A more robust check
        # might involve looking for specific success/error messages on the resulting page.
        WebDriverWait(driver, 10).until(
            EC.url_changes(register_url)
        )
        
        # Check if redirection occurred to a URL other than the registration URL
        current_url = driver.current_url
        if current_url != register_url:
            success = True
        else:
             success = False # Explicitly set to False


        result = {
            'success': success,
            'username': username,
            'email': email,
            'password': password,
            'is_startup_rep': is_startup_rep,
            'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        }

        return result

    except Exception as e:
        print(f"Selenium Error: {e}")  # Log the Selenium error
        return {'success': False, 'error': str(e)}
    finally:
        driver.quit()  # Always close the browser

# 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
    )


@app.route('/script.js')
def serve_js():
    return render_template('script.js'), 200, {'Content-Type': 'application/javascript'}

if __name__ == '__main__':
    app.run(debug=True) # Keep debug=True for development