* Minor bugfixes
[project/luci.git] / module / admin-core / src / controller / admin / uci.lua
1 module("ffluci.controller.admin.uci", package.seeall)
2 require("ffluci.util")
3 require("ffluci.sys")
4
5 -- This function has a higher priority than the admin_uci/apply template
6 function action_apply()
7 local changes = ffluci.model.uci.changes()
8 local output = ""
9
10 if changes then
11 local apply = {}
12
13 -- Collect files to be applied
14 for i, line in ipairs(ffluci.util.split(changes)) do
15 local r = line:match("^-?([^.]+)")
16 if r and not ffluci.util.contains(apply, ffluci.config.uci_oncommit[r]) then
17 table.insert(apply, ffluci.config.uci_oncommit[r])
18 end
19 end
20
21 -- Commit changes
22 ffluci.model.uci.commit()
23
24 -- Search for post-commit commands
25 if ffluci.config.uci_oncommit then
26 for i, cmd in ipairs(apply) do
27 if cmd then
28 output = output .. cmd .. ":" .. ffluci.sys.exec(cmd) .. "\n"
29 end
30 end
31 end
32 end
33
34 ffluci.template.render("admin_uci/apply", {changes=changes, output=output})
35 end
36
37
38 function action_revert()
39 local changes = ffluci.model.uci.changes()
40 if changes then
41 local revert = {}
42
43 -- Collect files to be reverted
44 for i, line in ipairs(ffluci.util.split(changes)) do
45 local r = line:match("^-?([^.]+)")
46 if r then
47 revert[r] = true
48 end
49 end
50
51 -- Revert them
52 for k, v in pairs(revert) do
53 ffluci.model.uci.revert(k)
54 end
55 end
56
57 ffluci.template.render("admin_uci/revert", {changes=changes})
58 end