2017-02-04 17:59:21 +00:00
|
|
|
define(['sorttable', 'virtual-dom', 'chroma-js', 'moment', 'helper'],
|
|
|
|
function (SortTable, V, chroma, moment, helper) {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var a = document.createElement('a');
|
|
|
|
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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
el.classList.add(d.flags.unseen ? 'unseen' : (d.flags.online ? 'online' : 'offline'));
|
2017-02-12 21:18:23 +00:00
|
|
|
el.textContent = _.t((d.flags.online ? 'node.lastOnline' : 'node.lastOffline'), {
|
|
|
|
time: d.lastseen.fromNow(),
|
|
|
|
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss')
|
|
|
|
});
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
2015-04-11 11:48:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirmware(d) {
|
2017-01-29 23:51:08 +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
|
|
|
|
2017-01-29 23:51:08 +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) {
|
2017-01-29 23:51:08 +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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('uptime' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2015-04-11 11:48:16 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
return moment.duration(d.statistics.uptime, 'seconds').humanize();
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-06 23:00:30 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
function showFirstseen(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('firstseen' in d)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
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) {
|
2017-01-28 14:33:13 +00:00
|
|
|
el.appendChild(document.createTextNode(d.statistics.clients > 0 ? d.statistics.clients : _.t('none')));
|
2017-01-29 23:51:08 +00:00
|
|
|
el.appendChild(document.createElement('br'));
|
2015-07-18 14:28:07 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('clients');
|
2017-02-04 19:01:49 +00:00
|
|
|
span.innerHTML = '<i class="ion-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) {
|
2017-01-29 23:51:08 +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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var link = !ip.startsWith('fe80:');
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (i > 0) {
|
2017-01-29 23:51:08 +00:00
|
|
|
el.appendChild(document.createElement('br'));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-30 01:20:43 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (link) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var a = document.createElement('a');
|
|
|
|
a.href = 'http://[' + ip + ']/';
|
2016-05-22 12:51:30 +00:00
|
|
|
a.textContent = ip;
|
|
|
|
el.appendChild(a);
|
|
|
|
} else {
|
|
|
|
el.appendChild(document.createTextNode(ip));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
|
2017-02-12 21:18:23 +00:00
|
|
|
function showBar(v, width, warning) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var span = document.createElement('span');
|
|
|
|
span.classList.add('bar');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var bar = document.createElement('span');
|
2017-02-12 21:18:23 +00:00
|
|
|
bar.style.width = (width * 100) + '%';
|
|
|
|
if (warning) {
|
2017-01-29 23:51:08 +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
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var label = document.createElement('label');
|
2017-02-12 21:18:23 +00:00
|
|
|
label.textContent = v;
|
2016-05-22 12:51:30 +00:00
|
|
|
span.appendChild(label);
|
|
|
|
|
|
|
|
return span;
|
2016-02-25 13:44:11 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
function showLoad(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('loadavg' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (el) {
|
2017-02-12 21:18:23 +00:00
|
|
|
var value = d.statistics.loadavg.toFixed(2);
|
|
|
|
var width = d.statistics.loadavg % 1;
|
|
|
|
var warning = false;
|
|
|
|
if (d.statistics.loadavg >= d.nodeinfo.hardware.nproc) {
|
|
|
|
warning = true;
|
|
|
|
}
|
|
|
|
el.appendChild(showBar(value, width, warning));
|
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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (!('memory_usage' in d.statistics)) {
|
2016-05-22 12:51:30 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
2016-02-25 13:44:11 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
return function (el) {
|
2017-02-12 21:18:23 +00:00
|
|
|
var value = Math.round(d.statistics.memory_usage * 100) + ' %';
|
|
|
|
var width = d.statistics.memory_usage;
|
|
|
|
var warning = false;
|
|
|
|
if (d.statistics.memory_usage >= 0.8) {
|
|
|
|
warning = true;
|
|
|
|
}
|
|
|
|
el.appendChild(showBar(value, width, warning));
|
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 showAutoupdate(d) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var au = helper.dictGet(d.nodeinfo, ['software', 'autoupdater']);
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!au) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2017-02-04 15:14:24 +00:00
|
|
|
return au.enabled ? _.t('node.activated', { branch: au.branch }) : _.t('node.deactivated');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showStatImg(o, d) {
|
|
|
|
var subst = {};
|
2017-01-28 14:33:13 +00:00
|
|
|
subst['{NODE_ID}'] = d.nodeinfo.node_id ? d.nodeinfo.node_id : _.t('unknown');
|
|
|
|
subst['{NODE_NAME}'] = d.nodeinfo.hostname ? d.nodeinfo.hostname.replace(/[^a-z0-9\-]/ig, '_') : _.t('unknown');
|
2017-01-29 23:51:08 +00:00
|
|
|
subst['{TIME}'] = d.lastseen.format('DDMMYYYYHmmss');
|
2017-01-28 14:33:13 +00:00
|
|
|
subst['{LOCALE}'] = _.locale();
|
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) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var linkScale = chroma.scale(chroma.bezier(['#04C714', '#FF5500', '#F02311'])).domain([1, 5]);
|
2017-02-04 19:01:49 +00:00
|
|
|
|
2017-02-04 17:59:21 +00:00
|
|
|
function renderNeighbourRow(n) {
|
|
|
|
var icons = [];
|
|
|
|
var name = [];
|
|
|
|
var unknown = !(n.node);
|
|
|
|
|
2017-02-04 19:01:49 +00:00
|
|
|
icons.push(V.h('span', { className: n.incoming ? 'ion-arrow-left-c' : 'ion-arrow-right-c' }));
|
2017-02-04 17:59:21 +00:00
|
|
|
if (!unknown && helper.hasLocation(n.node)) {
|
|
|
|
icons.push(V.h('span', { className: 'ion-location' }));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unknown) {
|
|
|
|
name.push(V.h('a', { href: router.getUrl({ n: n.node.nodeinfo.node_id }), onclick: router.node(n.node), className: 'online' }, n.node.nodeinfo.hostname));
|
|
|
|
} else {
|
|
|
|
name.push(n.link.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
var td1 = V.h('td', icons);
|
|
|
|
var td2 = V.h('td', name);
|
2017-02-04 19:01:49 +00:00
|
|
|
var td3 = V.h('td', (n.node.statistics.clients ? n.node.statistics.clients.toString() : '0'));
|
|
|
|
var td4 = V.h('td', { style: { color: linkScale(n.link.tq).hex() } }, helper.showTq(n.link));
|
|
|
|
var td5 = V.h('td', helper.showDistance(n.link));
|
2017-02-04 17:59:21 +00:00
|
|
|
|
2017-02-04 19:01:49 +00:00
|
|
|
return V.h('tr', [td1, td2, td3, td4, td5]);
|
2017-02-04 17:59:21 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var h2 = document.createElement('h2');
|
2016-05-22 12:51:30 +00:00
|
|
|
h2.textContent = d.nodeinfo.hostname;
|
|
|
|
el.appendChild(h2);
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var attributes = document.createElement('table');
|
|
|
|
attributes.classList.add('attributes');
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.status', showStatus(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.gateway', d.flags.gateway ? 'ja' : null);
|
|
|
|
helper.attributeEntry(attributes, 'node.coordinates', showGeoURI(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
2017-01-21 00:53:55 +00:00
|
|
|
if (config.nodeInfobox && config.nodeInfobox.contact) {
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.contact', helper.dictGet(d.nodeinfo, ['owner', 'contact']));
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.hardware', helper.dictGet(d.nodeinfo, ['hardware', 'model']));
|
|
|
|
helper.attributeEntry(attributes, 'node.primaryMac', helper.dictGet(d.nodeinfo, ['network', 'mac']));
|
|
|
|
helper.attributeEntry(attributes, 'node.id', helper.dictGet(d.nodeinfo, ['node_id']));
|
|
|
|
helper.attributeEntry(attributes, 'node.firmware', showFirmware(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.site', showSite(d, config));
|
|
|
|
helper.attributeEntry(attributes, 'node.uptime', showUptime(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.firstSeen', showFirstseen(d));
|
2017-01-21 00:53:55 +00:00
|
|
|
if (config.nodeInfobox && config.nodeInfobox.hardwareUsage) {
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.systemLoad', showLoad(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.ram', showRAM(d));
|
2017-01-21 00:53:55 +00:00
|
|
|
}
|
2017-01-28 14:33:13 +00:00
|
|
|
helper.attributeEntry(attributes, 'node.ipAddresses', showIPs(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.selectedGateway', helper.dictGet(d.statistics, ['gateway']));
|
|
|
|
helper.attributeEntry(attributes, 'node.update', showAutoupdate(d));
|
|
|
|
helper.attributeEntry(attributes, 'node.clients', showClients(d));
|
2016-05-22 12:51:30 +00:00
|
|
|
|
|
|
|
el.appendChild(attributes);
|
|
|
|
|
|
|
|
if (d.neighbours.length > 0) {
|
2017-01-29 23:51:08 +00:00
|
|
|
var h3 = document.createElement('h3');
|
2017-01-28 14:33:13 +00:00
|
|
|
h3.textContent = _.t('node.link', d.neighbours.length) + '(' + d.neighbours.length + ')';
|
2016-05-22 12:51:30 +00:00
|
|
|
el.appendChild(h3);
|
|
|
|
|
2017-02-04 17:59:21 +00:00
|
|
|
var headings = [{
|
|
|
|
name: ''
|
|
|
|
}, {
|
|
|
|
name: 'node.nodes',
|
|
|
|
sort: function (a, b) {
|
|
|
|
return a.node.nodeinfo.hostname.localeCompare(b.node.nodeinfo.hostname);
|
|
|
|
},
|
|
|
|
reverse: false
|
2017-02-04 19:01:49 +00:00
|
|
|
}, {
|
|
|
|
name: 'node.clients',
|
|
|
|
class: 'ion-people',
|
|
|
|
sort: function (a, b) {
|
|
|
|
return ('clients' in a.node.statistics ? a.node.statistics.clients : -1) -
|
|
|
|
('clients' in b.node.statistics ? b.node.statistics.clients : -1);
|
|
|
|
},
|
|
|
|
reverse: true
|
2017-02-04 17:59:21 +00:00
|
|
|
}, {
|
|
|
|
name: 'node.tq',
|
2017-02-04 19:01:49 +00:00
|
|
|
class: 'ion-connection-bars',
|
2017-02-04 17:59:21 +00:00
|
|
|
sort: function (a, b) {
|
|
|
|
return a.link.tq - b.link.tq;
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}, {
|
|
|
|
name: 'node.distance',
|
2017-02-04 19:01:49 +00:00
|
|
|
class: 'ion-arrow-resize',
|
2017-02-04 17:59:21 +00:00
|
|
|
sort: function (a, b) {
|
|
|
|
return (a.link.distance === undefined ? -1 : a.link.distance) -
|
|
|
|
(b.link.distance === undefined ? -1 : b.link.distance);
|
|
|
|
},
|
|
|
|
reverse: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
var table = new SortTable(headings, 1, renderNeighbourRow);
|
|
|
|
table.el.classList.add('node-links');
|
|
|
|
table.setData(d.neighbours);
|
|
|
|
|
|
|
|
el.appendChild(table.el);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2017-02-05 22:15:50 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
};
|
|
|
|
});
|