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, 16 Apr 2020 11:30:35 +0000 (13:30 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
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 2490823a16f5fc57fd3174afdd4c84abe9e702d4..daad2f633af6d373f430aef5074a37e2170d18ef 100644 (file)
                        "function": "action_confirm"
                },
                "auth": {}
+       },
+
+       "admin/menu": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.index",
+                       "function": "action_menu"
+               },
+               "auth": {}
        }
 }