From 4790f401791b6e75b3ddea49916c3ebfe55d0d03 Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Sun, 5 Nov 2023 04:39:02 +0000 Subject: [PATCH] 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 * add connect-flash package (#5509) Signed-off-by: si458 --------- Signed-off-by: si458 --- mcrec.js | 42 +++++++++++++++++++++--------------------- meshcentral.js | 2 +- meshrelay.js | 46 ++++++++++++++++++++++++---------------------- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/mcrec.js b/mcrec.js index 565062a9..43a78433 100644 --- a/mcrec.js +++ b/mcrec.js @@ -13,27 +13,15 @@ var worker = null; const NodeJSVer = Number(process.version.match(/^v(\d+\.\d+)/)[1]); var directRun = (require.main === module); function log() { if (directRun) { console.log(...arguments); } /*else { if (worker != null) { worker.parentPort.postMessage({ msg: arguments[0] }); } } */ } +function log2() { if (directRun) { console.log(...arguments); } else { process.send(...arguments); } /*else { if (worker != null) { worker.parentPort.postMessage({ msg: arguments[0] }); } } */ } if (directRun && (NodeJSVer >= 12)) { const xworker = require('worker_threads'); try { if (xworker.isMainThread == false) { worker = xworker; } } catch (ex) { log(ex); } } -function start() { startEx(process.argv); } -if (directRun) { setup(); } - -function setup() { InstallModules(['image-size'], start); } -function start() { startEx(process.argv); } -function startEx(argv) { - if (argv.length > 2) { indexFile(argv[2]); } else { - log("MeshCentral Session Recodings Processor"); - log("This tool will index a .mcrec file so that the player can seek thru the file."); - log(""); - log(" Usage: node mcrec [file]"); - } -} function indexFile(infile) { var state = { recFileName: null, recFile: null, recFileSize: 0, recFilePtr: 0 }; - if (fs.existsSync(infile) == false) { log("Missing file: " + infile); return; } + if (fs.existsSync(infile) == false) { log2("Missing file: " + infile); return; } state.recFileName = infile; state.recFileSize = fs.statSync(infile).size; - if (state.recFileSize < 32) { log("Invalid file: " + infile); return; } + if (state.recFileSize < 32) { log2("Invalid file size: " + infile); return; } log("Processing file: " + infile + ", " + state.recFileSize + " bytes."); state.recFile = fs.openSync(infile, 'r+'); state.indexTime = 10; // Interval between indexes in seconds @@ -43,8 +31,8 @@ function indexFile(infile) { state.height = 0; state.basePtr = null; readLastBlock(state, function (state, result, time, extras) { - if (result == false) { log("Invalid file: " + infile); return; } - if (extras != null) { log("File already indexed: " + infile); return; } + if (result == false) { log2("Invalid file: " + infile); return; } + if (extras != null) { log2("File already indexed: " + infile); return; } state.lastTimeStamp = time; readNextBlock(state, processBlock); }); @@ -68,7 +56,7 @@ function processBlock(state, block, err) { // Error reading the next block, exit now. fs.close(state.recFile, function () { for (var i in state) { delete state[i]; } // Clear the state. - log("Error."); + log2("Error."); }); return; } @@ -77,7 +65,7 @@ function processBlock(state, block, err) { writeIndex(state, function () { fs.close(state.recFile, function () { for (var i in state) { delete state[i]; } // Clear the state. - log("Done."); + log2("Done."); }); }); return; @@ -96,8 +84,8 @@ function processBlock(state, block, err) { if (block.type == 1) { // Metadata state.metadata = JSON.parse(block.data.toString()); - if (state.metadata.indexInterval != null) { log("This file is already indexed."); return; } - if (state.metadata.protocol != 2) { log("Only remote desktop sessions can currently be indexed."); return; } + if (state.metadata.indexInterval != null) { log2("This file is already indexed."); return; } + if (state.metadata.protocol != 2) { log2("Only remote desktop sessions can currently be indexed."); return; } state.metadataFlags = block.flags; state.metadataTime = block.time; state.recFileProtocol = state.metadata.protocol; @@ -329,6 +317,18 @@ function InstallModule(modulename, func, tag1, tag2) { }); } +function setup() { InstallModules(['image-size'], start); } +function start() { startEx(process.argv); } +function startEx(argv) { + if (argv.length > 2) { indexFile(argv[2]); } else { + log("MeshCentral Session Recodings Processor"); + log("This tool will index a .mcrec file so that the player can seek thru the file."); + log(""); + log(" Usage: node mcrec [file]"); + } +} +if (directRun) { setup(); } + // Export table module.exports.startEx = startEx; module.exports.indexFile = indexFile; \ No newline at end of file diff --git a/meshcentral.js b/meshcentral.js index 88f39877..b7163a4e 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -4005,7 +4005,7 @@ function mainStart() { 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'); } 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'); } 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)) { - 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; } + 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; } } if ((typeof config.domains[i].authstrategies.saml == 'object') || (typeof config.domains[i].authstrategies.jumpcloud == 'object')) { passport.push('passport-saml'); } } diff --git a/meshrelay.js b/meshrelay.js index dc70e5d7..5164fdf4 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -741,32 +741,34 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { var logfile = ws.logfile; delete ws.logfile; if (peer.ws) { delete peer.ws.logfile; } - recordingEntry(logfile, 3, 0, 'MeshCentralMCREC', function (logfile, tag) { - parent.parent.fs.close(logfile.fd); + setTimeout(function(){ // wait 5 seconds before finishing file for some reason? + recordingEntry(logfile, 3, 0, 'MeshCentralMCREC', function (logfile, tag) { + parent.parent.fs.closeSync(logfile.fd); - // Now that the recording file is closed, check if we need to index this file. - if (domain.sessionrecording.index && domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); } + // Now that the recording file is closed, check if we need to index this file. + if (domain.sessionrecording.index && domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); } - // Compute session length - var sessionLength = null; - if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); } + // Compute session length + var sessionLength = null; + if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); } - // Add a event entry about this recording - var basefile = parent.parent.path.basename(tag.logfile.filename); - 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 }; - if (user) { event.userids = [user._id]; } else if (peer.user) { event.userids = [peer.user._id]; } - var xprotocol = (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.p); - if ((xprotocol == null) && (logfile.text == 2)) { xprotocol = 200; } - if (xprotocol != null) { event.protocol = parseInt(xprotocol); } - var mesh = parent.meshes[tag.logfile.meshid]; - if (mesh != null) { event.meshname = mesh.name; event.meshid = mesh._id; } - if (tag.logfile.startTime) { event.startTime = tag.logfile.startTime; event.lengthTime = sessionLength; } - if (tag.logfile.name) { event.name = tag.logfile.name; } - if (tag.logfile.icon) { event.icon = tag.logfile.icon; } - parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event); + // Add a event entry about this recording + var basefile = parent.parent.path.basename(tag.logfile.filename); + 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 }; + if (user) { event.userids = [user._id]; } else if (peer.user) { event.userids = [peer.user._id]; } + var xprotocol = (((obj.req == null) || (obj.req.query == null)) ? null : obj.req.query.p); + if ((xprotocol == null) && (logfile.text == 2)) { xprotocol = 200; } + if (xprotocol != null) { event.protocol = parseInt(xprotocol); } + var mesh = parent.meshes[tag.logfile.meshid]; + if (mesh != null) { event.meshname = mesh.name; event.meshid = mesh._id; } + if (tag.logfile.startTime) { event.startTime = tag.logfile.startTime; event.lengthTime = sessionLength; } + if (tag.logfile.name) { event.name = tag.logfile.name; } + if (tag.logfile.icon) { event.icon = tag.logfile.icon; } + parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event); - cleanUpRecordings(); - }, { ws: ws, pws: peer.ws, logfile: logfile }); + cleanUpRecordings(); + }, { ws: ws, pws: peer.ws, logfile: logfile }); + },5000); } try { ws.close(); } catch (ex) { }