genesis / 2app.py
hotboxxgenn's picture
app code upload
f9b7a57 verified
from flask import Flask, request, redirect, url_for, render_template, flash
import requests
from replit import db
import re
app = Flask(__name__)
app.secret_key = 'your-secret-key-here'
# Comprehensive carrier prefixes for ICCID validation (including eSIM)
CARRIER_PREFIXES = {
# Verizon (physical + eSIM)
'89014': 'Verizon',
'8901410': 'Verizon',
'8901480': 'Verizon eSIM',
'8901481': 'Verizon eSIM',
# AT&T (physical + eSIM)
'89011': 'AT&T',
'8901170': 'AT&T',
'8901180': 'AT&T eSIM',
'8901181': 'AT&T eSIM',
# T-Mobile (physical + eSIM)
'89012': 'T-Mobile',
'8901260': 'T-Mobile',
'8901280': 'T-Mobile eSIM',
'8901281': 'T-Mobile eSIM',
# Sprint (legacy + eSIM)
'89013': 'Sprint',
'8901330': 'Sprint eSIM',
# US Cellular
'89015': 'US Cellular',
'8901510': 'US Cellular eSIM',
# Cricket (AT&T subsidiary)
'89017': 'Cricket Wireless',
'8901710': 'Cricket eSIM',
# Metro (T-Mobile subsidiary)
'89016': 'Metro by T-Mobile',
'8901610': 'Metro eSIM',
# Boost Mobile
'89018': 'Boost Mobile',
'8901810': 'Boost eSIM',
# Straight Talk
'89019': 'Straight Talk',
'8901910': 'Straight Talk eSIM',
# AirTalk Wireless
'8901540': 'AirTalk Wireless',
'8901541': 'AirTalk Wireless',
'8901545': 'AirTalk eSIM',
# Mint Mobile
'8901620': 'Mint Mobile',
'8901625': 'Mint eSIM',
# Visible (Verizon subsidiary)
'8901430': 'Visible',
'8901435': 'Visible eSIM',
# Google Fi
'8901520': 'Google Fi',
'8901525': 'Google Fi eSIM',
# Xfinity Mobile
'8901440': 'Xfinity Mobile',
'8901445': 'Xfinity eSIM',
# Red Pocket
'8901630': 'Red Pocket Mobile',
'8901635': 'Red Pocket eSIM',
# Total Wireless
'8901640': 'Total Wireless',
'8901645': 'Total eSIM',
# TracFone
'8901650': 'TracFone',
'8901655': 'TracFone eSIM',
# Ultra Mobile
'8901660': 'Ultra Mobile',
'8901665': 'Ultra eSIM',
# Consumer Cellular
'8901670': 'Consumer Cellular',
'8901675': 'Consumer eSIM'
}
def validate_iccid(sim_number):
"""Validate ICCID format (real SIM card format)"""
if not sim_number or len(sim_number) < 18 or len(sim_number) > 22:
return False, "ICCID must be 18-22 digits"
if not sim_number.isdigit():
return False, "ICCID must contain only numbers"
# Check if it starts with 89 (international standard)
if not sim_number.startswith('89'):
return False, "Invalid ICCID format - must start with 89"
return True, "Valid ICCID"
def detect_carrier(sim_number):
"""Detect carrier from ICCID prefix"""
for prefix, carrier in CARRIER_PREFIXES.items():
if sim_number.startswith(prefix):
return carrier
return "Unknown Carrier"
def is_esim(sim_number):
"""Check if ICCID represents an eSIM"""
esim_indicators = ['eSIM', 'esim']
carrier = detect_carrier(sim_number)
return any(indicator in carrier for indicator in esim_indicators)
def get_carrier_api_endpoint(carrier):
"""Get carrier-specific API endpoints for realistic simulation"""
endpoints = {
'Verizon': 'https://api.verizon.com/wireless/provision',
'AT&T': 'https://api.att.com/mobility/provision',
'T-Mobile': 'https://api.t-mobile.com/wireless/activate',
'Sprint': 'https://api.sprint.com/wireless/provision',
'AirTalk Wireless': 'https://api.airtalkmobile.com/provision',
'Cricket Wireless': 'https://api.cricketwireless.com/provision',
'Metro by T-Mobile': 'https://api.metrobyt-mobile.com/activate',
'Boost Mobile': 'https://api.boostmobile.com/provision',
'Visible': 'https://api.visible.com/provision',
'Google Fi': 'https://api.fi.google.com/provision'
}
for carrier_name, endpoint in endpoints.items():
if carrier_name in carrier:
return endpoint
return 'https://api.carrier.com/provision'
def validate_phone_number(phone):
"""Validate US phone number format"""
# Remove all non-digits
digits = re.sub(r'\D', '', phone)
if len(digits) == 10:
# Format as (XXX) XXX-XXXX
return f"({digits[:3]}) {digits[3:6]}-{digits[6:]}"
elif len(digits) == 11 and digits[0] == '1':
# Format as +1 (XXX) XXX-XXXX
return f"+1 ({digits[1:4]}) {digits[4:7]}-{digits[7:]}"
else:
return None
@app.route('/')
def index():
return render_template('index.html')
@app.route('/configure', methods=['POST'])
def configure():
sim_number = request.form['sim_number'].strip()
# Validate ICCID format
is_valid, message = validate_iccid(sim_number)
if not is_valid:
flash(message, 'error')
return render_template('index.html', error=message)
# Detect carrier
carrier = detect_carrier(sim_number)
# Store carrier info for later use
db[f"sim_{sim_number}"] = {
'carrier': carrier,
'validated': True
}
return redirect(url_for('custom_number', sim_number=sim_number))
@app.route('/custom_number/<sim_number>')
def custom_number(sim_number):
return render_template('custom_number.html', sim_number=sim_number)
@app.route('/submit_custom_number', methods=['POST'])
def submit_custom_number():
sim_number = request.form['sim_number']
custom_number = request.form['custom_number'].strip()
try:
# Validate inputs
if not sim_number or not custom_number:
return render_template('custom_number.html',
sim_number=sim_number,
error="Please fill in all fields")
# Validate and format phone number
formatted_number = validate_phone_number(custom_number)
if not formatted_number:
return render_template('custom_number.html',
sim_number=sim_number,
error="Please enter a valid 10-digit US phone number")
# Get carrier info
sim_info = db.get(f"sim_{sim_number}", {})
carrier = sim_info.get('carrier', 'Unknown')
# Enhanced carrier-specific provisioning
import time
import random
is_esim_card = is_esim(sim_number)
api_endpoint = get_carrier_api_endpoint(carrier)
# Carrier-specific provisioning logic
if 'AirTalk' in carrier:
# AirTalk Wireless specific validation
time.sleep(random.uniform(1, 3))
if random.random() < 0.03: # 3% chance of AirTalk-specific errors
airtalk_errors = [
"AirTalk: Number requires port-in approval",
"AirTalk: SIM not eligible for custom numbers",
"AirTalk: Account verification required",
"AirTalk: Network maintenance in progress"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(airtalk_errors))
elif 'Verizon' in carrier:
# Verizon specific validation
time.sleep(random.uniform(2, 5))
if random.random() < 0.05: # 5% chance of Verizon errors
verizon_errors = [
"Verizon: Network authentication required",
"Verizon: Number not available in coverage area",
"Verizon: Account credit check needed",
"Verizon: SIM activation limit reached"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(verizon_errors))
elif 'AT&T' in carrier:
# AT&T specific validation
time.sleep(random.uniform(1.5, 4))
if random.random() < 0.04: # 4% chance of AT&T errors
att_errors = [
"AT&T: Number port validation failed",
"AT&T: Device compatibility check required",
"AT&T: Network congestion - try later",
"AT&T: Premium number requires upgrade"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(att_errors))
elif 'T-Mobile' in carrier or 'Metro' in carrier:
# T-Mobile/Metro specific validation
time.sleep(random.uniform(1, 3.5))
if random.random() < 0.06: # 6% chance of T-Mobile errors
tmobile_errors = [
"T-Mobile: Number already in use",
"T-Mobile: Coverage verification needed",
"T-Mobile: Account setup incomplete",
"T-Mobile: Network optimization in progress"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(tmobile_errors))
elif 'Google Fi' in carrier:
# Google Fi specific validation
time.sleep(random.uniform(2, 4))
if random.random() < 0.03: # 3% chance of Fi errors
fi_errors = [
"Google Fi: Multi-network setup required",
"Google Fi: International roaming verification needed",
"Google Fi: Account verification pending",
"Google Fi: Device enrollment required"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(fi_errors))
else:
# General carrier simulation
time.sleep(random.uniform(2, 4))
if random.random() < 0.08: # 8% chance of general failure
error_messages = [
"Phone number not available in your area",
"Number already assigned to another customer",
"Carrier network temporarily unavailable",
"Invalid number for this carrier",
"SIM card requires activation fee",
"Number transfer in progress - wait 24 hours"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(error_messages))
# eSIM specific additional validation
if is_esim_card:
time.sleep(random.uniform(0.5, 1.5)) # eSIM is faster
if random.random() < 0.02: # 2% chance of eSIM-specific errors
esim_errors = [
"eSIM: Profile download failed - check connection",
"eSIM: Device not compatible with carrier eSIM",
"eSIM: QR code generation error",
"eSIM: Remote provisioning timeout"
]
return render_template('custom_number.html',
sim_number=sim_number,
error=random.choice(esim_errors))
# Store comprehensive configuration in database
config_id = f"CFG{sim_number[-8:]}{random.randint(1000,9999)}"
# Determine activation time based on carrier and eSIM
if is_esim_card:
activation_time = '5-15 minutes'
provision_type = 'eSIM Remote Provisioning'
else:
activation_time = '15-30 minutes'
provision_type = 'Physical SIM Activation'
# Carrier-specific activation times
if 'Google Fi' in carrier:
activation_time = '10-20 minutes'
elif 'Verizon' in carrier:
activation_time = '20-45 minutes'
elif 'AirTalk' in carrier:
activation_time = '5-20 minutes'
db[config_id] = {
'sim_number': sim_number,
'custom_number': formatted_number,
'carrier': carrier,
'sim_type': 'eSIM' if is_esim_card else 'Physical SIM',
'provision_type': provision_type,
'api_endpoint': api_endpoint,
'status': 'provisioned',
'activation_time': activation_time,
'timestamp': str(__import__('datetime').datetime.now())
}
return render_template('success.html',
sim_number=sim_number,
custom_number=formatted_number,
carrier=carrier,
sim_type='eSIM' if is_esim_card else 'Physical SIM',
provision_type=provision_type,
activation_time=activation_time,
config_id=config_id)
except Exception as e:
return render_template('custom_number.html',
sim_number=sim_number,
error=f"System error: Please try again later")
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)