@linxin666/dsh-ssh 0.4.19 → 0.4.20
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/README.i18n.yaml +2 -2
- package/README.md +13 -2
- package/README.zh.md +13 -2
- package/lib/client.js +468 -12
- package/lib/client.js.map +1 -1
- package/lib/index.js +455 -138
- package/lib/types/client/api.d.ts +8 -4
- package/lib/types/client/locales.d.ts +27 -1
- package/lib/types/client/panel/HostFormDialog.d.ts +3 -3
- package/lib/types/client/panel/HostsTab.d.ts +3 -3
- package/lib/types/client/panel/KeysTab.d.ts +8 -0
- package/lib/types/client/panel/controller.d.ts +1 -1
- package/lib/types/connection-trust.d.ts +26 -0
- package/lib/types/index.d.ts +6 -5
- package/lib/types/protocol.d.ts +41 -0
- package/lib/types/routes.d.ts +3 -0
- package/lib/types/service.d.ts +148 -0
- package/lib/types/store.d.ts +16 -3
- package/package.json +1 -1
- package/src/client/api.ts +41 -6
- package/src/client/locales.ts +55 -2
- package/src/client/panel/HostFormDialog.tsx +71 -14
- package/src/client/panel/HostsTab.tsx +9 -9
- package/src/client/panel/KeysTab.tsx +192 -0
- package/src/client/panel/SshPanel.tsx +4 -1
- package/src/client/panel/controller.ts +1 -1
- package/src/client/panel/helpers.ts +3 -2
- package/src/connection-trust.ts +70 -0
- package/src/engine/connection-pool.ts +141 -84
- package/src/engine.ts +1 -8
- package/src/index.ts +72 -6
- package/src/protocol.ts +45 -0
- package/src/routes.ts +80 -11
- package/src/service.ts +158 -0
- package/src/store.ts +123 -7
package/src/client/locales.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const zh = {
|
|
|
8
8
|
'panel.title': '远程 SSH',
|
|
9
9
|
'panel.backToConversation': '返回会话',
|
|
10
10
|
'tab.hosts': '主机',
|
|
11
|
+
'tab.keys': '密钥',
|
|
11
12
|
'tab.terminal': '终端',
|
|
12
13
|
'tab.transfer': '传输',
|
|
13
14
|
'tab.tunnels': '隧道',
|
|
@@ -65,9 +66,15 @@ export const zh = {
|
|
|
65
66
|
'form.auth.agent': 'SSH Agent',
|
|
66
67
|
'form.agentPath': 'Agent 路径',
|
|
67
68
|
'form.agentPathHint': '留空自动检测(SSH_AUTH_SOCK;Windows 上为原生 ssh-agent 命名管道);也可填 socket 路径或 pageant',
|
|
68
|
-
'form.authKeepHint': '编辑时密码 /
|
|
69
|
+
'form.authKeepHint': '编辑时密码 / 密钥口令留空将保留已存凭据;私钥路径用于匹配受管密钥且不会回读口令。Agent 路径留空是合法的自动检测。',
|
|
69
70
|
'form.keyPath': '私钥路径',
|
|
70
71
|
'form.keyPathHint': '如 ~/.ssh/id_ed25519',
|
|
72
|
+
'form.keyPathRequired': '请选择受管密钥或填写自定义私钥路径。',
|
|
73
|
+
'form.managedKey': '受管密钥',
|
|
74
|
+
'form.key.custom': '自定义路径…',
|
|
75
|
+
'form.key.customHint': '手动填写路径;编辑时口令留空保留原值。',
|
|
76
|
+
'form.key.managedHint': '路径与口令由受管密钥在宿主侧解析,不会向浏览器回读口令。',
|
|
77
|
+
'form.keyListError': '受管密钥列表读取失败:{error}。仍可使用自定义路径。',
|
|
71
78
|
'form.passphrase': '密钥口令',
|
|
72
79
|
'form.password': '密码',
|
|
73
80
|
'form.passwordHint': '明文保存在 $DSH_HOME/dsh-ssh.json(本机私有文件)',
|
|
@@ -88,6 +95,26 @@ export const zh = {
|
|
|
88
95
|
'form.cancel': '取消',
|
|
89
96
|
'form.required': '请填写必填字段:别名、主机地址、用户名。',
|
|
90
97
|
'form.portInvalid': '端口必须是 1-65535 之间的整数。',
|
|
98
|
+
// managed keys
|
|
99
|
+
'keys.add': '新增密钥',
|
|
100
|
+
'keys.empty': '尚未登记密钥。密钥只保存本机路径与可选口令,不复制或读取私钥内容。',
|
|
101
|
+
'keys.name': '名称',
|
|
102
|
+
'keys.col.name': '名称',
|
|
103
|
+
'keys.col.status': '文件状态',
|
|
104
|
+
'keys.col.usedBy': '引用主机',
|
|
105
|
+
'keys.exists': '文件存在',
|
|
106
|
+
'keys.missing': '文件不存在',
|
|
107
|
+
'keys.unused': '未被引用',
|
|
108
|
+
'keys.usedBy': '{count} 台:{hosts}',
|
|
109
|
+
'keys.pathHint': '绝对路径或 ~ 开头的路径;只检查文件元数据,不读取私钥内容。',
|
|
110
|
+
'keys.passphraseHint': '可选口令,明文存入本机 0600 配置文件;编辑时留空保留,勾选清除可移除。',
|
|
111
|
+
'keys.clearPassphrase': '清除已保存的口令',
|
|
112
|
+
'keys.required': '请填写密钥名称与路径。',
|
|
113
|
+
'keys.form.create': '新增受管密钥',
|
|
114
|
+
'keys.form.edit': '编辑受管密钥「{name}」',
|
|
115
|
+
'keys.editConfirm': '此密钥正被 {count} 台主机引用:{hosts}。本次只修改受管记录,不会自动改写这些主机的现有路径或凭据。继续?',
|
|
116
|
+
'keys.deleteConfirm': '删除受管密钥「{name}」?{count} 台引用主机({hosts})会保留各自现有私钥路径与凭据,不会被删除或改写。',
|
|
117
|
+
'keys.deleteConfirmUnused': '删除受管密钥「{name}」?只会删除这条受管记录,不会删除私钥文件。',
|
|
91
118
|
// terminal
|
|
92
119
|
'terminal.selectHost': '选择主机',
|
|
93
120
|
'terminal.connect': '连接',
|
|
@@ -183,6 +210,7 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
183
210
|
'panel.title': 'Remote SSH',
|
|
184
211
|
'panel.backToConversation': 'Back to chat',
|
|
185
212
|
'tab.hosts': 'Hosts',
|
|
213
|
+
'tab.keys': 'Keys',
|
|
186
214
|
'tab.terminal': 'Terminal',
|
|
187
215
|
'tab.transfer': 'Transfer',
|
|
188
216
|
'tab.tunnels': 'Tunnels',
|
|
@@ -238,9 +266,15 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
238
266
|
'form.auth.agent': 'SSH Agent',
|
|
239
267
|
'form.agentPath': 'Agent path',
|
|
240
268
|
'form.agentPathHint': 'Leave empty to auto-detect (SSH_AUTH_SOCK; the native ssh-agent named pipe on Windows), or set a socket path or "pageant"',
|
|
241
|
-
'form.authKeepHint': 'While editing,
|
|
269
|
+
'form.authKeepHint': 'While editing, empty password/passphrase fields keep stored secrets. The private-key path is shown for managed-key matching, never its passphrase. An empty agent path remains a valid auto-detect.',
|
|
242
270
|
'form.keyPath': 'Private key path',
|
|
243
271
|
'form.keyPathHint': 'e.g. ~/.ssh/id_ed25519',
|
|
272
|
+
'form.keyPathRequired': 'Choose a managed key or enter a custom private-key path.',
|
|
273
|
+
'form.managedKey': 'Managed key',
|
|
274
|
+
'form.key.custom': 'Custom path…',
|
|
275
|
+
'form.key.customHint': 'Enter a path yourself; an empty passphrase keeps the old value while editing.',
|
|
276
|
+
'form.key.managedHint': 'The Host resolves the managed path and passphrase without returning the passphrase to the browser.',
|
|
277
|
+
'form.keyListError': 'Could not load managed keys: {error}. Custom paths remain available.',
|
|
244
278
|
'form.passphrase': 'Key passphrase',
|
|
245
279
|
'form.password': 'Password',
|
|
246
280
|
'form.passwordHint': 'Stored in plaintext in $DSH_HOME/dsh-ssh.json (private local file)',
|
|
@@ -261,6 +295,25 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
261
295
|
'form.cancel': 'Cancel',
|
|
262
296
|
'form.required': 'Required fields missing: alias, host, user.',
|
|
263
297
|
'form.portInvalid': 'Port must be an integer between 1 and 65535.',
|
|
298
|
+
'keys.add': 'Add key',
|
|
299
|
+
'keys.empty': 'No managed keys yet. A key stores only a local path and optional passphrase; private-key contents are never copied or read.',
|
|
300
|
+
'keys.name': 'Name',
|
|
301
|
+
'keys.col.name': 'Name',
|
|
302
|
+
'keys.col.status': 'File status',
|
|
303
|
+
'keys.col.usedBy': 'Used by',
|
|
304
|
+
'keys.exists': 'File exists',
|
|
305
|
+
'keys.missing': 'File missing',
|
|
306
|
+
'keys.unused': 'Unused',
|
|
307
|
+
'keys.usedBy': '{count}: {hosts}',
|
|
308
|
+
'keys.pathHint': 'An absolute or ~-relative path; only file metadata is checked, never private-key contents.',
|
|
309
|
+
'keys.passphraseHint': 'Optional passphrase stored in plaintext in the local 0600 config. Blank preserves it while editing; use the clear checkbox to remove it.',
|
|
310
|
+
'keys.clearPassphrase': 'Clear the saved passphrase',
|
|
311
|
+
'keys.required': 'Enter both a key name and path.',
|
|
312
|
+
'keys.form.create': 'Add managed key',
|
|
313
|
+
'keys.form.edit': 'Edit managed key "{name}"',
|
|
314
|
+
'keys.editConfirm': '{count} hosts reference this key: {hosts}. This edits only the managed record; existing host paths and credentials are not rewritten. Continue?',
|
|
315
|
+
'keys.deleteConfirm': 'Delete managed key "{name}"? Its {count} referencing hosts ({hosts}) keep their existing private-key paths and credentials; no host is deleted or rewritten.',
|
|
316
|
+
'keys.deleteConfirmUnused': 'Delete managed key "{name}"? Only the managed record is removed; the private-key file is never deleted.',
|
|
264
317
|
'terminal.selectHost': 'Select host',
|
|
265
318
|
'terminal.connect': 'Connect',
|
|
266
319
|
'terminal.disconnect': 'Disconnect',
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host form dialog: create/edit one stored host entry. A fixed backdrop with
|
|
3
|
-
* a centered card; Escape and backdrop clicks close it.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* a centered card; Escape and backdrop clicks close it. Passwords and
|
|
4
|
+
* passphrases are never pre-filled. The browser-only panel summary includes
|
|
5
|
+
* the key path solely to match a managed key; passphrases resolve Host-side.
|
|
6
6
|
*/
|
|
7
|
-
import { useEffect, useState } from 'react'
|
|
7
|
+
import { useEffect, useRef, useState } from 'react'
|
|
8
8
|
import type { SshApi } from '../api.ts'
|
|
9
|
-
import type { HostPayload, SshAuthKind,
|
|
9
|
+
import type { HostPayload, SshAuthKind, SshKeySummary, SshPanelHostSummary } from '../../protocol.ts'
|
|
10
10
|
import { errorMessage, tt } from './helpers.ts'
|
|
11
11
|
import css from './panel.module.css'
|
|
12
12
|
|
|
@@ -14,9 +14,9 @@ import css from './panel.module.css'
|
|
|
14
14
|
export interface HostFormDialogProps {
|
|
15
15
|
api: SshApi
|
|
16
16
|
/** The host being edited; null/undefined means create. */
|
|
17
|
-
editing?:
|
|
17
|
+
editing?: SshPanelHostSummary | null
|
|
18
18
|
onClose: () => void
|
|
19
|
-
onSaved: (host:
|
|
19
|
+
onSaved: (host: SshPanelHostSummary) => void
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/** The staged form values (all strings; parsed on save). */
|
|
@@ -27,6 +27,7 @@ interface FormState {
|
|
|
27
27
|
user: string
|
|
28
28
|
authKind: SshAuthKind
|
|
29
29
|
keyPath: string
|
|
30
|
+
managedKeyId: string
|
|
30
31
|
passphrase: string
|
|
31
32
|
password: string
|
|
32
33
|
agentPath: string
|
|
@@ -45,14 +46,15 @@ function splitList(text: string): string[] {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/** Initial form state: the summary's public fields plus empty secrets. */
|
|
48
|
-
function blankOf(editing:
|
|
49
|
+
function blankOf(editing: SshPanelHostSummary | null | undefined): FormState {
|
|
49
50
|
return {
|
|
50
51
|
alias: editing?.alias ?? '',
|
|
51
52
|
host: editing?.host ?? '',
|
|
52
53
|
port: String(editing?.port ?? 22),
|
|
53
54
|
user: editing?.user ?? '',
|
|
54
55
|
authKind: editing?.auth ?? 'key',
|
|
55
|
-
keyPath: '',
|
|
56
|
+
keyPath: editing?.keyPath ?? '',
|
|
57
|
+
managedKeyId: '',
|
|
56
58
|
passphrase: '',
|
|
57
59
|
password: '',
|
|
58
60
|
agentPath: '',
|
|
@@ -71,6 +73,9 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
|
|
|
71
73
|
const [form, setForm] = useState<FormState>(() => blankOf(editing))
|
|
72
74
|
const [saving, setSaving] = useState(false)
|
|
73
75
|
const [error, setError] = useState<string | null>(null)
|
|
76
|
+
const [keys, setKeys] = useState<SshKeySummary[] | null>(null)
|
|
77
|
+
const [keysError, setKeysError] = useState<string | null>(null)
|
|
78
|
+
const keySelectionTouched = useRef(false)
|
|
74
79
|
|
|
75
80
|
// Escape closes the dialog.
|
|
76
81
|
useEffect(() => {
|
|
@@ -81,10 +86,37 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
|
|
|
81
86
|
return () => { document.removeEventListener('keydown', onKey) }
|
|
82
87
|
}, [onClose])
|
|
83
88
|
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
let cancelled = false
|
|
91
|
+
void api.listKeys().then(list => {
|
|
92
|
+
if (cancelled) return
|
|
93
|
+
setKeys(list)
|
|
94
|
+
setForm(previous => {
|
|
95
|
+
if (keySelectionTouched.current || previous.authKind !== 'key' || previous.managedKeyId !== '' || previous.keyPath === '') return previous
|
|
96
|
+
const match = list.find(key => key.path === previous.keyPath)
|
|
97
|
+
return match === undefined ? previous : { ...previous, managedKeyId: match.id, keyPath: match.path }
|
|
98
|
+
})
|
|
99
|
+
}, cause => {
|
|
100
|
+
if (!cancelled) setKeysError(errorMessage(cause))
|
|
101
|
+
})
|
|
102
|
+
return () => { cancelled = true }
|
|
103
|
+
}, [api])
|
|
104
|
+
|
|
84
105
|
const set = <K extends keyof FormState>(key: K, value: FormState[K]): void => {
|
|
85
106
|
setForm(prev => ({ ...prev, [key]: value }))
|
|
86
107
|
}
|
|
87
108
|
|
|
109
|
+
const chooseManagedKey = (id: string): void => {
|
|
110
|
+
keySelectionTouched.current = true
|
|
111
|
+
const selected = keys?.find(key => key.id === id)
|
|
112
|
+
setForm(previous => ({
|
|
113
|
+
...previous,
|
|
114
|
+
managedKeyId: selected?.id ?? '',
|
|
115
|
+
keyPath: selected?.path ?? previous.keyPath,
|
|
116
|
+
passphrase: '',
|
|
117
|
+
}))
|
|
118
|
+
}
|
|
119
|
+
|
|
88
120
|
const save = async (): Promise<void> => {
|
|
89
121
|
const alias = form.alias.trim()
|
|
90
122
|
const host = form.host.trim()
|
|
@@ -98,6 +130,10 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
|
|
|
98
130
|
setError(tt('form.portInvalid'))
|
|
99
131
|
return
|
|
100
132
|
}
|
|
133
|
+
if (form.authKind === 'key' && form.keyPath.trim() === '' && (editing == null || editing.auth !== 'key')) {
|
|
134
|
+
setError(tt('form.keyPathRequired'))
|
|
135
|
+
return
|
|
136
|
+
}
|
|
101
137
|
// A password-auth host needs a password on create; when editing, a blank
|
|
102
138
|
// secret field preserves the stored credential instead.
|
|
103
139
|
if (editing == null && form.authKind === 'password' && form.password === '') {
|
|
@@ -120,13 +156,14 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
|
|
|
120
156
|
: form.authKind === 'password'
|
|
121
157
|
? { kind: 'password', password: form.password }
|
|
122
158
|
: form.authKind === 'key'
|
|
123
|
-
? { kind: 'key', keyPath: form.keyPath.trim(), passphrase: form.passphrase === '' ? undefined : form.passphrase }
|
|
159
|
+
? { kind: 'key', keyPath: form.keyPath.trim(), passphrase: form.managedKeyId !== '' || form.passphrase === '' ? undefined : form.passphrase }
|
|
124
160
|
: { kind: 'agent', agentPath: form.agentPath.trim() === '' ? undefined : form.agentPath.trim() }
|
|
125
161
|
const payload: HostPayload = {
|
|
126
162
|
host,
|
|
127
163
|
port,
|
|
128
164
|
user,
|
|
129
165
|
auth,
|
|
166
|
+
...(form.authKind === 'key' && form.managedKeyId !== '' && (editing == null || keySelectionTouched.current) ? { managedKeyId: form.managedKeyId } : {}),
|
|
130
167
|
proxyJump: splitList(form.proxyJump),
|
|
131
168
|
// Always sent (never omitted): an empty value is the explicit clear,
|
|
132
169
|
// because the API cannot express "remove this field" any other way.
|
|
@@ -197,17 +234,37 @@ export function HostFormDialog({ api, editing, onClose, onSaved }: HostFormDialo
|
|
|
197
234
|
{editing != null && <span className={css.hint}>{tt('form.authKeepHint')}</span>}
|
|
198
235
|
</div>
|
|
199
236
|
{form.authKind === 'key' ? (
|
|
200
|
-
|
|
237
|
+
<>
|
|
238
|
+
<div className={css.field}>
|
|
239
|
+
<span className={css.fieldLabel}>{tt('form.managedKey')}</span>
|
|
240
|
+
<select
|
|
241
|
+
className={css.input}
|
|
242
|
+
aria-label={tt('form.managedKey')}
|
|
243
|
+
value={form.managedKeyId}
|
|
244
|
+
disabled={keys === null}
|
|
245
|
+
onChange={event => { chooseManagedKey(event.target.value) }}
|
|
246
|
+
>
|
|
247
|
+
<option value="">{tt('form.key.custom')}</option>
|
|
248
|
+
{(keys ?? []).map(key => <option key={key.id} value={key.id}>{key.name} — {key.path}</option>)}
|
|
249
|
+
</select>
|
|
250
|
+
<span className={css.hint}>
|
|
251
|
+
{keysError !== null
|
|
252
|
+
? tt('form.keyListError', { error: keysError })
|
|
253
|
+
: form.managedKeyId !== '' ? tt('form.key.managedHint') : tt('form.key.customHint')}
|
|
254
|
+
</span>
|
|
255
|
+
</div>
|
|
256
|
+
<div className={css.formRow}>
|
|
201
257
|
<label className={css.field}>
|
|
202
258
|
<span className={css.fieldLabel}>{tt('form.keyPath')}</span>
|
|
203
|
-
<input className={css.input} value={form.keyPath} onChange={event => { set('keyPath', event.target.value) }} />
|
|
259
|
+
<input className={css.input} value={form.keyPath} readOnly={form.managedKeyId !== ''} onChange={event => { set('keyPath', event.target.value) }} />
|
|
204
260
|
<span className={css.hint}>{tt('form.keyPathHint')}</span>
|
|
205
261
|
</label>
|
|
206
262
|
<label className={css.field}>
|
|
207
263
|
<span className={css.fieldLabel}>{tt('form.passphrase')}</span>
|
|
208
|
-
<input className={css.input} type="password" value={form.passphrase} onChange={event => { set('passphrase', event.target.value) }} />
|
|
264
|
+
<input className={css.input} type="password" value={form.passphrase} disabled={form.managedKeyId !== ''} onChange={event => { set('passphrase', event.target.value) }} />
|
|
209
265
|
</label>
|
|
210
|
-
|
|
266
|
+
</div>
|
|
267
|
+
</>
|
|
211
268
|
) : form.authKind === 'agent' ? (
|
|
212
269
|
<label className={css.field}>
|
|
213
270
|
<span className={css.fieldLabel}>{tt('form.agentPath')}</span>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
7
7
|
import type { SshApi } from '../api.ts'
|
|
8
|
-
import type { ImportSkipBlock, ImportSkipReason,
|
|
8
|
+
import type { ImportSkipBlock, ImportSkipReason, SshPanelHostSummary, TestResult } from '../../protocol.ts'
|
|
9
9
|
import type { SshKey } from '../locales.ts'
|
|
10
10
|
import { errorMessage, tt } from './helpers.ts'
|
|
11
11
|
import { HostFormDialog } from './HostFormDialog.tsx'
|
|
@@ -19,7 +19,7 @@ export interface HostsTabProps {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** The host-form dialog invocation. */
|
|
22
|
-
type DialogState = { mode: 'create' } | { mode: 'edit'; host:
|
|
22
|
+
type DialogState = { mode: 'create' } | { mode: 'edit'; host: SshPanelHostSummary }
|
|
23
23
|
|
|
24
24
|
/** Skipped-block rows rendered before the "and N more" summary. */
|
|
25
25
|
const IMPORT_SKIP_LIMIT = 8
|
|
@@ -39,7 +39,7 @@ export type HostGroupBy = 'none' | 'environment' | 'tags'
|
|
|
39
39
|
export interface HostGroup {
|
|
40
40
|
/** Group key: the environment name, one tag, or '' for the ungrouped bucket. */
|
|
41
41
|
key: string
|
|
42
|
-
hosts:
|
|
42
|
+
hosts: SshPanelHostSummary[]
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -48,10 +48,10 @@ export interface HostGroup {
|
|
|
48
48
|
* the grouping key land in the '' bucket, which always sorts last. Groups
|
|
49
49
|
* sort alphabetically; host order inside a group follows the API listing.
|
|
50
50
|
*/
|
|
51
|
-
export function groupHosts(hosts:
|
|
51
|
+
export function groupHosts(hosts: SshPanelHostSummary[], groupBy: HostGroupBy): HostGroup[] {
|
|
52
52
|
if (groupBy === 'none') return [{ key: '', hosts }]
|
|
53
|
-
const buckets = new Map<string,
|
|
54
|
-
const push = (key: string, host:
|
|
53
|
+
const buckets = new Map<string, SshPanelHostSummary[]>()
|
|
54
|
+
const push = (key: string, host: SshPanelHostSummary): void => {
|
|
55
55
|
const bucket = buckets.get(key)
|
|
56
56
|
if (bucket === undefined) buckets.set(key, [host])
|
|
57
57
|
else bucket.push(host)
|
|
@@ -72,7 +72,7 @@ export function groupHosts(hosts: SshHostSummary[], groupBy: HostGroupBy): HostG
|
|
|
72
72
|
|
|
73
73
|
/** The hosts table plus its toolbar and dialogs. */
|
|
74
74
|
export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
75
|
-
const [hosts, setHosts] = useState<
|
|
75
|
+
const [hosts, setHosts] = useState<SshPanelHostSummary[] | null>(null)
|
|
76
76
|
const [error, setError] = useState<string | null>(null)
|
|
77
77
|
const [search, setSearch] = useState('')
|
|
78
78
|
const [testingAlias, setTestingAlias] = useState<string | null>(null)
|
|
@@ -177,7 +177,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
const renderHostRow = (host:
|
|
180
|
+
const renderHostRow = (host: SshPanelHostSummary): ReactNode => {
|
|
181
181
|
const test = testResults[host.alias]
|
|
182
182
|
return (
|
|
183
183
|
<tr key={host.alias}>
|
|
@@ -216,7 +216,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
216
216
|
)
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
const renderHostTable = (rows:
|
|
219
|
+
const renderHostTable = (rows: SshPanelHostSummary[]): ReactNode => (
|
|
220
220
|
<table className={css.table}>
|
|
221
221
|
<thead>
|
|
222
222
|
<tr>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/** Managed local private-key references: CRUD without reading key contents. */
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
3
|
+
import type { SshApi } from '../api.ts'
|
|
4
|
+
import type { SshKeyPayload, SshKeySummary } from '../../protocol.ts'
|
|
5
|
+
import { errorMessage, tt } from './helpers.ts'
|
|
6
|
+
import css from './panel.module.css'
|
|
7
|
+
|
|
8
|
+
interface KeysTabProps {
|
|
9
|
+
api: SshApi
|
|
10
|
+
/** Confirmation seam for host-reference warnings; defaults to window.confirm. */
|
|
11
|
+
confirmAction?: (message: string) => boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type KeyDialog = { mode: 'create' } | { mode: 'edit'; key: SshKeySummary }
|
|
15
|
+
|
|
16
|
+
function KeyFormDialog(props: {
|
|
17
|
+
api: SshApi
|
|
18
|
+
editing?: SshKeySummary
|
|
19
|
+
onClose: () => void
|
|
20
|
+
onSaved: () => void
|
|
21
|
+
confirmAction: (message: string) => boolean
|
|
22
|
+
}) {
|
|
23
|
+
const { api, editing, onClose, onSaved, confirmAction } = props
|
|
24
|
+
const [name, setName] = useState(editing?.name ?? '')
|
|
25
|
+
const [path, setPath] = useState(editing?.path ?? '')
|
|
26
|
+
const [passphrase, setPassphrase] = useState('')
|
|
27
|
+
const [clearPassphrase, setClearPassphrase] = useState(false)
|
|
28
|
+
const [note, setNote] = useState(editing?.note ?? '')
|
|
29
|
+
const [saving, setSaving] = useState(false)
|
|
30
|
+
const [error, setError] = useState<string | null>(null)
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const onKey = (event: KeyboardEvent): void => { if (event.key === 'Escape') onClose() }
|
|
34
|
+
document.addEventListener('keydown', onKey)
|
|
35
|
+
return () => { document.removeEventListener('keydown', onKey) }
|
|
36
|
+
}, [onClose])
|
|
37
|
+
|
|
38
|
+
const save = async (): Promise<void> => {
|
|
39
|
+
if (name.trim() === '' || path.trim() === '') {
|
|
40
|
+
setError(tt('keys.required'))
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (editing !== undefined && editing.usedBy.length > 0) {
|
|
44
|
+
const confirmed = confirmAction(tt('keys.editConfirm', {
|
|
45
|
+
count: editing.usedBy.length,
|
|
46
|
+
hosts: editing.usedBy.join(', '),
|
|
47
|
+
}))
|
|
48
|
+
if (!confirmed) return
|
|
49
|
+
}
|
|
50
|
+
const payload: SshKeyPayload = {
|
|
51
|
+
name: name.trim(),
|
|
52
|
+
path: path.trim(),
|
|
53
|
+
note,
|
|
54
|
+
...(passphrase !== '' ? { passphrase }
|
|
55
|
+
: editing !== undefined && clearPassphrase ? { passphrase: null }
|
|
56
|
+
: {}),
|
|
57
|
+
}
|
|
58
|
+
setSaving(true)
|
|
59
|
+
setError(null)
|
|
60
|
+
try {
|
|
61
|
+
if (editing === undefined) await api.createKey(payload)
|
|
62
|
+
else await api.updateKey(editing.id, payload)
|
|
63
|
+
onSaved()
|
|
64
|
+
} catch (cause) {
|
|
65
|
+
setError(errorMessage(cause))
|
|
66
|
+
setSaving(false)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div className={css.modalBackdrop} onClick={onClose}>
|
|
72
|
+
<div className={css.modal} role="dialog" aria-modal="true" aria-label={editing === undefined ? tt('keys.form.create') : tt('keys.form.edit', { name: editing.name })} onClick={event => { event.stopPropagation() }}>
|
|
73
|
+
<h3 className={css.modalTitle}>{editing === undefined ? tt('keys.form.create') : tt('keys.form.edit', { name: editing.name })}</h3>
|
|
74
|
+
<label className={css.field}>
|
|
75
|
+
<span className={css.fieldLabel}>{tt('keys.name')}</span>
|
|
76
|
+
<input className={css.input} value={name} onChange={event => { setName(event.target.value) }} />
|
|
77
|
+
</label>
|
|
78
|
+
<label className={css.field}>
|
|
79
|
+
<span className={css.fieldLabel}>{tt('form.keyPath')}</span>
|
|
80
|
+
<input className={css.input} value={path} onChange={event => { setPath(event.target.value) }} />
|
|
81
|
+
<span className={css.hint}>{tt('keys.pathHint')}</span>
|
|
82
|
+
</label>
|
|
83
|
+
<label className={css.field}>
|
|
84
|
+
<span className={css.fieldLabel}>{tt('form.passphrase')}</span>
|
|
85
|
+
<input className={css.input} type="password" value={passphrase} disabled={clearPassphrase} onChange={event => { setPassphrase(event.target.value) }} />
|
|
86
|
+
<span className={css.hint}>{tt('keys.passphraseHint')}</span>
|
|
87
|
+
</label>
|
|
88
|
+
{editing?.hasPassphrase === true && (
|
|
89
|
+
<label className={css.radioLabel}>
|
|
90
|
+
<input type="checkbox" checked={clearPassphrase} onChange={event => {
|
|
91
|
+
const checked = event.target.checked
|
|
92
|
+
setClearPassphrase(checked)
|
|
93
|
+
if (checked) setPassphrase('')
|
|
94
|
+
}} />
|
|
95
|
+
{tt('keys.clearPassphrase')}
|
|
96
|
+
</label>
|
|
97
|
+
)}
|
|
98
|
+
<label className={css.field}>
|
|
99
|
+
<span className={css.fieldLabel}>{tt('form.description')}</span>
|
|
100
|
+
<input className={css.input} value={note} onChange={event => { setNote(event.target.value) }} />
|
|
101
|
+
</label>
|
|
102
|
+
{error !== null && <p className={css.formError}>{tt('common.error', { error })}</p>}
|
|
103
|
+
<div className={css.modalFooter}>
|
|
104
|
+
<button type="button" className={css.ghostButton} disabled={saving} onClick={onClose}>{tt('form.cancel')}</button>
|
|
105
|
+
<button type="button" className={css.primaryButton} disabled={saving} onClick={() => { void save() }}>{tt('form.save')}</button>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function KeysTab({ api, confirmAction }: KeysTabProps) {
|
|
113
|
+
const ask = confirmAction ?? ((message: string): boolean => window.confirm(message))
|
|
114
|
+
const [keys, setKeys] = useState<SshKeySummary[] | null>(null)
|
|
115
|
+
const [error, setError] = useState<string | null>(null)
|
|
116
|
+
const [dialog, setDialog] = useState<KeyDialog | null>(null)
|
|
117
|
+
const mounted = useRef(true)
|
|
118
|
+
useEffect(() => () => { mounted.current = false }, [])
|
|
119
|
+
|
|
120
|
+
const load = useCallback(async (): Promise<void> => {
|
|
121
|
+
try {
|
|
122
|
+
const list = await api.listKeys()
|
|
123
|
+
if (!mounted.current) return
|
|
124
|
+
setKeys(list)
|
|
125
|
+
setError(null)
|
|
126
|
+
} catch (cause) {
|
|
127
|
+
if (mounted.current) setError(errorMessage(cause))
|
|
128
|
+
}
|
|
129
|
+
}, [api])
|
|
130
|
+
useEffect(() => { void load() }, [load])
|
|
131
|
+
|
|
132
|
+
const remove = async (key: SshKeySummary): Promise<void> => {
|
|
133
|
+
const message = key.usedBy.length === 0
|
|
134
|
+
? tt('keys.deleteConfirmUnused', { name: key.name })
|
|
135
|
+
: tt('keys.deleteConfirm', { name: key.name, count: key.usedBy.length, hosts: key.usedBy.join(', ') })
|
|
136
|
+
if (!ask(message)) return
|
|
137
|
+
try {
|
|
138
|
+
await api.deleteKey(key.id)
|
|
139
|
+
await load()
|
|
140
|
+
} catch (cause) {
|
|
141
|
+
if (mounted.current) setError(errorMessage(cause))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div className={css.fillBody}>
|
|
147
|
+
<div className={css.toolbar}>
|
|
148
|
+
<div className={css.toolbarSpacer} />
|
|
149
|
+
<button type="button" className={css.primaryButton} onClick={() => { setDialog({ mode: 'create' }) }}>{tt('keys.add')}</button>
|
|
150
|
+
</div>
|
|
151
|
+
{error !== null && <div className={css.banner} data-kind="error">{tt('common.error', { error })}</div>}
|
|
152
|
+
{keys === null && error === null && <div className={css.loading}>{tt('common.loading')}</div>}
|
|
153
|
+
{keys !== null && keys.length === 0 && <div className={css.empty}>{tt('keys.empty')}</div>}
|
|
154
|
+
{keys !== null && keys.length > 0 && (
|
|
155
|
+
<div className={css.tableWrap}>
|
|
156
|
+
<table className={css.table}>
|
|
157
|
+
<thead><tr>
|
|
158
|
+
<th>{tt('keys.col.name')}</th>
|
|
159
|
+
<th>{tt('form.keyPath')}</th>
|
|
160
|
+
<th>{tt('keys.col.status')}</th>
|
|
161
|
+
<th>{tt('keys.col.usedBy')}</th>
|
|
162
|
+
<th>{tt('hosts.col.description')}</th>
|
|
163
|
+
<th>{tt('hosts.col.actions')}</th>
|
|
164
|
+
</tr></thead>
|
|
165
|
+
<tbody>{keys.map(key => (
|
|
166
|
+
<tr key={key.id}>
|
|
167
|
+
<td>{key.name}</td>
|
|
168
|
+
<td className={css.mono}>{key.path}</td>
|
|
169
|
+
<td><span className={css.badge} data-status={key.exists ? 'ok' : 'fail'}>{key.exists ? tt('keys.exists') : tt('keys.missing')}</span></td>
|
|
170
|
+
<td>{key.usedBy.length === 0 ? tt('keys.unused') : tt('keys.usedBy', { count: key.usedBy.length, hosts: key.usedBy.join(', ') })}</td>
|
|
171
|
+
<td className={css.cellMuted}>{key.note ?? ''}</td>
|
|
172
|
+
<td><div className={css.actions}>
|
|
173
|
+
<button type="button" className={css.linkButton} onClick={() => { setDialog({ mode: 'edit', key }) }}>{tt('hosts.edit')}</button>
|
|
174
|
+
<button type="button" className={css.linkButton} data-danger onClick={() => { void remove(key) }}>{tt('hosts.delete')}</button>
|
|
175
|
+
</div></td>
|
|
176
|
+
</tr>
|
|
177
|
+
))}</tbody>
|
|
178
|
+
</table>
|
|
179
|
+
</div>
|
|
180
|
+
)}
|
|
181
|
+
{dialog !== null && (
|
|
182
|
+
<KeyFormDialog
|
|
183
|
+
api={api}
|
|
184
|
+
editing={dialog.mode === 'edit' ? dialog.key : undefined}
|
|
185
|
+
onClose={() => { setDialog(null) }}
|
|
186
|
+
onSaved={() => { setDialog(null); void load() }}
|
|
187
|
+
confirmAction={ask}
|
|
188
|
+
/>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The SSH operations panel shell: a header with a close control, a
|
|
2
|
+
* The SSH operations panel shell: a header with a close control, a six-tab
|
|
3
3
|
* bar, and the active tab's content.
|
|
4
4
|
*
|
|
5
5
|
* The active tab and the terminal tabs live in the controller, not in
|
|
@@ -14,6 +14,7 @@ import type { PanelController, SshTab } from './controller.ts'
|
|
|
14
14
|
import { tt, type TerminalFontSource } from './helpers.ts'
|
|
15
15
|
import { ClusterTab } from './ClusterTab.tsx'
|
|
16
16
|
import { HostsTab } from './HostsTab.tsx'
|
|
17
|
+
import { KeysTab } from './KeysTab.tsx'
|
|
17
18
|
import { TerminalTab } from './TerminalTab.tsx'
|
|
18
19
|
import { TransferTab } from './TransferTab.tsx'
|
|
19
20
|
import { TunnelsTab } from './TunnelsTab.tsx'
|
|
@@ -32,6 +33,7 @@ export interface SshPanelProps {
|
|
|
32
33
|
/** The tab bar definition (labels resolved at render time). */
|
|
33
34
|
const TABS: ReadonlyArray<{ id: SshTab; label: () => string }> = [
|
|
34
35
|
{ id: 'hosts', label: () => tt('tab.hosts') },
|
|
36
|
+
{ id: 'keys', label: () => tt('tab.keys') },
|
|
35
37
|
{ id: 'terminal', label: () => tt('tab.terminal') },
|
|
36
38
|
{ id: 'transfer', label: () => tt('tab.transfer') },
|
|
37
39
|
{ id: 'tunnels', label: () => tt('tab.tunnels') },
|
|
@@ -70,6 +72,7 @@ export function SshPanel({ controller, api, terminalFont }: SshPanelProps) {
|
|
|
70
72
|
</div>
|
|
71
73
|
<div className={css.panelContent}>
|
|
72
74
|
{activeTab === 'hosts' && <HostsTab api={api} onConnect={alias => { controller.requestConnect(alias) }} />}
|
|
75
|
+
{activeTab === 'keys' && <KeysTab api={api} />}
|
|
73
76
|
{activeTab === 'terminal' && (
|
|
74
77
|
<TerminalTab api={api} controller={controller} terminalFont={terminalFont} />
|
|
75
78
|
)}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import type { TerminalConnection } from '../api.ts'
|
|
24
24
|
|
|
25
25
|
/** The panel's tab identifiers. */
|
|
26
|
-
export type SshTab = 'hosts' | 'terminal' | 'transfer' | 'tunnels' | 'cluster'
|
|
26
|
+
export type SshTab = 'hosts' | 'keys' | 'terminal' | 'transfer' | 'tunnels' | 'cluster'
|
|
27
27
|
|
|
28
28
|
/** Stable id shared by the sidebar panel row and the main-slot page. */
|
|
29
29
|
export const SSH_PANEL_ID = 'ssh'
|
|
@@ -10,8 +10,9 @@ export type TranslateValues = Record<string, string | number>
|
|
|
10
10
|
|
|
11
11
|
/** Active dictionary, picked by the document language at call time. */
|
|
12
12
|
export function dictionary(): Record<string, string> {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
// Chinese keeps the Chinese table; every other UI language falls back to English.
|
|
14
|
+
const lang = (typeof document !== 'undefined' && document.documentElement.lang !== '' ? document.documentElement.lang : 'zh').toLowerCase()
|
|
15
|
+
return lang.startsWith('zh') ? { ...zh } : { ...en }
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Generated by scripts/sync-shared.mjs from shared/host/connection-trust.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
+
/**
|
|
3
|
+
* Optional bridge to the Host connection trust decision. Newer hosts expose
|
|
4
|
+
* admit(request); the rc.3 SDK cohort exposes requestRejection(request). A
|
|
5
|
+
* missing or throwing bridge is not an admission: callers must retain their
|
|
6
|
+
* existing loopback or pairing fence.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { IncomingMessage } from 'node:http'
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
|
|
12
|
+
/** Structural host connection face across supported SDK cohorts. */
|
|
13
|
+
export interface HostConnectionService {
|
|
14
|
+
requestRejection?: (request: IncomingMessage) => unknown
|
|
15
|
+
admit?: (request: IncomingMessage) => { readonly peer?: unknown; readonly rejection?: unknown }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Lazily read the service captured in the plugin's dependency scope. */
|
|
19
|
+
export type HostConnectionReader = () => HostConnectionService | undefined
|
|
20
|
+
|
|
21
|
+
function resolveConnection(ctx: Context): HostConnectionService | undefined {
|
|
22
|
+
try {
|
|
23
|
+
const candidate = typeof ctx.get === 'function'
|
|
24
|
+
? (ctx.get('connection', false) ?? ctx.get('connection'))
|
|
25
|
+
: (ctx as { connection?: HostConnectionService }).connection
|
|
26
|
+
return candidate !== undefined && candidate !== null && (
|
|
27
|
+
typeof candidate.admit === 'function' || typeof candidate.requestRejection === 'function'
|
|
28
|
+
)
|
|
29
|
+
? candidate
|
|
30
|
+
: undefined
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether the Host's own authenticated/trusted-host decision admits a request. */
|
|
37
|
+
export function connectionAdmits(connection: HostConnectionService | undefined, request: IncomingMessage): boolean {
|
|
38
|
+
if (connection === undefined) return false
|
|
39
|
+
try {
|
|
40
|
+
if (typeof connection.admit === 'function') {
|
|
41
|
+
const admission = connection.admit(request)
|
|
42
|
+
return admission.rejection === undefined && 'peer' in admission && admission.peer !== undefined
|
|
43
|
+
}
|
|
44
|
+
if (typeof connection.requestRejection === 'function') return connection.requestRejection(request) === undefined
|
|
45
|
+
return false
|
|
46
|
+
} catch {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Capture connection in a scope that also injects connection.authentication:
|
|
53
|
+
* admit(request) resolves that service through the calling fiber. The returned
|
|
54
|
+
* reader falls back to a bare optional lookup on cohorts without that service.
|
|
55
|
+
*/
|
|
56
|
+
export function captureConnection(ctx: Context, effectName: string): HostConnectionReader {
|
|
57
|
+
let captured: HostConnectionService | undefined
|
|
58
|
+
const inject = (ctx as { inject?: (names: readonly string[], callback: (scoped: Context) => unknown) => unknown }).inject
|
|
59
|
+
if (typeof inject === 'function') {
|
|
60
|
+
inject.call(ctx, ['connection', 'connection.authentication'], (scoped: Context) => {
|
|
61
|
+
scoped.effect(() => {
|
|
62
|
+
captured = resolveConnection(scoped)
|
|
63
|
+
return () => {
|
|
64
|
+
captured = undefined
|
|
65
|
+
}
|
|
66
|
+
}, effectName)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
return () => captured ?? resolveConnection(ctx)
|
|
70
|
+
}
|