mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 15:41:17 +00:00
* fix(vault): round-trip jump host chains in CSV import/export CSV export dropped hostChain, so a vault imported on another machine lost every jump host. Persist the ordered chain as an OpenSSH ProxyJump column and bind each hop on import. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(vault): drop inline hops from a rejected ProxyJump chain A self-referential ProxyJump list created unresolved hops before the chain was skipped, so the import kept those hosts. Discard inline hosts created for that rejected chain. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(vault): prefer a same-group hop when binding CSV ProxyJump When an imported host and an existing vault host both match a hop endpoint, pick the candidate in the target host's group before falling back to the imported match. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(vault): prefer a same-group label when binding CSV ProxyJump Combine imported and existing label matches before pickCsvJumpCandidate so a cross-group imported label cannot beat an existing hop in the target group. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> * fix(vault): reject CSV ProxyJump chains that contain a malformed hop A multi-hop ProxyJump cell with any invalid hop now warns and leaves the host chain unset, instead of saving the valid hops as a shortened route. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
const FORMULA_PREFIX = /^[=+\-@\t\r]/u;
|
|
const KEY_PATH_MARKER = "__netcatty_csv_keypath_v1__:";
|
|
const PASSPHRASE_MARKER = "__netcatty_csv_passphrase_v1__:";
|
|
const PROXY_MARKER = "__netcatty_csv_proxy_v1__:";
|
|
const PROXY_JUMP_MARKER = "__netcatty_csv_proxyjump_v1__:";
|
|
const LOCAL_SHELL_MARKER = "__netcatty_csv_localshell_v1__:";
|
|
|
|
const encodeMarkedField = (value: string, marker: string): string => (
|
|
FORMULA_PREFIX.test(value) || value.startsWith(marker)
|
|
? `${marker}${encodeURIComponent(value)}`
|
|
: value
|
|
);
|
|
|
|
const decodeMarkedField = (value: string, marker: string): string => {
|
|
if (!value.startsWith(marker)) return value;
|
|
try {
|
|
return decodeURIComponent(value.slice(marker.length));
|
|
} catch {
|
|
return value;
|
|
}
|
|
};
|
|
|
|
export const encodeCsvKeyPath = (value: string): string => (
|
|
encodeMarkedField(value, KEY_PATH_MARKER)
|
|
);
|
|
|
|
export const decodeCsvKeyPath = (value: string): string => (
|
|
decodeMarkedField(value, KEY_PATH_MARKER)
|
|
);
|
|
|
|
export const encodeCsvPassphrase = (value: string): string => (
|
|
encodeMarkedField(value, PASSPHRASE_MARKER)
|
|
);
|
|
|
|
export const decodeCsvPassphrase = (value: string): string => (
|
|
decodeMarkedField(value, PASSPHRASE_MARKER)
|
|
);
|
|
|
|
export const encodeCsvProxy = (value: string): string => (
|
|
encodeMarkedField(value, PROXY_MARKER)
|
|
);
|
|
|
|
export const decodeCsvProxy = (value: string): string => (
|
|
decodeMarkedField(value, PROXY_MARKER)
|
|
);
|
|
|
|
export const encodeCsvProxyJump = (value: string): string => (
|
|
encodeMarkedField(value, PROXY_JUMP_MARKER)
|
|
);
|
|
|
|
export const decodeCsvProxyJump = (value: string): string => (
|
|
decodeMarkedField(value, PROXY_JUMP_MARKER)
|
|
);
|
|
|
|
export interface CsvLocalShellSpec {
|
|
shell?: string;
|
|
shellArgs?: string[];
|
|
shellName?: string;
|
|
shellIcon?: string;
|
|
startDir?: string;
|
|
/** Host OS of the local-shell entry; decides the default-shell fallback on connect. */
|
|
os?: "linux" | "windows" | "macos";
|
|
}
|
|
|
|
export const encodeCsvLocalShell = (spec: CsvLocalShellSpec): string => (
|
|
encodeMarkedField(JSON.stringify(spec), LOCAL_SHELL_MARKER)
|
|
);
|
|
|
|
const isNonEmptyString = (value: unknown): value is string => (
|
|
typeof value === "string" && value.trim().length > 0
|
|
);
|
|
|
|
const isNonEmptyStringArray = (value: unknown): value is string[] => (
|
|
Array.isArray(value) && value.length > 0 && value.every(isNonEmptyString)
|
|
);
|
|
|
|
export const decodeCsvLocalShell = (value: string): CsvLocalShellSpec | null => {
|
|
const raw = decodeMarkedField(value, LOCAL_SHELL_MARKER).trim();
|
|
if (!raw) return null;
|
|
try {
|
|
const parsed: unknown = JSON.parse(raw);
|
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
const record = parsed as Record<string, unknown>;
|
|
const spec: CsvLocalShellSpec = {
|
|
...(isNonEmptyString(record.shell) ? { shell: record.shell } : {}),
|
|
...(isNonEmptyStringArray(record.shellArgs) ? { shellArgs: record.shellArgs } : {}),
|
|
...(isNonEmptyString(record.shellName) ? { shellName: record.shellName } : {}),
|
|
...(isNonEmptyString(record.shellIcon) ? { shellIcon: record.shellIcon } : {}),
|
|
...(isNonEmptyString(record.startDir) ? { startDir: record.startDir } : {}),
|
|
...(record.os === "linux" || record.os === "windows" || record.os === "macos"
|
|
? { os: record.os }
|
|
: {}),
|
|
};
|
|
return Object.keys(spec).length > 0 ? spec : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|