1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2019 Jo-Philipp Wich <jo@mein.io>
3 -- Licensed to the public under the Apache License 2.0.
5 module("luci.controller.admin.uci", package.seeall)
7 local function ubus_state_to_http(errstr)
9 ["Invalid command"] = 400,
10 ["Invalid argument"] = 400,
11 ["Method not found"] = 404,
12 ["Entry not found"] = 404,
14 ["Permission denied"] = 403,
16 ["Not supported"] = 500,
17 ["Unknown error"] = 500,
18 ["Connection failed"] = 503
21 local code = map[errstr] or 200
22 local msg = errstr or "OK"
24 luci.http.status(code, msg)
27 luci.http.prepare_content("text/plain")
32 function action_apply_rollback()
33 local uci = require "luci.model.uci"
34 local token, errstr = uci:apply(true)
36 luci.http.prepare_content("application/json")
37 luci.http.write_json({ token = token })
39 ubus_state_to_http(errstr)
43 function action_apply_unchecked()
44 local uci = require "luci.model.uci"
45 local _, errstr = uci:apply(false)
46 ubus_state_to_http(errstr)
49 function action_confirm()
50 local uci = require "luci.model.uci"
51 local token = luci.http.formvalue("token")
52 local _, errstr = uci:confirm(token)
53 ubus_state_to_http(errstr)
56 function action_revert()
57 local uci = require "luci.model.uci"
58 local changes = uci:changes()
60 -- Collect files to be reverted
61 local _, errstr, r, tbl
62 for r, tbl in pairs(changes) do
63 _, errstr = uci:revert(r)
69 ubus_state_to_http(errstr or "OK")