luci-app-cjdns: luci admin support for cjdns-v20.2 (#394)
* luci-app-cjdns: luci admin support for cjdns-v20.2 * adds layer 2 and 3 address display column * fixes switch label pinger * get version from addr string * parse addr string for peerStats publicKey Signed-off-by: William Fleurant <william@netblazr.com> * luci-app-cjdns: bump release, update repo-url and license year Signed-off-by: William Fleurant <william@netblazr.com> * luci-app-cjdns: support views for 17.01 and 18.06 - fixed user/name column - removed latency column - combind peerstats functions - fix css on overview page - table displays with `cbi_update_table` with fallback - columns ordered similar to peerStats.js output - normalized XHR polling to mimic wireless.htm by jow@openwrt Signed-off-by: William Fleurant <william@netblazr.com>
This commit is contained in:
parent
b6efcd5cba
commit
cc7986a774
3 changed files with 83 additions and 127 deletions
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014,2015 Hyperboria.net
|
# Copyright (C) 2014,2018 Hyperboria.net
|
||||||
#
|
#
|
||||||
# You may redistribute this program and/or modify it under the terms of
|
# You may redistribute this program and/or modify it under the terms of
|
||||||
# the GNU General Public License as published by the Free Software Foundation,
|
# the GNU General Public License as published by the Free Software Foundation,
|
||||||
|
@ -18,7 +18,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=luci-app-cjdns
|
PKG_NAME:=luci-app-cjdns
|
||||||
PKG_VERSION:=1.3
|
PKG_VERSION:=1.3
|
||||||
PKG_RELEASE:=5
|
PKG_RELEASE:=6
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-3.0
|
PKG_LICENSE:=GPL-3.0
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ define Package/luci-app-cjdns
|
||||||
CATEGORY:=LuCI
|
CATEGORY:=LuCI
|
||||||
SUBMENU:=3. Applications
|
SUBMENU:=3. Applications
|
||||||
TITLE:=Encrypted near-zero-conf mesh routing protocol
|
TITLE:=Encrypted near-zero-conf mesh routing protocol
|
||||||
URL:=https://github.com/hyperboria/cjdns
|
URL:=https://github.com/cjdelisle/cjdns
|
||||||
MAINTAINER:=Lars Gierth <larsg@systemli.org>
|
MAINTAINER:=Lars Gierth <larsg@systemli.org>
|
||||||
DEPENDS:=+cjdns +luci-base
|
DEPENDS:=+cjdns +luci-base
|
||||||
endef
|
endef
|
||||||
|
|
|
@ -51,15 +51,16 @@ function act_peers()
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,peer in pairs(response.peers) do
|
for i,peer in pairs(response.peers) do
|
||||||
peer.ipv6 = publictoip6(peer.publicKey)
|
local peertable = peerstats_join(peer.addr)
|
||||||
if peer.user == nil then
|
peer.ipv6 = peertable['ipv6']
|
||||||
peer.user = ''
|
peer.version = peertable['version']
|
||||||
uci.cursor():foreach("cjdns", "udp_peer", function(udp_peer)
|
peer.label = peertable['label']
|
||||||
if peer.publicKey == udp_peer.public_key then
|
peer.pubkey = peertable['pubkey']
|
||||||
peer.user = udp_peer.user
|
uci.cursor():foreach("cjdns", "udp_peer", function(udp_peer)
|
||||||
end
|
if peer.pubkey == udp_peer.public_key then
|
||||||
end)
|
peer.user = udp_peer.user
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
peers[#peers + 1] = peer
|
peers[#peers + 1] = peer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,9 +98,13 @@ function act_ping()
|
||||||
luci.http.write_json(response)
|
luci.http.write_json(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
function publictoip6(publicKey)
|
function peerstats_join(addrLine)
|
||||||
local process = io.popen("/usr/bin/publictoip6 " .. publicKey, "r")
|
local pubkey = addrLine:sub(addrLine:len() - 53)
|
||||||
local ipv6 = process:read()
|
local process = io.popen("/usr/bin/publictoip6 " .. pubkey, "r")
|
||||||
process:close()
|
local ipv6 = process:read()
|
||||||
return ipv6
|
local label = 'label'
|
||||||
end
|
process:close()
|
||||||
|
local version = addrLine:match("^(v%w+)%.") or 'v0'
|
||||||
|
local label = addrLine:sub(version:len() + 2, version:len() + 20)
|
||||||
|
return { pubkey=pubkey, ipv6=ipv6, label=label, version=version }
|
||||||
|
end
|
|
@ -1,116 +1,67 @@
|
||||||
<script type="text/javascript">//<![CDATA[
|
<script type="text/javascript">//<![CDATA[
|
||||||
|
/* 75lb/usage-stats */
|
||||||
var peersURI = '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "peers")%>';
|
function lbbytes (bytes){
|
||||||
var updatePeers = function(x, peers) {
|
var kilobyte = 1024,
|
||||||
var table = document.getElementById('cjdns-peerings');
|
megabyte = kilobyte * 1024,
|
||||||
while (table.rows.length > 1) {
|
gigabyte = megabyte * 1024,
|
||||||
table.deleteRow(1);
|
terabyte = gigabyte * 1024;
|
||||||
|
if ((bytes >= 0) && (bytes < kilobyte)) {
|
||||||
|
return bytes + " B";
|
||||||
|
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
||||||
|
return (bytes / kilobyte).toFixed(2) + " KB";
|
||||||
|
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
|
||||||
|
return (bytes / megabyte).toFixed(2) + " MB";
|
||||||
|
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
|
||||||
|
return (bytes / gigabyte).toFixed(2) + " GB";
|
||||||
|
} else if (bytes >= terabyte) {
|
||||||
|
return (bytes / terabyte).toFixed(2) + " TB";
|
||||||
|
} else {
|
||||||
|
return bytes + " B";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((peers) && ((peers.err) || (typeof peers.length === 'undefined'))) {
|
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "peers")%>', null,
|
||||||
var errpeer = (peers.err)
|
function(x, st) {
|
||||||
? 'Socket Error: unable to connect to Admin API'
|
var table = document.getElementById('cjdns-peerings');
|
||||||
: 'No active peers';
|
if (st && table) {
|
||||||
var row = table.insertRow(-1);
|
var rows = [];
|
||||||
row.className = 'cbi-section-table-row';
|
st.forEach(function(peer) {
|
||||||
var cell = row.insertCell(-1);
|
rows.push([
|
||||||
cell.colSpan = 7;
|
peer.lladdr,
|
||||||
cell.textContent = errpeer;
|
peer.ipv6,
|
||||||
return;
|
peer.version,
|
||||||
};
|
((peer.isIncoming === 0) ? 'outgoing, ' : 'incoming, ').concat(peer.state.toLowerCase()),
|
||||||
|
lbbytes(peer.bytesIn) + ' / ' + lbbytes(peer.bytesOut),
|
||||||
|
(peer.user == null) ? '-' : peer.user
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
peers.forEach(function(peer, i) {
|
if (typeof(cbi_update_table) == 'function') {
|
||||||
if (peer.user == null) {
|
cbi_update_table(table, rows, '<em><%:Querying Admin API%></em>');
|
||||||
var user = '';
|
} else {
|
||||||
} else if (peer.user == 'Local Peers') {
|
while (table.rows.length > 1) { table.deleteRow(1); }
|
||||||
var user = 'beacon';
|
rows.forEach(function(peer) {
|
||||||
} else {
|
var row = table.insertRow(-1);
|
||||||
var user = peer.user;
|
peer.forEach(function(x) { row.insertCell(-1).textContent = x; });
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (peer.isIncoming === 0) {
|
);
|
||||||
var interface = 'outgoing';
|
|
||||||
} else {
|
|
||||||
var interface = 'incoming';
|
|
||||||
}
|
|
||||||
|
|
||||||
var status = interface + ', ' + peer.state.toLowerCase();
|
|
||||||
|
|
||||||
if (peer.version === 0) {
|
|
||||||
var version = '-';
|
|
||||||
} else {
|
|
||||||
var version = 'v' + peer.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rxtx = lbbytes(peer.bytesIn) + ' / ' + lbbytes(peer.bytesOut);
|
|
||||||
|
|
||||||
var row = table.insertRow(-1);
|
|
||||||
row.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
|
|
||||||
row.insertCell(-1).textContent = user;
|
|
||||||
row.insertCell(-1).textContent = peer.ipv6;
|
|
||||||
row.insertCell(-1).textContent = status;
|
|
||||||
row.insertCell(-1).textContent = version;
|
|
||||||
row.insertCell(-1).textContent = rxtx;
|
|
||||||
var latencyCell = row.insertCell(-1);
|
|
||||||
latencyCell.textContent = 'waiting';
|
|
||||||
|
|
||||||
var pingURI = '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "ping")%>';
|
|
||||||
var timeout = 2000;
|
|
||||||
XHR.get(pingURI, { label: peer.switchLabel, timeout: timeout }, function(x, pong) {
|
|
||||||
var pongrsp = ((pong.err == "ai:recv > timeout") || (pong == "undefined") || (pong.ms >= timeout))
|
|
||||||
? '> ' + timeout + ' ms'
|
|
||||||
: pong.ms + ' ms';
|
|
||||||
latencyCell.textContent = pongrsp;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
XHR.get(peersURI, null, updatePeers);
|
|
||||||
XHR.poll(5, peersURI, null, updatePeers);
|
|
||||||
|
|
||||||
//]]></script>
|
//]]></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<div class="cbi-map">
|
||||||
<%# Author: [GitHub/75lb] -%>
|
<fieldset class="cbi-section">
|
||||||
//<![CDATA[
|
<legend><%:Active cjdns peers%></legend>
|
||||||
function lbbytes (bytes){
|
<table class="table" id="cjdns-peerings">
|
||||||
|
<tr class="tr table-titles">
|
||||||
var kilobyte = 1024,
|
<th class="th nowrap">Address</th>
|
||||||
megabyte = kilobyte * 1024,
|
<th class="th nowrap">IPv6</th>
|
||||||
gigabyte = megabyte * 1024,
|
<th class="th nowrap">Version</th>
|
||||||
terabyte = gigabyte * 1024;
|
<th class="th nowrap">Status</th>
|
||||||
|
<th class="th nowrap">Rx / Tx</th>
|
||||||
if ((bytes >= 0) && (bytes < kilobyte)) {
|
<th class="th nowrap">User/Name</th>
|
||||||
return bytes + " B";
|
</tr>
|
||||||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
</table>
|
||||||
return (bytes / kilobyte).toFixed(2) + " KB";
|
</fieldset>
|
||||||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
|
</div>
|
||||||
return (bytes / megabyte).toFixed(2) + " MB";
|
|
||||||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
|
|
||||||
return (bytes / gigabyte).toFixed(2) + " GB";
|
|
||||||
} else if (bytes >= terabyte) {
|
|
||||||
return (bytes / terabyte).toFixed(2) + " TB";
|
|
||||||
} else {
|
|
||||||
return bytes + " B";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//]]>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<fieldset class="cbi-section">
|
|
||||||
<legend>Active cjdns peers</legend>
|
|
||||||
<table class="cbi-section-table" id="cjdns-peerings">
|
|
||||||
<tr class="cbi-section-table-titles">
|
|
||||||
<th class="cbi-section-table-cell">User/Name</th>
|
|
||||||
<th class="cbi-section-table-cell">IPv6</th>
|
|
||||||
<th class="cbi-section-table-cell">Status</th>
|
|
||||||
<th class="cbi-section-table-cell">Version</th>
|
|
||||||
<th class="cbi-section-table-cell">Rx / Tx</th>
|
|
||||||
<th class="cbi-section-table-cell">Latency</th>
|
|
||||||
</tr>
|
|
||||||
<tr class="cbi-section-table-row">
|
|
||||||
<td colspan="7">Querying Admin API</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
|
Loading…
Reference in a new issue