webssh2-server
Version:
A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2
85 lines (84 loc) • 2.92 kB
TypeScript
import type { ConnectConfig } from 'ssh2';
import type { Config } from '../types/config.js';
import type { Result } from '../types/result.js';
import { type SshCredentials, type PtyOptions } from './config-builder.js';
export interface ConnectionConfig {
host: string;
port: number;
username: string;
password?: string;
privateKey?: string;
passphrase?: string;
readyTimeout?: number;
keepaliveInterval?: number;
keepaliveCountMax?: number;
algorithms?: Record<string, unknown>;
allowedSubnets?: string[] | undefined;
}
export interface ShellOptions {
pty: PtyOptions;
env?: Record<string, string> | undefined;
}
export interface ExecOptions {
command: string;
pty?: PtyOptions | undefined;
env?: Record<string, string> | undefined;
}
export interface ConnectionState {
id: string;
status: 'disconnected' | 'connecting' | 'connected' | 'error';
host: string;
port: number;
username: string;
connectedAt?: Date;
lastActivity?: Date;
errorMessage?: string;
}
/**
* Create SSH connection configuration from credentials and app config
* Pure function - no side effects
*/
export declare const createConnectionConfig: (credentials: SshCredentials, appConfig: Config) => ConnectionConfig;
/**
* Prepare shell options from terminal config and environment
* Pure function - no side effects
*/
export declare const prepareShellOptions: (terminal: PtyOptions, env?: Record<string, string>, allowlist?: string[]) => ShellOptions;
/**
* Prepare exec command options
* Pure function - no side effects
*/
export declare const prepareExecOptions: (command: string, pty?: PtyOptions, env?: Record<string, string>, allowlist?: string[]) => ExecOptions;
/**
* Validate connection configuration
* Pure function - returns Result type
*/
export declare const validateConnectionConfig: (config: ConnectionConfig) => Result<ConnectionConfig>;
/**
* Create initial connection state
* Pure function - no side effects
*/
export declare const createConnectionState: (config: ConnectionConfig, id?: string) => ConnectionState;
/**
* Update connection state
* Pure function - returns new state
*/
export declare const updateConnectionState: (state: ConnectionState, update: Partial<ConnectionState>) => ConnectionState;
/**
* Process keyboard-interactive authentication
* Pure function - returns responses
*/
export declare const processKeyboardInteractive: (prompts: Array<{
prompt: string;
echo: boolean;
}>, password?: string) => string[];
/**
* Check if connection is allowed based on subnet restrictions
* Pure function - no side effects
*/
export declare const isConnectionAllowed: (host: string, allowedSubnets?: string[]) => Result<boolean>;
/**
* Convert to SSH2 connect config format
* Pure function - no side effects
*/
export declare const toSsh2Config: (config: ConnectionConfig) => Partial<ConnectConfig>;