Initial sync up with master after Prettier
This commit is contained in:
@@ -2,24 +2,19 @@
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const resetScreen = require('./ansi_term.js').resetScreen;
|
||||
const setSyncTermFontWithAlias = require('./ansi_term.js').setSyncTermFontWithAlias;
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const resetScreen = require('./ansi_term.js').resetScreen;
|
||||
const setSyncTermFontWithAlias = require('./ansi_term.js').setSyncTermFontWithAlias;
|
||||
|
||||
// deps
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
const net = require('net');
|
||||
const EventEmitter = require('events');
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
const net = require('net');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const {
|
||||
TelnetSocket,
|
||||
TelnetSpec :
|
||||
{
|
||||
Commands,
|
||||
Options,
|
||||
SubNegotiationCommands,
|
||||
},
|
||||
TelnetSpec: { Commands, Options, SubNegotiationCommands },
|
||||
} = require('telnet-socket');
|
||||
|
||||
/*
|
||||
@@ -37,15 +32,12 @@ const {
|
||||
|
||||
// :TODO: ENH: Support nodeMax and tooManyArt
|
||||
exports.moduleInfo = {
|
||||
name : 'Telnet Bridge',
|
||||
desc : 'Connect to other Telnet Systems',
|
||||
author : 'Andrew Pamment',
|
||||
name: 'Telnet Bridge',
|
||||
desc: 'Connect to other Telnet Systems',
|
||||
author: 'Andrew Pamment',
|
||||
};
|
||||
|
||||
const IAC_DO_TERM_TYPE = TelnetSocket.commandBuffer(
|
||||
Commands.DO,
|
||||
Options.TTYPE
|
||||
);
|
||||
const IAC_DO_TERM_TYPE = TelnetSocket.commandBuffer(Commands.DO, Options.TTYPE);
|
||||
|
||||
class TelnetClientConnection extends EventEmitter {
|
||||
constructor(client) {
|
||||
@@ -57,20 +49,20 @@ class TelnetClientConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
updateActivity() {
|
||||
if (0 === (this.dataHits++ % 4)) {
|
||||
if (0 === this.dataHits++ % 4) {
|
||||
this.client.explicitActivityTimeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
restorePipe() {
|
||||
if(!this.pipeRestored) {
|
||||
if (!this.pipeRestored) {
|
||||
this.pipeRestored = true;
|
||||
|
||||
this.client.restoreDataHandler();
|
||||
|
||||
// client may have bailed
|
||||
if(null !== _.get(this, 'client.term.output', null)) {
|
||||
if(this.bridgeConnection) {
|
||||
if (null !== _.get(this, 'client.term.output', null)) {
|
||||
if (this.bridgeConnection) {
|
||||
this.client.term.output.unpipe(this.bridgeConnection);
|
||||
}
|
||||
this.client.term.output.resume();
|
||||
@@ -99,7 +91,7 @@ class TelnetClientConnection extends EventEmitter {
|
||||
// This is enough (in additional to other negotiations handled in telnet.js)
|
||||
// to get us in on most systems
|
||||
//
|
||||
if(!this.termSent && data.indexOf(IAC_DO_TERM_TYPE) > -1) {
|
||||
if (!this.termSent && data.indexOf(IAC_DO_TERM_TYPE) > -1) {
|
||||
this.termSent = true;
|
||||
this.bridgeConnection.write(this.getTermTypeNegotiationBuffer());
|
||||
}
|
||||
@@ -117,13 +109,13 @@ class TelnetClientConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if(this.bridgeConnection) {
|
||||
if (this.bridgeConnection) {
|
||||
this.bridgeConnection.end();
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if(this.bridgeConnection) {
|
||||
if (this.bridgeConnection) {
|
||||
this.bridgeConnection.destroy();
|
||||
this.bridgeConnection.removeAllListeners();
|
||||
this.restorePipe();
|
||||
@@ -136,16 +128,12 @@ class TelnetClientConnection extends EventEmitter {
|
||||
// Create a TERMINAL-TYPE sub negotiation buffer using the
|
||||
// actual/current terminal type.
|
||||
//
|
||||
const sendTermType = TelnetSocket.commandBuffer(
|
||||
Commands.SB,
|
||||
Options.TTYPE,
|
||||
[
|
||||
SubNegotiationCommands.IS,
|
||||
...Buffer.from(this.client.term.termType), // e.g. "ansi"
|
||||
Commands.IAC,
|
||||
Commands.SE,
|
||||
]
|
||||
);
|
||||
const sendTermType = TelnetSocket.commandBuffer(Commands.SB, Options.TTYPE, [
|
||||
SubNegotiationCommands.IS,
|
||||
...Buffer.from(this.client.term.termType), // e.g. "ansi"
|
||||
Commands.IAC,
|
||||
Commands.SE,
|
||||
]);
|
||||
return sendTermType;
|
||||
}
|
||||
}
|
||||
@@ -154,8 +142,12 @@ exports.getModule = class TelnetBridgeModule extends MenuModule {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
||||
this.config = Object.assign({}, _.get(options, 'menuConfig.config'), options.extraArgs);
|
||||
this.config.port = this.config.port || 23;
|
||||
this.config = Object.assign(
|
||||
{},
|
||||
_.get(options, 'menuConfig.config'),
|
||||
options.extraArgs
|
||||
);
|
||||
this.config.port = this.config.port || 23;
|
||||
}
|
||||
|
||||
initSequence() {
|
||||
@@ -165,18 +157,18 @@ exports.getModule = class TelnetBridgeModule extends MenuModule {
|
||||
async.series(
|
||||
[
|
||||
function validateConfig(callback) {
|
||||
if(_.isString(self.config.host) &&
|
||||
_.isNumber(self.config.port))
|
||||
{
|
||||
if (_.isString(self.config.host) && _.isNumber(self.config.port)) {
|
||||
callback(null);
|
||||
} else {
|
||||
callback(new Error('Configuration is missing required option(s)'));
|
||||
callback(
|
||||
new Error('Configuration is missing required option(s)')
|
||||
);
|
||||
}
|
||||
},
|
||||
function createTelnetBridge(callback) {
|
||||
const connectOpts = {
|
||||
port : self.config.port,
|
||||
host : self.config.host,
|
||||
port: self.config.port,
|
||||
host: self.config.host,
|
||||
};
|
||||
|
||||
self.client.term.write(resetScreen());
|
||||
@@ -187,8 +179,11 @@ exports.getModule = class TelnetBridgeModule extends MenuModule {
|
||||
const telnetConnection = new TelnetClientConnection(self.client);
|
||||
|
||||
const connectionKeyPressHandler = (ch, key) => {
|
||||
if('escape' === key.name) {
|
||||
self.client.removeListener('key press', connectionKeyPressHandler);
|
||||
if ('escape' === key.name) {
|
||||
self.client.removeListener(
|
||||
'key press',
|
||||
connectionKeyPressHandler
|
||||
);
|
||||
telnetConnection.destroy();
|
||||
}
|
||||
};
|
||||
@@ -196,16 +191,26 @@ exports.getModule = class TelnetBridgeModule extends MenuModule {
|
||||
self.client.on('key press', connectionKeyPressHandler);
|
||||
|
||||
telnetConnection.on('connected', () => {
|
||||
self.client.removeListener('key press', connectionKeyPressHandler);
|
||||
self.client.log.info(connectOpts, 'Telnet bridge connection established');
|
||||
self.client.removeListener(
|
||||
'key press',
|
||||
connectionKeyPressHandler
|
||||
);
|
||||
self.client.log.info(
|
||||
connectOpts,
|
||||
'Telnet bridge connection established'
|
||||
);
|
||||
|
||||
// put the font back how it was prior, if fonts are enabled
|
||||
if(self.client.term.syncTermFontsEnabled && self.config.font) {
|
||||
self.client.term.rawWrite(setSyncTermFontWithAlias(self.config.font));
|
||||
if (self.client.term.syncTermFontsEnabled && self.config.font) {
|
||||
self.client.term.rawWrite(
|
||||
setSyncTermFontWithAlias(self.config.font)
|
||||
);
|
||||
}
|
||||
|
||||
self.client.once('end', () => {
|
||||
self.client.log.info('Connection ended. Terminating connection');
|
||||
self.client.log.info(
|
||||
'Connection ended. Terminating connection'
|
||||
);
|
||||
clientTerminated = true;
|
||||
telnetConnection.disconnect();
|
||||
});
|
||||
@@ -218,18 +223,25 @@ exports.getModule = class TelnetBridgeModule extends MenuModule {
|
||||
self.client.log.warn(`Telnet bridge connection error: ${err.message}`);
|
||||
}
|
||||
|
||||
callback(clientTerminated ? new Error('Client connection terminated') : null);
|
||||
callback(
|
||||
clientTerminated
|
||||
? new Error('Client connection terminated')
|
||||
: null
|
||||
);
|
||||
});
|
||||
|
||||
telnetConnection.connect(connectOpts);
|
||||
}
|
||||
},
|
||||
],
|
||||
err => {
|
||||
if(err) {
|
||||
self.client.log.warn( { error : err.message }, 'Telnet connection error');
|
||||
if (err) {
|
||||
self.client.log.warn(
|
||||
{ error: err.message },
|
||||
'Telnet connection error'
|
||||
);
|
||||
}
|
||||
|
||||
if(!clientTerminated) {
|
||||
if (!clientTerminated) {
|
||||
self.prevMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user