From f7dd9cfcbfa11dac81512493cb90b0b81d72cc07 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 7 Aug 2019 14:25:23 -0700 Subject: [PATCH] Node 6.x cbor fix. --- package.json | 4 ++-- views/default.handlebars | 2 +- webserver.js | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2ae91e78..2195d156 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.9-i", + "version": "0.3.9-j", "keywords": [ "Remote Management", "Intel AMT", @@ -29,7 +29,7 @@ "dependencies": { "archiver": "^3.0.0", "body-parser": "^1.19.0", - "cbor": "^4.1.5", + "cbor": "4.1.5", "compression": "^1.7.4", "connect-redis": "^3.4.1", "cookie-session": "^2.0.0-beta.3", diff --git a/views/default.handlebars b/views/default.handlebars index 54a03a56..37ba9c4b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1514,7 +1514,7 @@ x += '
' if (net.name) { x += addHtmlValue2('Name', '' + EscapeHtml(net.name) + ''); } if (net.desc) { x += addHtmlValue2('Description', EscapeHtml(net.desc).replace('(R)', '®').replace('(r)', '®')); } - if (net.dnssuffix) { x += addHtmlValue2('DNS suffix', EscapeHtml(net.dnssuffix)); } + if (net.dnssuffix) { x += addHtmlValue2('DNS suffix', EscapeHtml(net.dnssuffix) + ' '); } if (net.mac) { x += addHtmlValue2('MAC address', '' + EscapeHtml(net.mac.toLowerCase()) + ' '); } if (net.v4addr) { x += addHtmlValue2('IPv4 address', EscapeHtml(net.v4addr) + ' '); } if (net.v4mask) { x += addHtmlValue2('IPv4 mask', EscapeHtml(net.v4mask) + ' '); } diff --git a/webserver.js b/webserver.js index 4e5b8c94..5df92f46 100644 --- a/webserver.js +++ b/webserver.js @@ -1960,6 +1960,29 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { } } + /* + // Setup session recording if needed + if (domain.sessionrecording == true || ((typeof domain.sessionrecording == 'object') && ((domain.sessionrecording.protocols == null) || (domain.sessionrecording.protocols.indexOf(100) >= 0)))) { // TODO 100 + var recFilename = 'relaysession' + ((domain.id == '') ? '' : '-') + domain.id + '-' + Date.now() + '-' + 'AAAAAAA' + '.mcrec'; // TODO: Random ID + var recFullFilename = null; + if (domain.sessionrecording.filepath) { + try { obj.fs.mkdirSync(domain.sessionrecording.filepath); } catch (e) { } + recFullFilename = obj.path.join(domain.sessionrecording.filepath, recFilename); + } else { + try { obj.fs.mkdirSync(parent.recordpath); } catch (e) { } + recFullFilename = obj.path.join(parent.recordpath, recFilename); + } + var fd = obj.fs.openSync(recFullFilename, 'w'); + if (fd != null) { + // Write the recording file header + //console.log({ magic: 'MeshCentralRelaySession', ver: 1, userid: user._id, username: user.name, ipaddr: cleanRemoteAddr(ws._socket.remoteAddress), nodeid: node._id, intelamt: true, protocol: parseInt(req.query.p), time: new Date().toLocaleString() }); + var firstBlock = JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, userid: user._id, username: user.name, ipaddr: cleanRemoteAddr(ws._socket.remoteAddress), nodeid: node._id, intelamt: true, protocol: parseInt(req.query.p), time: new Date().toLocaleString() }) + recordingEntry(fd, 1, 0, firstBlock, function () { }); + ws.logfile = { fd: fd, lock: false }; + } + } + */ + // If Intel AMT CIRA connection is available, use it if (((conn & 2) != 0) && (parent.mpsserver.ciraConnections[req.query.host] != null)) { Debug(1, 'Opening relay CIRA channel connection to ' + req.query.host + '.'); @@ -3390,5 +3413,33 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { function checkAmtPassword(p) { return (p.length > 7) && (/\d/.test(p)) && (/[a-z]/.test(p)) && (/[A-Z]/.test(p)) && (/\W/.test(p)); } function getRandomAmtPassword() { var p; do { p = Buffer.from(obj.crypto.randomBytes(9), 'binary').toString('base64').split('/').join('@'); } while (checkAmtPassword(p) == false); return p; } + // Clean a IPv6 address that encodes a IPv4 address + function cleanRemoteAddr(addr) { if (addr.startsWith('::ffff:')) { return addr.substring(7); } else { return addr; } } + + // Record a new entry in a recording log + function recordingEntry(fd, type, flags, data, func) { + try { + if (typeof data == 'string') { + // String write + var blockData = Buffer.from(data), header = Buffer.alloc(16); // Header: Type (2) + Flags (2) + Size(4) + Time(8) + header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data) + header.writeInt16BE(flags, 2); // Flags (1 = Binary, 2 = User) + header.writeInt32BE(blockData.length, 4); // Size + header.writeIntBE(new Date(), 10, 6); // Time + var block = Buffer.concat([header, blockData]); + obj.fs.write(fd, block, 0, block.length, func); + } else { + // Binary write + var header = Buffer.alloc(16); // Header: Type (2) + Flags (2) + Size(4) + Time(8) + header.writeInt16BE(type, 0); // Type (1 = Header, 2 = Network Data) + header.writeInt16BE(flags | 1, 2); // Flags (1 = Binary, 2 = User) + header.writeInt32BE(data.length, 4); // Size + header.writeIntBE(new Date(), 10, 6); // Time + var block = Buffer.concat([header, data]); + obj.fs.write(fd, block, 0, block.length, func); + } + } catch (ex) { console.log(ex); func(); } + } + return obj; }; \ No newline at end of file