mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-24 13:13:13 -05:00
Create handler function for getnetworkinfo
This commit is contained in:
parent
000a0f126d
commit
c4b11d3384
59
meshuser.js
59
meshuser.js
@ -3606,35 +3606,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'toast', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'toast', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'getnetworkinfo':
|
|
||||||
{
|
|
||||||
// Argument validation
|
|
||||||
if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
|
|
||||||
if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
|
|
||||||
if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
|
|
||||||
|
|
||||||
// Get the node and the rights for this node
|
|
||||||
parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
|
|
||||||
if (visible == false) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; }
|
|
||||||
|
|
||||||
// Get network information about this node
|
|
||||||
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) { }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'changedevice':
|
case 'changedevice':
|
||||||
{
|
{
|
||||||
var err = null;
|
var err = null;
|
||||||
@ -5503,6 +5474,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
}
|
}
|
||||||
|
|
||||||
const serverCommands = {
|
const serverCommands = {
|
||||||
|
'getnetworkinfo': serverCommandGetNetworkInfo,
|
||||||
'lastconnect': serverCommandLastConnect,
|
'lastconnect': serverCommandLastConnect,
|
||||||
'serverconsole': serverCommandServerConsole
|
'serverconsole': serverCommandServerConsole
|
||||||
};
|
};
|
||||||
@ -5559,7 +5531,34 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||||||
'webstats': [serverUserCommandWebStats, ""]
|
'webstats': [serverUserCommandWebStats, ""]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function serverCommandGetNetworkInfo(command) {
|
||||||
|
// Argument validation
|
||||||
|
if (common.validateString(command.nodeid, 1, 1024) == false) return; // Check nodeid
|
||||||
|
if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
|
||||||
|
if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
|
||||||
|
|
||||||
|
// Get the node and the rights for this node
|
||||||
|
parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
|
||||||
|
if (visible == false) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; }
|
||||||
|
|
||||||
|
// Get network information about this node
|
||||||
|
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) { }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function serverCommandLastConnect(command) {
|
function serverCommandLastConnect(command) {
|
||||||
if (common.validateString(command.nodeid, 1, 1024) == false) return; // Check the nodeid
|
if (common.validateString(command.nodeid, 1, 1024) == false) return; // Check the nodeid
|
||||||
if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
|
if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user