UNPKG

hivessh

Version:

HiveSsh is an innovative library designed to streamline SSH2 connections and simplify task execution on Linux servers.

89 lines 4.47 kB
import net, { type ListenOptions as ServerOptions } from "net"; import { Client } from "ssh2"; export type LocalHostPortExtraOptions = Omit<Partial<ServerOptions>, "host" | "port" | "path">; export type SshTunnelOutLocalHostPort = { localHost: string; localPort: number; } & LocalHostPortExtraOptions; export type SshTunnelOutLocalSocket = { localPath: string; } & LocalHostPortExtraOptions; export interface SshTunnelOutRemoteHostPort { remoteHost: string; remotePort: number; forwardSourceHost?: string; forwardSourcePort?: number; } export interface SshTunnelOutRemoteSocket { remotePath: string; } export type SshTunnelLocalOutOptions = SshTunnelOutLocalHostPort | SshTunnelOutLocalSocket; export type SshTunnelRemoteOutOptions = SshTunnelOutRemoteHostPort | SshTunnelOutRemoteSocket; export type SshTunnelOutOptions = SshTunnelLocalOutOptions & SshTunnelRemoteOutOptions; /** * Returns true if the given options are for a local socket (i.e. path is present). * * @param options - The options to check. * @returns True if the options are for a local socket, otherwise false. */ export declare function isSshTunnelOutLocalSocketOption(options: SshTunnelOutOptions): options is SshTunnelOutLocalSocket & SshTunnelRemoteOutOptions; /** * Returns true if the given options are for a remote socket (i.e. remotePath is present). * * @param options - The options to check. * @returns True if the options are for a remote socket, otherwise false. */ export declare function isSshTunnelOutRemoteSocketOption(options: SshTunnelOutOptions): options is SshTunnelLocalOutOptions & SshTunnelOutRemoteSocket; /** * @experimental This function is experimental and may not be stable. * Tunnels incoming server socket conntions to a remote host and port bind (not linux socket). * * This function establishes an SSH tunnel by forwarding * a local server's address and port to a specified remote * host and port. It manages the connection and lifecycle of * the tunnel, ensuring that resources are cleaned up upon * closure of the server or socket. * * @param sshClient - The SSH client instance used to establish the tunnel. * @param server - The local server for which the tunnel is being created. * @param socket - The socket associated with the server. * @param tunnelOptions - Options specifying remote host and port details * and optional forwarding source host and port. * * @throws {Error} If the server's socket address is invalid. */ export declare function handleRemoteHostPortOutTunnel(sshClient: Client, server: net.Server, socket: net.Socket, tunnelOptions: SshTunnelOutRemoteHostPort): void; /** * @experimental This function is experimental and may not be stable. * Tunnels incoming server socket conntions to a remote socket (not address and port bind) using openssh. * * This function establishes an SSH tunnel by forwarding * a local server's address and port to a specified remote * socket path. It manages the connection and lifecycle of * the tunnel, ensuring that resources are cleaned up upon * closure of the server or socket. * * @param sshClient - The SSH client instance used to establish the tunnel. * @param server - The local server for which the tunnel is being created. * @param socket - The socket associated with the server. * @param tunnelOptions - Options specifying remote socket path details * and optional forwarding source host and port. * * @throws {Error} If the server's socket address is invalid. */ export declare function handleRemoteSocketOutTunnel(sshClient: Client, server: net.Server, socket: net.Socket, tunnelOptions: SshTunnelOutRemoteSocket): void; /** * @experimental This function is experimental and may not be stable. * Creates a local server that tunnels incoming connections to a remote linux socket or host and port bind. * * You need to close the server to stop tunneling! * * This function creates a server that listens for incoming connections and forwards them to the remote SSH host. * * @param sshClient - The SSH client instance used to establish the tunnel. * @param tunnelOptions - Options specifying remote linux socket or host and port details. * * @returns A promise that resolves to the created server that need to be closed. */ export declare function tunnelOut(sshClient: Client, tunnelOptions: SshTunnelOutOptions): Promise<net.Server>; //# sourceMappingURL=SshTunnel.d.ts.map