Updated all MeshAgents.

This commit is contained in:
Ylian Saint-Hilaire 2020-04-24 18:24:24 -07:00
parent 19f195b032
commit d787ee0743
26 changed files with 226 additions and 226 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,208 +0,0 @@
/*
Copyright 2019-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function trimIdentifiers(val)
{
for(var v in val)
{
if (!val[v] || val[v] == 'None' || val[v] == '') { delete val[v]; }
}
}
function linux_identifiers()
{
var identifiers = {};
var ret = {};
var values = {};
if (!require('fs').existsSync('/sys/class/dmi/id')) { throw ('this platform does not have DMI statistics'); }
var entries = require('fs').readdirSync('/sys/class/dmi/id');
for(var i in entries)
{
if (require('fs').statSync('/sys/class/dmi/id/' + entries[i]).isFile())
{
ret[entries[i]] = require('fs').readFileSync('/sys/class/dmi/id/' + entries[i]).toString().trim();
if (ret[entries[i]] == 'None') { delete ret[entries[i]];}
}
}
identifiers['bios_date'] = ret['bios_date'];
identifiers['bios_vendor'] = ret['bios_vendor'];
identifiers['bios_version'] = ret['bios_version'];
identifiers['board_name'] = ret['board_name'];
identifiers['board_serial'] = ret['board_serial'];
identifiers['board_vendor'] = ret['board_vendor'];
identifiers['board_version'] = ret['board_version'];
identifiers['product_uuid'] = ret['product_uuid'];
values.identifiers = identifiers;
values.linux = ret;
trimIdentifiers(values.identifiers);
return (values);
}
function windows_wmic_results(str)
{
var lines = str.trim().split('\r\n');
var keys = lines[0].split(',');
var i, key, keyval;
var tokens;
var result = [];
for (i = 1; i < lines.length; ++i)
{
var obj = {};
tokens = lines[i].split(',');
for (key = 0; key < keys.length; ++key)
{
if (tokens[key].trim())
{
obj[keys[key].trim()] = tokens[key].trim();
}
}
result.push(obj);
}
return (result);
}
function windows_identifiers()
{
var ret = { windows: {}}; values = {}; var items; var i; var item;
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'bios', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
for(i in items)
{
item = items[i].split('=');
values[item[0]] = item[1];
}
ret['identifiers'] = {};
ret['identifiers']['bios_date'] = values['ReleaseDate'];
ret['identifiers']['bios_vendor'] = values['Manufacturer'];
ret['identifiers']['bios_version'] = values['SMBIOSBIOSVersion'];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'BASEBOARD', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
for (i in items)
{
item = items[i].split('=');
values[item[0]] = item[1];
}
ret['identifiers']['board_name'] = values['Product'];
ret['identifiers']['board_serial'] = values['SerialNumber'];
ret['identifiers']['board_vendor'] = values['Manufacturer'];
ret['identifiers']['board_version'] = values['Version'];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'CSProduct', 'get', '/VALUE']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
var items = child.stdout.str.split('\r\r\n');
for (i in items)
{
item = items[i].split('=');
values[item[0]] = item[1];
}
ret['identifiers']['product_uuid'] = values['UUID'];
trimIdentifiers(ret.identifiers);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'MEMORYCHIP', 'LIST', '/FORMAT:CSV']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
ret.windows.memory = windows_wmic_results(child.stdout.str);
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'OS', 'GET', '/FORMAT:CSV']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
ret.windows.osinfo = windows_wmic_results(child.stdout.str)[0];
child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'PARTITION', 'LIST', '/FORMAT:CSV']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.waitExit();
ret.windows.partitions = windows_wmic_results(child.stdout.str);
return (ret);
}
function macos_identifiers()
{
var ret = { identifiers: {} };
var child;
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep board-id | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');
child.waitExit();
ret.identifiers.board_name = child.stdout.str.trim();
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep IOPlatformSerialNumber | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');
child.waitExit();
ret.identifiers.board_serial = child.stdout.str.trim();
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep manufacturer | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');
child.waitExit();
ret.identifiers.board_vendor = child.stdout.str.trim();
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep version | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');
child.waitExit();
ret.identifiers.board_version = child.stdout.str.trim();
child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('ioreg -d2 -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F= \'{ split($2, res, "\\""); print res[2]; }\'\nexit\n');
child.waitExit();
ret.identifiers.product_uuid = child.stdout.str.trim();
trimIdentifiers(ret.identifiers);
return (ret);
}
switch(process.platform)
{
case 'linux':
module.exports = { _ObjectID: 'identifiers', get: linux_identifiers };
break;
case 'win32':
module.exports = { _ObjectID: 'identifiers', get: windows_identifiers };
break;
case 'darwin':
module.exports = { _ObjectID: 'identifiers', get: macos_identifiers };
break;
default:
module.exports = { get: function () { throw ('Unsupported Platform'); } };
break;
}
// bios_date = BIOS->ReleaseDate
// bios_vendor = BIOS->Manufacturer
// bios_version = BIOS->SMBIOSBIOSVersion
// board_name = BASEBOARD->Product = ioreg/board-id
// board_serial = BASEBOARD->SerialNumber = ioreg/serial-number | ioreg/IOPlatformSerialNumber
// board_vendor = BASEBOARD->Manufacturer = ioreg/manufacturer
// board_version = BASEBOARD->Version

View File

@ -13,8 +13,54 @@
/*jshint esversion: 6 */
"use strict";
/*
--- KVM Commands ---
MNG_KVM_NOP = 0,
MNG_KVM_KEY = 1,
MNG_KVM_MOUSE = 2,
MNG_KVM_MOUSE_CURSOR = 88,
MNG_KVM_MOUSE_MOVE = 89,
MNG_KVM_PICTURE = 3,
MNG_KVM_COPY = 4,
MNG_KVM_COMPRESSION = 5,
MNG_KVM_REFRESH = 6,
MNG_KVM_SCREEN = 7,
MNG_KVM_PAUSE = 8,
MNG_TERMTEXT = 9,
MNG_CTRLALTDEL = 10,
MNG_KVM_GET_DISPLAYS = 11,
MNG_KVM_SET_DISPLAY = 12,
MNG_KVM_FRAME_RATE_TIMER = 13,
MNG_KVM_INIT_TOUCH = 14,
MNG_KVM_TOUCH = 15,
MNG_KVM_CONNECTCOUNT = 16,
MNG_KVM_MESSAGE = 17,
MNG_ECHO = 21,
MNG_JUMBO = 27,
MNG_GETDIR = 50,
MNG_FILEMOVE = 51,
MNG_FILEDELETE = 52,
MNG_FILECOPY = 53,
MNG_FILECREATEDIR = 54,
MNG_FILETRANSFER = 55,
MNG_FILEUPLOAD = 56,
MNG_FILESEARCH = 57,
MNG_FILETRANSFER2 = 58,
MNG_KVM_DISCONNECT = 59,
MNG_GETDIR2 = 60, // Same as MNG_GETDIR but with date/time.
MNG_FILEUPLOAD2 = 61, // Used for slot based fast upload.
MNG_FILEDELETEREC = 62, // Same as MNG_FILEDELETE but recursive
MNG_USERCONSENT = 63, // Used to notify management console of user consent state
MNG_DEBUG = 64, // Debug/Logging Message for ILibRemoteLogging
MNG_ERROR = 65,
MNG_ENCAPSULATE_AGENT_COMMAND = 70
*/
function CreateDesktopDecoder() {
var obj = {};
obj.agent = null;
obj.viewers = [];
obj.width = 0;
obj.height = 0;
obj.swidth = 0;
@ -28,9 +74,139 @@ function CreateDesktopDecoder() {
obj.lastScreenSizeCounter = 0;
obj.firstData = null;
obj.lastData = null;
obj.lastDisplayInfoData = null;
obj.desktopPaused = true;
obj.imageCompression = 50;
obj.imageScaling = 1024;
obj.imageFrameRate = 50;
obj.addPeer = function (peer) {
if (peer.req.query.browser) {
console.log('addPeer-viewer');
// This is a viewer
if (obj.viewers.indexOf(peer) >= 0) return true;
obj.viewers.push(peer);
// Setup the viewer
peer.desktopPaused = true;
peer.imageCompression = 30;
peer.imageScaling = 1024;
peer.imageFrameRate = 100;
peer.dataPtr = obj.firstData;
} else {
console.log('addPeer-agent');
if (obj.agent != null) return false;
// This is the agent
obj.agent = peer;
// Setup the agent
}
return true;
}
obj.removePeer = function (peer) {
if (peer == agent) {
console.log('removePeer-agent');
// Clean up the agent
// Agent has disconnected, disconnect everyone.
} else {
console.log('removePeer-viewer');
// Remove a viewer
var i = obj.viewers.indexOf(peer);
if (i == -1) return false;
obj.viewers.splice(i, 1);
// Clean up the viewer
}
return true;
}
// Process data coming from the agent or any viewers
obj.processData = function (peer, data) {
if (peer == obj.agent) { obj.processAgentData(data); } else { obj.processViewerData(peer, data); }
}
// Process incoming viewer data
obj.processViewerData = function (viewer, data) {
//console.log('ViewerData', data.length);
if ((typeof data != 'object') || (data.length < 4)) return; // Ignore all control traffic for now (WebRTC)
var command = data.readUInt16BE(0);
var cmdsize = data.readUInt16BE(2);
switch (command) {
case 1:// Key Events, forward to agent
//console.log('Viewer-Keys');
break;
case 2:// Mouse events, forward to agent
//console.log('Viewer-Mouse');
break;
case 5:// Compression
if (data.length < 10) return;
//viewer.imageType = data[4]; // Always 1=JPEG
viewer.imageCompression = data[5];
viewer.imageScaling = data.readUInt16BE(6);
viewer.imageFrameRate = data.readUInt16BE(8);
//console.log('Viewer-Compression', viewer.imageCompression, viewer.imageScaling, viewer.imageFrameRate);
// See if this changes anything
var viewersimageCompression = null;
var viewersimageScaling = null;
var viewersimageFrameRate = null;
for (var i in obj.viewers) {
if ((viewersimageCompression == null) || (obj.viewers[i].imageCompression > viewersimageCompression)) { viewersimageCompression = obj.viewers[i].imageCompression; };
if ((viewersimageScaling == null) || (obj.viewers[i].imageScaling > viewersimageScaling)) { viewersimageScaling = obj.viewers[i].imageScaling; };
if ((viewersimageFrameRate == null) || (obj.viewers[i].imageFrameRate < viewersimageFrameRate)) { viewersimageFrameRate = obj.viewers[i].imageFrameRate; };
}
if ((obj.imageCompression != viewersimageCompression) || (obj.imageScaling != viewersimageScaling) || (obj.imageFrameRate != viewersimageFrameRate)) {
// Update and send to agent new compression settings
obj.imageCompression = viewersimageCompression;
obj.imageScaling = viewersimageScaling;
obj.imageFrameRate = viewersimageFrameRate
console.log('Send-Agent-Compression', obj.imageCompression, obj.imageScaling, obj.imageFrameRate);
// obj.send(String.fromCharCode(0x00, 0x05, 0x00, 0x0A, type, obj.CompressionLevel) + obj.shortToStr(obj.ScalingLevel) + obj.shortToStr(obj.FrameRateTimer));
}
break;
case 6:// Refresh, handle this on the server
console.log('Viewer-Refresh');
viewer.dataPtr = obj.firstData; // Start over
// TODO
break;
case 8:// Pause and unpause
if (data.length != 5) break;
var pause = data[4]; // 0 = Unpause, 1 = Pause
if (viewer.desktopPaused == (pause == 1)) break;
viewer.desktopPaused = (pause == 1);
//console.log('Viewer-' + ((pause == 1)?'Pause':'UnPause'));
var viewersPaused = true;
for (var i in obj.viewers) { if (obj.viewers[i].desktopPaused == false) { viewersPaused = false; }; }
if (viewersPaused != obj.desktopPaused) {
obj.desktopPaused = viewersPaused;
console.log('Send-Agent-' + ((viewersPaused == 1)?'Pause':'UnPause'));
// TODO
}
if (viewer.desktopPaused == false) {
viewer.dataPtr = obj.firstData; // Start over
// TODO
}
break;
case 10:// CTRL-ALT-DEL, forward to agent
break;
case 14:// Touch setup
break;
default:
console.log('Un-handled viewer command: ' + command);
break;
}
}
// Process incoming agent data
obj.processAgentData = function (data) {
if ((typeof data != 'object') || (data.length < 4)) return;
//console.log('AgentData', data.length);
if ((typeof data != 'object') || (data.length < 4)) return; // Ignore all control traffic for now (WebRTC)
var command = data.readUInt16BE(0);
var cmdsize = data.readUInt16BE(2);
if ((command == 27) && (cmdsize == 8)) {
@ -89,6 +265,8 @@ function CreateDesktopDecoder() {
//console.log('list', xx);
//console.log('images', obj.imagesCount);
break;
case 4: // Tile Copy, do nothing.
break;
case 7: // Screen Size, clear the screen state and compute the tile count
obj.counter++;
@ -111,13 +289,45 @@ function CreateDesktopDecoder() {
obj.lastData = obj.counter;
// Add viewers must be set to start at "obj.counter"
// TODO
for (var i in obj.viewers) {
obj.viewers[i].dataPtr = obj.counter;
// TODO
}
//console.log("ScreenSize", obj.width, obj.height, obj.swidth, obj.sheight, obj.swidth * obj.sheight);
break;
case 11: // GetDisplays
// Store and send this to all viewers right away
obj.lastDisplayInfoData = data;
// TODO
break;
case 14: // KVM_INIT_TOUCH
break;
case 15: // KVM_TOUCH
break;
case 16: // MNG_KVM_CONNECTCOUNT
break;
case 17: // MNG_KVM_MESSAGE
// Send this to all viewers right away
// TODO
break;
case 65: // Alert
// Send this to all viewers right away
// TODO
break;
case 88: // MNG_KVM_MOUSE_CURSOR
// Send this to all viewers right away
// TODO
break;
default:
// 11, 14, 88
console.log('Un-handled command: ' + command);
console.log('Un-handled agent command: ' + command);
break;
}
}
@ -323,10 +533,9 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
else if ((typeof parent.parent.args.agentpong == 'number') && (obj.pongtimer == null)) { obj.pongtimer = setInterval(sendPong, parent.parent.args.agentpong * 1000); }
// Setup the desktop decoder
var agentPeer = null;
if (obj.req.query.browser == null) { agentPeer = obj; }
else if (obj.peer.req.query.browser == null) { agentPeer = obj.peer; }
if (agentPeer != null) { agentPeer.deskDecoder = CreateDesktopDecoder(); }
obj.deskDecoder = obj.peer.deskDecoder = CreateDesktopDecoder();
obj.deskDecoder.addPeer(obj);
obj.deskDecoder.addPeer(obj.peer);
// Setup session recording
var sessionUser = obj.user;
@ -425,7 +634,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
// When data is received from the mesh relay web socket
ws.on('message', function (data) {
// If this data was received by the agent, decode it.
if (this.me.deskDecoder != null) { this.me.deskDecoder.processAgentData(data); }
if (this.me.deskDecoder != null) { this.me.deskDecoder.processData(this.me, data); }
//console.log(typeof data, data.length);
if (this.peer != null) {

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.5.13",
"version": "0.5.14",
"keywords": [
"Remote Management",
"Intel AMT",
@ -40,7 +40,6 @@
"express-handlebars": "^3.1.0",
"express-ws": "^4.0.0",
"ipcheck": "^0.1.0",
"minify-js": "0.0.4",
"minimist": "^1.2.0",
"multiparty": "^4.2.1",
"nedb": "^1.8.0",

View File

@ -39,7 +39,7 @@ var CreateAgentRemoteDesktop = function (canvasid, scrolldiv) {
obj.oldie = false;
obj.CompressionLevel = 50;
obj.ScalingLevel = 1024;
obj.FrameRateTimer = 50;
obj.FrameRateTimer = 100;
obj.FirstDraw = false;
obj.ScreenWidth = 960;

View File

@ -29810,4 +29810,4 @@
]
}
]
}
}

View File

@ -1150,7 +1150,7 @@
// Process server-side web state
var webState = '{{{webstate}}}';
if (webState != '') { webState = JSON.parse(decodeURIComponent(webState)); }
for (var i in webState) { localStorage.setItem(i, webState[i]); }
for (var i in webState) { if (i != 'desktopsettings') { localStorage.setItem(i, webState[i]); } }
if (!webState.loctag) { try { delete localStorage.removeItem('loctag'); } catch (ex) { } }
var args, urlargs;
@ -3404,7 +3404,7 @@
QV('d7meshkvm', true);
d7bitmapquality.value = multidesktopsettings.quality;
d7bitmapscaling.value = multidesktopsettings.scaling;
if (multidesktopsettings.framerate) { d7framelimiter.value = multidesktopsettings.framerate; } else { d7framelimiter.value = 1000; }
if (multidesktopsettings.framerate) { d7framelimiter.value = multidesktopsettings.framerate; } else { d7framelimiter.value = 100; }
setDialogMode(7, "Remote Desktop Settings", 3, showMultiDesktopSettingsChanged);
}
@ -3447,7 +3447,7 @@
//desk.onConsoleMessageChange = function () { console.log('CONSOLEMSG:', desk.consoleMessage); }
desk.m.CompressionLevel = multidesktopsettings.quality;
desk.m.ScalingLevel = multidesktopsettings.scaling;
desk.m.FrameRateTimer = multidesktopsettings.framerate;
if (multidesktopsettings.framerate) { desk.m.FrameRateTimer = multidesktopsettings.framerate; }
//desk.m.onDisplayinfo = deskDisplayInfo;
//desk.m.onScreenSizeChange = deskAdjust;
if (debugmode > 0) { desk.m.onScreenSizeChange = mdeskAdjust; } // Multi-Desktop Adjust
@ -5931,7 +5931,7 @@
}
desktop.m.CompressionLevel = desktopsettings.quality; // Number from 1 to 100. 50 or less is best.
desktop.m.ScalingLevel = desktopsettings.scaling;
desktop.m.FrameRateTimer = desktopsettings.framerate;
if (desktopsettings.framerate) { desktop.m.FrameRateTimer = desktopsettings.framerate; }
desktop.m.onDisplayinfo = deskDisplayInfo;
desktop.m.onScreenSizeChange = deskAdjust;
desktop.Start(desktopNode._id);
@ -6077,7 +6077,7 @@
d7bitmapquality.value = 40; // Default value
if (ops.indexOf(parseInt(desktopsettings.quality)) >= 0) { d7bitmapquality.value = desktopsettings.quality; }
d7bitmapscaling.value = desktopsettings.scaling;
if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; }
if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; } else { d7framelimiter.value = 100; }
if (desktopsettings.localkeymap) { d7localKeyMap.checked = desktopsettings.localkeymap; }
QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (desktop.state != 0) && (desktopsettings.showfocus));
}