Fixed module installation code.

This commit is contained in:
Ylian Saint-Hilaire 2019-04-05 09:21:21 -07:00
parent d4115c7aa6
commit a9b485e3c7
3 changed files with 223 additions and 164 deletions

View File

@ -66,15 +66,15 @@ function CreateMeshCentralServer(config, args) {
// Setup the default configuration and files paths // 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\\'))) { 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.datapath = obj.path.join(__dirname, '../../meshcentral-data');
obj.filespath = obj.path.join(__dirname, '../../meshcentral-files'); 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/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'); } 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 { } else {
obj.parentpath = __dirname;
obj.datapath = obj.path.join(__dirname, '../meshcentral-data'); obj.datapath = obj.path.join(__dirname, '../meshcentral-data');
obj.filespath = obj.path.join(__dirname, '../meshcentral-files'); 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/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'); } 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) { function InstallModule(modulename, func, tag1, tag2) {
console.log('Installing ' + modulename + '...'); console.log('Installing ' + modulename + '...');
var child_process = require('child_process'); 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. // 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; InstallModuleChildProcess = null;
if (error != 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'); 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');

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.3.1-u", "version": "0.3.1-w",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -4,6 +4,8 @@
* @version v0.0.2c * @version v0.0.2c
*/ */
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
// Construct a MeshServer object // Construct a MeshServer object
var CreateAmtRemoteTerminal = function (divid) { var CreateAmtRemoteTerminal = function (divid) {
var obj = {}; var obj = {};
@ -32,10 +34,14 @@ var CreateAmtRemoteTerminal = function (divid) {
var _termstate = 0; var _termstate = 0;
var _escNumber = []; var _escNumber = [];
var _escNumberPtr = 0; var _escNumberPtr = 0;
var _escNumberMode = 0;
var _scratt = []; var _scratt = [];
var _tscreen = []; var _tscreen = [];
var _VTUNDERLINE = 1; var _VTUNDERLINE = 1;
var _VTREVERSE = 2; var _VTREVERSE = 2;
var _backSpaceErase = false;
var _cursorVisible = true;
var _scrollRegion = [0, 25];
obj.Start = function () { } obj.Start = function () { }
@ -72,6 +78,9 @@ var CreateAmtRemoteTerminal = function (divid) {
switch (c) { switch (c) {
case 27: // ESC case 27: // ESC
_termstate = 1; _termstate = 1;
_escNumber = [];
_escNumberPtr = 0;
_escNumberMode = 0;
break; break;
default: default:
// Process a single char // Process a single char
@ -82,8 +91,6 @@ var CreateAmtRemoteTerminal = function (divid) {
case 1: case 1:
switch (b) { switch (b) {
case '[': case '[':
_escNumberPtr = 0;
_escNumber = [];
_termstate = 2; _termstate = 2;
break; break;
case '(': case '(':
@ -92,6 +99,14 @@ var CreateAmtRemoteTerminal = function (divid) {
case ')': case ')':
_termstate = 5; _termstate = 5;
break; break;
case '=':
// Set alternate keypad mode
_termstate = 0;
break;
case '>':
// Set numeric keypad mode
_termstate = 0;
break;
default: default:
_termstate = 0; _termstate = 0;
break; break;
@ -107,16 +122,17 @@ var CreateAmtRemoteTerminal = function (divid) {
_escNumber[_escNumberPtr] = ((_escNumber[_escNumberPtr] * 10) + (b - '0')); _escNumber[_escNumberPtr] = ((_escNumber[_escNumberPtr] * 10) + (b - '0'));
} }
break; break;
} } else if (b == ';') {
else if (b == ';') {
// New number // New number
_escNumberPtr++; _escNumberPtr++;
break; break;
} } else if (b == '?') {
else { _escNumberMode = 1;
break;
} else {
// Process Escape Sequence // Process Escape Sequence
if (!_escNumber[0]) _escNumber[0] = 0; if (!_escNumber[0]) _escNumber[0] = 0;
_ProcessEscapeHandler(b, _escNumber, _escNumberPtr + 1); _ProcessEscapeHandler(b, _escNumber, _escNumberPtr + 1, _escNumberMode);
_termstate = 0; _termstate = 0;
} }
break; break;
@ -129,7 +145,18 @@ var CreateAmtRemoteTerminal = function (divid) {
} }
} }
function _ProcessEscapeHandler(code, args, argslen) { 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; var i;
switch (code) { switch (code) {
case 'c': // ResetDevice case 'c': // ResetDevice
@ -138,25 +165,25 @@ var CreateAmtRemoteTerminal = function (divid) {
break; break;
case 'A': // Move cursor up n lines case 'A': // Move cursor up n lines
if (argslen == 1) { if (argslen == 1) {
_termy -= args[0]; if (args[0] == 0) { _termy--; } else { _termy -= args[0]; }
if (_termy < 0) _termy = 0; if (_termy < 0) _termy = 0;
} }
break; break;
case 'B': // Move cursor down n lines case 'B': // Move cursor down n lines
if (argslen == 1) { if (argslen == 1) {
_termy += args[0]; if (args[0] == 0) { _termy++; } else { _termy += args[0]; }
if (_termy > obj.height) _termy = obj.height; if (_termy > obj.height) _termy = obj.height;
} }
break; break;
case 'C': // Move cursor right n lines case 'C': // Move cursor right n lines
if (argslen == 1) { if (argslen == 1) {
_termx += args[0]; if (args[0] == 0) { _termx++; } else { _termx += args[0]; }
if (_termx > obj.width) _termx = obj.width; if (_termx > obj.width) _termx = obj.width;
} }
break; break;
case 'D': // Move cursor left n lines case 'D': // Move cursor left n lines
if (argslen == 1) { if (argslen == 1) {
_termx -= args[0]; if (args[0] == 0) { _termx--; } else { _termx -= args[0]; }
if (_termx < 0) _termx = 0; if (_termx < 0) _termx = 0;
} }
break; break;
@ -174,6 +201,14 @@ var CreateAmtRemoteTerminal = function (divid) {
if (_termx > 79) _termx = 79; if (_termx > 79) _termx = 79;
} }
break; 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]];
}
}
break;
case 'J': // ClearScreen: case 'J': // ClearScreen:
if (argslen == 1 && args[0] == 2) { if (argslen == 1 && args[0] == 2) {
obj.TermClear((_TermCurrentBColor << 12) + (_TermCurrentFColor << 6)); // Erase entire screen obj.TermClear((_TermCurrentBColor << 12) + (_TermCurrentFColor << 6)); // Erase entire screen
@ -271,11 +306,36 @@ var CreateAmtRemoteTerminal = function (divid) {
case 'l': // DisableLineWrap: case 'l': // DisableLineWrap:
_TermLineWrap = false; _TermLineWrap = false;
break; 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: default:
//if (code != '@') alert(code); //if (code != '@') alert(code);
//console.log('unknown process', code, args, mode);
break; break;
} }
} }
}
obj.ProcessVt100String = function (str) { obj.ProcessVt100String = function (str) {
for (var i = 0; i < str.length; i++) _ProcessVt100Char(String.fromCharCode(str.charCodeAt(i))); for (var i = 0; i < str.length; i++) _ProcessVt100Char(String.fromCharCode(str.charCodeAt(i)));
@ -366,6 +426,7 @@ var CreateAmtRemoteTerminal = function (divid) {
function _ProcessVt100Char(c) { function _ProcessVt100Char(c) {
if (c == '\0' || c.charCodeAt() == 7) return; // Ignore null & bell if (c == '\0' || c.charCodeAt() == 7) return; // Ignore null & bell
var ch = c.charCodeAt(); var ch = c.charCodeAt();
//console.log('_ProcessVt100Char', ch, c);
// ###BEGIN###{Terminal-Enumation-All} // ###BEGIN###{Terminal-Enumation-All}
// UTF8 Terminal // UTF8 Terminal
@ -401,8 +462,8 @@ var CreateAmtRemoteTerminal = function (divid) {
switch (c) { switch (c) {
case '\b': // Backspace case '\b': // Backspace
if (_termx > 0) { if (_termx > 0) {
_termx = _termx - 1; _termx--;
_TermDrawChar(' '); if (_backSpaceErase) { _TermDrawChar(' '); }
} }
break; break;
case '\t': // tab case '\t': // tab
@ -411,7 +472,7 @@ var CreateAmtRemoteTerminal = function (divid) {
break; break;
case '\n': // Linefeed case '\n': // Linefeed
_termy++; _termy++;
if (_termy > (obj.height - 1)) { if (_termy > (_scrollRegion[1] - 1)) {
// Move everything up one line // Move everything up one line
_TermMoveUp(1); _TermMoveUp(1);
_termy = (obj.height - 1); _termy = (obj.height - 1);
@ -459,7 +520,7 @@ var CreateAmtRemoteTerminal = function (divid) {
} }
function _EraseCursorToEol() { function _EraseCursorToEol() {
var t = (_TermCurrentBColor << 12); var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse;
for (var x = _termx; x < obj.width; x++) { for (var x = _termx; x < obj.width; x++) {
_tscreen[_termy][x] = ' '; _tscreen[_termy][x] = ' ';
_scratt[_termy][x] = t; _scratt[_termy][x] = t;
@ -467,7 +528,7 @@ var CreateAmtRemoteTerminal = function (divid) {
} }
function _EraseBolToCursor() { function _EraseBolToCursor() {
var t = (_TermCurrentBColor << 12); var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse;
for (var x = 0; x < _termx; x++) { for (var x = 0; x < _termx; x++) {
_tscreen[_termy][x] = ' '; _tscreen[_termy][x] = ' ';
_scratt[_termy][x] = t; _scratt[_termy][x] = t;
@ -475,7 +536,7 @@ var CreateAmtRemoteTerminal = function (divid) {
} }
function _EraseLine(line) { function _EraseLine(line) {
var t = (_TermCurrentBColor << 12); var t = (_TermCurrentFColor << 6) + (_TermCurrentBColor << 12) + _TermCurrentReverse;
for (var x = 0; x < obj.width; x++) { for (var x = 0; x < obj.width; x++) {
_tscreen[line][x] = ' '; _tscreen[line][x] = ' ';
_scratt[line][x] = t; _scratt[line][x] = t;
@ -487,11 +548,11 @@ var CreateAmtRemoteTerminal = function (divid) {
function _TermMoveUp(linecount) { function _TermMoveUp(linecount) {
var x, y; 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]; _tscreen[y] = _tscreen[y + linecount];
_scratt[y] = _scratt[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] = []; _tscreen[y] = [];
_scratt[y] = []; _scratt[y] = [];
for (x = 0; x < obj.width; x++) { 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 y = 0; y < obj.height; ++y) {
for (var x = 0; x < obj.width; ++x) { for (var x = 0; x < obj.width; ++x) {
newat = _scratt[y][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) { if (newat != oldat) {
buf += closetag; buf += closetag;
closetag = ''; closetag = '';
@ -584,17 +645,11 @@ var CreateAmtRemoteTerminal = function (divid) {
c = _tscreen[y][x]; c = _tscreen[y][x];
switch (c) { switch (c) {
case '&': case '&': buf += '&amp;'; break;
buf += '&amp;'; break; case '<': buf += '&lt;'; break;
case '<': case '>': buf += '&gt;'; break;
buf += '&lt;'; break; case ' ': buf += '&nbsp;'; break;
case '>': default: buf += c; break;
buf += '&gt;'; break;
case ' ':
buf += '&nbsp;'; break;
default:
buf += c;
break;
} }
} }
if (y != (obj.height - 1)) buf += '<br>'; if (y != (obj.height - 1)) buf += '<br>';