mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-17 05:43:36 +00:00
8b6037b7ff
- ssh/ renamed to hosts/ (it covers SSH, RDP, VNC, Telnet, Docker, metrics) - serial/serial.ts and guacamole/ moved inside hosts/ - dashboard.ts and homepage.ts moved to services/ - swagger.ts moved to utils/ with adjusted scan globs Import paths and the generate:openapi script updated; ports and endpoints unchanged.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import type { ProxyNode } from "../../types/index.js";
|
|
import type { SOCKS5Config } from "../utils/socks5-helper.js";
|
|
|
|
type JumpHostProxyConfig = {
|
|
useSocks5?: boolean | null;
|
|
socks5Host?: string | null;
|
|
socks5Port?: number | null;
|
|
socks5Username?: string | null;
|
|
socks5Password?: string | null;
|
|
socks5ProxyChain?: ProxyNode[] | string | null;
|
|
};
|
|
|
|
function parseProxyChain(value: JumpHostProxyConfig["socks5ProxyChain"]) {
|
|
if (Array.isArray(value)) {
|
|
return value;
|
|
}
|
|
|
|
if (typeof value !== "string" || value.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
try {
|
|
const parsed = JSON.parse(value);
|
|
return Array.isArray(parsed) ? (parsed as ProxyNode[]) : [];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export function getJumpHostSocks5Config(
|
|
firstHop: JumpHostProxyConfig | null | undefined,
|
|
fallbackConfig?: SOCKS5Config | null,
|
|
): SOCKS5Config | null {
|
|
if (!firstHop?.useSocks5) {
|
|
return fallbackConfig ?? null;
|
|
}
|
|
|
|
const socks5ProxyChain = parseProxyChain(firstHop.socks5ProxyChain);
|
|
if (!firstHop.socks5Host && socks5ProxyChain.length === 0) {
|
|
return fallbackConfig ?? null;
|
|
}
|
|
|
|
return {
|
|
useSocks5: true,
|
|
socks5Host: firstHop.socks5Host ?? undefined,
|
|
socks5Port: firstHop.socks5Port ?? undefined,
|
|
socks5Username: firstHop.socks5Username ?? undefined,
|
|
socks5Password: firstHop.socks5Password ?? undefined,
|
|
socks5ProxyChain,
|
|
};
|
|
}
|