2008-05-25 17:00:30 +00:00
|
|
|
module("luci.controller.admin.uci", package.seeall)
|
|
|
|
require("luci.util")
|
|
|
|
require("luci.sys")
|
2008-04-11 18:24:25 +00:00
|
|
|
|
2008-05-22 14:04:03 +00:00
|
|
|
function index()
|
|
|
|
node("admin", "uci", "changes").target = template("admin_uci/changes")
|
2008-05-27 20:39:48 +00:00
|
|
|
node("admin", "uci", "revert").target = call("action_revert")
|
|
|
|
node("admin", "uci", "apply").target = call("action_apply")
|
2008-05-22 14:04:03 +00:00
|
|
|
end
|
|
|
|
|
2008-04-11 18:24:25 +00:00
|
|
|
-- This function has a higher priority than the admin_uci/apply template
|
|
|
|
function action_apply()
|
2008-05-25 17:00:30 +00:00
|
|
|
local changes = luci.model.uci.changes()
|
2008-04-11 18:24:25 +00:00
|
|
|
local output = ""
|
|
|
|
|
|
|
|
if changes then
|
2008-05-06 16:31:16 +00:00
|
|
|
local com = {}
|
|
|
|
local run = {}
|
2008-04-11 18:24:25 +00:00
|
|
|
|
2008-05-06 14:28:51 +00:00
|
|
|
-- Collect files to be applied and commit changes
|
2008-05-25 17:00:30 +00:00
|
|
|
for i, line in ipairs(luci.util.split(changes)) do
|
2008-04-11 18:24:25 +00:00
|
|
|
local r = line:match("^-?([^.]+)")
|
2008-05-06 16:31:16 +00:00
|
|
|
if r then
|
|
|
|
com[r] = true
|
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
|
|
|
|
run[luci.config.uci_oncommit[r]] = true
|
2008-05-06 16:31:16 +00:00
|
|
|
end
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-06 16:31:16 +00:00
|
|
|
-- Apply
|
|
|
|
for config, i in pairs(com) do
|
2008-05-25 17:00:30 +00:00
|
|
|
luci.model.uci.commit(config)
|
2008-05-06 16:31:16 +00:00
|
|
|
end
|
2008-04-11 18:24:25 +00:00
|
|
|
|
|
|
|
-- Search for post-commit commands
|
2008-05-06 16:31:16 +00:00
|
|
|
for cmd, i in pairs(run) do
|
2008-05-25 17:00:30 +00:00
|
|
|
output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
luci.template.render("admin_uci/apply", {changes=changes, output=output})
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function action_revert()
|
2008-05-25 17:00:30 +00:00
|
|
|
local changes = luci.model.uci.changes()
|
2008-04-11 18:24:25 +00:00
|
|
|
if changes then
|
|
|
|
local revert = {}
|
|
|
|
|
|
|
|
-- Collect files to be reverted
|
2008-05-25 17:00:30 +00:00
|
|
|
for i, line in ipairs(luci.util.split(changes)) do
|
2008-04-11 18:24:25 +00:00
|
|
|
local r = line:match("^-?([^.]+)")
|
|
|
|
if r then
|
|
|
|
revert[r] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Revert them
|
|
|
|
for k, v in pairs(revert) do
|
2008-05-25 17:00:30 +00:00
|
|
|
luci.model.uci.revert(k)
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-25 17:00:30 +00:00
|
|
|
luci.template.render("admin_uci/revert", {changes=changes})
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|