2015-01-16 22:38:38 +00:00
|
|
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
2015-10-06 20:29:07 +00:00
|
|
|
-- Copyright 2010-2015 Jo-Philipp Wich <jow@openwrt.org>
|
2015-01-16 22:38:38 +00:00
|
|
|
-- Licensed to the public under the Apache License 2.0.
|
2010-10-15 21:53:28 +00:00
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
module("luci.controller.admin.uci", package.seeall)
|
2008-04-11 18:24:25 +00:00
|
|
|
|
2008-05-22 14:04:03 +00:00
|
|
|
function index()
|
2018-04-05 20:37:37 +00:00
|
|
|
local redir = luci.http.formvalue("redir", true) or table.concat(disp.context.request, "/")
|
2010-10-15 21:53:28 +00:00
|
|
|
|
2011-08-12 13:16:27 +00:00
|
|
|
entry({"admin", "uci"}, nil, _("Configuration"))
|
|
|
|
entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir}
|
2015-10-06 20:29:07 +00:00
|
|
|
entry({"admin", "uci", "revert"}, post("action_revert"), _("Revert"), 30).query = {redir=redir}
|
|
|
|
entry({"admin", "uci", "apply"}, post("action_apply"), _("Apply"), 20).query = {redir=redir}
|
|
|
|
entry({"admin", "uci", "saveapply"}, post("action_apply"), _("Save & Apply"), 10).query = {redir=redir}
|
2008-05-22 14:04:03 +00:00
|
|
|
end
|
|
|
|
|
2008-06-05 19:16:38 +00:00
|
|
|
function action_changes()
|
2010-10-15 21:53:28 +00:00
|
|
|
local uci = luci.model.uci.cursor()
|
|
|
|
local changes = uci:changes()
|
|
|
|
|
|
|
|
luci.template.render("admin_uci/changes", {
|
|
|
|
changes = next(changes) and changes
|
|
|
|
})
|
2008-06-03 22:42:01 +00:00
|
|
|
end
|
|
|
|
|
2008-04-11 18:24:25 +00:00
|
|
|
function action_apply()
|
2008-07-29 15:33:28 +00:00
|
|
|
local path = luci.dispatcher.context.path
|
2008-08-26 23:00:44 +00:00
|
|
|
local uci = luci.model.uci.cursor()
|
2008-08-27 13:52:25 +00:00
|
|
|
local changes = uci:changes()
|
2008-09-06 13:51:51 +00:00
|
|
|
local reload = {}
|
|
|
|
|
|
|
|
-- Collect files to be applied and commit changes
|
|
|
|
for r, tbl in pairs(changes) do
|
|
|
|
table.insert(reload, r)
|
|
|
|
if path[#path] ~= "apply" then
|
|
|
|
uci:load(r)
|
|
|
|
uci:commit(r)
|
|
|
|
uci:unload(r)
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
2010-10-15 21:53:28 +00:00
|
|
|
|
|
|
|
luci.template.render("admin_uci/apply", {
|
|
|
|
changes = next(changes) and changes,
|
|
|
|
configs = reload
|
|
|
|
})
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function action_revert()
|
2008-08-26 23:00:44 +00:00
|
|
|
local uci = luci.model.uci.cursor()
|
|
|
|
local changes = uci:changes()
|
2008-09-06 13:51:51 +00:00
|
|
|
|
|
|
|
-- Collect files to be reverted
|
|
|
|
for r, tbl in pairs(changes) do
|
|
|
|
uci:load(r)
|
|
|
|
uci:revert(r)
|
|
|
|
uci:unload(r)
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
2010-10-15 21:53:28 +00:00
|
|
|
|
|
|
|
luci.template.render("admin_uci/revert", {
|
|
|
|
changes = next(changes) and changes
|
|
|
|
})
|
2008-06-03 22:42:01 +00:00
|
|
|
end
|