From 1e930c60f2ee1cbfac835b77aabdd5d586c0b865 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 5 Apr 2019 09:21:21 -0700 Subject: [PATCH] Fixed module installation code. --- meshcentral.js | 10 +- package.json | 2 +- public/scripts/amt-terminal-0.0.2.js | 375 +++++++++++++++------------ 3 files changed, 223 insertions(+), 164 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index 905427ce..7584a7bc 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -66,15 +66,15 @@ function CreateMeshCentralServer(config, args) { // Setup the default configuration and files paths if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { + obj.parentpath = obj.path.join(__dirname, '../..'); obj.datapath = obj.path.join(__dirname, '../../meshcentral-data'); obj.filespath = obj.path.join(__dirname, '../../meshcentral-files'); - obj.parentpath = obj.path.join(__dirname, '../..'); if (obj.fs.existsSync(obj.path.join(__dirname, '../../meshcentral-web/views'))) { obj.webViewsPath = obj.path.join(__dirname, '../../meshcentral-web/views'); } else { obj.webViewsPath = obj.path.join(__dirname, 'views'); } if (obj.fs.existsSync(obj.path.join(__dirname, '../../meshcentral-web/public'))) { obj.webPublicPath = obj.path.join(__dirname, '../../meshcentral-web/public'); } else { obj.webPublicPath = obj.path.join(__dirname, 'public'); } } else { + obj.parentpath = __dirname; obj.datapath = obj.path.join(__dirname, '../meshcentral-data'); obj.filespath = obj.path.join(__dirname, '../meshcentral-files'); - obj.parentpath = obj.path.join(__dirname, '..'); if (obj.fs.existsSync(obj.path.join(__dirname, '../meshcentral-web/views'))) { obj.webViewsPath = obj.path.join(__dirname, '../meshcentral-web/views'); } else { obj.webViewsPath = obj.path.join(__dirname, 'views'); } if (obj.fs.existsSync(obj.path.join(__dirname, '../meshcentral-web/public'))) { obj.webPublicPath = obj.path.join(__dirname, '../meshcentral-web/public'); } else { obj.webPublicPath = obj.path.join(__dirname, 'public'); } } @@ -1646,9 +1646,13 @@ var InstallModuleChildProcess = null; function InstallModule(modulename, func, tag1, tag2) { console.log('Installing ' + modulename + '...'); var child_process = require('child_process'); + var parentpath = __dirname; + + // Get the working directory + if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); } // Looks like we need to keep a global reference to the child process object for this to work correctly. - InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 10000, cwd: obj.parentpath }, function (error, stdout, stderr) { + InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 10000, cwd: parentpath }, function (error, stdout, stderr) { InstallModuleChildProcess = null; if (error != null) { console.log('ERROR: Unable to install required module "' + modulename + '". MeshCentral may not have access to npm, or npm may not have suffisent rights to load the new module. Try "npm install ' + modulename + '" to manualy install this module.\r\n'); diff --git a/package.json b/package.json index 7d52aabc..fbf3f23a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.1-u", + "version": "0.3.1-w", "keywords": [ "Remote Management", "Intel AMT", diff --git a/public/scripts/amt-terminal-0.0.2.js b/public/scripts/amt-terminal-0.0.2.js index 072ce943..27d6b591 100644 --- a/public/scripts/amt-terminal-0.0.2.js +++ b/public/scripts/amt-terminal-0.0.2.js @@ -4,6 +4,8 @@ * @version v0.0.2c */ +// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html + // Construct a MeshServer object var CreateAmtRemoteTerminal = function (divid) { var obj = {}; @@ -32,10 +34,14 @@ var CreateAmtRemoteTerminal = function (divid) { var _termstate = 0; var _escNumber = []; var _escNumberPtr = 0; + var _escNumberMode = 0; var _scratt = []; var _tscreen = []; var _VTUNDERLINE = 1; var _VTREVERSE = 2; + var _backSpaceErase = false; + var _cursorVisible = true; + var _scrollRegion = [0, 25]; obj.Start = function () { } @@ -72,6 +78,9 @@ var CreateAmtRemoteTerminal = function (divid) { switch (c) { case 27: // ESC _termstate = 1; + _escNumber = []; + _escNumberPtr = 0; + _escNumberMode = 0; break; default: // Process a single char @@ -82,8 +91,6 @@ var CreateAmtRemoteTerminal = function (divid) { case 1: switch (b) { case '[': - _escNumberPtr = 0; - _escNumber = []; _termstate = 2; break; case '(': @@ -92,6 +99,14 @@ var CreateAmtRemoteTerminal = function (divid) { case ')': _termstate = 5; break; + case '=': + // Set alternate keypad mode + _termstate = 0; + break; + case '>': + // Set numeric keypad mode + _termstate = 0; + break; default: _termstate = 0; break; @@ -107,16 +122,17 @@ var CreateAmtRemoteTerminal = function (divid) { _escNumber[_escNumberPtr] = ((_escNumber[_escNumberPtr] * 10) + (b - '0')); } break; - } - else if (b == ';') { + } else if (b == ';') { // New number _escNumberPtr++; break; - } - else { + } else if (b == '?') { + _escNumberMode = 1; + break; + } else { // Process Escape Sequence if (!_escNumber[0]) _escNumber[0] = 0; - _ProcessEscapeHandler(b, _escNumber, _escNumberPtr + 1); + _ProcessEscapeHandler(b, _escNumber, _escNumberPtr + 1, _escNumberMode); _termstate = 0; } break; @@ -129,151 +145,195 @@ var CreateAmtRemoteTerminal = function (divid) { } } - function _ProcessEscapeHandler(code, args, argslen) { - var i; - switch (code) { - case 'c': // ResetDevice - // Reset - obj.TermResetScreen(); - break; - case 'A': // Move cursor up n lines - if (argslen == 1) { - _termy -= args[0]; - if (_termy < 0) _termy = 0; - } - break; - case 'B': // Move cursor down n lines - if (argslen == 1) { - _termy += args[0]; - if (_termy > obj.height) _termy = obj.height; - } - break; - case 'C': // Move cursor right n lines - if (argslen == 1) { - _termx += args[0]; - if (_termx > obj.width) _termx = obj.width; - } - break; - case 'D': // Move cursor left n lines - if (argslen == 1) { - _termx -= args[0]; - if (_termx < 0) _termx = 0; - } - break; - case 'd': // Set cursor to line n - if (argslen == 1) { - _termy = args[0] - 1; - if (_termy > obj.height) _termy = obj.height; - if (_termy < 0) _termy = 0; - } - break; - case 'G': // Set cursor to col n - if (argslen == 1) { - _termx = args[0] - 1; - if (_termx < 0) _termx = 0; - if (_termx > 79) _termx = 79; - } - break; - case 'J': // ClearScreen: - if (argslen == 1 && args[0] == 2) { - obj.TermClear((_TermCurrentBColor << 12) + (_TermCurrentFColor << 6)); // Erase entire screen - _termx = 0; - _termy = 0; - } - else if (argslen == 0 || argslen == 1 && args[0] == 0) // Erase cursor down - { - _EraseCursorToEol(); - for (i = _termy + 1; i < obj.height; i++) _EraseLine(i); - } - else if (argslen == 1 && args[0] == 1) // Erase cursor up - { - _EraseCursorToEol(); - for (i = 0; i < _termy - 1; i++) _EraseLine(i); - } - break; - case 'H': // MoveCursor: - if (argslen == 2) { - if (args[0] < 1) args[0] = 1; - if (args[1] < 1) args[1] = 1; - if (args[0] > obj.height) args[0] = obj.height; - if (args[1] > obj.width) args[1] = obj.width; - _termy = args[0] - 1; - _termx = args[1] - 1; - } - else { - _termy = 0; - _termx = 0; - } - break; - case 'm': // ScreenAttribs: - // Change attributes - for (i = 0; i < argslen; i++) { - if (!args[i] || args[i] == 0) { - // Reset Attributes - _TermCurrentBColor = 0; - _TermCurrentFColor = 7; - _TermCurrentReverse = 0; + function _ProcessEscapeHandler(code, args, argslen, mode) { + //console.log('process', code, args, mode); + if (mode == 1) { + switch (code) { + case 'l': // Hide the cursor + if (args[0] == 25) { _cursorVisible = false; } + break; + case 'h': // Show the cursor + if (args[0] == 25) { _cursorVisible = true; } + break; + } + } else if (mode == 0) { + var i; + switch (code) { + case 'c': // ResetDevice + // Reset + obj.TermResetScreen(); + break; + case 'A': // Move cursor up n lines + if (argslen == 1) { + if (args[0] == 0) { _termy--; } else { _termy -= args[0]; } + if (_termy < 0) _termy = 0; } - else if (args[i] == 1) { - // Bright - if (_TermCurrentFColor < 8) _TermCurrentFColor += 8; + break; + case 'B': // Move cursor down n lines + if (argslen == 1) { + if (args[0] == 0) { _termy++; } else { _termy += args[0]; } + if (_termy > obj.height) _termy = obj.height; } - else if (args[i] == 2 || args[i] == 22) { - // Dim - if (_TermCurrentFColor >= 8) _TermCurrentFColor -= 8; + break; + case 'C': // Move cursor right n lines + if (argslen == 1) { + if (args[0] == 0) { _termx++; } else { _termx += args[0]; } + if (_termx > obj.width) _termx = obj.width; } - else if (args[i] == 7) { - // Set Reverse attribute true - _TermCurrentReverse = 2; + break; + case 'D': // Move cursor left n lines + if (argslen == 1) { + if (args[0] == 0) { _termx--; } else { _termx -= args[0]; } + if (_termx < 0) _termx = 0; } - else if (args[i] == 27) { - // Set Reverse attribute false - _TermCurrentReverse = 0; + break; + case 'd': // Set cursor to line n + if (argslen == 1) { + _termy = args[0] - 1; + if (_termy > obj.height) _termy = obj.height; + if (_termy < 0) _termy = 0; } - else if (args[i] >= 30 && args[i] <= 37) { - // Set Foreground Color - var bright = (_TermCurrentFColor >= 8); - _TermCurrentFColor = (args[i] - 30); - if (bright && _TermCurrentFColor <= 8) _TermCurrentFColor += 8; + break; + case 'G': // Set cursor to col n + if (argslen == 1) { + _termx = args[0] - 1; + if (_termx < 0) _termx = 0; + if (_termx > 79) _termx = 79; } - else if (args[i] >= 40 && args[i] <= 47) { - // Set Background Color - _TermCurrentBColor = (args[i] - 40); + break; + case 'P': // Move the rest of the line left, this is a guess as there is no documentation about this code (???) + if (argslen == 1) { + for (i = _termx; i < (obj.width - args[0]) ; i++) { + _tscreen[_termy][i] = _tscreen[_termy][i + args[0]] + _scratt[_termy][i] = _scratt[_termy][i + args[0]]; + } } - else if (args[i] >= 90 && args[i] <= 99) { - // Set Bright Foreground Color - _TermCurrentFColor = (args[i] - 82); + break; + case 'J': // ClearScreen: + if (argslen == 1 && args[0] == 2) { + obj.TermClear((_TermCurrentBColor << 12) + (_TermCurrentFColor << 6)); // Erase entire screen + _termx = 0; + _termy = 0; } - else if (args[i] >= 100 && args[i] <= 109) { - // Set Bright Background Color - _TermCurrentBColor = (args[i] - 92); - } - } - break; - case 'K': // EraseLine: - if (argslen == 0 || (argslen == 1 && (!args[0] || args[0] == 0))) { - _EraseCursorToEol(); // Erase from the cursor to the end of the line - } - else if (argslen == 1) { - if (args[0] == 1) // Erase from the beginning of the line to the cursor + else if (argslen == 0 || argslen == 1 && args[0] == 0) // Erase cursor down { - _EraseBolToCursor(); + _EraseCursorToEol(); + for (i = _termy + 1; i < obj.height; i++) _EraseLine(i); } - else if (args[0] == 2) // Erase the line with the cursor + else if (argslen == 1 && args[0] == 1) // Erase cursor up { - _EraseLine(_termy); + _EraseCursorToEol(); + for (i = 0; i < _termy - 1; i++) _EraseLine(i); } - } - break; - case 'h': // EnableLineWrap: - _TermLineWrap = true; - break; - case 'l': // DisableLineWrap: - _TermLineWrap = false; - break; - default: - //if (code != '@') alert(code); - break; + break; + case 'H': // MoveCursor: + if (argslen == 2) { + if (args[0] < 1) args[0] = 1; + if (args[1] < 1) args[1] = 1; + if (args[0] > obj.height) args[0] = obj.height; + if (args[1] > obj.width) args[1] = obj.width; + _termy = args[0] - 1; + _termx = args[1] - 1; + } + else { + _termy = 0; + _termx = 0; + } + break; + case 'm': // ScreenAttribs: + // Change attributes + for (i = 0; i < argslen; i++) { + if (!args[i] || args[i] == 0) { + // Reset Attributes + _TermCurrentBColor = 0; + _TermCurrentFColor = 7; + _TermCurrentReverse = 0; + } + else if (args[i] == 1) { + // Bright + if (_TermCurrentFColor < 8) _TermCurrentFColor += 8; + } + else if (args[i] == 2 || args[i] == 22) { + // Dim + if (_TermCurrentFColor >= 8) _TermCurrentFColor -= 8; + } + else if (args[i] == 7) { + // Set Reverse attribute true + _TermCurrentReverse = 2; + } + else if (args[i] == 27) { + // Set Reverse attribute false + _TermCurrentReverse = 0; + } + else if (args[i] >= 30 && args[i] <= 37) { + // Set Foreground Color + var bright = (_TermCurrentFColor >= 8); + _TermCurrentFColor = (args[i] - 30); + if (bright && _TermCurrentFColor <= 8) _TermCurrentFColor += 8; + } + else if (args[i] >= 40 && args[i] <= 47) { + // Set Background Color + _TermCurrentBColor = (args[i] - 40); + } + else if (args[i] >= 90 && args[i] <= 99) { + // Set Bright Foreground Color + _TermCurrentFColor = (args[i] - 82); + } + else if (args[i] >= 100 && args[i] <= 109) { + // Set Bright Background Color + _TermCurrentBColor = (args[i] - 92); + } + } + break; + case 'K': // EraseLine: + if (argslen == 0 || (argslen == 1 && (!args[0] || args[0] == 0))) { + _EraseCursorToEol(); // Erase from the cursor to the end of the line + } + else if (argslen == 1) { + if (args[0] == 1) // Erase from the beginning of the line to the cursor + { + _EraseBolToCursor(); + } + else if (args[0] == 2) // Erase the line with the cursor + { + _EraseLine(_termy); + } + } + break; + case 'h': // EnableLineWrap: + _TermLineWrap = true; + break; + case 'l': // DisableLineWrap: + _TermLineWrap = false; + break; + case 'r': // Set the scroll region + if (argslen == 2) { _scrollRegion = [args[0] - 1, args[1] - 1]; } + break; + case 'S': // Scroll up the scroll region X lines, default 1 + var x = 1; + if (argslen == 1) { x = args[0] } + for (var y = _scrollRegion[0]; y <= _scrollRegion[1] - x; y++) { + for (var z = 0; z < obj.width; z++) { _tscreen[y][z] = _tscreen[y + x][z]; _scratt[y][z] = _scratt[y + x][z]; } + } + for (var y = _scrollRegion[1] - x + 1; y < _scrollRegion[1]; y++) { + for (var z = 0; z < obj.width; z++) { _tscreen[y][z] = ' '; _scratt[y][z] = (7 << 6); } + } + break; + case 'T': // Scroll down the scroll region X lines, default 1 + var x = 1; + if (argslen == 1) { x = args[0] } + for (var y = _scrollRegion[1]; y > _scrollRegion[0] + x; y--) { + for (var z = 0; z < obj.width; z++) { _tscreen[y][z] = _tscreen[y - x][z]; _scratt[y][z] = _scratt[y - x][z]; } + } + for (var y = _scrollRegion[0] + x; y > _scrollRegion[0]; y--) { + for (var z = 0; z < obj.width; z++) { _tscreen[y][z] = ' '; _scratt[y][z] = (7 << 6); } + } + break; + default: + //if (code != '@') alert(code); + //console.log('unknown process', code, args, mode); + break; + } } } @@ -366,6 +426,7 @@ var CreateAmtRemoteTerminal = function (divid) { function _ProcessVt100Char(c) { if (c == '\0' || c.charCodeAt() == 7) return; // Ignore null & bell var ch = c.charCodeAt(); + //console.log('_ProcessVt100Char', ch, c); // ###BEGIN###{Terminal-Enumation-All} // UTF8 Terminal @@ -401,8 +462,8 @@ var CreateAmtRemoteTerminal = function (divid) { switch (c) { case '\b': // Backspace if (_termx > 0) { - _termx = _termx - 1; - _TermDrawChar(' '); + _termx--; + if (_backSpaceErase) { _TermDrawChar(' '); } } break; case '\t': // tab @@ -411,7 +472,7 @@ var CreateAmtRemoteTerminal = function (divid) { break; case '\n': // Linefeed _termy++; - if (_termy > (obj.height - 1)) { + if (_termy > (_scrollRegion[1] - 1)) { // Move everything up one line _TermMoveUp(1); _termy = (obj.height - 1); @@ -459,7 +520,7 @@ var CreateAmtRemoteTerminal = function (divid) { } function _EraseCursorToEol() { - var t = (_TermCurrentBColor << 12); + var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse; for (var x = _termx; x < obj.width; x++) { _tscreen[_termy][x] = ' '; _scratt[_termy][x] = t; @@ -467,7 +528,7 @@ var CreateAmtRemoteTerminal = function (divid) { } function _EraseBolToCursor() { - var t = (_TermCurrentBColor << 12); + var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse; for (var x = 0; x < _termx; x++) { _tscreen[_termy][x] = ' '; _scratt[_termy][x] = t; @@ -475,7 +536,7 @@ var CreateAmtRemoteTerminal = function (divid) { } function _EraseLine(line) { - var t = (_TermCurrentBColor << 12); + var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse; for (var x = 0; x < obj.width; x++) { _tscreen[line][x] = ' '; _scratt[line][x] = t; @@ -487,11 +548,11 @@ var CreateAmtRemoteTerminal = function (divid) { function _TermMoveUp(linecount) { var x, y; - for (y = 0; y < obj.height - linecount; y++) { + for (y = _scrollRegion[0]; y <= _scrollRegion[1] - linecount; y++) { _tscreen[y] = _tscreen[y + linecount]; _scratt[y] = _scratt[y + linecount]; } - for (y = obj.height - linecount; y < obj.height; y++) { + for (y = _scrollRegion[1] - linecount + 1; y <= _scrollRegion[1]; y++) { _tscreen[y] = []; _scratt[y] = []; for (x = 0; x < obj.width; x++) { @@ -569,7 +630,7 @@ var CreateAmtRemoteTerminal = function (divid) { for (var y = 0; y < obj.height; ++y) { for (var x = 0; x < obj.width; ++x) { newat = _scratt[y][x]; - if (_termx == x && _termy == y) { newat |= _VTREVERSE; } // If this is the cursor location, reverse the color. + if (_termx == x && _termy == y && _cursorVisible) { newat |= _VTREVERSE; } // If this is the cursor location, reverse the color. if (newat != oldat) { buf += closetag; closetag = ''; @@ -584,17 +645,11 @@ var CreateAmtRemoteTerminal = function (divid) { c = _tscreen[y][x]; switch (c) { - case '&': - buf += '&'; break; - case '<': - buf += '<'; break; - case '>': - buf += '>'; break; - case ' ': - buf += ' '; break; - default: - buf += c; - break; + case '&': buf += '&'; break; + case '<': buf += '<'; break; + case '>': buf += '>'; break; + case ' ': buf += ' '; break; + default: buf += c; break; } } if (y != (obj.height - 1)) buf += '
';