Many fixes with desktop recording indexor and player.

Ylian Saint-Hilaire committed Mar 3, 2020 at 16:22 UTC 421a6349d5377e5e381b9c05960e763592c7677b
4 files changed +49 -44
mcrec.js
+22 -22
@@ -113,13 +113,13 @@ function processBlock(state, block, err) {
113 // MeshCentral Remote Desktop
114 // TODO
115 if (block.data.length >= 4) {
116 - var command = block.data.readInt16BE(0);
117 - var cmdsize = block.data.readInt16BE(2);
116 + var command = block.data.readUInt16BE(0);
117 + var cmdsize = block.data.readUInt16BE(2);
118 if ((command == 27) && (cmdsize == 8)) {
119 // Jumbo packet
120 if (block.data.length >= 12) {
121 - command = block.data.readInt16BE(8);
122 - cmdsize = block.data.readInt32BE(4);
121 + command = block.data.readUInt16BE(8);
122 + cmdsize = block.data.readUInt32BE(4);
123 if (block.data.length == (cmdsize + 8)) {
124 block.data = block.data.slice(8, block.data.length);
125 } else {
@@ -131,8 +131,8 @@ function processBlock(state, block, err) {
131
132 switch (command) {
133 case 3: // Tile
134 - var x = block.data.readInt16BE(4);
135 - var y = block.data.readInt16BE(6);
134 + var x = block.data.readUInt16BE(4);
135 + var y = block.data.readUInt16BE(6);
136 var dimensions = require('image-size')(block.data.slice(8));
137 //log("Tile", x, y, dimensions.width, dimensions.height, block.ptr);
138 //console.log(elapseSeconds);
@@ -148,13 +148,13 @@ function processBlock(state, block, err) {
148
149 break;
150 case 4: // Tile copy
151 - var x = block.data.readInt16BE(4);
152 - var y = block.data.readInt16BE(6);
151 + var x = block.data.readUInt16BE(4);
152 + var y = block.data.readUInt16BE(6);
153 //log("TileCopy", x, y);
154 break;
155 case 7: // Screen Size, clear the screen state and computer the tile count
156 - state.width = block.data.readInt16BE(4);
157 - state.height = block.data.readInt16BE(6);
156 + state.width = block.data.readUInt16BE(4);
157 + state.height = block.data.readUInt16BE(6);
158 state.swidth = state.width / 16;
159 state.sheight = state.height / 16;
160 if (Math.floor(state.swidth) != state.swidth) { state.swidth = Math.floor(state.swidth) + 1; }
@@ -232,20 +232,20 @@ function recordingEntry(fd, type, flags, time, data, func, tag, position) {
232 function readLastBlock(state, func) {
233 var buf = Buffer.alloc(32);
234 fs.read(state.recFile, buf, 0, 32, state.recFileSize - 32, function (err, bytesRead, buf) {
235 - var type = buf.readInt16BE(0);
236 - var flags = buf.readInt16BE(2);
237 - var size = buf.readInt32BE(4);
238 - var time = (buf.readInt32BE(8) << 32) + buf.readInt32BE(12);
235 + var type = buf.readUInt16BE(0);
236 + var flags = buf.readUInt16BE(2);
237 + var size = buf.readUInt32BE(4);
238 + var time = (buf.readUInt32BE(8) << 32) + buf.readUInt32BE(12);
239 var magic = buf.toString('utf8', 16, 32);
240 if ((type == 3) && (size == 16) && (magic == 'MeshCentralMCNDX')) {
241 // Extra metadata present, lets read it.
242 extraMetadata = null;
243 var buf2 = Buffer.alloc(16);
244 fs.read(state.recFile, buf2, 0, 16, time, function (err, bytesRead, buf2) {
245 - var xtype = buf2.readInt16BE(0);
246 - var xflags = buf2.readInt16BE(2);
247 - var xsize = buf2.readInt32BE(4);
248 - var xtime = (buf2.readInt32BE(8) << 32) + buf.readInt32BE(12);
245 + var xtype = buf2.readUInt16BE(0);
246 + var xflags = buf2.readUInt16BE(2);
247 + var xsize = buf2.readUInt32BE(4);
248 + var xtime = (buf2.readUInt32BE(8) << 32) + buf.readUInt32BE(12);
249 var buf3 = Buffer.alloc(xsize);
250 fs.read(state.recFile, buf3, 0, xsize, time + 16, function (err, bytesRead, buf3) {
251 func(state, true, xtime, JSON.parse(buf3.toString()));
@@ -263,10 +263,10 @@ function readNextBlock(state, func) {
263 var r = {}, buf = Buffer.alloc(16);
264 fs.read(state.recFile, buf, 0, 16, state.recFilePtr, function (err, bytesRead, buf) {
265 if (bytesRead != 16) { func(state, null, true); return; } // Error
266 - r.type = buf.readInt16BE(0);
267 - r.flags = buf.readInt16BE(2);
268 - r.size = buf.readInt32BE(4);
269 - r.time = buf.readIntBE(8, 8);
266 + r.type = buf.readUInt16BE(0);
267 + r.flags = buf.readUInt16BE(2);
268 + r.size = buf.readUInt32BE(4);
269 + r.time = buf.readUIntBE(8, 8);
270 r.date = new Date(r.time);
271 r.ptr = state.recFilePtr;
272 if ((state.recFilePtr + 16 + r.size) > state.recFileSize) { func(state, null, true); return; } // Error
meshrelay.js
+13 -11
@@ -330,17 +330,6 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
330 if (relayinfo.state == 2) {
331 var peer = (relayinfo.peer1 == obj) ? relayinfo.peer2 : relayinfo.peer1;
332
333 - // Close the recording file
334 - if (ws.logfile != null) {
335 - recordingEntry(ws.logfile.fd, 3, 0, 'MeshCentralMCREC', function (fd, tag) {
336 - parent.parent.fs.close(fd);
337 - tag.ws.logfile = null;
338 - tag.pws.logfile = null;
339 - // Now that the recording file is closed, check if we need to index this file.
340 - if (domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); }
341 - }, { ws: ws, pws: peer.ws, logfile: ws.logfile });
342 - }
343 -
333 // Disconnect the peer
334 try { if (peer.relaySessionCounted) { parent.relaySessionCount--; delete peer.relaySessionCounted; } } catch (ex) { console.log(ex); }
335 parent.parent.debug('relay', 'Relay disconnect: ' + obj.id + ' (' + cleanRemoteAddr(obj.req.ip) + ' --> ' + cleanRemoteAddr(peer.req.ip) + ')');
@@ -369,6 +358,19 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
358 } else {
359 parent.parent.debug('relay', 'Relay disconnect: ' + obj.id + ' (' + cleanRemoteAddr(obj.req.ip) + ')');
360 }
361 +
362 + // Close the recording file if needed
363 + if (ws.logfile != null) {
364 + var logfile = ws.logfile;
365 + delete ws.logfile;
366 + if (peer.ws) { delete peer.ws.logfile; }
367 + recordingEntry(logfile.fd, 3, 0, 'MeshCentralMCREC', function (fd, tag) {
368 + parent.parent.fs.close(fd);
369 + // Now that the recording file is closed, check if we need to index this file.
370 + if (domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); }
371 + }, { ws: ws, pws: peer.ws, logfile: logfile });
372 + }
373 +
374 try { ws.close(); } catch (ex) { }
375 delete parent.wsrelays[obj.id];
376 }
redirserver.js
+2 -1
@@ -113,7 +113,8 @@ module.exports.CreateRedirServer = function (parent, db, args, func) {
113 if (parent.config.domains[i].dns != null) { continue; }
114 var url = parent.config.domains[i].url;
115 obj.app.get(url, performRedirection); // Root redirection
116 - obj.app.use(url + "clickonce", obj.express.static(obj.parent.path.join(__dirname, "public/clickonce"))); // Indicates the clickonce folder is public
116 + obj.app.get(url + 'player.htm', performRedirection); // Player redirection
117 + obj.app.use(url + 'clickonce', obj.express.static(obj.parent.path.join(__dirname, "public/clickonce"))); // Indicates the clickonce folder is public
118
119 // Setup all of the redirections to HTTPS
120 const redirections = ['terms', 'logout', 'MeshServerRootCert.cer', 'mescript.ashx', 'checkmail', 'agentinvite', 'messenger', 'meshosxagent', 'devicepowerevents.ashx', 'downloadfile.ashx', 'userfiles/*', 'webrelay.ashx', 'health.ashx', 'logo.png', 'welcome.jpg'];
views/player.handlebars
+12 -10
@@ -288,15 +288,18 @@
288 if ((playing == false) && (forced !== true)) return;
289 var flagBinary = (flags & 1) != 0, flagUser = (flags & 2) != 0;
290
291 - // Update the clock
292 - var deltaTimeTotalSec = Math.floor((time - recFileStartTime) / 1000);
293 - if (currentDeltaTimeTotalSec != deltaTimeTotalSec) {
294 - // Hours, minutes and seconds
295 - currentDeltaTimeTotalSec = deltaTimeTotalSec;
296 - var hrs = Math.floor(deltaTimeTotalSec / 3600);
297 - var mins = Math.floor((deltaTimeTotalSec % 3600) / 60);
298 - var secs = Math.floor(deltaTimeTotalSec % 60);
299 - QH('timespan', pad2(hrs) + ':' + pad2(mins) + ':' + pad2(secs))
291 + if (type == 2) {
292 + // Update the clock
293 + recFileLastTime = time;
294 + var deltaTimeTotalSec = Math.floor((time - recFileStartTime) / 1000);
295 + if (currentDeltaTimeTotalSec != deltaTimeTotalSec) {
296 + // Hours, minutes and seconds
297 + currentDeltaTimeTotalSec = deltaTimeTotalSec;
298 + var hrs = Math.floor(deltaTimeTotalSec / 3600);
299 + var mins = Math.floor((deltaTimeTotalSec % 3600) / 60);
300 + var secs = Math.floor(deltaTimeTotalSec % 60);
301 + QH('timespan', pad2(hrs) + ':' + pad2(mins) + ':' + pad2(secs))
302 + }
303 }
304
305 if ((type == 2) && flagBinary && !flagUser) {
@@ -325,7 +328,6 @@
328 }
329 }
330
328 - recFileLastTime = time;
331 if (playing) { readNextBlock(processBlock); }
332 }
333