fix: require license gate before gui entry
This commit is contained in:
1 parent
407c3b37c2
commit
f5a77867ee
8 files changed
+268
-9
No files matched your search
@@ -15,6 +15,17 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [V3.3.7] — 2026-06-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Dashboard 首次启动未授权时锁定在“授权”页,验证卡密成功后再进入数据看板。
|
||||
- WebGUI 未授权访问首页时先显示卡密验证门禁页,验证成功后再加载完整控制台。
|
||||
|
||||
### Fixed
|
||||
|
||||
- 保留运行接口的授权拦截,避免未输入卡密时通过接口直接启动运行。
|
||||
|
||||
## [V3.3.6] — 2026-06-27
|
||||
## [V3.3.5] — 2026-06-27
|
||||
## [V3.3.4] — 2026-06-26
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
from typing import Optional
|
||||
|
||||
APP_NAME = "douyin_guaji"
|
||||
APP_VERSION = "V3.3.6"
|
||||
APP_BUILD_DATE = "2026-06-27"
|
||||
APP_VERSION = "V3.3.7"
|
||||
APP_BUILD_DATE = "2026-06-28"
|
||||
|
||||
# 兼容旧代码与测试:提供 VERSION / RELEASE_DATE 别名
|
||||
# tests 期望: from version import VERSION, RELEASE_DATE, print_version_banner
|
||||
|
||||
@@ -58,8 +58,8 @@ class DashboardApp:
|
||||
"yg_like_keywords_text": self.data.cfg.get("yanghao_like_keywords", []) or [],
|
||||
"yg_fav_keywords_text": self.data.cfg.get("yanghao_fav_keywords", []) or [],
|
||||
}
|
||||
self.current_page = initial_page if initial_page in PAGES else "数据看板"
|
||||
self.license_locked = bool(license_locked)
|
||||
self.current_page = "授权" if self.license_locked else (initial_page if initial_page in PAGES else "数据看板")
|
||||
self._license_monitor_started = False
|
||||
self.status_var = tk.StringVar(value="请先验证卡密" if self.license_locked else "就绪")
|
||||
self.adb_exe = find_adb_executable()
|
||||
@@ -244,6 +244,8 @@ class DashboardApp:
|
||||
def _sync_nav(self) -> None:
|
||||
for name, btn in self.nav_buttons.items():
|
||||
active = name == self.current_page
|
||||
if hasattr(btn, "set_enabled"):
|
||||
btn.set_enabled((not self.license_locked) or name == "授权")
|
||||
if hasattr(btn, "set_active"):
|
||||
btn.set_active(active)
|
||||
|
||||
@@ -500,13 +502,17 @@ class DashboardApp:
|
||||
self.show_page(self.current_page)
|
||||
|
||||
def show_page(self, name: str) -> None:
|
||||
self.current_page = name
|
||||
target = name if name in PAGES else "数据看板"
|
||||
if self.license_locked and target != "授权":
|
||||
target = "授权"
|
||||
self.status_var.set("请先验证卡密")
|
||||
self.current_page = target
|
||||
self._sync_nav()
|
||||
self._capture_text_widgets()
|
||||
self._apply_text_cache_to_data()
|
||||
self._ensure_text_widgets()
|
||||
clear(self.content)
|
||||
builder = PAGES.get(name, PAGES["数据看板"])
|
||||
builder = PAGES.get(target, PAGES["数据看板"])
|
||||
builder(self.content, self.data, PageContext(self.config_vars, self.text_widgets, self._actions(), self.status_var, self.runner))
|
||||
try:
|
||||
self.content_scroll.canvas.yview_moveto(0)
|
||||
|
||||
@@ -222,21 +222,35 @@ class RoundedNavButton(tk.Canvas):
|
||||
self.text = _with_icon(text, NAV_ICONS.get(text))
|
||||
self.command = command
|
||||
self.active = active
|
||||
self.enabled = True
|
||||
super().__init__(parent, height=46, bg=theme.SURFACE, highlightthickness=0, bd=0, cursor="hand2")
|
||||
self.bind("<Configure>", lambda _e: self._draw())
|
||||
self.bind("<Button-1>", lambda _e: self.command())
|
||||
self.bind("<Button-1>", lambda _e: self._invoke())
|
||||
self.bind("<Enter>", lambda _e: self._draw(hover=True))
|
||||
self.bind("<Leave>", lambda _e: self._draw())
|
||||
|
||||
def _invoke(self) -> None:
|
||||
if self.enabled:
|
||||
self.command()
|
||||
|
||||
def set_active(self, active: bool) -> None:
|
||||
self.active = active
|
||||
self._draw()
|
||||
|
||||
def set_enabled(self, enabled: bool) -> None:
|
||||
self.enabled = bool(enabled)
|
||||
self.configure(cursor="hand2" if self.enabled else "arrow")
|
||||
self._draw()
|
||||
|
||||
def _draw(self, hover: bool = False) -> None:
|
||||
self.delete("all")
|
||||
width = max(1, self.winfo_width())
|
||||
bg = theme.TEAL_SOFT if self.active else (theme.SURFACE_HOVER if hover else theme.SURFACE)
|
||||
fg = theme.TEAL_DARK if self.active else theme.TEXT
|
||||
if not self.enabled:
|
||||
bg = theme.SURFACE
|
||||
fg = theme.MUTED
|
||||
else:
|
||||
bg = theme.TEAL_SOFT if self.active else (theme.SURFACE_HOVER if hover else theme.SURFACE)
|
||||
fg = theme.TEAL_DARK if self.active else theme.TEXT
|
||||
rounded_rect(self, 1, 4, width - 2, 42, theme.RADIUS_SM, fill=bg, outline=bg)
|
||||
if self.active:
|
||||
rounded_rect(self, 4, 12, 10, 34, 4, fill=theme.TEAL, outline=theme.TEAL)
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def render_license_gate_html(csrf_token: str) -> str:
|
||||
return f"""<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>卡密验证 - 抖音自动化助手</title>
|
||||
<style>
|
||||
:root {{
|
||||
color-scheme: light;
|
||||
--bg: #f5f8fb;
|
||||
--surface: #ffffff;
|
||||
--text: #16202a;
|
||||
--muted: #6f7f8f;
|
||||
--border: #dce7ef;
|
||||
--teal: #13998f;
|
||||
--teal-dark: #08746d;
|
||||
--teal-soft: #e6f7f5;
|
||||
--danger: #c83a4b;
|
||||
}}
|
||||
* {{ box-sizing: border-box; }}
|
||||
body {{
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 28px;
|
||||
font: 16px/1.55 "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;
|
||||
color: var(--text);
|
||||
background:
|
||||
radial-gradient(circle at 18% 12%, rgba(19, 153, 143, .12), transparent 30%),
|
||||
linear-gradient(135deg, #fbfdff 0%, var(--bg) 100%);
|
||||
}}
|
||||
.gate {{
|
||||
width: min(520px, 100%);
|
||||
padding: 34px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 255, 255, .92);
|
||||
box-shadow: 0 24px 70px rgba(22, 32, 42, .10);
|
||||
}}
|
||||
.brand {{ display: flex; gap: 16px; align-items: center; margin-bottom: 28px; }}
|
||||
.mark {{
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 14px;
|
||||
color: #fff;
|
||||
background: var(--teal);
|
||||
font-size: 23px;
|
||||
font-weight: 800;
|
||||
}}
|
||||
h1 {{ margin: 0; font-size: 26px; line-height: 1.2; }}
|
||||
p {{ margin: 7px 0 0; color: var(--muted); }}
|
||||
label {{ display: block; margin: 0 0 10px; font-weight: 700; }}
|
||||
input {{
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
padding: 0 16px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
outline: none;
|
||||
font: inherit;
|
||||
background: #fbfdff;
|
||||
}}
|
||||
input:focus {{
|
||||
border-color: var(--teal);
|
||||
box-shadow: 0 0 0 4px var(--teal-soft);
|
||||
background: #fff;
|
||||
}}
|
||||
button {{
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
margin-top: 18px;
|
||||
border: 0;
|
||||
border-radius: 14px;
|
||||
color: #fff;
|
||||
background: var(--teal);
|
||||
font: inherit;
|
||||
font-weight: 800;
|
||||
cursor: pointer;
|
||||
}}
|
||||
button:disabled {{ cursor: wait; opacity: .75; }}
|
||||
.msg {{
|
||||
min-height: 24px;
|
||||
margin-top: 14px;
|
||||
color: var(--muted);
|
||||
font-size: 15px;
|
||||
}}
|
||||
.msg.error {{ color: var(--danger); }}
|
||||
.msg.ok {{ color: var(--teal-dark); }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="gate" aria-labelledby="title">
|
||||
<div class="brand">
|
||||
<div class="mark">抖</div>
|
||||
<div>
|
||||
<h1 id="title">卡密验证</h1>
|
||||
<p>首次启动需要先验证卡密,成功后进入控制台。</p>
|
||||
</div>
|
||||
</div>
|
||||
<form id="license-form">
|
||||
<label for="license-input">输入卡密</label>
|
||||
<input id="license-input" name="license_text" autocomplete="off" autofocus>
|
||||
<button id="submit-btn" type="submit">验证并进入</button>
|
||||
<div id="message" class="msg" role="status"></div>
|
||||
</form>
|
||||
</main>
|
||||
<script>
|
||||
const csrfToken = {csrf_token!r};
|
||||
const form = document.getElementById("license-form");
|
||||
const input = document.getElementById("license-input");
|
||||
const button = document.getElementById("submit-btn");
|
||||
const message = document.getElementById("message");
|
||||
form.addEventListener("submit", async (event) => {{
|
||||
event.preventDefault();
|
||||
const licenseText = input.value.trim();
|
||||
message.className = "msg";
|
||||
if (!licenseText) {{
|
||||
message.textContent = "请先输入卡密。";
|
||||
message.classList.add("error");
|
||||
input.focus();
|
||||
return;
|
||||
}}
|
||||
button.disabled = true;
|
||||
message.textContent = "正在验证...";
|
||||
try {{
|
||||
const res = await fetch("/api/license", {{
|
||||
method: "POST",
|
||||
headers: {{
|
||||
"Content-Type": "application/json",
|
||||
"X-CSRF-Token": csrfToken
|
||||
}},
|
||||
body: JSON.stringify({{ license_text: licenseText }})
|
||||
}});
|
||||
const data = await res.json().catch(() => ({{}}));
|
||||
if (!res.ok || !data.ok) {{
|
||||
throw new Error(data.message || data.error || "卡密验证失败");
|
||||
}}
|
||||
message.textContent = "验证成功,正在进入...";
|
||||
message.classList.add("ok");
|
||||
window.location.reload();
|
||||
}} catch (err) {{
|
||||
message.textContent = err && err.message ? err.message : "卡密验证失败";
|
||||
message.classList.add("error");
|
||||
}} finally {{
|
||||
button.disabled = false;
|
||||
}}
|
||||
}});
|
||||
</script>
|
||||
</body>
|
||||
</html>"""
|
||||
@@ -12,6 +12,7 @@ from douyin.license.license_manager import (
|
||||
get_license_status_payload,
|
||||
install_license_or_activate,
|
||||
)
|
||||
from gui.web_gui_pkg.license_gate import render_license_gate_html
|
||||
from gui.web_gui_pkg import (
|
||||
_wg_log,
|
||||
find_adb_executable,
|
||||
@@ -104,6 +105,16 @@ def _license_gate_payload() -> dict:
|
||||
return payload
|
||||
|
||||
|
||||
def _send_html(handler, html: str, status: int = 200) -> None:
|
||||
data = html.encode("utf-8")
|
||||
handler.send_response(status)
|
||||
handler.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
handler.send_header("Content-Length", str(len(data)))
|
||||
handler.send_header("Cache-Control", "no-store")
|
||||
handler.end_headers()
|
||||
handler.wfile.write(data)
|
||||
|
||||
|
||||
def _is_invalid_ports_spec(spec) -> bool:
|
||||
"""判断端口规格是否为明确非法输入。"""
|
||||
if spec is None:
|
||||
@@ -369,6 +380,9 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
handler.send_error(HTTPStatus.FORBIDDEN)
|
||||
return
|
||||
|
||||
if u.path in {"/", "/index.html"} and not check_license().ok:
|
||||
return _send_html(handler, render_license_gate_html(csrf_token))
|
||||
|
||||
handler._serve_static(u.path)
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
# 这里的 version 由 tools/dev/bump_version.py 与 version.py 同步维护。
|
||||
# 注意:为兼容 PEP 440,这里去掉 "V" 前缀,仅保留数字部分(如 V3.3.3 → 3.3.3)。
|
||||
name = "douyin_guaji"
|
||||
version = "3.3.6"
|
||||
version = "3.3.7"
|
||||
description = "基于 ADB + OCR + 像素检测 + 模板匹配的抖音直播间福袋自动挂机工具"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@@ -16,6 +17,9 @@ class _DummyHandler:
|
||||
self.calls = []
|
||||
self.client_address = ("127.0.0.1", 12345)
|
||||
self.static_calls = []
|
||||
self.response_status = None
|
||||
self.response_headers = []
|
||||
self.wfile = io.BytesIO()
|
||||
|
||||
def _read_json(self):
|
||||
return self._body
|
||||
@@ -28,6 +32,15 @@ class _DummyHandler:
|
||||
self.calls.append((status, {"error": "send_error"}))
|
||||
return None
|
||||
|
||||
def send_response(self, status):
|
||||
self.response_status = status
|
||||
|
||||
def send_header(self, name, value):
|
||||
self.response_headers.append((name, value))
|
||||
|
||||
def end_headers(self):
|
||||
return None
|
||||
|
||||
def _serve_static(self, rel_path):
|
||||
self.static_calls.append(rel_path)
|
||||
return None
|
||||
@@ -101,6 +114,22 @@ def _get(path: str, monkeypatch, query: str = ""):
|
||||
return handler.calls[-1]
|
||||
|
||||
|
||||
def _license_ok(monkeypatch):
|
||||
class OkStatus:
|
||||
ok = True
|
||||
|
||||
monkeypatch.setattr(routes, "check_license", lambda: OkStatus())
|
||||
|
||||
|
||||
def _license_missing(monkeypatch):
|
||||
class MissingStatus:
|
||||
ok = False
|
||||
reason = "missing"
|
||||
message = "缺少授权文件"
|
||||
|
||||
monkeypatch.setattr(routes, "check_license", lambda: MissingStatus())
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"raw,expected",
|
||||
[
|
||||
@@ -154,6 +183,34 @@ def test_license_status_route_returns_public_payload(monkeypatch):
|
||||
assert obj == {"ok": True, "reason": "ok", "customer": "demo"}
|
||||
|
||||
|
||||
def test_web_root_requires_license_gate_before_static_app(monkeypatch):
|
||||
_license_missing(monkeypatch)
|
||||
handler = _DummyHandler()
|
||||
runner = _DummyRunner()
|
||||
u = SimpleNamespace(path="/", query="")
|
||||
|
||||
routes.handle_get(handler, u, runner, "token")
|
||||
|
||||
html = handler.wfile.getvalue().decode("utf-8")
|
||||
assert handler.response_status == 200
|
||||
assert "卡密验证" in html
|
||||
assert "输入卡密" in html
|
||||
assert "window.location.reload" in html
|
||||
assert handler.static_calls == []
|
||||
|
||||
|
||||
def test_web_root_enters_static_app_when_license_exists(monkeypatch):
|
||||
_license_ok(monkeypatch)
|
||||
handler = _DummyHandler()
|
||||
runner = _DummyRunner()
|
||||
u = SimpleNamespace(path="/", query="")
|
||||
|
||||
routes.handle_get(handler, u, runner, "token")
|
||||
|
||||
assert handler.static_calls == ["/"]
|
||||
assert handler.wfile.getvalue() == b""
|
||||
|
||||
|
||||
def test_license_install_route_accepts_code(monkeypatch):
|
||||
calls = {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user