Repository navigation
fix(review): 28 verified bugs across gateway, pool, generator and GUI #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f468b54
2fd51a3
bdb10ff
4192aa8
2d707eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import sys | ||
|
|
||
| from plan_check import get_zcode_jwt, get_plan, is_start_plan, DEVICE_MID | ||
| import plan_check | ||
|
|
||
| HERE = os.path.dirname(os.path.abspath(__file__)) | ||
| # destination for exported snapshots; override per machine (or copy the | ||
|
|
@@ -99,48 +100,54 @@ def main(): | |
| print(f"candidate accounts: {len(accounts)}") | ||
| os.makedirs(GATEWAY_ACCOUNTS, exist_ok=True) | ||
| exported = 0 | ||
| failed = 0 | ||
| for email, chat_token in accounts: | ||
| print(f"\n=== {email} ===") | ||
| zjwt = get_zcode_jwt(chat_token, log=lambda *a: print(' ', *a)) | ||
| if not zjwt: | ||
| print(" no zcodeJWT — skip") | ||
| continue | ||
| plan = get_plan(zjwt) | ||
| if not plan: | ||
| print(" no plan data — skip") | ||
| continue | ||
| starter = plan.get('starter') | ||
| referral = plan.get('referral') | ||
| print(f" plans={plan.get('plans')} starter={starter} referral={referral}") | ||
| if not (starter or referral or export_all): | ||
| continue | ||
| payload = jwt_payload(zjwt) | ||
| ident = payload.get('user_id') or payload.get('sub') or email | ||
| plans_list = plan.get('plans') or [] | ||
| chosen_plan = next((p for p in plans_list if is_start_plan(p)), | ||
| plans_list[0] if plans_list else '') | ||
| fields = { | ||
| 'captured_at': datetime.datetime.now(datetime.timezone.utc).isoformat(), | ||
| 'source': 'ZCODEAUTO chat.z.ai signup (OAuth CLI)', | ||
| 'account_id': ident, | ||
| 'email': email, | ||
| 'name': '', | ||
| 'device_mid': DEVICE_MID, | ||
| 'plan': chosen_plan, | ||
| 'access_token': zjwt, | ||
| } | ||
| if payload.get('exp'): | ||
| fields['expires_at'] = str(payload['exp']) | ||
| fields['expires_at_ms'] = str(int(payload['exp']) * 1000) | ||
| else: | ||
| fields['expires_at_ms'] = '0' | ||
| # drop empty values so the file matches ZcodeGate's own output exactly | ||
| fields = {k: v for k, v in fields.items() if v != ''} | ||
| dest = os.path.join(GATEWAY_ACCOUNTS, safe_name(email)) | ||
| write_snapshot(dest, fields) | ||
| exported += 1 | ||
| print(f" -> wrote {dest}") | ||
| print(f"\nexported {exported} account(s) to {GATEWAY_ACCOUNTS}") | ||
| try: | ||
| zjwt = get_zcode_jwt(chat_token, log=lambda *a: print(' ', *a)) | ||
| if not zjwt: | ||
| print(" no zcodeJWT — skip") | ||
| continue | ||
| plan = get_plan(zjwt) | ||
| if not plan: | ||
| print(" no plan data — skip") | ||
| continue | ||
| starter = plan.get('starter') | ||
| referral = plan.get('referral') | ||
| print(f" plans={plan.get('plans')} starter={starter} referral={referral}") | ||
| if not (starter or referral or export_all): | ||
| continue | ||
| payload = jwt_payload(zjwt) | ||
| ident = payload.get('user_id') or payload.get('sub') or email | ||
| plans_list = plan.get('plans') or [] | ||
| chosen_plan = next((p for p in plans_list if is_start_plan(p)), | ||
| plans_list[0] if plans_list else '') | ||
| fields = { | ||
| 'captured_at': datetime.datetime.now(datetime.timezone.utc).isoformat(), | ||
| 'source': 'ZCODEAUTO chat.z.ai signup (OAuth CLI)', | ||
| 'account_id': ident, | ||
| 'email': email, | ||
| 'name': '', | ||
| 'device_mid': plan_check.per_account_device_mid(zjwt) or DEVICE_MID, | ||
| 'plan': chosen_plan, | ||
| 'access_token': zjwt, | ||
| } | ||
| if payload.get('exp'): | ||
| fields['expires_at'] = str(payload['exp']) | ||
| fields['expires_at_ms'] = str(int(payload['exp']) * 1000) | ||
| else: | ||
| fields['expires_at_ms'] = '0' | ||
| # drop empty values so the file matches ZcodeGate's own output exactly | ||
| fields = {k: v for k, v in fields.items() if v != ''} | ||
| dest = os.path.join(GATEWAY_ACCOUNTS, safe_name(email)) | ||
| write_snapshot(dest, fields) | ||
| exported += 1 | ||
| print(f" -> wrote {dest}") | ||
| except Exception as e: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The exit status ignores Prompt for AI agents |
||
| failed += 1 | ||
| print(f" failed ({type(e).__name__}: {e}) — skip") | ||
| print(f"\nexported {exported} account(s) to {GATEWAY_ACCOUNTS}" | ||
| + (f" ({failed} failed)" if failed else "")) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |||||||||
| sys.stderr.reconfigure(encoding='utf-8', errors='replace') | ||||||||||
|
|
||||||||||
| from utils import BROWSER_ARGS | ||||||||||
| from plan_check import APP_VERSION, _request, direct_requests | ||||||||||
| from plan_check import APP_VERSION, _request, client_timezone, direct_requests | ||||||||||
|
|
||||||||||
| # NOTE: playwright is imported lazily inside claim_invite(). The referral | ||||||||||
| # helpers below (referral_summary / send_one_message) are imported by the | ||||||||||
|
|
@@ -502,6 +502,27 @@ def _proxies(): | |||||||||
| return {'http': raw, 'https': raw} | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _pw_proxy(proxy_url): | ||||||||||
| """Playwright proxy dict for `proxy_url`, or None for a direct connection. | ||||||||||
|
|
||||||||||
| A portless value (socks5://1.2.3.4) would otherwise become | ||||||||||
| "socks5://1.2.3.4:None" and Chromium refuses to launch — same guard as | ||||||||||
| main.pw_proxy(). Credentials travel as separate fields: Chromium drops | ||||||||||
| them from 'server' alone and then shows an auth popup. | ||||||||||
| """ | ||||||||||
| if not proxy_url: | ||||||||||
| return None | ||||||||||
| from urllib.parse import urlparse | ||||||||||
| u = urlparse(proxy_url) | ||||||||||
| if not u.hostname or not u.port: | ||||||||||
| return None | ||||||||||
| d = {'server': f"{u.scheme or 'http'}://{u.hostname}:{u.port}"} | ||||||||||
| if u.username: | ||||||||||
| d['username'] = u.username | ||||||||||
| d['password'] = u.password or '' | ||||||||||
| return d | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _direct_proxy_while(fn): | ||||||||||
| """Run `fn` with direct mode when force_direct=True; always restore.""" | ||||||||||
| import functools | ||||||||||
|
|
@@ -539,7 +560,6 @@ def per_account_device_mid(token: str) -> str: | |||||||||
| 'http-referer': 'https://zcode.z.ai', | ||||||||||
| 'user-agent': 'ZCode/' + APP_VERSION, | ||||||||||
| 'x-client-language': 'en-US', | ||||||||||
| 'x-client-timezone': 'Asia/Tehran', | ||||||||||
| 'x-device-mid': '58aca3b3-3239-4cb7-9c70-df3e5488fb99', | ||||||||||
| 'x-os-category': 'windows', | ||||||||||
| 'x-os-version': '10.0.26200', | ||||||||||
|
|
@@ -577,12 +597,15 @@ def report_login_device(zjwt: str, user_id: str = None, device_mid: str = None, | |||||||||
| mid = device_mid or per_account_device_mid(zjwt) | ||||||||||
| h = dict(APP_HEADERS) | ||||||||||
| h['authorization'] = 'Bearer ' + zjwt | ||||||||||
| h['x-client-timezone'] = client_timezone() | ||||||||||
| if mid: | ||||||||||
| h['x-device-mid'] = mid | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||||||||||
| endpoint = 'https://zcode.z.ai/api/v1/event/report' | ||||||||||
|
|
||||||||||
| # 1. app_login_ck | ||||||||||
| body_ck = { | ||||||||||
| 'event_id': str(_uuid.uuid4()), | ||||||||||
| 'client_timezone': 'Asia/Tehran', | ||||||||||
| 'client_timezone': client_timezone(), | ||||||||||
| 'client_language': 'en-US', | ||||||||||
| 'element_name': 'app_login_ck', | ||||||||||
| 'event_region': 'app', | ||||||||||
|
|
@@ -608,7 +631,7 @@ def report_login_device(zjwt: str, user_id: str = None, device_mid: str = None, | |||||||||
| # 2. app_login_success (the critical event that credits login_device) | ||||||||||
| body_success = { | ||||||||||
| 'event_id': str(_uuid.uuid4()), | ||||||||||
| 'client_timezone': 'Asia/Tehran', | ||||||||||
| 'client_timezone': client_timezone(), | ||||||||||
| 'client_language': 'en-US', | ||||||||||
| 'element_name': 'app_login_success', | ||||||||||
| 'event_region': 'app_profile', | ||||||||||
|
|
@@ -667,6 +690,10 @@ def device_login(chat_token, log=print, force_direct: bool = False): | |||||||||
| poll_token = secrets.token_hex(32) | ||||||||||
| h = dict(APP_HEADERS) | ||||||||||
| h['authorization'] = 'Bearer ' + poll_token | ||||||||||
| h['x-client-timezone'] = client_timezone() | ||||||||||
| mid = per_account_device_mid(chat_token) | ||||||||||
| if mid: | ||||||||||
| h['x-device-mid'] = mid | ||||||||||
| # zcode.z.ai answers 502 in bursts; init is idempotent (it just opens a | ||||||||||
| # new flow), so a few quick retries beat aborting the whole login | ||||||||||
| r = None | ||||||||||
|
|
@@ -848,19 +875,13 @@ def claim_invite(chat_token: str, invite_code: str = 'MT9GNDQ8', log=print, | |||||||||
| viewport={'width': 1280, 'height': 820}, user_agent=UA, | ||||||||||
| locale='en-US', timezone_id='America/New_York') | ||||||||||
| _px = _proxies() | ||||||||||
| if _px and _px.get('https'): | ||||||||||
| # embedded credentials (http://user:pass@host:port) must be split | ||||||||||
| # into separate fields — Chromium drops them from 'server' alone | ||||||||||
| # and then shows an auth popup (net::ERR_INVALID_AUTH_CREDENTIALS) | ||||||||||
| from urllib.parse import urlparse | ||||||||||
| _u = urlparse(_px['https']) | ||||||||||
| _pd = {'server': f"{_u.scheme or 'http'}://{_u.hostname}:{_u.port}"} | ||||||||||
| if _u.username: | ||||||||||
| _pd['username'] = _u.username | ||||||||||
| _pd['password'] = _u.password or '' | ||||||||||
| _pd = _pw_proxy((_px or {}).get('https')) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Rejecting a portless proxy launches Chromium directly but still fingerprints it with that proxy URL. Pass only the validated Prompt for AI agents |
||||||||||
| if _pd: | ||||||||||
| launch_kwargs['proxy'] = _pd | ||||||||||
| elif force_direct: | ||||||||||
| log(' invite: direct mode — claiming on the real IP') | ||||||||||
| elif _px and _px.get('https'): | ||||||||||
| log(' invite: proxy has no host:port — launching direct') | ||||||||||
|
Comment on lines
+883
to
+884
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: When a proxy is configured but has no host:port, the browser claim now launches on the real IP instead of failing. Raise an error here so the claim aborts rather than leaking the home IP. Prompt for AI agents
Suggested change
|
||||||||||
|
|
||||||||||
| import fingerprint as _fp | ||||||||||
| _px_url = (_px or {}).get('https') | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -496,7 +496,7 @@ def _plan_events(zjwt): | |
| pass | ||
| mid = per_account_device_mid(zjwt) | ||
| base = { | ||
| "client_timezone": "Asia/Tehran", | ||
| "client_timezone": client_timezone(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| "client_language": "en-US", | ||
| "event_text": "", | ||
| "user_id": jwt_user_id(zjwt), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -80,8 +80,13 @@ def _is_private_octets(parts: list[int]) -> bool: | |||||||||
| def valid_endpoint(host: str, port: int) -> bool: | ||||||||||
| if not (0 < port < 65536): | ||||||||||
| return False | ||||||||||
| octets = host.split(".") | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The new leading-zero check is ASCII-only, so fullwidth digits still bypass the loopback and link-local guards. Prompt for AI agents
Suggested change
|
||||||||||
| # getaddrinfo/inet_aton read a leading zero as octal ("0177" == 127), so a | ||||||||||
| # dotted quad like 0177.0.0.1 would slip past the loopback check below | ||||||||||
| if any(len(o) > 1 and o.startswith("0") for o in octets): | ||||||||||
| return False | ||||||||||
| try: | ||||||||||
| parts = [int(o) for o in host.split(".")] | ||||||||||
| parts = [int(o) for o in octets] | ||||||||||
| except ValueError: | ||||||||||
| return False | ||||||||||
| if len(parts) != 4 or any(p > 255 for p in parts): | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -96,42 +96,51 @@ def main(): | |||||||||||||||||||
| log = lambda m: print(m, flush=True) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| got = 0 | ||||||||||||||||||||
| failed = 0 | ||||||||||||||||||||
| for n, (email, _password, token) in enumerate(rows, 1): | ||||||||||||||||||||
| log(f"[{n}/{len(rows)}] {email}") | ||||||||||||||||||||
| zjwt = get_zcode_jwt(token, log=lambda *a, **k: None) | ||||||||||||||||||||
| if not zjwt: | ||||||||||||||||||||
| log(' login failed') | ||||||||||||||||||||
| record = {'email': email, 'plans': None, 'error': 'login'} | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| plan = get_plan(zjwt, log=lambda *a, **k: None) or {} | ||||||||||||||||||||
| ids = plan.get('plans') or [] | ||||||||||||||||||||
| if not ids and escalate: | ||||||||||||||||||||
| log(' no plan — escalating to the full desktop device_login') | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| from invite_claim import device_login | ||||||||||||||||||||
| zjwt2, _ = device_login(token, log=lambda *a, **k: None) | ||||||||||||||||||||
| if zjwt2: | ||||||||||||||||||||
| zjwt = zjwt2 | ||||||||||||||||||||
| time.sleep(2) | ||||||||||||||||||||
| plan = get_plan(zjwt, log=lambda *a, **k: None) or {} | ||||||||||||||||||||
| ids = plan.get('plans') or [] | ||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||
| log(f' escalate failed ({type(e).__name__}: {e})') | ||||||||||||||||||||
| has_start = any(is_start_plan(p) for p in ids) | ||||||||||||||||||||
| got += 1 if has_start else 0 | ||||||||||||||||||||
| record = {'email': email, 'plans': ids, 'starter': has_start, | ||||||||||||||||||||
| 'referral': plan.get('referral'), | ||||||||||||||||||||
| 'campaign': plan.get('campaign'), | ||||||||||||||||||||
| 'entitlements': plan.get('entitlements'), | ||||||||||||||||||||
| 'ts': int(time.time())} | ||||||||||||||||||||
| if has_start: | ||||||||||||||||||||
| with open(startplan_path, 'a', encoding='utf-8') as f: | ||||||||||||||||||||
| f.write(f"{email}:{_password}:{token}\n") | ||||||||||||||||||||
| log(f" -> {ids}") | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| zjwt = get_zcode_jwt(token, log=lambda *a, **k: None) | ||||||||||||||||||||
| if not zjwt: | ||||||||||||||||||||
| log(' login failed') | ||||||||||||||||||||
| record = {'email': email, 'plans': None, 'error': 'login'} | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| plan = get_plan(zjwt, log=lambda *a, **k: None) or {} | ||||||||||||||||||||
| ids = plan.get('plans') or [] | ||||||||||||||||||||
| if not ids and escalate: | ||||||||||||||||||||
| log(' no plan — escalating to the full desktop device_login') | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| from invite_claim import device_login | ||||||||||||||||||||
| zjwt2, _ = device_login(token, log=lambda *a, **k: None) | ||||||||||||||||||||
| if zjwt2: | ||||||||||||||||||||
| zjwt = zjwt2 | ||||||||||||||||||||
| time.sleep(2) | ||||||||||||||||||||
| plan = get_plan(zjwt, log=lambda *a, **k: None) or {} | ||||||||||||||||||||
| ids = plan.get('plans') or [] | ||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||
| log(f' escalate failed ({type(e).__name__}: {e})') | ||||||||||||||||||||
| has_start = any(is_start_plan(p) for p in ids) | ||||||||||||||||||||
| got += 1 if has_start else 0 | ||||||||||||||||||||
| record = {'email': email, 'plans': ids, 'starter': has_start, | ||||||||||||||||||||
| 'referral': plan.get('referral'), | ||||||||||||||||||||
| 'campaign': plan.get('campaign'), | ||||||||||||||||||||
| 'entitlements': plan.get('entitlements'), | ||||||||||||||||||||
| 'ts': int(time.time())} | ||||||||||||||||||||
| if has_start: | ||||||||||||||||||||
| with open(startplan_path, 'a', encoding='utf-8') as f: | ||||||||||||||||||||
| f.write(f"{email}:{_password}:{token}\n") | ||||||||||||||||||||
|
Comment on lines
+129
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A failed Prompt for AI agents
Suggested change
|
||||||||||||||||||||
| log(f" -> {ids}") | ||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||
| failed += 1 | ||||||||||||||||||||
| log(f' failed ({type(e).__name__}: {e})') | ||||||||||||||||||||
| record = {'email': email, 'plans': None, | ||||||||||||||||||||
| 'error': f'{type(e).__name__}: {e}'} | ||||||||||||||||||||
| with open(plans_path, 'a', encoding='utf-8') as f: | ||||||||||||||||||||
| f.write(json.dumps(record, ensure_ascii=False) + "\n") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| log(f"\n{got}/{len(rows)} accounts currently hold a Start Plan") | ||||||||||||||||||||
| if failed: | ||||||||||||||||||||
| log(f"{failed} account(s) failed — see the error field in {plans_path}") | ||||||||||||||||||||
| log(f"ledger: {plans_path}") | ||||||||||||||||||||
| return 0 | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Derive the device id from
chat_token, notzjwt.zjwtis re-minted on every run, so a re-export gives the account a newdevice_mid. Theor DEVICE_MIDfallback is also unreachable, sinceper_account_device_midnever returns an empty string.Prompt for AI agents