Skip to content
Snippets Groups Projects
Unverified Commit 90fe74bf authored by Matthias Schiffer's avatar Matthias Schiffer Committed by GitHub
Browse files

Merge pull request #2289 from freifunk-gluon/status-page-improvements

Status page improvements
parents 83d0e327 a3572784
No related branches found
No related tags found
No related merge requests found
...@@ -29,17 +29,31 @@ ...@@ -29,17 +29,31 @@
local mesh = get_mesh() local mesh = get_mesh()
local function get_interfaces() local function get_interfaces(uconn)
local uconn = ubus.connect()
if not uconn then
error('failed to connect to ubus')
end
local interfaces = util.get_mesh_devices(uconn) local interfaces = util.get_mesh_devices(uconn)
ubus.close(uconn)
table.sort(interfaces) table.sort(interfaces)
return interfaces return interfaces
end 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) local function is_wireless(iface)
while true do while true do
local pattern = '/sys/class/net/' .. iface .. '/lower_*' local pattern = '/sys/class/net/' .. iface .. '/lower_*'
...@@ -52,7 +66,15 @@ ...@@ -52,7 +66,15 @@
return unistd.access('/sys/class/net/' .. iface .. '/wireless') ~= nil return unistd.access('/sys/class/net/' .. iface .. '/wireless') ~= nil
end 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) local function sorted(t)
t = {unpack(t)} t = {unpack(t)}
...@@ -66,12 +88,17 @@ ...@@ -66,12 +88,17 @@
local function formatBits(bits) local function formatBits(bits)
local units = {[0]='', 'k', 'M', 'G'} local units = {[0]='', 'k', 'M', 'G'}
local unit = 0
local pow = math.floor(math.log(math.max(math.abs(bits), 1)) / math.log(1000)) for i = 1, #units do
local known_pow = math.min(pow, #units) if math.abs(bits) < 1000 then
break
end
unit = i
bits = bits / 1000
end
local significand = bits/(1000^known_pow) return string.format('%g %sbit', bits, units[unit])
return string.format('%g %sbit', significand, units[known_pow])
end end
local function statistics(key, format) local function statistics(key, format)
...@@ -190,11 +217,17 @@ ...@@ -190,11 +217,17 @@
<tr><th><%:Wireless 2.4 GHz%></th><td><%= statistics('clients/wifi24') %></td></tr> <tr><th><%:Wireless 2.4 GHz%></th><td><%= statistics('clients/wifi24') %></td></tr>
<tr><th><%:Wireless 5 GHz%></th><td><%= statistics('clients/wifi5') %></td></tr> <tr><th><%:Wireless 5 GHz%></th><td><%= statistics('clients/wifi5') %></td></tr>
</table> </table>
<div id="radios" style="display: none"> <% if radios[1] then -%>
<h3><%:Radios%></h3> <h3><%:Radios%></h3>
<table id="radio-devices"> <table>
<% for _, radio in ipairs(radios) do -%>
<tr>
<th><%| radio.name %></th>
<td><%| translatef('Channel %u', radio.channel) %></td>
</tr>
<%- end %>
</table> </table>
</div> <%- end %>
<h3><%:Traffic%></h3> <h3><%:Traffic%></h3>
<table> <table>
......
"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&&0<e;n/=10)e--;return r(t,e)}function o(t){return function(t,e,n){var r=0;if(void 0===n)return"- ";for(;e<n&&r<t.length-1;)n/=e,r++;return(n=a(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 l={id:function(t){return t},decimal:function(t){return r(t,2)},percent:function(t){return i["%s used"].sprintf(a(100*t,3)+"%")},memory:function(t){t=1-t.available/t.total;return l.percent(t)},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),t="";return 1===n?t+=i["1 day"]+", ":1<n&&(t+=i["%s days"].sprintf(n)+", "),t+=r+":",e<10&&(t+="0"),t+=e},packetsDiff:function(t,e,n){if(0<n)return n=(t-e)/n,i["%s packets/s"].sprintf(r(n,0))},bytesDiff:function(t,e,n){if(0<n)return o(8*((t-e)/n))+"bps"},bytes:function(t){return o(t)+"B"},neighbour:function(t){if(!t)return"";for(var e in c){var n=c[e].lookup_neigh(t);if(n){var r=document.createElement("span");r.appendChild(document.createTextNode("via "));var i=document.createElement("a");return i.href="http://["+n.get_addr()+"]/",i.textContent=n.get_hostname(),r.appendChild(i),r.appendChild(document.createTextNode(" ("+e+")")),r}}return"via "+t+" (unknown iface)"}};function s(e,t){return t.split("/").forEach(function(t){e=e&&e[t]}),e}function d(t,e){var n=new EventSource(t),r={};n.onmessage=function(t){t=JSON.parse(t.data);e(t,r),r=t},n.onerror=function(){n.close(),window.setTimeout(function(){d(t,e)},3e3)}}var x,k=document.body.getAttribute("data-node-address");try{x=JSON.parse(document.body.getAttribute("data-node-location"))}catch(t){}function t(t){var e=document.getElementById("mesh-vpn");if(t){e.style.display="";for(var r=document.getElementById("mesh-vpn-peers");r.lastChild;)r.removeChild(r.lastChild);t=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);t.sort(),t.forEach(function(t){var e=document.createElement("tr"),n=document.createElement("th");n.textContent=t[0],e.appendChild(n);n=document.createElement("td");t[1]?n.textContent=i.connected+" ("+l.time(t[1].established)+")":n.textContent=i["not connected"],e.appendChild(n),r.appendChild(e)})}else e.style.display="none"}function e(t){var e=document.getElementById("radios");if(t){e.style.display="";for(var r=document.getElementById("radio-devices");r.lastChild;)r.removeChild(r.lastChild);t.sort(function(t,e){return t.phy-e.phy}),t.forEach(function(t){var e=document.createElement("tr"),n=document.createElement("th");n.textContent="phy"+t.phy,e.appendChild(n);n=document.createElement("td");n.innerHTML=t.frequency+" MHz<br />Channel "+(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;e<t;e++){var n=o.height-40*e;c.moveTo(0,n-.5),c.lineTo(o.width,n-.5);var r=Math.round((r=o.height,(i*n+a*(r-n))/r))+" dBm";c.save(),c.strokeStyle="rgba(255, 255, 255, 0.9)",c.lineWidth=4,c.miterLimit=2,c.strokeText(r,o.width-5,n-2.5),c.fillText(r,o.width-5,n-2.5),c.restore()}c.stroke(),c.strokeStyle="rgba(0, 0, 0, 0.83)",c.lineWidth=1.5,c.strokeRect(.5,.5,o.width-1,o.height-1),c.restore()}())}t(),window.addEventListener("resize",l);var s=0;return window.requestAnimationFrame(function t(e){40<e-s&&(l(),n=(n+1)%o.width,s=e),window.requestAnimationFrame(t)}),{el:o,addSignal:function(t){r.push(t),t.resize(o.width,o.height)},removeSignal:function(t){r.splice(r.indexOf(t),1)}}}function f(t,o,e,n){var r,i=t.table.firstElementChild,a=t.table.insertRow(),c=a.insertCell();c.setAttribute("data-label",i.children[0].textContent),t.wireless&&((r=document.createElement("span")).textContent="",r.style.color=e,c.appendChild(r));var l=document.createElement("span");l.textContent=o,c.appendChild(l);var s={};for(var u,d,h,f,g,p,m,v,b,C=0;C<i.children.length;C++)u=i.children[C],f=h=d=void 0,(f=u.getAttribute("data-key"))&&(d=u.getAttribute("data-suffix")||"",(h=a.insertCell()).textContent="-",h.setAttribute("data-label",u.textContent),s[f]={td:h,suffix:d});function y(){b&&window.clearTimeout(b),b=window.setTimeout(function(){v&&t.signalgraph.removeSignal(v),a.parentNode.removeChild(a),n()},6e4)}function E(t){t=function(t){"::"==(t="::"==t.slice(0,2)?"0"+t:t).slice(-2)&&(t+="0");var n=(t=t.split(":")).length,r=[];return t.forEach(function(t,e){if(""===t)for(;n++<=8;)r.push(0);else/^[a-f0-9]{1,4}$/i.test(t)&&r.push(parseInt(t,16))}),r}(t);if(t){var e="";return t.forEach(function(t){e+=("0000000000000000"+t.toString(2)).slice(-16)}),e}}function w(t){var r=E(k);if(t&&t[0]){(t=t.map(function(t){var e=E(t);if(!e)return[-1];var n=0;return[n=r?function(t,e){for(var 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]||t[1]<e[1]?-1: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",200<t.inactive),v.set(200<t.inactive?null:t.signal),y()}}}function u(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={},l=[];function s(){var t;o||(o=!0,(t=new EventSource("/cgi-bin/dyn/neighbours-nodeinfo?"+encodeURIComponent(e))).addEventListener("neighbour",function(t){try{var n=JSON.parse(t.data);r=[],i=n.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 r,i},!1),t.onerror=function(){t.close(),o=!1,Object.keys(c).forEach(function(t){0<c[t]&&(c[t]--,s())})})}function u(t){var e=a[t];return e||(c[t]=3,e=a[t]=f(i,t,(l=l[0]?l:["#396AB1","#DA7C30","#3E9651","#CC2529","#535154","#6B4C9A","#922428","#948B3D"]).shift(),function(){delete c[t],delete a[t]}),s()),e}return n&&d("/cgi-bin/dyn/stations?"+encodeURIComponent(e),function(n){Object.keys(n).forEach(function(t){var e=n[t];u(t).update_wifi(e)})}),{get_neigh:u,lookup_neigh:function(t){return a[t]}}}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]=u(t,e,n)});var g=document.body.getAttribute("data-mesh-provider");g&&d(g,function(r){Object.keys(r).forEach(function(t){var e=r[t],n=c[e.ifname];n&&n.get_neigh(t).update_mesh(e)})})}(); "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){var r=0;if(void 0===n)return"- ";for(;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 s={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.available/t.total;return s.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"},neighbour:function(t){if(!t)return"";for(var e in c){var n=c[e].lookup_neigh(t);if(n){var r=document.createElement("span");r.appendChild(document.createTextNode("via "));var i=document.createElement("a");return i.href="http://["+n.get_addr()+"]/",i.textContent=n.get_hostname(),r.appendChild(i),r.appendChild(document.createTextNode(" ("+e+")")),r}}return"via "+t+" (unknown iface)"}};function l(e,t){return t.split("/").forEach(function(t){e=e&&e[t]}),e}function d(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(){d(t,n)},3e3)}}var y,w=document.body.getAttribute("data-node-address");try{y=JSON.parse(document.body.getAttribute("data-node-location"))}catch(t){}function t(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+" ("+s.time(t[1].established)+")":r.textContent=a["not connected"],e.appendChild(r),i.appendChild(e)})}else e.style.display="none"}var e=document.querySelectorAll("[data-statistics]");d("/cgi-bin/dyn/statistics",function(o,c){var u=o.uptime-c.uptime;e.forEach(function(t){var e=t.getAttribute("data-statistics"),n=t.getAttribute("data-format"),r=l(c,e),i=l(o,e);try{var a=s[n](i,r,u);switch(typeof a){case"object":t.lastChild&&t.removeChild(t.lastChild),t.appendChild(a);break;default:t.textContent=a}}catch(t){console.error(t)}});try{t(o.mesh_vpn)}catch(t){console.error(t)}});var c={};function E(a){var o=document.createElement("canvas"),c=o.getContext("2d"),u=null;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(u);c.clearRect(t,0,5,o.height),i&&(n=t,r=i,c.beginPath(),c.fillStyle=a,c.arc(n,r,1.2,0,2*Math.PI,!1),c.closePath(),c.fill())},set:function(t){u=t}}}function h(){var u=-100,s=0,n=0,r=[],l=document.createElement("canvas");l.className="signalgraph",l.height=200;var d=l.getContext("2d");function t(){l.width=l.clientWidth,r.forEach(function(t){t.resize(l.width,l.height)})}function i(){if(0!==l.clientWidth){l.width!==l.clientWidth&&t(),d.clearRect(0,0,l.width,l.height);var e=!1;r.forEach(function(t){t.highlight&&(e=!0)}),d.save(),r.forEach(function(t){e&&(d.globalAlpha=.2),t.highlight&&(d.globalAlpha=1),t.draw(n,function(t){return e=t,n=u,r=s,i=l.height,(1-(e-n)/(r-n))*i;var e,n,r,i}),d.drawImage(t.canvas,0,0)}),d.restore(),d.save(),d.beginPath(),d.strokeStyle="rgba(255, 180, 0, 0.15)",d.lineWidth=5,d.moveTo(n+2.5,0),d.lineTo(n+2.5,l.height),d.stroke(),function(){var t,e,n,r,i=Math.floor(l.height/40);d.save(),d.lineWidth=.5,d.strokeStyle="rgba(0, 0, 0, 0.25)",d.fillStyle="rgba(0, 0, 0, 0.5)",d.textAlign="end",d.textBaseline="bottom",d.beginPath();for(var a=0;a<i;a++){var o=l.height-40*a;d.moveTo(0,o-.5),d.lineTo(l.width,o-.5);var c=Math.round((t=o,e=u,n=s,r=l.height,(e*t+n*(r-t))/r))+" dBm";d.save(),d.strokeStyle="rgba(255, 255, 255, 0.9)",d.lineWidth=4,d.miterLimit=2,d.strokeText(c,l.width-5,o-2.5),d.fillText(c,l.width-5,o-2.5),d.restore()}d.stroke(),d.strokeStyle="rgba(0, 0, 0, 0.83)",d.lineWidth=1.5,d.strokeRect(.5,.5,l.width-1,l.height-1),d.restore()}()}}t(),window.addEventListener("resize",i);var a=0;return window.requestAnimationFrame(function t(e){40<e-a&&(i(),n=(n+1)%l.width,a=e),window.requestAnimationFrame(t)}),{el:l,addSignal:function(t){r.push(t),t.resize(l.width,l.height)},removeSignal:function(t){r.splice(r.indexOf(t),1)}}}function f(t,d,e,n){var r=t.table.firstElementChild,i=t.table.insertRow(),a=i.insertCell();if(a.setAttribute("data-label",r.children[0].textContent),t.wireless){var o=document.createElement("span");o.textContent="",o.style.color=e,a.appendChild(o)}var h=document.createElement("span");h.textContent=d,a.appendChild(h);var c,f,u,s,l,g={};function v(t){var e=t.getAttribute("data-key");if(e){var n=t.getAttribute("data-suffix")||"",r=i.insertCell();r.textContent="-",r.setAttribute("data-label",t.textContent),g[e]={td:r,suffix:n}}}for(var p=0;p<r.children.length;p++)v(r.children[p]);function m(){l&&window.clearTimeout(l),l=window.setTimeout(function(){s&&t.signalgraph.removeSignal(s),i.parentNode.removeChild(i),n()},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}}function C(t){var r=b(w);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}}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),(u=i.insertCell()).textContent="-",u.setAttribute("data-label",r.children[Object.keys(g).length+3].textContent),s=E(e),t.signalgraph.addSignal(s)),i.onmouseenter=function(){i.classList.add("highlight"),s&&(s.highlight=!0)},i.onmouseleave=function(){i.classList.remove("highlight"),s&&(s.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,u=(a*=c)-(r*=c),s=(o*=c)-(i*=c),l=Math.sin(u/2)*Math.sin(u/2)+Math.sin(s/2)*Math.sin(s/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,u,s,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,u.textContent=Math.round(t.inactive/1e3)+" s",i.classList.toggle("inactive",200<t.inactive),s.set(200<t.inactive?null:t.signal),m()}}}function u(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={},u=[];function s(){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);(r=[],i=n.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 r,i},!1),t.onerror=function(){t.close(),o=!1,Object.keys(c).forEach(function(t){0<c[t]&&(c[t]--,s())})}}}function l(t){var e=a[t];return e||(c[t]=3,e=a[t]=f(i,t,(u[0]||(u=["#396AB1","#DA7C30","#3E9651","#CC2529","#535154","#6B4C9A","#922428","#948B3D"]),u.shift()),function(){delete c[t],delete a[t]}),s()),e}return n&&d("/cgi-bin/dyn/stations?"+encodeURIComponent(e),function(n){Object.keys(n).forEach(function(t){var e=n[t];l(t).update_wifi(e)})}),{get_neigh:l,lookup_neigh:function(t){return a[t]}}}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]=u(t,e,n)});var n=document.body.getAttribute("data-mesh-provider");n&&d(n,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 \ No newline at end of file
...@@ -31,8 +31,8 @@ msgstr "Automatische Updates" ...@@ -31,8 +31,8 @@ msgstr "Automatische Updates"
msgid "Bandwidth limit" msgid "Bandwidth limit"
msgstr "Bandbreitenlimit" msgstr "Bandbreitenlimit"
msgid "Channel" msgid "Channel %u"
msgstr "Kanal" msgstr "Kanal %u"
msgid "Clients" msgid "Clients"
msgstr "Clients" msgstr "Clients"
......
...@@ -22,7 +22,7 @@ msgstr "" ...@@ -22,7 +22,7 @@ msgstr ""
msgid "Bandwidth limit" msgid "Bandwidth limit"
msgstr "" msgstr ""
msgid "Channel" msgid "Channel %u"
msgstr "" msgstr ""
msgid "Clients" msgid "Clients"
......
...@@ -216,50 +216,6 @@ ...@@ -216,50 +216,6 @@
}); });
} }
function update_radios(wireless) {
function channel(frequency) {
if (frequency===2484)
return 14
if (2412<=frequency && frequency<=2472)
return (frequency-2407)/5
if (5160<=frequency && frequency<=5885)
return (frequency-5000)/5
return 'unknown'
}
var div = document.getElementById('radios');
if (!wireless) {
div.style.display = 'none';
return;
}
div.style.display = '';
var table = document.getElementById('radio-devices');
while (table.lastChild)
table.removeChild(table.lastChild);
wireless.sort(function (a, b) {
return a.phy - b.phy;
});
wireless.forEach(function (radio) {
var tr = document.createElement('tr');
var th = document.createElement('th');
th.textContent = "phy" + radio.phy;
tr.appendChild(th);
var td = document.createElement('td');
td.innerHTML = radio.frequency + " MHz<br />Channel " + channel(radio.frequency);
tr.appendChild(td);
table.appendChild(tr);
});
}
var statisticsElems = document.querySelectorAll('[data-statistics]'); var statisticsElems = document.querySelectorAll('[data-statistics]');
add_event_source('/cgi-bin/dyn/statistics', function(data, dataPrev) { add_event_source('/cgi-bin/dyn/statistics', function(data, dataPrev) {
...@@ -274,14 +230,13 @@ ...@@ -274,14 +230,13 @@
try { try {
var format_result = formats[format](value, valuePrev, diff); var format_result = formats[format](value, valuePrev, diff);
switch (typeof format_result) { switch (typeof format_result) {
case "string":
elem.textContent = format_result;
break;
case "object": case "object":
if (elem.lastChild) if (elem.lastChild)
elem.removeChild(elem.lastChild); elem.removeChild(elem.lastChild);
elem.appendChild(format_result); elem.appendChild(format_result);
break; break;
default:
elem.textContent = format_result;
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
...@@ -293,11 +248,6 @@ ...@@ -293,11 +248,6 @@
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
try {
update_radios(data.wireless);
} catch (e) {
console.error(e);
}
}) })
function haversine(lat1, lon1, lat2, lon2) { function haversine(lat1, lon1, lat2, lon2) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment