From 8b63ac792a9691dfcbaf539db973222a450eb666 Mon Sep 17 00:00:00 2001
From: Christof Schulze <christof.schulze@gmx.net>
Date: Sat, 11 Feb 2017 17:25:06 +0100
Subject: [PATCH] gluon-statuspage-api: make
 lib/gluon/status-page/www/cgi-bin/interfaces mesh-protocol agnostic

---
 package/gluon-status-page-api/Makefile        |  2 +-
 .../gluon/status-page/www/cgi-bin/interfaces  | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/package/gluon-status-page-api/Makefile b/package/gluon-status-page-api/Makefile
index 1c54dac0a..27afccd1e 100644
--- a/package/gluon-status-page-api/Makefile
+++ b/package/gluon-status-page-api/Makefile
@@ -14,7 +14,7 @@ define Package/gluon-status-page-api
   SECTION:=gluon
   CATEGORY:=Gluon
   TITLE:=API for gluon-status-page
-  DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-respondd +libiwinfo +libjson-c +libnl-tiny
+  DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-respondd +libiwinfo +libjson-c +libnl-tiny +libubus-lua
 endef
 
 define Build/Prepare
diff --git a/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces b/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces
index 0277b7899..696f3ce66 100755
--- a/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces
+++ b/package/gluon-status-page-api/luasrc/lib/gluon/status-page/www/cgi-bin/interfaces
@@ -1,27 +1,24 @@
 #!/usr/bin/lua
-
 util = require 'gluon.util'
-
 fs = require 'nixio.fs'
 json = require 'luci.jsonc'
+ubus = require 'ubus'
 
 io.write("Access-Control-Allow-Origin: *\n")
 io.write("Content-type: application/json\n\n")
 
-f = io.popen('batctl if')
-
+local uconn = ubus.connect()
+if not uconn then
+	error("Failed to connect to ubusd")
+end
+list = util.get_mesh_devices(uconn)
+ubus.close(uconn)
 interfaces = {}
-
-for line in f:lines() do
-  ifname = line:match('^(.-):')
-  if ifname ~= nil then
+for _,ifname in ipairs(list) do
     pcall(function()
       local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
       interfaces[ifname] = { address = address }
     end)
-  end
 end
 
-f:close()
-
 io.write(json.stringify(interfaces))
-- 
GitLab