修改默认值

This commit is contained in:
xiaobai committed 2026-03-24 17:51:23 +08:00
1 parent a1867fd03e
commit 6faee25ba7
4 files changed
+38 -19

No files matched your search

+4 -1
View File
@@ -45,7 +45,10 @@ python -m maintain
### 3) 必填配置(配置编辑页) ### 3) 必填配置(配置编辑页)
- `cliproxy_management_base`、`cliproxy_management_key`:巡检/清理必填。 - `cliproxy_management_base`、`cliproxy_management_key`:巡检/清理核心配置。默认值为:
- `cliproxy_management_base = http://127.0.0.1:8317`
- `cliproxy_management_key = $CLIPROXY_MANAGEMENT_KEY`,若未设置则回退 `$MANAGEMENT_KEY`
- 因此单机部署通常只需要设置一个环境变量 `CLIPROXY_MANAGEMENT_KEY`(或 `MANAGEMENT_KEY`)即可。
- **CPA auths 固定目录**:部署时在仓库里改 `maintain/paths_config.py` 的 `CPA_AUTHS_DIR`(例如 NAS 挂载点 `/mnt/cpa_auths`)。新库默认会把 **`codex_stats_oauth_dir`** 与流水线 **`cpa_target_dir`** 设成该路径;**统计目录留空**时也会回落到该路径。已有 SQLite 里若仍是旧值,可在「配置编辑」里改一次或删掉对应 `settings` 行后重启。 - **CPA auths 固定目录**:部署时在仓库里改 `maintain/paths_config.py` 的 `CPA_AUTHS_DIR`(例如 NAS 挂载点 `/mnt/cpa_auths`)。新库默认会把 **`codex_stats_oauth_dir`** 与流水线 **`cpa_target_dir`** 设成该路径;**统计目录留空**时也会回落到该路径。已有 SQLite 里若仍是旧值,可在「配置编辑」里改一次或删掉对应 `settings` 行后重启。
- `cliproxy_sweeper_threshold` / `cliproxy_sweeper_run_mode`:控制 `/usage` 清理阈值与 delete/observe 模式。 - `cliproxy_sweeper_threshold` / `cliproxy_sweeper_run_mode`:控制 `/usage` 清理阈值与 delete/observe 模式。
+19 -9
View File
@@ -25,6 +25,7 @@ from maintain import db
from maintain.batch_register import run_batch from maintain.batch_register import run_batch
from maintain.runtime_log import rtlog, runtime_log_path from maintain.runtime_log import rtlog, runtime_log_path
from maintain.cliproxy_mgmt import ( from maintain.cliproxy_mgmt import (
management_api_root,
probe_auth_file_models_for_oauth_stem, probe_auth_file_models_for_oauth_stem,
verify_management_auth, verify_management_auth,
) )
@@ -240,10 +241,13 @@ def api_overview():
"dingtalk_webhook": settings.get("dingtalk_webhook", ""), "dingtalk_webhook": settings.get("dingtalk_webhook", ""),
"dingtalk_secret": settings.get("dingtalk_secret", ""), "dingtalk_secret": settings.get("dingtalk_secret", ""),
"cliproxy_management_base": settings.get( "cliproxy_management_base": settings.get(
"cliproxy_management_base", "" "cliproxy_management_base", db.DEFAULT_CLIPROXY_BASE
), ),
"cliproxy_management_key_set": bool( "cliproxy_management_key_set": bool(
settings.get("cliproxy_management_key", "").strip() (
settings.get("cliproxy_management_key", "").strip()
or db.DEFAULT_CLIPROXY_KEY
)
), ),
"cliproxy_probe_timeout_sec": settings.get( "cliproxy_probe_timeout_sec": settings.get(
"cliproxy_probe_timeout_sec", "30" "cliproxy_probe_timeout_sec", "30"
@@ -463,8 +467,8 @@ def _probe_error_skip_delete(err: str) -> bool:
def _run_cliproxy_inspect_worker(task_id: int, source: str) -> None: def _run_cliproxy_inspect_worker(task_id: int, source: str) -> None:
base = db.get_setting("cliproxy_management_base", "").strip() base = db.get_setting("cliproxy_management_base", db.DEFAULT_CLIPROXY_BASE).strip()
key = db.get_setting("cliproxy_management_key", "").strip() key = db.get_setting("cliproxy_management_key", db.DEFAULT_CLIPROXY_KEY).strip()
if not base or not key: if not base or not key:
rtlog().warning( rtlog().warning(
"[inspect#%s] %s 中止: 未配置管理地址或密钥", task_id, source "[inspect#%s] %s 中止: 未配置管理地址或密钥", task_id, source
@@ -624,8 +628,8 @@ def _run_cliproxy_sweeper_worker(
finalize_task: bool = True, finalize_task: bool = True,
) -> dict[str, int | str]: ) -> dict[str, int | str]:
"""按 usage 连续失败阈值清理 auth-files 里的失效 JSON。""" """按 usage 连续失败阈值清理 auth-files 里的失效 JSON。"""
base = db.get_setting("cliproxy_management_base", "").strip() base = db.get_setting("cliproxy_management_base", db.DEFAULT_CLIPROXY_BASE).strip()
key = db.get_setting("cliproxy_management_key", "").strip() key = db.get_setting("cliproxy_management_key", db.DEFAULT_CLIPROXY_KEY).strip()
if not base or not key: if not base or not key:
msg = "请先在「配置编辑」填写 Cliproxy 管理地址与密钥" msg = "请先在「配置编辑」填写 Cliproxy 管理地址与密钥"
if finalize_task: if finalize_task:
@@ -641,6 +645,12 @@ def _run_cliproxy_sweeper_worker(
db.get_setting("cliproxy_sweeper_allow_name_fallback", "1").strip() == "1" db.get_setting("cliproxy_sweeper_allow_name_fallback", "1").strip() == "1"
) )
apply_mode = run_mode == "delete" apply_mode = run_mode == "delete"
mgmt_root = management_api_root(base)
if not mgmt_root:
msg = "管理端地址无效,请检查 cliproxy_management_base"
if finalize_task:
db.update_task(task_id, status="error", message=msg)
raise RuntimeError(msg)
rtlog().info( rtlog().info(
"[sweeper#%s] %s 开始 base=%s threshold=%s mode=%s", "[sweeper#%s] %s 开始 base=%s threshold=%s mode=%s",
@@ -660,7 +670,7 @@ def _run_cliproxy_sweeper_worker(
run_started_epoch = int(time.time()) run_started_epoch = int(time.time())
usage_obj = cliproxy_sweeper.request_json_or_die( usage_obj = cliproxy_sweeper.request_json_or_die(
base_url=base.rstrip("/"), base_url=mgmt_root,
path="/usage", path="/usage",
method="GET", method="GET",
headers=headers, headers=headers,
@@ -673,7 +683,7 @@ def _run_cliproxy_sweeper_worker(
run_started_epoch=run_started_epoch, run_started_epoch=run_started_epoch,
) )
auth_files_obj = cliproxy_sweeper.request_json_or_die( auth_files_obj = cliproxy_sweeper.request_json_or_die(
base_url=base.rstrip("/"), base_url=mgmt_root,
path="/auth-files", path="/auth-files",
method="GET", method="GET",
headers=headers, headers=headers,
@@ -700,7 +710,7 @@ def _run_cliproxy_sweeper_worker(
file_name = str(c.get("file_name", "")) file_name = str(c.get("file_name", ""))
encoded_name = urllib.parse.quote(file_name, safe="") encoded_name = urllib.parse.quote(file_name, safe="")
code, _ = cliproxy_sweeper.http_request_with_retry( code, _ = cliproxy_sweeper.http_request_with_retry(
base_url=base.rstrip("/"), base_url=mgmt_root,
path=f"/auth-files?name={encoded_name}", path=f"/auth-files?name={encoded_name}",
method="DELETE", method="DELETE",
headers=headers, headers=headers,
+11 -5
View File
@@ -13,6 +13,12 @@ from maintain.paths_config import CPA_AUTHS_DIR
ROOT = Path(__file__).resolve().parent.parent ROOT = Path(__file__).resolve().parent.parent
DB_PATH = ROOT / "maintain" / "data" / "maintain.db" DB_PATH = ROOT / "maintain" / "data" / "maintain.db"
ACCOUNTS_OAUTH = ROOT / "accounts" / "oauth" ACCOUNTS_OAUTH = ROOT / "accounts" / "oauth"
DEFAULT_CLIPROXY_BASE = os.getenv("CLIPROXY_MANAGEMENT_BASE", "http://192.168.31.188:8317/").strip()
DEFAULT_CLIPROXY_KEY = (
os.getenv("CLIPROXY_MANAGEMENT_KEY")
or os.getenv("MANAGEMENT_KEY")
or ""
).strip()
_lock = threading.Lock() _lock = threading.Lock()
@@ -117,8 +123,8 @@ def init_db() -> None:
"dingtalk_webhook": "", "dingtalk_webhook": "",
"dingtalk_secret": "", "dingtalk_secret": "",
# Cliproxy 管理端巡检(与 Web 管理台「探测模型」同源) # Cliproxy 管理端巡检(与 Web 管理台「探测模型」同源)
"cliproxy_management_base": "", "cliproxy_management_base": DEFAULT_CLIPROXY_BASE,
"cliproxy_management_key": "", "cliproxy_management_key": DEFAULT_CLIPROXY_KEY,
"cliproxy_probe_timeout_sec": "30", "cliproxy_probe_timeout_sec": "30",
"cliproxy_sweeper_threshold": "3", "cliproxy_sweeper_threshold": "3",
"cliproxy_sweeper_run_mode": "delete", "cliproxy_sweeper_run_mode": "delete",
@@ -251,9 +257,9 @@ def pick_random_proxy_url() -> Optional[str]:
def cliproxy_inspect_configured() -> bool: def cliproxy_inspect_configured() -> bool:
return bool(get_setting("cliproxy_management_base", "").strip()) and bool( base = get_setting("cliproxy_management_base", DEFAULT_CLIPROXY_BASE).strip()
get_setting("cliproxy_management_key", "").strip() key = get_setting("cliproxy_management_key", DEFAULT_CLIPROXY_KEY).strip()
) return bool(base) and bool(key)
def _oauth_json_is_codex_candidate(data: dict[str, Any], *, strict_codex_type: bool) -> bool: def _oauth_json_is_codex_candidate(data: dict[str, Any], *, strict_codex_type: bool) -> bool:
+4 -4
View File
@@ -188,13 +188,13 @@
<div id="section-config" class="section"> <div id="section-config" class="section">
<div class="panel"> <div class="panel">
<h3>Cliproxy 管理端(巡检必填)</h3> <h3>Cliproxy 管理端(巡检必填)</h3>
<p style="color:var(--muted);font-size:0.8rem;margin:0 0 12px;line-height:1.5">与 <a href="https://help.router-for.me/cn/management/api" target="_blank" rel="noopener">管理 API</a> 一致。若<strong>注册成功后的 JSON 已迁入 Cliproxy 的 auth 目录</strong>,须填写下方「统计目录」为该目录绝对路径,否则维护台仍只扫项目内 <code>accounts/oauth</code>,账号数会显示 0。巡检按该目录下的文件名调用 <code>auth-files/models</code>;删除失效 JSON 也在该目录内。密钥存 SQLite。</p> <p style="color:var(--muted);font-size:0.8rem;margin:0 0 12px;line-height:1.5">与 <a href="https://help.router-for.me/cn/management/api" target="_blank" rel="noopener">管理 API</a> 一致。若<strong>注册成功后的 JSON 已迁入 Cliproxy 的 auth 目录</strong>,请填写下方「统计目录」为该目录绝对路径;留空时使用部署侧固定目录(<code>maintain/paths_config.py</code> 的 <code>CPA_AUTHS_DIR</code>)。巡检按该目录下的文件名调用 <code>auth-files/models</code>;删除失效 JSON 也在该目录内。密钥存 SQLite。</p>
<label>统计 / 巡检用 Codex JSON 目录(留空 = 项目内 accounts/oauth)</label> <label>统计 / 巡检用 Codex JSON 目录(留空 = fixed CPA_AUTHS_DIR)</label>
<input type="text" id="cfgStatsOauthDir" placeholder="/root/.cli-proxy-api 或你的 CPA auth 绝对路径" /> <input type="text" id="cfgStatsOauthDir" placeholder="/root/.cli-proxy-api 或你的 CPA auth 绝对路径" />
<label>管理 Base(如 http://127.0.0.1:8317,勿带 /v0/management)</label> <label>管理 Base(默认 http://127.0.0.1:8317,勿带 /v0/management)</label>
<input type="text" id="cfgClipBase" placeholder="http://127.0.0.1:8317" /> <input type="text" id="cfgClipBase" placeholder="http://127.0.0.1:8317" />
<label>Management Key(Bearer)</label> <label>Management Key(Bearer)</label>
<input type="password" id="cfgClipKey" autocomplete="new-password" placeholder="留空表示不修改已保存的密钥" /> <input type="password" id="cfgClipKey" autocomplete="new-password" placeholder="留空表示不修改;也可用环境变量 CLIPROXY_MANAGEMENT_KEY / MANAGEMENT_KEY" />
<label>探测超时(秒)</label> <label>探测超时(秒)</label>
<input type="number" id="cfgClipTimeout" min="5" max="120" value="30" /> <input type="number" id="cfgClipTimeout" min="5" max="120" value="30" />
<label>失效清理阈值(连续失败次数)</label> <label>失效清理阈值(连续失败次数)</label>