1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2015 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 module("luci.controller.admin.uci", package.seeall)
8 local redir = luci.http.formvalue("redir", true)
9 or table.concat(luci.dispatcher.context.request, "/")
11 entry({"admin", "uci"}, nil, _("Configuration"))
12 entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir}
13 entry({"admin", "uci", "revert"}, post("action_revert"), _("Revert"), 30).query = {redir=redir}
16 local authen = function(checkpass, allowed_users)
17 return "root", luci.http.formvalue("sid")
20 node = entry({"admin", "uci", "apply_rollback"}, post("action_apply_rollback"), nil)
22 node.sysauth_authenticator = authen
24 node = entry({"admin", "uci", "apply_unchecked"}, post("action_apply_unchecked"), nil)
26 node.sysauth_authenticator = authen
28 node = entry({"admin", "uci", "confirm"}, post("action_confirm"), nil)
30 node.sysauth_authenticator = authen
34 function action_changes()
35 local uci = require "luci.model.uci"
36 local changes = uci:changes()
38 luci.template.render("admin_uci/changes", {
39 changes = next(changes) and changes,
44 function action_revert()
45 local uci = require "luci.model.uci"
46 local changes = uci:changes()
48 -- Collect files to be reverted
50 for r, tbl in pairs(changes) do
54 luci.template.render("admin_uci/revert", {
55 changes = next(changes) and changes
60 local function ubus_state_to_http(errstr)
62 ["Invalid command"] = 400,
63 ["Invalid argument"] = 400,
64 ["Method not found"] = 404,
65 ["Entry not found"] = 404,
67 ["Permission denied"] = 403,
69 ["Not supported"] = 500,
70 ["Unknown error"] = 500,
71 ["Connection failed"] = 503
74 local code = map[errstr] or 200
75 local msg = errstr or "OK"
77 luci.http.status(code, msg)
80 luci.http.prepare_content("text/plain")
85 function action_apply_rollback()
86 local uci = require "luci.model.uci"
87 local _, errstr = uci:apply(true)
88 ubus_state_to_http(errstr)
91 function action_apply_unchecked()
92 local uci = require "luci.model.uci"
93 local _, errstr = uci:apply(false)
94 ubus_state_to_http(errstr)
97 function action_confirm()
98 local uci = require "luci.model.uci"
99 local _, errstr = uci:confirm()
100 ubus_state_to_http(errstr)