From 7fa862a2635797f1aac45cfa067442ec478acb3e Mon Sep 17 00:00:00 2001 From: Osvaldo Ortega <48293249+osortega@users.noreply.github.com> Date: Fri, 23 Feb 2024 20:50:44 +0000 Subject: [PATCH] Adding Terminal and Shell request messages --- src/ts/ssh/index.ts | 2 + src/ts/ssh/messages/connectionMessages.ts | 57 +++++++++++++++++++---- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/ts/ssh/index.ts b/src/ts/ssh/index.ts index 005d3ce..25c96a3 100644 --- a/src/ts/ssh/index.ts +++ b/src/ts/ssh/index.ts @@ -60,6 +60,8 @@ export { ChannelRequestMessage, ChannelRequestType, CommandRequestMessage, + TerminalRequestMessage, + ShellRequestMessage, } from './messages/connectionMessages'; export { diff --git a/src/ts/ssh/messages/connectionMessages.ts b/src/ts/ssh/messages/connectionMessages.ts index e0621c9..f67251f 100644 --- a/src/ts/ssh/messages/connectionMessages.ts +++ b/src/ts/ssh/messages/connectionMessages.ts @@ -6,7 +6,7 @@ import { Buffer } from 'buffer'; import { SshMessage } from './sshMessage'; import { SshDataReader, SshDataWriter, formatBuffer } from '../io/sshData'; -export abstract class ConnectionMessage extends SshMessage {} +export abstract class ConnectionMessage extends SshMessage { } export abstract class ChannelMessage extends ConnectionMessage { private recipientChannelValue?: number; @@ -91,9 +91,8 @@ export class ChannelOpenMessage extends ConnectionMessage { } public toString() { - return `${super.toString()}(channelType=${this.channelType}, senderChannel=${ - this.senderChannel - })`; + return `${super.toString()}(channelType=${this.channelType}, senderChannel=${this.senderChannel + })`; } } @@ -161,9 +160,8 @@ export class ChannelOpenFailureMessage extends ChannelMessage { } public toString() { - return `${super.toString()} (${SshChannelOpenFailureReason[this.reasonCode || 0]}: ${ - this.description - })`; + return `${super.toString()} (${SshChannelOpenFailureReason[this.reasonCode || 0]}: ${this.description + })`; } } @@ -239,9 +237,8 @@ export class ChannelExtendedDataMessage extends ChannelMessage { } public toString() { - return `${super.toString()} (dataTypeCode=${this.dataTypeCode}, data=${ - this.data ? formatBuffer(this.data, '') : '[0]' - })` + return `${super.toString()} (dataTypeCode=${this.dataTypeCode}, data=${this.data ? formatBuffer(this.data, '') : '[0]' + })` } } @@ -325,6 +322,46 @@ export class CommandRequestMessage extends ChannelRequestMessage { } } +export class TerminalRequestMessage extends ChannelRequestMessage { + public term: string = ''; + public columns: number = 0; + public rows: number = 0; + public pixelWidth: number = 0; + public pixelHeight: number = 0; + public terminalModes: string = ''; + public wantReply: boolean = true + + public constructor() { + super(); + this.requestType = ChannelRequestType.terminal; + } + + protected onRead(reader: SshDataReader): void { + super.onRead(reader); + } + + protected onWrite(writer: SshDataWriter): void { + super.onWrite(writer); + writer.writeString(this.term, 'ascii'); + writer.writeUInt32(this.columns); + writer.writeUInt32(this.rows); + writer.writeUInt32(this.pixelWidth); + writer.writeUInt32(this.pixelHeight); + writer.writeString(this.terminalModes, 'ascii'); + } + + public toString(): string { + return `${super.toString()} (requestType=${this.requestType})`; + } +} + +export class ShellRequestMessage extends ChannelRequestMessage { + public constructor() { + super(); + this.requestType = ChannelRequestType.shell; + } +} + export class ChannelSignalMessage extends ChannelRequestMessage { private signalValue?: string; private errorMessageValue?: string;