luci-base: convert menu nodes to JSON
authorJo-Philipp Wich <jo@mein.io>
Fri, 6 Dec 2019 20:51:32 +0000 (21:51 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 16 Dec 2019 17:07:17 +0000 (18:07 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/luasrc/controller/admin/index.lua
modules/luci-base/luasrc/controller/admin/uci.lua
modules/luci-base/root/usr/share/luci/menu.d/luci-base.json [new file with mode: 0644]

index 0cebfa4f57130dca52f57da05e7d8596f906b66c..68bbd38a71428ea5b02b423f6ff014d87c3a524f 100644 (file)
@@ -3,85 +3,6 @@
 
 module("luci.controller.admin.index", package.seeall)
 
-function index()
-       function toplevel_page(page, preflookup, preftarget)
-               if preflookup and preftarget then
-                       if lookup(preflookup) then
-                               page.target = preftarget
-                       end
-               end
-
-               if not page.target then
-                       page.target = firstchild()
-               end
-       end
-
-       local uci = require("luci.model.uci").cursor()
-
-       local root = node()
-       if not root.target then
-               root.target = alias("admin")
-               root.index = true
-       end
-
-       local page   = node("admin")
-
-       page.title   = _("Administration")
-       page.order   = 10
-       page.sysauth = "root"
-       page.sysauth_authenticator = "htmlauth"
-       page.ucidata = true
-       page.index = true
-       page.target = firstnode()
-
-       -- Empty menu tree to be populated by addons and modules
-
-       page = node("admin", "status")
-       page.title = _("Status")
-       page.order = 10
-       page.index = true
-       -- overview is from mod-admin-full
-       toplevel_page(page, "admin/status/overview", alias("admin", "status", "overview"))
-
-       page = node("admin", "system")
-       page.title = _("System")
-       page.order = 20
-       page.index = true
-       -- system/system is from mod-admin-full
-       toplevel_page(page, "admin/system/system", alias("admin", "system", "system"))
-
-       -- Only used if applications add items
-       page = node("admin", "vpn")
-       page.title = _("VPN")
-       page.order = 30
-       page.index = true
-       toplevel_page(page, false, false)
-
-       -- Only used if applications add items
-       page = node("admin", "services")
-       page.title = _("Services")
-       page.order = 40
-       page.index = true
-       toplevel_page(page, false, false)
-
-       -- Even for mod-admin-full network just uses first submenu item as landing
-       page = node("admin", "network")
-       page.title = _("Network")
-       page.order = 50
-       page.index = true
-       toplevel_page(page, false, false)
-
-       page = entry({"admin", "translations"}, call("action_translations"), nil)
-       page.leaf = true
-
-       page = entry({"admin", "ubus"}, call("action_ubus"), nil)
-       page.sysauth = false
-       page.leaf = true
-
-       -- Logout is last
-       entry({"admin", "logout"}, call("action_logout"), _("Logout"), 999)
-end
-
 function action_logout()
        local dsp = require "luci.dispatcher"
        local utl = require "luci.util"
index 6b19c62f81c96f96da9506343a2a0f4acb06bfbc..7aad10d58a280370b6b0066f64a58da1b62addf2 100644 (file)
@@ -4,32 +4,6 @@
 
 module("luci.controller.admin.uci", package.seeall)
 
-function index()
-       local redir = luci.http.formvalue("redir", true)
-               or table.concat(luci.dispatcher.context.request, "/")
-
-       entry({"admin", "uci"}, nil, _("Configuration"))
-       entry({"admin", "uci", "revert"}, post("action_revert"), nil)
-
-       local node
-       local authen = function(checkpass, allowed_users)
-               return "root", luci.http.formvalue("sid")
-       end
-
-       node = entry({"admin", "uci", "apply_rollback"}, post("action_apply_rollback"), nil)
-       node.cors = true
-       node.sysauth_authenticator = authen
-
-       node = entry({"admin", "uci", "apply_unchecked"}, post("action_apply_unchecked"), nil)
-       node.cors = true
-       node.sysauth_authenticator = authen
-
-       node = entry({"admin", "uci", "confirm"}, call("action_confirm"), nil)
-       node.cors = true
-       node.sysauth = false
-end
-
-
 local function ubus_state_to_http(errstr)
        local map = {
                ["Invalid command"]   = 400,
diff --git a/modules/luci-base/root/usr/share/luci/menu.d/luci-base.json b/modules/luci-base/root/usr/share/luci/menu.d/luci-base.json
new file mode 100644 (file)
index 0000000..cdfffb5
--- /dev/null
@@ -0,0 +1,142 @@
+{
+       "admin": {
+               "title": "Administration",
+               "order": 10,
+               "action": {
+                       "type": "firstchild",
+                       "recurse": true
+               },
+               "auth": {
+                       "methods": [ "cookie:sysauth" ],
+                       "login": true
+               }
+       },
+
+       "admin/status": {
+               "title": "Status",
+               "order": 10,
+               "action": {
+                       "type": "firstchild",
+                       "preferred": "overview",
+                       "recurse": true
+               }
+       },
+
+       "admin/system": {
+               "title": "System",
+               "order": 20,
+               "action": {
+                       "type": "firstchild",
+                       "preferred": "system",
+                       "recurse": true
+               }
+       },
+
+       "admin/vpn": {
+               "title": "VPN",
+               "order": 30,
+               "action": {
+                       "type": "firstchild",
+                       "recurse": true
+               }
+       },
+
+       "admin/services": {
+               "title": "Services",
+               "order": 40,
+               "action": {
+                       "type": "firstchild",
+                       "recurse": true
+               }
+       },
+
+       "admin/network": {
+               "title": "Network",
+               "order": 50,
+               "action": {
+                       "type": "firstchild",
+                       "recurse": true
+               }
+       },
+
+       "admin/translations/*": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.index",
+                       "function": "action_translations"
+               },
+               "auth": {
+                       "methods": [ "cookie:sysauth" ]
+               }
+       },
+
+       "admin/ubus/*": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.index",
+                       "function": "action_ubus"
+               },
+               "auth": {}
+       },
+
+       "admin/logout": {
+               "title": "Logout",
+               "order": 999,
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.index",
+                       "function": "action_logout"
+               }
+       },
+
+       "admin/uci": {
+               "action": {
+                       "type": "firstchild"
+               }
+       },
+
+       "admin/uci/revert": {
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.uci",
+                       "function": "action_revert",
+                       "post": true
+               }
+       },
+
+       "admin/uci/apply_rollback": {
+               "cors": true,
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.uci",
+                       "function": "action_apply_rollback",
+                       "post": true
+               },
+               "auth": {
+                       "methods": [ "cookie:sysauth" ]
+               }
+       },
+
+       "admin/uci/apply_unchecked": {
+               "cors": true,
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.uci",
+                       "function": "action_apply_unchecked",
+                       "post": true
+               },
+               "auth": {
+                       "methods": [ "cookie:sysauth" ]
+               }
+       },
+
+       "admin/uci/confirm": {
+               "cors": true,
+               "action": {
+                       "type": "call",
+                       "module": "luci.controller.admin.uci",
+                       "function": "action_confirm"
+               },
+               "auth": {}
+       }
+}