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,238 @@
1
+ /**
2
+ * Transfer tab: upload/download one file with progress, plus a toggleable
3
+ * remote directory browser (api.ls) whose file rows fill the remote path
4
+ * input and whose directory rows navigate.
5
+ */
6
+ import { useEffect, useRef, useState, type ChangeEvent } from 'react'
7
+ import type { SshApi } from '../api.ts'
8
+ import type { RemoteDirEntry, SshHostSummary, TransferProgress } from '../../protocol.ts'
9
+ import { errorMessage, tt } from './helpers.ts'
10
+ import css from './panel.module.css'
11
+
12
+ /** Transfer tab props. */
13
+ export interface TransferTabProps {
14
+ api: SshApi
15
+ }
16
+
17
+ /** One in-flight transfer (drives the progress bar). */
18
+ interface TransferState {
19
+ kind: 'upload' | 'download'
20
+ phase: TransferProgress['phase']
21
+ percent: number
22
+ speedBps?: number
23
+ file: string
24
+ }
25
+
26
+ /** The last transfer's outcome line. */
27
+ type TransferStatus = { kind: 'ok'; bytes: number } | { kind: 'error'; error: string }
28
+
29
+ /** Join a directory path with a child entry name. */
30
+ function joinRemotePath(dir: string, name: string): string {
31
+ const base = dir.endsWith('/') ? dir : dir + '/'
32
+ return base + name
33
+ }
34
+
35
+ /** Parent path of a remote directory ('/' stays '/'). */
36
+ function parentOf(dir: string): string {
37
+ const trimmed = dir.replace(/\/+$/, '')
38
+ const index = trimmed.lastIndexOf('/')
39
+ if (index <= 0) return '/'
40
+ return trimmed.slice(0, index)
41
+ }
42
+
43
+ /** Human byte sizes through the transfer.* locale templates. */
44
+ function formatBytes(bytes: number): string {
45
+ if (bytes < 1024) return tt('transfer.bytes', { value: bytes })
46
+ if (bytes < 1024 * 1024) return tt('transfer.kib', { value: (bytes / 1024).toFixed(1) })
47
+ if (bytes < 1024 * 1024 * 1024) return tt('transfer.mib', { value: (bytes / (1024 * 1024)).toFixed(1) })
48
+ return tt('transfer.gib', { value: (bytes / (1024 * 1024 * 1024)).toFixed(1) })
49
+ }
50
+
51
+ /** The upload/download tab. */
52
+ export function TransferTab({ api }: TransferTabProps) {
53
+ const [hosts, setHosts] = useState<SshHostSummary[]>([])
54
+ const [listError, setListError] = useState<string | null>(null)
55
+ const [alias, setAlias] = useState('')
56
+ const [remotePath, setRemotePath] = useState('')
57
+ const [browseOpen, setBrowseOpen] = useState(false)
58
+ const [browseDir, setBrowseDir] = useState('/')
59
+ const [entries, setEntries] = useState<RemoteDirEntry[]>([])
60
+ const [browsing, setBrowsing] = useState(false)
61
+ const [transfer, setTransfer] = useState<TransferState | null>(null)
62
+ const [status, setStatus] = useState<TransferStatus | null>(null)
63
+ const fileRef = useRef<HTMLInputElement | null>(null)
64
+ const seqRef = useRef(0)
65
+
66
+ useEffect(() => {
67
+ let disposed = false
68
+ void (async () => {
69
+ try {
70
+ const list = await api.listHosts()
71
+ if (!disposed) setHosts(list)
72
+ } catch (cause) {
73
+ if (!disposed) setListError(errorMessage(cause))
74
+ }
75
+ })()
76
+ return () => { disposed = true }
77
+ }, [api])
78
+
79
+ const loadDir = async (path: string): Promise<void> => {
80
+ if (alias === '') return
81
+ const seq = ++seqRef.current
82
+ setBrowsing(true)
83
+ try {
84
+ const list = await api.ls(alias, path)
85
+ if (seq !== seqRef.current) return
86
+ const sorted = [...list].sort((a, b) => {
87
+ if (a.type !== b.type) return a.type === 'dir' ? -1 : 1
88
+ return a.name.localeCompare(b.name)
89
+ })
90
+ setEntries(sorted)
91
+ setBrowseDir(path)
92
+ setListError(null)
93
+ } catch (cause) {
94
+ if (seq === seqRef.current) setListError(errorMessage(cause))
95
+ } finally {
96
+ if (seq === seqRef.current) setBrowsing(false)
97
+ }
98
+ }
99
+
100
+ const openBrowse = (): void => {
101
+ if (alias === '') return
102
+ setBrowseOpen(true)
103
+ const path = remotePath.trim() === '' ? '/' : remotePath.trim()
104
+ void loadDir(path)
105
+ }
106
+
107
+ const handleFile = async (event: ChangeEvent<HTMLInputElement>): Promise<void> => {
108
+ const file = event.target.files?.[0]
109
+ event.target.value = ''
110
+ if (file === undefined || alias === '' || remotePath.trim() === '' || transfer !== null) return
111
+ setStatus(null)
112
+ setTransfer({ kind: 'upload', phase: 'connecting', percent: 0, file: file.name })
113
+ try {
114
+ const outcome = await api.uploadFile(file, alias, remotePath.trim(), progress => {
115
+ setTransfer(prev => prev === null ? prev : {
116
+ kind: 'upload',
117
+ phase: progress.phase,
118
+ percent: progress.percent,
119
+ speedBps: progress.speedBps,
120
+ file: progress.file,
121
+ })
122
+ })
123
+ setStatus({ kind: 'ok', bytes: outcome.transferredBytes })
124
+ } catch (cause) {
125
+ setStatus({ kind: 'error', error: errorMessage(cause) })
126
+ } finally {
127
+ setTransfer(null)
128
+ }
129
+ }
130
+
131
+ const handleDownload = async (): Promise<void> => {
132
+ if (alias === '' || remotePath.trim() === '' || transfer !== null) return
133
+ setStatus(null)
134
+ setTransfer({ kind: 'download', phase: 'connecting', percent: 0, file: remotePath.trim() })
135
+ try {
136
+ const result = await api.downloadFile(alias, remotePath.trim(), progress => {
137
+ setTransfer(prev => prev === null ? prev : {
138
+ kind: 'download',
139
+ phase: progress.phase,
140
+ percent: progress.percent,
141
+ speedBps: progress.speedBps,
142
+ file: progress.file,
143
+ })
144
+ })
145
+ // Streamed downloads (File System Access API) were already saved; the
146
+ // Blob fallback triggers a browser save here.
147
+ if (!result.streamed && result.blob !== undefined) {
148
+ const url = URL.createObjectURL(result.blob)
149
+ const anchor = document.createElement('a')
150
+ anchor.href = url
151
+ anchor.download = result.filename
152
+ document.body.appendChild(anchor)
153
+ anchor.click()
154
+ anchor.remove()
155
+ // Defer the revoke: some engines need the URL alive past the click.
156
+ setTimeout(() => { URL.revokeObjectURL(url) }, 10_000)
157
+ }
158
+ setStatus({ kind: 'ok', bytes: result.bytes })
159
+ } catch (cause) {
160
+ setStatus({ kind: 'error', error: errorMessage(cause) })
161
+ } finally {
162
+ setTransfer(null)
163
+ }
164
+ }
165
+
166
+ const ready = alias !== '' && remotePath.trim() !== '' && transfer === null
167
+
168
+ return (
169
+ <div className={css.tabBody}>
170
+ <div className={css.controls}>
171
+ <select className={css.input} value={alias} onChange={event => { setAlias(event.target.value) }}>
172
+ <option value="">{tt('transfer.selectHost')}</option>
173
+ {hosts.map(host => <option key={host.alias} value={host.alias}>{host.alias} ({host.host})</option>)}
174
+ </select>
175
+ <input className={css.input} placeholder={tt('transfer.remotePathHint')} value={remotePath} onChange={event => { setRemotePath(event.target.value) }} />
176
+ <button type="button" className={css.ghostButton} disabled={alias === ''} onClick={openBrowse}>{tt('transfer.browseRemote')}</button>
177
+ <div className={css.toolbarSpacer} />
178
+ <button type="button" className={css.primaryButton} disabled={!ready} onClick={() => { fileRef.current?.click() }}>{tt('transfer.upload')}</button>
179
+ <button type="button" className={css.ghostButton} disabled={!ready} onClick={() => { void handleDownload() }}>{tt('transfer.download')}</button>
180
+ <input ref={fileRef} type="file" className={css.hiddenFile} onChange={event => { void handleFile(event) }} />
181
+ </div>
182
+ {listError !== null && <div className={css.banner} data-kind="error" role="alert">{tt('common.error', { error: listError })}</div>}
183
+ {browseOpen && (
184
+ <div className={css.browsePanel}>
185
+ <div className={css.browseHeader}>
186
+ <span className={css.browsePath}>{browseDir}</span>
187
+ <button type="button" className={css.linkButton} disabled={browsing} onClick={() => { void loadDir(browseDir) }}>{tt('transfer.refresh')}</button>
188
+ </div>
189
+ <div className={css.browseList}>
190
+ {browseDir !== '/' && (
191
+ <button type="button" className={css.dirRow} data-up onClick={() => { void loadDir(parentOf(browseDir)) }}>
192
+ <span className={css.dirName}>{tt('transfer.upLevel')}</span>
193
+ <span className={css.dirType} />
194
+ <span className={css.dirSize} />
195
+ </button>
196
+ )}
197
+ {/* An empty directory used to render nothing at all, which is
198
+ indistinguishable from a listing that failed to load. Every other
199
+ list surface in the panel states emptiness explicitly. */}
200
+ {entries.length === 0 && (
201
+ <div className={css.empty}>{tt('transfer.emptyDir')}</div>
202
+ )}
203
+ {entries.map(entry => (
204
+ <button key={entry.name} type="button" className={css.dirRow} data-type={entry.type} onClick={() => {
205
+ if (entry.type === 'dir') {
206
+ void loadDir(joinRemotePath(browseDir, entry.name))
207
+ } else {
208
+ setRemotePath(joinRemotePath(browseDir, entry.name))
209
+ }
210
+ }}>
211
+ <span className={css.dirName}>{entry.name}</span>
212
+ <span className={css.dirType}>{entry.type === 'dir' ? '[' + tt('transfer.dir') + ']' : entry.type === 'file' ? '[' + tt('transfer.file') + ']' : ''}</span>
213
+ <span className={css.dirSize}>{formatBytes(entry.size)}</span>
214
+ </button>
215
+ ))}
216
+ </div>
217
+ </div>
218
+ )}
219
+ {transfer !== null && (
220
+ <div className={css.transferBlock}>
221
+ <div className={css.progressMeta}>
222
+ <span>{transfer.kind === 'upload' ? tt('transfer.uploading', { file: transfer.file }) : tt('transfer.downloading')}</span>
223
+ <span>{tt('transfer.percent', { value: Math.round(transfer.percent) })}</span>
224
+ {transfer.speedBps !== undefined && transfer.phase === 'transferring' && <span>{tt('transfer.speed', { value: formatBytes(transfer.speedBps) })}</span>}
225
+ </div>
226
+ <div className={css.progressTrack}>
227
+ <div className={css.progressBar} style={{ width: Math.min(100, Math.max(0, transfer.percent)) + '%' }} />
228
+ </div>
229
+ </div>
230
+ )}
231
+ {status !== null && (
232
+ <div className={css.banner} data-kind={status.kind}>
233
+ {status.kind === 'ok' ? tt('transfer.done', { bytes: status.bytes }) : tt('transfer.failed', { error: status.error })}
234
+ </div>
235
+ )}
236
+ </div>
237
+ )
238
+ }
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Tunnel edit dialog: rename a forward, annotate it, and — for forwards this
3
+ * plugin owns — re-point it.
4
+ *
5
+ * The two kinds of tunnel get different forms on purpose. A forward that
6
+ * belongs to another process cannot be re-pointed from here (the `ssh -N -L …`
7
+ * command line is fixed for the life of that process), so offering port fields
8
+ * would be a promise the plugin cannot keep; only the name and remark are
9
+ * editable, and they persist by local port instead of by tunnel id.
10
+ */
11
+ import { useEffect, useState } from 'react'
12
+ import type { SshApi } from '../api.ts'
13
+ import type { TunnelInfo } from '../../protocol.ts'
14
+ import { errorMessage, tt } from './helpers.ts'
15
+ import css from './panel.module.css'
16
+
17
+ /** Tunnel edit dialog props. */
18
+ export interface TunnelEditDialogProps {
19
+ api: SshApi
20
+ /** The tunnel being edited. */
21
+ tunnel: TunnelInfo
22
+ onClose: () => void
23
+ /** Receives the outcome text so the tab can announce it once. */
24
+ onSaved: (notice: string) => void
25
+ }
26
+
27
+ /** Whether this forward can be re-pointed from the panel. */
28
+ export function isEditableRouting(tunnel: TunnelInfo): boolean {
29
+ return tunnel.source !== 'external'
30
+ }
31
+
32
+ /** The staged form values (all strings; parsed on save). */
33
+ interface FormState {
34
+ name: string
35
+ description: string
36
+ remoteHost: string
37
+ remotePort: string
38
+ localPort: string
39
+ }
40
+
41
+ function blankOf(tunnel: TunnelInfo): FormState {
42
+ return {
43
+ name: tunnel.name ?? '',
44
+ description: tunnel.description ?? '',
45
+ remoteHost: tunnel.remoteHost,
46
+ remotePort: String(tunnel.remotePort),
47
+ localPort: String(tunnel.localPort),
48
+ }
49
+ }
50
+
51
+ /** The tunnel edit modal. */
52
+ export function TunnelEditDialog({ api, tunnel, onClose, onSaved }: TunnelEditDialogProps) {
53
+ const [form, setForm] = useState<FormState>(() => blankOf(tunnel))
54
+ const [saving, setSaving] = useState(false)
55
+ const [error, setError] = useState<string | null>(null)
56
+ const editableRouting = isEditableRouting(tunnel)
57
+
58
+ useEffect(() => {
59
+ const onKey = (event: KeyboardEvent): void => {
60
+ if (event.key === 'Escape') onClose()
61
+ }
62
+ document.addEventListener('keydown', onKey)
63
+ return () => { document.removeEventListener('keydown', onKey) }
64
+ }, [onClose])
65
+
66
+ const set = <K extends keyof FormState>(key: K, value: FormState[K]): void => {
67
+ setForm(prev => ({ ...prev, [key]: value }))
68
+ }
69
+
70
+ const save = async (): Promise<void> => {
71
+ const remotePort = Number(form.remotePort)
72
+ const localPort = Number(form.localPort)
73
+ if (editableRouting) {
74
+ if (!Number.isInteger(remotePort) || remotePort < 1 || remotePort > 65535) {
75
+ setError(tt('form.portInvalid'))
76
+ return
77
+ }
78
+ if (!Number.isInteger(localPort) || localPort < 1 || localPort > 65535) {
79
+ setError(tt('form.portInvalid'))
80
+ return
81
+ }
82
+ if (form.remoteHost.trim() === '') {
83
+ setError(tt('tunnel.remoteHostRequired'))
84
+ return
85
+ }
86
+ }
87
+ setSaving(true)
88
+ setError(null)
89
+ try {
90
+ if (!editableRouting) {
91
+ await api.setTunnelRemark(tunnel.localPort, {
92
+ name: form.name.trim(),
93
+ description: form.description.trim(),
94
+ })
95
+ onSaved(form.name.trim() === '' && form.description.trim() === ''
96
+ ? tt('tunnel.remarkCleared')
97
+ : tt('tunnel.remarkSaved'))
98
+ return
99
+ }
100
+ const result = await api.updateTunnel(tunnel.id, {
101
+ // Always sent: an empty string is the explicit clear, so saving the
102
+ // form can both set and remove a name.
103
+ name: form.name.trim(),
104
+ description: form.description.trim(),
105
+ remoteHost: form.remoteHost.trim(),
106
+ remotePort,
107
+ localPort,
108
+ })
109
+ onSaved(result.restarted
110
+ ? tt('tunnel.rebuilt', { localPort: result.tunnel.localPort })
111
+ : tt('tunnel.updated'))
112
+ } catch (cause) {
113
+ setError(errorMessage(cause))
114
+ setSaving(false)
115
+ }
116
+ }
117
+
118
+ const titleId = 'dsh-ssh-tunnel-edit-title'
119
+
120
+ return (
121
+ <div className={css.modalBackdrop} onClick={onClose}>
122
+ <div
123
+ className={css.modal}
124
+ role="dialog"
125
+ aria-modal="true"
126
+ aria-labelledby={titleId}
127
+ onClick={event => { event.stopPropagation() }}
128
+ >
129
+ <h3 className={css.modalTitle} id={titleId}>{tt('tunnel.editTitle', { alias: tunnel.alias })}</h3>
130
+ <div className={css.formRow}>
131
+ <label className={css.field}>
132
+ <span className={css.fieldLabel}>{tt('tunnel.name')}</span>
133
+ <input className={css.input} value={form.name} onChange={event => { set('name', event.target.value) }} />
134
+ <span className={css.hint}>{tt('tunnel.nameHint')}</span>
135
+ </label>
136
+ <label className={css.field}>
137
+ <span className={css.fieldLabel}>{tt('tunnel.description')}</span>
138
+ <input className={css.input} value={form.description} onChange={event => { set('description', event.target.value) }} />
139
+ <span className={css.hint}>{tt('tunnel.descriptionHint')}</span>
140
+ </label>
141
+ </div>
142
+ {editableRouting
143
+ ? (
144
+ <>
145
+ <div className={css.formRow}>
146
+ <label className={css.field}>
147
+ <span className={css.fieldLabel}>{tt('tunnel.remoteHost')}</span>
148
+ <input className={css.input} value={form.remoteHost} onChange={event => { set('remoteHost', event.target.value) }} />
149
+ </label>
150
+ <label className={css.field}>
151
+ <span className={css.fieldLabel}>{tt('tunnel.remotePort')}</span>
152
+ <input className={css.input} type="number" min={1} max={65535} value={form.remotePort} onChange={event => { set('remotePort', event.target.value) }} />
153
+ </label>
154
+ <label className={css.field}>
155
+ <span className={css.fieldLabel}>{tt('tunnel.localPort')}</span>
156
+ <input className={css.input} type="number" min={1} max={65535} value={form.localPort} onChange={event => { set('localPort', event.target.value) }} />
157
+ </label>
158
+ </div>
159
+ {/* Changing any of the three ports cannot be applied in place:
160
+ the listener is bound to the old target, so the forward is
161
+ rebuilt. Saying so before the click beats explaining after. */}
162
+ <p className={css.hint}>{tt('tunnel.editRestartHint')}</p>
163
+ </>
164
+ )
165
+ : <p className={css.hint}>{tt('tunnel.editExternalHint')}</p>}
166
+ {error !== null && <p className={css.formError} role="alert">{tt('common.error', { error })}</p>}
167
+ <div className={css.modalFooter}>
168
+ <button type="button" className={css.ghostButton} disabled={saving} onClick={onClose}>{tt('form.cancel')}</button>
169
+ <button type="button" className={css.primaryButton} disabled={saving} onClick={() => { void save() }}>{tt('form.save')}</button>
170
+ </div>
171
+ </div>
172
+ </div>
173
+ )
174
+ }