Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
| 2 |
-
import requests
|
| 3 |
-
from bs4 import BeautifulSoup
|
| 4 |
import random
|
| 5 |
import string
|
| 6 |
import json
|
|
@@ -9,6 +7,14 @@ import os
|
|
| 9 |
import time
|
| 10 |
from datetime import datetime
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
app = Flask(__name__)
|
| 13 |
|
| 14 |
# Configuration globale
|
|
@@ -28,85 +34,96 @@ config = {
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
-
# Fonction pour générer un nom d'utilisateur aléatoire (min
|
| 32 |
-
def generate_random_username(min_length=
|
| 33 |
-
"""Génère un nom d'utilisateur aléatoire d'au moins
|
| 34 |
length = random.randint(min_length, max_length)
|
| 35 |
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
|
| 36 |
|
| 37 |
# Fonction pour générer une adresse email aléatoire
|
| 38 |
def generate_random_email():
|
| 39 |
-
"""Génère une adresse email aléatoire"""
|
| 40 |
-
username = ''.join(random.choice(string.ascii_lowercase) for _ in range(
|
| 41 |
domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
|
| 42 |
-
return f"{username}@{random.choice(domains)}"
|
| 43 |
|
| 44 |
# Fonction pour générer un mot de passe aléatoire
|
| 45 |
-
def generate_random_password(
|
| 46 |
-
"""Génère un mot de passe aléatoire
|
| 47 |
-
chars = string.
|
|
|
|
| 48 |
return ''.join(random.choice(chars) for _ in range(length))
|
|
|
|
| 49 |
# Fonction pour créer un compte
|
| 50 |
def create_account(is_startup_rep=False):
|
| 51 |
-
"""Crée un compte sur le site web"""
|
| 52 |
register_url = f"{config['base_url']}/register"
|
| 53 |
-
|
| 54 |
-
#
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
try:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
if not csrf_token:
|
| 67 |
-
return {'success': False, 'error': "Impossible de trouver le token CSRF"}
|
| 68 |
-
|
| 69 |
-
# Générer des informations de compte aléatoires
|
| 70 |
username = generate_random_username()
|
| 71 |
email = generate_random_email()
|
| 72 |
password = generate_random_password()
|
| 73 |
-
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
'confirm_password': password,
|
| 81 |
-
'submit': 'Register'
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
# Ajouter l'option startup rep si nécessaire
|
| 85 |
if is_startup_rep:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
result = {
|
| 97 |
-
'success':
|
| 98 |
'username': username,
|
| 99 |
'email': email,
|
| 100 |
'password': password,
|
| 101 |
'is_startup_rep': is_startup_rep,
|
| 102 |
'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 103 |
-
'status_code': response.status_code
|
| 104 |
}
|
| 105 |
-
|
| 106 |
return result
|
| 107 |
-
|
| 108 |
except Exception as e:
|
|
|
|
| 109 |
return {'success': False, 'error': str(e)}
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Fonction pour créer plusieurs comptes en arrière-plan
|
| 112 |
def create_accounts_background(num_accounts, startup_ratio=0.3):
|
|
@@ -165,6 +182,7 @@ def create_accounts_background(num_accounts, startup_ratio=0.3):
|
|
| 165 |
with open(config['accounts_file'], 'w') as f:
|
| 166 |
json.dump(accounts, f, indent=2)
|
| 167 |
|
|
|
|
| 168 |
# Routes Flask
|
| 169 |
@app.route('/')
|
| 170 |
def index():
|
|
@@ -174,17 +192,17 @@ def index():
|
|
| 174 |
def start():
|
| 175 |
if config['is_running']:
|
| 176 |
return jsonify({"status": "error", "message": "Une génération est déjà en cours"})
|
| 177 |
-
|
| 178 |
num_accounts = int(request.form.get('num_accounts', 10))
|
| 179 |
startup_ratio = float(request.form.get('startup_ratio', 0.3))
|
| 180 |
-
|
| 181 |
config['is_running'] = True
|
| 182 |
-
|
| 183 |
# Démarrer le processus en arrière-plan
|
| 184 |
thread = threading.Thread(target=create_accounts_background, args=(num_accounts, startup_ratio))
|
| 185 |
thread.daemon = True
|
| 186 |
thread.start()
|
| 187 |
-
|
| 188 |
return jsonify({"status": "success", "message": "Génération démarrée"})
|
| 189 |
|
| 190 |
@app.route('/stop', methods=['POST'])
|
|
@@ -200,7 +218,7 @@ def progress():
|
|
| 200 |
def view_accounts():
|
| 201 |
page = int(request.args.get('page', 1))
|
| 202 |
per_page = 20
|
| 203 |
-
|
| 204 |
accounts = []
|
| 205 |
if os.path.exists(config['accounts_file']):
|
| 206 |
try:
|
|
@@ -208,15 +226,15 @@ def view_accounts():
|
|
| 208 |
accounts = json.load(f)
|
| 209 |
except:
|
| 210 |
accounts = []
|
| 211 |
-
|
| 212 |
total_accounts = len(accounts)
|
| 213 |
total_pages = (total_accounts + per_page - 1) // per_page
|
| 214 |
-
|
| 215 |
start_idx = (page - 1) * per_page
|
| 216 |
end_idx = start_idx + per_page
|
| 217 |
-
|
| 218 |
current_accounts = accounts[start_idx:end_idx]
|
| 219 |
-
|
| 220 |
return render_template(
|
| 221 |
'accounts.html',
|
| 222 |
accounts=current_accounts,
|
|
@@ -230,6 +248,5 @@ def view_accounts():
|
|
| 230 |
def serve_js():
|
| 231 |
return render_template('script.js'), 200, {'Content-Type': 'application/javascript'}
|
| 232 |
|
| 233 |
-
|
| 234 |
if __name__ == '__main__':
|
| 235 |
-
app.run(debug=True)
|
|
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
|
|
|
|
|
|
| 2 |
import random
|
| 3 |
import string
|
| 4 |
import json
|
|
|
|
| 7 |
import time
|
| 8 |
from datetime import datetime
|
| 9 |
|
| 10 |
+
# --- Selenium Imports ---
|
| 11 |
+
from selenium import webdriver
|
| 12 |
+
from selenium.webdriver.common.by import By
|
| 13 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
| 14 |
+
from selenium.webdriver.support import expected_conditions as EC
|
| 15 |
+
from selenium.webdriver.chrome.service import Service as ChromeService
|
| 16 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
| 17 |
+
|
| 18 |
app = Flask(__name__)
|
| 19 |
|
| 20 |
# Configuration globale
|
|
|
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
+
# Fonction pour générer un nom d'utilisateur aléatoire (min 3 caractères)
|
| 38 |
+
def generate_random_username(min_length=3, max_length=10): # Adjusted min_length
|
| 39 |
+
"""Génère un nom d'utilisateur aléatoire d'au moins 3 caractères"""
|
| 40 |
length = random.randint(min_length, max_length)
|
| 41 |
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
|
| 42 |
|
| 43 |
# Fonction pour générer une adresse email aléatoire
|
| 44 |
def generate_random_email():
|
| 45 |
+
"""Génère une adresse email aléatoire au format plus standard"""
|
| 46 |
+
username = ''.join(random.choice(string.ascii_lowercase) for _ in range(7))
|
| 47 |
domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
|
| 48 |
+
return f"{username}+{int(time.time())}@{random.choice(domains)}" # Added timestamp
|
| 49 |
|
| 50 |
# Fonction pour générer un mot de passe aléatoire
|
| 51 |
+
def generate_random_password(min_length=6, max_length=12): # Adjusted min_length
|
| 52 |
+
"""Génère un mot de passe aléatoire"""
|
| 53 |
+
chars = string.ascii_letters + string.digits + "!@#$%^&*"
|
| 54 |
+
length = random.randint(min_length, max_length)
|
| 55 |
return ''.join(random.choice(chars) for _ in range(length))
|
| 56 |
+
|
| 57 |
# Fonction pour créer un compte
|
| 58 |
def create_account(is_startup_rep=False):
|
| 59 |
+
"""Crée un compte sur le site web en utilisant Selenium"""
|
| 60 |
register_url = f"{config['base_url']}/register"
|
| 61 |
+
|
| 62 |
+
# Use webdriver_manager to handle ChromeDriver
|
| 63 |
+
service = ChromeService(executable_path=ChromeDriverManager().install())
|
| 64 |
+
options = webdriver.ChromeOptions()
|
| 65 |
+
options.add_argument('--headless') # Run in headless mode (no GUI)
|
| 66 |
+
options.add_argument('--no-sandbox') # Needed for Replit/containers
|
| 67 |
+
options.add_argument('--disable-dev-shm-usage') # Also for Replit
|
| 68 |
+
|
| 69 |
+
driver = webdriver.Chrome(service=service, options=options)
|
| 70 |
+
|
| 71 |
try:
|
| 72 |
+
driver.get(register_url)
|
| 73 |
+
|
| 74 |
+
# Wait for the form to be present (important for dynamic pages)
|
| 75 |
+
WebDriverWait(driver, 10).until(
|
| 76 |
+
EC.presence_of_element_located((By.ID, "username"))
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# Generate random account data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
username = generate_random_username()
|
| 81 |
email = generate_random_email()
|
| 82 |
password = generate_random_password()
|
| 83 |
+
|
| 84 |
+
# Fill out the form fields
|
| 85 |
+
driver.find_element(By.ID, "username").send_keys(username)
|
| 86 |
+
driver.find_element(By.ID, "email").send_keys(email)
|
| 87 |
+
driver.find_element(By.ID, "password").send_keys(password)
|
| 88 |
+
driver.find_element(By.ID, "confirm_password").send_keys(password)
|
| 89 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if is_startup_rep:
|
| 91 |
+
driver.find_element(By.ID, "is_startup_rep").click()
|
| 92 |
+
|
| 93 |
+
# Submit the form
|
| 94 |
+
driver.find_element(By.ID, "submit").click()
|
| 95 |
+
|
| 96 |
+
# Wait for a result (either success or failure) - Adjust the wait time as needed
|
| 97 |
+
# We'll check for redirection as an indicator of success. A more robust check
|
| 98 |
+
# might involve looking for specific success/error messages on the resulting page.
|
| 99 |
+
WebDriverWait(driver, 10).until(
|
| 100 |
+
EC.url_changes(register_url)
|
| 101 |
+
)
|
| 102 |
|
| 103 |
+
# Check if redirection occurred to a URL other than the registration URL
|
| 104 |
+
current_url = driver.current_url
|
| 105 |
+
if current_url != register_url:
|
| 106 |
+
success = True
|
| 107 |
+
else:
|
| 108 |
+
success = False # Explicitly set to False
|
| 109 |
+
|
| 110 |
+
|
| 111 |
result = {
|
| 112 |
+
'success': success,
|
| 113 |
'username': username,
|
| 114 |
'email': email,
|
| 115 |
'password': password,
|
| 116 |
'is_startup_rep': is_startup_rep,
|
| 117 |
'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
|
| 118 |
}
|
| 119 |
+
|
| 120 |
return result
|
| 121 |
+
|
| 122 |
except Exception as e:
|
| 123 |
+
print(f"Selenium Error: {e}") # Log the Selenium error
|
| 124 |
return {'success': False, 'error': str(e)}
|
| 125 |
+
finally:
|
| 126 |
+
driver.quit() # Always close the browser
|
| 127 |
|
| 128 |
# Fonction pour créer plusieurs comptes en arrière-plan
|
| 129 |
def create_accounts_background(num_accounts, startup_ratio=0.3):
|
|
|
|
| 182 |
with open(config['accounts_file'], 'w') as f:
|
| 183 |
json.dump(accounts, f, indent=2)
|
| 184 |
|
| 185 |
+
|
| 186 |
# Routes Flask
|
| 187 |
@app.route('/')
|
| 188 |
def index():
|
|
|
|
| 192 |
def start():
|
| 193 |
if config['is_running']:
|
| 194 |
return jsonify({"status": "error", "message": "Une génération est déjà en cours"})
|
| 195 |
+
|
| 196 |
num_accounts = int(request.form.get('num_accounts', 10))
|
| 197 |
startup_ratio = float(request.form.get('startup_ratio', 0.3))
|
| 198 |
+
|
| 199 |
config['is_running'] = True
|
| 200 |
+
|
| 201 |
# Démarrer le processus en arrière-plan
|
| 202 |
thread = threading.Thread(target=create_accounts_background, args=(num_accounts, startup_ratio))
|
| 203 |
thread.daemon = True
|
| 204 |
thread.start()
|
| 205 |
+
|
| 206 |
return jsonify({"status": "success", "message": "Génération démarrée"})
|
| 207 |
|
| 208 |
@app.route('/stop', methods=['POST'])
|
|
|
|
| 218 |
def view_accounts():
|
| 219 |
page = int(request.args.get('page', 1))
|
| 220 |
per_page = 20
|
| 221 |
+
|
| 222 |
accounts = []
|
| 223 |
if os.path.exists(config['accounts_file']):
|
| 224 |
try:
|
|
|
|
| 226 |
accounts = json.load(f)
|
| 227 |
except:
|
| 228 |
accounts = []
|
| 229 |
+
|
| 230 |
total_accounts = len(accounts)
|
| 231 |
total_pages = (total_accounts + per_page - 1) // per_page
|
| 232 |
+
|
| 233 |
start_idx = (page - 1) * per_page
|
| 234 |
end_idx = start_idx + per_page
|
| 235 |
+
|
| 236 |
current_accounts = accounts[start_idx:end_idx]
|
| 237 |
+
|
| 238 |
return render_template(
|
| 239 |
'accounts.html',
|
| 240 |
accounts=current_accounts,
|
|
|
|
| 248 |
def serve_js():
|
| 249 |
return render_template('script.js'), 200, {'Content-Type': 'application/javascript'}
|
| 250 |
|
|
|
|
| 251 |
if __name__ == '__main__':
|
| 252 |
+
app.run(debug=True) # Keep debug=True for development
|