%-
local ubus = require 'ubus'
local unistd = require 'posix.unistd'
local util = require 'gluon.util'
local translations = {}
local function _(v)
translations[v] = translate(v)
end
-- i18n strings for JavaScript
_('.') -- decimal point
_('connected')
_('not connected')
_('1 day')
_('%s days')
_('%s used')
_('%s packets/s')
local function get_mesh()
local f = loadfile('/lib/gluon/status-page/mesh.lua')
if f then
return f()
end
return {}
end
local mesh = get_mesh()
local function get_interfaces()
local uconn = ubus.connect()
if not uconn then
error('failed to connect to ubus')
end
local interfaces = util.get_mesh_devices(uconn)
ubus.close(uconn)
table.sort(interfaces)
return interfaces
end
local function is_wireless(iface)
while true do
local pattern = '/sys/class/net/' .. iface .. '/lower_*'
local lower = util.glob(pattern)[1]
if not lower then break end
iface = lower:sub(pattern:len())
end
return unistd.access('/sys/class/net/' .. iface .. '/wireless') ~= nil
end
local interfaces = get_interfaces()
local function sorted(t)
t = {unpack(t)}
table.sort(t)
return t
end
local function enabled(v)
return v and translate('enabled') or translate('disabled')
end
local function statistics(key, format)
return string.format('', pcdata(key), pcdata(format or 'id'))
end
local function statisticsTraffic(key)
return string.format('%s %s %s',
statistics(key .. '/packets', 'packetsDiff'),
statistics(key .. '/bytes', 'bytesDiff'),
statistics(key .. '/bytes', 'bytes')
)
end
http:prepare_content("application/xhtml+xml")
-%>
<%| nodeinfo.hostname %> - <%:Status%>
>
<%| nodeinfo.hostname %>
<%:Overview%>
<%:Node name%>
<%| nodeinfo.hostname %>
<% if nodeinfo.owner and nodeinfo.owner.contact then -%>
<%- end %>
<% if nodeinfo.software.autoupdater then -%>
<%:Automatic updates%>
<%| enabled(nodeinfo.software.autoupdater.enabled) %><%|
nodeinfo.software.autoupdater.enabled and
string.format(' (%s)', nodeinfo.software.autoupdater.branch)
%>
<%- end %>
<%:Monitoring%>
<%:Uptime%>
<%= statistics('uptime', 'time') %>
<%:Load average%>
<%= statistics('loadavg', 'decimal') %>
<%:RAM%>
<%= statistics('memory', 'memory') %>
<%:Filesystem%>
<%= statistics('rootfs_usage', 'percent') %>
<%:Gateway%>
<%= statistics('gateway') %>
<%:Clients%>
<%= statistics('clients/total') %>
<%:Traffic%>
<%:Transmitted%>
<%= statisticsTraffic('traffic/tx') %>
<%:Received%>
<%= statisticsTraffic('traffic/rx') %>
<%:Forwarded%>
<%= statisticsTraffic('traffic/forward') %>
<%:Mesh VPN%>
<%:Neighbors%>
<%
for _, iface in ipairs(interfaces) do
local wireless = is_wireless(iface)
local address = util.readfile('/sys/class/net/' .. iface .. '/address')
if address then
%>