diff --git a/luci-app-cjdns/luasrc/controller/cjdns.lua b/luci-app-cjdns/luasrc/controller/cjdns.lua index 72c9d86..362d84a 100644 --- a/luci-app-cjdns/luasrc/controller/cjdns.lua +++ b/luci-app-cjdns/luasrc/controller/cjdns.lua @@ -51,17 +51,16 @@ function act_peers() end for i,peer in pairs(response.peers) do - peer.ipv6 = publictoip6(peer.addr) - peer.version = pstatver(peer.addr) - peer.label = pstatlabel(peer.addr) - 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 @@ -99,23 +98,13 @@ function act_ping() luci.http.write_json(response) end -function publictoip6(addrLine) - local t = string.sub(addrLine, string.len(addrLine) - 53) - local process = io.popen("/usr/bin/publictoip6 " .. t, "r") - local ipv6 = process:read() - process:close() - return ipv6 -end - -function pstatver(addrLine) - for str in string.gmatch(addrLine, "([^"..".".."]+)") do - if str then return str else return '-' end - end -end - -function pstatlabel(addrLine) - local t={}; local i=0; for str in string.gmatch(addrLine, "([^"..".".."]+)") do - if i >= 1 and i <= 4 then t[#t+1] = str end i = i + 1 - end - return table.concat(t, ".") -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 diff --git a/luci-app-cjdns/luasrc/view/cjdns/status.htm b/luci-app-cjdns/luasrc/view/cjdns/status.htm index 5851138..3da5d7c 100644 --- a/luci-app-cjdns/luasrc/view/cjdns/status.htm +++ b/luci-app-cjdns/luasrc/view/cjdns/status.htm @@ -1,119 +1,67 @@ - - -
+