luci-base: implement JSON endpoint to fetch menu information
authorJo-Philipp Wich <jo@mein.io>
Wed, 15 Apr 2020 20:25:48 +0000 (22:25 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:50 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
[require authentication for 19.07]
(backported from commit e56e442d6af125522214a9bc9ab957ac39c5c0c8)

modules/luci-base/luasrc/controller/admin/index.lua
modules/luci-base/root/usr/share/luci/menu.d/luci-base.json

index 68bbd38a71428ea5b02b423f6ff014d87c3a524f..736d0cdccff3cc1362875b8fa01fe8023c05a55e 100644 (file)
@@ -182,3 +182,15 @@ function action_ubus()
        luci.http.prepare_content("application/json")
        luci.http.write_json(response)
 end
+
+function action_menu()
+       local dsp = require "luci.dispatcher"
+       local utl = require "luci.util"
+       local http = require "luci.http"
+
+       local acls = utl.ubus("session", "access", { ubus_rpc_session = http.getcookie("sysauth") })
+       local menu = dsp.menu_json(acls or {}) or {}
+
+       http.prepare_content("application/json")
+       http.write_json(menu)
+end
index cdfffb5123f0ef2f6463a822aa1c13e6b44015bc..3b9e2fd9902176ec1d30c8a4712101c2d86534d2 100644 (file)
                        "function": "action_confirm"
                },
                "auth": {}
+       },
+
+       "admin/menu": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.index",
+                       "function": "action_menu"
+               },
+               "auth": {
+                       "methods": [ "cookie:sysauth" ]
+               }
        }
 }