dsh-plugin-mesh 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +7 -4
- package/README.md +98 -2
- package/client/client.js +685 -122
- package/lib/_selftest-reply-route.mjs +80 -2
- package/lib/_selftest-switch.mjs +142 -0
- package/lib/_selftest-tsnet.mjs +258 -1
- package/lib/_selftest-workbench.mjs +289 -0
- package/lib/discovery.js +89 -18
- package/lib/index.js +1128 -253
- package/lib/switch.js +110 -0
- package/lib/tsnet/channels.js +72 -0
- package/lib/tsnet/manager.js +316 -51
- package/llms.txt +56 -10
- package/package.json +5 -4
- package/scripts/check-tarball.mjs +1 -0
package/client/client.js
CHANGED
|
@@ -1248,6 +1248,43 @@ window.__ModuleLoader__.load({
|
|
|
1248
1248
|
.mesh-actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
|
|
1249
1249
|
.mesh-divider { height: 1px; background: var(--mesh-line); margin: 14px 0; }
|
|
1250
1250
|
|
|
1251
|
+
/* ── 一键关闭(kill switch)── */
|
|
1252
|
+
.mesh-switch-list {
|
|
1253
|
+
display: flex; flex-direction: column; gap: 8px; margin-top: 12px;
|
|
1254
|
+
}
|
|
1255
|
+
.mesh-switch-row {
|
|
1256
|
+
display: flex; align-items: flex-start; gap: 12px;
|
|
1257
|
+
padding: 12px 14px;
|
|
1258
|
+
border: 1px solid var(--mesh-line); border-radius: 11px;
|
|
1259
|
+
background: var(--mesh-surface);
|
|
1260
|
+
transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease;
|
|
1261
|
+
}
|
|
1262
|
+
/* 关闭中的一行用左侧警示条标出来:列表里三行很像,必须一眼看出哪条关了 */
|
|
1263
|
+
.mesh-switch-row.is-off { border-left: 2px solid var(--mesh-warn); }
|
|
1264
|
+
.mesh-switch-row-icon {
|
|
1265
|
+
flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
|
|
1266
|
+
display: grid; place-items: center;
|
|
1267
|
+
color: var(--mesh-accent);
|
|
1268
|
+
background: color-mix(in srgb, var(--mesh-accent) 8%, transparent);
|
|
1269
|
+
}
|
|
1270
|
+
.mesh-switch-row.is-off .mesh-switch-row-icon { color: var(--mesh-warn); background: color-mix(in srgb, var(--mesh-warn) 10%, transparent); }
|
|
1271
|
+
.mesh-switch-row-main { flex: 1; min-width: 0; }
|
|
1272
|
+
.mesh-switch-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
1273
|
+
.mesh-switch-row-title { font-size: 12.5px; font-weight: 600; }
|
|
1274
|
+
.mesh-switch-row-desc { margin-top: 3px; font-size: 11px; line-height: 1.6; color: var(--mesh-muted); }
|
|
1275
|
+
.mesh-switch-row-meta {
|
|
1276
|
+
margin-top: 5px;
|
|
1277
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
1278
|
+
font-size: 10px; color: var(--mesh-muted);
|
|
1279
|
+
word-break: break-word;
|
|
1280
|
+
}
|
|
1281
|
+
.mesh-switch-row-action { flex: 0 0 auto; align-self: center; }
|
|
1282
|
+
@media (max-width: 560px) {
|
|
1283
|
+
.mesh-switch-row { flex-wrap: wrap; }
|
|
1284
|
+
.mesh-switch-row-action { width: 100%; }
|
|
1285
|
+
.mesh-switch-row-action .mesh-btn { width: 100%; }
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1251
1288
|
/* ── 主页(卡片工作台) ── */
|
|
1252
1289
|
.mesh-home { flex: 1; min-height: 0; overflow-y: auto; }
|
|
1253
1290
|
.mesh-home-inner { max-width: 1040px; margin: 0 auto; padding: 26px 30px 60px; }
|
|
@@ -1303,6 +1340,35 @@ window.__ModuleLoader__.load({
|
|
|
1303
1340
|
.mesh-hero-stat { display: flex; flex-direction: column; gap: 2px; min-width: 54px; }
|
|
1304
1341
|
.mesh-hero-stat-value { font-size: 17px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1305
1342
|
.mesh-hero-stat-label { font-size: 10px; color: var(--mesh-muted); }
|
|
1343
|
+
|
|
1344
|
+
/* ── 概览卡上的一键关闭快捷条 ── */
|
|
1345
|
+
.mesh-home-switch {
|
|
1346
|
+
display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
|
|
1347
|
+
margin-top: 14px; padding-top: 11px;
|
|
1348
|
+
border-top: 1px dashed var(--mesh-line);
|
|
1349
|
+
}
|
|
1350
|
+
.mesh-home-switch-label {
|
|
1351
|
+
font-size: 10px; color: var(--mesh-muted); letter-spacing: .02em;
|
|
1352
|
+
margin-right: 2px;
|
|
1353
|
+
}
|
|
1354
|
+
.mesh-home-switch-pill {
|
|
1355
|
+
display: inline-flex; align-items: center; gap: 5px;
|
|
1356
|
+
padding: 3px 9px;
|
|
1357
|
+
border: 1px solid var(--mesh-line); border-radius: 999px;
|
|
1358
|
+
background: var(--mesh-surface-2); color: var(--mesh-fg);
|
|
1359
|
+
font-size: 11px; line-height: 1.5; cursor: pointer;
|
|
1360
|
+
transition: border-color var(--mesh-dur-fast) ease, background var(--mesh-dur-fast) ease,
|
|
1361
|
+
transform var(--mesh-dur-press) var(--mesh-ease-out);
|
|
1362
|
+
}
|
|
1363
|
+
.mesh-home-switch-pill:hover { border-color: var(--mesh-accent); }
|
|
1364
|
+
.mesh-home-switch-pill:active { transform: scale(0.97); }
|
|
1365
|
+
.mesh-home-switch-pill:disabled { cursor: progress; opacity: .7; }
|
|
1366
|
+
.mesh-home-switch-pill.is-off { border-color: var(--mesh-warn); }
|
|
1367
|
+
.mesh-home-switch-pill.is-off .mesh-home-switch-name { color: var(--mesh-warn); }
|
|
1368
|
+
.mesh-home-switch-pill.is-stalled { border-color: var(--mesh-warn); }
|
|
1369
|
+
.mesh-home-switch-name { font-weight: 600; }
|
|
1370
|
+
.mesh-home-switch-state { color: var(--mesh-muted); font-variant-numeric: tabular-nums; }
|
|
1371
|
+
.mesh-home.is-dense .mesh-home-switch { margin-top: 9px; padding-top: 8px; gap: 4px; }
|
|
1306
1372
|
.mesh-mini-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--mesh-line); font-size: 11.5px; min-width: 0; }
|
|
1307
1373
|
.mesh-mini-row:first-child { border-top: 0; padding-top: 0; }
|
|
1308
1374
|
.mesh-mini-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
@@ -2266,6 +2332,11 @@ window.__ModuleLoader__.load({
|
|
|
2266
2332
|
h("path", { key: "b", d: "M8.5 16a5 5 0 0 1 7 0" }),
|
|
2267
2333
|
h("path", { key: "c", d: "M12 19h.01" }),
|
|
2268
2334
|
];
|
|
2335
|
+
case "power":
|
|
2336
|
+
return [
|
|
2337
|
+
h("path", { key: "a", d: "M12 3v9" }),
|
|
2338
|
+
h("path", { key: "b", d: "M6.3 6.8a8 8 0 1 0 11.4 0" }),
|
|
2339
|
+
];
|
|
2269
2340
|
case "key":
|
|
2270
2341
|
return [
|
|
2271
2342
|
h("circle", { key: "a", cx: 8, cy: 15, r: 4 }),
|
|
@@ -2723,13 +2794,24 @@ window.__ModuleLoader__.load({
|
|
|
2723
2794
|
? h("p", { className: "mesh-p" }, "对端还没有报告通道信息。等它下一次广播后会出现。")
|
|
2724
2795
|
: eps.map((ep, i) => {
|
|
2725
2796
|
const cooling = ep.downUntil && now < ep.downUntil;
|
|
2726
|
-
|
|
2797
|
+
// 多 tailnet:通道 key 才是端点身份(lan / tsnet:<id>),
|
|
2798
|
+
// 只比 transport 会把"局域网在用"错标到每条 tailnet 上。
|
|
2799
|
+
const epKey = ep.channel || ep.transport || "";
|
|
2800
|
+
const active = !!(peer.online && (peer.channel || peer.transport) && epKey === (peer.channel || peer.transport));
|
|
2727
2801
|
const state = active ? "在用" : cooling ? "冷却中" : ep.verified === false ? "未探测" : "备用";
|
|
2728
2802
|
const kind = active ? "ok" : cooling ? "warn" : "idle";
|
|
2729
|
-
const
|
|
2803
|
+
const channelTag =
|
|
2804
|
+
ep.transport === "tsnet"
|
|
2805
|
+
? epKey.startsWith("tsnet:cand:")
|
|
2806
|
+
? "候选地址"
|
|
2807
|
+
: epKey.startsWith("tsnet:")
|
|
2808
|
+
? epKey.slice("tsnet:".length)
|
|
2809
|
+
: ""
|
|
2810
|
+
: "";
|
|
2811
|
+
const label = ep.transport === "tsnet" ? (channelTag ? `互联网 · ${channelTag}` : "互联网") : "局域网";
|
|
2730
2812
|
return h(
|
|
2731
2813
|
"div",
|
|
2732
|
-
{ key: `ep-${
|
|
2814
|
+
{ key: `ep-${epKey}-${i}`, className: "mesh-channel" },
|
|
2733
2815
|
h("span", { className: "mesh-channel-icon" }, h(Icon, { name: ep.transport === "tsnet" ? "tailscale" : "wifi", size: 14 })),
|
|
2734
2816
|
h(
|
|
2735
2817
|
"span",
|
|
@@ -3955,6 +4037,158 @@ window.__ModuleLoader__.load({
|
|
|
3955
4037
|
|
|
3956
4038
|
// ─────────────────────── 连接 / 设置 ───────────────────────
|
|
3957
4039
|
|
|
4040
|
+
/**
|
|
4041
|
+
* 一键关闭(kill switch)。
|
|
4042
|
+
*
|
|
4043
|
+
* 三个范围与宿主 lib/switch.js 一致:all / lan / internet。
|
|
4044
|
+
* 刻意**不做二次确认**:这个功能最需要的时刻是"我怀疑有人能连上我",
|
|
4045
|
+
* 那一刻要的是快;误点的代价只是再点一次打开(配置、会话都不丢)。
|
|
4046
|
+
* 牙口留给别处:按钮文案写清楚会发生什么,关闭后顶部横幅常驻提示。
|
|
4047
|
+
*/
|
|
4048
|
+
const MESH_SWITCH_ROWS = [
|
|
4049
|
+
{
|
|
4050
|
+
scope: "all",
|
|
4051
|
+
title: "全部 Mesh",
|
|
4052
|
+
icon: "power",
|
|
4053
|
+
desc: "局域网 + 互联网一起关。关掉后这台机器不再被任何设备发现,也不再接受任务。",
|
|
4054
|
+
},
|
|
4055
|
+
{
|
|
4056
|
+
scope: "lan",
|
|
4057
|
+
title: "局域网 Mesh",
|
|
4058
|
+
icon: "wifi",
|
|
4059
|
+
desc: "停发组播、停止扫描与 ping,对端端口从局域网收回(只绑本机回环)。",
|
|
4060
|
+
},
|
|
4061
|
+
{
|
|
4062
|
+
scope: "internet",
|
|
4063
|
+
title: "互联网 Mesh",
|
|
4064
|
+
icon: "tailscale",
|
|
4065
|
+
desc: "停掉全部 tailnet sidecar。通道与授权码保留,打开即恢复,不用重新登录。",
|
|
4066
|
+
},
|
|
4067
|
+
];
|
|
4068
|
+
|
|
4069
|
+
function SwitchRow({ row, off, badge, meta, note, busy, onToggle }) {
|
|
4070
|
+
return h(
|
|
4071
|
+
"div",
|
|
4072
|
+
{ className: cls("mesh-switch-row", off && "is-off"), "data-mesh-switch": row.scope },
|
|
4073
|
+
h("span", { className: "mesh-switch-row-icon" }, h(Icon, { name: row.icon, size: 15 })),
|
|
4074
|
+
h(
|
|
4075
|
+
"div",
|
|
4076
|
+
{ className: "mesh-switch-row-main" },
|
|
4077
|
+
h(
|
|
4078
|
+
"div",
|
|
4079
|
+
{ className: "mesh-switch-row-top" },
|
|
4080
|
+
h("span", { className: "mesh-switch-row-title" }, row.title),
|
|
4081
|
+
h(Badge, { kind: off ? "warn" : "ok" }, badge),
|
|
4082
|
+
),
|
|
4083
|
+
h("div", { className: "mesh-switch-row-desc" }, row.desc),
|
|
4084
|
+
meta ? h("div", { className: "mesh-switch-row-meta" }, meta) : null,
|
|
4085
|
+
note ? h("div", { className: "mesh-note is-warn", style: { marginTop: 8 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, note)) : null,
|
|
4086
|
+
),
|
|
4087
|
+
h(
|
|
4088
|
+
"div",
|
|
4089
|
+
{ className: "mesh-switch-row-action" },
|
|
4090
|
+
h(
|
|
4091
|
+
Button,
|
|
4092
|
+
{
|
|
4093
|
+
variant: off ? "secondary" : "danger",
|
|
4094
|
+
size: "sm",
|
|
4095
|
+
icon: off ? "check" : "power",
|
|
4096
|
+
loading: busy,
|
|
4097
|
+
onClick: () => onToggle(row.scope, !off),
|
|
4098
|
+
},
|
|
4099
|
+
off ? "打开" : `一键关闭${row.scope === "all" ? " Mesh" : ""}`,
|
|
4100
|
+
),
|
|
4101
|
+
),
|
|
4102
|
+
);
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
function SwitchBody({ sw, push, reload }) {
|
|
4106
|
+
const st = sw || {};
|
|
4107
|
+
const lan = st.lan || {};
|
|
4108
|
+
const net = st.internet || {};
|
|
4109
|
+
const [busy, setBusy] = react.useState("");
|
|
4110
|
+
const [error, setError] = react.useState("");
|
|
4111
|
+
|
|
4112
|
+
const apply = async (scope, off) => {
|
|
4113
|
+
setBusy(scope);
|
|
4114
|
+
setError("");
|
|
4115
|
+
try {
|
|
4116
|
+
const r = await api("/switch", { scope, off });
|
|
4117
|
+
if (r && r.ok) {
|
|
4118
|
+
const label = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
|
|
4119
|
+
push(
|
|
4120
|
+
"success",
|
|
4121
|
+
`${label}已${off ? "关闭" : "打开"}${r.changed === false ? "(本来就是这个状态)" : ""}`,
|
|
4122
|
+
// 误点一键关闭时,"撤销"要在一处就能点回来,而不是去翻三个开关
|
|
4123
|
+
{ label: "撤销", onClick: () => apply(scope, !off) },
|
|
4124
|
+
);
|
|
4125
|
+
await reload();
|
|
4126
|
+
} else {
|
|
4127
|
+
setError(apiErr(r));
|
|
4128
|
+
}
|
|
4129
|
+
} catch (e) {
|
|
4130
|
+
setError(String((e && e.message) || e));
|
|
4131
|
+
} finally {
|
|
4132
|
+
setBusy("");
|
|
4133
|
+
}
|
|
4134
|
+
};
|
|
4135
|
+
|
|
4136
|
+
const LAN_META = () =>
|
|
4137
|
+
lan.off
|
|
4138
|
+
? `对端端口${lan.port ? ` ${lan.bind || "回环"}:${lan.port}` : "已停"} · 组播已停`
|
|
4139
|
+
: `监听 ${lan.bind || "—"}:${lan.port || "—"} · 组播 ${lan.multicast ? "开" : "关"}`;
|
|
4140
|
+
const NET_META = () =>
|
|
4141
|
+
`运行中 ${net.running || 0} / 已启用 ${net.configured || 0} 条通道` + (net.off ? " · sidecar 已停" : "");
|
|
4142
|
+
|
|
4143
|
+
// 「全部」这一行不能复用单条的 active:两条都开着才叫全部开启,
|
|
4144
|
+
// 只关了一条要显示「部分关闭」而不是含糊的「开启」。
|
|
4145
|
+
const partial = !st.all && (!!lan.off || !!net.off);
|
|
4146
|
+
const values = {
|
|
4147
|
+
all: {
|
|
4148
|
+
off: !!st.all,
|
|
4149
|
+
badge: st.all ? "已关闭" : partial ? "部分关闭" : "全部开启",
|
|
4150
|
+
meta: `${lan.off ? "局域网已关" : "局域网开着"} · ${net.off ? "互联网已关" : "互联网开着"}`,
|
|
4151
|
+
},
|
|
4152
|
+
lan: { off: !!lan.off, badge: lan.off ? "已关闭" : lan.active ? "运行中" : "开启(未监听)", meta: LAN_META(), note: lan.note || "" },
|
|
4153
|
+
internet: {
|
|
4154
|
+
off: !!net.off,
|
|
4155
|
+
badge: net.off ? "已关闭" : net.active ? "运行中" : net.stalled ? "启动受阻" : "开启(未连接)",
|
|
4156
|
+
meta: NET_META(),
|
|
4157
|
+
note: net.note || "",
|
|
4158
|
+
},
|
|
4159
|
+
};
|
|
4160
|
+
|
|
4161
|
+
return h(
|
|
4162
|
+
"div",
|
|
4163
|
+
null,
|
|
4164
|
+
h(
|
|
4165
|
+
"p",
|
|
4166
|
+
{ className: "mesh-p", style: { marginBottom: 4 } },
|
|
4167
|
+
"关闭立即生效,并写入本机状态 —— 重启 DSH 后仍保持关闭,直到在这里打开。面板本身始终可用。",
|
|
4168
|
+
),
|
|
4169
|
+
error ? h("div", { className: "mesh-note is-err", style: { marginTop: 10 } }, h(Icon, { name: "alert", size: 13 }), h("span", null, error)) : null,
|
|
4170
|
+
h(
|
|
4171
|
+
"div",
|
|
4172
|
+
{ className: "mesh-switch-list" },
|
|
4173
|
+
MESH_SWITCH_ROWS.map((row) =>
|
|
4174
|
+
h(SwitchRow, {
|
|
4175
|
+
key: row.scope,
|
|
4176
|
+
row,
|
|
4177
|
+
off: values[row.scope].off,
|
|
4178
|
+
badge: values[row.scope].badge,
|
|
4179
|
+
meta: values[row.scope].meta,
|
|
4180
|
+
note: values[row.scope].note,
|
|
4181
|
+
busy: busy === row.scope,
|
|
4182
|
+
onToggle: apply,
|
|
4183
|
+
}),
|
|
4184
|
+
),
|
|
4185
|
+
),
|
|
4186
|
+
st.by
|
|
4187
|
+
? h("p", { className: "mesh-hint", style: { marginTop: 10 } }, `最近一次操作:${st.at ? new Date(st.at).toLocaleString() : "—"}(${st.by === "tool" ? "agent 调用" : st.by === "ui" ? "界面" : st.by})`)
|
|
4188
|
+
: null,
|
|
4189
|
+
);
|
|
4190
|
+
}
|
|
4191
|
+
|
|
3958
4192
|
function SettingsSection({ id, icon, title, subtitle, status, open, onToggle, children }) {
|
|
3959
4193
|
return h(
|
|
3960
4194
|
"section",
|
|
@@ -4208,85 +4442,187 @@ window.__ModuleLoader__.load({
|
|
|
4208
4442
|
);
|
|
4209
4443
|
}
|
|
4210
4444
|
|
|
4445
|
+
/** 单条通道的阶段 → 文案/颜色。 */
|
|
4446
|
+
function channelPhase(ch) {
|
|
4447
|
+
const p = ch && ch.node && ch.node.phase ? ch.node.phase : ch && ch.enabled ? "idle" : "off";
|
|
4448
|
+
// 卡在控制面上时 phase 仍然会是 starting —— 光看 phase 会一直显示「正在启动」。
|
|
4449
|
+
// node.stalled 是宿主按时间+证据给的结论,优先级更高(真机反馈 2026-10-29)。
|
|
4450
|
+
const stalled = !!(ch && ch.node && ch.node.stalled);
|
|
4451
|
+
const map = {
|
|
4452
|
+
off: ["未启用", "idle"],
|
|
4453
|
+
idle: ["未连接", "idle"],
|
|
4454
|
+
starting: ["正在启动", "warn"],
|
|
4455
|
+
downloading: ["正在下载组件", "warn"],
|
|
4456
|
+
"needs-login": ["需要授权", "warn"],
|
|
4457
|
+
stalled: ["启动受阻", "err"],
|
|
4458
|
+
running: ["已连接", "ok"],
|
|
4459
|
+
exited: ["已停止", "idle"],
|
|
4460
|
+
error: ["出错", "err"],
|
|
4461
|
+
};
|
|
4462
|
+
const key = stalled && p !== "running" ? "stalled" : p;
|
|
4463
|
+
const m = map[key] || [p, "idle"];
|
|
4464
|
+
return { phase: key, label: m[0], kind: m[1] };
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
/**
|
|
4468
|
+
* 汇总多条 tailnet 通道的状态。
|
|
4469
|
+
*
|
|
4470
|
+
* 多 tailnet 之后"连上没连上"不再是一个布尔值:3 条通道里连上 2 条,
|
|
4471
|
+
* 既要显示"已连接",又要让用户看见还差一条。所以标签带分数。
|
|
4472
|
+
*/
|
|
4211
4473
|
function tsnetPhase(tsnet) {
|
|
4212
|
-
|
|
4213
|
-
const
|
|
4474
|
+
if (!tsnet) return { phase: "off", label: "未启用", kind: "idle", channels: [], running: 0 };
|
|
4475
|
+
const channels = Array.isArray(tsnet.channels) ? tsnet.channels.slice() : [];
|
|
4476
|
+
// 旧主机只有单节点字段:合成一个通道视图,界面逻辑不分叉
|
|
4477
|
+
if (channels.length === 0 && tsnet.node) {
|
|
4478
|
+
channels.push({
|
|
4479
|
+
id: "default",
|
|
4480
|
+
label: "Tailscale",
|
|
4481
|
+
enabled: tsnet.enabled === true,
|
|
4482
|
+
authKeySaved: tsnet.authKeySaved === true,
|
|
4483
|
+
controlUrl: tsnet.controlUrl || "",
|
|
4484
|
+
hostname: (tsnet.node && tsnet.node.hostname) || "",
|
|
4485
|
+
node: tsnet.node,
|
|
4486
|
+
recentEvents: tsnet.recentEvents || [],
|
|
4487
|
+
});
|
|
4488
|
+
}
|
|
4489
|
+
const phases = channels.map((c) => channelPhase(c).phase);
|
|
4490
|
+
const running = phases.filter((p) => p === "running").length;
|
|
4491
|
+
let phase = tsnet.enabled ? "idle" : "off";
|
|
4492
|
+
if (running > 0) phase = "running";
|
|
4493
|
+
else if (phases.includes("needs-login")) phase = "needs-login";
|
|
4494
|
+
else if (phases.includes("downloading")) phase = "downloading";
|
|
4495
|
+
else if (phases.includes("stalled")) phase = "stalled";
|
|
4496
|
+
else if (phases.includes("starting")) phase = "starting";
|
|
4497
|
+
else if (phases.includes("error")) phase = "error";
|
|
4498
|
+
else if (phases.includes("exited")) phase = "exited";
|
|
4499
|
+
else if (channels.length === 0) phase = tsnet.enabled ? "idle" : "off";
|
|
4500
|
+
const base = channelPhase({ enabled: tsnet.enabled, node: null });
|
|
4214
4501
|
const map = {
|
|
4215
4502
|
off: ["未启用", "idle"],
|
|
4216
4503
|
idle: ["已启用 · 未启动", "idle"],
|
|
4217
4504
|
starting: ["正在启动", "warn"],
|
|
4218
4505
|
downloading: ["正在下载组件", "warn"],
|
|
4219
4506
|
"needs-login": ["需要授权", "warn"],
|
|
4507
|
+
stalled: ["启动受阻", "err"],
|
|
4220
4508
|
running: ["已连接", "ok"],
|
|
4221
4509
|
exited: ["已停止", "idle"],
|
|
4222
4510
|
error: ["出错", "err"],
|
|
4223
4511
|
};
|
|
4224
|
-
|
|
4512
|
+
const m = map[phase] || base;
|
|
4513
|
+
let label = m[0];
|
|
4514
|
+
if (phase === "running" && channels.length > 1) label = `已连接 ${running}/${channels.length} 条`;
|
|
4515
|
+
return { phase, label, kind: m[1], channels, running };
|
|
4516
|
+
}
|
|
4517
|
+
|
|
4518
|
+
/** 通道列表的公共视图:旧主机没有 channels 时用旧字段兜底。 */
|
|
4519
|
+
function tsnetChannelsOf(tsnet) {
|
|
4520
|
+
const list = tsnet && Array.isArray(tsnet.channels) ? tsnet.channels.slice() : [];
|
|
4521
|
+
if (list.length > 0) return list;
|
|
4522
|
+
if (tsnet && tsnet.node) {
|
|
4523
|
+
return [
|
|
4524
|
+
{
|
|
4525
|
+
id: "default",
|
|
4526
|
+
label: "Tailscale",
|
|
4527
|
+
enabled: tsnet.enabled === true,
|
|
4528
|
+
authKeySaved: tsnet.authKeySaved === true,
|
|
4529
|
+
controlUrl: tsnet.controlUrl || "",
|
|
4530
|
+
hostname: (tsnet.node && tsnet.node.hostname) || "",
|
|
4531
|
+
node: tsnet.node,
|
|
4532
|
+
recentEvents: tsnet.recentEvents || [],
|
|
4533
|
+
},
|
|
4534
|
+
];
|
|
4535
|
+
}
|
|
4536
|
+
return [];
|
|
4537
|
+
}
|
|
4538
|
+
|
|
4539
|
+
/** 已连接通道的 tailnet 地址(供设置页/卡片显示一行摘要)。 */
|
|
4540
|
+
function tsnetAddressList(tsnet) {
|
|
4541
|
+
return tsnetChannelsOf(tsnet)
|
|
4542
|
+
.filter((c) => c.node && c.node.phase === "running")
|
|
4543
|
+
.map((c) => (c.node && c.node.selfIpv4) || "")
|
|
4544
|
+
.filter(Boolean);
|
|
4225
4545
|
}
|
|
4226
4546
|
|
|
4227
4547
|
function TsnetBody({ tsnet, push, reload }) {
|
|
4228
|
-
const [key, setKey] = react.useState("");
|
|
4229
|
-
const [controlUrl, setControlUrl] = react.useState((tsnet && tsnet.controlUrl) || "");
|
|
4230
4548
|
const [busy, setBusy] = react.useState("");
|
|
4231
4549
|
const [error, setError] = react.useState("");
|
|
4232
|
-
|
|
4233
|
-
react.
|
|
4234
|
-
|
|
4235
|
-
}, [tsnet && tsnet.controlUrl]);
|
|
4550
|
+
const [draftLabel, setDraftLabel] = react.useState("");
|
|
4551
|
+
const [draftKey, setDraftKey] = react.useState("");
|
|
4552
|
+
const [draftControl, setDraftControl] = react.useState("");
|
|
4236
4553
|
|
|
4237
4554
|
if (!tsnet) {
|
|
4238
4555
|
return h("p", { className: "mesh-p" }, "当前主机版本还没有跨网络组网能力。升级插件后会出现在这里。");
|
|
4239
4556
|
}
|
|
4240
4557
|
|
|
4241
|
-
const
|
|
4558
|
+
const channels = tsnetChannelsOf(tsnet);
|
|
4242
4559
|
const phase = tsnetPhase(tsnet);
|
|
4243
|
-
const running = phase.
|
|
4244
|
-
const events = (
|
|
4245
|
-
const canConnect = !!(tsnet.authKeySaved || key.trim());
|
|
4560
|
+
const running = phase.running;
|
|
4561
|
+
const events = (channels.find((c) => c.node && c.node.phase === "running")?.recentEvents || channels[0]?.recentEvents || tsnet.recentEvents || []).slice(-6);
|
|
4246
4562
|
|
|
4247
|
-
const
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
return;
|
|
4251
|
-
}
|
|
4252
|
-
setBusy("connect");
|
|
4563
|
+
const run = async (path, body, okText) => {
|
|
4564
|
+
const tag = `${path}${body && body.id ? `:${body.id}` : ""}`;
|
|
4565
|
+
setBusy(tag);
|
|
4253
4566
|
setError("");
|
|
4254
4567
|
try {
|
|
4255
|
-
const
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
if (!saved || !saved.ok) {
|
|
4261
|
-
setError(`保存失败:${apiErr(saved)}`);
|
|
4262
|
-
return;
|
|
4263
|
-
}
|
|
4264
|
-
setKey("");
|
|
4265
|
-
const started = await api("/tsnet/start", {});
|
|
4266
|
-
if (started && started.ok) {
|
|
4267
|
-
push("success", "已开始连接。授权码只保存在本机,之后不用再填。");
|
|
4268
|
-
} else {
|
|
4269
|
-
push("error", `启动失败:${apiErr(started)}`);
|
|
4568
|
+
const r = await api(path, body || {});
|
|
4569
|
+
if (r && r.ok) {
|
|
4570
|
+
push("success", okText || "完成");
|
|
4571
|
+
await reload();
|
|
4572
|
+
return r;
|
|
4270
4573
|
}
|
|
4271
|
-
|
|
4574
|
+
setError(apiErr(r));
|
|
4575
|
+
return r;
|
|
4272
4576
|
} catch (e) {
|
|
4273
4577
|
setError(String((e && e.message) || e));
|
|
4578
|
+
return null;
|
|
4274
4579
|
} finally {
|
|
4275
4580
|
setBusy("");
|
|
4276
4581
|
}
|
|
4277
4582
|
};
|
|
4278
4583
|
|
|
4279
|
-
|
|
4280
|
-
|
|
4584
|
+
// 保存通道列表时只回传非敏感字段;授权码留空 = 保留原值(宿主按 id 合并)。
|
|
4585
|
+
const payloadOf = (list) =>
|
|
4586
|
+
list.map((c) => ({
|
|
4587
|
+
id: c.id,
|
|
4588
|
+
label: c.label,
|
|
4589
|
+
controlUrl: c.controlUrl || "",
|
|
4590
|
+
hostname: c.hostname || "",
|
|
4591
|
+
enabled: c.enabled !== false,
|
|
4592
|
+
}));
|
|
4593
|
+
|
|
4594
|
+
const addChannel = async () => {
|
|
4595
|
+
if (!draftKey.trim()) {
|
|
4596
|
+
setError("先填入授权码。");
|
|
4597
|
+
return;
|
|
4598
|
+
}
|
|
4599
|
+
setBusy("add");
|
|
4281
4600
|
setError("");
|
|
4282
4601
|
try {
|
|
4283
|
-
const
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4602
|
+
const next = [
|
|
4603
|
+
...payloadOf(channels),
|
|
4604
|
+
{
|
|
4605
|
+
label: draftLabel.trim() || `Tailnet ${channels.length + 1}`,
|
|
4606
|
+
authKey: draftKey.trim(),
|
|
4607
|
+
controlUrl: draftControl.trim(),
|
|
4608
|
+
enabled: true,
|
|
4609
|
+
},
|
|
4610
|
+
];
|
|
4611
|
+
const saved = await api("/tsnet/config", { channels: next });
|
|
4612
|
+
if (!saved || !saved.ok) {
|
|
4613
|
+
setError(`保存失败:${apiErr(saved)}`);
|
|
4614
|
+
return;
|
|
4615
|
+
}
|
|
4616
|
+
const created = (saved.channels || []).find((c) => !channels.some((x) => x.id === c.id));
|
|
4617
|
+
if (created) {
|
|
4618
|
+
const started = await api("/tsnet/start", { id: created.id });
|
|
4619
|
+
if (started && started.ok) push("success", `通道「${created.label}」已开始连接。授权码只保存在本机。`);
|
|
4620
|
+
else push("error", `通道已保存,但启动失败:${apiErr(started)}`);
|
|
4289
4621
|
}
|
|
4622
|
+
setDraftLabel("");
|
|
4623
|
+
setDraftKey("");
|
|
4624
|
+
setDraftControl("");
|
|
4625
|
+
await reload();
|
|
4290
4626
|
} catch (e) {
|
|
4291
4627
|
setError(String((e && e.message) || e));
|
|
4292
4628
|
} finally {
|
|
@@ -4294,60 +4630,171 @@ window.__ModuleLoader__.load({
|
|
|
4294
4630
|
}
|
|
4295
4631
|
};
|
|
4296
4632
|
|
|
4633
|
+
const removeChannel = async (ch) => {
|
|
4634
|
+
const next = payloadOf(channels.filter((c) => c.id !== ch.id));
|
|
4635
|
+
// 最后一条也允许删:宿主会顺带清掉旧版单通道字段并关闭组网,
|
|
4636
|
+
// 否则"删不掉、也关不干净"会变成又一处静默残留。
|
|
4637
|
+
await run(
|
|
4638
|
+
"/tsnet/config",
|
|
4639
|
+
{ channels: next },
|
|
4640
|
+
next.length === 0 ? "所有通道已删除,跨网络组网已关闭" : `通道「${ch.label || ch.id}」已删除`,
|
|
4641
|
+
);
|
|
4642
|
+
};
|
|
4643
|
+
|
|
4644
|
+
const updateEnabled = async (ch, enabled) => {
|
|
4645
|
+
const next = payloadOf(channels).map((c) => (c.id === ch.id ? { ...c, enabled } : c));
|
|
4646
|
+
await run("/tsnet/config", { channels: next }, enabled ? "通道已启用" : "通道已停用");
|
|
4647
|
+
};
|
|
4648
|
+
|
|
4297
4649
|
return h(
|
|
4298
4650
|
"div",
|
|
4299
4651
|
null,
|
|
4300
4652
|
h(
|
|
4301
4653
|
"p",
|
|
4302
4654
|
{ className: "mesh-p", style: { marginBottom: 12 } },
|
|
4303
|
-
"让不在同一网络的电脑也能互相派发任务。使用同一套设备列表,不需要另装 Tailscale
|
|
4655
|
+
"让不在同一网络的电脑也能互相派发任务。使用同一套设备列表,不需要另装 Tailscale 客户端。一台机器可以同时加入多个 tailnet:设备身份仍然只有一个,每条通道只是它的一条路。",
|
|
4304
4656
|
),
|
|
4305
|
-
|
|
4657
|
+
channels.length === 0
|
|
4306
4658
|
? h(
|
|
4307
4659
|
"div",
|
|
4308
|
-
{ className: "mesh-note
|
|
4309
|
-
h(Icon, { name: "
|
|
4660
|
+
{ className: "mesh-note" },
|
|
4661
|
+
h(Icon, { name: "key", size: 13 }),
|
|
4310
4662
|
h("span", null,
|
|
4311
|
-
"
|
|
4312
|
-
h("a", { href:
|
|
4663
|
+
"还没有配置 tailnet 通道。需要一个 Tailscale 授权码:打开 ",
|
|
4664
|
+
h("a", { href: TS_KEYS_URL, target: "_blank", rel: "noreferrer" }, TS_KEYS_URL),
|
|
4665
|
+
" 登录后点 Generate auth key;生成时勾选 Reusable,如果后台开了设备审批再勾 Pre-approved。",
|
|
4313
4666
|
),
|
|
4314
4667
|
)
|
|
4315
4668
|
: null,
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
h("span", null, String(node.error)),
|
|
4322
|
-
)
|
|
4323
|
-
: null,
|
|
4324
|
-
phase.phase === "downloading"
|
|
4325
|
-
? h(
|
|
4326
|
-
"div",
|
|
4327
|
-
{ className: "mesh-note" },
|
|
4328
|
-
h("span", { className: "mesh-spinner" }),
|
|
4329
|
-
h("span", null, `正在下载组件${node && node.downloadPercent ? ` · ${node.downloadPercent}%` : ""}。第一次使用会稍慢,之后不再下载。`),
|
|
4330
|
-
)
|
|
4331
|
-
: null,
|
|
4332
|
-
h(
|
|
4333
|
-
Collapse,
|
|
4334
|
-
{ open: running },
|
|
4335
|
-
h(
|
|
4669
|
+
channels.map((ch) => {
|
|
4670
|
+
const cp = channelPhase(ch);
|
|
4671
|
+
const node = ch.node || null;
|
|
4672
|
+
const isBusy = !!busy;
|
|
4673
|
+
return h(
|
|
4336
4674
|
"div",
|
|
4337
|
-
{ className: "mesh-channel" },
|
|
4338
|
-
h("span", { className: "mesh-channel-icon" }, h(Icon, { name: "tailscale", size: 14 })),
|
|
4675
|
+
{ key: ch.id, className: "mesh-channel-card", style: { marginBottom: 10 } },
|
|
4339
4676
|
h(
|
|
4340
|
-
"
|
|
4341
|
-
{ className: "mesh-channel
|
|
4342
|
-
h("span", { className: "mesh-channel-
|
|
4343
|
-
h(
|
|
4677
|
+
"div",
|
|
4678
|
+
{ className: "mesh-channel" },
|
|
4679
|
+
h("span", { className: "mesh-channel-icon" }, h(Icon, { name: "tailscale", size: 14 })),
|
|
4680
|
+
h(
|
|
4681
|
+
"span",
|
|
4682
|
+
{ className: "mesh-channel-main" },
|
|
4683
|
+
h(
|
|
4684
|
+
"span",
|
|
4685
|
+
{ className: "mesh-channel-title" },
|
|
4686
|
+
ch.label || "Tailscale",
|
|
4687
|
+
h(Badge, { kind: cp.kind }, cp.label),
|
|
4688
|
+
ch.id !== "default" ? h("span", { className: "mesh-channel-sub", style: { marginLeft: 6 } }, ch.id) : null,
|
|
4689
|
+
),
|
|
4690
|
+
h(
|
|
4691
|
+
"span",
|
|
4692
|
+
{ className: "mesh-channel-sub" },
|
|
4693
|
+
node && node.selfIpv4
|
|
4694
|
+
? [node.selfIpv4, node.selfDnsName].filter(Boolean).join(" · ")
|
|
4695
|
+
: ch.authKeySaved
|
|
4696
|
+
? `已保存授权码${ch.controlUrl ? ` · ${ch.controlUrl}` : " · 官方 Tailscale"}`
|
|
4697
|
+
: "未设置授权码",
|
|
4698
|
+
),
|
|
4699
|
+
),
|
|
4700
|
+
cp.phase === "running"
|
|
4701
|
+
? h(
|
|
4702
|
+
Button,
|
|
4703
|
+
{
|
|
4704
|
+
variant: "ghost",
|
|
4705
|
+
size: "sm",
|
|
4706
|
+
loading: busy === `/tsnet/stop:${ch.id}`,
|
|
4707
|
+
disabled: isBusy && busy !== `/tsnet/stop:${ch.id}`,
|
|
4708
|
+
onClick: () => run("/tsnet/stop", { id: ch.id }, `通道「${ch.label || ch.id}」已断开`),
|
|
4709
|
+
},
|
|
4710
|
+
"断开",
|
|
4711
|
+
)
|
|
4712
|
+
: h(
|
|
4713
|
+
Button,
|
|
4714
|
+
{
|
|
4715
|
+
variant: "ghost",
|
|
4716
|
+
size: "sm",
|
|
4717
|
+
loading: busy === `/tsnet/start:${ch.id}`,
|
|
4718
|
+
disabled: isBusy && busy !== `/tsnet/start:${ch.id}`,
|
|
4719
|
+
onClick: () => run("/tsnet/start", { id: ch.id }, `通道「${ch.label || ch.id}」已启动`),
|
|
4720
|
+
},
|
|
4721
|
+
cp.phase === "stalled" ? "重试连接" : "连接",
|
|
4722
|
+
),
|
|
4344
4723
|
),
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4724
|
+
node && node.authUrl
|
|
4725
|
+
? h(
|
|
4726
|
+
"div",
|
|
4727
|
+
{ className: "mesh-note is-warn" },
|
|
4728
|
+
h(Icon, { name: "alert", size: 13 }),
|
|
4729
|
+
h("span", null,
|
|
4730
|
+
"这条通道需要你授权加入 tailnet:",
|
|
4731
|
+
h("a", { href: node.authUrl, target: "_blank", rel: "noreferrer", style: { marginLeft: 4, wordBreak: "break-all" } }, "打开授权页"),
|
|
4732
|
+
),
|
|
4733
|
+
)
|
|
4734
|
+
: null,
|
|
4735
|
+
node && node.stalled
|
|
4736
|
+
? h(
|
|
4737
|
+
"div",
|
|
4738
|
+
{ className: "mesh-note is-err" },
|
|
4739
|
+
h(Icon, { name: "alert", size: 13 }),
|
|
4740
|
+
h(
|
|
4741
|
+
"span",
|
|
4742
|
+
null,
|
|
4743
|
+
`启动受阻:${node.stalledReason || "控制面一直没有回应"}`,
|
|
4744
|
+
node.stalledHint ? h("div", { className: "mesh-hint", style: { marginTop: 4 } }, node.stalledHint) : null,
|
|
4745
|
+
),
|
|
4746
|
+
)
|
|
4747
|
+
: null,
|
|
4748
|
+
node && node.error
|
|
4749
|
+
? h(
|
|
4750
|
+
"div",
|
|
4751
|
+
{ className: "mesh-note is-err" },
|
|
4752
|
+
h(Icon, { name: "alert", size: 13 }),
|
|
4753
|
+
h("span", null, String(node.error)),
|
|
4754
|
+
)
|
|
4755
|
+
: null,
|
|
4756
|
+
cp.phase === "downloading"
|
|
4757
|
+
? h(
|
|
4758
|
+
"div",
|
|
4759
|
+
{ className: "mesh-note" },
|
|
4760
|
+
h("span", { className: "mesh-spinner" }),
|
|
4761
|
+
h("span", null, `正在下载组件${node && node.downloadPercent ? ` · ${node.downloadPercent}%` : ""}。第一次使用会稍慢,之后不再下载。`),
|
|
4762
|
+
)
|
|
4763
|
+
: null,
|
|
4764
|
+
h(
|
|
4765
|
+
Fold,
|
|
4766
|
+
{ title: "通道设置", right: ch.controlUrl ? "自定义控制服务器" : "官方 Tailscale" },
|
|
4767
|
+
h(
|
|
4768
|
+
"dl",
|
|
4769
|
+
{ className: "mesh-kv" },
|
|
4770
|
+
h("dt", null, "通道 id"), h("dd", null, ch.id),
|
|
4771
|
+
h("dt", null, "节点名"), h("dd", null, (node && node.hostname) || ch.hostname || "—"),
|
|
4772
|
+
h("dt", null, "控制服务器"), h("dd", null, ch.controlUrl || "官方"),
|
|
4773
|
+
h("dt", null, "授权码"), h("dd", null, ch.authKeySaved ? "已保存(不会显示内容)" : "未设置"),
|
|
4774
|
+
),
|
|
4775
|
+
h(
|
|
4776
|
+
"div",
|
|
4777
|
+
{ className: "mesh-actions-row" },
|
|
4778
|
+
h(Button, { variant: "ghost", size: "sm", disabled: !!busy || cp.phase !== "running", loading: busy === `/tsnet/scan:${ch.id}`, onClick: () => run("/tsnet/scan", { id: ch.id }, "已扫描该通道") }, "扫描该通道"),
|
|
4779
|
+
h(ConfirmButton, {
|
|
4780
|
+
label: "重新登录",
|
|
4781
|
+
confirmLabel: "确认清除身份?",
|
|
4782
|
+
disabled: !!busy || !ch.authKeySaved,
|
|
4783
|
+
onConfirm: () => run("/tsnet/relogin", { id: ch.id }, "已清除节点身份,等待重新授权"),
|
|
4784
|
+
}),
|
|
4785
|
+
h(ConfirmButton, {
|
|
4786
|
+
label: "删除通道",
|
|
4787
|
+
confirmLabel: "确认删除?",
|
|
4788
|
+
disabled: !!busy,
|
|
4789
|
+
onConfirm: () => removeChannel(ch),
|
|
4790
|
+
}),
|
|
4791
|
+
),
|
|
4792
|
+
),
|
|
4793
|
+
);
|
|
4794
|
+
}),
|
|
4348
4795
|
h(
|
|
4349
|
-
|
|
4350
|
-
{
|
|
4796
|
+
Fold,
|
|
4797
|
+
{ title: channels.length ? "添加通道" : "配置第一条通道", right: "多 tailnet", defaultOpen: channels.length === 0 },
|
|
4351
4798
|
h(
|
|
4352
4799
|
"div",
|
|
4353
4800
|
null,
|
|
@@ -4356,21 +4803,39 @@ window.__ModuleLoader__.load({
|
|
|
4356
4803
|
{ className: "mesh-note" },
|
|
4357
4804
|
h(Icon, { name: "key", size: 13 }),
|
|
4358
4805
|
h("span", null,
|
|
4359
|
-
"
|
|
4360
|
-
h("a", { href: TS_KEYS_URL, target: "_blank", rel: "noreferrer" }, TS_KEYS_URL),
|
|
4361
|
-
" 登录后点 Generate auth key;生成时勾选 Reusable,如果后台开了设备审批再勾 Pre-approved。",
|
|
4806
|
+
"每条通道对应一个 tailnet(一把 tskey 一把钥匙,但可以加多条)。名称只用于本机显示;重命名不影响设备身份。",
|
|
4362
4807
|
),
|
|
4363
4808
|
),
|
|
4364
4809
|
h(
|
|
4365
4810
|
Field,
|
|
4366
|
-
{ label: "
|
|
4811
|
+
{ label: "名称(可选)", hint: "例如「个人」「公司」;留空自动命名。" },
|
|
4812
|
+
h("input", {
|
|
4813
|
+
className: "mesh-input",
|
|
4814
|
+
value: draftLabel,
|
|
4815
|
+
placeholder: "公司 tailnet",
|
|
4816
|
+
onChange: (e) => setDraftLabel(e.target.value),
|
|
4817
|
+
}),
|
|
4818
|
+
),
|
|
4819
|
+
h(
|
|
4820
|
+
Field,
|
|
4821
|
+
{ label: "授权码", hint: "只保存在本机;粘贴新值会新增一条通道。" },
|
|
4367
4822
|
h("input", {
|
|
4368
4823
|
className: "mesh-input",
|
|
4369
4824
|
type: "password",
|
|
4370
4825
|
autoComplete: "off",
|
|
4371
|
-
value:
|
|
4372
|
-
placeholder:
|
|
4373
|
-
onChange: (e) =>
|
|
4826
|
+
value: draftKey,
|
|
4827
|
+
placeholder: "tskey-auth-…",
|
|
4828
|
+
onChange: (e) => setDraftKey(e.target.value),
|
|
4829
|
+
}),
|
|
4830
|
+
),
|
|
4831
|
+
h(
|
|
4832
|
+
Field,
|
|
4833
|
+
{ label: "控制服务器(可选)", hint: "留空用官方 Tailscale;Headscale 用户填自己的地址。" },
|
|
4834
|
+
h("input", {
|
|
4835
|
+
className: "mesh-input",
|
|
4836
|
+
value: draftControl,
|
|
4837
|
+
placeholder: "https://controlplane.tailscale.com",
|
|
4838
|
+
onChange: (e) => setDraftControl(e.target.value),
|
|
4374
4839
|
}),
|
|
4375
4840
|
),
|
|
4376
4841
|
h(
|
|
@@ -4378,44 +4843,24 @@ window.__ModuleLoader__.load({
|
|
|
4378
4843
|
{ className: "mesh-actions-row" },
|
|
4379
4844
|
h(
|
|
4380
4845
|
Button,
|
|
4381
|
-
{ variant: "primary", icon: "plug", loading: busy === "
|
|
4382
|
-
|
|
4846
|
+
{ variant: "primary", icon: "plug", loading: busy === "add", disabled: !!busy || !draftKey.trim(), onClick: addChannel },
|
|
4847
|
+
"添加并连接",
|
|
4383
4848
|
),
|
|
4384
|
-
tsnet.enabled && !running && tsnet.authKeySaved
|
|
4385
|
-
? h(Button, { variant: "ghost", loading: busy === "/tsnet/start", onClick: () => runNode("/tsnet/start", "已启动") }, "只启动")
|
|
4386
|
-
: null,
|
|
4387
4849
|
),
|
|
4388
4850
|
),
|
|
4389
4851
|
),
|
|
4390
4852
|
h(
|
|
4391
4853
|
Fold,
|
|
4392
|
-
{ title: "
|
|
4393
|
-
h(
|
|
4394
|
-
Field,
|
|
4395
|
-
{ label: "控制服务器", hint: "留空用官方 Tailscale;Headscale 用户填自己的地址。修改后点“保存并重启”。" },
|
|
4396
|
-
h("input", {
|
|
4397
|
-
className: "mesh-input",
|
|
4398
|
-
value: controlUrl,
|
|
4399
|
-
placeholder: "https://controlplane.tailscale.com",
|
|
4400
|
-
onChange: (e) => setControlUrl(e.target.value),
|
|
4401
|
-
}),
|
|
4402
|
-
),
|
|
4854
|
+
{ title: "维护", right: running ? "扫描与组件" : undefined },
|
|
4403
4855
|
h(
|
|
4404
4856
|
"div",
|
|
4405
4857
|
{ className: "mesh-actions-row" },
|
|
4406
|
-
h(Button, { variant: "ghost", size: "sm", disabled:
|
|
4407
|
-
h(Button, { variant: "ghost", size: "sm", disabled: !canConnect || !!busy, loading: busy === "connect", onClick: saveAndConnect }, "保存并重启"),
|
|
4408
|
-
h(ConfirmButton, {
|
|
4409
|
-
label: "重新登录",
|
|
4410
|
-
confirmLabel: "确认清除身份?",
|
|
4411
|
-
disabled: !tsnet.enabled || !!busy,
|
|
4412
|
-
onConfirm: () => runNode("/tsnet/relogin", "已清除节点身份,等待重新授权"),
|
|
4413
|
-
}),
|
|
4858
|
+
h(Button, { variant: "ghost", size: "sm", disabled: !!busy || running === 0, loading: busy === "/tsnet/scan", onClick: () => run("/tsnet/scan", {}, "已扫描所有通道") }, "扫描所有通道"),
|
|
4414
4859
|
h(ConfirmButton, {
|
|
4415
4860
|
label: "重新下载组件",
|
|
4416
4861
|
confirmLabel: "确认重新下载?",
|
|
4417
|
-
disabled:
|
|
4418
|
-
onConfirm: () =>
|
|
4862
|
+
disabled: !!busy,
|
|
4863
|
+
onConfirm: () => run("/tsnet/reinstall", {}, "已重新下载组件"),
|
|
4419
4864
|
}),
|
|
4420
4865
|
),
|
|
4421
4866
|
events.length
|
|
@@ -4478,8 +4923,20 @@ window.__ModuleLoader__.load({
|
|
|
4478
4923
|
const self = (state && state.self) || {};
|
|
4479
4924
|
const cfg = (state && state.config) || {};
|
|
4480
4925
|
const tsnet = state && state.tsnet;
|
|
4926
|
+
const sw = state && state.switch;
|
|
4481
4927
|
const phase = tsnetPhase(tsnet);
|
|
4482
4928
|
const toggle = (id) => onOpen(open === id ? null : id);
|
|
4929
|
+
// 关闭状态的摘要要能一眼看出"哪一条被关了",而不是只说"有东西关了"
|
|
4930
|
+
const swOff = Boolean(sw && (sw.lan.off || sw.internet.off));
|
|
4931
|
+
const swSubtitle = !sw
|
|
4932
|
+
? "本机 mesh 开关"
|
|
4933
|
+
: sw.all
|
|
4934
|
+
? "全部已关闭 · 不广播、不监听、不接受任务"
|
|
4935
|
+
: sw.lan.off
|
|
4936
|
+
? "局域网已关闭 · 互联网仍可用"
|
|
4937
|
+
: sw.internet.off
|
|
4938
|
+
? "互联网已关闭 · 局域网仍可用"
|
|
4939
|
+
: "全部开启 · 局域网 + 互联网";
|
|
4483
4940
|
|
|
4484
4941
|
return h(
|
|
4485
4942
|
"div",
|
|
@@ -4493,6 +4950,21 @@ window.__ModuleLoader__.load({
|
|
|
4493
4950
|
// tab 已经叫「连接」了,标题再写一遍是重复;这里只留一句说明。
|
|
4494
4951
|
h("p", null, "本机身份、配对码与跨网络互联。改动立即生效,不需要重启。"),
|
|
4495
4952
|
),
|
|
4953
|
+
sw
|
|
4954
|
+
? h(
|
|
4955
|
+
SettingsSection,
|
|
4956
|
+
{
|
|
4957
|
+
id: "switch",
|
|
4958
|
+
icon: "power",
|
|
4959
|
+
title: "一键关闭",
|
|
4960
|
+
subtitle: swSubtitle,
|
|
4961
|
+
status: h(Badge, { kind: swOff ? "warn" : "ok" }, sw.all ? "全部关闭" : swOff ? "部分关闭" : "全部开启"),
|
|
4962
|
+
open: open === "switch",
|
|
4963
|
+
onToggle: () => toggle("switch"),
|
|
4964
|
+
},
|
|
4965
|
+
h(SwitchBody, { sw, push, reload }),
|
|
4966
|
+
)
|
|
4967
|
+
: null,
|
|
4496
4968
|
h(
|
|
4497
4969
|
SettingsSection,
|
|
4498
4970
|
{
|
|
@@ -4534,8 +5006,8 @@ window.__ModuleLoader__.load({
|
|
|
4534
5006
|
id: "tsnet",
|
|
4535
5007
|
icon: "tailscale",
|
|
4536
5008
|
title: "互联网组网",
|
|
4537
|
-
subtitle: tsnet.enabled
|
|
4538
|
-
? `${phase.label}${tsnet.
|
|
5009
|
+
subtitle: tsnet.enabled || tsnetAddressList(tsnet).length
|
|
5010
|
+
? `${phase.label}${tsnetAddressList(tsnet).length ? ` · ${tsnetAddressList(tsnet)[0]}` : ""}`
|
|
4539
5011
|
: "未启用 · 跨网络互联(Tailscale)",
|
|
4540
5012
|
status: h(Badge, { kind: phase.kind }, phase.label),
|
|
4541
5013
|
open: open === "tsnet",
|
|
@@ -4571,6 +5043,69 @@ window.__ModuleLoader__.load({
|
|
|
4571
5043
|
);
|
|
4572
5044
|
}
|
|
4573
5045
|
|
|
5046
|
+
/**
|
|
5047
|
+
* 概览卡上的「一键关闭」快捷条。
|
|
5048
|
+
*
|
|
5049
|
+
* 为什么放主页概览:用户想关 mesh 的时候通常就在主页,不在设置页 ——
|
|
5050
|
+
* 要的是"一眼看见状态、一下点掉",而不是先找到连接页再展开折叠。
|
|
5051
|
+
* 设置页里那份保留:那里有端口/组播/受阻原因等细节。
|
|
5052
|
+
*
|
|
5053
|
+
* 三个胶囊都**没有二次确认**:这是紧急动作,误点的成本只是再点一次。
|
|
5054
|
+
*/
|
|
5055
|
+
function HomeSwitchBar({ sw, push, reload }) {
|
|
5056
|
+
const [busy, setBusy] = react.useState("");
|
|
5057
|
+
if (!sw) return null; // 老宿主没有这个能力:不占位、也不显示一个点了没用的按钮
|
|
5058
|
+
const lan = sw.lan || {};
|
|
5059
|
+
const net = sw.internet || {};
|
|
5060
|
+
const rows = [
|
|
5061
|
+
{ scope: "all", label: "全部", off: !!sw.all },
|
|
5062
|
+
{ scope: "lan", label: "局域网", off: !!lan.off },
|
|
5063
|
+
{ scope: "internet", label: "互联网", off: !!net.off, stalled: !net.off && !!net.stalled },
|
|
5064
|
+
];
|
|
5065
|
+
const toggle = async (scope, off) => {
|
|
5066
|
+
setBusy(scope);
|
|
5067
|
+
try {
|
|
5068
|
+
const r = await api("/switch", { scope, off });
|
|
5069
|
+
if (r && r.ok) {
|
|
5070
|
+
const name = scope === "all" ? "Mesh" : scope === "lan" ? "局域网 Mesh" : "互联网 Mesh";
|
|
5071
|
+
push("success", `${name}已${off ? "关闭" : "打开"}`, {
|
|
5072
|
+
label: "撤销",
|
|
5073
|
+
onClick: () => toggle(scope, !off),
|
|
5074
|
+
});
|
|
5075
|
+
await reload();
|
|
5076
|
+
} else {
|
|
5077
|
+
push("error", apiErr(r));
|
|
5078
|
+
}
|
|
5079
|
+
} catch (e) {
|
|
5080
|
+
push("error", String((e && e.message) || e));
|
|
5081
|
+
} finally {
|
|
5082
|
+
setBusy("");
|
|
5083
|
+
}
|
|
5084
|
+
};
|
|
5085
|
+
return h(
|
|
5086
|
+
"div",
|
|
5087
|
+
{ className: "mesh-home-switch", "data-mesh-home-switch": "1" },
|
|
5088
|
+
h("span", { className: "mesh-home-switch-label" }, "一键关闭"),
|
|
5089
|
+
rows.map((r) => {
|
|
5090
|
+
const stateText = r.off ? "已关" : r.stalled ? "受阻" : "开";
|
|
5091
|
+
return h(
|
|
5092
|
+
"button",
|
|
5093
|
+
{
|
|
5094
|
+
key: r.scope,
|
|
5095
|
+
type: "button",
|
|
5096
|
+
className: cls("mesh-home-switch-pill", r.off && "is-off", r.stalled && "is-stalled", busy === r.scope && "is-busy"),
|
|
5097
|
+
disabled: !!busy,
|
|
5098
|
+
title: `${r.off ? "打开" : "关闭"}${r.scope === "all" ? " Mesh(局域网 + 互联网)" : r.scope === "lan" ? "局域网 Mesh" : "互联网 Mesh"}`,
|
|
5099
|
+
onClick: () => toggle(r.scope, !r.off),
|
|
5100
|
+
},
|
|
5101
|
+
h(Dot, { kind: r.off ? "idle" : r.stalled ? "warn" : "ok" }),
|
|
5102
|
+
h("span", { className: "mesh-home-switch-name" }, r.label),
|
|
5103
|
+
h("span", { className: "mesh-home-switch-state" }, busy === r.scope ? "…" : stateText),
|
|
5104
|
+
);
|
|
5105
|
+
}),
|
|
5106
|
+
);
|
|
5107
|
+
}
|
|
5108
|
+
|
|
4574
5109
|
function HomeCard({ card, subtitle, status, editing, index, count, onMove, onHide, children, footer }) {
|
|
4575
5110
|
return h(
|
|
4576
5111
|
"article",
|
|
@@ -4752,8 +5287,8 @@ window.__ModuleLoader__.load({
|
|
|
4752
5287
|
children: h(
|
|
4753
5288
|
"p",
|
|
4754
5289
|
{ className: "mesh-card-text" },
|
|
4755
|
-
tsnet
|
|
4756
|
-
? `已连接
|
|
5290
|
+
tsnetAddressList(tsnet).length
|
|
5291
|
+
? `已连接 ${tsnetAddressList(tsnet).length} 条通道 · ${tsnetAddressList(tsnet).join(" · ")}`
|
|
4757
5292
|
: "让不在同一网络的电脑也能互相派发任务。需要免费的 Tailscale 账号,授权码只保存一次。",
|
|
4758
5293
|
),
|
|
4759
5294
|
footer: h(Button, { variant: "ghost", size: "sm", icon: "tailscale", onClick: () => onConnect("tsnet") }, "设置互联网组网"),
|
|
@@ -5377,6 +5912,8 @@ window.__ModuleLoader__.load({
|
|
|
5377
5912
|
firstRun,
|
|
5378
5913
|
hostDown,
|
|
5379
5914
|
onDispatched,
|
|
5915
|
+
push,
|
|
5916
|
+
reload,
|
|
5380
5917
|
}) {
|
|
5381
5918
|
const [editing, setEditing] = react.useState(false);
|
|
5382
5919
|
const [drag, setDrag] = react.useState({ draggingId: null, dropId: null, resizingId: null });
|
|
@@ -5650,6 +6187,7 @@ window.__ModuleLoader__.load({
|
|
|
5650
6187
|
h(HomeStat, { label: "跨网络", value: tsnet ? phase.label : "未启用" }),
|
|
5651
6188
|
h(HomeStat, { label: "更新", value: ago(lastOk, now) }),
|
|
5652
6189
|
),
|
|
6190
|
+
h(HomeSwitchBar, { sw: state && state.switch, push, reload }),
|
|
5653
6191
|
),
|
|
5654
6192
|
footer: h(
|
|
5655
6193
|
react.Fragment,
|
|
@@ -5703,8 +6241,8 @@ window.__ModuleLoader__.load({
|
|
|
5703
6241
|
children: h(
|
|
5704
6242
|
"p",
|
|
5705
6243
|
{ className: "mesh-card-text" },
|
|
5706
|
-
tsnet
|
|
5707
|
-
? `已连接
|
|
6244
|
+
tsnetAddressList(tsnet).length
|
|
6245
|
+
? `已连接 ${tsnetAddressList(tsnet).length} 条通道 · ${tsnetAddressList(tsnet).join(" · ")}`
|
|
5708
6246
|
: "让不在同一网络的电脑也能互相派发任务。需要免费的 Tailscale 账号,授权码只保存一次。",
|
|
5709
6247
|
),
|
|
5710
6248
|
footer: h(Button, { variant: "ghost", size: "sm", icon: "tailscale", onClick: () => onConnect("tsnet") }, "设置互联网组网"),
|
|
@@ -6054,6 +6592,7 @@ window.__ModuleLoader__.load({
|
|
|
6054
6592
|
const self = state && state.self ? state.self : null;
|
|
6055
6593
|
const peers = state && Array.isArray(state.peers) ? state.peers : [];
|
|
6056
6594
|
const online = peers.filter((p) => p && p.online).length;
|
|
6595
|
+
const sw = state && state.switch ? state.switch : null;
|
|
6057
6596
|
const tasks = react.useMemo(() => taskList(state), [state]);
|
|
6058
6597
|
const sortedPeers = react.useMemo(
|
|
6059
6598
|
() =>
|
|
@@ -6452,6 +6991,25 @@ window.__ModuleLoader__.load({
|
|
|
6452
6991
|
action: { label: "重试", onClick: reload },
|
|
6453
6992
|
})
|
|
6454
6993
|
: null,
|
|
6994
|
+
sw && (sw.lan.off || sw.internet.off)
|
|
6995
|
+
? h(Banner, {
|
|
6996
|
+
kind: "warn",
|
|
6997
|
+
title: sw.all
|
|
6998
|
+
? "Mesh 已全部关闭"
|
|
6999
|
+
: sw.lan.off
|
|
7000
|
+
? "局域网 Mesh 已关闭"
|
|
7001
|
+
: "互联网 Mesh 已关闭",
|
|
7002
|
+
// 关掉之后"没有设备"是正常的,不是故障 —— 这一句把两者区分开
|
|
7003
|
+
detail: `${sw.summary || ""} · 关闭期间不广播、不接受任务;重启后仍保持`.trim(),
|
|
7004
|
+
action: {
|
|
7005
|
+
label: "去打开",
|
|
7006
|
+
onClick: () => {
|
|
7007
|
+
setView("connect");
|
|
7008
|
+
setSettingsOpen("switch");
|
|
7009
|
+
},
|
|
7010
|
+
},
|
|
7011
|
+
})
|
|
7012
|
+
: null,
|
|
6455
7013
|
state.duplicateNames && state.duplicateNames.length
|
|
6456
7014
|
? h(Banner, {
|
|
6457
7015
|
kind: "warn",
|
|
@@ -6496,6 +7054,8 @@ window.__ModuleLoader__.load({
|
|
|
6496
7054
|
firstRun: firstRunNode,
|
|
6497
7055
|
hostDown,
|
|
6498
7056
|
onDispatched: (peer, r) => notifyDispatched((peer && peer.machine) || "", r),
|
|
7057
|
+
push,
|
|
7058
|
+
reload,
|
|
6499
7059
|
})
|
|
6500
7060
|
: view === "devices"
|
|
6501
7061
|
? h(DeviceView, {
|
|
@@ -6655,6 +7215,9 @@ window.__ModuleLoader__.load({
|
|
|
6655
7215
|
sendToAgent,
|
|
6656
7216
|
PairingBody,
|
|
6657
7217
|
TsnetBody,
|
|
7218
|
+
SwitchBody,
|
|
7219
|
+
SwitchRow,
|
|
7220
|
+
HomeSwitchBar,
|
|
6658
7221
|
};
|
|
6659
7222
|
return module.exports;
|
|
6660
7223
|
},
|