recovered snapshot from suspended aaronjaworski710 (history unavailable)
This commit is contained in:
+176
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env python3
|
||||
# __portable_paths__ (auto-injected: portable, env-overridable paths)
|
||||
import os as _pos, sys as _psys
|
||||
from pathlib import Path as _PPath
|
||||
_ROOT = _PPath(__file__).resolve().parent
|
||||
_REPO = _ROOT
|
||||
for _ in range(4):
|
||||
if (_REPO / ".git").exists() or (_REPO / "README.md").exists():
|
||||
break
|
||||
if _REPO.parent == _REPO:
|
||||
break
|
||||
_REPO = _REPO.parent
|
||||
_DATA = _PPath(_pos.environ.get("TOOLKIT_DATA", str(_REPO / "data")))
|
||||
_WORK = _PPath(_pos.environ.get("TOOLKIT_WORK", str(_REPO / "_work")))
|
||||
try:
|
||||
_DATA.mkdir(parents=True, exist_ok=True)
|
||||
_WORK.mkdir(parents=True, exist_ok=True)
|
||||
except Exception:
|
||||
pass
|
||||
_PY = _pos.environ.get("PYTHON_BIN") or _psys.executable
|
||||
_USERPROFILE = _pos.environ.get("USERPROFILE") or str(_PPath.home())
|
||||
def _d(name, env=None):
|
||||
"""Data-file path under ./data (or $TOOLKIT_DATA); optional per-file env override."""
|
||||
if env and _pos.environ.get(env):
|
||||
return _PPath(_pos.environ[env])
|
||||
return _DATA / name
|
||||
def _w(name=""):
|
||||
"""Work-dir path under ./_work (or $TOOLKIT_WORK)."""
|
||||
return (_WORK / name) if name else _WORK
|
||||
# --- end portable prelude ---
|
||||
|
||||
# Haze mass registration: working_mails.txt -> bootstrap -> IMAP OTP -> verify -> token
|
||||
# Appends live tokens to tokens.json (proxy pool) and accounts.jsonl (bank)
|
||||
import json, subprocess, imaplib, email, re, time, email.utils, os, random, sys
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
import threading
|
||||
|
||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
API = "https://usehaze.ai/api"
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36"
|
||||
MAILS = str(_d("Desktop/avtoreg/working_mails.txt","MAIL_POOL"))
|
||||
PW = os.environ["HAZE_PW"]
|
||||
STATE_F = os.path.join(DIR, "reg_state.json")
|
||||
BANK_F = os.path.join(DIR, "accounts.jsonl")
|
||||
POOL_F = os.path.join(DIR, "tokens.json")
|
||||
LOCK = threading.Lock()
|
||||
|
||||
state = json.load(open(STATE_F, encoding="utf-8")) if os.path.exists(STATE_F) else {"used": [], "stats": {}}
|
||||
USED = set(state["used"])
|
||||
|
||||
def save_state():
|
||||
with LOCK:
|
||||
state["used"] = list(USED)
|
||||
json.dump(state, open(STATE_F, "w", encoding="utf-8"))
|
||||
|
||||
def curl_post(path, payload, timeout=60):
|
||||
r = subprocess.run(["curl", "-s", "-X", "POST", API + path,
|
||||
"-H", "Content-Type: application/json",
|
||||
"-H", "User-Agent: " + UA,
|
||||
"-d", json.dumps(payload),
|
||||
"-w", "\n%{http_code}"],
|
||||
capture_output=True, text=True, timeout=timeout)
|
||||
body, _, code = r.stdout.rpartition("\n")
|
||||
try: return int(code), json.loads(body)
|
||||
except Exception: return int(code or 0), {"raw": body[:200]}
|
||||
|
||||
def get_otp(mail, mpass, start, tries=12):
|
||||
for t in range(tries):
|
||||
time.sleep(5 + random.random() * 3)
|
||||
try:
|
||||
m = imaplib.IMAP4_SSL("secureimap.t-online.de", 993, timeout=30)
|
||||
m.login(mail, mpass); m.select("INBOX")
|
||||
typ, data = m.search(None, '(FROM "welcome@workos.dev")')
|
||||
ids = data[0].split()
|
||||
otp = None
|
||||
for i in reversed(ids[-3:]):
|
||||
typ, d = m.fetch(i, "(RFC822)")
|
||||
raw = d[0][1].decode("utf-8", "ignore")
|
||||
msg = email.message_from_string(raw)
|
||||
try:
|
||||
dt = email.utils.parsedate_to_datetime(msg["Date"]).timestamp()
|
||||
except Exception:
|
||||
continue
|
||||
if dt < start - 30: continue
|
||||
body = ""
|
||||
for p in msg.walk():
|
||||
if p.get_content_type() == "text/plain":
|
||||
body = p.get_payload(decode=True).decode("utf-8", "ignore"); break
|
||||
codes = re.findall(r"\b(\d{6})\b", body)
|
||||
if codes: otp = codes[0]; break
|
||||
m.logout()
|
||||
if otp: return otp
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def add_token(tok, mail):
|
||||
with LOCK:
|
||||
pool = json.load(open(POOL_F, encoding="utf-8")) if os.path.exists(POOL_F) else []
|
||||
if not any(p["token"] == tok for p in pool):
|
||||
pool.append({"token": tok, "email": mail, "ok": True, "fails": 0})
|
||||
json.dump(pool, open(POOL_F, "w", encoding="utf-8"), indent=1)
|
||||
with open(BANK_F, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({"email": mail, "plan": "free", "ts": int(time.time())}) + "\n")
|
||||
|
||||
def reg_one(mail, mpass):
|
||||
start = time.time()
|
||||
c, res = 0, {}
|
||||
for attempt in range(4):
|
||||
try:
|
||||
c, res = curl_post("/auth/bootstrap", {"email": mail, "password": PW, "create": True})
|
||||
except Exception as e:
|
||||
return mail, "bootstrap_exc:" + str(e)[:60]
|
||||
if c == 429:
|
||||
wait = 30 * (attempt + 1) + random.random() * 20
|
||||
time.sleep(wait)
|
||||
continue
|
||||
break
|
||||
if c == 429:
|
||||
return mail, "rate_limited_final"
|
||||
if c == 401:
|
||||
return mail, "exists_other_pw" # registered elsewhere, unusable
|
||||
if c == 200 and res.get("status") == "authenticated" and "accessToken" in res:
|
||||
add_token(res["accessToken"], mail)
|
||||
return mail, "OK:existing"
|
||||
if c != 200 or "pendingToken" not in res:
|
||||
return mail, f"boot:{c}:{json.dumps(res)[:80]}"
|
||||
otp = get_otp(mail, mpass, start)
|
||||
if not otp:
|
||||
return mail, "no_otp"
|
||||
try:
|
||||
c2, res2 = curl_post("/auth/verify-code", {"code": otp, "pending_authentication_token": res["pendingToken"]})
|
||||
except Exception as e:
|
||||
return mail, "verify_exc:" + str(e)[:60]
|
||||
if "accessToken" in res2:
|
||||
add_token(res2["accessToken"], mail)
|
||||
return mail, "OK:" + str(res2.get("profile", {}).get("plan"))
|
||||
return mail, f"verify:{c2}:{json.dumps(res2)[:80]}"
|
||||
|
||||
def load_mails(limit):
|
||||
out = []
|
||||
for ln in open(MAILS, encoding="utf-8", errors="ignore"):
|
||||
ln = ln.strip()
|
||||
if not ln or ln.startswith("#") or ":" not in ln: continue
|
||||
mail, _, mpass = ln.partition(":")
|
||||
if "-" in mail.split("@")[0]: continue # dash aliases dead for delivery
|
||||
if mail in USED: continue
|
||||
out.append((mail, mpass))
|
||||
if len(out) >= limit: break
|
||||
return out
|
||||
|
||||
def main():
|
||||
n = int(sys.argv[1]) if len(sys.argv) > 1 else 30
|
||||
workers = int(sys.argv[2]) if len(sys.argv) > 2 else 4
|
||||
mails = load_mails(n)
|
||||
print(f"mass reg: {len(mails)} mails, {workers} workers", flush=True)
|
||||
stats = {"ok": 0, "fail": 0}
|
||||
with ThreadPoolExecutor(max_workers=workers) as ex:
|
||||
futs = {}
|
||||
for m, p in mails:
|
||||
futs[ex.submit(reg_one, m, p)] = m
|
||||
time.sleep(4 + random.random() * 4)
|
||||
for f in as_completed(futs):
|
||||
mail, res = f.result()
|
||||
USED.add(mail)
|
||||
if res.startswith("OK"):
|
||||
stats["ok"] += 1
|
||||
print(f"[OK {stats['ok']}] {mail} -> {res}", flush=True)
|
||||
else:
|
||||
stats["fail"] += 1
|
||||
print(f"[FAIL] {mail} -> {res}", flush=True)
|
||||
save_state()
|
||||
print(f"DONE ok={stats['ok']} fail={stats['fail']}", flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user