From 35ade80f1c827fd5d61528152a8a4e58ceccc7fa Mon Sep 17 00:00:00 2001 From: Matthias Schiffer <mschiffer@universe-factory.net> Date: Sun, 15 Apr 2018 11:36:37 +0200 Subject: [PATCH] gluon-status-page: move mesh protocol specific definitions into a separate file --- .../gluon/status-page/view/status-page.html | 20 +++++++- .../status-page/www/static/status-page.js | 2 +- .../javascript/status-page.js | 47 ++++++++++++++----- .../luasrc/lib/gluon/status-page/mesh.lua | 10 ++++ .../gluon-status-page/src/neighbours-batadv.c | 2 +- 5 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua 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 a37666326..17e2a8dea 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 @@ -18,6 +18,16 @@ _('%s used') _('%s packets/s') + local function get_mesh() + local f = loadfile('/lib/gluon/status-page/mesh.lua') + if f then + return f() + end + return {} + end + + local mesh = get_mesh() + local function get_interfaces() local uconn = ubus.connect() if not uconn then @@ -77,7 +87,11 @@ <link rel="stylesheet" href="/static/status-page.css" type="text/css" /> </head> - <body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%= attr('data-translations', translations) .. attr('data-node-location', nodeinfo.location) %>> + <body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%= + attr('data-translations', translations) .. + attr('data-node-location', nodeinfo.location) .. + attr('data-mesh-provider', mesh.provider) + %>> <header> <h1><%| nodeinfo.hostname %></h1> </header> @@ -139,7 +153,9 @@ <table class="datatable"> <tr> <th><%:Node%></th> - <th>TQ</th> + <% for i, v in ipairs(mesh.attrs or {}) do %> + <th<%= attr('data-key', v[1]) .. attr('data-suffix', v[3]) %>><%| v[2] %></th> + <% end %> <% if wireless then %> <th>dBm</th> <th><%:Distance%></th> 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 55ee27a64..242ef0b3e 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 t=JSON.parse(document.body.getAttribute("data-translations"));function e(e,n){return e.toFixed(n).replace(/\./,t["."])}function n(t,n){n--;for(var i=t;i>=10&&n>0;i/=10)n--;return e(t,n)}function i(t){return function(t,e,i){for(var r=0;i>e&&r<t.length-1;)i/=e,r++;return(i=n(i,3))+" "+t[r]}(["","K","M","G","T"],1024,t)}String.prototype.sprintf=function(){var t=0,e=arguments;return this.replace(/%s/g,function(){return e[t++]})};var r={id:function(t){return t},decimal:function(t){return e(t,2)},percent:function(e){return t["%s used"].sprintf(n(100*e,3)+"%")},memory:function(t){var e=1-(t.free+t.buffers+t.cached)/t.total;return r.percent(e)},time:function(e){var n=Math.round(e/60),i=Math.floor(n/1440),r=Math.floor(n%1440/60);n=Math.floor(n%60);var a="";return 1===i?a+=t["1 day"]+", ":i>1&&(a+=t["%s days"].sprintf(i)+", "),a+=r+":",n<10&&(a+="0"),a+=n},packetsDiff:function(n,i,r){if(r>0)return a=(n-i)/r,t["%s packets/s"].sprintf(e(a,0));var a},bytesDiff:function(t,e,n){if(n>0)return i(8*((t-e)/n))+"bps"},bytes:function(t){return i(t)+"B"}};function a(t,e){return e.split("/").forEach(function(e){t&&(t=t[e])}),t}function o(t,e){var n=new EventSource(t),i={};n.onmessage=function(t){var n=JSON.parse(t.data);e(n,i),i=n},n.onerror=function(){n.close(),window.setTimeout(function(){o(t,e)},3e3)}}var c,s=document.body.getAttribute("data-node-address");try{c=JSON.parse(document.body.getAttribute("data-node-location"))}catch(t){}var u=document.querySelectorAll("[data-statistics]");o("/cgi-bin/dyn/statistics",function(e,n){var i=e.uptime-n.uptime;u.forEach(function(t){var o=t.getAttribute("data-statistics"),c=t.getAttribute("data-format"),s=a(n,o),u=a(e,o);try{var l=r[c](u,s,i);void 0!==l&&(t.textContent=l)}catch(t){console.error(t)}});try{!function(e){var n=document.getElementById("mesh-vpn");if(e){n.style.display="";for(var i=document.getElementById("mesh-vpn-peers");i.lastChild;)i.removeChild(i.lastChild);var a=function t(e,n){return Object.keys(n.peers||{}).forEach(function(t){e.push([t,n.peers[t]])}),Object.keys(n.groups||{}).forEach(function(i){t(e,n.groups[i])}),e}([],e);a.sort(),a.forEach(function(e){var n=document.createElement("tr"),a=document.createElement("th");a.textContent=e[0],n.appendChild(a);var o=document.createElement("td");e[1]?o.textContent=t.connected+" ("+r.time(e[1].established)+")":o.textContent=t["not connected"],n.appendChild(o),i.appendChild(n)})}else n.style.display="none"}(e.mesh_vpn)}catch(t){console.error(t)}});var l={};function h(t){var e=document.createElement("canvas"),n=e.getContext("2d"),i=null,r=1.2;return{canvas:e,highlight:!1,resize:function(t,i){try{n.getImageData(0,0,t,i)}catch(t){}e.width=t,e.height=i},draw:function(a,o){var c,s,u=o(i);n.clearRect(a,0,5,e.height),u&&(c=a,s=u,n.beginPath(),n.fillStyle=t,n.arc(c,s,r,0,2*Math.PI,!1),n.closePath(),n.fill())},set:function(t){i=t}}}function f(){var t=-100,e=0,n=0,i=[],r=document.createElement("canvas");r.className="signalgraph",r.height=200;var a=r.getContext("2d");function o(){r.width=r.clientWidth,i.forEach(function(t){t.resize(r.width,r.height)})}function c(){if(0!==r.clientWidth){r.width!==r.clientWidth&&o(),a.clearRect(0,0,r.width,r.height);var c=!1;i.forEach(function(t){t.highlight&&(c=!0)}),a.save(),i.forEach(function(i){c&&(a.globalAlpha=.2),i.highlight&&(a.globalAlpha=1),i.draw(n,function(n){return i=n,a=t,o=e,c=r.height,(1-(i-a)/(o-a))*c;var i,a,o,c}),a.drawImage(i.canvas,0,0)}),a.restore(),a.save(),a.beginPath(),a.strokeStyle="rgba(255, 180, 0, 0.15)",a.lineWidth=5,a.moveTo(n+2.5,0),a.lineTo(n+2.5,r.height),a.stroke(),function(){var n,i,o,c,s=Math.floor(r.height/40);a.save(),a.lineWidth=.5,a.strokeStyle="rgba(0, 0, 0, 0.25)",a.fillStyle="rgba(0, 0, 0, 0.5)",a.textAlign="end",a.textBaseline="bottom",a.beginPath();for(var u=0;u<s;u++){var l=r.height-40*u;a.moveTo(0,l-.5),a.lineTo(r.width,l-.5);var h=Math.round((n=l,i=t,o=e,c=r.height,(i*n+o*(c-n))/c))+" dBm";a.save(),a.strokeStyle="rgba(255, 255, 255, 0.9)",a.lineWidth=4,a.miterLimit=2,a.strokeText(h,r.width-5,l-2.5),a.fillText(h,r.width-5,l-2.5),a.restore()}a.stroke(),a.strokeStyle="rgba(0, 0, 0, 0.83)",a.lineWidth=1.5,a.strokeRect(.5,.5,r.width-1,r.height-1),a.restore()}()}}o(),window.addEventListener("resize",c);var s=0;return window.requestAnimationFrame(function t(e){e-s>40&&(c(),n=(n+1)%r.width,s=e),window.requestAnimationFrame(t)}),{el:r,addSignal:function(t){i.push(t),t.resize(r.width,r.height)},removeSignal:function(t){i.splice(i.indexOf(t),1)}}}function d(t,e,n,i){var r=t.table.insertRow(),a=r.insertCell();if(t.wireless){var o=document.createElement("span");o.textContent="⬤ ",o.style.color=n,a.appendChild(o)}var u=document.createElement("span");u.textContent=e,a.appendChild(u);var l,f,d,g,v,m=r.insertCell();function p(){v&&window.clearTimeout(v),v=window.setTimeout(function(){g&&t.signalgraph.removeSignal(g),r.parentNode.removeChild(r),i()},6e4)}function b(t){var e=function(t){"::"==t.slice(0,2)&&(t="0"+t),"::"==t.slice(-2)&&(t+="0");var e=t.split(":"),n=e.length,i=[];return e.forEach(function(t,e){if(""===t)for(;n++<=8;)i.push(0);else{if(!/^[a-f0-9]{1,4}$/i.test(t))return;i.push(parseInt(t,16))}}),i}(t);if(e){var n="";return e.forEach(function(t){n+=("0000000000000000"+t.toString(2)).slice(-16)}),n}}return m.textContent="-",t.wireless&&((l=r.insertCell()).textContent="-",(f=r.insertCell()).textContent="-",(d=r.insertCell()).textContent="-",g=h(n),t.signalgraph.addSignal(g)),r.onmouseenter=function(){r.classList.add("highlight"),g&&(g.highlight=!0)},r.onmouseleave=function(){r.classList.remove("highlight"),g&&(g.highlight=!1)},p(),{update_nodeinfo:function(t){var e,n,i,r,a,o,l,h,d=function(t){var e=b(s);if(t&&t[0]){(t=t.map(function(t){var n=b(t);if(!n)return[-1];var i=0;return e&&(i=function(t,e){var n;for(n=0;n<t.length&&n<e.length&&t[n]===e[n];n++);return n}(e,n)),[i,n,t]})).sort(function(t,e){return t[0]<e[0]?1:t[0]>e[0]?-1:t[1]<e[1]?-1:t[1]>e[1]?1:0});var n=t[0][2];return n&&!/^fe80:/i.test(n)?n:void 0}}(t.network.addresses);if(d){if("span"===u.nodeName.toLowerCase()){var g=u;u=document.createElement("a"),g.parentNode.replaceChild(u,g)}u.href="http://["+d+"]/"}if(u.textContent=t.hostname,c&&t.location){var v=(e=c.latitude,n=c.longitude,i=t.location.latitude,r=t.location.longitude,a=Math.PI/180,o=(i*=a)-(e*=a),l=(r*=a)-(n*=a),h=Math.sin(o/2)*Math.sin(o/2)+Math.sin(l/2)*Math.sin(l/2)*Math.cos(e)*Math.cos(i),2*Math.asin(Math.sqrt(h))*6372.8);f.textContent=Math.round(1e3*v)+" m"}p()},update_mesh:function(t){m.textContent=Math.round(t.tq/2.55)+" %",p()},update_wifi:function(t){l.textContent=t.signal,d.textContent=Math.round(t.inactive/1e3)+" s",r.classList.toggle("inactive",t.inactive>200),g.set(t.inactive>200?null:t.signal),p()}}}function g(t,e,n){var i,r={};n&&(i=f(),t.appendChild(i.el));var a={table:t.firstElementChild,signalgraph:i,ifname:e,wireless:n},c=!1,s={},u=[];function l(){if(!c){c=!0;var t=new EventSource("/cgi-bin/dyn/neighbours-nodeinfo?"+encodeURIComponent(e));t.addEventListener("neighbour",function(t){try{var e=JSON.parse(t.data);(n=e,i=[],a=n.network.mesh,Object.keys(a).forEach(function(t){var e=a[t].interfaces;Object.keys(e).forEach(function(t){e[t].forEach(function(t){i.push(t)})})}),i).forEach(function(t){var n=r[t];if(n){delete s[t];try{n.update_nodeinfo(e)}catch(t){console.error(t)}}})}catch(t){console.error(t)}var n,i,a},!1),t.onerror=function(){t.close(),c=!1,Object.keys(s).forEach(function(t){s[t]>0&&(s[t]--,l())})}}}function h(t){var e=r[t];return e||(s[t]=3,e=r[t]=d(a,t,(u[0]||(u=["#396AB1","#DA7C30","#3E9651","#CC2529","#535154","#6B4C9A","#922428","#948B3D"]),u.shift()),function(){delete s[t],delete r[t]}),l()),e}return n&&o("/cgi-bin/dyn/stations?"+encodeURIComponent(e),function(t){Object.keys(t).forEach(function(e){var n=t[e];h(e).update_wifi(n)})}),{get_neigh:h}}document.querySelectorAll("[data-interface]").forEach(function(t){var e=t.getAttribute("data-interface"),n=(t.getAttribute("data-interface-address"),!!t.getAttribute("data-interface-wireless"));l[e]=g(t,e,n)}),o("/cgi-bin/dyn/neighbours-batadv",function(t){Object.keys(t).forEach(function(e){var n=t[e],i=l[n.ifname];i&&i.get_neigh(e).update_mesh(n)})})}(); \ No newline at end of file +"use strict";!function(){var a=JSON.parse(document.body.getAttribute("data-translations"));function i(t,e){return t.toFixed(e).replace(/\./,a["."])}function o(t,e){e--;for(var n=t;10<=n&&0<e;n/=10)e--;return i(t,e)}function r(t){return function(t,e,n){for(var r=0;e<n&&r<t.length-1;)n/=e,r++;return(n=o(n,3))+" "+t[r]}(["","K","M","G","T"],1024,t)}String.prototype.sprintf=function(){var t=0,e=arguments;return this.replace(/%s/g,function(){return e[t++]})};var u={id:function(t){return t},decimal:function(t){return i(t,2)},percent:function(t){return a["%s used"].sprintf(o(100*t,3)+"%")},memory:function(t){var e=1-(t.free+t.buffers+t.cached)/t.total;return u.percent(e)},time:function(t){var e=Math.round(t/60),n=Math.floor(e/1440),r=Math.floor(e%1440/60);e=Math.floor(e%60);var i="";return 1===n?i+=a["1 day"]+", ":1<n&&(i+=a["%s days"].sprintf(n)+", "),i+=r+":",e<10&&(i+="0"),i+=e},packetsDiff:function(t,e,n){if(0<n)return r=(t-e)/n,a["%s packets/s"].sprintf(i(r,0));var r},bytesDiff:function(t,e,n){if(0<n)return r(8*((t-e)/n))+"bps"},bytes:function(t){return r(t)+"B"}};function f(e,t){return t.split("/").forEach(function(t){e&&(e=e[t])}),e}function l(t,n){var e=new EventSource(t),r={};e.onmessage=function(t){var e=JSON.parse(t.data);n(e,r),r=e},e.onerror=function(){e.close(),window.setTimeout(function(){l(t,n)},3e3)}}var y,C=document.body.getAttribute("data-node-address");try{y=JSON.parse(document.body.getAttribute("data-node-location"))}catch(t){}var t=document.querySelectorAll("[data-statistics]");l("/cgi-bin/dyn/statistics",function(o,c){var s=o.uptime-c.uptime;t.forEach(function(t){var e=t.getAttribute("data-statistics"),n=t.getAttribute("data-format"),r=f(c,e),i=f(o,e);try{var a=u[n](i,r,s);void 0!==a&&(t.textContent=a)}catch(t){console.error(t)}});try{!function(t){var e=document.getElementById("mesh-vpn");if(t){e.style.display="";for(var i=document.getElementById("mesh-vpn-peers");i.lastChild;)i.removeChild(i.lastChild);var n=function e(n,r){return Object.keys(r.peers||{}).forEach(function(t){n.push([t,r.peers[t]])}),Object.keys(r.groups||{}).forEach(function(t){e(n,r.groups[t])}),n}([],t);n.sort(),n.forEach(function(t){var e=document.createElement("tr"),n=document.createElement("th");n.textContent=t[0],e.appendChild(n);var r=document.createElement("td");t[1]?r.textContent=a.connected+" ("+u.time(t[1].established)+")":r.textContent=a["not connected"],e.appendChild(r),i.appendChild(e)})}else e.style.display="none"}(o.mesh_vpn)}catch(t){console.error(t)}});var c={};function w(a){var o=document.createElement("canvas"),c=o.getContext("2d"),s=null,u=1.2;return{canvas:o,highlight:!1,resize:function(t,e){try{c.getImageData(0,0,t,e)}catch(t){}o.width=t,o.height=e},draw:function(t,e){var n,r,i=e(s);c.clearRect(t,0,5,o.height),i&&(n=t,r=i,c.beginPath(),c.fillStyle=a,c.arc(n,r,u,0,2*Math.PI,!1),c.closePath(),c.fill())},set:function(t){s=t}}}function h(){var s=-100,u=0,n=0,r=[],f=document.createElement("canvas");f.className="signalgraph",f.height=200;var l=f.getContext("2d");function t(){f.width=f.clientWidth,r.forEach(function(t){t.resize(f.width,f.height)})}function i(){if(0!==f.clientWidth){f.width!==f.clientWidth&&t(),l.clearRect(0,0,f.width,f.height);var e=!1;r.forEach(function(t){t.highlight&&(e=!0)}),l.save(),r.forEach(function(t){e&&(l.globalAlpha=.2),t.highlight&&(l.globalAlpha=1),t.draw(n,function(t){return e=t,n=s,r=u,i=f.height,(1-(e-n)/(r-n))*i;var e,n,r,i}),l.drawImage(t.canvas,0,0)}),l.restore(),l.save(),l.beginPath(),l.strokeStyle="rgba(255, 180, 0, 0.15)",l.lineWidth=5,l.moveTo(n+2.5,0),l.lineTo(n+2.5,f.height),l.stroke(),function(){var t,e,n,r,i=Math.floor(f.height/40);l.save(),l.lineWidth=.5,l.strokeStyle="rgba(0, 0, 0, 0.25)",l.fillStyle="rgba(0, 0, 0, 0.5)",l.textAlign="end",l.textBaseline="bottom",l.beginPath();for(var a=0;a<i;a++){var o=f.height-40*a;l.moveTo(0,o-.5),l.lineTo(f.width,o-.5);var c=Math.round((t=o,e=s,n=u,r=f.height,(e*t+n*(r-t))/r))+" dBm";l.save(),l.strokeStyle="rgba(255, 255, 255, 0.9)",l.lineWidth=4,l.miterLimit=2,l.strokeText(c,f.width-5,o-2.5),l.fillText(c,f.width-5,o-2.5),l.restore()}l.stroke(),l.strokeStyle="rgba(0, 0, 0, 0.83)",l.lineWidth=1.5,l.strokeRect(.5,.5,f.width-1,f.height-1),l.restore()}()}}t(),window.addEventListener("resize",i);var a=0;return window.requestAnimationFrame(function t(e){40<e-a&&(i(),n=(n+1)%f.width,a=e),window.requestAnimationFrame(t)}),{el:f,addSignal:function(t){r.push(t),t.resize(f.width,f.height)},removeSignal:function(t){r.splice(r.indexOf(t),1)}}}function d(t,e,n,r){var i=t.table.firstElementChild,a=t.table.insertRow(),o=a.insertCell();if(t.wireless){var c=document.createElement("span");c.textContent="⬤ ",c.style.color=n,o.appendChild(c)}var h=document.createElement("span");h.textContent=e,o.appendChild(h);var s,d,u,f,l,v={};function g(t){var e=t.getAttribute("data-key");if(e){var n=t.getAttribute("data-suffix")||"",r=a.insertCell();r.textContent="-",v[e]={td:r,suffix:n}}}for(var m=0;m<i.children.length;m++)g(i.children[m]);function p(){l&&window.clearTimeout(l),l=window.setTimeout(function(){f&&t.signalgraph.removeSignal(f),a.parentNode.removeChild(a),r()},6e4)}function b(t){var e=function(t){"::"==t.slice(0,2)&&(t="0"+t),"::"==t.slice(-2)&&(t+="0");var e=t.split(":"),n=e.length,r=[];return e.forEach(function(t,e){if(""===t)for(;n++<=8;)r.push(0);else{if(!/^[a-f0-9]{1,4}$/i.test(t))return;r.push(parseInt(t,16))}}),r}(t);if(e){var n="";return e.forEach(function(t){n+=("0000000000000000"+t.toString(2)).slice(-16)}),n}}return t.wireless&&((s=a.insertCell()).textContent="-",(d=a.insertCell()).textContent="-",(u=a.insertCell()).textContent="-",f=w(n),t.signalgraph.addSignal(f)),a.onmouseenter=function(){a.classList.add("highlight"),f&&(f.highlight=!0)},a.onmouseleave=function(){a.classList.remove("highlight"),f&&(f.highlight=!1)},p(),{update_nodeinfo:function(t){var e,n,r,i,a,o,c,s,u=function(t){var r=b(C);if(t&&t[0]){(t=t.map(function(t){var e=b(t);if(!e)return[-1];var n=0;return r&&(n=function(t,e){var n;for(n=0;n<t.length&&n<e.length&&t[n]===e[n];n++);return n}(r,e)),[n,e,t]})).sort(function(t,e){return t[0]<e[0]?1:t[0]>e[0]?-1:t[1]<e[1]?-1:t[1]>e[1]?1:0});var e=t[0][2];return e&&!/^fe80:/i.test(e)?e:void 0}}(t.network.addresses);if(u){if("span"===h.nodeName.toLowerCase()){var f=h;h=document.createElement("a"),f.parentNode.replaceChild(h,f)}h.href="http://["+u+"]/"}if(h.textContent=t.hostname,y&&t.location){var l=(e=y.latitude,n=y.longitude,r=t.location.latitude,i=t.location.longitude,a=Math.PI/180,o=(r*=a)-(e*=a),c=(i*=a)-(n*=a),s=Math.sin(o/2)*Math.sin(o/2)+Math.sin(c/2)*Math.sin(c/2)*Math.cos(e)*Math.cos(r),2*Math.asin(Math.sqrt(s))*6372.8);d.textContent=Math.round(1e3*l)+" m"}p()},update_mesh:function(n){Object.keys(v).forEach(function(t){var e=v[t];e.td.textContent=n[t]+e.suffix}),p()},update_wifi:function(t){s.textContent=t.signal,u.textContent=Math.round(t.inactive/1e3)+" s",a.classList.toggle("inactive",200<t.inactive),f.set(200<t.inactive?null:t.signal),p()}}}function s(t,e,n){var r,a={};n&&(r=h(),t.appendChild(r.el));var i={table:t.firstElementChild,signalgraph:r,ifname:e,wireless:n},o=!1,c={},s=[];function u(){if(!o){o=!0;var t=new EventSource("/cgi-bin/dyn/neighbours-nodeinfo?"+encodeURIComponent(e));t.addEventListener("neighbour",function(t){try{var n=JSON.parse(t.data);(e=n,r=[],i=e.network.mesh,Object.keys(i).forEach(function(t){var e=i[t].interfaces;Object.keys(e).forEach(function(t){e[t].forEach(function(t){r.push(t)})})}),r).forEach(function(t){var e=a[t];if(e){delete c[t];try{e.update_nodeinfo(n)}catch(t){console.error(t)}}})}catch(t){console.error(t)}var e,r,i},!1),t.onerror=function(){t.close(),o=!1,Object.keys(c).forEach(function(t){0<c[t]&&(c[t]--,u())})}}}function f(t){var e=a[t];return e||(c[t]=3,e=a[t]=d(i,t,(s[0]||(s=["#396AB1","#DA7C30","#3E9651","#CC2529","#535154","#6B4C9A","#922428","#948B3D"]),s.shift()),function(){delete c[t],delete a[t]}),u()),e}return n&&l("/cgi-bin/dyn/stations?"+encodeURIComponent(e),function(n){Object.keys(n).forEach(function(t){var e=n[t];f(t).update_wifi(e)})}),{get_neigh:f}}document.querySelectorAll("[data-interface]").forEach(function(t){var e=t.getAttribute("data-interface"),n=(t.getAttribute("data-interface-address"),!!t.getAttribute("data-interface-wireless"));c[e]=s(t,e,n)});var e=document.body.getAttribute("data-mesh-provider");e&&l(e,function(r){Object.keys(r).forEach(function(t){var e=r[t],n=c[e.ifname];n&&n.get_neigh(t).update_mesh(e)})})}(); \ No newline at end of file diff --git a/package/gluon-status-page/javascript/status-page.js b/package/gluon-status-page/javascript/status-page.js index d7afd5eb4..b82c6a11c 100644 --- a/package/gluon-status-page/javascript/status-page.js +++ b/package/gluon-status-page/javascript/status-page.js @@ -412,6 +412,7 @@ } function Neighbour(iface, addr, color, destroy) { + var th = iface.table.firstElementChild; var el = iface.table.insertRow(); var tdHostname = el.insertCell(); @@ -427,8 +428,26 @@ hostname.textContent = addr; tdHostname.appendChild(hostname); - var tdTQ = el.insertCell(); - tdTQ.textContent = '-'; + var meshAttrs = {}; + + function add_attr(attr) { + var key = attr.getAttribute('data-key'); + if (!key) + return; + + var suffix = attr.getAttribute('data-suffix') || ''; + + var td = el.insertCell(); + td.textContent = '-'; + + meshAttrs[key] = { + 'td': td, + 'suffix': suffix, + }; + } + + for (var i = 0; i < th.children.length; i++) + add_attr(th.children[i]); var tdSignal; var tdDistance; @@ -585,7 +604,10 @@ updated(); }, 'update_mesh': function(mesh) { - tdTQ.textContent = Math.round(mesh.tq / 2.55) + ' %'; + Object.keys(meshAttrs).forEach(function(key) { + var attr = meshAttrs[key]; + attr.td.textContent = mesh[key] + attr.suffix; + }); updated(); }, @@ -724,14 +746,17 @@ interfaces[ifname] = Interface(elem, ifname, wireless); }); - add_event_source('/cgi-bin/dyn/neighbours-batadv', function(data) { - Object.keys(data).forEach(function (addr) { - var mesh = data[addr]; - var iface = interfaces[mesh.ifname]; - if (!iface) - return; + var mesh_provider = document.body.getAttribute('data-mesh-provider'); + if (mesh_provider) { + add_event_source(mesh_provider, function(data) { + Object.keys(data).forEach(function (addr) { + var mesh = data[addr]; + var iface = interfaces[mesh.ifname]; + if (!iface) + return; - iface.get_neigh(addr).update_mesh(mesh); + iface.get_neigh(addr).update_mesh(mesh); + }); }); - }); + } })(); diff --git a/package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua b/package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua new file mode 100644 index 000000000..733e6d7c9 --- /dev/null +++ b/package/gluon-status-page/luasrc/lib/gluon/status-page/mesh.lua @@ -0,0 +1,10 @@ +return { + provider = '/cgi-bin/dyn/neighbours-batadv', + -- List of mesh-specific attributes, each a tuple of + -- 1) the internal identifier (JSON key) + -- 2) human-readable key (not translatable yet) + -- 3) value suffix (optional) + attrs = { + {'tq', 'TQ', ' %'}, + }, +} diff --git a/package/gluon-status-page/src/neighbours-batadv.c b/package/gluon-status-page/src/neighbours-batadv.c index 3b0363cc1..b923d7f1e 100644 --- a/package/gluon-status-page/src/neighbours-batadv.c +++ b/package/gluon-status-page/src/neighbours-batadv.c @@ -76,7 +76,7 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg) if (!neigh) return NL_OK; - json_object_object_add(neigh, "tq", json_object_new_int(tq)); + json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255)); json_object_object_add(neigh, "ifname", json_object_new_string(ifname)); json_object_object_add(opts->obj, mac1, neigh); -- GitLab