2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 module("luci.controller.mini.uci", package.seeall)
18 local i18n = luci.i18n.translate
20 entry({"mini", "uci"}, nil, i18n("config"))
21 entry({"mini", "uci", "changes"}, call("action_changes"), i18n("changes"), 30)
22 entry({"mini", "uci", "revert"}, call("action_revert"), i18n("revert"), 20)
23 entry({"mini", "uci", "apply"}, 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
37 val = "="..luci.util.pcdata(v)
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("mini/uci_changes", {changes=changes})
55 function action_apply()
56 local changes = luci.model.uci.changes()
63 -- Collect files to be applied and commit changes
64 for r, tbl in pairs(changes) do
66 luci.model.uci.load_config(r)
67 luci.model.uci.commit(r)
68 luci.model.uci.unload(r)
69 if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
70 run[luci.config.uci_oncommit[r]] = true
75 -- Search for post-commit commands
76 for cmd, i in pairs(run) do
77 output = output .. cmd .. ":" .. luci.util.exec(cmd) .. "\n"
82 luci.template.render("mini/uci_apply", {changes=convert_changes(changes), output=output})
86 function action_revert()
87 local changes = luci.model.uci.changes()
91 -- Collect files to be reverted
92 for r, tbl in pairs(changes) do
93 luci.model.uci.load_config(r)
94 luci.model.uci.revert(r)
95 luci.model.uci.unload(r)
99 luci.template.render("mini/uci_revert", {changes=convert_changes(changes)})