@linxin666/dsh-ssh 0.4.19 → 0.4.21
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 +726 -109
- package/lib/client.js.map +1 -1
- package/lib/index.js +1074 -352
- 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/engine/cluster.d.ts +7 -2
- package/lib/types/engine/connection-pool.d.ts +11 -2
- package/lib/types/engine/sftp.d.ts +5 -0
- package/lib/types/engine/terminal-sessions.d.ts +5 -3
- 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 -4
- package/package.json +1 -1
- package/src/client/api.ts +147 -58
- package/src/client/locales.ts +55 -2
- package/src/client/panel/HostFormDialog.tsx +76 -17
- package/src/client/panel/HostsTab.tsx +50 -25
- package/src/client/panel/KeysTab.tsx +192 -0
- package/src/client/panel/SshPanel.tsx +4 -1
- package/src/client/panel/TerminalTab.tsx +14 -9
- package/src/client/panel/TunnelsTab.tsx +24 -7
- package/src/client/panel/controller.ts +77 -12
- package/src/client/panel/helpers.ts +3 -2
- package/src/connection-trust.ts +70 -0
- package/src/engine/cluster.ts +45 -13
- package/src/engine/connection-pool.ts +279 -96
- package/src/engine/proxy-command.ts +27 -10
- package/src/engine/sftp.ts +69 -35
- package/src/engine/terminal-sessions.ts +110 -35
- package/src/engine/tunnel.ts +20 -2
- package/src/engine.ts +5 -8
- package/src/index.ts +113 -39
- package/src/protocol.ts +45 -0
- package/src/routes.ts +130 -23
- package/src/service.ts +158 -0
- package/src/store.ts +324 -104
- package/src/tools.ts +3 -5
|
@@ -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,10 +72,10 @@ 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
|
-
const [
|
|
78
|
+
const [testingAliases, setTestingAliases] = useState<ReadonlySet<string>>(() => new Set())
|
|
79
79
|
const [testResults, setTestResults] = useState<Record<string, TestResult>>({})
|
|
80
80
|
const [importing, setImporting] = useState(false)
|
|
81
81
|
const [notice, setNotice] = useState<string | null>(null)
|
|
@@ -93,7 +93,10 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
93
93
|
// sibling tabs (terminal / transfer / tunnels) already guard with a
|
|
94
94
|
// disposed flag.
|
|
95
95
|
const mountedRef = useRef(true)
|
|
96
|
-
useEffect(() =>
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
mountedRef.current = true
|
|
98
|
+
return () => { mountedRef.current = false }
|
|
99
|
+
}, [])
|
|
97
100
|
|
|
98
101
|
const load = useCallback(async (query?: string): Promise<void> => {
|
|
99
102
|
const seq = ++seqRef.current
|
|
@@ -108,23 +111,37 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
108
111
|
}
|
|
109
112
|
}, [api])
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// Debounced search: every keystroke re-filters through the API.
|
|
114
|
+
// Initial load fires once right away; later search edits debounce through the API.
|
|
115
|
+
const loadedApiRef = useRef<SshApi | null>(null)
|
|
114
116
|
useEffect(() => {
|
|
117
|
+
const query = search.trim()
|
|
118
|
+
const normalized = query === '' ? undefined : query
|
|
119
|
+
if (loadedApiRef.current !== api) {
|
|
120
|
+
loadedApiRef.current = api
|
|
121
|
+
void load(normalized)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
115
124
|
const timer = setTimeout(() => {
|
|
116
|
-
|
|
117
|
-
void load(query === '' ? undefined : query)
|
|
125
|
+
void load(normalized)
|
|
118
126
|
}, 300)
|
|
119
127
|
return () => { clearTimeout(timer) }
|
|
120
|
-
}, [search, load])
|
|
128
|
+
}, [api, search, load])
|
|
129
|
+
|
|
130
|
+
const reloadCurrent = (): void => {
|
|
131
|
+
const query = search.trim()
|
|
132
|
+
void load(query === '' ? undefined : query)
|
|
133
|
+
}
|
|
121
134
|
|
|
122
135
|
// Every async setState path guards with mountedRef, not just load(): a
|
|
123
136
|
// promise settling after unmount would setState against the torn-down
|
|
124
137
|
// environment (window is not defined, main-CI flake).
|
|
125
138
|
const runTest = async (alias: string): Promise<void> => {
|
|
126
139
|
if (!mountedRef.current) return
|
|
127
|
-
|
|
140
|
+
setTestingAliases(prev => {
|
|
141
|
+
const next = new Set(prev)
|
|
142
|
+
next.add(alias)
|
|
143
|
+
return next
|
|
144
|
+
})
|
|
128
145
|
try {
|
|
129
146
|
const result = await api.testHost(alias)
|
|
130
147
|
if (!mountedRef.current) return
|
|
@@ -133,7 +150,14 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
133
150
|
if (!mountedRef.current) return
|
|
134
151
|
setTestResults(prev => ({ ...prev, [alias]: { ok: false, error: errorMessage(cause) } }))
|
|
135
152
|
} finally {
|
|
136
|
-
if (mountedRef.current)
|
|
153
|
+
if (mountedRef.current) {
|
|
154
|
+
setTestingAliases(prev => {
|
|
155
|
+
if (!prev.has(alias)) return prev
|
|
156
|
+
const next = new Set(prev)
|
|
157
|
+
next.delete(alias)
|
|
158
|
+
return next
|
|
159
|
+
})
|
|
160
|
+
}
|
|
137
161
|
}
|
|
138
162
|
}
|
|
139
163
|
|
|
@@ -142,7 +166,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
142
166
|
try {
|
|
143
167
|
await api.deleteHost(alias)
|
|
144
168
|
if (!mountedRef.current) return
|
|
145
|
-
|
|
169
|
+
reloadCurrent()
|
|
146
170
|
} catch (cause) {
|
|
147
171
|
if (!mountedRef.current) return
|
|
148
172
|
setError(errorMessage(cause))
|
|
@@ -168,7 +192,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
168
192
|
if (!mountedRef.current) return
|
|
169
193
|
setNotice(tt('hosts.imported', { parsed: result.parsed, added: result.added, skipped: result.skipped }))
|
|
170
194
|
setImportSkips(result.skippedBlocks)
|
|
171
|
-
|
|
195
|
+
reloadCurrent()
|
|
172
196
|
} catch (cause) {
|
|
173
197
|
if (!mountedRef.current) return
|
|
174
198
|
setError(errorMessage(cause))
|
|
@@ -177,8 +201,9 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
177
201
|
}
|
|
178
202
|
}
|
|
179
203
|
|
|
180
|
-
const renderHostRow = (host:
|
|
204
|
+
const renderHostRow = (host: SshPanelHostSummary): ReactNode => {
|
|
181
205
|
const test = testResults[host.alias]
|
|
206
|
+
const testing = testingAliases.has(host.alias)
|
|
182
207
|
return (
|
|
183
208
|
<tr key={host.alias}>
|
|
184
209
|
<td className={css.mono}>{host.alias}</td>
|
|
@@ -198,10 +223,10 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
198
223
|
<td className={css.cellMuted}>{host.description ?? ''}</td>
|
|
199
224
|
<td>
|
|
200
225
|
<div className={css.actions}>
|
|
201
|
-
<button type="button" className={css.linkButton} disabled={
|
|
202
|
-
{
|
|
226
|
+
<button type="button" className={css.linkButton} disabled={testing} onClick={() => { void runTest(host.alias) }}>
|
|
227
|
+
{testing ? tt('hosts.testing') : tt('hosts.test')}
|
|
203
228
|
</button>
|
|
204
|
-
{
|
|
229
|
+
{testing && <span className={css.spinner} aria-hidden="true" />}
|
|
205
230
|
{test !== undefined && (
|
|
206
231
|
<span className={css.inlineTest} data-status={test.ok ? 'ok' : 'fail'}>
|
|
207
232
|
{test.ok ? tt('hosts.testOk', { latency: test.latencyMs ?? 0 }) : tt('hosts.testFail', { error: test.error ?? '' })}
|
|
@@ -216,7 +241,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
216
241
|
)
|
|
217
242
|
}
|
|
218
243
|
|
|
219
|
-
const renderHostTable = (rows:
|
|
244
|
+
const renderHostTable = (rows: SshPanelHostSummary[]): ReactNode => (
|
|
220
245
|
<table className={css.table}>
|
|
221
246
|
<thead>
|
|
222
247
|
<tr>
|
|
@@ -320,7 +345,7 @@ export function HostsTab({ api, onConnect }: HostsTabProps) {
|
|
|
320
345
|
api={api}
|
|
321
346
|
editing={dialog.mode === 'edit' ? dialog.host : null}
|
|
322
347
|
onClose={() => { setDialog(null) }}
|
|
323
|
-
onSaved={() => { setDialog(null);
|
|
348
|
+
onSaved={() => { setDialog(null); reloadCurrent() }}
|
|
324
349
|
/>
|
|
325
350
|
)}
|
|
326
351
|
</div>
|
|
@@ -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
|
)}
|
|
@@ -110,6 +110,8 @@ export function TerminalTab({ api, controller, presetAlias, terminalFont }: Term
|
|
|
110
110
|
const dataSubRef = useRef<IDisposable | null>(null)
|
|
111
111
|
/** Tab whose screen the terminal currently holds. */
|
|
112
112
|
const renderedRef = useRef<string | undefined>(undefined)
|
|
113
|
+
/** Last geometry pushed to the active socket to skip duplicate resizes. */
|
|
114
|
+
const lastSentSizeRef = useRef<{ connection: TerminalConnection; cols: number; rows: number } | null>(null)
|
|
113
115
|
/** Tabs with a background close in flight, so one click cannot open two. */
|
|
114
116
|
const closingRef = useRef<Set<string>>(new Set())
|
|
115
117
|
const fontSource = terminalFont ?? NO_FONT_SOURCE
|
|
@@ -129,7 +131,10 @@ export function TerminalTab({ api, controller, presetAlias, terminalFont }: Term
|
|
|
129
131
|
term.options.fontFamily = next
|
|
130
132
|
fitRef.current?.fit()
|
|
131
133
|
const link = linkRef.current
|
|
132
|
-
if (link !== null)
|
|
134
|
+
if (link !== null) {
|
|
135
|
+
link.connection.resize(term.cols, term.rows)
|
|
136
|
+
lastSentSizeRef.current = { connection: link.connection, cols: term.cols, rows: term.rows }
|
|
137
|
+
}
|
|
133
138
|
}, [fontOverride])
|
|
134
139
|
|
|
135
140
|
// Fetch the host list on tab activation.
|
|
@@ -159,17 +164,16 @@ export function TerminalTab({ api, controller, presetAlias, terminalFont }: Term
|
|
|
159
164
|
// height and the last line is clipped below the fold). ResizeObserver may
|
|
160
165
|
// be absent (jsdom tests); the window listener then remains the only path.
|
|
161
166
|
useEffect(() => {
|
|
162
|
-
let lastCols = -1
|
|
163
|
-
let lastRows = -1
|
|
164
167
|
const sync = (): void => {
|
|
165
168
|
const term = termRef.current
|
|
166
169
|
const fit = fitRef.current
|
|
167
170
|
if (term === null || fit === null) return
|
|
168
171
|
fit.fit()
|
|
169
172
|
const link = linkRef.current
|
|
170
|
-
if (link
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
if (link === null) return
|
|
174
|
+
const last = lastSentSizeRef.current
|
|
175
|
+
if (last === null || last.connection !== link.connection || term.cols !== last.cols || term.rows !== last.rows) {
|
|
176
|
+
lastSentSizeRef.current = { connection: link.connection, cols: term.cols, rows: term.rows }
|
|
173
177
|
link.connection.resize(term.cols, term.rows)
|
|
174
178
|
}
|
|
175
179
|
}
|
|
@@ -336,11 +340,12 @@ export function TerminalTab({ api, controller, presetAlias, terminalFont }: Term
|
|
|
336
340
|
}
|
|
337
341
|
if (tab.status === 'connected' && tab.sessionId !== undefined) {
|
|
338
342
|
const sessionId = tab.sessionId
|
|
343
|
+
// Always clear retained output before attaching: the host replays its
|
|
344
|
+
// full scrollback on attach, including after a panel remount where the
|
|
345
|
+
// local xterm starts fresh (renderedRef.current === undefined).
|
|
346
|
+
controller.clearTerminalOutput(tab.id)
|
|
339
347
|
if (needsScreenClear(tab.id)) {
|
|
340
|
-
// The host replays its scrollback on attach, so the screen starts empty
|
|
341
|
-
// and the retained copy is replaced by that replay.
|
|
342
348
|
view.term.reset()
|
|
343
|
-
controller.clearTerminalOutput(tab.id)
|
|
344
349
|
renderedRef.current = tab.id
|
|
345
350
|
}
|
|
346
351
|
bindConnection(tab, api.attachTerminal(sessionId, view.term.cols, view.term.rows))
|
|
@@ -72,6 +72,11 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
|
|
|
72
72
|
// state, and the list is diff-set so an unchanged poll tick keeps the
|
|
73
73
|
// previous state reference (no wasted re-render).
|
|
74
74
|
const seqRef = useRef(0)
|
|
75
|
+
const mountedRef = useRef(true)
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
mountedRef.current = true
|
|
78
|
+
return () => { mountedRef.current = false }
|
|
79
|
+
}, [])
|
|
75
80
|
const automaticRead = useRef<{ running: boolean; resume?: () => void }>({ running: false })
|
|
76
81
|
useEffect(() => {
|
|
77
82
|
if (!active) return
|
|
@@ -128,24 +133,26 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
|
|
|
128
133
|
}
|
|
129
134
|
}, [api, active])
|
|
130
135
|
|
|
131
|
-
const refresh = async (): Promise<void> => {
|
|
136
|
+
const refresh = async (preserveError = false): Promise<void> => {
|
|
132
137
|
const seq = ++seqRef.current
|
|
133
138
|
try {
|
|
134
139
|
const list = await api.listTunnels()
|
|
135
|
-
if (seq !== seqRef.current) return
|
|
140
|
+
if (!mountedRef.current || seq !== seqRef.current) return
|
|
136
141
|
setTunnels(list)
|
|
137
|
-
setError(null)
|
|
142
|
+
if (!preserveError) setError(null)
|
|
138
143
|
} catch (cause) {
|
|
139
|
-
if (seq !== seqRef.current) return
|
|
140
|
-
setError(errorMessage(cause))
|
|
144
|
+
if (!mountedRef.current || seq !== seqRef.current) return
|
|
145
|
+
if (!preserveError) setError(errorMessage(cause))
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
const stopTunnel = async (tunnelId: string): Promise<void> => {
|
|
145
150
|
try {
|
|
146
151
|
await api.stopTunnel(tunnelId)
|
|
152
|
+
if (!mountedRef.current) return
|
|
147
153
|
await refresh()
|
|
148
154
|
} catch (cause) {
|
|
155
|
+
if (!mountedRef.current) return
|
|
149
156
|
setError(errorMessage(cause))
|
|
150
157
|
}
|
|
151
158
|
}
|
|
@@ -155,11 +162,13 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
|
|
|
155
162
|
setBusy(true)
|
|
156
163
|
try {
|
|
157
164
|
await api.stopAllTunnels(alias === '' ? undefined : alias)
|
|
165
|
+
if (!mountedRef.current) return
|
|
158
166
|
await refresh()
|
|
159
167
|
} catch (cause) {
|
|
168
|
+
if (!mountedRef.current) return
|
|
160
169
|
setError(errorMessage(cause))
|
|
161
170
|
} finally {
|
|
162
|
-
setBusy(false)
|
|
171
|
+
if (mountedRef.current) setBusy(false)
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
174
|
|
|
@@ -176,6 +185,7 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
|
|
|
176
185
|
return
|
|
177
186
|
}
|
|
178
187
|
setBusy(true)
|
|
188
|
+
setError(null)
|
|
179
189
|
setNotice(null)
|
|
180
190
|
try {
|
|
181
191
|
const tunnel = await api.startTunnel({
|
|
@@ -184,15 +194,22 @@ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
|
|
|
184
194
|
remoteHost: remoteHost.trim() === '' ? undefined : remoteHost.trim(),
|
|
185
195
|
localPort: localPortNumber,
|
|
186
196
|
})
|
|
197
|
+
if (!mountedRef.current) return
|
|
198
|
+
if (tunnel.state === 'failed') {
|
|
199
|
+
setError(tt('tunnel.failed', { error: tunnel.error ?? 'unknown error' }))
|
|
200
|
+
await refresh(true)
|
|
201
|
+
return
|
|
202
|
+
}
|
|
187
203
|
setNotice(tt('tunnel.started', { localPort: tunnel.localPort }))
|
|
188
204
|
setRemotePort('')
|
|
189
205
|
setRemoteHost('')
|
|
190
206
|
setLocalPort('')
|
|
191
207
|
await refresh()
|
|
192
208
|
} catch (cause) {
|
|
209
|
+
if (!mountedRef.current) return
|
|
193
210
|
setError(tt('tunnel.failed', { error: errorMessage(cause) }))
|
|
194
211
|
} finally {
|
|
195
|
-
setBusy(false)
|
|
212
|
+
if (mountedRef.current) setBusy(false)
|
|
196
213
|
}
|
|
197
214
|
}
|
|
198
215
|
|