489 lines
20 KiB
Python
489 lines
20 KiB
Python
"""Camb.ai autoreg farm: signup -> mail verify -> skip onboarding -> create API key -> bank.
|
|
|
|
Usage: python farm.py <count> [start_idx]
|
|
One playwright session, fresh incognito context per account (Chrome dies between runs).
|
|
"""
|
|
import json
|
|
import random
|
|
import re
|
|
import string
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
import requests
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
import chr
|
|
|
|
MPOOL = sys.argv[3] if len(sys.argv) > 3 else r"C:\Users\User\Desktop\avtoreg\working_mails.txt"
|
|
BANK = "camb_bank.jsonl"
|
|
VPS = "root@144.31.34.147"
|
|
VPS_LIST = ["root@144.31.34.149", "root@144.31.34.150", "root@144.31.34.147"]
|
|
|
|
N = int(sys.argv[1]) if len(sys.argv) > 1 and sys.argv[1].isdigit() else 1
|
|
START = int(sys.argv[2]) if len(sys.argv) > 2 and sys.argv[2].isdigit() else 30
|
|
|
|
|
|
def local_code(email, password, timeout=90):
|
|
import imaplib
|
|
end = time.time() + timeout
|
|
while time.time() < end:
|
|
try:
|
|
m = imaplib.IMAP4_SSL("secureimap.t-online.de", 993, timeout=40)
|
|
m.login(email, password)
|
|
m.select("INBOX", readonly=True)
|
|
d = m.search(None, "ALL")[1][0].split()
|
|
uids = [int(x) for x in d] if d else []
|
|
for u in reversed(uids[-40:]):
|
|
md = m.fetch(str(u), "(RFC822)")[1]
|
|
if not md or not md[0]:
|
|
continue
|
|
msg = email.message_from_bytes(md[0][1])
|
|
subj = str(msg.get("Subject", ""))
|
|
frm = str(msg.get("From", ""))
|
|
if "camb" not in (subj + frm).lower():
|
|
continue
|
|
body = ""
|
|
if msg.is_multipart():
|
|
for pp in msg.walk():
|
|
if pp.get_content_type() in ("text/plain", "text/html"):
|
|
try:
|
|
body += pp.get_payload(decode=True).decode(pp.get_content_charset() or "utf-8", "ignore")
|
|
except Exception:
|
|
pass
|
|
else:
|
|
try:
|
|
body = msg.get_payload(decode=True).decode("utf-8", "ignore")
|
|
except Exception:
|
|
pass
|
|
mm = re.search(r"code is\s+([A-Za-z0-9]{6})", subj + " " + body)
|
|
if mm:
|
|
m.logout()
|
|
return mm.group(1)
|
|
m.logout()
|
|
except Exception:
|
|
pass
|
|
time.sleep(8)
|
|
return None
|
|
|
|
|
|
def gen_pass(n=16):
|
|
parts = [random.choice(string.ascii_uppercase), random.choice(string.ascii_lowercase),
|
|
random.choice(string.digits), random.choice("*#!")]
|
|
parts += [random.choice(string.ascii_letters + string.digits + "*#!") for _ in range(n - 4)]
|
|
random.shuffle(parts)
|
|
return "".join(parts)
|
|
|
|
|
|
def mail_code(email, password, timeout=150, tag=""):
|
|
"""fetch 6-char verification code (camb letter: 'code is XXXXXX')."""
|
|
deadline = time.time() + timeout
|
|
while time.time() < deadline:
|
|
for host in VPS_LIST:
|
|
try:
|
|
r = subprocess.run(
|
|
["ssh", "-o", "StrictHostKeyChecking=no", "-o", "ConnectTimeout=12", host,
|
|
"python3", "/root/camb_code.py", email, password, "60"],
|
|
capture_output=True, text=True, timeout=80)
|
|
out = (r.stdout or "") + (r.stderr or "")
|
|
m = re.search(r"CCODE\s+([A-Z0-9]{6})\b", out)
|
|
if m:
|
|
return m.group(1)
|
|
except Exception:
|
|
continue
|
|
loc = local_code(email, password, timeout=45)
|
|
if loc:
|
|
return loc
|
|
time.sleep(6)
|
|
return None
|
|
|
|
|
|
def one(ctx, email, password, tag):
|
|
events = []
|
|
|
|
def on_resp(r):
|
|
try:
|
|
if "client.camb.ai" in r.url:
|
|
b = ""
|
|
try:
|
|
if "json" in (r.headers.get("content-type") or ""):
|
|
b = r.text()[:600]
|
|
except Exception:
|
|
pass
|
|
events.append((r.status, r.request.method, r.url, b))
|
|
except Exception:
|
|
pass
|
|
|
|
pg = ctx.new_page()
|
|
pg.on("response", on_resp)
|
|
# wipe any previous session (cookies + localStorage) before signup
|
|
try:
|
|
pg.goto("https://studio.camb.ai/public/onboarding", wait_until="domcontentloaded", timeout=60000)
|
|
time.sleep(6)
|
|
pg.evaluate("()=>{try{localStorage.clear();sessionStorage.clear()}catch(e){}}")
|
|
ctx.clear_cookies()
|
|
time.sleep(2)
|
|
except Exception:
|
|
pass
|
|
# --- signup form
|
|
ok_form = False
|
|
for attempt in range(6):
|
|
try:
|
|
pg.goto("https://studio.camb.ai/public/onboarding", wait_until="domcontentloaded", timeout=60000)
|
|
pg.wait_for_selector("input[name=name]", timeout=30000)
|
|
ok_form = True
|
|
break
|
|
except Exception as e:
|
|
print(f"[{tag}] form attempt {attempt}:", str(e)[:80])
|
|
time.sleep(5)
|
|
if not ok_form:
|
|
print(f"[{tag}] form never appeared"); pg.close(); return None
|
|
pg.fill("input[name=name]", "Nik Reform")
|
|
pg.fill("input[type=email]", email)
|
|
pw = gen_pass()
|
|
pg.fill("input[type=password]", pw)
|
|
cb = pg.query_selector("#consent")
|
|
if cb:
|
|
bb = cb.bounding_box()
|
|
if bb:
|
|
pg.mouse.click(bb["x"] + bb["width"] / 2, bb["y"] + bb["height"] / 2)
|
|
time.sleep(0.5)
|
|
checked = cb.get_attribute("aria-checked") or cb.get_attribute("data-state")
|
|
print(f"[{tag}] consent state: {checked}")
|
|
else:
|
|
print(f"[{tag}] no consent checkbox")
|
|
time.sleep(2)
|
|
for el in pg.query_selector_all("button"):
|
|
try:
|
|
t = (el.inner_text() or "").strip()[:25]
|
|
d = el.get_attribute("disabled")
|
|
print(f"[{tag}] btn: {t!r} disabled={d}")
|
|
except Exception:
|
|
pass
|
|
# wait for turnstile token
|
|
for _ in range(24):
|
|
t = pg.evaluate("()=>{const i=document.querySelector('input[name=cf-turnstile-response]');return i?i.value:''}")
|
|
if t and len(t) > 50:
|
|
break
|
|
time.sleep(1.5)
|
|
clicked = False
|
|
for el in pg.query_selector_all("button"):
|
|
try:
|
|
t = (el.inner_text() or "").lower()
|
|
if "create account" in t:
|
|
el.click()
|
|
clicked = True
|
|
print(f"[{tag}] clicked btn: {t.strip()[:30]}")
|
|
break
|
|
except Exception:
|
|
pass
|
|
if not clicked:
|
|
for el in pg.query_selector_all("button"):
|
|
try:
|
|
tp = (el.get_attribute("type") or "").lower()
|
|
if tp == "submit":
|
|
el.click()
|
|
clicked = True
|
|
break
|
|
except Exception:
|
|
pass
|
|
if not clicked:
|
|
pg.keyboard.press("Enter")
|
|
print(f"[{tag}] pressed Enter")
|
|
time.sleep(8)
|
|
signed = any("auth/signup" in u and s == 200 for s, m, u, b in events)
|
|
print(f"[{tag}] signup events:", [(s, u.split('camb.ai')[-1][:60]) for s, m, u, b in events if 'uservault' in u])
|
|
if not signed:
|
|
# maybe verify-code screen appeared anyway
|
|
pass
|
|
# --- verify code
|
|
code = mail_code(email, password, tag=tag)
|
|
print(f"[{tag}] code: {code}")
|
|
if not code:
|
|
return {"email": email, "password": pw, "error": "no_code"}
|
|
box = None
|
|
try:
|
|
pg.wait_for_selector("input[autocomplete='one-time-code'], input[maxlength='6']", timeout=30000)
|
|
box = pg.query_selector("input[autocomplete='one-time-code']") or pg.query_selector("input[maxlength='6']")
|
|
except Exception:
|
|
box = None
|
|
if not box:
|
|
return {"email": email, "password": pw, "error": "no_code_field"}
|
|
# --- verify code via direct PATCH (React OTP form sends empty value)
|
|
try:
|
|
vres = pg.evaluate("""async (code) => {
|
|
try {
|
|
const r = await fetch('https://client.camb.ai/uservault/auth/refresh-token',
|
|
{method:'POST', credentials:'include', headers:{'Content-Type':'application/json'}, body:'{}'});
|
|
const j = await r.json();
|
|
const jwt = (j.payload||{}).access_token || '';
|
|
if (!jwt) return 'NOJWT:'+r.status;
|
|
const rv = await fetch('https://client.camb.ai/uservault/users/verification/mail/verify?verification_code='+encodeURIComponent(code),
|
|
{method:'PATCH', credentials:'include', headers:{'Authorization':'Bearer '+jwt,'Content-Type':'application/json'}});
|
|
const jv = await rv.json();
|
|
return 'PATCH '+rv.status+' '+JSON.stringify(jv.payload||jv).slice(0,120);
|
|
} catch(e){ return 'ERR:'+e.message; }
|
|
}""", code)
|
|
print(f"[{tag}] verify: {vres}")
|
|
except Exception as e:
|
|
print(f"[{tag}] verify call failed: {str(e)[:80]}")
|
|
try:
|
|
vstat = pg.evaluate("""async () => {
|
|
try {
|
|
const r = await fetch('https://client.camb.ai/uservault/auth/refresh-token',
|
|
{method:'POST', credentials:'include', headers:{'Content-Type':'application/json'}, body:'{}'});
|
|
const j = await r.json();
|
|
const jwt = (j.payload||{}).access_token || '';
|
|
if (!jwt) return 'NOJWT:'+r.status;
|
|
const r2 = await fetch('https://client.camb.ai/uservault/users/me',
|
|
{credentials:'include', headers:{'Authorization':'Bearer '+jwt}});
|
|
const j2 = await r2.json();
|
|
const u = (j2.payload||{}).user || j2.payload || {};
|
|
return 'verified='+String(u.email_verified ?? u.is_email_verified ?? '?');
|
|
} catch(e){ return 'ERR:'+e.message; }
|
|
}""")
|
|
print(f"[{tag}] verify status: {vstat}")
|
|
for st, meth, url, body in events:
|
|
if "verification" in url or "verify" in url:
|
|
print(f"[{tag}] VER {st} {meth} {url.split('camb.ai')[-1][:60]} {body[:180]}")
|
|
except Exception as e:
|
|
print(f"[{tag}] verify probe failed: {str(e)[:60]}")
|
|
# --- skip onboarding questions
|
|
for _ in range(4):
|
|
el = pg.query_selector("text=Skip")
|
|
if not el:
|
|
break
|
|
el.click()
|
|
time.sleep(5)
|
|
# --- team id (URL after onboarding redirect, then fetch fallback)
|
|
try:
|
|
pg.goto("https://studio.camb.ai/workspace", wait_until="domcontentloaded", timeout=60000)
|
|
time.sleep(10)
|
|
except Exception:
|
|
pass
|
|
team_id = None
|
|
m = re.search(r"/workspace/(\d+)", pg.url)
|
|
if m:
|
|
team_id = int(m.group(1))
|
|
if not team_id:
|
|
team_id = pg.evaluate("""async () => {
|
|
try {
|
|
const r = await fetch('https://client.camb.ai/uservault/auth/refresh-token',
|
|
{method:'POST', credentials:'include', headers:{'Content-Type':'application/json'}, body:'{}'});
|
|
const j = await r.json();
|
|
const jwt = (j.payload||{}).access_token || '';
|
|
if (!jwt) return 'NOJWT:'+r.status;
|
|
const r2 = await fetch('https://client.camb.ai/v1/teams/',
|
|
{credentials:'include', headers:{'Authorization':'Bearer '+jwt}});
|
|
const j2 = await r2.json();
|
|
const teams = (j2.payload||{}).teams || j2.payload || [];
|
|
const t = teams[0] || {};
|
|
return t.id || t.team_id || ('NOTEAM:'+JSON.stringify(j2).slice(0,120));
|
|
} catch(e){ return 'ERR:'+e.message; }
|
|
}""")
|
|
print(f"[{tag}] team_id:", team_id, "url:", pg.url[:90])
|
|
if isinstance(team_id, str):
|
|
print(f"[{tag}] team debug: {team_id}")
|
|
team_id = None
|
|
if not team_id:
|
|
return {"email": email, "password": pw, "error": "no_team"}
|
|
rec = {"email": email, "password": pw, "team_id": team_id, "credits": 5000, "ts": int(time.time())}
|
|
return rec
|
|
|
|
|
|
def create_key(p, team_id, tag, attempts=3):
|
|
"""Fresh browser session (profile keeps cookies), open api-keys, create key."""
|
|
key = None
|
|
for att in range(attempts):
|
|
try:
|
|
chr.ensure(9242, r"C:\Users\User\tmp\camb\prof_farm")
|
|
time.sleep(4)
|
|
b = p.chromium.connect_over_cdp("http://127.0.0.1:9242")
|
|
ctx = b.contexts[0]
|
|
pg = ctx.new_page()
|
|
pg.goto(f"https://studio.camb.ai/workspace/{team_id}/api-keys", wait_until="domcontentloaded", timeout=60000)
|
|
time.sleep(14)
|
|
if "/public/onboarding" in pg.url:
|
|
print(f"[{tag}] create_key: not verified, at {pg.url}")
|
|
try:
|
|
pg.close()
|
|
except Exception:
|
|
pass
|
|
return None
|
|
tt = ""
|
|
got = []
|
|
def on_r(r):
|
|
try:
|
|
if "camb.ai" in r.url and ("api" in r.url.lower() or "key" in r.url.lower()):
|
|
body = ""
|
|
try:
|
|
if "json" in (r.headers.get("content-type") or ""):
|
|
body = r.text()[:800]
|
|
except Exception:
|
|
pass
|
|
got.append((r.status, r.request.method, r.url, body))
|
|
except Exception:
|
|
pass
|
|
pg.on("response", on_r)
|
|
for el in pg.query_selector_all("button"):
|
|
try:
|
|
if "create new api key" in (el.inner_text() or "").lower():
|
|
bb = el.bounding_box()
|
|
if bb:
|
|
pg.mouse.click(bb["x"] + bb["width"] / 2, bb["y"] + bb["height"] / 2)
|
|
tt = "clicked create"
|
|
break
|
|
except Exception:
|
|
pass
|
|
print(f"[{tag}] create_key att{att}: url={pg.url[:70]} {tt}")
|
|
time.sleep(6)
|
|
# name input: React controlled -> real keyboard events
|
|
nmv = "farm" + str(int(time.time()))[-4:]
|
|
inp = pg.query_selector("input[name=api-key-name]")
|
|
if inp:
|
|
bb = inp.bounding_box()
|
|
pg.mouse.click(bb["x"] + 20, bb["y"] + bb["height"] / 2)
|
|
time.sleep(0.4)
|
|
pg.keyboard.type(nmv, delay=80)
|
|
time.sleep(1.2)
|
|
print(f"[{tag}] name typed: {inp.input_value()}")
|
|
else:
|
|
print(f"[{tag}] name input missing")
|
|
time.sleep(1.5)
|
|
for el in pg.query_selector_all("button"):
|
|
try:
|
|
if "create secret key" in (el.inner_text() or "").lower():
|
|
bb = el.bounding_box()
|
|
if bb:
|
|
pg.mouse.click(bb["x"] + bb["width"] / 2, bb["y"] + bb["height"] / 2)
|
|
print(f"[{tag}] clicked create secret key dis={el.get_attribute('disabled')}")
|
|
break
|
|
except Exception:
|
|
pass
|
|
time.sleep(10)
|
|
for st, meth, url, body in got:
|
|
print(f"[{tag}] KEYEV {st} {meth} {url.split('camb.ai')[-1][:70]} {body[:220]}")
|
|
if not key:
|
|
for pat in (r'"api_key"\s*:\s*"([^"]{20,})"', r'"key"\s*:\s*"([^"]{20,})"',
|
|
r'"secret"\s*:\s*"([^"]{20,})"'):
|
|
m2 = re.search(pat, body)
|
|
if m2 and not m2.group(1).startswith("eyJ"):
|
|
key = m2.group(1)
|
|
break
|
|
if not key:
|
|
for el in pg.query_selector_all("input"):
|
|
try:
|
|
v = el.input_value()
|
|
if v and len(v) >= 30 and " " not in v.strip() and re.fullmatch(r"[A-Za-z0-9\-]+", v.strip()):
|
|
key = v.strip()
|
|
break
|
|
except Exception:
|
|
pass
|
|
if not key:
|
|
cands = pg.evaluate("""() => {
|
|
const out = [];
|
|
for (const el of document.querySelectorAll('input,textarea,code,pre,div,span,p')) {
|
|
let v = (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') ? (el.value || '') : (el.innerText || '');
|
|
v = (v || '').trim();
|
|
if (v.length >= 24 && v.length <= 120 && !v.includes(' ')) out.push(v);
|
|
}
|
|
return [...new Set(out)].slice(0, 30);
|
|
}""")
|
|
print(f"[{tag}] DOM cands:", cands[:6])
|
|
for c in cands:
|
|
if c.startswith("eyJ") or c.count(".") >= 2:
|
|
continue
|
|
if re.fullmatch(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}", c):
|
|
key = c
|
|
break
|
|
if re.fullmatch(r"[0-9a-fA-F]{32,48}", c):
|
|
key = c
|
|
break
|
|
try:
|
|
pg.close()
|
|
except Exception:
|
|
pass
|
|
if key:
|
|
break
|
|
except Exception as e:
|
|
print(f"[{tag}] create_key err att{att}", type(e).__name__, str(e)[:100])
|
|
kill_chrome(9242)
|
|
time.sleep(3)
|
|
print(f"[{tag}] api_key:", key)
|
|
return key
|
|
|
|
|
|
def kill_chrome(port):
|
|
import psutil
|
|
for pr in psutil.process_iter(["pid", "name", "cmdline"]):
|
|
try:
|
|
if pr.info["name"] and "chrome" in pr.info["name"].lower():
|
|
cl = " ".join(pr.info["cmdline"] or [])
|
|
if f"--remote-debugging-port={port}" in cl:
|
|
psutil.Process(pr.info["pid"]).kill()
|
|
except Exception:
|
|
pass
|
|
time.sleep(3)
|
|
|
|
|
|
def main():
|
|
mails = []
|
|
for line in open(MPOOL, encoding="utf-8", errors="ignore"):
|
|
line = line.strip()
|
|
if ":" in line and "@" in line:
|
|
e, p = line.split(":", 1)
|
|
mails.append((e.strip(), p.strip()))
|
|
print(f"pool: {len(mails)}")
|
|
kill_chrome(9242)
|
|
time.sleep(3)
|
|
with sync_playwright() as p:
|
|
for i in range(N):
|
|
email, mpass = mails[START + i]
|
|
tag = f"A{i}"
|
|
print(f"=== {tag} {email}")
|
|
try:
|
|
chr.ensure(9242, r"C:\Users\User\tmp\camb\prof_farm")
|
|
b = p.chromium.connect_over_cdp("http://127.0.0.1:9242")
|
|
main_ctx = b.contexts[0]
|
|
except Exception as e:
|
|
print(f"[{tag}] browser dead: {str(e)[:80]}")
|
|
rec = {"email": email, "error": f"browser:{str(e)[:80]}"}
|
|
with open(BANK, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(rec) + "\n")
|
|
time.sleep(20)
|
|
continue
|
|
try:
|
|
rec = one(main_ctx, email, mpass, tag)
|
|
except Exception as e:
|
|
print(f"[{tag}] FATAL", type(e).__name__, str(e)[:120])
|
|
rec = {"email": email, "error": f"fatal:{str(e)[:100]}"}
|
|
if rec and rec.get("team_id") and not rec.get("error"):
|
|
key = create_key(p, rec["team_id"], tag)
|
|
rec["api_key"] = key
|
|
if not key:
|
|
rec["error"] = "no_key"
|
|
else:
|
|
try:
|
|
r = requests.post("https://client.camb.ai/apis/tts-stream",
|
|
json={"text": "Test.", "language": "en-us", "voice_id": 147320,
|
|
"speech_model": "mars-flash", "output_configuration": {"format": "wav"}},
|
|
headers={"x-api-key": key}, stream=True, timeout=90)
|
|
rec["tts_check"] = r.status_code
|
|
rec["tts_credits"] = r.headers.get("x-credits-required")
|
|
print(f"[{tag}] tts check: {r.status_code} credits={rec['tts_credits']}")
|
|
r.close()
|
|
if r.status_code != 200:
|
|
rec["api_key"] = None
|
|
rec["error"] = f"bad_key:{r.status_code}"
|
|
except Exception as e:
|
|
rec["tts_check"] = f"err:{str(e)[:60]}"
|
|
if rec:
|
|
with open(BANK, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(rec) + "\n")
|
|
time.sleep(random.randint(20, 40))
|
|
print("DONE")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |