From f6f1de4bd884444019193cd06aae5fa28074ab8d Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 8 Mar 2018 21:39:42 -0700 Subject: [PATCH] Move to pty-node over custom pty2.js --- core/archive_util.js | 2 +- core/door.js | 18 +++++++----------- core/event_scheduler.js | 2 +- core/file_transfer.js | 15 +++++++++------ package.json | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/core/archive_util.js b/core/archive_util.js index 00e48ed8..8a4c388a 100644 --- a/core/archive_util.js +++ b/core/archive_util.js @@ -10,7 +10,7 @@ const resolveMimeType = require('./mime_util.js').resolveMimeType; // base/modules const fs = require('graceful-fs'); const _ = require('lodash'); -const pty = require('ptyw.js'); +const pty = require('node-pty'); let archiveUtil; diff --git a/core/door.js b/core/door.js index 525a7a02..58c8effa 100644 --- a/core/door.js +++ b/core/door.js @@ -6,7 +6,7 @@ const stringFormat = require('./string_format.js'); const events = require('events'); const _ = require('lodash'); -const pty = require('ptyw.js'); +const pty = require('node-pty'); const decode = require('iconv-lite').decode; const createServer = require('net').createServer; @@ -18,8 +18,7 @@ function Door(client, exeInfo) { const self = this; this.client = client; this.exeInfo = exeInfo; - this.exeInfo.encoding = this.exeInfo.encoding || 'cp437'; - this.exeInfo.encoding = this.exeInfo.encoding.toLowerCase(); + this.exeInfo.encoding = (this.exeInfo.encoding || 'cp437').toLowerCase(); let restored = false; // @@ -36,11 +35,7 @@ function Door(client, exeInfo) { // this.doorDataHandler = function(data) { - if(self.client.term.outputEncoding === self.exeInfo.encoding) { - self.client.term.rawWrite(data); - } else { - self.client.term.write(decode(data, self.exeInfo.encoding)); - } + self.client.term.write(decode(data, self.exeInfo.encoding)); }; this.restoreIo = function(piped) { @@ -113,10 +108,11 @@ Door.prototype.run = function() { } const door = pty.spawn(self.exeInfo.cmd, args, { - cols : self.client.term.termWidth, - rows : self.client.term.termHeight, + cols : self.client.term.termWidth, + rows : self.client.term.termHeight, // :TODO: cwd - env : self.exeInfo.env, + env : self.exeInfo.env, + encoding : null, // we want to handle all encoding ourself }); if('stdio' === self.exeInfo.io) { diff --git a/core/event_scheduler.js b/core/event_scheduler.js index 0366d5ba..10c59f72 100644 --- a/core/event_scheduler.js +++ b/core/event_scheduler.js @@ -9,7 +9,7 @@ const Log = require('./logger.js').log; const _ = require('lodash'); const later = require('later'); const path = require('path'); -const pty = require('ptyw.js'); +const pty = require('node-pty'); const sane = require('sane'); const moment = require('moment'); const paths = require('path'); diff --git a/core/file_transfer.js b/core/file_transfer.js index bb3d362c..757eff8a 100644 --- a/core/file_transfer.js +++ b/core/file_transfer.js @@ -14,7 +14,7 @@ const Log = require('./logger.js').log; // deps const async = require('async'); const _ = require('lodash'); -const pty = require('ptyw.js'); +const pty = require('node-pty'); const temptmp = require('temptmp').createTrackedSession('transfer_file'); const paths = require('path'); const fs = require('graceful-fs'); @@ -361,11 +361,14 @@ exports.getModule = class TransferFileModule extends MenuModule { 'Executing external protocol' ); - const externalProc = pty.spawn(cmd, args, { - cols : this.client.term.termWidth, - rows : this.client.term.termHeight, - cwd : this.recvDirectory, - }); + const spawnOpts = { + cols : this.client.term.termWidth, + rows : this.client.term.termHeight, + cwd : this.recvDirectory, + encoding : null, // don't bork our data! + }; + + const externalProc = pty.spawn(cmd, args, spawnOpts); this.client.setTemporaryDirectDataHandler(data => { // needed for things like sz/rz diff --git a/package.json b/package.json index 8c7a7a5d..88844455 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "minimist": "1.2.x", "moment": "^2.20.1", "nodemailer": "^4.4.1", - "ptyw.js": "NuSkooler/ptyw.js", + "node-pty": "^0.7.4", "rlogin": "^1.0.0", "sane": "^2.2.0", "sanitize-filename": "^1.6.1",