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 242ef0b3..b936b61d 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 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&&0e[0]?-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=10&&n>0;r/=10)n--;return t(e,n)}function n(e){return g["%s packets/s"].sprintf(t(e,0))}function r(t,n,r){var i=0;if(void 0===r)return"- ";for(;r>n&&i40&&(i(),u=(u+1)%f.width,h=t),window.requestAnimationFrame(o)}var a=-100,c=0,u=0,s=[],f=document.createElement("canvas");f.className="signalgraph",f.height=200;var l=f.getContext("2d");r(),window.addEventListener("resize",i);var h=0;return window.requestAnimationFrame(o),{el:f,addSignal:function(t){s.push(t),t.resize(f.width,f.height)},removeSignal:function(t){s.splice(s.indexOf(t),1)}}}function d(t,e,n,r){function i(){k&&window.clearTimeout(k),k=window.setTimeout(function(){x&&t.signalgraph.removeSignal(x),h.parentNode.removeChild(h),r()},6e4)}function o(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}function a(t){var e=o(t);if(e){var n="";return e.forEach(function(t){n+=("0000000000000000"+t.toString(2)).slice(-16)}),n}}function c(t,e){var n;for(n=0;ne[0]?-1:t[1]e[1]?1:0});var n=t[0][2];return n&&!/^fe80:/i.test(n)?n:void 0}}var s=t.table.firstElementChild,h=t.table.insertRow(),d=h.insertCell();if(t.wireless){var v=document.createElement("span");v.textContent="⬤ ",v.style.color=n,d.appendChild(v)}var g=document.createElement("span");g.textContent=e,d.appendChild(g);for(var p={},y=0;y200),x.set(t.inactive>200?null:t.signal),i()}}}function v(t,e,n){function r(){return g[0]||(g=["#396AB1","#DA7C30","#3E9651","#CC2529","#535154","#6B4C9A","#922428","#948B3D"]),g.shift()}function i(t){var e=[],n=t.network.mesh;return Object.keys(n).forEach(function(t){var r=n[t].interfaces;Object.keys(r).forEach(function(t){r[t].forEach(function(t){e.push(t)})})}),e}function o(){if(!l){l=!0;var t=new EventSource("/cgi-bin/dyn/neighbours-nodeinfo?"+encodeURIComponent(e));t.addEventListener("neighbour",function(t){try{var e=JSON.parse(t.data);i(e).forEach(function(t){var n=s[t];if(n){delete v[t];try{n.update_nodeinfo(e)}catch(t){console.error(t)}}})}catch(t){console.error(t)}},!1),t.onerror=function(){t.close(),l=!1,Object.keys(v).forEach(function(t){v[t]>0&&(v[t]--,o())})}}}function a(t){var e=s[t];return e||(v[t]=3,e=s[t]=d(f,t,r(),function(){delete v[t],delete s[t]}),o()),e}var c,s={};n&&(c=h(),t.appendChild(c.el));var f={table:t.firstElementChild,signalgraph:c,ifname:e,wireless:n},l=!1,v={},g=[];return n&&u("/cgi-bin/dyn/stations?"+encodeURIComponent(e),function(t){Object.keys(t).forEach(function(e){var n=t[e];a(e).update_wifi(n)})}),{get_neigh:a}}var g=JSON.parse(document.body.getAttribute("data-translations"));String.prototype.sprintf=function(){var t=0,e=arguments;return this.replace(/%s/g,function(){return e[t++]})};var m,p={id:function(t){return t},decimal:function(e){return t(e,2)},percent:function(t){return g["%s used"].sprintf(e(100*t,3)+"%")},memory:function(t){var e=1-(t.free+t.buffers+t.cached)/t.total;return p.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+=g["1 day"]+", ":n>1&&(i+=g["%s days"].sprintf(n)+", "),i+=r+":",e<10&&(i+="0"),i+=e},packetsDiff:function(t,e,r){if(r>0)return n((t-e)/r)},bytesDiff:function(t,e,n){if(n>0)return o((t-e)/n)},bytes:function(t){return a(t)}},b=document.body.getAttribute("data-node-address");try{m=JSON.parse(document.body.getAttribute("data-node-location"))}catch(t){}var y=document.querySelectorAll("[data-statistics]");u("/cgi-bin/dyn/statistics",function(t,e){var n=t.uptime-e.uptime;y.forEach(function(r){var i=r.getAttribute("data-statistics"),o=r.getAttribute("data-format"),a=c(e,i),u=c(t,i);try{var s=p[o](u,a,n);void 0!==s&&(r.textContent=s)}catch(t){console.error(t)}});try{s(t.mesh_vpn)}catch(t){console.error(t)}});var C={};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]=v(t,e,n)});var w=document.body.getAttribute("data-mesh-provider");w&&u(w,function(t){Object.keys(t).forEach(function(e){var n=t[e],r=C[n.ifname];r&&r.get_neigh(e).update_mesh(n)})})}(); \ 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 b82c6a11..fcd6fd95 100644 --- a/package/gluon-status-page/javascript/status-page.js +++ b/package/gluon-status-page/javascript/status-page.js @@ -39,6 +39,9 @@ function prettyPrefix(prefixes, step, d) { var prefix = 0; + if (d === undefined) + return "- "; + while (d > step && prefix < prefixes.length - 1) { d /= step; prefix++;