dsh-ssh-hub 0.0.0-stage → 0.2.0

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.
Files changed (133) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +271 -2
  3. package/cordis.patch.yml +16 -0
  4. package/icon.svg +3 -0
  5. package/lib/client.js +13975 -0
  6. package/lib/index.js +6908 -0
  7. package/lib/types/activity/history.d.ts +50 -0
  8. package/lib/types/alerting/notify.d.ts +89 -0
  9. package/lib/types/alerting/prompt-summary.d.ts +28 -0
  10. package/lib/types/alerting/rules.d.ts +135 -0
  11. package/lib/types/alerting/tools.d.ts +30 -0
  12. package/lib/types/audit/audit-log.d.ts +84 -0
  13. package/lib/types/audit/recorder.d.ts +50 -0
  14. package/lib/types/client/api.d.ts +222 -0
  15. package/lib/types/client/index.d.ts +45 -0
  16. package/lib/types/client/locales.d.ts +319 -0
  17. package/lib/types/client/native-panel.d.ts +70 -0
  18. package/lib/types/client/panel/ClusterTab.d.ts +7 -0
  19. package/lib/types/client/panel/DeployTab.d.ts +10 -0
  20. package/lib/types/client/panel/FleetTab.d.ts +10 -0
  21. package/lib/types/client/panel/HostFormDialog.d.ts +12 -0
  22. package/lib/types/client/panel/HostsTab.d.ts +25 -0
  23. package/lib/types/client/panel/LogsTab.d.ts +10 -0
  24. package/lib/types/client/panel/SshPanel.d.ts +14 -0
  25. package/lib/types/client/panel/TerminalTab.d.ts +27 -0
  26. package/lib/types/client/panel/TransferTab.d.ts +7 -0
  27. package/lib/types/client/panel/TunnelEditDialog.d.ts +15 -0
  28. package/lib/types/client/panel/TunnelsTab.d.ts +27 -0
  29. package/lib/types/client/panel/controller.d.ts +253 -0
  30. package/lib/types/client/panel/helpers.d.ts +45 -0
  31. package/lib/types/client/panel/tabs.d.ts +62 -0
  32. package/lib/types/client/panel/xterm.css.d.ts +2 -0
  33. package/lib/types/client/settings-binding.d.ts +71 -0
  34. package/lib/types/deploy/orchestrator.d.ts +158 -0
  35. package/lib/types/deploy/tools.d.ts +14 -0
  36. package/lib/types/dsh-home.d.ts +16 -0
  37. package/lib/types/engine/cluster.d.ts +19 -0
  38. package/lib/types/engine/connection-pool.d.ts +183 -0
  39. package/lib/types/engine/proxy-command.d.ts +36 -0
  40. package/lib/types/engine/pty.d.ts +32 -0
  41. package/lib/types/engine/sftp.d.ts +20 -0
  42. package/lib/types/engine/terminal-sessions.d.ts +67 -0
  43. package/lib/types/engine/tunnel-discovery.d.ts +89 -0
  44. package/lib/types/engine/tunnel-remarks.d.ts +49 -0
  45. package/lib/types/engine/tunnel.d.ts +76 -0
  46. package/lib/types/engine.d.ts +103 -0
  47. package/lib/types/http.d.ts +59 -0
  48. package/lib/types/index.d.ts +128 -0
  49. package/lib/types/inspect/checks.d.ts +118 -0
  50. package/lib/types/inspect/inspection.d.ts +111 -0
  51. package/lib/types/inspect/tools.d.ts +50 -0
  52. package/lib/types/logs/search.d.ts +131 -0
  53. package/lib/types/logs/tools.d.ts +6 -0
  54. package/lib/types/loopback.d.ts +64 -0
  55. package/lib/types/monitor/loop.d.ts +133 -0
  56. package/lib/types/monitor/metrics.d.ts +151 -0
  57. package/lib/types/mount-once.d.ts +55 -0
  58. package/lib/types/protocol.d.ts +524 -0
  59. package/lib/types/routes.d.ts +82 -0
  60. package/lib/types/security/known-hosts.d.ts +153 -0
  61. package/lib/types/security/master-secret.d.ts +157 -0
  62. package/lib/types/security/redact.d.ts +44 -0
  63. package/lib/types/security/secrets.d.ts +70 -0
  64. package/lib/types/ssh-config.d.ts +42 -0
  65. package/lib/types/store.d.ts +183 -0
  66. package/lib/types/tool-surface.d.ts +72 -0
  67. package/lib/types/tools.d.ts +56 -0
  68. package/locale/en.json +6 -0
  69. package/locale/zh.json +6 -0
  70. package/package.json +126 -6
  71. package/src/activity/history.ts +117 -0
  72. package/src/alerting/notify.ts +212 -0
  73. package/src/alerting/prompt-summary.ts +71 -0
  74. package/src/alerting/rules.ts +281 -0
  75. package/src/alerting/tools.ts +263 -0
  76. package/src/audit/audit-log.ts +199 -0
  77. package/src/audit/recorder.ts +73 -0
  78. package/src/client/api.ts +782 -0
  79. package/src/client/css-modules.d.ts +5 -0
  80. package/src/client/index.ts +150 -0
  81. package/src/client/locales.ts +654 -0
  82. package/src/client/native-panel.tsx +141 -0
  83. package/src/client/panel/ClusterTab.tsx +141 -0
  84. package/src/client/panel/DeployTab.tsx +314 -0
  85. package/src/client/panel/FleetTab.tsx +494 -0
  86. package/src/client/panel/HostFormDialog.tsx +289 -0
  87. package/src/client/panel/HostsTab.tsx +395 -0
  88. package/src/client/panel/LogsTab.tsx +208 -0
  89. package/src/client/panel/SshPanel.tsx +105 -0
  90. package/src/client/panel/TerminalTab.tsx +550 -0
  91. package/src/client/panel/TransferTab.tsx +238 -0
  92. package/src/client/panel/TunnelEditDialog.tsx +174 -0
  93. package/src/client/panel/TunnelsTab.tsx +328 -0
  94. package/src/client/panel/controller.ts +507 -0
  95. package/src/client/panel/helpers.ts +84 -0
  96. package/src/client/panel/panel.module.css +1734 -0
  97. package/src/client/panel/tabs.ts +52 -0
  98. package/src/client/panel/xterm.css.ts +2 -0
  99. package/src/client/settings-binding.ts +184 -0
  100. package/src/deploy/orchestrator.ts +326 -0
  101. package/src/deploy/tools.ts +225 -0
  102. package/src/dsh-home.ts +42 -0
  103. package/src/engine/cluster.ts +60 -0
  104. package/src/engine/connection-pool.ts +721 -0
  105. package/src/engine/proxy-command.ts +248 -0
  106. package/src/engine/pty.ts +78 -0
  107. package/src/engine/sftp.ts +229 -0
  108. package/src/engine/terminal-sessions.ts +280 -0
  109. package/src/engine/tunnel-discovery.ts +353 -0
  110. package/src/engine/tunnel-remarks.ts +120 -0
  111. package/src/engine/tunnel.ts +300 -0
  112. package/src/engine.ts +195 -0
  113. package/src/http.ts +127 -0
  114. package/src/index.ts +690 -0
  115. package/src/inspect/checks.ts +251 -0
  116. package/src/inspect/inspection.ts +321 -0
  117. package/src/inspect/tools.ts +366 -0
  118. package/src/logs/search.ts +251 -0
  119. package/src/logs/tools.ts +160 -0
  120. package/src/loopback.ts +119 -0
  121. package/src/monitor/loop.ts +265 -0
  122. package/src/monitor/metrics.ts +333 -0
  123. package/src/mount-once.ts +142 -0
  124. package/src/protocol.ts +534 -0
  125. package/src/routes.ts +998 -0
  126. package/src/security/known-hosts.ts +342 -0
  127. package/src/security/master-secret.ts +334 -0
  128. package/src/security/redact.ts +119 -0
  129. package/src/security/secrets.ts +152 -0
  130. package/src/ssh-config.ts +182 -0
  131. package/src/store.ts +757 -0
  132. package/src/tool-surface.ts +96 -0
  133. package/src/tools.ts +550 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * Tunnels tab: the live local port-forward list (auto-refresh every 5s while
3
+ * visible) with per-row edit and stop, a stop-all action scoped to the selected
4
+ * alias, and a new-tunnel form.
5
+ */
6
+ import { useEffect, useRef, useState } from 'react'
7
+ import type { SshApi } from '../api.ts'
8
+ import type { SshHostSummary, TunnelInfo } from '../../protocol.ts'
9
+ import { errorMessage, tt } from './helpers.ts'
10
+ import { TunnelEditDialog } from './TunnelEditDialog.tsx'
11
+ import css from './panel.module.css'
12
+
13
+ /** Live-tunnel polling interval while the tab and page are visible (ms). */
14
+ export const TUNNEL_POLL_MS = 5000
15
+
16
+ /**
17
+ * Return `next` only when the tunnel list changed in a user-visible way
18
+ * (identity, ordering or any renderable field), else `null` so a poll tick
19
+ * with no real change keeps the previous reference and React skips the
20
+ * re-render. `prev === null` (first load) always accepts the list.
21
+ */
22
+ export function diffTunnels(prev: TunnelInfo[] | null, next: TunnelInfo[]): TunnelInfo[] | null {
23
+ if (prev === null) return next
24
+ if (prev.length !== next.length) return next
25
+ for (let index = 0; index < prev.length; index += 1) {
26
+ const a = prev[index]
27
+ const b = next[index]
28
+ if (a.id !== b.id || a.alias !== b.alias || a.state !== b.state
29
+ || a.localPort !== b.localPort || a.remoteHost !== b.remoteHost
30
+ || a.remotePort !== b.remotePort || a.startedAt !== b.startedAt
31
+ || a.error !== b.error || a.source !== b.source || a.pid !== b.pid
32
+ || a.live !== b.live || a.kind !== b.kind
33
+ || a.name !== b.name || a.description !== b.description
34
+ || a.customRemark !== b.customRemark) {
35
+ return next
36
+ }
37
+ }
38
+ return null
39
+ }
40
+
41
+ /** Tunnels tab props. */
42
+ export interface TunnelsTabProps {
43
+ api: SshApi
44
+ /** Pause automatic reads while the owning panel is closed, preserving form state. */
45
+ active?: boolean
46
+ }
47
+
48
+ /** The tunnels tab. */
49
+ /**
50
+ * Whether any forward is one this plugin can stop.
51
+ *
52
+ * External forwards belong to processes we did not start, so "Stop all" must not
53
+ * be offered when they are all there is: the button would look enabled and do
54
+ * nothing. Kept as a pure function so the rule can be asserted without a browser.
55
+ */
56
+ export function hasOwnedTunnels(tunnels: TunnelInfo[] | null): boolean {
57
+ return (tunnels ?? []).some(tunnel => tunnel.source !== 'external')
58
+ }
59
+
60
+ export function TunnelsTab({ api, active = true }: TunnelsTabProps) {
61
+ const [hosts, setHosts] = useState<SshHostSummary[]>([])
62
+ const [tunnels, setTunnels] = useState<TunnelInfo[] | null>(null)
63
+ const [error, setError] = useState<string | null>(null)
64
+ const [notice, setNotice] = useState<string | null>(null)
65
+ const [alias, setAlias] = useState('')
66
+ const [remotePort, setRemotePort] = useState('')
67
+ const [remoteHost, setRemoteHost] = useState('')
68
+ const [localPort, setLocalPort] = useState('')
69
+ const [name, setName] = useState('')
70
+ const [busy, setBusy] = useState(false)
71
+ const [editing, setEditing] = useState<TunnelInfo | null>(null)
72
+
73
+ // Hosts for the new-tunnel form (failure does not block tunnel listing).
74
+ useEffect(() => {
75
+ let disposed = false
76
+ void (async () => {
77
+ try {
78
+ const list = await api.listHosts()
79
+ if (!disposed) setHosts(list)
80
+ } catch {
81
+ // Tunnels may still exist; keep the list usable.
82
+ }
83
+ })()
84
+ return () => { disposed = true }
85
+ }, [api])
86
+
87
+ // Live list with a TUNNEL_POLL_MS heartbeat while visible. Every load
88
+ // carries a sequence number so stale responses never overwrite newer
89
+ // state, and the list is diff-set so an unchanged poll tick keeps the
90
+ // previous state reference (no wasted re-render).
91
+ const seqRef = useRef(0)
92
+ const automaticRead = useRef<{ running: boolean; resume?: () => void }>({ running: false })
93
+ useEffect(() => {
94
+ if (!active) return
95
+ let disposed = false
96
+ const read = automaticRead.current
97
+ let timer: ReturnType<typeof setInterval> | undefined
98
+ const load = async (): Promise<void> => {
99
+ if (disposed || read.running || document.visibilityState === 'hidden') return
100
+ read.running = true
101
+ const seq = ++seqRef.current
102
+ try {
103
+ const list = await api.listTunnels()
104
+ if (disposed || seq !== seqRef.current) return
105
+ setTunnels(prev => diffTunnels(prev, list) ?? prev)
106
+ setError(null)
107
+ } catch (cause) {
108
+ if (disposed || seq !== seqRef.current) return
109
+ setError(errorMessage(cause))
110
+ } finally {
111
+ read.running = false
112
+ const resume = read.resume
113
+ read.resume = undefined
114
+ resume?.()
115
+ }
116
+ }
117
+ const resume = (): void => {
118
+ if (disposed || document.visibilityState === 'hidden') return
119
+ // Rapid close/reopen must not start more reads while the old effect's
120
+ // request is pending. Keep only the latest visible refresh.
121
+ if (read.running) read.resume = resume
122
+ else void load()
123
+ }
124
+ const stop = (): void => {
125
+ if (timer !== undefined) clearInterval(timer)
126
+ timer = undefined
127
+ }
128
+ const onVisibility = (): void => {
129
+ if (document.visibilityState === 'hidden') {
130
+ stop()
131
+ if (read.resume === resume) read.resume = undefined
132
+ } else if (timer === undefined) {
133
+ resume()
134
+ timer = setInterval(() => { void load() }, TUNNEL_POLL_MS)
135
+ }
136
+ }
137
+ document.addEventListener('visibilitychange', onVisibility)
138
+ onVisibility()
139
+ return () => {
140
+ disposed = true
141
+ seqRef.current += 1
142
+ if (read.resume === resume) read.resume = undefined
143
+ stop()
144
+ document.removeEventListener('visibilitychange', onVisibility)
145
+ }
146
+ }, [api, active])
147
+
148
+ const refresh = async (): Promise<void> => {
149
+ const seq = ++seqRef.current
150
+ try {
151
+ const list = await api.listTunnels()
152
+ if (seq !== seqRef.current) return
153
+ setTunnels(list)
154
+ setError(null)
155
+ } catch (cause) {
156
+ if (seq !== seqRef.current) return
157
+ setError(errorMessage(cause))
158
+ }
159
+ }
160
+
161
+ const stopTunnel = async (tunnelId: string): Promise<void> => {
162
+ try {
163
+ await api.stopTunnel(tunnelId)
164
+ await refresh()
165
+ } catch (cause) {
166
+ setError(errorMessage(cause))
167
+ }
168
+ }
169
+
170
+ const stopAll = async (): Promise<void> => {
171
+ if (!window.confirm(tt('tunnel.stopAllConfirm'))) return
172
+ setBusy(true)
173
+ try {
174
+ await api.stopAllTunnels(alias === '' ? undefined : alias)
175
+ await refresh()
176
+ } catch (cause) {
177
+ setError(errorMessage(cause))
178
+ } finally {
179
+ setBusy(false)
180
+ }
181
+ }
182
+
183
+ const start = async (): Promise<void> => {
184
+ if (alias === '' || remotePort.trim() === '') return
185
+ const remotePortNumber = Number(remotePort)
186
+ const localPortNumber = localPort.trim() === '' ? undefined : Number(localPort)
187
+ if (!Number.isInteger(remotePortNumber) || remotePortNumber < 1 || remotePortNumber > 65535) {
188
+ setError(tt('form.portInvalid'))
189
+ return
190
+ }
191
+ if (localPortNumber !== undefined && (!Number.isInteger(localPortNumber) || localPortNumber < 1 || localPortNumber > 65535)) {
192
+ setError(tt('form.portInvalid'))
193
+ return
194
+ }
195
+ setBusy(true)
196
+ setNotice(null)
197
+ try {
198
+ const tunnel = await api.startTunnel({
199
+ alias,
200
+ remotePort: remotePortNumber,
201
+ remoteHost: remoteHost.trim() === '' ? undefined : remoteHost.trim(),
202
+ localPort: localPortNumber,
203
+ name: name.trim() === '' ? undefined : name.trim(),
204
+ })
205
+ setNotice(tt('tunnel.started', { localPort: tunnel.localPort }))
206
+ setRemotePort('')
207
+ setRemoteHost('')
208
+ setLocalPort('')
209
+ setName('')
210
+ await refresh()
211
+ } catch (cause) {
212
+ setError(tt('tunnel.failed', { error: errorMessage(cause) }))
213
+ } finally {
214
+ setBusy(false)
215
+ }
216
+ }
217
+
218
+ const ownedExists = hasOwnedTunnels(tunnels)
219
+
220
+ return (
221
+ <div className={css.tabBody}>
222
+ <div className={css.controls}>
223
+ {/* "Stop all" can only act on forwards this plugin owns. When every row
224
+ is an external process it would do nothing at all, so it is hidden
225
+ rather than left there to disappoint the click. */}
226
+ {ownedExists && (
227
+ <button type="button" className={css.ghostButton} disabled={busy} onClick={() => { void stopAll() }}>{tt('tunnel.stopAll')}</button>
228
+ )}
229
+ <button type="button" className={css.ghostButton} onClick={() => { void refresh() }}>{tt('common.refresh')}</button>
230
+ </div>
231
+ {error !== null && <div className={css.banner} data-kind="error" role="alert">{error}</div>}
232
+ {notice !== null && <div className={css.banner} data-kind="ok" role="status">{notice}</div>}
233
+ {tunnels !== null && tunnels.length === 0 && <div className={css.empty}>{tt('tunnel.empty')}</div>}
234
+ {(tunnels ?? []).some(tunnel => tunnel.source === 'external') && (
235
+ <div className={css.hint}>{tt('tunnel.externalHint')}</div>
236
+ )}
237
+ <div className={css.tunnelList}>
238
+ {(tunnels ?? []).map(tunnel => (
239
+ <div
240
+ key={tunnel.id}
241
+ className={css.tunnelRow}
242
+ data-state={tunnel.state}
243
+ data-source={tunnel.source ?? 'plugin'}
244
+ >
245
+ <div className={css.tunnelInfo}>
246
+ <div className={css.tunnelHeaderLine}>
247
+ {tunnel.name !== undefined && tunnel.name !== '' && (
248
+ <span className={css.tunnelName}>{tunnel.name}</span>
249
+ )}
250
+ <span className={css.tunnelEndpoint}>
251
+ {tunnel.alias}: 127.0.0.1:{tunnel.localPort} -&gt; {tunnel.remoteHost}:{tunnel.remotePort}
252
+ </span>
253
+ </div>
254
+ {(Boolean(tunnel.description) || tunnel.source === 'external') && (
255
+ <div className={css.tunnelMetaLine}>
256
+ {tunnel.customRemark === true && (
257
+ <span className={css.tunnelRemarkTag}>{tt('tunnel.customRemark')}</span>
258
+ )}
259
+ {tunnel.description !== undefined && tunnel.description !== '' && (
260
+ <span className={css.tunnelDesc}>{tunnel.description}</span>
261
+ )}
262
+ {tunnel.source === 'external' && (
263
+ <span className={css.tunnelPid}>{tt('tunnel.externalMeta', { pid: tunnel.pid ?? 0 })}</span>
264
+ )}
265
+ </div>
266
+ )}
267
+ </div>
268
+ <div className={css.tunnelActions}>
269
+ <button type="button" className={css.ghostButton} onClick={() => { setEditing(tunnel) }}>{tt('tunnel.edit')}</button>
270
+ {tunnel.source === 'external'
271
+ ? (
272
+ <span className={css.tunnelState} data-live={tunnel.live === true ? 'true' : 'false'}>
273
+ {tunnel.live === true ? tt('tunnel.externalLive') : tt('tunnel.externalDead')}
274
+ </span>
275
+ )
276
+ : (
277
+ <button type="button" className={css.ghostButton} onClick={() => { void stopTunnel(tunnel.id) }}>{tt('tunnel.stop')}</button>
278
+ )}
279
+ </div>
280
+ </div>
281
+ ))}
282
+ </div>
283
+ {editing !== null && (
284
+ <TunnelEditDialog
285
+ api={api}
286
+ tunnel={editing}
287
+ onClose={() => { setEditing(null) }}
288
+ onSaved={notice => {
289
+ setEditing(null)
290
+ setNotice(notice)
291
+ setError(null)
292
+ void refresh()
293
+ }}
294
+ />
295
+ )}
296
+ <div className={css.formCard}>
297
+ <div className={css.formRow}>
298
+ <label className={css.field}>
299
+ <span className={css.fieldLabel}>{tt('tunnel.alias')}</span>
300
+ <select className={css.input} value={alias} onChange={event => { setAlias(event.target.value) }}>
301
+ <option value="">{tt('terminal.selectHost')}</option>
302
+ {hosts.map(host => <option key={host.alias} value={host.alias}>{host.alias}</option>)}
303
+ </select>
304
+ </label>
305
+ <label className={css.field}>
306
+ <span className={css.fieldLabel}>{tt('tunnel.remotePort')}</span>
307
+ <input className={css.input} type="number" min={1} max={65535} value={remotePort} onChange={event => { setRemotePort(event.target.value) }} />
308
+ </label>
309
+ <label className={css.field}>
310
+ <span className={css.fieldLabel}>{tt('tunnel.remoteHost')}</span>
311
+ <input className={css.input} value={remoteHost} placeholder={tt('tunnel.remoteHostHint')} onChange={event => { setRemoteHost(event.target.value) }} />
312
+ </label>
313
+ <label className={css.field}>
314
+ <span className={css.fieldLabel}>{tt('tunnel.localPort')}</span>
315
+ <input className={css.input} type="number" min={1} max={65535} value={localPort} placeholder={tt('tunnel.localPortHint')} onChange={event => { setLocalPort(event.target.value) }} />
316
+ </label>
317
+ <label className={css.field}>
318
+ <span className={css.fieldLabel}>{tt('tunnel.name')}</span>
319
+ <input className={css.input} value={name} placeholder={tt('tunnel.nameHint')} onChange={event => { setName(event.target.value) }} />
320
+ </label>
321
+ </div>
322
+ <div>
323
+ <button type="button" className={css.primaryButton} disabled={busy || alias === '' || remotePort.trim() === ''} onClick={() => { void start() }}>{tt('tunnel.start')}</button>
324
+ </div>
325
+ </div>
326
+ </div>
327
+ )
328
+ }