%-
local ubus = require 'ubus'
local unistd = require 'posix.unistd'
local util = require 'gluon.util'
local translations = {}
local site_i18n = i18n 'gluon-site'
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 formatBits(bits)
local units = {[0]='', 'k', 'M', 'G'}
local pow = math.floor(math.log(math.max(math.abs(bits), 1)) / math.log(1000))
local known_pow = math.min(pow, #units)
local significand = bits/(1000^known_pow)
return string.format('%g %sbit', significand, units[known_pow])
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 -%>
<%| enabled(nodeinfo.network.mesh_vpn.enabled) %>
<% if nodeinfo.network.mesh_vpn.provider then -%>
<%| nodeinfo.network.mesh_vpn.provider %>
<%- end %>
<% if nodeinfo.network.mesh_vpn.bandwidth_limit.enabled then -%>
<%:Bandwidth limit%>
<% if nodeinfo.network.mesh_vpn.bandwidth_limit.ingress then -%>
▼ <%| formatBits(nodeinfo.network.mesh_vpn.bandwidth_limit.ingress*1000) %>/s <%:downstream%>
<%- end %>
<% if nodeinfo.network.mesh_vpn.bandwidth_limit.egress then -%>
▲ <%| formatBits(nodeinfo.network.mesh_vpn.bandwidth_limit.egress*1000) %>/s <%:upstream%>
<%- end %>
<%- end %>
<%- end %>
<%:Site%>
<%| site.site_name() %>
<% if nodeinfo.system.domain_code then -%>
<%:Domain%>
<%| site.domain_names[nodeinfo.system.domain_code]() %>
<% if nodeinfo.system.domain_code ~= nodeinfo.system.primary_domain_code then %>
(<%| site.domain_names[nodeinfo.system.primary_domain_code]() %>)
<%- end %>
<%
for _, iface in ipairs(interfaces) do
local wireless = is_wireless(iface)
local address = util.readfile('/sys/class/net/' .. iface .. '/address')
if address then
%>