gluon-status-page: use ubus to get radio channels

Do not depend on the respondd-airtime module just to get the configured
channels. This removes the display of the frequency in addition to the
channel, as it is not readily available.

In addition, the translation string is improved to allow for text after
the channel number.
This commit is contained in:
Matthias Schiffer 2021-08-07 22:16:10 +02:00
parent f2e0f7e3a8
commit 0d3fa6b59b
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
5 changed files with 42 additions and 63 deletions

View File

@ -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 @@
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)}
@ -195,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>

File diff suppressed because one or more lines are too long

View File

@ -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"

View File

@ -22,7 +22,7 @@ msgstr ""
msgid "Bandwidth limit" msgid "Bandwidth limit"
msgstr "" msgstr ""
msgid "Channel" msgid "Channel %u"
msgstr "" msgstr ""
msgid "Clients" 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]'); 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) {
@ -293,11 +249,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) {