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
19 local redir = luci.http.formvalue("redir", true) or
20 luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
22 entry({"mini", "uci"}, nil, i18n("config"))
23 entry({"mini", "uci", "changes"}, call("action_changes"), i18n("changes"), 30).query = {redir=redir}
24 entry({"mini", "uci", "revert"}, call("action_revert"), i18n("revert"), 20).query = {redir=redir}
25 entry({"mini", "uci", "saveapply"}, call("action_apply"), i18n("saveapply"), 10).query = {redir=redir}
28 function convert_changes(changes)
29 local util = require "luci.util"
32 for r, tbl in pairs(changes) do
33 for s, os in pairs(tbl) do
34 for o, v in pairs(os) do
35 ret = (ret and ret.."\n" or "") .. "%s%s.%s%s%s" % {
36 v == "" and "-" or "",
39 o ~= ".type" and "."..o or "",
40 v ~= "" and "="..util.pcdata(v) or ""
48 function action_changes()
49 local changes = convert_changes(luci.model.uci.cursor():changes())
50 luci.template.render("mini/uci_changes", {changes=changes})
53 function action_apply()
54 local path = luci.dispatcher.context.path
55 local uci = luci.model.uci.cursor()
56 local changes = uci:changes()
59 -- Collect files to be applied and commit changes
60 for r, tbl in pairs(changes) do
61 table.insert(reload, r)
67 local function _reload()
68 local cmd = uci:apply(reload, true)
72 luci.template.render("mini/uci_apply", {changes=convert_changes(changes), reload=_reload})
76 function action_revert()
77 local uci = luci.model.uci.cursor()
78 local changes = uci:changes()
80 -- Collect files to be reverted
81 for r, tbl in pairs(changes) do
87 luci.template.render("mini/uci_revert", {changes=convert_changes(changes)})