luci-app-babeld: add babeld overview 4664/head
authorNick Hainke <vincent@systemli.org>
Fri, 18 Dec 2020 18:17:07 +0000 (19:17 +0100)
committerNick Hainke <vincent@systemli.org>
Sat, 19 Dec 2020 12:54:23 +0000 (13:54 +0100)
Add overview of babeld status, xroutes and routes.

Signed-off-by: Nick Hainke <vincent@systemli.org>
applications/luci-app-babeld/Makefile [new file with mode: 0644]
applications/luci-app-babeld/luasrc/model/cbi/babeld.lua [new file with mode: 0644]
applications/luci-app-babeld/root/usr/share/luci/menu.d/luci-app-babeld.json [new file with mode: 0644]
applications/luci-app-babeld/root/usr/share/rpcd/acl.d/luci-app-babeld.json [new file with mode: 0644]

diff --git a/applications/luci-app-babeld/Makefile b/applications/luci-app-babeld/Makefile
new file mode 100644 (file)
index 0000000..adfd08c
--- /dev/null
@@ -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 (file)
index 0000000..2169de4
--- /dev/null
@@ -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]
+
+               %>
+               <div class="cbi-section-node">
+                       <h3>Babel-Info</h3>
+                       <div class="table" id=babel_status_main">
+                               <div class="tr table-titles">
+                                       <div class="th">Version</div>
+                                       <div class="th">Version-Daemon</div>
+                                       <div class="th">Host</div>
+                                       <div class="th">ID</div>
+                                       <div class="th">Status</div>
+                               </div>
+                               <div class="tr">
+                                       <div class="td"><%= babel_version %></div>
+                                       <div class="td"><%= babeld_version %></div>
+                                       <div class="td"><%= babeld_host %></div>
+                                       <div class="td"><%= babeld_id %></div>
+                                       <div class="td"><%= babeld_status %></div>
+                               </div>
+                       </div>
+               </div>
+               
+               <%
+               local xroutes = {}
+               for key,value in ipairs(t) do
+                       if string.match(value, "xroute") then
+                               xroutes[#xroutes+1] = value
+                       end
+               end
+               %>
+
+               <div class="cbi-section-node">
+                       <h3>X-Routes</h3>
+                       <div class="table" id=babel_overview_xroute">
+                               <div class="tr table-titles">
+                                       <div class="th">Route</div>
+                                       <div class="th">Prefix</div>
+                                       <div class="th">From</div>
+                                       <div class="th">Metric</div>
+                               </div>
+                               <%
+                               for key,route in ipairs(xroutes) do
+                                       local route_sep = string.split(route," ")
+                               %>
+                                       <div class="tr">
+                                               <div class="td"><%= route_sep[3] %></div>
+                                               <div class="td"><%= route_sep[5] %></div>
+                                               <div class="td"><%= route_sep[7] %></div>
+                                               <div class="td"><%= route_sep[9] %></div>
+                                       </div>
+                               <%
+                               end
+                               %>
+                       </div>
+               </div>
+               
+               <%
+               local routes = {}
+               for key,value in ipairs(t) do
+                       if string.match(value, "add route") then
+                                       routes[#routes+1] = value
+                       end
+               end
+               %>
+
+               <div class="cbi-section-node">
+                       <h3>Routes</h3>
+                       <div class="table" id=babel_overview_route">
+                               <div class="tr table-titles">
+                                       <div class="th">Prefix</div>
+                                       <div class="th">From</div>
+                                       <div class="th">Installed</div>
+                                       <div class="th">ID</div>
+                                       <div class="th">Metric</div>
+                                       <div class="th">Ref-Metric</div>
+                                       <div class="th">Via</div>
+                                       <div class="th">Interface</div>
+                               </div>
+                               <%
+                               for key,route in ipairs(routes) do
+                                       local route_sep = string.split(route," ")
+                               %>
+
+                                       <div class="tr">
+                                               <div class="td"><%= route_sep[5] %></div>
+                                               <div class="td"><%= route_sep[7] %></div>
+                                               <div class="td"><%= route_sep[9] %></div>
+                                               <div class="td"><%= route_sep[11] %></div>
+                                               <div class="td"><%= route_sep[13] %></div>
+                                               <div class="td"><%= route_sep[15] %></div>
+                                               <div class="td"><%= route_sep[17] %></div>
+                                               <div class="td"><%= route_sep[19] %></div>
+                                       </div>
+                               <%
+                               end
+                               %>
+                       </div>
+               </div>
+       ]])
+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 (file)
index 0000000..8d0b010
--- /dev/null
@@ -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 (file)
index 0000000..51687ba
--- /dev/null
@@ -0,0 +1,11 @@
+{
+       "luci-app-babeld": {
+               "description": "Grant UCI access for babeld",
+               "read": {
+                       "uci": [ "babeld" ]
+               },
+               "write": {
+                       "uci": [ "babeld" ]
+               }
+       }
+}