Files
Netcatty/domain/quickConnectHost.ts
T
626e0ce5bd fix(quick-connect): accept multi-@ jump chains like JumpServer (#3525)
* fix(#3523): automated AI fix

* fix(#3523): parse JumpServer login on final SSH host

* fix(#3523): preserve login with SSH HostName override

* fix(#3523): guard JumpServer credential presets

* fix(#3523): retain SSH user with HostName alias

* fix(#3523): distinguish JumpServer login from SSH user option

---------

Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
2026-09-24 17:49:46 +08:00

86 lines
2.4 KiB
TypeScript

import { sanitizeCredentialValue } from "./credentials";
import type { Host, Identity, SSHKey } from "./models";
import type { QuickConnectTarget } from "./quickConnect";
export type QuickConnectProtocol = "ssh" | "mosh" | "et" | "telnet";
export type QuickConnectAuthMethod = "password" | "key" | "certificate";
export const getQuickConnectDefaultPort = (
protocol: QuickConnectProtocol,
): number => protocol === "telnet" ? 23 : 22;
export const isQuickConnectIdentityUsable = (
identity: Identity | undefined,
keys: SSHKey[],
protocol: QuickConnectProtocol = "ssh",
): boolean => {
if (!identity?.username.trim() || protocol === "telnet") return false;
if (identity.authMethod === "password") {
return Boolean(sanitizeCredentialValue(identity.password));
}
return Boolean(identity.keyId && keys.some((key) => key.id === identity.keyId));
};
export const isQuickConnectIdentityCompatible = (
identity: Identity,
target: QuickConnectTarget,
): boolean => !target.isJumpServerLogin
|| identity.username === target.username;
type BuildQuickConnectHostInput = {
id: string;
createdAt: number;
target: QuickConnectTarget;
protocol: QuickConnectProtocol;
port: number;
username: string;
authMethod: QuickConnectAuthMethod;
password?: string;
selectedKeyId?: string | null;
selectedIdentityId?: string | null;
save?: boolean;
};
export const buildQuickConnectHost = ({
id,
createdAt,
target,
protocol,
port,
username,
authMethod,
password,
selectedKeyId,
selectedIdentityId,
save = false,
}: BuildQuickConnectHostInput): Host => {
const isTelnet = protocol === "telnet";
const applicableIdentityId = isTelnet ? undefined : selectedIdentityId || undefined;
return {
id,
label: target.hostname,
hostname: target.hostname,
port,
username,
group: "",
tags: [],
os: "linux",
protocol: protocol === "mosh" || protocol === "et" ? "ssh" : protocol,
authMethod,
identityId: applicableIdentityId,
password: !applicableIdentityId && authMethod === "password" ? password : undefined,
identityFileId:
!applicableIdentityId && authMethod !== "password"
? selectedKeyId || undefined
: undefined,
moshEnabled: protocol === "mosh",
etEnabled: protocol === "et",
etPort: protocol === "et" ? 2022 : undefined,
telnetEnabled: isTelnet,
telnetPort: isTelnet ? port : undefined,
ephemeral: !save,
createdAt,
};
};