Browse Source

add connectivity to router name

tags/0.6.2
Souichi Tomoe 4 years ago
parent
commit
496b87720d
1 changed files with 39 additions and 16 deletions
  1. +39
    -16
      files/www/freifunk/cgi-bin/status

+ 39
- 16
files/www/freifunk/cgi-bin/status View File

@@ -97,29 +97,52 @@ fi
%>

<script>

var own_data = <% /usr/sbin/print_map.sh %>;

function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}

var neighbors = document.getElementsByClassName("neighbor");
Array.prototype.forEach.call(neighbors, function(el) {
var xhr = createCORSRequest('GET', el.href + "/cgi-bin/data");
xhr.onload = function() {
var json = JSON.parse(xhr.responseText);
if('name' in json) {
el.textContent = json.name;
+ var neigh_data = JSON.parse(xhr.responseText);
+
+ // set node name
+ if('name' in neigh_data) {
+ el.textContent = neigh_data.name;
+ }
+
+ // add connection quality
+ var qual = -1;
+ if('links' in neigh_data && 'links' in own_data) {
+ Array.prototype.forEach.call(neigh_data.links, function(neigh_link) {
+ Array.prototype.forEach.call(own_data.links, function(own_link) {
+ if(own_link.dmac == neigh_link.smac) {
+ qual = Math.max(qual, own_link.qual, neigh_link.qual);
+ }
+ });
+ });
+ }
+
+ if(qual > 0)
+ {
+ var e = document.createTextNode(" (" + (100. * qual / 255.).toFixed(0) + "%)");
+ el.parentNode.appendChild(e);
}
};


Loading…
Cancel
Save