2008-04-11 18:24:25 +00:00
|
|
|
module("ffluci.controller.admin.uci", package.seeall)
|
|
|
|
require("ffluci.util")
|
|
|
|
require("ffluci.sys")
|
|
|
|
|
|
|
|
-- This function has a higher priority than the admin_uci/apply template
|
|
|
|
function action_apply()
|
|
|
|
local changes = ffluci.model.uci.changes()
|
|
|
|
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-04-11 18:24:25 +00:00
|
|
|
for i, line in ipairs(ffluci.util.split(changes)) do
|
|
|
|
local r = line:match("^-?([^.]+)")
|
2008-05-06 16:31:16 +00:00
|
|
|
if r then
|
|
|
|
com[r] = true
|
|
|
|
|
|
|
|
if ffluci.config.uci_oncommit and ffluci.config.uci_oncommit[r] then
|
|
|
|
run[ffluci.config.uci_oncommit[r]] = true
|
|
|
|
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
|
|
|
|
ffluci.model.uci.commit(config)
|
|
|
|
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
|
|
|
|
output = output .. cmd .. ":" .. ffluci.sys.exec(cmd) .. "\n"
|
2008-04-11 18:24:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ffluci.template.render("admin_uci/apply", {changes=changes, output=output})
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function action_revert()
|
|
|
|
local changes = ffluci.model.uci.changes()
|
|
|
|
if changes then
|
|
|
|
local revert = {}
|
|
|
|
|
|
|
|
-- Collect files to be reverted
|
|
|
|
for i, line in ipairs(ffluci.util.split(changes)) do
|
|
|
|
local r = line:match("^-?([^.]+)")
|
|
|
|
if r then
|
|
|
|
revert[r] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Revert them
|
|
|
|
for k, v in pairs(revert) do
|
|
|
|
ffluci.model.uci.revert(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ffluci.template.render("admin_uci/revert", {changes=changes})
|
|
|
|
end
|