wait 5 sec after record and also pass message back (#5508)

* wait 5 sec after record and also pass message back Signed-off-by: si458 <simonsmith5521@gmail.com> * add connect-flash package (#5509) Signed-off-by: si458 <simonsmith5521@gmail.com> --------- Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Nov 5, 2023 at 04:39 UTC 4790f401791b6e75b3ddea49916c3ebfe55d0d03
3 files changed +50 -48
mcrec.js
+21 -21
@@ -13,27 +13,15 @@ var worker = null;
13 const NodeJSVer = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
14 var directRun = (require.main === module);
15 function log() { if (directRun) { console.log(...arguments); } /*else { if (worker != null) { worker.parentPort.postMessage({ msg: arguments[0] }); } } */ }
16 +function log2() { if (directRun) { console.log(...arguments); } else { process.send(...arguments); } /*else { if (worker != null) { worker.parentPort.postMessage({ msg: arguments[0] }); } } */ }
17 if (directRun && (NodeJSVer >= 12)) { const xworker = require('worker_threads'); try { if (xworker.isMainThread == false) { worker = xworker; } } catch (ex) { log(ex); } }
17 -function start() { startEx(process.argv); }
18 -if (directRun) { setup(); }
19 -
20 -function setup() { InstallModules(['image-size'], start); }
21 -function start() { startEx(process.argv); }
22 -function startEx(argv) {
23 - if (argv.length > 2) { indexFile(argv[2]); } else {
24 - log("MeshCentral Session Recodings Processor");
25 - log("This tool will index a .mcrec file so that the player can seek thru the file.");
26 - log("");
27 - log(" Usage: node mcrec [file]");
28 - }
29 -}
18
19 function indexFile(infile) {
20 var state = { recFileName: null, recFile: null, recFileSize: 0, recFilePtr: 0 };
33 - if (fs.existsSync(infile) == false) { log("Missing file: " + infile); return; }
21 + if (fs.existsSync(infile) == false) { log2("Missing file: " + infile); return; }
22 state.recFileName = infile;
23 state.recFileSize = fs.statSync(infile).size;
36 - if (state.recFileSize < 32) { log("Invalid file: " + infile); return; }
24 + if (state.recFileSize < 32) { log2("Invalid file size: " + infile); return; }
25 log("Processing file: " + infile + ", " + state.recFileSize + " bytes.");
26 state.recFile = fs.openSync(infile, 'r+');
27 state.indexTime = 10; // Interval between indexes in seconds
@@ -43,8 +31,8 @@ function indexFile(infile) {
31 state.height = 0;
32 state.basePtr = null;
33 readLastBlock(state, function (state, result, time, extras) {
46 - if (result == false) { log("Invalid file: " + infile); return; }
47 - if (extras != null) { log("File already indexed: " + infile); return; }
34 + if (result == false) { log2("Invalid file: " + infile); return; }
35 + if (extras != null) { log2("File already indexed: " + infile); return; }
36 state.lastTimeStamp = time;
37 readNextBlock(state, processBlock);
38 });
@@ -68,7 +56,7 @@ function processBlock(state, block, err) {
56 // Error reading the next block, exit now.
57 fs.close(state.recFile, function () {
58 for (var i in state) { delete state[i]; } // Clear the state.
71 - log("Error.");
59 + log2("Error.");
60 });
61 return;
62 }
@@ -77,7 +65,7 @@ function processBlock(state, block, err) {
65 writeIndex(state, function () {
66 fs.close(state.recFile, function () {
67 for (var i in state) { delete state[i]; } // Clear the state.
80 - log("Done.");
68 + log2("Done.");
69 });
70 });
71 return;
@@ -96,8 +84,8 @@ function processBlock(state, block, err) {
84 if (block.type == 1) {
85 // Metadata
86 state.metadata = JSON.parse(block.data.toString());
99 - if (state.metadata.indexInterval != null) { log("This file is already indexed."); return; }
100 - if (state.metadata.protocol != 2) { log("Only remote desktop sessions can currently be indexed."); return; }
87 + if (state.metadata.indexInterval != null) { log2("This file is already indexed."); return; }
88 + if (state.metadata.protocol != 2) { log2("Only remote desktop sessions can currently be indexed."); return; }
89 state.metadataFlags = block.flags;
90 state.metadataTime = block.time;
91 state.recFileProtocol = state.metadata.protocol;
@@ -329,6 +317,18 @@ function InstallModule(modulename, func, tag1, tag2) {
317 });
318 }
319
320 +function setup() { InstallModules(['image-size'], start); }
321 +function start() { startEx(process.argv); }
322 +function startEx(argv) {
323 + if (argv.length > 2) { indexFile(argv[2]); } else {
324 + log("MeshCentral Session Recodings Processor");
325 + log("This tool will index a .mcrec file so that the player can seek thru the file.");
326 + log("");
327 + log(" Usage: node mcrec [file]");
328 + }
329 +}
330 +if (directRun) { setup(); }
331 +
332 // Export table
333 module.exports.startEx = startEx;
334 module.exports.indexFile = indexFile;
\ No newline at end of file
meshcentral.js
+1 -1
@@ -4005,7 +4005,7 @@ function mainStart() {
4005 if ((typeof config.domains[i].authstrategies.reddit == 'object') && (typeof config.domains[i].authstrategies.reddit.clientid == 'string') && (typeof config.domains[i].authstrategies.reddit.clientsecret == 'string') && (passport.indexOf('passport-reddit') == -1)) { passport.push('passport-reddit'); }
4006 if ((typeof config.domains[i].authstrategies.azure == 'object') && (typeof config.domains[i].authstrategies.azure.clientid == 'string') && (typeof config.domains[i].authstrategies.azure.clientsecret == 'string') && (typeof config.domains[i].authstrategies.azure.tenantid == 'string') && (passport.indexOf('passport-azure-oauth2') == -1)) { passport.push('passport-azure-oauth2'); passport.push('jwt-simple'); }
4007 if ((typeof config.domains[i].authstrategies.oidc == 'object') && (typeof config.domains[i].authstrategies.oidc.clientid == 'string') && (typeof config.domains[i].authstrategies.oidc.clientsecret == 'string') && (typeof config.domains[i].authstrategies.oidc.issuer == 'string') && (passport.indexOf('@mstrhakr/passport-openidconnect') == -1)) {
4008 - if ((nodeVersion >= 17) || ((Math.floor(nodeVersion) == 16) && (nodeVersion >= 16.13)) || ((Math.floor(nodeVersion) == 14) && (nodeVersion >= 14.15)) || ((Math.floor(nodeVersion) == 12) && (nodeVersion >= 12.19))) { passport.push('@mstrhakr/passport-openidconnect'); passport.push('openid-client'); } else { addServerWarning('This NodeJS version does not support OpenID.', 25); delete config.domains[i].authstrategies.oidc; }
4008 + if ((nodeVersion >= 17) || ((Math.floor(nodeVersion) == 16) && (nodeVersion >= 16.13)) || ((Math.floor(nodeVersion) == 14) && (nodeVersion >= 14.15)) || ((Math.floor(nodeVersion) == 12) && (nodeVersion >= 12.19))) { passport.push('@mstrhakr/passport-openidconnect'); passport.push('openid-client'); passport.push('connect-flash'); } else { addServerWarning('This NodeJS version does not support OpenID.', 25); delete config.domains[i].authstrategies.oidc; }
4009 }
4010 if ((typeof config.domains[i].authstrategies.saml == 'object') || (typeof config.domains[i].authstrategies.jumpcloud == 'object')) { passport.push('passport-saml'); }
4011 }
meshrelay.js
+28 -26
@@ -741,32 +741,34 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
741 var logfile = ws.logfile;
742 delete ws.logfile;
743 if (peer.ws) { delete peer.ws.logfile; }
744 - recordingEntry(logfile, 3, 0, 'MeshCentralMCREC', function (logfile, tag) {
745 - parent.parent.fs.close(logfile.fd);
746 -
747 - // Now that the recording file is closed, check if we need to index this file.
748 - if (domain.sessionrecording.index && domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); }
749 -
750 - // Compute session length
751 - var sessionLength = null;
752 - if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); }
753 -
754 - // Add a event entry about this recording
755 - var basefile = parent.parent.path.basename(tag.logfile.filename);
756 - var event = { etype: 'relay', action: 'recording', domain: domain.id, nodeid: tag.logfile.nodeid, msg: "Finished recording session" + (sessionLength ? (', ' + sessionLength + ' second(s)') : ''), filename: basefile, size: tag.logfile.size };
757 - if (user) { event.userids = [user._id]; } else if (peer.user) { event.userids = [peer.user._id]; }
758 - var xprotocol = (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.p);
759 - if ((xprotocol == null) && (logfile.text == 2)) { xprotocol = 200; }
760 - if (xprotocol != null) { event.protocol = parseInt(xprotocol); }
761 - var mesh = parent.meshes[tag.logfile.meshid];
762 - if (mesh != null) { event.meshname = mesh.name; event.meshid = mesh._id; }
763 - if (tag.logfile.startTime) { event.startTime = tag.logfile.startTime; event.lengthTime = sessionLength; }
764 - if (tag.logfile.name) { event.name = tag.logfile.name; }
765 - if (tag.logfile.icon) { event.icon = tag.logfile.icon; }
766 - parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event);
767 -
768 - cleanUpRecordings();
769 - }, { ws: ws, pws: peer.ws, logfile: logfile });
744 + setTimeout(function(){ // wait 5 seconds before finishing file for some reason?
745 + recordingEntry(logfile, 3, 0, 'MeshCentralMCREC', function (logfile, tag) {
746 + parent.parent.fs.closeSync(logfile.fd);
747 +
748 + // Now that the recording file is closed, check if we need to index this file.
749 + if (domain.sessionrecording.index && domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); }
750 +
751 + // Compute session length
752 + var sessionLength = null;
753 + if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); }
754 +
755 + // Add a event entry about this recording
756 + var basefile = parent.parent.path.basename(tag.logfile.filename);
757 + var event = { etype: 'relay', action: 'recording', domain: domain.id, nodeid: tag.logfile.nodeid, msg: "Finished recording session" + (sessionLength ? (', ' + sessionLength + ' second(s)') : ''), filename: basefile, size: tag.logfile.size };
758 + if (user) { event.userids = [user._id]; } else if (peer.user) { event.userids = [peer.user._id]; }
759 + var xprotocol = (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.p);
760 + if ((xprotocol == null) && (logfile.text == 2)) { xprotocol = 200; }
761 + if (xprotocol != null) { event.protocol = parseInt(xprotocol); }
762 + var mesh = parent.meshes[tag.logfile.meshid];
763 + if (mesh != null) { event.meshname = mesh.name; event.meshid = mesh._id; }
764 + if (tag.logfile.startTime) { event.startTime = tag.logfile.startTime; event.lengthTime = sessionLength; }
765 + if (tag.logfile.name) { event.name = tag.logfile.name; }
766 + if (tag.logfile.icon) { event.icon = tag.logfile.icon; }
767 + parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event);
768 +
769 + cleanUpRecordings();
770 + }, { ws: ws, pws: peer.ws, logfile: logfile });
771 + },5000);
772 }
773
774 try { ws.close(); } catch (ex) { }