Telnet Bridge updates

* Use telnet-socket TelnetSpec/etc. consts & helpers
* Enable passthrough
This commit is contained in:
Bryan Ashby 2020-05-27 21:05:19 -06:00
parent 4dea9bdeb6
commit 87a23bd3c8
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
2 changed files with 26 additions and 18 deletions

View File

@ -397,6 +397,7 @@ exports.getModule = class TransferFileModule extends MenuModule {
this.client.setTemporaryDirectDataHandler(data => { this.client.setTemporaryDirectDataHandler(data => {
updateActivity(); updateActivity();
// needed for things like sz/rz // needed for things like sz/rz
if(processIACs) { if(processIACs) {
let iacPos = data.indexOf(EscapedIAC); let iacPos = data.indexOf(EscapedIAC);

View File

@ -11,7 +11,16 @@ const async = require('async');
const _ = require('lodash'); const _ = require('lodash');
const net = require('net'); const net = require('net');
const EventEmitter = require('events'); const EventEmitter = require('events');
const buffers = require('buffers');
const {
TelnetSocket,
TelnetSpec :
{
Commands,
Options,
SubNegotiationCommands,
},
} = require('telnet-socket');
/* /*
Expected configuration block: Expected configuration block:
@ -33,7 +42,10 @@ exports.moduleInfo = {
author : 'Andrew Pamment', author : 'Andrew Pamment',
}; };
const IAC_DO_TERM_TYPE = Buffer.from( [ 255, 253, 24 ] ); const IAC_DO_TERM_TYPE = TelnetSocket.commandBuffer(
Commands.DO,
Options.TTYPE,
);
class TelnetClientConnection extends EventEmitter { class TelnetClientConnection extends EventEmitter {
constructor(client) { constructor(client) {
@ -46,6 +58,7 @@ class TelnetClientConnection extends EventEmitter {
restorePipe() { restorePipe() {
if(!this.pipeRestored) { if(!this.pipeRestored) {
this.pipeRestored = true; this.pipeRestored = true;
this.client.dataPassthrough = false;
// client may have bailed // client may have bailed
if(null !== _.get(this, 'client.term.output', null)) { if(null !== _.get(this, 'client.term.output', null)) {
@ -62,6 +75,7 @@ class TelnetClientConnection extends EventEmitter {
this.emit('connected'); this.emit('connected');
this.pipeRestored = false; this.pipeRestored = false;
this.client.dataPassthrough = true;
this.client.term.output.pipe(this.bridgeConnection); this.client.term.output.pipe(this.bridgeConnection);
}); });
@ -69,7 +83,7 @@ class TelnetClientConnection extends EventEmitter {
this.client.term.rawWrite(data); this.client.term.rawWrite(data);
// //
// Wait for a terminal type request, and send it eactly once. // Wait for a terminal type request, and send it exactly once.
// This is enough (in additional to other negotiations handled in telnet.js) // This is enough (in additional to other negotiations handled in telnet.js)
// to get us in on most systems // to get us in on most systems
// //
@ -110,25 +124,18 @@ class TelnetClientConnection extends EventEmitter {
// Create a TERMINAL-TYPE sub negotiation buffer using the // Create a TERMINAL-TYPE sub negotiation buffer using the
// actual/current terminal type. // actual/current terminal type.
// //
let bufs = buffers(); const sendTermType = TelnetSocket.commandBuffer(
Commands.SB,
bufs.push(Buffer.from( Options.TTYPE,
[ [
255, // IAC SubNegotiationCommands.IS,
250, // SB ...Buffer.from(this.client.term.termType), // e.g. "ansi"
24, // TERMINAL-TYPE Commands.IAC,
0, // IS Commands.SE,
] ]
));
bufs.push(
Buffer.from(this.client.term.termType), // e.g. "ansi"
Buffer.from( [ 255, 240 ] ) // IAC, SE
); );
return sendTermType;
return bufs.toBuffer();
} }
} }
exports.getModule = class TelnetBridgeModule extends MenuModule { exports.getModule = class TelnetBridgeModule extends MenuModule {