* Added DHCP page
[project/luci.git] / src / ffluci / 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 then
17 apply[r] = true
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 k, v in pairs(apply) do
27 local cmd = ffluci.config.uci_oncommit[k]
28 if cmd then
29 output = output .. cmd .. ":" .. ffluci.sys.exec(cmd)
30 end
31 end
32 end
33 end
34
35 ffluci.template.render("admin_uci/apply", {changes=changes, output=output})
36 end
37
38
39 function action_revert()
40 local changes = ffluci.model.uci.changes()
41 if changes then
42 local revert = {}
43
44 -- Collect files to be reverted
45 for i, line in ipairs(ffluci.util.split(changes)) do
46 local r = line:match("^-?([^.]+)")
47 if r then
48 revert[r] = true
49 end
50 end
51
52 -- Revert them
53 for k, v in pairs(revert) do
54 ffluci.model.uci.revert(k)
55 end
56 end
57
58 ffluci.template.render("admin_uci/revert", {changes=changes})
59 end