* Core translation
[project/luci.git] / modules / admin-core / luasrc / controller / admin / uci.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 module("luci.controller.admin.uci", package.seeall)
15
16 function index()
17 node("admin", "uci", "changes").target = call("action_changes")
18 node("admin", "uci", "revert").target = call("action_revert")
19 node("admin", "uci", "apply").target = call("action_apply")
20 end
21
22 function convert_changes(changes)
23 local ret = {}
24 for r, tbl in pairs(changes) do
25 for s, os in pairs(tbl) do
26 for o, v in pairs(os) do
27 local val, str
28 if (v == "") then
29 str = "-"
30 val = ""
31 else
32 str = ""
33 val = "="..v
34 end
35 str = r.."."..s
36 if o ~= ".type" then
37 str = str.."."..o
38 end
39 table.insert(ret, str..val)
40 end
41 end
42 end
43 return table.concat(ret, "\n")
44 end
45
46 function action_changes()
47 local changes = convert_changes(luci.model.uci.changes())
48 luci.template.render("admin_uci/changes", {changes=changes})
49 end
50
51 function action_apply()
52 local changes = luci.model.uci.changes()
53 local output = ""
54
55 if changes then
56 local com = {}
57 local run = {}
58
59 -- Collect files to be applied and commit changes
60 for r, tbl in pairs(changes) do
61 if r then
62 luci.model.uci.load(r)
63 luci.model.uci.commit(r)
64 luci.model.uci.unload(r)
65 if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
66 run[luci.config.uci_oncommit[r]] = true
67 end
68 end
69 end
70
71 -- Search for post-commit commands
72 for cmd, i in pairs(run) do
73 output = output .. cmd .. ":" .. luci.sys.exec(cmd) .. "\n"
74 end
75 end
76
77
78 luci.template.render("admin_uci/apply", {changes=convert_changes(changes), output=output})
79 end
80
81
82 function action_revert()
83 local changes = luci.model.uci.changes()
84 if changes then
85 local revert = {}
86
87 -- Collect files to be reverted
88 for r, tbl in pairs(changes) do
89 luci.model.uci.load(r)
90 luci.model.uci.revert(r)
91 luci.model.uci.unload(r)
92 end
93 end
94
95 luci.template.render("admin_uci/revert", {changes=convert_changes(changes)})
96 end