From b46e1839df56df0d0b51a5fa6c7cbf7acf121091 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 7 Aug 2021 22:16:10 +0200 Subject: [PATCH] gluon-status-page: use ubus to get radio channels Do not depend on the respondd-airtime module just to get the configured channels. This removes the display of the frequency in addition to the channel, as it is not readily available. In addition, the translation string is improved to allow for text after the channel number. (cherry picked from commit 0d3fa6b59be7c01eed7cc4bcced38647031c9373) --- .../gluon/status-page/view/status-page.html | 48 ++++++++++++++---- .../status-page/www/static/status-page.js | 2 +- package/gluon-status-page/i18n/de.po | 4 +- .../i18n/gluon-status-page.pot | 2 +- .../javascript/status-page.js | 49 ------------------- 5 files changed, 42 insertions(+), 63 deletions(-) diff --git a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html index 6bd90f8b..90d7ca0b 100644 --- a/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html +++ b/package/gluon-status-page/files/lib/gluon/status-page/view/status-page.html @@ -29,17 +29,31 @@ local mesh = get_mesh() - local function get_interfaces() - local uconn = ubus.connect() - if not uconn then - error('failed to connect to ubus') - end + local function get_interfaces(uconn) local interfaces = util.get_mesh_devices(uconn) - ubus.close(uconn) table.sort(interfaces) return interfaces end + local function get_radios(uconn) + local radios = uconn:call("network.wireless", "status", {}) + local ret = {} + + for radio, info in pairs(radios) do + if info.up then + table.insert(ret, { + name = radio, + channel = info.config.channel, + }) + end + end + + table.sort(ret, function(a, b) + return a.name < b.name + end) + return ret + end + local function is_wireless(iface) while true do local pattern = '/sys/class/net/' .. iface .. '/lower_*' @@ -52,7 +66,15 @@ return unistd.access('/sys/class/net/' .. iface .. '/wireless') ~= nil end - local interfaces = get_interfaces() + local uconn = ubus.connect() + if not uconn then + error('failed to connect to ubus') + end + + local interfaces = get_interfaces(uconn) + local radios = get_radios(uconn) + + ubus.close(uconn) local function sorted(t) t = {unpack(t)} @@ -195,11 +217,17 @@ <%:Wireless 2.4 GHz%><%= statistics('clients/wifi24') %> <%:Wireless 5 GHz%><%= statistics('clients/wifi5') %> - + <%- end %>

<%:Traffic%>

diff --git a/package/gluon-status-page/files/lib/gluon/status-page/www/static/status-page.js b/package/gluon-status-page/files/lib/gluon/status-page/www/static/status-page.js index 5be175f8..83d63cd5 100644 --- a/package/gluon-status-page/files/lib/gluon/status-page/www/static/status-page.js +++ b/package/gluon-status-page/files/lib/gluon/status-page/www/static/status-page.js @@ -1 +1 @@ -"use strict";!function(){var i=JSON.parse(document.body.getAttribute("data-translations"));function r(t,e){return t.toFixed(e).replace(/\./,i["."])}function a(t,e){e--;for(var n=t;10<=n&&0Channel "+(2484===(t=t.frequency)?14:2412<=t&&t<=2472?(t-2407)/5:5160<=t&&t<=5885?(t-5e3)/5:"unknown"),e.appendChild(n),r.appendChild(e)})}else e.style.display="none"}var n=document.querySelectorAll("[data-statistics]");d("/cgi-bin/dyn/statistics",function(a,o){var c=a.uptime-o.uptime;n.forEach(function(t){var e=t.getAttribute("data-statistics"),n=t.getAttribute("data-format"),r=s(o,e),e=s(a,e);try{var i=l[n](e,r,c);switch(typeof i){case"string":t.textContent=i;break;case"object":t.lastChild&&t.removeChild(t.lastChild),t.appendChild(i)}}catch(t){console.error(t)}});try{t(a.mesh_vpn)}catch(t){console.error(t)}try{e(a.wireless)}catch(t){console.error(t)}});var c={};function A(n){var r=document.createElement("canvas"),i=r.getContext("2d"),a=null;return{canvas:r,highlight:!1,resize:function(t,e){try{i.getImageData(0,0,t,e)}catch(t){}r.width=t,r.height=e},draw:function(t,e){e=e(a);i.clearRect(t,0,5,r.height),e&&(t=t,e=e,i.beginPath(),i.fillStyle=n,i.arc(t,e,1.2,0,2*Math.PI,!1),i.closePath(),i.fill())},set:function(t){a=t}}}function h(){var i=-100,a=0,n=0,r=[],o=document.createElement("canvas");o.className="signalgraph",o.height=200;var c=o.getContext("2d");function t(){o.width=o.clientWidth,r.forEach(function(t){t.resize(o.width,o.height)})}function l(){var e;0!==o.clientWidth&&(o.width!==o.clientWidth&&t(),c.clearRect(0,0,o.width,o.height),e=!1,r.forEach(function(t){t.highlight&&(e=!0)}),c.save(),r.forEach(function(t){e&&(c.globalAlpha=.2),t.highlight&&(c.globalAlpha=1),t.draw(n,function(t){return e=o.height,(1-(t-i)/(a-i))*e;var e}),c.drawImage(t.canvas,0,0)}),c.restore(),c.save(),c.beginPath(),c.strokeStyle="rgba(255, 180, 0, 0.15)",c.lineWidth=5,c.moveTo(n+2.5,0),c.lineTo(n+2.5,o.height),c.stroke(),function(){var t=Math.floor(o.height/40);c.save(),c.lineWidth=.5,c.strokeStyle="rgba(0, 0, 0, 0.25)",c.fillStyle="rgba(0, 0, 0, 0.5)",c.textAlign="end",c.textBaseline="bottom",c.beginPath();for(var e=0;ee[0]||t[1]e[1]?1:0});t=t[0][2];return t&&!/^fe80:/i.test(t)?t:void 0}}return t.wireless&&((g=a.insertCell()).textContent="-",g.setAttribute("data-label",i.children[Object.keys(s).length+1].textContent),(p=a.insertCell()).textContent="-",p.setAttribute("data-label",i.children[Object.keys(s).length+2].textContent),(m=a.insertCell()).textContent="-",m.setAttribute("data-label",i.children[Object.keys(s).length+3].textContent),v=A(e),t.signalgraph.addSignal(v)),a.onmouseenter=function(){a.classList.add("highlight"),v&&(v.highlight=!0)},a.onmouseleave=function(){a.classList.remove("highlight"),v&&(v.highlight=!1)},y(),{get_hostname:function(){return l.textContent},get_addr:function(){return o},update_nodeinfo:function(t){var e,n,r,i,a;(o=w(t.network.addresses))&&("span"===l.nodeName.toLowerCase()&&(a=l,l=document.createElement("a"),a.parentNode.replaceChild(l,a)),l.href="http://["+o+"]/"),l.textContent=t.hostname,x&&t.location&&(e=x.latitude,n=x.longitude,r=t.location.latitude,i=t.location.longitude,a=Math.PI/180,t=(r*=a)-(e*=a),n=(i*=a)-(n*=a),r=Math.sin(t/2)*Math.sin(t/2)+Math.sin(n/2)*Math.sin(n/2)*Math.cos(e)*Math.cos(r),r=6372.8*(2*Math.asin(Math.sqrt(r))),p.textContent=Math.round(1e3*r)+" m"),y()},update_mesh:function(n){Object.keys(s).forEach(function(t){var e=s[t];e.td.textContent=n[t]+e.suffix}),y()},update_wifi:function(t){g.textContent=t.signal,m.textContent=Math.round(t.inactive/1e3)+" s",a.classList.toggle("inactive",200e[0]?-1:t[1]e[1]?1:0});var e=t[0][2];return e&&!/^fe80:/i.test(e)?e:void 0}}return t.wireless&&((c=i.insertCell()).textContent="-",c.setAttribute("data-label",r.children[Object.keys(g).length+1].textContent),(f=i.insertCell()).textContent="-",f.setAttribute("data-label",r.children[Object.keys(g).length+2].textContent),(s=i.insertCell()).textContent="-",s.setAttribute("data-label",r.children[Object.keys(g).length+3].textContent),u=E(e),t.signalgraph.addSignal(u)),i.onmouseenter=function(){i.classList.add("highlight"),u&&(u.highlight=!0)},i.onmouseleave=function(){i.classList.remove("highlight"),u&&(u.highlight=!1)},m(),{get_hostname:function(){return h.textContent},get_addr:function(){return d},update_nodeinfo:function(t){if(d=C(t.network.addresses)){if("span"===h.nodeName.toLowerCase()){var e=h;h=document.createElement("a"),e.parentNode.replaceChild(h,e)}h.href="http://["+d+"]/"}if(h.textContent=t.hostname,y&&t.location){var n=(r=y.latitude,i=y.longitude,a=t.location.latitude,o=t.location.longitude,c=Math.PI/180,s=(a*=c)-(r*=c),u=(o*=c)-(i*=c),l=Math.sin(s/2)*Math.sin(s/2)+Math.sin(u/2)*Math.sin(u/2)*Math.cos(r)*Math.cos(a),2*Math.asin(Math.sqrt(l))*6372.8);f.textContent=Math.round(1e3*n)+" m"}var r,i,a,o,c,s,u,l;m()},update_mesh:function(n){Object.keys(g).forEach(function(t){var e=g[t];e.td.textContent=n[t]+e.suffix}),m()},update_wifi:function(t){c.textContent=t.signal,s.textContent=Math.round(t.inactive/1e3)+" s",i.classList.toggle("inactive",200Channel " + channel(radio.frequency); - tr.appendChild(td); - - table.appendChild(tr); - }); - } - var statisticsElems = document.querySelectorAll('[data-statistics]'); add_event_source('/cgi-bin/dyn/statistics', function(data, dataPrev) { @@ -293,11 +249,6 @@ } catch (e) { console.error(e); } - try { - update_radios(data.wireless); - } catch (e) { - console.error(e); - } }) function haversine(lat1, lon1, lat2, lon2) {