1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Improved session recording support.

This commit is contained in:
Ylian Saint-Hilaire 2019-08-13 11:49:05 -07:00
parent dd92927586
commit e076883bc0
14 changed files with 123 additions and 47 deletions

File diff suppressed because one or more lines are too long

View file

@ -84,6 +84,7 @@
var recFilePtr = 0;
var recFileStartTime = 0;
var recFileLastTime = 0;
var recFileEndTime = 0;
var recFileMetadata = null;
var recFileProtocol = 0;
var agentDesktop = null;
@ -106,18 +107,24 @@
}
function readNextBlock(func) {
if ((recFilePtr + 16) > recFile.size) { func(-1); } else {
if ((recFilePtr + 16) > recFile.size) { QS('progressbar').width = '100%'; func(-1); } else {
var fr = new FileReader();
fr.onload = function () {
var type = ReadShort(this.result, 0);
var flags = ReadShort(this.result, 2);
var size = ReadInt(this.result, 4);
var time = (ReadInt(this.result, 8) << 32) + ReadInt(this.result, 12);
if ((recFilePtr + 16 + size) > recFile.size) { func(-1); } else {
if ((recFilePtr + 16 + size) > recFile.size) { QS('progressbar').width = '100%'; func(-1); } else {
var fr2 = new FileReader();
fr2.onload = function () {
recFilePtr += (16 + size);
QS('progressbar').width = Math.floor(100 * (recFilePtr / recFile.size)) + '%';
if (recFileEndTime == 0) {
// File pointer progress bar
QS('progressbar').width = Math.floor(100 * (recFilePtr / recFile.size)) + '%';
} else {
// Time progress bar
QS('progressbar').width = Math.floor(((recFileLastTime - recFileStartTime) / (recFileEndTime - recFileStartTime)) * 100) + '%';
}
func(type, flags, time, this.result);
};
fr2.readAsBinaryString(recFile.slice(recFilePtr + 16, recFilePtr + 16 + size));
@ -127,6 +134,20 @@
}
}
function readLastBlock(func) {
if (recFile.size < 32) { func(-1); } else {
var fr = new FileReader();
fr.onload = function () {
var type = ReadShort(this.result, 0);
var flags = ReadShort(this.result, 2);
var size = ReadInt(this.result, 4);
var time = (ReadInt(this.result, 8) << 32) + ReadInt(this.result, 12);
if ((type == 3) && (size == 16) && (this.result.substring(16, 32) == 'MeshCentralMCREC')) { func(type, flags, time); } else { func(-1); }
};
fr.readAsBinaryString(recFile.slice(recFile.size - 32, recFile.size));
}
}
function addInfo(name, value) { if (value == null) return ''; return addInfoNoEsc(name, EscapeHtml(value)); }
function addInfoNoEsc(name, value) {
@ -141,6 +162,7 @@
if ((recFileMetadata == null) || (recFileMetadata.magic != 'MeshCentralRelaySession') || (recFileMetadata.ver != 1)) { cleanup(); return; }
var x = '';
x += addInfo('Time', recFileMetadata.time);
if (recFileEndTime != 0) { var secs = Math.floor((recFileEndTime - time) / 1000); x += addInfo('Duration', secs + ' second' + ((secs > 1) ? 's' : '')); }
x += addInfo('Username', recFileMetadata.username);
x += addInfo('UserID', recFileMetadata.userid);
x += addInfo('SessionID', recFileMetadata.sessionid);
@ -178,6 +200,7 @@
amtDesktop = CreateAmtRemoteDesktop('Desk');
amtDesktop.onScreenSizeChange = deskAdjust;
amtDesktop.State = 3;
amtDesktop.Start();
deskAdjust();
}
QV('metadatadiv', true);
@ -213,15 +236,20 @@
}
if ((type == 2) && flagBinary && !flagUser) {
// Device --> User data
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; }
if ((readState == 0) && (rstr2hex(data) == '4100000000000000')) { readState = 1; } // We are not authenticated, KVM data starts here.
else if (readState == 1) { amtDesktop.ProcessData(data); }
//console.log(rstr2hex(data));
}
} else if ((type == 2) && flagBinary && flagUser) {
// User --> Device data
if (recFileProtocol == 101) {
// Intel AMT KVM
if (rstr2hex(data) == '0000000008080001000700070003050200000000') { amtDesktop.bpp = 1; } // Switch to 1 byte per pixel.
}
}
@ -238,6 +266,7 @@
readState = 0;
waitTimerArgs = null;
currentDeltaTimeTotalSec = 0;
recFileEndTime = 0;
if (waitTimer != null) { clearTimeout(waitTimer); waitTimer = null; }
QH('deskstatus', '');
QE('PlayButton', false);
@ -267,6 +296,7 @@
recFile = files[0];
recFilePtr = 0;
readNextBlock(processFirstBlock);
readLastBlock(function (type, flags, time) { if (type == 3) { recFileEndTime = time; } else { recFileEndTime = 0; } });
}
var dragtimer = null;
@ -309,6 +339,7 @@
recFile = files[0];
recFilePtr = 0;
readNextBlock(processFirstBlock);
readLastBlock(function (type, flags, time) { if (type == 3) { recFileEndTime = time; } else { recFileEndTime = 0; } });
Q('OpenFileButton').blur();
}
@ -358,13 +389,18 @@
QE('RestartButton', false);
QS('progressbar').width = '0px';
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; }
if (agentDesktop) {
agentDesktop.Canvas.clearRect(0, 0, agentDesktop.CanvasId.width, agentDesktop.CanvasId.height);
} else if (amtDesktop) {
amtDesktop.canvas.clearRect(0, 0, amtDesktop.CanvasId.width, amtDesktop.CanvasId.height);
amtDesktop = CreateAmtRemoteDesktop('Desk');
amtDesktop.onScreenSizeChange = deskAdjust;
amtDesktop.State = 3;
amtDesktop.Start();
}
}
function clearConsoleMsg() {
console.log('clearConsoleMsg');
}
function clearConsoleMsg() { QH('p11DeskConsoleMsg', ''); }
// Toggle the web page to full screen
function toggleAspectRatio(toggle) {
@ -404,9 +440,9 @@
} else {
var wNew = ((deskW * parentH) / deskH) + 'px';
//if (webPageFullScreen || fullscreen) {
//QS('Desk').height = null;
//QS('Desk').height = null;
//} else {
QS('Desk').height = '100%';
QS('Desk').height = '100%';
//}
QS('Desk').width = wNew;
}

View file

@ -25,6 +25,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
obj.webchannel = null;
obj.webrtc = null;
obj.debugmode = 0;
obj.serverIsRecording = false;
if (domainUrl == null) { domainUrl = '/'; }
// Console Message
@ -95,7 +96,8 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
obj.xxOnMessage = function (e) {
//console.log('Recv', e.data, e.data.byteLength, obj.State);
if (obj.State < 3) {
if (e.data == 'c') {
if ((e.data == 'c') || (e.data == 'cr')) {
if (e.data == 'cr') { obj.serverIsRecording = true; }
try { obj.socket.send(obj.protocol); } catch (ex) { }
obj.xxStateChange(3);

View file

@ -245,6 +245,11 @@ var CreateAmtRedirect = function (module, authCookie) {
if (obj.amtaccumulator.length > 8) { obj.m.ProcessData(obj.amtaccumulator.substring(8)); }
cmdsize = obj.amtaccumulator.length;
break;
case 0xF0:
// console.log('Session is being recorded');
obj.serverIsRecording = true;
cmdsize = 1;
break;
default:
console.log("Unknown Intel AMT command: " + obj.amtaccumulator.charCodeAt(0) + " acclen=" + obj.amtaccumulator.length);
obj.Stop(4);