mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-12 11:01:52 +00:00
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>
This commit is contained in:
parent
7b016eac58
commit
4790f40179
3 changed files with 46 additions and 44 deletions
42
mcrec.js
42
mcrec.js
|
@ -13,27 +13,15 @@ var worker = null;
|
||||||
const NodeJSVer = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
const NodeJSVer = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||||
var directRun = (require.main === module);
|
var directRun = (require.main === module);
|
||||||
function log() { if (directRun) { console.log(...arguments); } /*else { if (worker != null) { worker.parentPort.postMessage({ msg: arguments[0] }); } } */ }
|
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); } }
|
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) {
|
function indexFile(infile) {
|
||||||
var state = { recFileName: null, recFile: null, recFileSize: 0, recFilePtr: 0 };
|
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.recFileName = infile;
|
||||||
state.recFileSize = fs.statSync(infile).size;
|
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.");
|
log("Processing file: " + infile + ", " + state.recFileSize + " bytes.");
|
||||||
state.recFile = fs.openSync(infile, 'r+');
|
state.recFile = fs.openSync(infile, 'r+');
|
||||||
state.indexTime = 10; // Interval between indexes in seconds
|
state.indexTime = 10; // Interval between indexes in seconds
|
||||||
|
@ -43,8 +31,8 @@ function indexFile(infile) {
|
||||||
state.height = 0;
|
state.height = 0;
|
||||||
state.basePtr = null;
|
state.basePtr = null;
|
||||||
readLastBlock(state, function (state, result, time, extras) {
|
readLastBlock(state, function (state, result, time, extras) {
|
||||||
if (result == false) { log("Invalid file: " + infile); return; }
|
if (result == false) { log2("Invalid file: " + infile); return; }
|
||||||
if (extras != null) { log("File already indexed: " + infile); return; }
|
if (extras != null) { log2("File already indexed: " + infile); return; }
|
||||||
state.lastTimeStamp = time;
|
state.lastTimeStamp = time;
|
||||||
readNextBlock(state, processBlock);
|
readNextBlock(state, processBlock);
|
||||||
});
|
});
|
||||||
|
@ -68,7 +56,7 @@ function processBlock(state, block, err) {
|
||||||
// Error reading the next block, exit now.
|
// Error reading the next block, exit now.
|
||||||
fs.close(state.recFile, function () {
|
fs.close(state.recFile, function () {
|
||||||
for (var i in state) { delete state[i]; } // Clear the state.
|
for (var i in state) { delete state[i]; } // Clear the state.
|
||||||
log("Error.");
|
log2("Error.");
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +65,7 @@ function processBlock(state, block, err) {
|
||||||
writeIndex(state, function () {
|
writeIndex(state, function () {
|
||||||
fs.close(state.recFile, function () {
|
fs.close(state.recFile, function () {
|
||||||
for (var i in state) { delete state[i]; } // Clear the state.
|
for (var i in state) { delete state[i]; } // Clear the state.
|
||||||
log("Done.");
|
log2("Done.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -96,8 +84,8 @@ function processBlock(state, block, err) {
|
||||||
if (block.type == 1) {
|
if (block.type == 1) {
|
||||||
// Metadata
|
// Metadata
|
||||||
state.metadata = JSON.parse(block.data.toString());
|
state.metadata = JSON.parse(block.data.toString());
|
||||||
if (state.metadata.indexInterval != null) { log("This file is already indexed."); return; }
|
if (state.metadata.indexInterval != null) { log2("This file is already indexed."); return; }
|
||||||
if (state.metadata.protocol != 2) { log("Only remote desktop sessions can currently be indexed."); return; }
|
if (state.metadata.protocol != 2) { log2("Only remote desktop sessions can currently be indexed."); return; }
|
||||||
state.metadataFlags = block.flags;
|
state.metadataFlags = block.flags;
|
||||||
state.metadataTime = block.time;
|
state.metadataTime = block.time;
|
||||||
state.recFileProtocol = state.metadata.protocol;
|
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
|
// Export table
|
||||||
module.exports.startEx = startEx;
|
module.exports.startEx = startEx;
|
||||||
module.exports.indexFile = indexFile;
|
module.exports.indexFile = indexFile;
|
|
@ -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.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.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 ((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'); }
|
if ((typeof config.domains[i].authstrategies.saml == 'object') || (typeof config.domains[i].authstrategies.jumpcloud == 'object')) { passport.push('passport-saml'); }
|
||||||
}
|
}
|
||||||
|
|
46
meshrelay.js
46
meshrelay.js
|
@ -741,32 +741,34 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) {
|
||||||
var logfile = ws.logfile;
|
var logfile = ws.logfile;
|
||||||
delete ws.logfile;
|
delete ws.logfile;
|
||||||
if (peer.ws) { delete peer.ws.logfile; }
|
if (peer.ws) { delete peer.ws.logfile; }
|
||||||
recordingEntry(logfile, 3, 0, 'MeshCentralMCREC', function (logfile, tag) {
|
setTimeout(function(){ // wait 5 seconds before finishing file for some reason?
|
||||||
parent.parent.fs.close(logfile.fd);
|
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.
|
// 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); }
|
if (domain.sessionrecording.index && domain.sessionrecording.index !== false) { parent.parent.certificateOperations.acceleratorPerformOperation('indexMcRec', tag.logfile.filename); }
|
||||||
|
|
||||||
// Compute session length
|
// Compute session length
|
||||||
var sessionLength = null;
|
var sessionLength = null;
|
||||||
if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); }
|
if (tag.logfile.startTime != null) { sessionLength = Math.round((Date.now() - tag.logfile.startTime) / 1000); }
|
||||||
|
|
||||||
// Add a event entry about this recording
|
// Add a event entry about this recording
|
||||||
var basefile = parent.parent.path.basename(tag.logfile.filename);
|
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 };
|
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]; }
|
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);
|
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) && (logfile.text == 2)) { xprotocol = 200; }
|
||||||
if (xprotocol != null) { event.protocol = parseInt(xprotocol); }
|
if (xprotocol != null) { event.protocol = parseInt(xprotocol); }
|
||||||
var mesh = parent.meshes[tag.logfile.meshid];
|
var mesh = parent.meshes[tag.logfile.meshid];
|
||||||
if (mesh != null) { event.meshname = mesh.name; event.meshid = mesh._id; }
|
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.startTime) { event.startTime = tag.logfile.startTime; event.lengthTime = sessionLength; }
|
||||||
if (tag.logfile.name) { event.name = tag.logfile.name; }
|
if (tag.logfile.name) { event.name = tag.logfile.name; }
|
||||||
if (tag.logfile.icon) { event.icon = tag.logfile.icon; }
|
if (tag.logfile.icon) { event.icon = tag.logfile.icon; }
|
||||||
parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event);
|
parent.parent.DispatchEvent(['*', 'recording', tag.logfile.nodeid, tag.logfile.meshid], obj, event);
|
||||||
|
|
||||||
cleanUpRecordings();
|
cleanUpRecordings();
|
||||||
}, { ws: ws, pws: peer.ws, logfile: logfile });
|
}, { ws: ws, pws: peer.ws, logfile: logfile });
|
||||||
|
},5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
try { ws.close(); } catch (ex) { }
|
try { ws.close(); } catch (ex) { }
|
||||||
|
|
Loading…
Reference in a new issue