blob: 3c9fc8739523a16ae2f3ebe91bd19e0ddefcac97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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
local apply = {}
-- Collect files to be applied
for i, line in ipairs(ffluci.util.split(changes)) do
local r = line:match("^-?([^.]+)")
if r then
apply[r] = true
end
end
-- Commit changes
ffluci.model.uci.commit()
-- Search for post-commit commands
if ffluci.config.uci_oncommit then
for k, v in pairs(apply) do
local cmd = ffluci.config.uci_oncommit[k]
if cmd then
output = output .. cmd .. ":" .. ffluci.sys.exec(cmd)
end
end
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
|