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"), 40)
21 entry({"admin", "uci", "revert"}, call("action_revert"), i18n("revert"), 30)
22 entry({"admin", "uci", "apply"}, call("action_apply"), i18n("apply"), 20)
23 entry({"admin", "uci", "saveapply"}, call("action_apply"), i18n("saveapply"), 10)
26 function convert_changes(changes)
28 for r, tbl in pairs(changes) do
29 for s, os in pairs(tbl) do
30 for o, v in pairs(os) do
43 table.insert(ret, str..val)
47 return table.concat(ret, "\n")
50 function action_changes()
51 local changes = convert_changes(luci.model.uci.changes())
52 luci.template.render("admin_uci/changes", {changes=changes})
55 function action_apply()
56 local path = luci.dispatcher.context.path
57 local changes = luci.model.uci.changes()
64 -- Collect files to be applied and commit changes
65 for r, tbl in pairs(changes) do
67 if path[#path] ~= "apply" then
68 luci.model.uci.load(r)
69 luci.model.uci.commit(r)
70 luci.model.uci.unload(r)
72 if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
73 run[luci.config.uci_oncommit[r]] = true
78 -- Search for post-commit commands
79 for cmd, i in pairs(run) do
80 output = output .. cmd .. ":" .. luci.util.exec(cmd) .. "\n"
85 luci.template.render("admin_uci/apply", {changes=convert_changes(changes), output=output})
89 function action_revert()
90 local changes = luci.model.uci.changes()
94 -- Collect files to be reverted
95 for r, tbl in pairs(changes) do
96 luci.model.uci.load(r)
97 luci.model.uci.revert(r)
98 luci.model.uci.unload(r)
102 luci.template.render("admin_uci/revert", {changes=convert_changes(changes)})