1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Update to latest LuCi changes

This commit is contained in:
Ycarus (Yannick Chabanois) 2019-07-12 18:27:38 +02:00
parent 976a467d5f
commit f139a9c784
75 changed files with 22413 additions and 14077 deletions

View file

@ -88,6 +88,9 @@ function index()
page = entry({"admin", "translations"}, call("action_translations"), nil)
page.leaf = true
page = entry({"admin", "ubus"}, call("action_ubus"), nil)
page.leaf = true
-- Logout is last
entry({"admin", "logout"}, call("action_logout"), _("Logout"), 999)
end
@ -129,6 +132,124 @@ function action_translations(lang)
http.write_json(i18n.dump())
end
local function ubus_reply(id, data, code, errmsg)
local reply = { jsonrpc = "2.0", id = id }
if errmsg then
reply.error = {
code = code,
message = errmsg
}
else
reply.result = { code, data }
end
return reply
end
local ubus_types = {
nil,
"array",
"object",
"string",
nil, -- INT64
"number",
nil, -- INT16,
"boolean",
"double"
}
local function ubus_request(req)
if type(req) ~= "table" or type(req.method) ~= "string" or type(req.params) ~= "table" or
#req.params < 2 or req.jsonrpc ~= "2.0" or req.id == nil then
return ubus_reply(nil, nil, -32600, "Invalid request")
elseif req.method == "call" then
local sid, obj, fun, arg =
req.params[1], req.params[2], req.params[3], req.params[4] or {}
if type(arg) ~= "table" or arg.ubus_rpc_session ~= nil then
return ubus_reply(req.id, nil, -32602, "Invalid parameters")
end
if sid == "00000000000000000000000000000000" then
sid = luci.dispatcher.context.authsession
end
arg.ubus_rpc_session = sid
local res, code = luci.util.ubus(obj, fun, arg)
return ubus_reply(req.id, res, code or 0)
elseif req.method == "list" then
if type(params) ~= "table" or #params == 0 then
local objs = { luci.util.ubus() }
return ubus_reply(req.id, objs, 0)
else
local n, rv = nil, {}
for n = 1, #params do
if type(params[n]) ~= "string" then
return ubus_reply(req.id, nil, -32602, "Invalid parameters")
end
local sig = luci.util.ubus(params[n])
if sig and type(sig) == "table" then
rv[params[n]] = {}
local m, p
for m, p in pairs(sig) do
if type(p) == "table" then
rv[params[n]][m] = {}
local pn, pt
for pn, pt in pairs(p) do
rv[params[n]][m][pn] = ubus_types[pt] or "unknown"
end
end
end
end
end
return ubus_reply(req.id, rv, 0)
end
end
return ubus_reply(req.id, nil, -32601, "Method not found")
end
function action_ubus()
local parser = require "luci.jsonc".new()
luci.http.context.request:setfilehandler(function(_, s)
if not s then
return nil
end
local ok, err = parser:parse(s)
return (not err or nil)
end)
luci.http.context.request:content()
local json = parser:get()
if json == nil or type(json) ~= "table" then
luci.http.prepare_content("application/json")
luci.http.write_json(ubus_reply(nil, nil, -32700, "Parse error"))
return
end
local response
if #json == 0 then
response = ubus_request(json)
else
response = {}
local _, request
for _, request in ipairs(json) do
response[_] = ubus_request(request)
end
end
luci.http.prepare_content("application/json")
luci.http.write_json(response)
end
function lease_status()
local s = require "luci.tools.status"

View file

@ -1,5 +1,5 @@
-- Copyright 2008 Steven Barth <steven@midlink.org>
-- Copyright 2010-2015 Jo-Philipp Wich <jow@openwrt.org>
-- Copyright 2010-2019 Jo-Philipp Wich <jo@mein.io>
-- Licensed to the public under the Apache License 2.0.
module("luci.controller.admin.uci", package.seeall)
@ -9,8 +9,7 @@ function index()
or table.concat(luci.dispatcher.context.request, "/")
entry({"admin", "uci"}, nil, _("Configuration"))
entry({"admin", "uci", "changes"}, post_on({ trigger_apply = true }, "action_changes"), _("Changes"), 40).query = {redir=redir}
entry({"admin", "uci", "revert"}, post("action_revert"), _("Revert"), 30).query = {redir=redir}
entry({"admin", "uci", "revert"}, post("action_revert"), nil)
local node
local authen = function(checkpass, allowed_users)
@ -31,34 +30,6 @@ function index()
end
function action_changes()
local uci = require "luci.model.uci"
local changes = uci:changes()
luci.template.render("admin_uci/changes", {
changes = next(changes) and changes,
timeout = timeout,
trigger_apply = luci.http.formvalue("trigger_apply") and true or false
})
end
function action_revert()
local uci = require "luci.model.uci"
local changes = uci:changes()
-- Collect files to be reverted
local r, tbl
for r, tbl in pairs(changes) do
uci:revert(r)
end
luci.template.render("admin_uci/revert", {
changes = next(changes) and changes,
trigger_revert = true
})
end
local function ubus_state_to_http(errstr)
local map = {
["Invalid command"] = 400,
@ -107,3 +78,19 @@ function action_confirm()
local _, errstr = uci:confirm(token)
ubus_state_to_http(errstr)
end
function action_revert()
local uci = require "luci.model.uci"
local changes = uci:changes()
-- Collect files to be reverted
local _, errstr, r, tbl
for r, tbl in pairs(changes) do
_, errstr = uci:revert(r)
if errstr then
break
end
end
ubus_state_to_http(errstr or "OK")
end