mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-25 21:53:14 -05:00
Added network interface names escaping.
This commit is contained in:
parent
cce68922d7
commit
8fc23995b9
@ -1164,6 +1164,14 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
// Check if network information is present
|
||||
if ((command.netif2 == null) && (command.netif == null)) return;
|
||||
|
||||
// Escape any field names that have special characters
|
||||
if (command.netif2 != null) {
|
||||
for (var i in command.netif2) {
|
||||
var esc = common.escapeFieldName(i);
|
||||
if (esc !== i) { command.netif2[esc] = command.netif2[i]; delete command.netif2[i]; }
|
||||
}
|
||||
}
|
||||
|
||||
// Sent by the agent to update agent network interface information
|
||||
delete command.action;
|
||||
command.updateTime = Date.now();
|
||||
|
@ -901,7 +901,13 @@ function CreateMeshCentralServer(config, args) {
|
||||
if (badCharCount > 0) { console.log(badCharCount + ' invalid character(s) where removed.'); }
|
||||
try { json = JSON.parse(json2); } catch (e) { console.log('Invalid JSON format: ' + obj.args.dbimport + ': ' + e); process.exit(); }
|
||||
if ((json == null) || (typeof json.length != 'number') || (json.length < 1)) { console.log('Invalid JSON format: ' + obj.args.dbimport + '.'); }
|
||||
for (i in json) { if ((json[i].type == "mesh") && (json[i].links != null)) { for (var j in json[i].links) { var esc = obj.common.escapeFieldName(j); if (esc !== j) { json[i].links[esc] = json[i].links[j]; delete json[i].links[j]; } } } } // Escape MongoDB invalid field chars
|
||||
// Escape MongoDB invalid field chars
|
||||
for (i in json) {
|
||||
var doc = json[i];
|
||||
for (var j in doc) { if (j.indexOf('.') >= 0) { console.log("Invalid field name (" + j + ") in document: " + json[i]); return; } }
|
||||
if ((json[i].type == "ifinfo") && (json[i].netif2 != null)) { for (var j in json[i].netif2) { var esc = obj.common.escapeFieldName(j); if (esc !== j) { json[i].netif2[esc] = json[i].netif2[j]; delete json[i].netif2[j]; } } }
|
||||
if ((json[i].type == "mesh") && (json[i].links != null)) { for (var j in json[i].links) { var esc = obj.common.escapeFieldName(j); if (esc !== j) { json[i].links[esc] = json[i].links[j]; delete json[i].links[j]; } } }
|
||||
}
|
||||
//for (i in json) { if ((json[i].type == "node") && (json[i].host != null)) { json[i].rname = json[i].host; delete json[i].host; } } // DEBUG: Change host to rname
|
||||
setTimeout(function () { // If the Mongo database is being created for the first time, there is a race condition here. This will get around it.
|
||||
obj.db.RemoveAll(function () {
|
||||
|
@ -3857,6 +3857,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
db.Get('if' + node._id, function (err, netinfos) {
|
||||
if ((netinfos == null) || (netinfos.length != 1)) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: node._id, netif: null, netif2: null })); } catch (ex) { } return; }
|
||||
var netinfo = netinfos[0];
|
||||
|
||||
// Unescape any field names that have special characters if needed
|
||||
if (netinfo.netif2 != null) {
|
||||
for (var i in netinfo.netif2) {
|
||||
var esc = common.unEscapeFieldName(i);
|
||||
if (esc !== i) { netinfo.netif2[esc] = netinfo.netif2[i]; delete netinfo.netif2[i]; }
|
||||
}
|
||||
}
|
||||
|
||||
try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: node._id, updateTime: netinfo.updateTime, netif: netinfo.netif, netif2: netinfo.netif2 })); } catch (ex) { }
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user