gluon-status-page: move mesh protocol specific definitions into a separate file
This commit is contained in:
parent
3282a63ea7
commit
35ade80f1c
@ -18,6 +18,16 @@
|
|||||||
_('%s used')
|
_('%s used')
|
||||||
_('%s packets/s')
|
_('%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 function get_interfaces()
|
||||||
local uconn = ubus.connect()
|
local uconn = ubus.connect()
|
||||||
if not uconn then
|
if not uconn then
|
||||||
@ -77,7 +87,11 @@
|
|||||||
|
|
||||||
<link rel="stylesheet" href="/static/status-page.css" type="text/css" />
|
<link rel="stylesheet" href="/static/status-page.css" type="text/css" />
|
||||||
</head>
|
</head>
|
||||||
<body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%= attr('data-translations', translations) .. attr('data-node-location', nodeinfo.location) %>>
|
<body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%=
|
||||||
|
attr('data-translations', translations) ..
|
||||||
|
attr('data-node-location', nodeinfo.location) ..
|
||||||
|
attr('data-mesh-provider', mesh.provider)
|
||||||
|
%>>
|
||||||
<header>
|
<header>
|
||||||
<h1><%| nodeinfo.hostname %></h1>
|
<h1><%| nodeinfo.hostname %></h1>
|
||||||
</header>
|
</header>
|
||||||
@ -139,7 +153,9 @@
|
|||||||
<table class="datatable">
|
<table class="datatable">
|
||||||
<tr>
|
<tr>
|
||||||
<th><%:Node%></th>
|
<th><%:Node%></th>
|
||||||
<th>TQ</th>
|
<% for i, v in ipairs(mesh.attrs or {}) do %>
|
||||||
|
<th<%= attr('data-key', v[1]) .. attr('data-suffix', v[3]) %>><%| v[2] %></th>
|
||||||
|
<% end %>
|
||||||
<% if wireless then %>
|
<% if wireless then %>
|
||||||
<th>dBm</th>
|
<th>dBm</th>
|
||||||
<th><%:Distance%></th>
|
<th><%:Distance%></th>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -412,6 +412,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Neighbour(iface, addr, color, destroy) {
|
function Neighbour(iface, addr, color, destroy) {
|
||||||
|
var th = iface.table.firstElementChild;
|
||||||
var el = iface.table.insertRow();
|
var el = iface.table.insertRow();
|
||||||
|
|
||||||
var tdHostname = el.insertCell();
|
var tdHostname = el.insertCell();
|
||||||
@ -427,8 +428,26 @@
|
|||||||
hostname.textContent = addr;
|
hostname.textContent = addr;
|
||||||
tdHostname.appendChild(hostname);
|
tdHostname.appendChild(hostname);
|
||||||
|
|
||||||
var tdTQ = el.insertCell();
|
var meshAttrs = {};
|
||||||
tdTQ.textContent = '-';
|
|
||||||
|
function add_attr(attr) {
|
||||||
|
var key = attr.getAttribute('data-key');
|
||||||
|
if (!key)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var suffix = attr.getAttribute('data-suffix') || '';
|
||||||
|
|
||||||
|
var td = el.insertCell();
|
||||||
|
td.textContent = '-';
|
||||||
|
|
||||||
|
meshAttrs[key] = {
|
||||||
|
'td': td,
|
||||||
|
'suffix': suffix,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < th.children.length; i++)
|
||||||
|
add_attr(th.children[i]);
|
||||||
|
|
||||||
var tdSignal;
|
var tdSignal;
|
||||||
var tdDistance;
|
var tdDistance;
|
||||||
@ -585,7 +604,10 @@
|
|||||||
updated();
|
updated();
|
||||||
},
|
},
|
||||||
'update_mesh': function(mesh) {
|
'update_mesh': function(mesh) {
|
||||||
tdTQ.textContent = Math.round(mesh.tq / 2.55) + ' %';
|
Object.keys(meshAttrs).forEach(function(key) {
|
||||||
|
var attr = meshAttrs[key];
|
||||||
|
attr.td.textContent = mesh[key] + attr.suffix;
|
||||||
|
});
|
||||||
|
|
||||||
updated();
|
updated();
|
||||||
},
|
},
|
||||||
@ -724,14 +746,17 @@
|
|||||||
interfaces[ifname] = Interface(elem, ifname, wireless);
|
interfaces[ifname] = Interface(elem, ifname, wireless);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_event_source('/cgi-bin/dyn/neighbours-batadv', function(data) {
|
var mesh_provider = document.body.getAttribute('data-mesh-provider');
|
||||||
Object.keys(data).forEach(function (addr) {
|
if (mesh_provider) {
|
||||||
var mesh = data[addr];
|
add_event_source(mesh_provider, function(data) {
|
||||||
var iface = interfaces[mesh.ifname];
|
Object.keys(data).forEach(function (addr) {
|
||||||
if (!iface)
|
var mesh = data[addr];
|
||||||
return;
|
var iface = interfaces[mesh.ifname];
|
||||||
|
if (!iface)
|
||||||
|
return;
|
||||||
|
|
||||||
iface.get_neigh(addr).update_mesh(mesh);
|
iface.get_neigh(addr).update_mesh(mesh);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
return {
|
||||||
|
provider = '/cgi-bin/dyn/neighbours-batadv',
|
||||||
|
-- List of mesh-specific attributes, each a tuple of
|
||||||
|
-- 1) the internal identifier (JSON key)
|
||||||
|
-- 2) human-readable key (not translatable yet)
|
||||||
|
-- 3) value suffix (optional)
|
||||||
|
attrs = {
|
||||||
|
{'tq', 'TQ', ' %'},
|
||||||
|
},
|
||||||
|
}
|
@ -76,7 +76,7 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
|||||||
if (!neigh)
|
if (!neigh)
|
||||||
return NL_OK;
|
return NL_OK;
|
||||||
|
|
||||||
json_object_object_add(neigh, "tq", json_object_new_int(tq));
|
json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255));
|
||||||
json_object_object_add(neigh, "ifname", json_object_new_string(ifname));
|
json_object_object_add(neigh, "ifname", json_object_new_string(ifname));
|
||||||
|
|
||||||
json_object_object_add(opts->obj, mac1, neigh);
|
json_object_object_add(opts->obj, mac1, neigh);
|
||||||
|
Loading…
Reference in New Issue
Block a user