ctxdev autoreg v2: t-online flow, grant banner form, VPS IMAP read, proxy pool loop, dash login
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import json, os, re, subprocess, sys, time
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
MAIL = sys.argv[1]
|
||||
PW = sys.argv[2]
|
||||
PORT = os.environ.get("CTX_CDP_PORT", "9353")
|
||||
CDP = "http://127.0.0.1:%s" % PORT
|
||||
PROF = os.environ.get("CTX_CHROME_PROF", BASE + r"\chrome_ld1")
|
||||
PROXY = os.environ.get("CTX_CHROME_PROXY", "")
|
||||
|
||||
def log(*a, **kw):
|
||||
kw.setdefault("flush", True); print(*a, **kw)
|
||||
|
||||
def txt(pg, n=350):
|
||||
try: return pg.inner_text("body")[:n]
|
||||
except Exception: return ""
|
||||
|
||||
def click(pg, rx):
|
||||
for kind in ("button", "link"):
|
||||
try:
|
||||
el = pg.get_by_role(kind, name=re.compile(rx, re.I)).first
|
||||
if el.count() and el.is_visible(): el.click(); return True
|
||||
except Exception: pass
|
||||
return False
|
||||
|
||||
env2 = dict(os.environ); env2.update({"CTX_CDP_PORT": PORT, "CTX_CHROME_PROF": PROF, "CTX_CHROME_PROXY": PROXY})
|
||||
subprocess.run([sys.executable, os.path.join(BASE, "chrome_up.py")], check=False, env=env2)
|
||||
time.sleep(3)
|
||||
|
||||
with sync_playwright() as p:
|
||||
b = p.chromium.connect_over_cdp(CDP, timeout=90000)
|
||||
ctx = b.contexts[0]
|
||||
pg = ctx.new_page(); pg.set_default_timeout(50000)
|
||||
pg.goto("https://www.context.dev/login", timeout=90000, wait_until="domcontentloaded")
|
||||
time.sleep(8)
|
||||
log("login page:", txt(pg, 150).replace("\n", " "))
|
||||
em = pg.locator("input[type=email]").first
|
||||
em.click(); em.type(MAIL, delay=30)
|
||||
time.sleep(1)
|
||||
if not click(pg, "^continue$"):
|
||||
pg.keyboard.press("Enter")
|
||||
time.sleep(6)
|
||||
if pg.locator("input[type=password]").count() == 0:
|
||||
try:
|
||||
pg.locator("button[type=submit]").first.click(force=True)
|
||||
except Exception: pass
|
||||
time.sleep(5)
|
||||
log("after email:", txt(pg, 200).replace("\n", " "))
|
||||
pwf = pg.locator("input[type=password]").first
|
||||
for _ in range(15):
|
||||
if pwf.count(): break
|
||||
time.sleep(2)
|
||||
log("pw field:", pwf.count())
|
||||
if pwf.count() == 0:
|
||||
log("STEP1 FAIL")
|
||||
pg.close(); sys.exit(3)
|
||||
if pwf.count():
|
||||
pwf.click(); pwf.type(PW, delay=25)
|
||||
time.sleep(1)
|
||||
click(pg, "^sign in$|^continue$|^submit$|log in")
|
||||
for _ in range(14):
|
||||
time.sleep(4)
|
||||
if "/login" not in pg.url:
|
||||
break
|
||||
time.sleep(3)
|
||||
log("after pw:", txt(pg, 250).replace("\n", " "), "|", pg.url[:90])
|
||||
time.sleep(5)
|
||||
log("final:", txt(pg, 300).replace("\n", " "), "|", pg.url[:90])
|
||||
keys = pg.evaluate("""() => {
|
||||
const m = document.body.innerText.match(/ctxt_secret_[A-Za-z0-9]+/g);
|
||||
return m || null;
|
||||
}""")
|
||||
log("keys on page:", keys)
|
||||
pg.screenshot(path=os.path.join(BASE, "ld_final.png"))
|
||||
json.dump({"url": pg.url, "text": txt(pg, 1500), "keys": keys},
|
||||
open(os.path.join(BASE, "ld_state.json"), "w"), ensure_ascii=False, indent=1)
|
||||
pg.close()
|
||||
Reference in New Issue
Block a user