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

Status page improvements
This commit is contained in:
Matthias Schiffer 2021-09-04 21:11:05 +02:00 committed by GitHub
commit 90fe74bf4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 70 deletions

View File

@ -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)}
@ -66,12 +88,17 @@
local function formatBits(bits)
local units = {[0]='', 'k', 'M', 'G'}
local unit = 0
local pow = math.floor(math.log(math.max(math.abs(bits), 1)) / math.log(1000))
local known_pow = math.min(pow, #units)
for i = 1, #units do
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', significand, units[known_pow])
return string.format('%g %sbit', bits, units[unit])
end
local function statistics(key, format)
@ -190,11 +217,17 @@
<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>
</table>
<div id="radios" style="display: none">
<% if radios[1] then -%>
<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>
</div>
<%- end %>
<h3><%:Traffic%></h3>
<table>

File diff suppressed because one or more lines are too long

View File

@ -31,8 +31,8 @@ msgstr "Automatische Updates"
msgid "Bandwidth limit"
msgstr "Bandbreitenlimit"
msgid "Channel"
msgstr "Kanal"
msgid "Channel %u"
msgstr "Kanal %u"
msgid "Clients"
msgstr "Clients"

View File

@ -22,7 +22,7 @@ msgstr ""
msgid "Bandwidth limit"
msgstr ""
msgid "Channel"
msgid "Channel %u"
msgstr ""
msgid "Clients"

View File

@ -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]');
add_event_source('/cgi-bin/dyn/statistics', function(data, dataPrev) {
@ -274,14 +230,13 @@
try {
var format_result = formats[format](value, valuePrev, diff);
switch (typeof format_result) {
case "string":
elem.textContent = format_result;
break;
case "object":
if (elem.lastChild)
elem.removeChild(elem.lastChild);
elem.appendChild(format_result);
break;
default:
elem.textContent = format_result;
}
} catch (e) {
console.error(e);
@ -293,11 +248,6 @@
} catch (e) {
console.error(e);
}
try {
update_radios(data.wireless);
} catch (e) {
console.error(e);
}
})
function haversine(lat1, lon1, lat2, lon2) {