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