5edcc973ee14472e6d845c2b1fd3dc956770172e
[project/luci.git] / modules / admin-full / luasrc / controller / admin / uci.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6
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
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 module("luci.controller.admin.uci", package.seeall)
17
18 function index()
19 local i18n = luci.i18n.translate
20 local redir = luci.http.formvalue("redir", true) or
21 luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
22
23 entry({"admin", "uci"}, nil, i18n("Configuration"))
24 entry({"admin", "uci", "changes"}, call("action_changes"), i18n("Changes"), 40).query = {redir=redir}
25 entry({"admin", "uci", "revert"}, call("action_revert"), i18n("Revert"), 30).query = {redir=redir}
26 entry({"admin", "uci", "apply"}, call("action_apply"), i18n("Apply"), 20).query = {redir=redir}
27 entry({"admin", "uci", "saveapply"}, call("action_apply"), i18n("Save &#38; Apply"), 10).query = {redir=redir}
28 end
29
30 function action_changes()
31 local uci = luci.model.uci.cursor()
32 local changes = uci:changes()
33
34 luci.template.render("admin_uci/changes", {
35 changes = next(changes) and changes
36 })
37 end
38
39 function action_apply()
40 local path = luci.dispatcher.context.path
41 local uci = luci.model.uci.cursor()
42 local changes = uci:changes()
43 local reload = {}
44
45 -- Collect files to be applied and commit changes
46 for r, tbl in pairs(changes) do
47 table.insert(reload, r)
48 if path[#path] ~= "apply" then
49 uci:load(r)
50 uci:commit(r)
51 uci:unload(r)
52 end
53 end
54
55 luci.template.render("admin_uci/apply", {
56 changes = next(changes) and changes,
57 configs = reload
58 })
59 end
60
61
62 function action_revert()
63 local uci = luci.model.uci.cursor()
64 local changes = uci:changes()
65
66 -- Collect files to be reverted
67 for r, tbl in pairs(changes) do
68 uci:load(r)
69 uci:revert(r)
70 uci:unload(r)
71 end
72
73 luci.template.render("admin_uci/revert", {
74 changes = next(changes) and changes
75 })
76 end