2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.admin.uci", package.seeall)
17 local i18n = luci.i18n.translate
19 entry({"admin", "uci"}, nil, i18n("config"))
20 entry({"admin", "uci", "changes"}, call("action_changes"), i18n("changes"))
21 entry({"admin", "uci", "revert"}, call("action_revert"), i18n("revert"))
22 entry({"admin", "uci", "apply"}, call("action_apply"), i18n("apply"))
25 function convert_changes(changes)
27 for r, tbl in pairs(changes) do
28 for s, os in pairs(tbl) do
29 for o, v in pairs(os) do
42 table.insert(ret, str..val)
46 return table.concat(ret, "\n")
49 function action_changes()
50 local changes = convert_changes(luci.model.uci.changes())
51 luci.template.render("admin_uci/changes", {changes=changes})
54 function action_apply()
55 local changes = luci.model.uci.changes()
62 -- Collect files to be applied and commit changes
63 for r, tbl in pairs(changes) do
65 luci.model.uci.load(r)
66 luci.model.uci.commit(r)
67 luci.model.uci.unload(r)
68 if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
69 run[luci.config.uci_oncommit[r]] = true
74 -- Search for post-commit commands
75 for cmd, i in pairs(run) do
76 output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
81 luci.template.render("admin_uci/apply", {changes=convert_changes(changes), output=output})
85 function action_revert()
86 local changes = luci.model.uci.changes()
90 -- Collect files to be reverted
91 for r, tbl in pairs(changes) do
92 luci.model.uci.load(r)
93 luci.model.uci.revert(r)
94 luci.model.uci.unload(r)
98 luci.template.render("admin_uci/revert", {changes=convert_changes(changes)})