From 0871b64426cbdce6eeef47ce6232bb14df2c8bca Mon Sep 17 00:00:00 2001 From: TanXin Date: Sun, 21 Jun 2026 17:23:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(ssh):=20=E4=BF=AE=E5=A4=8D=20IPv6=20?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E8=BF=9E=E6=8E=A5=E5=A4=B1=E8=B4=A5=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E8=BF=9E=E8=AE=A1=E6=95=B0=E5=99=A8=E4=B8=8D=E9=80=92?= =?UTF-8?q?=E5=A2=9E=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - IPv6 地址传入 connect() API 前自动添加方括号包裹,避免冒号被误解析为 host:port 分隔符 - 移除 WebSocket onopen 中的 reconnectAttempts 重置,改为 SSH 认证成功时才重置,修复重连计数始终显示 1/5 的问题 --- frontend/src/terminal.ts | 3 +- src/worker/durable-object.ts | 3 +- src/worker/html.ts | 490 +++++++++++++++++------------------ 3 files changed, 248 insertions(+), 248 deletions(-) diff --git a/frontend/src/terminal.ts b/frontend/src/terminal.ts index e48a8c3..f91f51d 100644 --- a/frontend/src/terminal.ts +++ b/frontend/src/terminal.ts @@ -131,7 +131,6 @@ export class SSHTerminal { privateKey: config.privateKey, })); - this.reconnectAttempts = 0; this.startHeartbeat(); resolve(); }; @@ -160,7 +159,6 @@ export class SSHTerminal { ws.onopen = () => { this.terminal.writeln('\x1b[32m[+] WebSocket connected, authenticating...\x1b[0m'); - this.reconnectAttempts = 0; this.startHeartbeat(); }; @@ -188,6 +186,7 @@ export class SSHTerminal { case 'status': this.terminal.writeln(`\x1b[32m[*] ${msg.message}\x1b[0m`); if (msg.message === '认证成功') { + this.reconnectAttempts = 0; const statusText = document.getElementById('status-text'); if (statusText) statusText.innerHTML = ' STATUS: ONLINE'; } diff --git a/src/worker/durable-object.ts b/src/worker/durable-object.ts index 0579e90..9bbeaa6 100644 --- a/src/worker/durable-object.ts +++ b/src/worker/durable-object.ts @@ -169,7 +169,8 @@ export class SSHSessionDO { } const { connect } = await import('cloudflare:sockets'); - const socket = connect({ hostname: config.host, port: config.port }); + const hostname = config.host.includes(':') ? `[${config.host}]` : config.host; + const socket = connect({ hostname, port: config.port }); await socket.opened; diff --git a/src/worker/html.ts b/src/worker/html.ts index 28a3061..7dba2ac 100644 --- a/src/worker/html.ts +++ b/src/worker/html.ts @@ -1,46 +1,46 @@ // Automatically generated by scripts/build-html.js. Do not edit directly. -export const HTML = ` - - - - - - CloudSSH - - - - - +export const HTML = ` + + + + + + CloudSSH + + + + +