From 16853bcd2e4224c281731adbfa490d704784ec20 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 6 Dec 2019 21:51:32 +0100 Subject: [PATCH] luci-base: convert menu nodes to JSON Signed-off-by: Jo-Philipp Wich --- .../luasrc/controller/admin/index.lua | 79 ---------- .../luci-base/luasrc/controller/admin/uci.lua | 26 ---- .../root/usr/share/luci/menu.d/luci-base.json | 142 ++++++++++++++++++ 3 files changed, 142 insertions(+), 105 deletions(-) create mode 100644 modules/luci-base/root/usr/share/luci/menu.d/luci-base.json diff --git a/modules/luci-base/luasrc/controller/admin/index.lua b/modules/luci-base/luasrc/controller/admin/index.lua index 0cebfa4f57..68bbd38a71 100644 --- a/modules/luci-base/luasrc/controller/admin/index.lua +++ b/modules/luci-base/luasrc/controller/admin/index.lua @@ -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" diff --git a/modules/luci-base/luasrc/controller/admin/uci.lua b/modules/luci-base/luasrc/controller/admin/uci.lua index 6b19c62f81..7aad10d58a 100644 --- a/modules/luci-base/luasrc/controller/admin/uci.lua +++ b/modules/luci-base/luasrc/controller/admin/uci.lua @@ -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 index 0000000000..cdfffb5123 --- /dev/null +++ b/modules/luci-base/root/usr/share/luci/menu.d/luci-base.json @@ -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": {} + } +} -- 2.30.2