From 808b8c1986ae943ae6f1152d165786ede146d532 Mon Sep 17 00:00:00 2001 From: Daniel Krah Date: Sat, 5 Nov 2016 21:23:27 +0100 Subject: [PATCH] Count Clients in a Mesh (#61) This functions count all clients in a meshcloud. It count over wireless and cable links not over VPN links via l2tp or fastd. --- lib/infobox/node.js | 58 ++++++++++++++++++++++++++++++++++++++++++++- scss/main.scss | 7 ++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/infobox/node.js b/lib/infobox/node.js index 0304d5f..4310548 100644 --- a/lib/infobox/node.js +++ b/lib/infobox/node.js @@ -133,14 +133,70 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], if (!d.flags.online) return undefined + var meshclients = getMeshClients(d) + resetMeshClients(d) + var before = " (" + var after = " in der lokalen Wolke)" return function (el) { el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine")) + el.appendChild(document.createTextNode(before)) + el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine")) + el.appendChild(document.createTextNode(after)) el.appendChild(document.createElement("br")) var span = document.createElement("span") span.classList.add("clients") span.textContent = " ".repeat(d.statistics.clients) el.appendChild(span) + + var spanmesh = document.createElement("span") + spanmesh.classList.add("clientsMesh") + spanmesh.textContent = " ".repeat(meshclients - d.statistics.clients) + el.appendChild(spanmesh) + } + } + + function getMeshClients(node) { + var meshclients = node.statistics.clients + + if (!node) + return 0 + + if (node.parsed) + return 0 + + node.parsed = 1 + node.neighbours.forEach(function (neighbour) { + if (!neighbour.link.isVPN && neighbour.node) + meshclients += getMeshClients(neighbour.node) + }) + + return meshclients + } + + function resetMeshClients(node) { + if (!node.parsed) + return + + node.parsed = 0 + + node.neighbours.forEach(function (neighbour) { + if (!neighbour.link.isVPN && neighbour.node) + resetMeshClients(neighbour.node) + }) + + return + } + + function showMeshClients(d) { + if (!d.flags.online) + return undefined + + var meshclients = getMeshClients(d) + resetMeshClients(d) + return function (el) { + el.appendChild(document.createTextNode(meshclients > 0 ? meshclients : "keine")) + el.appendChild(document.createElement("br")) } } @@ -351,7 +407,7 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"], attributeEntry(attributes, "Webseite", showPages(d)) attributeEntry(attributes, "Gewähltes Gateway", showGateway(d, router)) attributeEntry(attributes, "Autom. Updates", showAutoupdate(d)) - attributeEntry(attributes, "Clients", showClients(d)) + attributeEntry(attributes, "Clients", showClients(d), showMeshClients(d)) el.appendChild(attributes) diff --git a/scss/main.scss b/scss/main.scss index e290144..4a7170e 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -143,6 +143,13 @@ table.attributes td { white-space: normal; } +.infobox .clientsMesh { + font-family: "ionicons"; + color: #dbdbdb; + word-spacing: -0.2em; + white-space: normal; +} + .infobox { position: relative; padding: 0.25em 0;