From d9afb1159ec3c87d58c6ee3f62e6df458deadffc Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 22 Nov 2013 18:05:51 +0100 Subject: [PATCH] API:config/resetall --- src/rest/api/api_config.lua | 9 +++++++++ src/util/settings.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 137f491..5a230a8 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -88,6 +88,15 @@ function M.all_GET(request, response) end end +function M.resetall_POST(request, response) + response:setSuccess() + settings.resetAll() + + for k,v in pairs(settings.getAll()) do + response:addData(k,v) + end +end + function M.supportedprinters_GET(request, response) response:setSuccess() for k,v in pairs(printer.supportedPrinters()) do diff --git a/src/util/settings.lua b/src/util/settings.lua index f7be765..38fdcd0 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -239,6 +239,32 @@ function M.set(key, value) return true end +--- Reset all settings to their default values +-- @string key The key to set. +-- @treturn bool|nil True if everything went well, nil in case of error. +function M.resetAll() + log:info("settings:resetAll") + for k,_ in pairs(baseconfig) do + if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway + M.reset(k) + end + end + return true +end + +--- Reset setting to default value +-- @string key The key to reset. +-- @treturn bool|nil True if everything went well, nil in case of error. +function M.reset(key) + log:info("settings:reset") + + --log:info(" key: "..utils.dump(key)) + uci:delete(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key) + uci:commit(UCI_CONFIG_NAME) + return true +end + + --- Returns a UCI configuration key from the system section. -- @string key The key for which to return the value, must be non-empty. -- @return Requested value or false if it does not exist or nil on invalid key.