recovered snapshot from suspended aaronjaworski710 (history unavailable)
This commit is contained in:
+364
@@ -0,0 +1,364 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
TokenHarbor auto-reg v2 — Playwright stealth + proxy + API key creation.
|
||||
Full flow: signup → verify email (IMAP) → claim $5 → create API key → push to gateway.
|
||||
"""
|
||||
# __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, re, ssl, sys, random, os
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import imaplib
|
||||
import email as em
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import urlopen, Request
|
||||
|
||||
# Add playwright
|
||||
sys.path.insert(0, str(_REPO))
|
||||
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = str(_w("tmp/playwright_pkg/playwright/driver/package/.local-browsers"))
|
||||
from playwright.sync_api import sync_playwright
|
||||
# Account passwords live in <project root>/.env (gitignored). Guarded import:
|
||||
# python-dotenv is not a declared dependency of these standalone scripts.
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env"))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
# ── CONFIG ──
|
||||
PASSWORD = os.environ["TOKENHARBOR_PASSWORD"]
|
||||
GATEWAY_URL = "https://gateway.example.com/th"
|
||||
GATEWAY_KEY = os.environ.get("TH_GATEWAY_KEY", "")
|
||||
POOL_FILE = Path(str(_d("Downloads/Telegram Desktop/working_mails.txt","MAIL_POOL")))
|
||||
KEYS_FILE = Path(str(_d("Desktop/авторег проект/tokenharbor_keys.txt")))
|
||||
STATE_FILE = Path(str(_d("Desktop/авторег проект/th_stealth_state.json")))
|
||||
|
||||
# Proxy pool — bpproxy residential hardsessions
|
||||
PROXY_POOL_FILE = Path(str(_d("tmp/bpproxy_hardsession_pool.txt")))
|
||||
PROXY_POOL = []
|
||||
def load_proxy_pool():
|
||||
global PROXY_POOL
|
||||
PROXY_POOL = []
|
||||
if PROXY_POOL_FILE.exists():
|
||||
with open(PROXY_POOL_FILE) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line.startswith("http://"):
|
||||
_parsed = urlparse(line)
|
||||
PROXY_POOL.append({
|
||||
"server": f"http://{_parsed.hostname}:{_parsed.port}",
|
||||
"username": _parsed.username,
|
||||
"password": _parsed.password,
|
||||
})
|
||||
if not PROXY_POOL:
|
||||
# Fallback: direct connection (no proxy)
|
||||
PROXY_POOL.append({"server": "direct://", "username": None, "password": None})
|
||||
print("WARNING: No proxies — using DIRECT connection", flush=True)
|
||||
else:
|
||||
print(f"Loaded {len(PROXY_POOL)} proxies", flush=True)
|
||||
|
||||
def get_proxy():
|
||||
"""Rotate proxy — pick next one from pool."""
|
||||
if not PROXY_POOL:
|
||||
load_proxy_pool()
|
||||
proxy = PROXY_POOL.pop(0)
|
||||
PROXY_POOL.append(proxy) # round-robin
|
||||
return proxy
|
||||
|
||||
# ── HELPERS ──
|
||||
def load_state():
|
||||
if STATE_FILE.exists():
|
||||
try: return json.loads(STATE_FILE.read_text())
|
||||
except: pass
|
||||
return {"done": [], "fail": [], "keys": []}
|
||||
|
||||
def save_state(state):
|
||||
STATE_FILE.write_text(json.dumps(state, indent=2, default=str))
|
||||
|
||||
def push_key(api_key):
|
||||
try:
|
||||
data = json.dumps({"provider": "tokenharbor", "key": api_key}).encode()
|
||||
req = Request(
|
||||
f"{GATEWAY_URL}/provider/add?provider=tokenharbor",
|
||||
data=data,
|
||||
headers={"Content-Type": "application/json", "Authorization": f"Bearer {GATEWAY_KEY}"},
|
||||
method="POST",
|
||||
)
|
||||
resp = urlopen(req, timeout=10)
|
||||
return json.loads(resp.read()), resp.status
|
||||
except Exception as e:
|
||||
return {"error": str(e)}, 500
|
||||
|
||||
def wait_for_verify_email(email_addr, email_pass, timeout=30):
|
||||
ctx = ssl.create_default_context()
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
try:
|
||||
import socket
|
||||
socket.setdefaulttimeout(15)
|
||||
mail = imaplib.IMAP4_SSL("secureimap.t-online.de", 993, ssl_context=ctx, timeout=15)
|
||||
mail.login(email_addr, email_pass)
|
||||
mail.select("INBOX")
|
||||
except Exception as e:
|
||||
print(f" IMAP error: {e}", flush=True)
|
||||
return None
|
||||
|
||||
status, baseline = mail.search(None, 'ALL')
|
||||
known_ids = set(baseline[0].split()) if baseline[0] else set()
|
||||
start = time.time()
|
||||
|
||||
while time.time() - start < timeout:
|
||||
try:
|
||||
mail.select("INBOX")
|
||||
status, data = mail.search(None, 'ALL')
|
||||
if status == "OK" and data[0]:
|
||||
new_ids = set(data[0].split()) - known_ids
|
||||
for mid in sorted(new_ids, reverse=True):
|
||||
status, msg_data = mail.fetch(mid, "(RFC822)")
|
||||
if status != "OK": continue
|
||||
msg = em.message_from_bytes(msg_data[0][1])
|
||||
body_text = ""
|
||||
if msg.is_multipart():
|
||||
for part in msg.walk():
|
||||
if part.get_content_type() in ("text/plain", "text/html"):
|
||||
payload = part.get_payload(decode=True)
|
||||
if payload: body_text += payload.decode("utf-8", errors="replace")
|
||||
else:
|
||||
payload = msg.get_payload(decode=True)
|
||||
if payload: body_text = payload.decode("utf-8", errors="replace")
|
||||
|
||||
if "tokenharbor" in body_text.lower() and "verify" in body_text.lower():
|
||||
links = re.findall(r'https://tokenharbor\.ai/verify-email\?token=[^\s"<>]+', body_text)
|
||||
if links:
|
||||
mail.logout()
|
||||
return links[0]
|
||||
time.sleep(3)
|
||||
except:
|
||||
time.sleep(5)
|
||||
try: mail.logout()
|
||||
except: pass
|
||||
return None
|
||||
|
||||
# ── MAIN ──
|
||||
def process_one(email, email_pass, state):
|
||||
label = email.split("@")[0][:15]
|
||||
print(f"\n[{label}] Starting...", flush=True)
|
||||
|
||||
with sync_playwright() as p:
|
||||
proxy = get_proxy()
|
||||
is_direct = proxy["server"] == "direct://"
|
||||
print(f" [{label}] Proxy: {'DIRECT' if is_direct else proxy['server']}", flush=True)
|
||||
launch_args = {"headless": False, "args": ["--disable-blink-features=AutomationControlled", "--no-sandbox"]}
|
||||
if not is_direct:
|
||||
launch_args["proxy"] = proxy
|
||||
browser = p.chromium.launch(**launch_args)
|
||||
context = browser.new_context(
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36",
|
||||
viewport={"width": 1280, "height": 800},
|
||||
)
|
||||
page = context.new_page()
|
||||
page.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined});")
|
||||
|
||||
api_key = None
|
||||
error = None
|
||||
|
||||
try:
|
||||
# ── STEP 1: Login first (if already registered), else signup ──
|
||||
print(f" [{label}] Login...", flush=True)
|
||||
page.goto("https://tokenharbor.ai/login", wait_until="networkidle", timeout=30000)
|
||||
time.sleep(2)
|
||||
page.fill("input[type='email']", email)
|
||||
page.fill("input[type='password']", PASSWORD)
|
||||
time.sleep(1)
|
||||
page.press("input[type='password']", "Enter")
|
||||
time.sleep(6)
|
||||
|
||||
body = page.inner_text("body")
|
||||
if "BALANCE" in body:
|
||||
print(f" [{label}] Already registered, logged in!", flush=True)
|
||||
else:
|
||||
# Login failed — try signup
|
||||
print(f" [{label}] Not registered, signing up...", flush=True)
|
||||
page.goto("https://tokenharbor.ai/login", wait_until="networkidle", timeout=30000)
|
||||
time.sleep(2)
|
||||
page.click("button:has-text('Sign up')")
|
||||
time.sleep(2)
|
||||
page.fill("input[type='email']", email)
|
||||
time.sleep(1)
|
||||
page.fill("input[type='password']", PASSWORD)
|
||||
time.sleep(random.uniform(2, 4))
|
||||
page.click("button:has-text('Create account')")
|
||||
time.sleep(8)
|
||||
|
||||
body = page.inner_text("body")
|
||||
|
||||
if "too fast" in body.lower() or "breath" in body.lower():
|
||||
print(f" [{label}] Rate limited (speed)", flush=True)
|
||||
return None, "rate_limited_speed"
|
||||
|
||||
if "too many" in body.lower():
|
||||
print(f" [{label}] Rate limited (IP)", flush=True)
|
||||
return None, "rate_limited_ip"
|
||||
|
||||
if "BALANCE" not in body:
|
||||
print(f" [{label}] Signup failed", flush=True)
|
||||
return None, "signup_failed"
|
||||
|
||||
print(f" [{label}] Signed up!", flush=True)
|
||||
page.keyboard.press("Escape")
|
||||
time.sleep(1)
|
||||
|
||||
# ── STEP 2: Verify email ──
|
||||
page.goto("https://tokenharbor.ai/dashboard", wait_until="networkidle", timeout=15000)
|
||||
time.sleep(3)
|
||||
page.keyboard.press("Escape")
|
||||
time.sleep(1)
|
||||
body = page.inner_text("body")
|
||||
|
||||
if "verify your email" in body.lower():
|
||||
print(f" [{label}] Sending verification...", flush=True)
|
||||
try:
|
||||
page.click("button:has-text('Verify email')", force=True, timeout=5000)
|
||||
except:
|
||||
pass
|
||||
time.sleep(5)
|
||||
|
||||
verify_link = wait_for_verify_email(email, email_pass)
|
||||
if verify_link:
|
||||
page.goto(verify_link, wait_until="networkidle", timeout=15000)
|
||||
time.sleep(3)
|
||||
print(f" [{label}] Email verified!", flush=True)
|
||||
else:
|
||||
print(f" [{label}] No verify email received", flush=True)
|
||||
else:
|
||||
print(f" [{label}] No verification needed", flush=True)
|
||||
|
||||
# ── STEP 3: Claim $5 ──
|
||||
page.goto("https://tokenharbor.ai/dashboard", wait_until="networkidle", timeout=15000)
|
||||
time.sleep(4)
|
||||
page.keyboard.press("Escape")
|
||||
time.sleep(1)
|
||||
body = page.inner_text("body")
|
||||
|
||||
if "gift" in body.lower() and "claim" in body.lower():
|
||||
print(f" [{label}] Claiming $5...", flush=True)
|
||||
try:
|
||||
page.click("button:has-text('gift')", force=True, timeout=5000)
|
||||
time.sleep(2)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
page.click("button:has-text('Claim')", force=True, timeout=5000)
|
||||
time.sleep(5)
|
||||
print(f" [{label}] $5 claimed!", flush=True)
|
||||
except Exception as e:
|
||||
print(f" [{label}] Claim error: {e}", flush=True)
|
||||
|
||||
# ── STEP 4: Create API key ──
|
||||
print(f" [{label}] Creating API key...", flush=True)
|
||||
result = page.evaluate("""(label) => {
|
||||
return fetch('/api/keys', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({label: label})
|
||||
}).then(r => r.json());
|
||||
}""", label)
|
||||
|
||||
if "plaintext" in result:
|
||||
api_key = result["plaintext"]
|
||||
print(f" [{label}] KEY: {api_key}", flush=True)
|
||||
|
||||
# Save to file
|
||||
with open(KEYS_FILE, "a", encoding="utf-8") as f:
|
||||
f.write(f"{email} | {api_key} | {datetime.now().isoformat()}\n")
|
||||
|
||||
# Push to gateway
|
||||
gw_result, gw_status = push_key(api_key)
|
||||
print(f" [{label}] Gateway: {gw_result.get('status', gw_result)}", flush=True)
|
||||
else:
|
||||
print(f" [{label}] Key creation failed: {result}", flush=True)
|
||||
error = "no_key"
|
||||
|
||||
except Exception as e:
|
||||
print(f" [{label}] ERROR: {e}", flush=True)
|
||||
error = str(e)[:100]
|
||||
finally:
|
||||
browser.close()
|
||||
|
||||
return api_key, error
|
||||
|
||||
|
||||
def main(count=1):
|
||||
load_proxy_pool()
|
||||
state = load_state()
|
||||
done_set = set(state.get("done", []))
|
||||
fail_set = set(
|
||||
item["email"] if isinstance(item, dict) else item for item in state.get("fail", [])
|
||||
)
|
||||
|
||||
# Load pool
|
||||
pool = []
|
||||
with open(POOL_FILE, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if ":" in line and "@" in line:
|
||||
parts = line.strip().split(":", 1)
|
||||
if len(parts) == 2:
|
||||
eml, pwd = parts
|
||||
if "t-online.de" in eml and eml not in done_set and eml not in fail_set:
|
||||
pool.append((eml, pwd))
|
||||
|
||||
pool = pool[:count]
|
||||
print(f"Processing {len(pool)} accounts...", flush=True)
|
||||
|
||||
for i, (eml, pwd) in enumerate(pool):
|
||||
key, err = process_one(eml, pwd, state)
|
||||
|
||||
state = load_state()
|
||||
if key:
|
||||
state.setdefault("done", []).append(eml)
|
||||
state.setdefault("keys", []).append(key)
|
||||
else:
|
||||
state.setdefault("fail", []).append({"email": eml, "error": err or "unknown"})
|
||||
save_state(state)
|
||||
|
||||
if i < len(pool) - 1:
|
||||
delay = random.uniform(300, 420)
|
||||
print(f" Waiting {delay:.0f}s...", flush=True)
|
||||
time.sleep(delay)
|
||||
|
||||
state = load_state()
|
||||
print(f"\nDone: {len(state.get('done', []))}, Fail: {len(state.get('fail', []))}, Keys: {len(state.get('keys', []))}", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = int(sys.argv[1]) if len(sys.argv) > 1 else 1
|
||||
main(n)
|
||||
Reference in New Issue
Block a user