From 35761aa3a07e6a9ee75cd9a2f4536c11f1cdd9dd Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Fri, 18 Dec 2020 19:17:07 +0100 Subject: [PATCH] luci-app-babeld: add babeld overview Add overview of babeld status, xroutes and routes. Signed-off-by: Nick Hainke --- applications/luci-app-babeld/Makefile | 10 ++ .../luasrc/model/cbi/babeld.lua | 127 ++++++++++++++++++ .../share/luci/menu.d/luci-app-babeld.json | 13 ++ .../usr/share/rpcd/acl.d/luci-app-babeld.json | 11 ++ 4 files changed, 161 insertions(+) create mode 100644 applications/luci-app-babeld/Makefile create mode 100644 applications/luci-app-babeld/luasrc/model/cbi/babeld.lua create mode 100644 applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json create mode 100644 applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json diff --git a/applications/luci-app-babeld/Makefile b/applications/luci-app-babeld/Makefile new file mode 100644 index 0000000000..adfd08ccd8 --- /dev/null +++ b/applications/luci-app-babeld/Makefile @@ -0,0 +1,10 @@ +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=LuCI support for babeld +LUCI_DEPENDS:=+babeld +luci-compat +LUCI_PKGARCH:=all + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature + diff --git a/applications/luci-app-babeld/luasrc/model/cbi/babeld.lua b/applications/luci-app-babeld/luasrc/model/cbi/babeld.lua new file mode 100644 index 0000000000..2169de4731 --- /dev/null +++ b/applications/luci-app-babeld/luasrc/model/cbi/babeld.lua @@ -0,0 +1,127 @@ +m = Map("babeld", translate("Babeld Overview")) +m.pageaction = false + +s = m:section(NamedSection, "__babeldoverview__") + +function s.render(self, sid) + local tpl = require "luci.template" + + tpl.render_string([[ + <% + local utl = require "luci.util" + local v6_port = 33123 + -- FIXME: check if call is correct + local dump = utl.exec("(echo dump | nc ::1 %d)" % v6_port) + local t = {} + + for strline in string.gmatch(dump, "[^\n]+") do + t[#t+1] = strline; + end + + local babel_version = t[1] + local babeld_version = t[2] + local babeld_host = string.split(t[3], " ")[2] + local babeld_id = string.split(t[4], " ")[2] + local babeld_status = t[5] + + %> +
+

Babel-Info

+
+
+
Version
+
Version-Daemon
+
Host
+
ID
+
Status
+
+
+
<%= babel_version %>
+
<%= babeld_version %>
+
<%= babeld_host %>
+
<%= babeld_id %>
+
<%= babeld_status %>
+
+
+
+ + <% + local xroutes = {} + for key,value in ipairs(t) do + if string.match(value, "xroute") then + xroutes[#xroutes+1] = value + end + end + %> + +
+

X-Routes

+
+
+
Route
+
Prefix
+
From
+
Metric
+
+ <% + for key,route in ipairs(xroutes) do + local route_sep = string.split(route," ") + %> +
+
<%= route_sep[3] %>
+
<%= route_sep[5] %>
+
<%= route_sep[7] %>
+
<%= route_sep[9] %>
+
+ <% + end + %> +
+
+ + <% + local routes = {} + for key,value in ipairs(t) do + if string.match(value, "add route") then + routes[#routes+1] = value + end + end + %> + +
+

Routes

+
+
+
Prefix
+
From
+
Installed
+
ID
+
Metric
+
Ref-Metric
+
Via
+
Interface
+
+ <% + for key,route in ipairs(routes) do + local route_sep = string.split(route," ") + %> + +
+
<%= route_sep[5] %>
+
<%= route_sep[7] %>
+
<%= route_sep[9] %>
+
<%= route_sep[11] %>
+
<%= route_sep[13] %>
+
<%= route_sep[15] %>
+
<%= route_sep[17] %>
+
<%= route_sep[19] %>
+
+ <% + end + %> +
+
+ ]]) +end + +return m diff --git a/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json b/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json new file mode 100644 index 0000000000..8d0b010c21 --- /dev/null +++ b/applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json @@ -0,0 +1,13 @@ +{ + "admin/status/babeld": { + "title": "Babeld", + "action": { + "type": "cbi", + "path": "babeld", + "post": { "cbi.submit": true } + }, + "depends": { + "acl": [ "luci-app-babeld" ] + } + } +} diff --git a/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json b/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json new file mode 100644 index 0000000000..51687bad5c --- /dev/null +++ b/applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json @@ -0,0 +1,11 @@ +{ + "luci-app-babeld": { + "description": "Grant UCI access for babeld", + "read": { + "uci": [ "babeld" ] + }, + "write": { + "uci": [ "babeld" ] + } + } +} -- 2.30.2