Files
dsh_shenxian/dsh-server-docs/scripts/cf-probe.py
T
admin 971ccc3703 feat(auth): 注册页人机验证 + 邮箱验证码;品牌标识去 DeepSeek(附域名迁移线 序㊿ 补提交)
三条线合并入库 —— 均已完成并上线(源码与生产一致,此前只部署未入仓)。
⚠️ 其中域名迁移线为**另一会话**产出,本会话只做入库、**未复验其正确性**(它自报零回归)。

【档案 134 · 注册页人机验证 + 邮箱验证码】
- DB 迁移 v10:users.email(唯一索引 LOWER(email))+ email_codes 事件表(2 索引)
- 新增模块 src/web/{register-guard,mail,turnstile,email-code}.ts
- routes/auth.ts:新增 GET /api/auth/register/config、POST /api/auth/register/email-code;
  注册接口加人机验证与验证码校验;config.ts 新增 12 项配置(默认空 ⇒ 不配 = 老行为)
- 邮件走**可插拔驱动**(brevo/http/log),发件人 [email protected](Brevo 域名已认证 + DKIM + SPF)
- 防爆破:三层配额(邮箱 6/h、8/天;IP 20/h;全局 200/h)+ 递增冷却阶梯
  (60→60→180→300→900→1800s)+ 试错 5 次作废 + 码只存哈希 + 单次使用 + 与用户名绑定
- Turnstile 服务端校 **success + action + hostname 三项**:sitekey 是公开的,
  只校 success 时"拿我们的 sitekey 在自己站点替真人取合法 token 再打我们接口"这条路是通的
- 新增 test/register-guard.test.mjs(19 用例)

【档案 137 · 品牌标识改造 — 去 DeepSeek 图形】
- login/register/admin 页头:删 DeepSeek 鲸鱼图标 + 「DeepSeek」文字图形
  → 平台标识(中文「能力枢纽」/英语及其他语言「CapabilityNet」,走 i18n 词条 brand.name)
- portal 顶栏换图标(页面名「管理门户」保留)
- 新建 web/favicon.svg(平台自有 hub 图标,避开 DeepSeek 蓝)+ 四页 favicon 指向它
- 新增 test/i18n-brand.test.mjs(node:vm 跑真实 i18n.js,六条语言路径断言渲染结果)
- scripts/verify-static.mjs 新增 SVG 段:XML 注释不得含 ASCII 双连字符(否则整份 SVG
  解析失败、图标静默不显示 —— 实际踩到过)
- 🔴 会话页面(实例内官方 dsh 界面)的标识**按用户要求未动**(也受 R2 约束)

【档案 135/136 · 域名迁移线(另一会话产出)】
- 域名收敛为 ai1net.com;旧域 alotbuy.com 降级为 301 过渡装置
- src/net/relay/{addr-override,directory,rendezvous,switcher}.ts 种子与候选链更新;
  src/web/server.ts、src/worker/relay-tunnel.ts、scripts/verify-cluster-domain.mjs
- 档案 136 = 控制面按两台中继取并集(**已立项、未落地**)

验证(本会话两条线):新增单测 21 条全通过|全量 221 pass / 0 fail / 1 skipped|
verify-static 全合格|其余 10 个 verify 脚本全 OK|线上实测:Turnstile 假 token 403、
发码 delivered、四页 deepseek 命中 0、favicon 200。
2026-09-19 09:11:24 +08:00

89 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""探测 _acme-challenge 名称是否被通配 CNAME 劫持(只读+临时记录,用完即删)。
用法: python3 cf-probe.py <zone名> [_acme-challenge.<zone>]
"""
import json
import re
import sys
import time
import urllib.request
CRED = '/etc/cloudflare.ini'
# 2026-09-19 域迁 ai1net.com 后其 zone 走独立凭据(与旧域 token 不通用)
CREDS = {'ai1net.com': '/etc/cloudflare-ai1net.ini'}
API = 'https://api.cloudflare.com/client/v4'
def token(zone=None):
txt = open(CREDS.get(zone or '', CRED), 'r', encoding='utf-8').read()
m = re.search(r'dns_cloudflare_api_token\s*=\s*([A-Za-z0-9_\-]+)', txt)
if not m:
sys.exit('未找到 token')
return m.group(1)
def req(method, path, tok, body=None):
data = json.dumps(body).encode('utf-8') if body is not None else None
r = urllib.request.Request(API + path, data=data, method=method,
headers={'Authorization': 'Bearer ' + tok,
'Content-Type': 'application/json'})
with urllib.request.urlopen(r, timeout=20) as resp:
return json.loads(resp.read().decode('utf-8'))
def doh(name, typ, server='https://dns.google/resolve'):
url = '%s?name=%s&type=%s' % (server, name, typ)
r = urllib.request.Request(url, headers={'accept': 'application/dns-json'})
with urllib.request.urlopen(r, timeout=20) as resp:
return json.loads(resp.read().decode('utf-8'))
def show(title, name, typ):
print('--- %s ---' % title)
for srv, label in [('https://dns.google/resolve', 'Google'), ('https://cloudflare-dns.com/dns-query', 'CF')]:
try:
d = doh(name, typ, srv)
ans = d.get('Answer') or []
print(' [%s] Status=%s' % (label, d.get('Status')))
if not ans:
print(' (无 Answer)')
for a in ans:
print(' type=%-6s %s' % (a.get('type'), str(a.get('data'))[:90]))
except Exception as e:
print(' [%s] 查询失败: %s' % (label, e))
def main():
zone = sys.argv[1] if len(sys.argv) > 1 else 'ai1net.com'
name = sys.argv[2] if len(sys.argv) > 2 else '_acme-challenge.' + zone
tok = token(zone)
zid = ''
for z in (req('GET', '/zones?name=' + zone, tok).get('result') or []):
zid = z['id']
if zid == '':
sys.exit('zone 不在权限内')
print('=== 创建临时 TXT: %s ===' % name)
created = req('POST', '/zones/%s/dns_records' % zid, tok,
{'type': 'TXT', 'name': name, 'content': 'probe-test-value-12345', 'ttl': 120})
if not created.get('success'):
print(' 创建失败:', created.get('errors'))
return
rid = created['result']['id']
print(' 已创建 id=%s' % rid)
try:
for wait in (3, 10, 30):
time.sleep(wait if wait == 3 else wait - 3)
print('\n=== 等待累计 ~%ds 后查询 ===' % wait)
show('TXT 查询', name, 'TXT')
finally:
print('\n=== 清理临时记录 ===')
d = req('DELETE', '/zones/%s/dns_records/%s' % (zid, rid), tok)
print(' 删除成功:', d.get('success'))
if __name__ == '__main__':
main()