diff --git a/docs/license.md b/docs/license.md index cdec24f..2c164ec 100644 --- a/docs/license.md +++ b/docs/license.md @@ -24,7 +24,13 @@ ## 环境变量 -在仓库根目录创建 **`license.env`**(勿提交 Git),或写入各实例 `.env`: +在**仓库根目录**创建 **`license.env`**(勿提交 Git): + +```bash +cd /opt/crypto_monitor_user # 或你的安装目录 +cp license.env.example license.env +# 编辑 license.env:LICENSE_CLIENT_KEY 必须与授权站 CLIENT_API_KEY 完全一致 +``` ```env LICENSE_API_URL=https://sq.bz121.com @@ -35,6 +41,10 @@ LICENSE_CLIENT_KEY=与授权站 CLIENT_API_KEY 相同 # LICENSE_DISABLED=false ``` +改完后**重启** Flask / 中控进程。页面若提示未配置 `LICENSE_CLIENT_KEY`,就是根目录缺少有效的 `license.env`。 + +也可在各实例 `.env` 里写同样的 `LICENSE_*`(不要留空键)。 + 许可状态保存在仓库根目录 **`data/license_state.json`**(三所 + 中控共用)。 系统约每 **3 天** 向授权站校验一次;明确过期或换机后旧设备将无法使用。 diff --git a/lib/license/license_lib.py b/lib/license/license_lib.py index e084f32..49942d5 100644 --- a/lib/license/license_lib.py +++ b/lib/license/license_lib.py @@ -46,9 +46,13 @@ def _load_license_env() -> None: continue key, value = raw.split("=", 1) key = key.strip().lstrip("\ufeff") - if not key or key in os.environ: + if not key: continue - os.environ[key] = value.strip().strip('"').strip("'") + val = value.strip().strip('"').strip("'") + # 仅在未设置或为空时写入,避免空 LICENSE_CLIENT_KEY= 挡住 license.env + if (os.environ.get(key) or "").strip(): + continue + os.environ[key] = val def api_base_url() -> str: @@ -158,7 +162,7 @@ def _parse_expires_at(value: str | None) -> float | None: def _http_json(method: str, path: str, body: dict[str, Any]) -> dict[str, Any]: key = client_key() if not key: - return {"ok": False, "message": "未配置 LICENSE_CLIENT_KEY(与授权站 CLIENT_API_KEY 一致)"} + return {"ok": False, "message": "未配置 LICENSE_CLIENT_KEY。请在仓库根目录复制 license.env.example 为 license.env,填入与授权站相同的 CLIENT_API_KEY,然后重启服务。"} url = f"{api_base_url()}{path}" payload = json.dumps(body).encode("utf-8") req = Request(