Files

204 lines
11 KiB
Python

import os, time, json, sys, random
sys.path.insert(0,"C:/Users/User/tmp/crowllm")
from playwright.sync_api import sync_playwright
BASE=os.environ.get("CROWL_DIR", os.getcwd())
BANK=os.environ.get("CROWL_BANK", os.path.join(BASE,"accounts.jsonl"))
OUT=os.environ.get("CROWL_OUT", os.path.join(BASE,"keys.jsonl"))
FOUT=os.environ.get("CROWL_FAIL", os.path.join(BASE,"fail.jsonl"))
_doms=os.environ.get("CROWL_DOMAINS","")
DOMS=[d.strip() for d in _doms.split(",") if d.strip()]
IDX=sys.argv[1] if len(sys.argv)>1 else "1"
PROF=os.environ.get("CROWL_PROFILE") or os.path.join(BASE,f"prof_{IDX}")
LOGF=os.environ.get("CROWL_LOG") or os.path.join(BASE,f"reg_{IDX}.log.txt")
log=open(LOGF,"a",encoding="utf-8")
def L(*a):
s=" ".join(str(x) for x in a)
log.write(s+"\n"); log.flush()
print(s.encode('ascii','replace').decode(), flush=True)
used=set()
for f in (OUT,FOUT):
try:
for l in open(f,encoding='utf-8'):
if l.strip():
j=json.loads(l)
if j.get('email'): used.add(j['email'])
except FileNotFoundError: pass
bank=[json.loads(l) for l in open(BANK,encoding='utf-8') if l.strip()]
cand=[b for b in bank if b['email'] not in used and (not DOMS or any(d in b['email'] for d in DOMS))]
if not cand: cand=[b for b in bank if b['email'] not in used]
if not cand:
L("NO CANDIDATES"); sys.exit(3)
acc=random.choice(cand); EMAIL,PW=acc['email'],acc['password']
L("ACC", EMAIL)
res={'email':EMAIL,'dom':EMAIL.split('@')[-1],'profile':PROF}
CHROME=os.environ.get("CROWL_CHROME")
if not CHROME or not os.path.exists(CHROME):
CHROME=None
for c in ["C:/Program Files/Google/Chrome/Application/chrome.exe",
"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe"),
"/usr/bin/google-chrome", "/usr/bin/chromium"]:
if c and os.path.exists(c): CHROME=c; break
if not CHROME:
raise SystemExit("Chrome not found - set CROWL_CHROME")
def ev(pg, expr, default=None, tries=3, wait=1.0):
for i in range(tries):
try: return pg.evaluate(expr)
except Exception: time.sleep(wait)
return default
def live(ctx): return [x for x in ctx.pages if not x.is_closed()]
def gpage(ctx):
for x in live(ctx):
try:
if "accounts.google.com" in x.url: return x
except Exception: pass
return None
GOOGLE_BTN_JS="() => { const bs=[...document.querySelectorAll('button')]; const g=bs.find(b=>(b.innerText||'').includes('Google')); if(!g) return null; const r=g.getBoundingClientRect(); return [r.x+r.width/2, r.y+r.height/2]; }"
CONSENT_JS=("() => { const want=['continue','allow']; const nodes=[...document.querySelectorAll('button,[role=button],span[jsname],input[type=submit]')];"
" const el=nodes.find(e=>{const t=((e.innerText||e.getAttribute('aria-label')||'')+'').trim().toLowerCase(); const r=e.getBoundingClientRect();"
" return r.width>40&&r.height>18&&r.width<500&&want.some(w=>t===w||t.startsWith(w));});"
" if(el){const r=el.getBoundingClientRect(); return [r.x+r.width/2,r.y+r.height/2,'direct']}"
" const c=[...document.querySelectorAll('div')].find(e=>{const t=(e.innerText||'').toLowerCase(); const r=e.getBoundingClientRect();"
" return t.includes('cancel')&&t.includes('continue')&&r.height<90&&r.height>20&&r.width<950;});"
" if(c){const r=c.getBoundingClientRect(); return [r.x+r.width*0.85,r.y+r.height/2,'zone']}"
" return null }")
BODY_JS="() => document.body.innerText.replace(/\\n/g,' | ').slice(0,400)"
with sync_playwright() as p:
ctx=p.chromium.launch_persistent_context(user_data_dir=PROF, headless=False, executable_path=CHROME,
args=["--disable-blink-features=AutomationControlled","--no-first-run","--no-default-browser-check",
"--disable-dev-shm-usage","--disable-popup-blocking"],
viewport={"width":1280,"height":900}, ignore_default_args=["--enable-automation"])
pg=live(ctx)[0]
pg.goto("https://crowllm.com/sign-up?aff=ezPS", wait_until="domcontentloaded", timeout=90000)
try: pg.wait_for_selector('span[role=checkbox][data-slot=checkbox]', state="visible", timeout=45000)
except Exception as e:
L("noform", str(e)[:60]); res['stage']='no_form'
if res.get('stage') is None:
t=0
for i in range(45):
t=ev(pg, "() => { const e=document.querySelector('input[name=cf-turnstile-response]'); return e?e.value.length:0 }", 0) or 0
if t>50: break
time.sleep(2)
L("ts", t)
pg.locator('span[role=checkbox][data-slot=checkbox]').first.click(force=True, timeout=10000)
time.sleep(0.8)
rs=ev(pg, GOOGLE_BTN_JS); L("grect", rs)
gp=None
for attempt in range(4):
if rs:
try:
pg.mouse.move(rs[0]-40, rs[1]-8); time.sleep(0.2)
pg.mouse.click(rs[0], rs[1]); L("gclick", attempt)
except Exception as e: L("mouse err", str(e)[:60])
time.sleep(4)
gp=gpage(ctx)
if gp is None and "accounts.google" in pg.url: gp=pg
if gp is not None: break
rs=ev(pg, GOOGLE_BTN_JS)
if gp is None:
res['stage']='no_google_page'
else:
ok=False
for i in range(12):
try:
loc=gp.locator("input[name=identifier]").first
if loc.count()>0: loc.fill(EMAIL, timeout=10000); ok=True; break
except Exception: pass
time.sleep(1.5)
L("emailfill", ok)
if not ok: res['stage']='no_email_field'
else:
time.sleep(0.7)
ev(gp, "() => { const b=document.querySelector('#identifierNext button')||document.querySelector('#identifierNext'); if(b) b.click(); return 1 }")
pwok=False
for i in range(20):
time.sleep(2)
u=gp.url
if "deletedaccount" in u or "rejected" in u: res['stage']='account_dead'; break
try:
pw=gp.locator("input[name=Passwd]").first
if pw.count()>0 and pw.is_visible(): pwok=True; break
except Exception: pass
L("pwok", pwok)
if res.get('stage') is None and pwok:
try: gp.locator("input[name=Passwd]").first.fill(PW, timeout=12000); pok=True
except Exception: pok=False
if pok:
time.sleep(0.7)
ev(gp, "() => { const b=document.querySelector('#passwordNext button')||document.querySelector('#passwordNext'); if(b) b.click(); return 1 }")
clicked=0
for i in range(45):
time.sleep(2)
host=gp.url.split("/")[2] if "://" in gp.url else ""
if host.endswith("crowllm.com"):
L("landed", gp.url[:70]); break
b=ev(gp, BODY_JS, "") or ""
low=b.lower()
if not b.strip(): continue
if "2-step" in low or "verify it" in low:
res['stage']='needs_2fa'; break
cr=None
try: cr=gp.evaluate(CONSENT_JS)
except Exception: pass
if cr and (clicked==0 or i%5==0):
clicked+=1
try:
gp.mouse.move(cr[0]-30, cr[1]-4); time.sleep(0.15)
gp.mouse.click(cr[0], cr[1])
except Exception: pass
L("g3", gp.url[:70])
else: res['stage']='pw_fill_fail'
elif res.get('stage') is None: res['stage']='no_pw_field'
# collect via refresh cookie (new-api access token)
tgt=None
for x in live(ctx):
try:
if "crowllm.com" in x.url: tgt=x; break
except Exception: pass
if tgt is None:
res['stage']=res.get('stage') or 'no_crowllm_page'
else:
time.sleep(5)
got=ev(tgt, """async () => {
const out={};
let rr=await fetch('/api/user/auth/refresh',{method:'POST',credentials:'include'});
out.refresh=rr.status;
let tok=null;
try { const j=await rr.json(); tok=(j.data&&(j.data.access_token||j.data.token))||j.access_token||null } catch(e){}
if(!tok){ try { rr=await fetch('/api/user/auth/refresh',{method:'POST',credentials:'include'}); const j=await rr.json(); tok=(j.data&&(j.data.access_token||j.data.token))||null } catch(e){} }
if(!tok) { out.err='no access token'; return out }
const h={'Content-Type':'application/json','Authorization':'Bearer '+tok};
const me=await (await fetch('/api/user/self',{credentials:'include',headers:h})).json();
const d=me.data||{};
out.uid=d.id; out.quota=d.quota; out.earned=d.earned_quota; out.used=d.used_quota; out.username=d.username; out.aff=d.aff_code;
await fetch('/api/token/',{method:'POST',credentials:'include',headers:h,body:JSON.stringify({name:'auto',remain_quota:0,expired_time:-1,unlimited_quota:true,model_limits_enabled:false,model_limits:'',allow_ips:'',group:''})});
const ls=await (await fetch('/api/token/?p=1&size=10',{credentials:'include',headers:h})).json();
const t=(ls.data&&ls.data.items&&ls.data.items[0])||null;
if(!t){ out.err='no token row'; out.raw=JSON.stringify(ls).slice(0,200); return out }
const kb=await (await fetch('/api/token/'+t.id+'/key',{method:'POST',credentials:'include',headers:h})).json();
out.tid=t.id; out.key=kb.data; out.toklen=tok.length;
return out;
}""", None, tries=2)
L("GOT", json.dumps(got, ensure_ascii=False)[:500] if got else "None")
if got and got.get('key'):
key=got['key']
if isinstance(key,dict): key=key.get('key')
key=str(key).strip("'\"")
open(OUT,"a",encoding="utf-8").write(json.dumps({'email':EMAIL,'password':PW,'uid':got.get('uid'),
'quota':got.get('quota'),'earned':got.get('earned'),'key':key,'profile':PROF,'time':int(time.time())},ensure_ascii=False)+"\n")
res['uid']=got.get('uid'); res['has_key']=True
L("SAVED keylen", len(key), "uid", got.get('uid'), "quota", got.get('quota'), "earned", got.get('earned'))
else:
res['stage']=res.get('stage') or 'no_key'
try: ctx.close()
except Exception: pass
if not res.get('has_key'):
open(FOUT,"a",encoding="utf-8").write(json.dumps(res,ensure_ascii=False)+"\n")
L("RESULT", json.dumps(res, ensure_ascii=False)[:250])
L("DONE")