175 lines
6.2 KiB
Python
175 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Entry point: ChatGPT Plus auto-registration + subscription, or Codex OAuth login."""
|
|
import argparse
|
|
import random
|
|
import string
|
|
import sys
|
|
|
|
from config import settings
|
|
from vmail_client import MailClient
|
|
from captcha_solver import CaptchaSolver
|
|
from http_client import HTTPClient
|
|
from chatgpt_register_http_reverse import ChatGPTRegisterHTTPReverse
|
|
from chatgpt_payment import ChatGPTPayment
|
|
from codex_oauth_http_flow import CodexOAuthHTTPFlow, DEFAULT_AUTHORIZE_URL
|
|
|
|
|
|
def generate_password(length=16):
|
|
chars = string.ascii_letters + string.digits + "!@#$%"
|
|
while True:
|
|
pwd = "".join(random.choice(chars) for _ in range(length))
|
|
if (any(c.islower() for c in pwd) and any(c.isupper() for c in pwd)
|
|
and any(c.isdigit() for c in pwd) and any(c in "!@#$%" for c in pwd)):
|
|
return pwd
|
|
|
|
|
|
def generate_name():
|
|
first = random.choice(["John", "Jane", "Mike", "Sarah", "David", "Emma", "Chris", "Lisa"])
|
|
last = random.choice(["Smith", "Johnson", "Brown", "Davis", "Wilson", "Moore", "Taylor", "Lee"])
|
|
return f"{first} {last}"
|
|
|
|
|
|
def cmd_register(args):
|
|
"""Register a new ChatGPT account and optionally subscribe to Plus."""
|
|
password = generate_password()
|
|
name = generate_name()
|
|
|
|
print("Generated credentials:")
|
|
print(f" Password: {password}")
|
|
print(f" Name: {name}")
|
|
|
|
mail = MailClient()
|
|
http = HTTPClient(proxy=settings.socks5_proxy)
|
|
http.enable_pacing(min_delay=0.5, max_delay=2.0)
|
|
|
|
try:
|
|
print("\n=== ChatGPT Registration ===")
|
|
register = ChatGPTRegisterHTTPReverse(http, mail)
|
|
session = register.register(password, name)
|
|
print("\n Registration complete!")
|
|
print(f" Email: {session['email']}")
|
|
print(f" Mailbox password: {session['mailbox_password']}")
|
|
print(f" ChatGPT password: {password}")
|
|
if session["access_token"]:
|
|
print(f" Access Token: {session['access_token'][:50]}...")
|
|
|
|
if settings.card_number and session.get("access_token"):
|
|
print("\n=== ChatGPT Plus Subscription ===")
|
|
captcha = CaptchaSolver(settings.yescaptcha_api_key)
|
|
payment = ChatGPTPayment(http, captcha)
|
|
success = payment.subscribe_plus(
|
|
access_token=session["access_token"],
|
|
country=settings.country,
|
|
currency=settings.currency,
|
|
card_info={
|
|
"number": settings.card_number,
|
|
"exp_month": settings.card_exp_month,
|
|
"exp_year": settings.card_exp_year,
|
|
"cvc": settings.card_cvc,
|
|
"billing_name": settings.billing_name or name,
|
|
"billing_email": settings.billing_email or session["email"],
|
|
"billing_address_line1": settings.billing_address_line1,
|
|
"billing_address_city": settings.billing_address_city,
|
|
"billing_address_state": settings.billing_address_state,
|
|
"billing_address_postal_code": settings.billing_address_postal_code,
|
|
},
|
|
)
|
|
if success:
|
|
print("\n Plus subscription complete!")
|
|
print(f" Email: {session['email']}")
|
|
print(f" Mailbox password: {session['mailbox_password']}")
|
|
print(f" ChatGPT password: {password}")
|
|
else:
|
|
print("\n No card info configured, skipping Plus subscription")
|
|
except Exception as e:
|
|
print(f"\n Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return 1
|
|
finally:
|
|
http.close()
|
|
return 0
|
|
|
|
|
|
def cmd_codex_login(args):
|
|
"""Run Codex OAuth login and print the callback URL with authorization code."""
|
|
email = args.email
|
|
password = args.password
|
|
if not email:
|
|
email = input("Email: ").strip()
|
|
if not password:
|
|
import getpass
|
|
password = getpass.getpass("Password: ")
|
|
|
|
authorize_url = args.authorize_url or DEFAULT_AUTHORIZE_URL
|
|
|
|
print(f"Starting Codex OAuth flow for {email}")
|
|
flow = CodexOAuthHTTPFlow(
|
|
authorize_url=authorize_url,
|
|
email=email,
|
|
password=password,
|
|
otp=args.otp or "",
|
|
workspace_id=args.workspace_id or "",
|
|
)
|
|
try:
|
|
callback_url = flow.run()
|
|
print("\n" + "=" * 60)
|
|
print("[SUCCESS] callback_url:")
|
|
print(callback_url)
|
|
print("=" * 60)
|
|
return 0
|
|
except Exception as e:
|
|
print(f"\n[ERROR] {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return 1
|
|
finally:
|
|
flow.close()
|
|
|
|
|
|
def build_parser():
|
|
parser = argparse.ArgumentParser(
|
|
description="ChatGPT Plus auto-registration + subscription, or Codex OAuth login",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Commands:
|
|
register Auto-register a new ChatGPT account and subscribe to Plus
|
|
codex-login Run Codex CLI OAuth login and obtain the callback URL
|
|
|
|
Examples:
|
|
python src/main.py register
|
|
python src/main.py codex-login --email user@example.com --password mypass
|
|
"""
|
|
)
|
|
sub = parser.add_subparsers(dest="command")
|
|
|
|
# register sub-command
|
|
sub.add_parser("register", help="Register new ChatGPT account + optional Plus subscription")
|
|
|
|
# codex-login sub-command
|
|
p_codex = sub.add_parser("codex-login", help="Codex CLI OAuth login (HTTP-only, no browser)")
|
|
p_codex.add_argument("--email", default="", help="OpenAI account email")
|
|
p_codex.add_argument("--password", default="", help="OpenAI account password")
|
|
p_codex.add_argument("--otp", default="", help="Email OTP code (if already known)")
|
|
p_codex.add_argument("--workspace-id", dest="workspace_id", default="", help="Workspace ID to select")
|
|
p_codex.add_argument("--authorize-url", dest="authorize_url", default="", help="Custom authorize URL")
|
|
|
|
return parser
|
|
|
|
|
|
def main():
|
|
parser = build_parser()
|
|
args = parser.parse_args()
|
|
|
|
if args.command == "register":
|
|
return cmd_register(args)
|
|
elif args.command == "codex-login":
|
|
return cmd_codex_login(args)
|
|
else:
|
|
parser.print_help()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|