Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, redirect, url_for
|
|
|
|
|
|
|
| 2 |
import random
|
| 3 |
import string
|
| 4 |
import json
|
|
@@ -7,14 +9,6 @@ import os
|
|
| 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,96 +28,86 @@ config = {
|
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
-
# Fonction pour générer un nom d'utilisateur aléatoire (
|
| 38 |
-
def generate_random_username(min_length=
|
| 39 |
-
"""Génère un nom d'utilisateur aléatoire d'
|
| 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
|
| 46 |
-
username = ''.join(random.choice(string.ascii_lowercase) for _ in range(
|
| 47 |
domains = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
|
| 48 |
-
return f"{username}
|
| 49 |
|
| 50 |
# Fonction pour générer un mot de passe aléatoire
|
| 51 |
-
def generate_random_password(
|
| 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
|
| 60 |
register_url = f"{config['base_url']}/register"
|
| 61 |
-
|
| 62 |
-
#
|
| 63 |
-
|
| 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 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
username = generate_random_username()
|
| 81 |
email = generate_random_email()
|
| 82 |
password = generate_random_password()
|
| 83 |
-
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if is_startup_rep:
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 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':
|
| 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,7 +166,6 @@ 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,17 +175,17 @@ 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,7 +201,7 @@ def progress():
|
|
| 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,15 +209,15 @@ def view_accounts():
|
|
| 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,
|
|
@@ -243,10 +226,9 @@ def view_accounts():
|
|
| 243 |
total_accounts=total_accounts
|
| 244 |
)
|
| 245 |
|
| 246 |
-
|
| 247 |
@app.route('/script.js')
|
| 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)
|
|
|
|
| 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 |
import time
|
| 10 |
from datetime import datetime
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
app = Flask(__name__)
|
| 13 |
|
| 14 |
# Configuration globale
|
|
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
+
# Fonction pour générer un nom d'utilisateur aléatoire (longueur normale)
|
| 32 |
+
def generate_random_username(min_length=8, max_length=12):
|
| 33 |
+
"""Génère un nom d'utilisateur aléatoire d'une longueur raisonnable"""
|
| 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(12))
|
| 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(length=10):
|
| 46 |
+
"""Génère un mot de passe aléatoire avec un mélange de caractères"""
|
| 47 |
+
chars = string.ascii_letters + string.digits + string.punctuation
|
|
|
|
| 48 |
return ''.join(random.choice(chars) for _ in range(length))
|
| 49 |
|
| 50 |
# Fonction pour créer un compte
|
| 51 |
def create_account(is_startup_rep=False):
|
| 52 |
+
"""Crée un compte sur le site web"""
|
| 53 |
register_url = f"{config['base_url']}/register"
|
| 54 |
+
|
| 55 |
+
# Première requête pour récupérer le token CSRF
|
| 56 |
+
session = requests.Session()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
try:
|
| 58 |
+
response = session.get(register_url)
|
| 59 |
+
|
| 60 |
+
if response.status_code != 200:
|
| 61 |
+
return {'success': False, 'error': f"Erreur lors de l'accès à la page: {response.status_code}"}
|
| 62 |
+
|
| 63 |
+
# Extraire le token CSRF
|
| 64 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 65 |
+
csrf_token = soup.find('input', {'id': 'csrf_token'}).get('value')
|
| 66 |
+
|
| 67 |
+
if not csrf_token:
|
| 68 |
+
return {'success': False, 'error': "Impossible de trouver le token CSRF"}
|
| 69 |
+
|
| 70 |
+
# Générer des informations de compte aléatoires
|
| 71 |
username = generate_random_username()
|
| 72 |
email = generate_random_email()
|
| 73 |
password = generate_random_password()
|
| 74 |
+
|
| 75 |
+
# Préparer les données du formulaire
|
| 76 |
+
form_data = {
|
| 77 |
+
'csrf_token': csrf_token,
|
| 78 |
+
'username': username,
|
| 79 |
+
'email': email,
|
| 80 |
+
'password': password,
|
| 81 |
+
'confirm_password': password,
|
| 82 |
+
'submit': 'Register'
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
# Ajouter l'option startup rep si nécessaire
|
| 86 |
if is_startup_rep:
|
| 87 |
+
form_data['is_startup_rep'] = 'y'
|
| 88 |
+
|
| 89 |
+
# Envoyer le formulaire
|
| 90 |
+
headers = {
|
| 91 |
+
'Referer': register_url,
|
| 92 |
+
'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'
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
response = session.post(register_url, data=form_data, headers=headers)
|
|
|
|
|
|
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
result = {
|
| 98 |
+
'success': response.status_code == 200 or response.status_code == 302,
|
| 99 |
'username': username,
|
| 100 |
'email': email,
|
| 101 |
'password': password,
|
| 102 |
'is_startup_rep': is_startup_rep,
|
| 103 |
'created_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 104 |
+
'status_code': response.status_code
|
| 105 |
}
|
| 106 |
+
|
| 107 |
return result
|
| 108 |
+
|
| 109 |
except Exception as e:
|
|
|
|
| 110 |
return {'success': False, 'error': str(e)}
|
|
|
|
|
|
|
| 111 |
|
| 112 |
# Fonction pour créer plusieurs comptes en arrière-plan
|
| 113 |
def create_accounts_background(num_accounts, startup_ratio=0.3):
|
|
|
|
| 166 |
with open(config['accounts_file'], 'w') as f:
|
| 167 |
json.dump(accounts, f, indent=2)
|
| 168 |
|
|
|
|
| 169 |
# Routes Flask
|
| 170 |
@app.route('/')
|
| 171 |
def index():
|
|
|
|
| 175 |
def start():
|
| 176 |
if config['is_running']:
|
| 177 |
return jsonify({"status": "error", "message": "Une génération est déjà en cours"})
|
| 178 |
+
|
| 179 |
num_accounts = int(request.form.get('num_accounts', 10))
|
| 180 |
startup_ratio = float(request.form.get('startup_ratio', 0.3))
|
| 181 |
+
|
| 182 |
config['is_running'] = True
|
| 183 |
+
|
| 184 |
# Démarrer le processus en arrière-plan
|
| 185 |
thread = threading.Thread(target=create_accounts_background, args=(num_accounts, startup_ratio))
|
| 186 |
thread.daemon = True
|
| 187 |
thread.start()
|
| 188 |
+
|
| 189 |
return jsonify({"status": "success", "message": "Génération démarrée"})
|
| 190 |
|
| 191 |
@app.route('/stop', methods=['POST'])
|
|
|
|
| 201 |
def view_accounts():
|
| 202 |
page = int(request.args.get('page', 1))
|
| 203 |
per_page = 20
|
| 204 |
+
|
| 205 |
accounts = []
|
| 206 |
if os.path.exists(config['accounts_file']):
|
| 207 |
try:
|
|
|
|
| 209 |
accounts = json.load(f)
|
| 210 |
except:
|
| 211 |
accounts = []
|
| 212 |
+
|
| 213 |
total_accounts = len(accounts)
|
| 214 |
total_pages = (total_accounts + per_page - 1) // per_page
|
| 215 |
+
|
| 216 |
start_idx = (page - 1) * per_page
|
| 217 |
end_idx = start_idx + per_page
|
| 218 |
+
|
| 219 |
current_accounts = accounts[start_idx:end_idx]
|
| 220 |
+
|
| 221 |
return render_template(
|
| 222 |
'accounts.html',
|
| 223 |
accounts=current_accounts,
|
|
|
|
| 226 |
total_accounts=total_accounts
|
| 227 |
)
|
| 228 |
|
|
|
|
| 229 |
@app.route('/script.js')
|
| 230 |
def serve_js():
|
| 231 |
return render_template('script.js'), 200, {'Content-Type': 'application/javascript'}
|
| 232 |
|
| 233 |
if __name__ == '__main__':
|
| 234 |
+
app.run(debug=True)
|