luci-app-cjdns: luci admin support for cjdns-v20.2 (#394)
authorWilliam Fleurant <meshnet@protonmail.com>
Mon, 3 Sep 2018 00:50:34 +0000 (00:50 +0000)
committerGitHub <noreply@github.com>
Mon, 3 Sep 2018 00:50:34 +0000 (00:50 +0000)
* 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>
luci-app-cjdns/Makefile
luci-app-cjdns/luasrc/controller/cjdns.lua
luci-app-cjdns/luasrc/view/cjdns/status.htm

index 793b4ecd4f30a776fd89b71b881ccd6009f84a76..9c92151ed89554cd0f349d45e6c865609d91745e 100644 (file)
@@ -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
 # 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_VERSION:=1.3
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_LICENSE:=GPL-3.0
 
@@ -29,7 +29,7 @@ define Package/luci-app-cjdns
        CATEGORY:=LuCI
        SUBMENU:=3. Applications
        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>
        DEPENDS:=+cjdns +luci-base
 endef
index 63644cbad9705f2f5849198f975ba7882c088a9b..362d84a76499131501e2eb7c5a7f788b9cef9fd7 100644 (file)
@@ -51,15 +51,16 @@ function act_peers()
                end
 
                for i,peer in pairs(response.peers) do
-                       peer.ipv6 = publictoip6(peer.publicKey)
-                       if peer.user == nil then
-                               peer.user = ''
-                               uci.cursor():foreach("cjdns", "udp_peer", function(udp_peer)
-                                       if peer.publicKey == udp_peer.public_key then
-                                               peer.user = udp_peer.user
-                                       end
-                               end)
-                       end
+                       local peertable = peerstats_join(peer.addr)
+                       peer.ipv6 = peertable['ipv6']
+                       peer.version = peertable['version']
+                       peer.label = peertable['label']
+                       peer.pubkey = peertable['pubkey']
+                       uci.cursor():foreach("cjdns", "udp_peer", function(udp_peer)
+                               if peer.pubkey == udp_peer.public_key then
+                                       peer.user = udp_peer.user
+                               end
+                       end)
                        peers[#peers + 1] = peer
                end
 
@@ -97,9 +98,13 @@ function act_ping()
        luci.http.write_json(response)
 end
 
-function publictoip6(publicKey)
-       local process = io.popen("/usr/bin/publictoip6 " .. publicKey, "r")
-       local ipv6    = process:read()
-       process:close()
-       return ipv6
-end
+function peerstats_join(addrLine)
+    local pubkey = addrLine:sub(addrLine:len() - 53)
+    local process = io.popen("/usr/bin/publictoip6 " .. pubkey, "r")
+    local ipv6 = process:read()
+    local label = 'label'
+    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
\ No newline at end of file
index 9d43e85a8dce2ab4571bcc638a341eb62762a31d..3da5d7c2cc7b936996196e1b60948ae81981fded 100644 (file)
 <script type="text/javascript">//<![CDATA[
-
-       var peersURI = '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "peers")%>';
-       var updatePeers = function(x, peers) {
-               var table = document.getElementById('cjdns-peerings');
-               while (table.rows.length > 1) {
-                       table.deleteRow(1);
+       /* 75lb/usage-stats */
+       function lbbytes (bytes){
+               var kilobyte = 1024,
+                       megabyte = kilobyte * 1024,
+                       gigabyte = megabyte * 1024,
+                       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'))) {
-                       var errpeer = (peers.err)
-                                               ? 'Socket Error: unable to connect to Admin API'
-                                               : 'No active peers';
-                       var row = table.insertRow(-1);
-                       row.className = 'cbi-section-table-row';
-                       var cell = row.insertCell(-1);
-                       cell.colSpan = 7;
-                       cell.textContent = errpeer;
-                       return;
-               };
-
-               peers.forEach(function(peer, i) {
-                       if (peer.user == null) {
-                               var user = '';
-                       } else if (peer.user == 'Local Peers') {
-                               var user = 'beacon';
-                       } else {
-                               var user = peer.user;
-                       }
-
-                       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;
+       XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "cjdns", "peers")%>', null,
+               function(x, st) {
+                       var table = document.getElementById('cjdns-peerings');
+                       if (st && table) {
+                               var rows = [];
+                               st.forEach(function(peer) {
+                                       rows.push([
+                                               peer.lladdr,
+                                               peer.ipv6,
+                                               peer.version,
+                                               ((peer.isIncoming === 0) ? 'outgoing, ' : 'incoming, ').concat(peer.state.toLowerCase()),
+                                               lbbytes(peer.bytesIn) + ' / ' + lbbytes(peer.bytesOut),
+                                               (peer.user == null) ? '-' : peer.user
+                                       ]);
+                               });
+
+                               if (typeof(cbi_update_table) == 'function') {
+                                       cbi_update_table(table, rows, '<em><%:Querying Admin API%></em>');
+                               } else {
+                                       while (table.rows.length > 1) { table.deleteRow(1); }
+                                       rows.forEach(function(peer) {
+                                               var row = table.insertRow(-1);
+                                               peer.forEach(function(x) { row.insertCell(-1).textContent = x; });
+                                       });
+                               }
                        }
-
-                       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 type="text/javascript">
-<%# Author: [GitHub/75lb] -%>
-//<![CDATA[
-function lbbytes (bytes){
-
-       var kilobyte = 1024,
-           megabyte = kilobyte * 1024,
-           gigabyte = megabyte * 1024,
-           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";
-       }
-};
-//]]>
-</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>
+<div class="cbi-map">
+       <fieldset class="cbi-section">
+               <legend><%:Active cjdns peers%></legend>
+               <table class="table" id="cjdns-peerings">
+                       <tr class="tr table-titles">
+                               <th class="th nowrap">Address</th>
+                               <th class="th nowrap">IPv6</th>
+                               <th class="th nowrap">Version</th>
+                               <th class="th nowrap">Status</th>
+                               <th class="th nowrap">Rx / Tx</th>
+                               <th class="th nowrap">User/Name</th>
+                       </tr>
+               </table>
+       </fieldset>
+</div>
\ No newline at end of file