2016-12-26 02:44:59 +00:00
|
|
|
define(["chroma-js", "moment/moment", "tablesort", "helper", "moment/locale/de"],
|
2016-05-26 23:34:42 +00:00
|
|
|
function (chroma, moment, Tablesort, helper) {
|
2016-05-27 21:59:01 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showGeoURI(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
if (!helper.hasLocation(d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (el) {
|
|
|
|
var a = document.createElement("a");
|
2017-01-17 16:00:03 +00:00
|
|
|
a.textContent = Number(d.nodeinfo.location.latitude.toFixed(6)) + ", " + Number(d.nodeinfo.location.longitude.toFixed(6));
|
|
|
|
a.href = "geo:" + d.nodeinfo.location.latitude + "," + d.nodeinfo.location.longitude;
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(a);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function showStatus(d) {
|
|
|
|
return function (el) {
|
|
|
|
el.classList.add(d.flags.unseen ? "unseen" : (d.flags.online ? "online" : "offline"));
|
|
|
|
if (d.flags.online) {
|
|
|
|
el.textContent = "online, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")";
|
|
|
|
} else {
|
|
|
|
el.textContent = "offline, letzte Nachricht " + d.lastseen.fromNow() + " (" + d.lastseen.format("DD.MM.YYYY, H:mm:ss") + ")";
|
|
|
|
}
|
|
|
|
};
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirmware(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var release = helper.dictGet(d.nodeinfo, ["software", "firmware", "release"]);
|
|
|
|
var base = helper.dictGet(d.nodeinfo, ["software", "firmware", "base"]);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
if (release === null || base === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return release + " / " + base;
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showSite(d, config) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var site = helper.dictGet(d.nodeinfo, ["system", "site_code"]);
|
2016-05-22 12:51:30 +00:00
|
|
|
var rt = site;
|
|
|
|
if (config.siteNames) {
|
|
|
|
config.siteNames.forEach(function (t) {
|
|
|
|
if (site === t.site) {
|
|
|
|
rt = t.name;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return rt;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showUptime(d) {
|
|
|
|
if (!("uptime" in d.statistics)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return moment.duration(d.statistics.uptime, "seconds").humanize();
|
|
|
|
}
|
2015-07-06 23:00:30 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirstseen(d) {
|
|
|
|
if (!("firstseen" in d)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return d.firstseen.fromNow(true);
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showClients(d) {
|
|
|
|
if (!d.flags.online) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
|
|
|
el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : "keine"));
|
|
|
|
el.appendChild(document.createElement("br"));
|
2015-07-18 14:28:07 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var span = document.createElement("span");
|
|
|
|
span.classList.add("clients");
|
2016-05-26 23:34:42 +00:00
|
|
|
span.innerHTML = "<i class=\"ion-ios-person\"></i>".repeat(d.statistics.clients);
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(span);
|
|
|
|
};
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showIPs(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var ips = helper.dictGet(d.nodeinfo, ["network", "addresses"]);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (ips === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
ips.sort();
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
|
|
|
ips.forEach(function (ip, i) {
|
|
|
|
var link = !ip.startsWith("fe80:");
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (i > 0) {
|
|
|
|
el.appendChild(document.createElement("br"));
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (link) {
|
|
|
|
var a = document.createElement("a");
|
|
|
|
a.href = "http://[" + ip + "]/";
|
|
|
|
a.textContent = ip;
|
|
|
|
el.appendChild(a);
|
|
|
|
} else {
|
|
|
|
el.appendChild(document.createTextNode(ip));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
2016-06-03 17:44:07 +00:00
|
|
|
function showBar(v) {
|
2016-05-22 11:23:43 +00:00
|
|
|
var span = document.createElement("span");
|
2016-06-03 17:44:07 +00:00
|
|
|
span.classList.add("bar");
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var bar = document.createElement("span");
|
|
|
|
bar.style.width = (v * 100) + "%";
|
|
|
|
span.appendChild(bar);
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var label = document.createElement("label");
|
|
|
|
label.textContent = (Math.round(v * 100)) + " %";
|
|
|
|
span.appendChild(label);
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return span;
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2017-01-07 15:09:35 +00:00
|
|
|
function showLoadBar(v, p) {
|
2016-05-22 12:51:30 +00:00
|
|
|
var span = document.createElement("span");
|
2016-06-03 17:44:07 +00:00
|
|
|
span.classList.add("bar");
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
var bar = document.createElement("span");
|
2017-01-07 15:09:35 +00:00
|
|
|
bar.style.width = ((v * 100) % 100) + "%";
|
|
|
|
if (v >= p) {
|
2016-06-03 17:44:07 +00:00
|
|
|
span.classList.add("warning");
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-06-03 17:44:07 +00:00
|
|
|
span.appendChild(bar);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
var label = document.createElement("label");
|
|
|
|
label.textContent = (v);
|
|
|
|
span.appendChild(label);
|
|
|
|
|
|
|
|
return span;
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
function showLoad(d) {
|
|
|
|
if (!("loadavg" in d.statistics)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (el) {
|
2017-01-07 15:09:35 +00:00
|
|
|
el.appendChild(showLoadBar(d.statistics.loadavg.toFixed(2), d.nodeinfo.hardware.nproc));
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showRAM(d) {
|
|
|
|
if (!("memory_usage" in d.statistics)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
2016-06-03 17:44:07 +00:00
|
|
|
el.appendChild(showBar(d.statistics.memory_usage));
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showPages(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var webpages = helper.dictGet(d.nodeinfo, ["pages"]);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (webpages === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
webpages.sort();
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
|
|
|
webpages.forEach(function (webpage, i) {
|
|
|
|
if (i > 0) {
|
|
|
|
el.appendChild(document.createElement("br"));
|
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var a = document.createElement("span");
|
|
|
|
var link = document.createElement("a");
|
|
|
|
link.href = webpage;
|
|
|
|
if (webpage.search(/^https:\/\//i) !== -1) {
|
|
|
|
var lock = document.createElement("span");
|
2016-05-26 23:34:42 +00:00
|
|
|
lock.classList.add("ion-android-lock");
|
2016-05-22 12:51:30 +00:00
|
|
|
a.appendChild(lock);
|
|
|
|
var t1 = document.createTextNode(" ");
|
|
|
|
a.appendChild(t1);
|
|
|
|
link.textContent = webpage.replace(/^https:\/\//i, "");
|
2016-02-25 13:50:40 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
else {
|
|
|
|
link.textContent = webpage.replace(/^http:\/\//i, "");
|
|
|
|
}
|
|
|
|
a.appendChild(link);
|
|
|
|
el.appendChild(a);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function showAutoupdate(d) {
|
2016-05-26 16:37:24 +00:00
|
|
|
var au = helper.dictGet(d.nodeinfo, ["software", "autoupdater"]);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!au) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return au.enabled ? "aktiviert (" + au.branch + ")" : "deaktiviert";
|
|
|
|
}
|
|
|
|
|
|
|
|
function showStatImg(o, d) {
|
|
|
|
var subst = {};
|
|
|
|
subst["{NODE_ID}"] = d.nodeinfo.node_id ? d.nodeinfo.node_id : "unknown";
|
2016-05-26 16:37:24 +00:00
|
|
|
subst["{NODE_NAME}"] = d.nodeinfo.hostname ? d.nodeinfo.hostname.replace(/[^a-z0-9\-]/ig, "_") : "unknown";
|
2016-06-22 01:15:53 +00:00
|
|
|
subst["{TIME}"] = d.lastseen.format("DDMMYYYYHmmss");
|
2016-05-26 16:37:24 +00:00
|
|
|
return helper.showStat(o, subst);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-25 10:21:09 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (config, el, router, d) {
|
2016-05-26 23:34:42 +00:00
|
|
|
var linkScale = chroma.scale(chroma.bezier(["#04C714", "#FF5500", "#F02311"])).domain([1, 5]);
|
2016-05-22 12:51:30 +00:00
|
|
|
var h2 = document.createElement("h2");
|
|
|
|
h2.textContent = d.nodeinfo.hostname;
|
|
|
|
el.appendChild(h2);
|
|
|
|
|
|
|
|
var attributes = document.createElement("table");
|
|
|
|
attributes.classList.add("attributes");
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
helper.attributeEntry(attributes, "Status", showStatus(d));
|
|
|
|
helper.attributeEntry(attributes, "Gateway", d.flags.gateway ? "ja" : null);
|
|
|
|
helper.attributeEntry(attributes, "Koordinaten", showGeoURI(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
if (config.showContact) {
|
2016-05-26 16:37:24 +00:00
|
|
|
helper.attributeEntry(attributes, "Kontakt", helper.dictGet(d.nodeinfo, ["owner", "contact"]));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
helper.attributeEntry(attributes, "Hardware", helper.dictGet(d.nodeinfo, ["hardware", "model"]));
|
|
|
|
helper.attributeEntry(attributes, "Primäre MAC", helper.dictGet(d.nodeinfo, ["network", "mac"]));
|
|
|
|
helper.attributeEntry(attributes, "Node ID", helper.dictGet(d.nodeinfo, ["node_id"]));
|
|
|
|
helper.attributeEntry(attributes, "Firmware", showFirmware(d));
|
|
|
|
helper.attributeEntry(attributes, "Site", showSite(d, config));
|
|
|
|
helper.attributeEntry(attributes, "Uptime", showUptime(d));
|
|
|
|
helper.attributeEntry(attributes, "Teil des Netzes", showFirstseen(d));
|
|
|
|
helper.attributeEntry(attributes, "Systemlast", showLoad(d));
|
|
|
|
helper.attributeEntry(attributes, "Arbeitsspeicher", showRAM(d));
|
|
|
|
helper.attributeEntry(attributes, "IP Adressen", showIPs(d));
|
|
|
|
helper.attributeEntry(attributes, "Webseite", showPages(d));
|
|
|
|
helper.attributeEntry(attributes, "Gewähltes Gateway", helper.dictGet(d.statistics, ["gateway"]));
|
|
|
|
helper.attributeEntry(attributes, "Autom. Updates", showAutoupdate(d));
|
|
|
|
helper.attributeEntry(attributes, "Clients", showClients(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
el.appendChild(attributes);
|
|
|
|
|
|
|
|
if (config.nodeInfos) {
|
|
|
|
config.nodeInfos.forEach(function (nodeInfo) {
|
|
|
|
var h4 = document.createElement("h4");
|
|
|
|
h4.textContent = nodeInfo.name;
|
|
|
|
el.appendChild(h4);
|
|
|
|
el.appendChild(showStatImg(nodeInfo, d));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d.neighbours.length > 0) {
|
|
|
|
var h3 = document.createElement("h3");
|
|
|
|
h3.textContent = "Links (" + d.neighbours.length + ")";
|
|
|
|
el.appendChild(h3);
|
|
|
|
|
|
|
|
var table = document.createElement("table");
|
|
|
|
var thead = document.createElement("thead");
|
2016-02-18 17:42:42 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
var tr = document.createElement("tr");
|
|
|
|
var th1 = document.createElement("th");
|
|
|
|
th1.textContent = " ";
|
|
|
|
tr.appendChild(th1);
|
|
|
|
|
|
|
|
var th2 = document.createElement("th");
|
|
|
|
th2.textContent = "Knoten";
|
|
|
|
th2.classList.add("sort-default");
|
|
|
|
tr.appendChild(th2);
|
|
|
|
|
|
|
|
var th3 = document.createElement("th");
|
|
|
|
th3.textContent = "TQ";
|
|
|
|
tr.appendChild(th3);
|
|
|
|
|
|
|
|
var th4 = document.createElement("th");
|
2016-05-24 21:21:46 +00:00
|
|
|
th4.textContent = "Entfernung";
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(th4);
|
|
|
|
|
|
|
|
thead.appendChild(tr);
|
|
|
|
table.appendChild(thead);
|
|
|
|
|
|
|
|
var tbody = document.createElement("tbody");
|
|
|
|
|
|
|
|
d.neighbours.forEach(function (d) {
|
|
|
|
var unknown = !(d.node);
|
|
|
|
var tr = document.createElement("tr");
|
|
|
|
|
|
|
|
var td1 = document.createElement("td");
|
2016-05-26 23:34:42 +00:00
|
|
|
|
|
|
|
var direction = document.createElement("span");
|
|
|
|
direction.classList.add(d.incoming ? "ion-ios-arrow-thin-left" : "ion-ios-arrow-thin-right");
|
|
|
|
td1.appendChild(direction);
|
|
|
|
|
|
|
|
if (!unknown && helper.hasLocation(d.node)) {
|
|
|
|
var span = document.createElement("span");
|
2016-06-03 17:44:07 +00:00
|
|
|
span.classList.add("ion-location");
|
2016-05-26 23:34:42 +00:00
|
|
|
td1.appendChild(span);
|
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(td1);
|
|
|
|
|
|
|
|
var td2 = document.createElement("td");
|
2016-06-03 19:04:48 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!unknown) {
|
2016-06-03 19:04:48 +00:00
|
|
|
var a1 = document.createElement("a");
|
|
|
|
a1.textContent = d.node.nodeinfo.hostname;
|
|
|
|
a1.classList.add("online");
|
2016-05-22 12:51:30 +00:00
|
|
|
a1.href = "#";
|
2016-06-03 19:04:48 +00:00
|
|
|
a1.onclick = router.node(d.node);
|
|
|
|
td2.appendChild(a1);
|
|
|
|
} else {
|
|
|
|
td2.textContent = d.id;
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-06-22 01:15:53 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(td2);
|
|
|
|
|
|
|
|
var td3 = document.createElement("td");
|
2016-05-26 23:34:42 +00:00
|
|
|
td3.textContent = helper.showTq(d.link);
|
|
|
|
td3.style.color = linkScale(d.link.tq).hex();
|
2016-05-22 12:51:30 +00:00
|
|
|
tr.appendChild(td3);
|
|
|
|
|
|
|
|
var td4 = document.createElement("td");
|
2016-05-26 23:34:42 +00:00
|
|
|
td4.textContent = helper.showDistance(d.link);
|
2016-05-24 21:21:46 +00:00
|
|
|
td4.setAttribute("data-sort", d.link.distance !== undefined ? -d.link.distance : 1);
|
|
|
|
tr.appendChild(td4);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
tbody.appendChild(tr);
|
|
|
|
});
|
|
|
|
|
|
|
|
table.appendChild(tbody);
|
2016-05-26 23:34:42 +00:00
|
|
|
table.classList.add("node-links");
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2016-05-26 16:37:24 +00:00
|
|
|
Tablesort(table);
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
el.appendChild(table);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|