222 lines
8.9 KiB
Python
222 lines
8.9 KiB
Python
#!/usr/bin/env python
|
|
"""smallest.ai (smallest.ai / Waves) autoreg pipeline.
|
|
|
|
Flow (no captcha, no SMS, email OTP only):
|
|
1) GET /console/v1/csrf-token -> x-csrf-token cookie + token
|
|
2) POST /console/v1/auth/send-otp {userEmail} -> OTP mail from noreply@smallest.ai
|
|
3) POST /console/v1/auth/verify-otp (form-urlencoded: userEmail, otp, origin=console)
|
|
-> 302 to /dashboard/settings/subscription, sets accessToken/refreshToken cookies
|
|
4) GET /atoms/v1/account/get-account-details -> userId + orgId (auto-created)
|
|
5) POST /atoms/v1/onboarding/create {"data":{...}} -> hasOnboarded=true
|
|
6) GET /payment/v1/credits/balance -> 10.0 free credits (plan_standard)
|
|
7) POST /console/v1/apikeys/create-api-key -> key record (value masked server-side)
|
|
|
|
Every write to waves/console needs X-Organization-Id for org-scoped routes.
|
|
"""
|
|
import json, os, random, re, subprocess, sys, threading, time
|
|
import requests
|
|
|
|
BASE = "https://api.smallest.ai"
|
|
CONSOLE = BASE + "/console/v1"
|
|
ATOMS = BASE + "/atoms/v1"
|
|
PAYMENT = BASE + "/payment/v1"
|
|
WAVES = BASE + "/waves/v1"
|
|
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
"(KHTML, like Gecko) Chrome/156.0.0.0 Safari/537.36")
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
MAIL_POOL = r"C:\Users\User\Desktop\avtoreg\working_mails.txt"
|
|
USED_FILE = os.path.join(HERE, "used_mails.txt")
|
|
BANK = os.path.join(HERE, "bank.jsonl")
|
|
VPS = os.environ.get("SM_VPS", "root@144.31.34.147")
|
|
IMAP_HOST = "secureimap.t-online.de"
|
|
|
|
_lock = threading.Lock()
|
|
|
|
|
|
# ---------------------------------------------------------------- mail reader
|
|
def _ssh(cmd, timeout=180):
|
|
p = subprocess.run(["ssh", "-o", "StrictHostKeyChecking=no", "-o", "ConnectTimeout=20", VPS, cmd],
|
|
capture_output=True, text=True, timeout=timeout)
|
|
return (p.stdout or "") + (p.stderr or "")
|
|
|
|
|
|
def fetch_code(email, pw, timeout=150):
|
|
"""Poll the mailbox (on VPS, t-online IMAP is throttled from home) for the
|
|
smallest.ai OTP. Returns 6-digit code or None."""
|
|
remote = (
|
|
'python3 - "%s" "%s" %d <<\'PYEOF\'\n'
|
|
"import imaplib,email,re,sys,time,html\n"
|
|
"addr,pw,tmo=sys.argv[1],sys.argv[2],int(sys.argv[3])\n"
|
|
"t0=time.time()\n"
|
|
"while time.time()-t0<tmo:\n"
|
|
" try:\n"
|
|
" m=imaplib.IMAP4_SSL('secureimap.t-online.de',993,timeout=40)\n"
|
|
" m.login(addr,pw); m.select('INBOX',readonly=True)\n"
|
|
" typ,d=m.uid('SEARCH',None,'FROM','noreply@smallest.ai')\n"
|
|
" uids=[int(x) for x in (d[0].split() if d and d[0] else [])]\n"
|
|
" for u in sorted(uids,reverse=True)[:3]:\n"
|
|
" typ,md=m.uid('FETCH',str(u),'(RFC822)')\n"
|
|
" msg=email.message_from_bytes(md[0][1])\n"
|
|
" for p in msg.walk():\n"
|
|
" b=(p.get_payload(decode=True) or b'').decode(p.get_content_charset() or 'utf-8','replace')\n"
|
|
" t=html.unescape(re.sub(r'<[^>]+>',' ',b)); t=re.sub(r'\\s+',' ',t)\n"
|
|
" mm=re.search(r'account\\.\\s*(\\d{6})',t) or re.search(r'\\b(\\d{6})\\b',t)\n"
|
|
" if mm:\n"
|
|
" print('CODE',mm.group(1)); m.logout(); sys.exit(0)\n"
|
|
" m.logout()\n"
|
|
" except Exception as e:\n"
|
|
" print('ERR',type(e).__name__)\n"
|
|
" time.sleep(5)\n"
|
|
"print('NONE')\n"
|
|
"PYEOF\n" % (email, pw, timeout)
|
|
)
|
|
out = _ssh(remote, timeout=timeout + 60)
|
|
m = re.search(r"CODE (\d{6})", out)
|
|
return m.group(1) if m else None
|
|
|
|
|
|
# ------------------------------------------------------------------- http ops
|
|
def new_session(referer="/login"):
|
|
s = requests.Session()
|
|
s.headers.update({"User-Agent": UA, "Origin": "https://app.smallest.ai",
|
|
"Referer": "https://app.smallest.ai" + referer,
|
|
"Accept": "application/json, text/plain, */*"})
|
|
return s
|
|
|
|
|
|
def csrf(s, base=CONSOLE):
|
|
tok = json.loads(s.get(base + "/csrf-token", timeout=25).text)["csrfToken"]
|
|
s.headers["x-csrf-token"] = tok
|
|
return tok
|
|
|
|
|
|
def register(email, pw, otp_timeout=150, verbose=True):
|
|
"""Returns dict with session cookies + org/user ids, or {'error': ...}."""
|
|
s = new_session()
|
|
csrf(s)
|
|
r = s.post(CONSOLE + "/auth/send-otp", json={"userEmail": email}, timeout=30)
|
|
if r.status_code != 200 or "success" not in r.text.lower():
|
|
return {"error": "send-otp %s %s" % (r.status_code, r.text[:120])}
|
|
code = fetch_code(email, pw, timeout=otp_timeout)
|
|
if not code:
|
|
return {"error": "no-otp"}
|
|
r = s.post(CONSOLE + "/auth/verify-otp",
|
|
data={"userEmail": email, "otp": code, "origin": "console"},
|
|
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
|
timeout=30, allow_redirects=False)
|
|
loc = r.headers.get("location", "")
|
|
if "error=" in loc:
|
|
return {"error": "verify %s" % loc.split("error=")[-1][:80]}
|
|
if "accessToken" not in s.cookies:
|
|
return {"error": "no-token %s" % loc[:80]}
|
|
acc = s.get(ATOMS + "/account/get-account-details", timeout=25).json()
|
|
org = acc["organizations"][0]["orgId"]
|
|
uid = acc["userId"]
|
|
s.headers["X-Organization-Id"] = org
|
|
csrf(s, ATOMS)
|
|
body = {"data": {"name": "Wave Labs", "nameType": "workspace",
|
|
"firstName": "Alex", "lastName": "M",
|
|
"helpOption": "voice-cloning", "platform": "Atoms"}}
|
|
onb = s.post(ATOMS + "/onboarding/create", json=body, timeout=30)
|
|
bal = s.get(PAYMENT + "/credits/balance", timeout=25)
|
|
credits = None
|
|
try:
|
|
credits = bal.json()["data"]["creditBalance"]
|
|
except Exception:
|
|
pass
|
|
rec = {"email": email, "pw": pw, "userId": uid, "orgId": org,
|
|
"credits": credits, "onboarded": onb.status_code == 201,
|
|
"cookies": s.cookies.get_dict(), "ts": int(time.time())}
|
|
if verbose:
|
|
print("OK %s org=%s credits=%s onb=%s" % (email, org, credits, onb.status_code), flush=True)
|
|
return rec
|
|
|
|
|
|
def make_key(rec, name="auto"):
|
|
s = session_from(rec)
|
|
csrf(s)
|
|
s.headers["X-Organization-Id"] = rec["orgId"]
|
|
r = s.post(CONSOLE + "/apikeys/create-api-key",
|
|
json={"userId": rec["userId"], "apiKeyName": name}, timeout=30)
|
|
return r.status_code, r.text[:200]
|
|
|
|
|
|
def session_from(rec, referer="/dashboard"):
|
|
s = new_session(referer)
|
|
for k, v in rec["cookies"].items():
|
|
s.cookies.set(k, v, domain="api.smallest.ai")
|
|
s.headers["X-Organization-Id"] = rec["orgId"]
|
|
return s
|
|
|
|
|
|
# ------------------------------------------------------------------- wave run
|
|
def load_pool():
|
|
used = set()
|
|
if os.path.exists(USED_FILE):
|
|
used = {l.strip() for l in open(USED_FILE, encoding="utf-8", errors="ignore")}
|
|
out = []
|
|
for l in open(MAIL_POOL, encoding="utf-8", errors="ignore"):
|
|
l = l.strip()
|
|
if not l or l.startswith("#") or ":" not in l:
|
|
continue
|
|
em, pw = l.split(":", 1)
|
|
if "@t-online.de" not in em or em in used:
|
|
continue
|
|
out.append((em, pw))
|
|
random.shuffle(out)
|
|
return out
|
|
|
|
|
|
def wave(n=5, workers=3):
|
|
pool = load_pool()
|
|
print("pool free:", len(pool), flush=True)
|
|
todo = pool[: max(n * 2, n)]
|
|
q = list(todo)
|
|
got = 0
|
|
res = []
|
|
|
|
def worker():
|
|
nonlocal got
|
|
while True:
|
|
with _lock:
|
|
if not q or got >= n:
|
|
return
|
|
em, pw = q.pop(0)
|
|
try:
|
|
rec = register(em, pw)
|
|
except Exception as e:
|
|
rec = {"error": "%s: %s" % (type(e).__name__, e), "email": em, "pw": pw}
|
|
if rec.get("error"):
|
|
print("FAIL", em, rec["error"][:90], flush=True)
|
|
continue
|
|
with _lock:
|
|
got += 1
|
|
res.append(rec)
|
|
with open(BANK, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
|
|
with open(USED_FILE, "a", encoding="utf-8") as f:
|
|
f.write(em + "\n")
|
|
|
|
ths = [threading.Thread(target=worker) for _ in range(workers)]
|
|
for t in ths:
|
|
t.start()
|
|
for t in ths:
|
|
t.join()
|
|
print("WAVE DONE ok=%d" % len(res), flush=True)
|
|
return res
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) > 1 and sys.argv[1] == "wave":
|
|
n = int(sys.argv[2]) if len(sys.argv) > 2 else 5
|
|
w = int(sys.argv[3]) if len(sys.argv) > 3 else 3
|
|
wave(n, w)
|
|
elif len(sys.argv) > 2 and sys.argv[1] == "one":
|
|
em, pw = sys.argv[2], sys.argv[3]
|
|
rec = register(em, pw)
|
|
print(json.dumps({k: v for k, v in rec.items() if k != "cookies"}, indent=1))
|
|
elif len(sys.argv) > 2 and sys.argv[1] == "key":
|
|
recs = [json.loads(l) for l in open(BANK, encoding="utf-8")]
|
|
for i, rec in enumerate(recs[: int(sys.argv[2])]):
|
|
print(rec["email"], make_key(rec, "auto%d" % i)) |