Properly showing device names and IPs.
This commit is contained in:
parent
df520fcce6
commit
50099ee4ef
@ -86,3 +86,65 @@ function deviceFromID(what)
|
||||
}
|
||||
return null; //No match. return a null value
|
||||
}
|
||||
|
||||
//return a list of all the ip addresses a device has
|
||||
function ipsFromDevice(what) {
|
||||
var ipaddresses = [];
|
||||
for (var i = 0; i < what.nic.length; i++) {
|
||||
ipaddresses = ipaddresses.concat(ipsFromNic(what.nic[i]));
|
||||
}
|
||||
//console.log("Adding to nics " + ipaddresses.length);
|
||||
return ipaddresses;
|
||||
}
|
||||
|
||||
function ipsFromInterface(what, nictype) {
|
||||
var ipaddresses = [];
|
||||
if (typeof (what.myip) === "array") {
|
||||
for (var x = 0; x < what.myip.length; x++) {
|
||||
var one = {
|
||||
nic: what.nicname,
|
||||
ip: what.myip[x].ip,
|
||||
mask: what.myip[x].mask,
|
||||
cidrip: what.myip[x].ip + "/" + NetmaskToCIDR(what.myip[x].mask),
|
||||
nictype: nictype,
|
||||
};
|
||||
ipaddresses.push(one);
|
||||
}
|
||||
}
|
||||
else if (typeof (what.myip) === "object") {
|
||||
var one = {
|
||||
nic: what.nicname,
|
||||
ip: what.myip.ip,
|
||||
mask: what.myip.mask,
|
||||
cidrip: what.myip.ip + "/" + NetmaskToCIDR(what.myip.mask),
|
||||
nictype: nictype,
|
||||
};
|
||||
ipaddresses.push(one);
|
||||
//console.log("found an ip object: " + JSON.stringify(one) + " " + nictype);
|
||||
}
|
||||
return ipaddresses;
|
||||
}
|
||||
|
||||
function ipsFromNic(what) {
|
||||
var ipaddresses = [];
|
||||
//console.log("Looking at a nic: " + JSON.stringify(what));
|
||||
if (typeof (what.interface) === "array") {
|
||||
for (var i = 0; i < what.interface.length; i++) {
|
||||
//console.log("Trying to add a nic." + what.interface[i].nicname);
|
||||
ipaddresses=ipaddresses.concat(ipsFromInterface(what.interface[i],what.nictype[0]));
|
||||
}
|
||||
}
|
||||
else if (typeof (what.interface) === "object")
|
||||
ipaddresses=ipaddresses.concat(ipsFromInterface(what.interface, what.nictype[0]));
|
||||
|
||||
return ipaddresses;
|
||||
}
|
||||
|
||||
function NetmaskToCIDR(mask) {
|
||||
var cidr = 0;
|
||||
var maskNodes = mask.match(/(\d+)/g);
|
||||
for (var i in maskNodes) {
|
||||
cidr += (((maskNodes[i] >>> 0).toString(2)).match(/1/g) || []).length;
|
||||
}
|
||||
return cidr;
|
||||
}
|
26
Web/ui.js
26
Web/ui.js
@ -284,6 +284,9 @@ function PrintNetworkDevice(ToPrint)
|
||||
var xpoint = rect.center.x;
|
||||
var ystart = rect.epoint.y; //the bottom-most Y point
|
||||
var gap = 3;
|
||||
var delta;
|
||||
var ipaddresses = ipsFromDevice(ToPrint);
|
||||
console.log("addresses: " + JSON.stringify(ipaddresses));
|
||||
switch (uiDeviceInfoLevel) {
|
||||
case 0:
|
||||
//Do not print anything
|
||||
@ -293,10 +296,27 @@ function PrintNetworkDevice(ToPrint)
|
||||
printCenteredText(MainCanvas_ctx, ToPrint.hostname, xpoint, ystart);
|
||||
break;
|
||||
case 2:
|
||||
//Print both the name and the IP addresses
|
||||
break;
|
||||
case 3:
|
||||
//print just the ip addresses
|
||||
console.log("printing device " + ToPrint.hostname);
|
||||
//Print both the name and the IP addresses
|
||||
if (uiDeviceInfoLevel == 2) {
|
||||
delta = printCenteredText(MainCanvas_ctx, ToPrint.hostname, xpoint, ystart) + gap;
|
||||
ystart += delta / 2;
|
||||
}
|
||||
//print the ip addresses
|
||||
for (var x = 0; x < ipaddresses.length; x++) {
|
||||
//Print the IP address if the type is correct.
|
||||
console.log(JSON.stringify(ipaddresses[x]));
|
||||
switch (ipaddresses[x].nictype) {
|
||||
case "eth":
|
||||
case "management_interface":
|
||||
console.log("Found a " + ipaddresses[x].nictype)
|
||||
let mystring = ipaddresses[x].cidrip;
|
||||
delta = printCenteredText(MainCanvas_ctx, mystring, xpoint, ystart);
|
||||
ystart += (delta / 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user