1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-02-14 20:11:52 +00:00

Added reverse DNS when Intel AMT device added using meshcmd.

This commit is contained in:
Ylian Saint-Hilaire 2021-03-08 11:06:39 -08:00
parent 8eb5b49ee5
commit 0a24dd8290
2 changed files with 64 additions and 40 deletions

View file

@ -873,7 +873,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
// Close the duplicate agent // Close the duplicate agent
parent.agentStats.duplicateAgentCount++; parent.agentStats.duplicateAgentCount++;
parent.setAgentIssue(obj, "duplicateAgent"); parent.setAgentIssue(obj, 'duplicateAgent');
if (obj.nodeid != null) { parent.parent.debug('agent', 'Duplicate agent ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } if (obj.nodeid != null) { parent.parent.debug('agent', 'Duplicate agent ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); }
dupAgent.close(3); dupAgent.close(3);
} else { } else {

View file

@ -440,32 +440,44 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
console.log('Too many devices on this domain to accept the CIRA connection. meshid: ' + socket.tag.meshid); console.log('Too many devices on this domain to accept the CIRA connection. meshid: ' + socket.tag.meshid);
socket.end(); socket.end();
} else { } else {
// We are under the limit, create the new device. // Attempts reverse DNS loopup on the device IP address
// Node is not in the database, add it. Credentials will be empty until added by the user. require('dns').reverse(socket.remoteAddr, function (err, hostnames) {
var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: socket.remoteAddr, domain: domainid, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } }; var hostname = socket.remoteAddr;
if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; } if ((err == null) && (hostnames != null) && (hostnames.length > 0)) { hostname = hostnames[0]; }
obj.db.Set(device);
// Event the new node // We are under the limit, create the new device.
addedTlsDeviceCount++; // Node is not in the database, add it. Credentials will be empty until added by the user.
var change = 'CIRA added device ' + socket.tag.name + ' to mesh ' + mesh.name; var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: hostname, domain: domainid, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } };
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: domainid }); if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; }
obj.db.Set(device);
// Add the connection to the MPS connection list // Event the new node
addCiraConnection(socket); addedTlsDeviceCount++;
var change = 'CIRA added device ' + socket.tag.name + ' to mesh ' + mesh.name;
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: domainid });
// Add the connection to the MPS connection list
addCiraConnection(socket);
});
} }
}); });
return; return;
} else { } else {
// Node is not in the database, add it. Credentials will be empty until added by the user. // Attempts reverse DNS loopup on the device IP address
var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: socket.remoteAddr, domain: domainid, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } }; require('dns').reverse(socket.remoteAddr, function (err, hostnames) {
if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; } var hostname = socket.remoteAddr;
obj.db.Set(device); if ((err == null) && (hostnames != null) && (hostnames.length > 0)) { hostname = hostnames[0]; }
// Event the new node // Node is not in the database, add it. Credentials will be empty until added by the user.
addedTlsDeviceCount++; var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: hostname, domain: domainid, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } };
var change = 'CIRA added device ' + socket.tag.name + ' to mesh ' + mesh.name; if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; }
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: domainid }); obj.db.Set(device);
// Event the new node
addedTlsDeviceCount++;
var change = 'CIRA added device ' + socket.tag.name + ' to mesh ' + mesh.name;
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: domainid });
});
} }
} else { } else {
// New CIRA connection for unknown node, disconnect. // New CIRA connection for unknown node, disconnect.
@ -596,33 +608,45 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
console.log('Too many devices on this domain to accept the CIRA connection. meshid: ' + socket.tag.meshid); console.log('Too many devices on this domain to accept the CIRA connection. meshid: ' + socket.tag.meshid);
socket.end(); socket.end();
} else { } else {
// We are under the limit, create the new device. // Attempts reverse DNS loopup on the device IP address
// Node is not in the database, add it. Credentials will be empty until added by the user. require('dns').reverse(socket.remoteAddr, function (err, hostnames) {
var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: socket.remoteAddr, domain: mesh.domain, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } }; var hostname = socket.remoteAddr;
if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; } if ((err == null) && (hostnames != null) && (hostnames.length > 0)) { hostname = hostnames[0]; }
obj.db.Set(device);
// Event the new node // We are under the limit, create the new device.
addedDeviceCount++; // Node is not in the database, add it. Credentials will be empty until added by the user.
var change = 'CIRA added device ' + socket.tag.name + ' to group ' + mesh.name; var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: hostname, domain: mesh.domain, intelamt: { user: (typeof socket.tag.meiState.amtuser == 'string') ? socket.tag.meiState.amtuser : '', pass: (typeof socket.tag.meiState.amtpass == 'string') ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } };
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: mesh.domain }); if ((typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; }
obj.db.Set(device);
// Add the connection to the MPS connection list // Event the new node
addCiraConnection(socket); addedDeviceCount++;
SendUserAuthSuccess(socket); // Notify the auth success on the CIRA connection var change = 'CIRA added device ' + socket.tag.name + ' to group ' + mesh.name;
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: mesh.domain });
// Add the connection to the MPS connection list
addCiraConnection(socket);
SendUserAuthSuccess(socket); // Notify the auth success on the CIRA connection
});
} }
}); });
return; return;
} else { } else {
// Node is not in the database, add it. Credentials will be empty until added by the user. // Attempts reverse DNS loopup on the device IP address
var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState && socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: socket.remoteAddr, domain: mesh.domain, intelamt: { user: ((socket.tag.meiState) && (typeof socket.tag.meiState.amtuser == 'string')) ? socket.tag.meiState.amtuser : '', pass: ((socket.tag.meiState) && (typeof socket.tag.meiState.amtpass == 'string')) ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } }; require('dns').reverse(socket.remoteAddr, function (err, hostnames) {
if ((socket.tag.meiState != null) && (typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; } var hostname = socket.remoteAddr;
obj.db.Set(device); if ((err == null) && (hostnames != null) && (hostnames.length > 0)) { hostname = hostnames[0]; }
// Event the new node // Node is not in the database, add it. Credentials will be empty until added by the user.
addedDeviceCount++; var device = { type: 'node', mtype: 1, _id: socket.tag.nodeid, meshid: socket.tag.meshid, name: socket.tag.name, icon: (socket.tag.meiState && socket.tag.meiState.isBatteryPowered) ? 2 : 1, host: hostname, domain: mesh.domain, intelamt: { user: ((socket.tag.meiState) && (typeof socket.tag.meiState.amtuser == 'string')) ? socket.tag.meiState.amtuser : '', pass: ((socket.tag.meiState) && (typeof socket.tag.meiState.amtpass == 'string')) ? socket.tag.meiState.amtpass : '', tls: 0, state: 2 } };
var change = 'CIRA added device ' + socket.tag.name + ' to group ' + mesh.name; if ((socket.tag.meiState != null) && (typeof socket.tag.meiState.desc == 'string') && (socket.tag.meiState.desc.length > 0) && (socket.tag.meiState.desc.length < 1024)) { device.desc = socket.tag.meiState.desc; }
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: mesh.domain }); obj.db.Set(device);
// Event the new node
addedDeviceCount++;
var change = 'CIRA added device ' + socket.tag.name + ' to group ' + mesh.name;
obj.parent.DispatchEvent(['*', socket.tag.meshid], obj, { etype: 'node', action: 'addnode', node: parent.webserver.CloneSafeNode(device), msg: change, domain: mesh.domain });
});
} }
} else { } else {
// Node is already present // Node is already present