dsh-remote-vs 0.28.0 → 0.29.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.
- package/README.en.md +50 -5
- package/README.md +42 -5
- package/lib/client.js +217 -112
- package/lib/index.js +1468 -51
- package/lib/types/client/HostsView.d.ts +139 -2
- package/lib/types/client/api.d.ts +25 -1
- package/lib/types/client/connection.d.ts +28 -1
- package/lib/types/forward.d.ts +11 -1
- package/lib/types/pool.d.ts +95 -1
- package/lib/types/protocol.d.ts +122 -0
- package/lib/types/proxy.d.ts +136 -0
- package/lib/types/store.d.ts +81 -1
- package/lib/types/tools.d.ts +3 -0
- package/package.json +1 -1
- package/src/client/ConnectionStatus.tsx +19 -5
- package/src/client/HostsView.tsx +552 -11
- package/src/client/PortsView.tsx +16 -0
- package/src/client/SettingsHosts.tsx +132 -6
- package/src/client/api.ts +30 -0
- package/src/client/connection.ts +76 -2
- package/src/client/i18n.ts +102 -0
- package/src/client/vsc/vsc.css +105 -0
- package/src/forward.ts +38 -2
- package/src/importers.ts +125 -13
- package/src/keygen.ts +8 -1
- package/src/pool.ts +422 -27
- package/src/protocol.ts +128 -0
- package/src/proxy.ts +673 -0
- package/src/routes.ts +73 -5
- package/src/store.ts +335 -0
- package/src/tools.ts +47 -2
package/src/client/HostsView.tsx
CHANGED
|
@@ -1,18 +1,478 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hosts view: list + add/edit form + test + key bootstrap + push + import.
|
|
3
|
+
*
|
|
4
|
+
* The form also owns the host's 「网络出口」 (egress: proxy / jump host) block.
|
|
5
|
+
* It is COLLAPSED by default, because most hosts go out directly and a wall of
|
|
6
|
+
* empty proxy fields reads as "you must fill this in"; the collapsed row still
|
|
7
|
+
* carries a read-only chip with the resulting route, so the answer to "how does
|
|
8
|
+
* this host get out" never needs a click. The profile-wide default that
|
|
9
|
+
* `跟随默认` resolves to lives in Settings (`SettingsHosts.tsx`).
|
|
3
10
|
*/
|
|
4
|
-
import { useState, type ReactNode } from 'react'
|
|
5
|
-
import type {
|
|
11
|
+
import { useId, useState, type ReactNode } from 'react'
|
|
12
|
+
import type {
|
|
13
|
+
RemoteDeployState,
|
|
14
|
+
RemoteHostProxySetting,
|
|
15
|
+
RemoteHostProxyView,
|
|
16
|
+
RemoteHostSummary,
|
|
17
|
+
RemoteProxyMode,
|
|
18
|
+
RemoteProxySetting,
|
|
19
|
+
RemoteProxySettingsView,
|
|
20
|
+
} from '../protocol.ts'
|
|
6
21
|
import { RemoteApiError, api, type HostForm } from './api.ts'
|
|
7
22
|
import { DoctorPanel } from './DoctorPanel.tsx'
|
|
8
|
-
import { Btn, Field, Notice, Row, hairline, inputStyle } from './ui.tsx'
|
|
23
|
+
import { Btn, Field, Notice, Row, hairline, inputStyle, optionStyle, selectStyle } from './ui.tsx'
|
|
9
24
|
import { confirmDialog } from './vsc/kit.tsx'
|
|
10
25
|
|
|
26
|
+
/** The translator shape this plugin's views pass around. */
|
|
27
|
+
type TFn = (key: string) => string
|
|
28
|
+
|
|
11
29
|
function err(e: unknown): string {
|
|
12
30
|
return e instanceof RemoteApiError ? e.message : String(e)
|
|
13
31
|
}
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
/** Short word for a proxy flavour, as the chips print it. */
|
|
34
|
+
function shortKind(t: TFn, kind: 'http' | 'socks5'): string {
|
|
35
|
+
return kind === 'http' ? t('proxy.shortHttp') : t('proxy.shortSocks5')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Everything the egress controls edit, as form strings. */
|
|
39
|
+
export interface ProxyFormState {
|
|
40
|
+
mode: RemoteProxyMode
|
|
41
|
+
kind: 'http' | 'socks5'
|
|
42
|
+
host: string
|
|
43
|
+
port: string
|
|
44
|
+
username: string
|
|
45
|
+
password: string
|
|
46
|
+
viaAlias: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A blank draft: `跟随默认`, HTTP, no address (i.e. a fresh host). */
|
|
50
|
+
export function emptyProxyState(): ProxyFormState {
|
|
51
|
+
return { mode: 'inherit', kind: 'http', host: '', port: '', username: '', password: '', viaAlias: '' }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Seed the controls from a stored (secret-free) host view.
|
|
56
|
+
*
|
|
57
|
+
* The password box stays EMPTY on purpose: the Host never echoes it back, and
|
|
58
|
+
* `proxySettingOf` expresses "keep the stored one" by omitting the field, so an
|
|
59
|
+
* untouched box cannot overwrite a working credential with an empty string.
|
|
60
|
+
*/
|
|
61
|
+
export function proxyStateOf(view: RemoteHostProxyView | undefined): ProxyFormState {
|
|
62
|
+
const state = emptyProxyState()
|
|
63
|
+
if (view === undefined) return state
|
|
64
|
+
state.mode = view.mode
|
|
65
|
+
state.viaAlias = view.jumpVia ?? ''
|
|
66
|
+
if (view.target !== undefined) {
|
|
67
|
+
state.kind = view.target.kind
|
|
68
|
+
state.host = view.target.host
|
|
69
|
+
state.port = String(view.target.port)
|
|
70
|
+
state.username = view.target.username ?? ''
|
|
71
|
+
}
|
|
72
|
+
return state
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The profile default as a draft (it only knows `direct` / `proxy`). */
|
|
76
|
+
export function defaultProxyStateOf(view: RemoteProxySettingsView | undefined): ProxyFormState {
|
|
77
|
+
const state = emptyProxyState()
|
|
78
|
+
state.mode = view === undefined ? 'direct' : view.defaultMode
|
|
79
|
+
if (view?.target !== undefined) {
|
|
80
|
+
state.kind = view.target.kind
|
|
81
|
+
state.host = view.target.host
|
|
82
|
+
state.port = String(view.target.port)
|
|
83
|
+
state.username = view.target.username ?? ''
|
|
84
|
+
}
|
|
85
|
+
return state
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The endpoint half of a proxy decision.
|
|
90
|
+
*
|
|
91
|
+
* An empty password is OMITTED (not sent as `''`): that is the contract for
|
|
92
|
+
* "keep the stored secret", and it is the only reason the browser never has to
|
|
93
|
+
* see the password at all.
|
|
94
|
+
*/
|
|
95
|
+
export function proxyTargetOf(state: ProxyFormState): RemoteProxySetting {
|
|
96
|
+
const parsed = Number.parseInt(state.port, 10)
|
|
97
|
+
const username = state.username.trim()
|
|
98
|
+
return {
|
|
99
|
+
kind: state.kind,
|
|
100
|
+
host: state.host.trim(),
|
|
101
|
+
port: Number.isInteger(parsed) ? parsed : 0,
|
|
102
|
+
...(username === '' ? {} : { username }),
|
|
103
|
+
...(state.password === '' ? {} : { password: state.password }),
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The `proxy` field for one save, or `undefined` when it must be left out.
|
|
109
|
+
*
|
|
110
|
+
* `undefined` is the BACKWARD-COMPATIBLE answer: an old Host ignores the field,
|
|
111
|
+
* and on create an absent value simply inherits the profile default. An UPDATE
|
|
112
|
+
* that switches back to `跟随默认` is the one case an explicit
|
|
113
|
+
* `{ mode: 'inherit' }` has to be sent, or the stored proxy would never clear.
|
|
114
|
+
*/
|
|
115
|
+
export function proxySettingOf(state: ProxyFormState): RemoteHostProxySetting | undefined {
|
|
116
|
+
if (state.mode === 'inherit') return undefined
|
|
117
|
+
if (state.mode === 'direct') return { mode: 'direct' }
|
|
118
|
+
if (state.mode === 'jump') return { mode: 'jump', jump: { viaAlias: state.viaAlias.trim() } }
|
|
119
|
+
return { mode: 'proxy', proxy: proxyTargetOf(state) }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* What stops a save: an unusable proxy endpoint, or no jump host picked.
|
|
124
|
+
*
|
|
125
|
+
* `jumpChoices` is the list of aliases the save can legally name (every stored
|
|
126
|
+
* host except the one being edited). A stored jump host that has since been
|
|
127
|
+
* deleted is NOT saveable — the Host refuses a `viaAlias` it does not know — so
|
|
128
|
+
* the form has to say that in the user's language instead of forwarding a raw
|
|
129
|
+
* `unknown host alias` rejection for a field nobody touched.
|
|
130
|
+
*/
|
|
131
|
+
export function proxyFormProblem(
|
|
132
|
+
state: ProxyFormState,
|
|
133
|
+
jumpChoices?: string[],
|
|
134
|
+
): 'target' | 'jump' | 'jumpGone' | undefined {
|
|
135
|
+
if (state.mode === 'proxy') {
|
|
136
|
+
const parsed = Number.parseInt(state.port, 10)
|
|
137
|
+
if (state.host.trim() === '' || !Number.isInteger(parsed) || parsed < 1 || parsed > 65535) return 'target'
|
|
138
|
+
}
|
|
139
|
+
if (state.mode === 'jump') {
|
|
140
|
+
const alias = state.viaAlias.trim()
|
|
141
|
+
if (alias === '') return 'jump'
|
|
142
|
+
if (jumpChoices !== undefined && !jumpChoices.includes(alias)) return 'jumpGone'
|
|
143
|
+
}
|
|
144
|
+
return undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* One line saying where traffic goes — the collapsed chip's text.
|
|
149
|
+
*
|
|
150
|
+
* `跟随默认` is resolved against the profile default when it is known: the whole
|
|
151
|
+
* point of showing the chip while collapsed is that "follow the default" alone
|
|
152
|
+
* does not tell the user whether that means direct or a proxy. An unknown
|
|
153
|
+
* default (a Host without the route, or a failed read) degrades to the bare
|
|
154
|
+
* phrase rather than guessing "direct".
|
|
155
|
+
*/
|
|
156
|
+
export function proxySummary(t: TFn, state: ProxyFormState, fallback: RemoteProxySettingsView | undefined): string {
|
|
157
|
+
if (state.mode === 'direct') return t('proxy.summaryDirect')
|
|
158
|
+
if (state.mode === 'proxy') {
|
|
159
|
+
const host = state.host.trim()
|
|
160
|
+
const port = state.port.trim()
|
|
161
|
+
if (host === '' || port === '') return t('proxy.chipProxy')
|
|
162
|
+
return t('proxy.summaryProxy')
|
|
163
|
+
.replace('{kind}', shortKind(t, state.kind))
|
|
164
|
+
.replace('{host}', host)
|
|
165
|
+
.replace('{port}', port)
|
|
166
|
+
}
|
|
167
|
+
if (state.mode === 'jump') {
|
|
168
|
+
const alias = state.viaAlias.trim()
|
|
169
|
+
return alias === '' ? t('proxy.mode.jump') : t('proxy.summaryJump').replace('{alias}', alias)
|
|
170
|
+
}
|
|
171
|
+
const target = fallback?.target
|
|
172
|
+
if (fallback === undefined || (fallback.defaultMode === 'proxy' && target === undefined)) {
|
|
173
|
+
return t('proxy.chipInherit')
|
|
174
|
+
}
|
|
175
|
+
if (fallback.defaultMode === 'direct') return t('proxy.summaryInheritDirect')
|
|
176
|
+
return t('proxy.summaryInheritProxy')
|
|
177
|
+
.replace('{kind}', shortKind(t, target?.kind ?? 'http'))
|
|
178
|
+
.replace('{host}', target?.host ?? '')
|
|
179
|
+
.replace('{port}', String(target?.port ?? ''))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** One rendered chip: its word, its hover text, and whether it is a problem. */
|
|
183
|
+
export interface ProxyChipModel {
|
|
184
|
+
mode: RemoteProxyMode
|
|
185
|
+
label: string
|
|
186
|
+
title: string
|
|
187
|
+
problem: boolean
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The host ROW's chip: which way this host leaves the machine.
|
|
192
|
+
*
|
|
193
|
+
* Deliberately shorter than the form's summary (`代理`, not `经 HTTP 代理 h:p`) —
|
|
194
|
+
* a list row has one line of room and the full route is the `title`. A refused
|
|
195
|
+
* setting keeps its chip text and switches to the error colour, because the row
|
|
196
|
+
* still has to say what was configured; `problem` explains why it cannot work.
|
|
197
|
+
*
|
|
198
|
+
* `fallback` is the profile-wide default, so a `跟随默认` row resolves to what it
|
|
199
|
+
* actually does (the form's chip already does) — without it the row would say
|
|
200
|
+
* "follow default" while the same host's form says "follow default (via …)". An
|
|
201
|
+
* unknown default degrades to the bare phrase rather than guessing "direct".
|
|
202
|
+
*/
|
|
203
|
+
export function proxyChipOf(t: TFn, view: RemoteHostProxyView, fallback?: RemoteProxySettingsView): ProxyChipModel {
|
|
204
|
+
const state = proxyStateOf(view)
|
|
205
|
+
const summary = proxySummary(t, state, fallback)
|
|
206
|
+
const label = view.mode === 'jump'
|
|
207
|
+
? (view.jumpVia === undefined ? t('proxy.mode.jump') : t('proxy.chipJump').replace('{alias}', view.jumpVia))
|
|
208
|
+
: summary
|
|
209
|
+
return {
|
|
210
|
+
mode: view.mode,
|
|
211
|
+
label,
|
|
212
|
+
title: view.problem ?? t('proxy.chipTitle').replace('{summary}', summary),
|
|
213
|
+
problem: view.problem !== undefined,
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Read-only route chip (secondary outline, never a status colour). */
|
|
218
|
+
export function ProxyChip(props: { chip: ProxyChipModel }): ReactNode {
|
|
219
|
+
const chip = props.chip
|
|
220
|
+
return (
|
|
221
|
+
<span
|
|
222
|
+
className={chip.problem ? 'rvs-proxy-chip is-error' : 'rvs-proxy-chip'}
|
|
223
|
+
data-proxy-mode={chip.mode}
|
|
224
|
+
{...(chip.problem ? { 'data-proxy-problem': '1' } : {})}
|
|
225
|
+
title={chip.title}
|
|
226
|
+
>
|
|
227
|
+
{chip.label}
|
|
228
|
+
</span>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Collapsible section header: a real `<button>` with `aria-expanded`.
|
|
234
|
+
*
|
|
235
|
+
* A `<details>` element was refused on purpose: its summary marker cannot be
|
|
236
|
+
* restyled without vendor pseudo-elements and it gives no place for the chip.
|
|
237
|
+
* A native button keeps Enter/Space, focus and the announced state for free.
|
|
238
|
+
*/
|
|
239
|
+
export function ProxySectionHeader(props: {
|
|
240
|
+
open: boolean
|
|
241
|
+
label: string
|
|
242
|
+
expandLabel: string
|
|
243
|
+
collapseLabel: string
|
|
244
|
+
chip: ProxyChipModel
|
|
245
|
+
controls: string
|
|
246
|
+
onToggle: () => void
|
|
247
|
+
}): ReactNode {
|
|
248
|
+
return (
|
|
249
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: props.open ? 8 : 4 }}>
|
|
250
|
+
<button
|
|
251
|
+
type="button"
|
|
252
|
+
className="rvs-proxy-toggle"
|
|
253
|
+
aria-expanded={props.open}
|
|
254
|
+
aria-controls={props.controls}
|
|
255
|
+
title={props.open ? props.collapseLabel : props.expandLabel}
|
|
256
|
+
onClick={props.onToggle}
|
|
257
|
+
>
|
|
258
|
+
<span className="rvs-proxy-caret" aria-hidden="true">▸</span>
|
|
259
|
+
<span style={{ fontSize: 12, opacity: 0.75 }}>{props.label}</span>
|
|
260
|
+
</button>
|
|
261
|
+
<span style={{ flex: 1 }} />
|
|
262
|
+
<ProxyChip chip={props.chip} />
|
|
263
|
+
</div>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The endpoint controls, shared by the per-host form and the profile default.
|
|
269
|
+
*
|
|
270
|
+
* Password semantics are identical in both places: `storedPassword` only
|
|
271
|
+
* switches the placeholder, and an empty box is omitted from the payload.
|
|
272
|
+
*/
|
|
273
|
+
export function ProxyFields(props: {
|
|
274
|
+
t: TFn
|
|
275
|
+
state: ProxyFormState
|
|
276
|
+
onChange: (next: ProxyFormState) => void
|
|
277
|
+
storedPassword: boolean
|
|
278
|
+
disabled?: boolean
|
|
279
|
+
}): ReactNode {
|
|
280
|
+
const t = props.t
|
|
281
|
+
const state = props.state
|
|
282
|
+
const set = (patch: Partial<ProxyFormState>): void => props.onChange({ ...state, ...patch })
|
|
283
|
+
const disabled = props.disabled === true
|
|
284
|
+
return (
|
|
285
|
+
<>
|
|
286
|
+
<div style={{ display: 'flex', gap: 8 }}>
|
|
287
|
+
<div style={{ flex: 1.1 }}>
|
|
288
|
+
<Field label={t('proxy.kind')}>
|
|
289
|
+
<select
|
|
290
|
+
value={state.kind}
|
|
291
|
+
disabled={disabled}
|
|
292
|
+
onChange={(e) => set({ kind: e.target.value === 'socks5' ? 'socks5' : 'http' })}
|
|
293
|
+
style={selectStyle}
|
|
294
|
+
>
|
|
295
|
+
<option value="http" style={optionStyle}>{t('proxy.typeHttp')}</option>
|
|
296
|
+
<option value="socks5" style={optionStyle}>{t('proxy.typeSocks5')}</option>
|
|
297
|
+
</select>
|
|
298
|
+
</Field>
|
|
299
|
+
</div>
|
|
300
|
+
<div style={{ flex: 1.9 }}>
|
|
301
|
+
<Field label={t('proxy.host')}>
|
|
302
|
+
<input
|
|
303
|
+
value={state.host}
|
|
304
|
+
disabled={disabled}
|
|
305
|
+
onChange={(e) => set({ host: e.target.value })}
|
|
306
|
+
placeholder="192.0.2.10"
|
|
307
|
+
style={inputStyle}
|
|
308
|
+
/>
|
|
309
|
+
</Field>
|
|
310
|
+
</div>
|
|
311
|
+
<div style={{ flex: 0.8 }}>
|
|
312
|
+
<Field label={t('proxy.port')}>
|
|
313
|
+
<input
|
|
314
|
+
value={state.port}
|
|
315
|
+
disabled={disabled}
|
|
316
|
+
inputMode="numeric"
|
|
317
|
+
onChange={(e) => set({ port: e.target.value })}
|
|
318
|
+
placeholder="3128"
|
|
319
|
+
style={inputStyle}
|
|
320
|
+
/>
|
|
321
|
+
</Field>
|
|
322
|
+
</div>
|
|
323
|
+
</div>
|
|
324
|
+
<div style={{ display: 'flex', gap: 8 }}>
|
|
325
|
+
<div style={{ flex: 1 }}>
|
|
326
|
+
<Field label={t('proxy.username')}>
|
|
327
|
+
<input
|
|
328
|
+
value={state.username}
|
|
329
|
+
disabled={disabled}
|
|
330
|
+
autoComplete="off"
|
|
331
|
+
onChange={(e) => set({ username: e.target.value })}
|
|
332
|
+
style={inputStyle}
|
|
333
|
+
/>
|
|
334
|
+
</Field>
|
|
335
|
+
</div>
|
|
336
|
+
<div style={{ flex: 1 }}>
|
|
337
|
+
<Field label={t('proxy.password')}>
|
|
338
|
+
<input
|
|
339
|
+
type="password"
|
|
340
|
+
value={state.password}
|
|
341
|
+
disabled={disabled}
|
|
342
|
+
autoComplete="new-password"
|
|
343
|
+
onChange={(e) => set({ password: e.target.value })}
|
|
344
|
+
placeholder={props.storedPassword ? t('proxy.passwordKeep') : ''}
|
|
345
|
+
style={inputStyle}
|
|
346
|
+
/>
|
|
347
|
+
</Field>
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
</>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The egress block of the host form (collapsed by default). */
|
|
355
|
+
function HostProxySection(props: {
|
|
356
|
+
t: TFn
|
|
357
|
+
state: ProxyFormState
|
|
358
|
+
onChange: (next: ProxyFormState) => void
|
|
359
|
+
open: boolean
|
|
360
|
+
onToggle: () => void
|
|
361
|
+
proxyDefault: RemoteProxySettingsView | undefined
|
|
362
|
+
hosts: RemoteHostSummary[]
|
|
363
|
+
self: string | undefined
|
|
364
|
+
storedPassword: boolean
|
|
365
|
+
busy: boolean
|
|
366
|
+
error: string | undefined
|
|
367
|
+
}): ReactNode {
|
|
368
|
+
const t = props.t
|
|
369
|
+
const state = props.state
|
|
370
|
+
const set = (patch: Partial<ProxyFormState>): void => props.onChange({ ...state, ...patch })
|
|
371
|
+
const panelId = useId()
|
|
372
|
+
const groupName = useId()
|
|
373
|
+
const summary = proxySummary(t, state, props.proxyDefault)
|
|
374
|
+
const chip: ProxyChipModel = {
|
|
375
|
+
mode: state.mode,
|
|
376
|
+
label: summary,
|
|
377
|
+
title: t('proxy.chipTitle').replace('{summary}', summary),
|
|
378
|
+
problem: false,
|
|
379
|
+
}
|
|
380
|
+
// A jump host must be another STORED host: the tunnel rides its pooled SSH
|
|
381
|
+
// connection, and the alias being edited is not a candidate for itself.
|
|
382
|
+
const candidates = props.hosts.filter(host => host.alias !== props.self)
|
|
383
|
+
const missing = state.viaAlias !== '' && !candidates.some(host => host.alias === state.viaAlias)
|
|
384
|
+
return (
|
|
385
|
+
<div style={{ ...hairline, marginTop: 2, paddingTop: 8, marginBottom: 8 }}>
|
|
386
|
+
<ProxySectionHeader
|
|
387
|
+
open={props.open}
|
|
388
|
+
label={t('proxy.title')}
|
|
389
|
+
expandLabel={t('proxy.expand')}
|
|
390
|
+
collapseLabel={t('proxy.collapse')}
|
|
391
|
+
chip={chip}
|
|
392
|
+
controls={panelId}
|
|
393
|
+
onToggle={props.onToggle}
|
|
394
|
+
/>
|
|
395
|
+
<div id={panelId} hidden={!props.open} className="rvs-proxy-panel">
|
|
396
|
+
<Row>
|
|
397
|
+
<span style={{ opacity: 0.75, marginRight: 4 }}>{t('proxy.mode')}</span>
|
|
398
|
+
<label style={{ marginRight: 10 }}>
|
|
399
|
+
<input
|
|
400
|
+
type="radio"
|
|
401
|
+
name={groupName}
|
|
402
|
+
checked={state.mode === 'inherit'}
|
|
403
|
+
disabled={props.busy}
|
|
404
|
+
onChange={() => set({ mode: 'inherit' })}
|
|
405
|
+
/>{' '}{t('proxy.mode.inherit')}
|
|
406
|
+
</label>
|
|
407
|
+
<label style={{ marginRight: 10 }}>
|
|
408
|
+
<input
|
|
409
|
+
type="radio"
|
|
410
|
+
name={groupName}
|
|
411
|
+
checked={state.mode === 'direct'}
|
|
412
|
+
disabled={props.busy}
|
|
413
|
+
onChange={() => set({ mode: 'direct' })}
|
|
414
|
+
/>{' '}{t('proxy.mode.direct')}
|
|
415
|
+
</label>
|
|
416
|
+
<label style={{ marginRight: 10 }}>
|
|
417
|
+
<input
|
|
418
|
+
type="radio"
|
|
419
|
+
name={groupName}
|
|
420
|
+
checked={state.mode === 'proxy'}
|
|
421
|
+
disabled={props.busy}
|
|
422
|
+
onChange={() => set({ mode: 'proxy' })}
|
|
423
|
+
/>{' '}{t('proxy.mode.proxy')}
|
|
424
|
+
</label>
|
|
425
|
+
<label>
|
|
426
|
+
<input
|
|
427
|
+
type="radio"
|
|
428
|
+
name={groupName}
|
|
429
|
+
checked={state.mode === 'jump'}
|
|
430
|
+
disabled={props.busy}
|
|
431
|
+
onChange={() => set({ mode: 'jump' })}
|
|
432
|
+
/>{' '}{t('proxy.mode.jump')}
|
|
433
|
+
</label>
|
|
434
|
+
</Row>
|
|
435
|
+
{state.mode === 'proxy' && (
|
|
436
|
+
<ProxyFields
|
|
437
|
+
t={t}
|
|
438
|
+
state={state}
|
|
439
|
+
onChange={props.onChange}
|
|
440
|
+
storedPassword={props.storedPassword}
|
|
441
|
+
disabled={props.busy}
|
|
442
|
+
/>
|
|
443
|
+
)}
|
|
444
|
+
{state.mode === 'jump' && (
|
|
445
|
+
<>
|
|
446
|
+
<Field label={t('proxy.jumpVia')}>
|
|
447
|
+
<select
|
|
448
|
+
value={state.viaAlias}
|
|
449
|
+
disabled={props.busy}
|
|
450
|
+
onChange={(e) => set({ viaAlias: e.target.value })}
|
|
451
|
+
style={selectStyle}
|
|
452
|
+
>
|
|
453
|
+
{candidates.length === 0 && <option value="" style={optionStyle}>{t('proxy.jumpNone')}</option>}
|
|
454
|
+
{missing && (
|
|
455
|
+
<option value={state.viaAlias} style={optionStyle}>
|
|
456
|
+
{t('proxy.jumpMissing').replace('{alias}', state.viaAlias)}
|
|
457
|
+
</option>
|
|
458
|
+
)}
|
|
459
|
+
{candidates.map(host => (
|
|
460
|
+
<option key={host.alias} value={host.alias} style={optionStyle}>
|
|
461
|
+
{host.alias === host.host ? host.alias : `${host.alias} (${host.host})`}
|
|
462
|
+
</option>
|
|
463
|
+
))}
|
|
464
|
+
</select>
|
|
465
|
+
</Field>
|
|
466
|
+
<div style={{ fontSize: 11, opacity: 0.6, marginBottom: 8 }}>{t('proxy.jumpHint')}</div>
|
|
467
|
+
</>
|
|
468
|
+
)}
|
|
469
|
+
{props.error !== undefined && <Notice kind="error">{props.error}</Notice>}
|
|
470
|
+
</div>
|
|
471
|
+
</div>
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function DeployBadge(props: { deploy: RemoteDeployState | undefined; t: TFn }): ReactNode {
|
|
16
476
|
const d = props.deploy
|
|
17
477
|
if (d === undefined || d.status === 'not-deployed') return <span style={{ opacity: 0.6 }}>{props.t('deploy.notDeployed')}</span>
|
|
18
478
|
const color = d.status === 'failed' ? '#e06060' : d.status === 'ok' ? '#7ee2a8' : '#e8b84b'
|
|
@@ -28,10 +488,14 @@ function DeployBadge(props: { deploy: RemoteDeployState | undefined; t: (k: stri
|
|
|
28
488
|
)
|
|
29
489
|
}
|
|
30
490
|
|
|
31
|
-
function HostFormView(props: {
|
|
32
|
-
t:
|
|
491
|
+
export function HostFormView(props: {
|
|
492
|
+
t: TFn
|
|
33
493
|
initial?: RemoteHostSummary
|
|
34
494
|
busy: boolean
|
|
495
|
+
/** Every stored host: the jump-host list (minus the one being edited). */
|
|
496
|
+
hosts: RemoteHostSummary[]
|
|
497
|
+
/** The profile-wide default, so `跟随默认` can be spelled out while collapsed. */
|
|
498
|
+
proxyDefault?: RemoteProxySettingsView
|
|
35
499
|
onSave: (form: HostForm) => void
|
|
36
500
|
onCancel: () => void
|
|
37
501
|
}): ReactNode {
|
|
@@ -45,9 +509,46 @@ function HostFormView(props: {
|
|
|
45
509
|
const [passphrase, setPassphrase] = useState('')
|
|
46
510
|
const [password, setPassword] = useState('')
|
|
47
511
|
const [description, setDescription] = useState(props.initial?.description ?? '')
|
|
512
|
+
const [proxy, setProxy] = useState<ProxyFormState>(() => proxyStateOf(props.initial?.proxy))
|
|
513
|
+
/** Collapsed by default: most hosts go out directly, and the chip says so. */
|
|
514
|
+
const [proxyOpen, setProxyOpen] = useState(false)
|
|
515
|
+
const [proxyError, setProxyError] = useState<string | undefined>(undefined)
|
|
516
|
+
/**
|
|
517
|
+
* "Leave it empty to keep it" is only true while the endpoint is UNCHANGED.
|
|
518
|
+
*
|
|
519
|
+
* The Host keeps a stored proxy password only when kind/host/port/username all
|
|
520
|
+
* still match (a new endpoint must not inherit the old secret), so a bare
|
|
521
|
+
* `hasPassword` would promise something an edited port silently breaks. The
|
|
522
|
+
* placeholder is therefore decided against the draft, not the stored view.
|
|
523
|
+
*/
|
|
524
|
+
const storedTarget = props.initial?.proxy?.target
|
|
525
|
+
const storedPassword = storedTarget?.hasPassword === true
|
|
526
|
+
&& proxy.mode === 'proxy'
|
|
527
|
+
&& proxy.kind === storedTarget.kind
|
|
528
|
+
&& proxy.host.trim() === storedTarget.host
|
|
529
|
+
&& proxy.port.trim() === String(storedTarget.port)
|
|
530
|
+
&& proxy.username.trim() === (storedTarget.username ?? '')
|
|
531
|
+
/** Aliases a jump setting may legally name (the Host refuses anything else). */
|
|
532
|
+
const jumpChoices = props.hosts.filter(entry => entry.alias !== props.initial?.alias).map(entry => entry.alias)
|
|
48
533
|
|
|
49
534
|
const save = (): void => {
|
|
535
|
+
const problem = proxyFormProblem(proxy, jumpChoices)
|
|
536
|
+
if (problem !== undefined) {
|
|
537
|
+
// Show the message next to the fields it is about, and open the section so
|
|
538
|
+
// it cannot be hidden behind a collapsed header.
|
|
539
|
+
setProxyError(
|
|
540
|
+
problem === 'target'
|
|
541
|
+
? t('proxy.invalidTarget')
|
|
542
|
+
: problem === 'jump'
|
|
543
|
+
? t('proxy.invalidJump')
|
|
544
|
+
: t('proxy.jumpGone').replace('{alias}', proxy.viaAlias.trim()),
|
|
545
|
+
)
|
|
546
|
+
setProxyOpen(true)
|
|
547
|
+
return
|
|
548
|
+
}
|
|
549
|
+
setProxyError(undefined)
|
|
50
550
|
const portNum = Number.parseInt(port, 10)
|
|
551
|
+
const setting = proxySettingOf(proxy)
|
|
51
552
|
const form: HostForm = {
|
|
52
553
|
alias: alias.trim(),
|
|
53
554
|
host: host.trim(),
|
|
@@ -61,6 +562,7 @@ function HostFormView(props: {
|
|
|
61
562
|
}
|
|
62
563
|
: { kind: 'password', password },
|
|
63
564
|
...(description.trim() !== '' ? { description: description.trim() } : {}),
|
|
565
|
+
...(setting === undefined ? {} : { proxy: setting }),
|
|
64
566
|
}
|
|
65
567
|
props.onSave(form)
|
|
66
568
|
}
|
|
@@ -136,6 +638,19 @@ function HostFormView(props: {
|
|
|
136
638
|
/>
|
|
137
639
|
</Field>
|
|
138
640
|
)}
|
|
641
|
+
<HostProxySection
|
|
642
|
+
t={t}
|
|
643
|
+
state={proxy}
|
|
644
|
+
onChange={(next) => { setProxy(next); setProxyError(undefined) }}
|
|
645
|
+
open={proxyOpen}
|
|
646
|
+
onToggle={() => setProxyOpen(!proxyOpen)}
|
|
647
|
+
proxyDefault={props.proxyDefault}
|
|
648
|
+
hosts={props.hosts}
|
|
649
|
+
self={props.initial?.alias}
|
|
650
|
+
storedPassword={storedPassword}
|
|
651
|
+
busy={props.busy}
|
|
652
|
+
error={proxyError}
|
|
653
|
+
/>
|
|
139
654
|
<Field label={t('form.description')}>
|
|
140
655
|
<input value={description} disabled={props.busy} onChange={(e) => setDescription(e.target.value)} style={inputStyle} />
|
|
141
656
|
</Field>
|
|
@@ -148,8 +663,10 @@ function HostFormView(props: {
|
|
|
148
663
|
}
|
|
149
664
|
|
|
150
665
|
export function HostsView(props: {
|
|
151
|
-
t:
|
|
666
|
+
t: TFn
|
|
152
667
|
hosts: RemoteHostSummary[]
|
|
668
|
+
/** Profile-wide egress default, so `跟随默认` chips can be resolved. */
|
|
669
|
+
proxyDefault?: RemoteProxySettingsView
|
|
153
670
|
onChanged: () => void
|
|
154
671
|
}): ReactNode {
|
|
155
672
|
const t = props.t
|
|
@@ -238,14 +755,22 @@ export function HostsView(props: {
|
|
|
238
755
|
|
|
239
756
|
const saveForm = (form: HostForm): void => {
|
|
240
757
|
setBusy('save')
|
|
241
|
-
const
|
|
758
|
+
const editingAlias = editing === 'new' ? undefined : editing as string
|
|
759
|
+
const stored = editingAlias === undefined ? undefined : props.hosts.find(h => h.alias === editingAlias)?.proxy
|
|
760
|
+
// An omitted `proxy` means "keep what is stored", so switching back to
|
|
761
|
+
// 跟随默认 has to SAY it — but only when there was something to clear: a host
|
|
762
|
+
// that never had a proxy must not start carrying an explicit `inherit`.
|
|
763
|
+
const proxyPatch = form.proxy
|
|
764
|
+
?? (stored === undefined || stored.mode === 'inherit' ? undefined : { mode: 'inherit' as const })
|
|
765
|
+
const task = editingAlias === undefined
|
|
242
766
|
? api.createHost(form)
|
|
243
|
-
: api.updateHost(
|
|
767
|
+
: api.updateHost(editingAlias, {
|
|
244
768
|
host: form.host,
|
|
245
769
|
port: form.port,
|
|
246
770
|
user: form.user,
|
|
247
771
|
auth: form.auth,
|
|
248
772
|
description: form.description,
|
|
773
|
+
...(proxyPatch === undefined ? {} : { proxy: proxyPatch }),
|
|
249
774
|
})
|
|
250
775
|
task.then(
|
|
251
776
|
(h) => {
|
|
@@ -285,6 +810,7 @@ export function HostsView(props: {
|
|
|
285
810
|
<Row>
|
|
286
811
|
<code style={{ fontWeight: 700 }}>{h.alias}</code>
|
|
287
812
|
<code style={{ opacity: 0.75 }}>{h.user}@{h.host}:{h.port}</code>
|
|
813
|
+
<ProxyChip chip={proxyChipOf(t, h.proxy, props.proxyDefault)} />
|
|
288
814
|
<span style={{ fontSize: 12, opacity: 0.75 }}>
|
|
289
815
|
{h.auth === 'key' ? (h.keyReady ? '🔑✓' : '🔑?') : '🔒'}
|
|
290
816
|
{h.managedKey ? ' (managed)' : ''}
|
|
@@ -315,7 +841,15 @@ export function HostsView(props: {
|
|
|
315
841
|
<Btn kind="danger" onClick={() => { void runDelete(h.alias) }} disabled={disabled}>{t('hosts.delete')}</Btn>
|
|
316
842
|
</Row>
|
|
317
843
|
{editing === h.alias && (
|
|
318
|
-
<HostFormView
|
|
844
|
+
<HostFormView
|
|
845
|
+
t={t}
|
|
846
|
+
initial={h}
|
|
847
|
+
busy={disabled}
|
|
848
|
+
hosts={props.hosts}
|
|
849
|
+
proxyDefault={props.proxyDefault}
|
|
850
|
+
onSave={saveForm}
|
|
851
|
+
onCancel={() => setEditing(null)}
|
|
852
|
+
/>
|
|
319
853
|
)}
|
|
320
854
|
</div>
|
|
321
855
|
))}
|
|
@@ -323,7 +857,14 @@ export function HostsView(props: {
|
|
|
323
857
|
<DoctorPanel key={doctor} t={t} alias={doctor} onClose={() => setDoctor(null)} />
|
|
324
858
|
)}
|
|
325
859
|
{editing === 'new' && (
|
|
326
|
-
<HostFormView
|
|
860
|
+
<HostFormView
|
|
861
|
+
t={t}
|
|
862
|
+
busy={disabled}
|
|
863
|
+
hosts={props.hosts}
|
|
864
|
+
proxyDefault={props.proxyDefault}
|
|
865
|
+
onSave={saveForm}
|
|
866
|
+
onCancel={() => setEditing(null)}
|
|
867
|
+
/>
|
|
327
868
|
)}
|
|
328
869
|
</div>
|
|
329
870
|
)
|
package/src/client/PortsView.tsx
CHANGED
|
@@ -631,6 +631,22 @@ export function PortsView(props: {
|
|
|
631
631
|
</div>
|
|
632
632
|
{forward.lastError !== undefined && <div className="rvs-ports-err">{forward.lastError}</div>}
|
|
633
633
|
<div className="rvs-ports-actions">
|
|
634
|
+
{/*
|
|
635
|
+
Which SSH connection this rule currently rides. Absent until the
|
|
636
|
+
first connection succeeded (nothing to say yet) and absent from
|
|
637
|
+
older hosts that do not publish `transport`.
|
|
638
|
+
*/}
|
|
639
|
+
{forward.transport !== undefined && forward.connections > 0 && (
|
|
640
|
+
<span
|
|
641
|
+
className="rvs-ports-transport"
|
|
642
|
+
data-transport={forward.transport}
|
|
643
|
+
title={forward.transport === 'dedicated'
|
|
644
|
+
? t('ports.transportDedicatedHint')
|
|
645
|
+
: t('ports.transportSharedHint')}
|
|
646
|
+
>
|
|
647
|
+
{forward.transport === 'dedicated' ? t('ports.transportDedicated') : t('ports.transportShared')}
|
|
648
|
+
</span>
|
|
649
|
+
)}
|
|
634
650
|
<span className="rvs-ports-conn">
|
|
635
651
|
{t('ports.connections').replace('{count}', String(forward.connections))}
|
|
636
652
|
</span>
|