From dd92927586295d2af780d56ef70fc17b32d22cd0 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 12 Aug 2019 16:16:52 -0700 Subject: [PATCH] MeshPlayer improvements. --- MeshCentralServer.njsproj | 1 + meshcentral.js | 2 +- multiserver.js | 1 + public/player.htm | 66 +++++++++++++++++++++-------- public/scripts/amt-desktop-0.0.2.js | 8 ++-- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/MeshCentralServer.njsproj b/MeshCentralServer.njsproj index 3c791b13..a13f4527 100644 --- a/MeshCentralServer.njsproj +++ b/MeshCentralServer.njsproj @@ -219,6 +219,7 @@ + diff --git a/meshcentral.js b/meshcentral.js index ccbe61ee..4bc4e648 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -108,7 +108,7 @@ function CreateMeshCentralServer(config, args) { try { require('./pass').hash('test', function () { }, 0); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not. // Check for invalid arguments - var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'memorytracking']; + var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'shownodes', 'showmeshes', 'showevents', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpsdebug', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'swarmdebug', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'memorytracking', 'serverid']; for (var arg in obj.args) { obj.args[arg.toLocaleLowerCase()] = obj.args[arg]; if (validArguments.indexOf(arg.toLocaleLowerCase()) == -1) { console.log('Invalid argument "' + arg + '", use --help.'); return; } } if (obj.args.mongodb == true) { console.log('Must specify: --mongodb [connectionstring] \r\nSee https://docs.mongodb.com/manual/reference/connection-string/ for MongoDB connection string.'); return; } for (i in obj.config.settings) { obj.args[i] = obj.config.settings[i]; } // Place all settings into arguments, arguments have already been placed into settings so arguments take precedence. diff --git a/multiserver.js b/multiserver.js index 70b23587..40c52297 100644 --- a/multiserver.js +++ b/multiserver.js @@ -384,6 +384,7 @@ module.exports.CreateMultiServer = function (parent, args) { if (obj.peerConfig == null) { return null; } obj.serverid = obj.parent.config.peers.serverid; if (obj.serverid == null) { obj.serverid = require("os").hostname().toLowerCase(); } else { obj.serverid = obj.serverid.toLowerCase(); } + if (args.serverid != null) { obj.serverid = args.serverid.toLowerCase(); } if (obj.parent.config.peers.servers[obj.serverid] == null) { console.log("Error: Unable to peer with other servers, \"" + obj.serverid + "\" not present in peer servers list."); return null; } //console.log('Server peering ID: ' + obj.serverid); diff --git a/public/player.htm b/public/player.htm index 1507bace..c012641c 100644 --- a/public/player.htm +++ b/public/player.htm @@ -10,6 +10,10 @@ + + + +
@@ -83,6 +87,7 @@ var recFileMetadata = null; var recFileProtocol = 0; var agentDesktop = null; + var amtDesktop = null; var playing = false; var readState = 0; var waitTimer = null; @@ -162,6 +167,19 @@ agentDesktop.State = 3; deskAdjust(); } + else if (recFileMetadata.protocol == 101) { + // Intel AMT Redirection + recFileProtocol = 101; + x += '

Press [space] to play/pause.'; + QE('PlayButton', true); + QE('PauseButton', false); + QE('RestartButton', false); + recFileStartTime = recFileLastTime = time; + amtDesktop = CreateAmtRemoteDesktop('Desk'); + amtDesktop.onScreenSizeChange = deskAdjust; + amtDesktop.State = 3; + deskAdjust(); + } QV('metadatadiv', true); QH('metadatadiv', x); QH('deskstatus', recFile.name); @@ -181,19 +199,32 @@ function processBlockEx(type, flags, time, data) { if (playing == false) return; var flagBinary = (flags & 1) != 0, flagUser = (flags & 2) != 0; - if ((type == 2) && flagBinary && !flagUser) { - var deltaTimeTotalSec = Math.floor((time - recFileStartTime) / 1000); - if (currentDeltaTimeTotalSec != deltaTimeTotalSec) { - currentDeltaTimeTotalSec = deltaTimeTotalSec; - var deltaTimeHours = Math.floor(deltaTimeTotalSec / 3600); - deltaTimeTotalSec -= (deltaTimeHours * 3600) - var deltaTimeMinutes = Math.floor(deltaTimeTotalSec / 60); - deltaTimeTotalSec -= (deltaTimeHours * 60) - var deltaTimeSeconds = Math.floor(deltaTimeTotalSec); - QH('timespan', pad2(deltaTimeHours) + ':' + pad2(deltaTimeMinutes) + ':' + pad2(deltaTimeSeconds)) - } - agentDesktop.ProcessData(data); + + // Update the clock + var deltaTimeTotalSec = Math.floor((time - recFileStartTime) / 1000); + if (currentDeltaTimeTotalSec != deltaTimeTotalSec) { + currentDeltaTimeTotalSec = deltaTimeTotalSec; + var deltaTimeHours = Math.floor(deltaTimeTotalSec / 3600); + deltaTimeTotalSec -= (deltaTimeHours * 3600) + var deltaTimeMinutes = Math.floor(deltaTimeTotalSec / 60); + deltaTimeTotalSec -= (deltaTimeHours * 60) + var deltaTimeSeconds = Math.floor(deltaTimeTotalSec); + QH('timespan', pad2(deltaTimeHours) + ':' + pad2(deltaTimeMinutes) + ':' + pad2(deltaTimeSeconds)) } + + if ((type == 2) && flagBinary && !flagUser) { + if (recFileProtocol == 2) { + // MeshCentral Remote Desktop + agentDesktop.ProcessData(data); + } else if (recFileProtocol == 101) { + // Intel AMT KVM + //if ((readState == 0) && (rstr2hex(data) == '140000000400000000')) { readState = 1; } + if ((readState == 0) && (rstr2hex(data) == '4100000000000000')) { readState = 1; } + else if (readState == 1) { amtDesktop.ProcessData(data); } + //console.log(rstr2hex(data)); + } + } + recFileLastTime = time; if (playing) { readNextBlock(processBlock); } } @@ -202,10 +233,8 @@ recFile = null; recFilePtr = 0; recFileMetadata = null; - if (agentDesktop != null) { - agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height); - agentDesktop = null; - } + if (agentDesktop != null) { agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height); agentDesktop = null; } + if (amtDesktop != null) { amtDesktop.canvas.clearRect(0, 0, amtDesktop.CanvasId.width, amtDesktop.CanvasId.height); amtDesktop = null; } readState = 0; waitTimerArgs = null; currentDeltaTimeTotalSec = 0; @@ -328,8 +357,9 @@ QE('PauseButton', false); QE('RestartButton', false); QS('progressbar').width = '0px'; - QH('timespan', '00:00:00') - agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height); + QH('timespan', '00:00:00'); + if (agentDesktop) { agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height); } + if (amtDesktop) { amtDesktop.canvas.clearRect(0, 0, amtDesktop.CanvasId.width, amtDesktop.CanvasId.height); amtDesktop = CreateAmtRemoteDesktop('Desk'); amtDesktop.onScreenSizeChange = deskAdjust; amtDesktop.State = 3; } } function clearConsoleMsg() { diff --git a/public/scripts/amt-desktop-0.0.2.js b/public/scripts/amt-desktop-0.0.2.js index 6b639936..7f28fd8d 100644 --- a/public/scripts/amt-desktop-0.0.2.js +++ b/public/scripts/amt-desktop-0.0.2.js @@ -78,7 +78,7 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) { obj.ProcessData = function (data) { if (!data) return; - // obj.Debug("KRecv(" + data.length + "): " + rstr2hex(data)); + //obj.Debug("KRecv(" + data.length + "): " + rstr2hex(data)); //obj.inbytes += data.length; //obj.Debug("KRecv(" + obj.inbytes + ")"); obj.acc += data; @@ -159,7 +159,7 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) { if (obj.bpp == 1) obj.send(String.fromCharCode(0, 0, 0, 0, 8, 8, 0, 1) + ShortToStr(7) + ShortToStr(7) + ShortToStr(3) + String.fromCharCode(5, 2, 0, 0, 0, 0)); // Setup 8 bit color RGB332 obj.state = 4; - obj.parent.xxStateChange(3); + if (obj.parent) { obj.parent.xxStateChange(3); } _SendRefresh(); //obj.timer = setInterval(obj.xxOnTimer, 50); @@ -602,13 +602,13 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) { obj.Stop = function () { obj.UnGrabMouseInput(); obj.UnGrabKeyInput(); - obj.parent.Stop(); + if (obj.parent) { obj.parent.Stop(); } } obj.send = function (x) { //obj.Debug("KSend(" + x.length + "): " + rstr2hex(x)); //obj.outbytes += x.length; - obj.parent.send(x); + if (obj.parent) { obj.parent.send(x); } } var convertAmtKeyCodeTable = {