2013-12-20 16:29:46 +01:00
--
-- This file is part of the Doodle3D project (http://doodle3d.com).
--
-- @copyright 2013, Doodle3D
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
2013-11-04 22:34:09 +01:00
---
-- The settings interface reads and writes configuration keys using [UCI](http://wiki.openwrt.org/doc/uci).
-- All keys have pre-defined defaults in @{conf_defaults} which will be used
-- if no value is stored in the UCI config. The UCI config file is `/etc/config/wifibox`.
-- The default values guarantee there will always be a set of reasonable settings
-- to use and provide a clear overview of all existing configuration keys as well.
2013-11-29 13:00:09 +01:00
-- uci api: http://wiki.openwrt.org/doc/techref/uci, http://luci.subsignal.org/api/luci/modules/luci.model.uci.html
2013-07-28 05:01:58 +02:00
local uci = require ( ' uci ' ) . cursor ( )
2013-07-26 02:17:05 +02:00
local utils = require ( ' util.utils ' )
2013-07-17 17:43:33 +02:00
local baseconfig = require ( ' conf_defaults ' )
2013-10-17 14:04:13 +02:00
local utils = require ( ' util.utils ' )
local log = require ( ' util.logger ' )
2013-07-17 17:43:33 +02:00
local M = { }
2013-11-04 22:34:09 +01:00
--- UCI config name (i.e., file under `/etc/config`)
2013-07-28 05:01:58 +02:00
local UCI_CONFIG_NAME = ' wifibox '
--- Absolute path to the UCI config file
2013-07-17 17:43:33 +02:00
local UCI_CONFIG_FILE = ' /etc/config/ ' .. UCI_CONFIG_NAME
2013-07-28 05:01:58 +02:00
2013-11-04 22:34:09 +01:00
--- [Section type](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used in @{UCI_CONFIG_FILE}
2013-07-28 05:01:58 +02:00
local UCI_CONFIG_TYPE = ' settings '
2013-11-04 22:34:09 +01:00
--- [Section name](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used for 'public' settings (as predefined in conf_defaults.lua) in @{UCI_CONFIG_FILE}
2013-07-28 05:01:58 +02:00
local UCI_CONFIG_SECTION = ' general '
2013-11-04 22:34:09 +01:00
--- [Section name](http://wiki.openwrt.org/doc/techref/uci#about.uci.structure) that will be used for 'firmware-local' settings in @{UCI_CONFIG_FILE}
2013-08-22 18:34:45 +02:00
local UCI_CONFIG_SYSTEM_SECTION = ' system '
2013-07-17 17:43:33 +02:00
local ERR_NO_SUCH_KEY = " key does not exist "
2013-07-28 05:01:58 +02:00
--- Returns a key with all periods ('.') replaced by underscores ('_').
2013-11-04 22:34:09 +01:00
-- @string key The key for which to substitute dots.
2013-07-26 02:17:05 +02:00
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
local function replaceDots ( key )
if type ( key ) ~= ' string ' then return key end
2013-07-27 00:25:43 +02:00
local r = key : gsub ( ' %. ' , ' _ ' )
return r
end
2013-07-28 05:01:58 +02:00
--- Returns a key with all underscores ('_') replaced by periods ('.').
2013-11-04 22:34:09 +01:00
-- @string key The key for which to substitute underscores.
2013-07-28 05:01:58 +02:00
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
2013-07-27 00:25:43 +02:00
local function replaceUnderscores ( key )
if type ( key ) ~= ' string ' then return key end
local r = key : gsub ( ' _ ' , ' %. ' )
return r
2013-07-26 02:17:05 +02:00
end
2013-07-28 05:01:58 +02:00
--- Converts a lua value to equivalent representation for UCI.
-- Boolean values are converted to '1' and '0', everything else is converted to a string.
--
2013-11-04 22:34:09 +01:00
-- @p v The value to convert.
-- @p vType The type of the given value.
2013-07-28 05:01:58 +02:00
-- @return A value usable to write to UCI.
2013-07-26 02:17:05 +02:00
local function toUciValue ( v , vType )
if vType == ' bool ' then return v and ' 1 ' or ' 0 ' end
2013-11-04 22:34:09 +01:00
if ( vType == ' string ' ) then
v = v : gsub ( ' [ \n \r ] ' , ' \\ n ' )
2013-08-28 17:12:41 +02:00
end
2013-07-17 17:43:33 +02:00
return tostring ( v )
end
2013-07-28 05:01:58 +02:00
--- Converts a value read from UCI to a correctly typed lua value.
-- For boolean, '1' is converted to true and everything else to false. Floats
-- and ints are converted to numbers and everything else will be returned as is.
--
2013-11-04 22:34:09 +01:00
-- @p v The value to convert.
-- @p vType The type of the given value.
2013-07-28 05:01:58 +02:00
-- @return A lua value typed correctly with regard to the vType parameter.
2013-07-26 02:17:05 +02:00
local function fromUciValue ( v , vType )
if v == nil then return nil end
2013-11-04 22:34:09 +01:00
2013-07-26 02:17:05 +02:00
if vType == ' bool ' then
2013-07-17 17:43:33 +02:00
return ( v == ' 1 ' ) and true or false
2013-07-26 02:17:05 +02:00
elseif vType == ' float ' or vType == ' int ' then
2013-07-17 17:43:33 +02:00
return tonumber ( v )
2013-08-28 17:12:41 +02:00
elseif vType == ' string ' then
2013-11-04 22:34:09 +01:00
v = v : gsub ( ' \\ n ' , ' \n ' )
2013-08-28 17:12:41 +02:00
return v
2013-07-17 17:43:33 +02:00
else
return v
end
2013-11-04 22:34:09 +01:00
2013-07-17 17:43:33 +02:00
end
2013-07-28 05:01:58 +02:00
--- Reports whether a value is valid given the constraints specified in a base table.
2013-11-04 22:34:09 +01:00
-- @p value The value to test.
2016-01-05 18:25:38 +01:00
-- @tab baseTable The base table to use constraint data from (min,max,regex,isValid).
2013-07-28 05:01:58 +02:00
-- @treturn bool Returns true if the value is valid, false if it is not.
2013-07-17 17:43:33 +02:00
local function isValid ( value , baseTable )
2013-08-29 01:40:51 +02:00
local varType , min , max , regex , isValid = baseTable.type , baseTable.min , baseTable.max , baseTable.regex , baseTable.isValid
2013-11-04 22:34:09 +01:00
if isValid then
2013-10-17 15:28:57 +02:00
local ok , msg = isValid ( value )
if msg == nil then msg = " invalid value " end
return ok or nil , msg
2013-08-29 01:40:51 +02:00
end
2013-07-26 02:17:05 +02:00
if varType == ' bool ' then
return type ( value ) == ' boolean ' or nil , " invalid bool value "
2013-11-04 22:34:09 +01:00
2013-07-26 02:17:05 +02:00
elseif varType == ' int ' or varType == ' float ' then
2013-07-17 22:55:27 +02:00
local numValue = tonumber ( value )
2013-10-17 14:04:13 +02:00
if numValue == nil then
return nil , " invalid number "
elseif varType == ' int ' and math.floor ( numValue ) ~= numValue then
return nil , " invalid int "
elseif min and numValue < min then
2013-10-18 16:16:05 +02:00
return nil , " too low "
2013-10-17 14:04:13 +02:00
elseif max and numValue > max then
2013-10-18 16:16:05 +02:00
return nil , " too high "
2013-10-17 14:04:13 +02:00
end
2013-11-04 22:34:09 +01:00
2013-07-26 02:17:05 +02:00
elseif varType == ' string ' then
2013-07-17 17:43:33 +02:00
local ok = true
2013-10-17 14:04:13 +02:00
if min and value : len ( ) < min then
2013-10-18 16:16:05 +02:00
return nil , " too short "
2013-10-17 14:04:13 +02:00
elseif max and value : len ( ) > max then
2013-10-18 16:16:05 +02:00
return nil , " too long "
2013-10-17 14:04:13 +02:00
elseif regex and value : match ( regex ) == nil then
return nil , " invalid value "
2013-11-04 22:34:09 +01:00
end
2013-07-17 17:43:33 +02:00
end
2013-08-29 01:40:51 +02:00
2013-07-17 17:43:33 +02:00
return true
end
2013-11-04 22:34:09 +01:00
--- Looks up the table in @{conf_defaults}.lua corresponding to a key.
-- @string key The key for which to return the base table.
2013-07-28 05:01:58 +02:00
-- @treturn table The base table for key, or nil if it does not exist.
2013-07-17 17:43:33 +02:00
local function getBaseKeyTable ( key )
local base = baseconfig [ key ]
return type ( base ) == ' table ' and base.default ~= nil and base or nil
end
2013-11-28 17:48:00 +01:00
--- Looks up the table in @{subconf_defaults}.lua corresponding to a key.
-- @string key The key for which to return the base table.
-- @treturn table The base table for key, or nil if it does not exist.
2013-11-29 11:03:27 +01:00
--[[local function getSubBaseKeyTable(key)
2013-11-28 17:48:00 +01:00
local base = subconfig [ key ]
return type ( base ) == ' table ' and base.default ~= nil and base or nil
2013-11-29 11:03:27 +01:00
end ] ] --
2013-11-28 17:48:00 +01:00
2013-07-17 17:43:33 +02:00
2013-07-26 02:17:05 +02:00
--- Returns the value of the requested key if it exists.
2013-11-04 22:34:09 +01:00
-- @p key The key to return the associated value for.
2013-12-23 15:33:55 +01:00
-- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type, or nil if the key could not be read because of a UCI error.
-- @treturn string Message in case of error.
2013-07-17 17:43:33 +02:00
function M . get ( key )
2013-12-09 21:12:16 +01:00
--log:info("settings:get: "..utils.dump(key))
2013-07-26 02:17:05 +02:00
key = replaceDots ( key )
2015-06-09 17:12:59 +02:00
-- retrieve settings's base settings from conf_defaults.lua
2013-07-17 17:43:33 +02:00
local base = getBaseKeyTable ( key )
if not base then return nil , ERR_NO_SUCH_KEY end
2013-12-23 15:33:55 +01:00
2015-06-09 17:12:59 +02:00
-- check which uci section to read.
-- By default it will read from the general section, but if a base setting contains a subSection it will check that subSection
2013-11-28 17:48:00 +01:00
local section = UCI_CONFIG_SECTION ;
2013-12-23 15:33:55 +01:00
if base.subSection ~= nil then
2013-11-28 17:48:00 +01:00
section = M.get ( base.subSection )
end
2015-06-09 17:12:59 +02:00
-- get setting from uci
2013-12-23 14:35:03 +01:00
local uciV , msg = uci : get ( UCI_CONFIG_NAME , section , key )
if not uciV and msg ~= nil then
local errorMSG = " Issue reading setting ' " .. utils.dump ( key ) .. " ': " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2015-06-09 17:12:59 +02:00
-- convert uci value into proper lua value
2013-12-23 14:35:03 +01:00
local uciV = fromUciValue ( uciV , base.type )
2013-11-28 17:48:00 +01:00
if uciV ~= nil then
2013-12-23 15:33:55 +01:00
-- returning value from uci
2013-11-28 17:48:00 +01:00
return uciV
2013-12-23 15:33:55 +01:00
elseif base.subSection ~= nil then
2013-11-29 11:03:27 +01:00
local subDefault = base [ " default_ " .. section ]
if subDefault ~= nil then
2013-12-09 21:12:16 +01:00
-- returning subsection default value
2013-11-29 11:03:27 +01:00
return subDefault
2013-11-28 17:48:00 +01:00
end
end
2013-12-09 21:12:16 +01:00
-- returning default value
2013-11-28 17:48:00 +01:00
return base.default
2013-07-17 17:43:33 +02:00
end
2013-07-28 05:01:58 +02:00
--- Returns all configuration keys with their current values.
2013-12-23 15:33:55 +01:00
-- @return A table containing a key/value pair for each configuration key, or nil if a UCI error occured.
-- @return string Message in case of error.
2013-07-27 00:25:43 +02:00
function M . getAll ( )
local result = { }
for k , _ in pairs ( baseconfig ) do
if not k : match ( ' ^[A-Z_]*$ ' ) then --TEMP: skip 'constants', which should be moved anyway
local key = replaceUnderscores ( k )
2013-12-23 14:35:03 +01:00
local v , msg = M.get ( key )
2013-12-23 15:33:55 +01:00
if not v and msg ~= nil then
2013-12-23 14:35:03 +01:00
return nil , msg
else
result [ key ] = v
end
2013-07-27 00:25:43 +02:00
end
end
return result
end
2013-07-28 05:01:58 +02:00
--- Reports whether or not a key exists.
2013-11-04 22:34:09 +01:00
-- @string key The key to find.
2013-07-28 05:01:58 +02:00
-- @treturn bool True if the key exists, false if not.
2013-07-17 17:43:33 +02:00
function M . exists ( key )
2013-07-26 02:17:05 +02:00
key = replaceDots ( key )
2013-07-17 17:43:33 +02:00
return getBaseKeyTable ( key ) ~= nil
end
2013-07-28 05:01:58 +02:00
--- Reports whether or not a key is at its default value.
-- 'Default' in this regard means that no UCI value is defined. This means that
-- if for instance, the default is 'abc', and UCI contains a configured value of
-- 'abc' as well, that key is _not_ a default value.
--
2013-11-04 22:34:09 +01:00
-- @string key The key to report about.
2013-07-28 05:01:58 +02:00
-- @treturn bool True if the key is currently at its default value, false if not.
2013-07-17 17:43:33 +02:00
function M . isDefault ( key )
2013-07-26 02:17:05 +02:00
key = replaceDots ( key )
2013-07-17 17:43:33 +02:00
if not M.exists ( key ) then return nil , ERR_NO_SUCH_KEY end
return uci : get ( UCI_CONFIG_NAME , UCI_CONFIG_SECTION , key ) == nil
end
2013-07-28 05:01:58 +02:00
--- Sets a key to a new value or reverts it to the default value.
2013-11-04 22:34:09 +01:00
-- @string key The key to set.
-- @p[opt=nil] value The value or set, or nil to revert key to its default value.
2013-12-23 18:05:48 +01:00
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when setting multiple values
2013-12-23 14:35:03 +01:00
-- @treturn bool|nil True if everything went well, false if validation error, nil in case of error.
2013-07-28 05:01:58 +02:00
-- @treturn ?string Error message in case first return value is nil (invalid key).
2013-12-23 18:05:48 +01:00
function M . set ( key , value , noCommit )
2013-12-16 03:33:44 +01:00
log : info ( " settings:set: " .. utils.dump ( key ) .. " to: " .. utils.dump ( value ) )
2013-07-26 02:17:05 +02:00
key = replaceDots ( key )
2013-08-29 01:40:51 +02:00
2013-07-26 02:17:05 +02:00
local r = utils.create ( UCI_CONFIG_FILE )
2013-12-23 14:35:03 +01:00
local rv , msg = uci : set ( UCI_CONFIG_NAME , UCI_CONFIG_SECTION , UCI_CONFIG_TYPE )
if not rv and msg ~= nil then
local errorMSG = " Issue creating section ' " .. utils.dump ( UCI_CONFIG_SECTION ) .. " ': " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-11-04 22:34:09 +01:00
2013-07-17 17:43:33 +02:00
local base = getBaseKeyTable ( key )
2013-12-23 14:35:03 +01:00
if not base then return false , ERR_NO_SUCH_KEY end
2013-12-23 15:33:55 +01:00
2013-10-17 14:04:13 +02:00
--log:info(" base.type: "..utils.dump(base.type))
2013-07-29 13:48:56 +02:00
if base.type == ' bool ' then
if value ~= " " then
value = utils.toboolean ( value )
else
value = nil
end
elseif base.type == ' int ' or base.type == ' float ' then
value = tonumber ( value )
2013-11-04 22:34:09 +01:00
if ( value == nil ) then
2013-12-23 14:35:03 +01:00
return false , " Value isn't a valid int or float "
2013-08-29 01:40:51 +02:00
end
2013-07-29 13:48:56 +02:00
end
2013-12-23 18:05:47 +01:00
2013-10-17 14:04:13 +02:00
local valid , m = isValid ( value , base )
if not valid then
2013-12-23 14:35:03 +01:00
return false , m
2013-10-17 14:04:13 +02:00
end
2013-11-04 22:34:09 +01:00
2013-11-28 17:48:00 +01:00
local section = UCI_CONFIG_SECTION ;
2013-12-23 15:33:55 +01:00
if base.subSection ~= nil then
2013-11-28 17:48:00 +01:00
section = M.get ( base.subSection )
2013-12-23 14:35:03 +01:00
local rv , msg = uci : set ( UCI_CONFIG_NAME , section , UCI_CONFIG_TYPE )
if not rv and msg ~= nil then
2013-12-23 18:05:47 +01:00
local errorMSG = " Issue getting subsection ' " .. utils.dump ( base.subSection ) .. " ': " .. utils.dump ( msg ) ;
2013-12-23 14:35:03 +01:00
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-11-28 17:48:00 +01:00
end
2013-08-28 17:12:41 +02:00
2013-07-17 17:43:33 +02:00
if value ~= nil then
2013-12-23 14:35:03 +01:00
local rv , msg = uci : set ( UCI_CONFIG_NAME , section , key , toUciValue ( value , base.type ) )
if not rv and msg ~= nil then
local errorMSG = " Issue setting setting ' " .. utils.dump ( key ) .. " ' in section ' " .. utils.dump ( section ) .. " ': " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-07-17 17:43:33 +02:00
else
2013-12-23 14:35:03 +01:00
local rv , msg = uci : delete ( UCI_CONFIG_NAME , section , key )
if not rv and msg ~= nil then
local errorMSG = " Issue deleting setting ' " .. utils.dump ( key ) .. " ' in section ' " .. utils.dump ( section ) .. " ': " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-07-17 17:43:33 +02:00
end
2013-11-04 22:34:09 +01:00
2013-12-23 18:05:48 +01:00
if noCommit ~= true then uci : commit ( UCI_CONFIG_NAME ) end
2013-07-17 17:43:33 +02:00
return true
end
2013-12-23 18:05:48 +01:00
--- Commit the UCI configuration, this can be used after making multiple changes
-- which have not been committed yet.
function M . commit ( )
uci : commit ( UCI_CONFIG_NAME )
end
2013-12-23 15:33:55 +01:00
--- Reset all settings to their default values
2013-11-22 18:05:51 +01:00
-- @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 " )
2013-11-29 12:59:51 +01:00
2013-12-23 20:27:32 +01:00
-- find all sections
2013-12-23 14:35:03 +01:00
local allSections , msg = uci : get_all ( UCI_CONFIG_NAME )
if not allSections and msg ~= nil then
local errorMSG = " Issue reading all settings: " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-11-29 12:59:51 +01:00
2013-12-23 20:27:32 +01:00
-- delete all uci sections but system
2013-12-23 15:33:55 +01:00
for key , value in pairs ( allSections ) do
2013-11-29 12:59:51 +01:00
if key ~= " system " and not key : match ( ' ^[A-Z_]*$ ' ) then --TEMP: skip 'constants', which should be moved anyway
2013-12-23 14:35:03 +01:00
local rv , msg = uci : delete ( UCI_CONFIG_NAME , key )
if not rv and msg ~= nil then
local errorMSG = " Issue deleting setting ' " .. utils.dump ( key ) .. " ': " .. utils.dump ( msg ) ;
log : info ( errorMSG )
return nil , errorMSG ;
end
2013-12-23 15:33:55 +01:00
end
2013-11-22 18:05:51 +01:00
end
2013-12-23 20:27:32 +01:00
2013-12-16 03:33:44 +01:00
-- reset all to defaults
for k , _ in pairs ( baseconfig ) do
if not k : match ( ' ^[A-Z_]*$ ' ) then --TEMP: skip 'constants', which should be moved anyway
2013-12-23 20:27:32 +01:00
M.reset ( k , true )
2013-12-16 03:33:44 +01:00
end
end
2013-12-23 20:27:32 +01:00
M.commit ( )
2013-11-22 18:05:51 +01:00
return true
end
2013-12-23 15:33:55 +01:00
--- Reset setting to default value
2013-11-22 18:05:51 +01:00
-- @string key The key to reset.
2013-12-23 20:27:32 +01:00
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values
2013-11-22 18:05:51 +01:00
-- @treturn bool|nil True if everything went well, nil in case of error.
2013-12-23 20:27:32 +01:00
function M . reset ( key , noCommit )
2013-12-16 03:33:44 +01:00
log : info ( " settings:reset: " .. utils.dump ( key ) )
2013-12-23 15:33:55 +01:00
2013-12-16 03:33:44 +01:00
-- delete
2013-11-29 13:00:09 +01:00
key = replaceDots ( key )
local base = getBaseKeyTable ( key )
if not base then return nil , ERR_NO_SUCH_KEY end
local section = UCI_CONFIG_SECTION ;
2013-12-23 15:33:55 +01:00
if base.subSection ~= nil then
2013-11-29 13:00:09 +01:00
section = M.get ( base.subSection )
2013-12-23 20:27:32 +01:00
end
2013-12-23 14:35:03 +01:00
local rv , msg = uci : delete ( UCI_CONFIG_NAME , section , key )
2013-12-23 20:26:44 +01:00
-- we can't respond to errors in general here because when a key isn't found
-- (which always happens when reset is used in resetall) it will also generate a error
--if not rv and msg ~= nil then
-- local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..section.."': "..utils.dump(msg);
-- log:info(errorMSG)
-- return nil, errorMSG;
--end
2013-12-23 15:33:55 +01:00
2013-12-16 03:33:44 +01:00
-- reuse get logic to retrieve default and set it.
2013-12-23 20:27:32 +01:00
M.set ( key , M.get ( key ) , true )
2013-12-23 15:33:55 +01:00
2013-12-23 20:27:32 +01:00
if noCommit ~= true then uci : commit ( UCI_CONFIG_NAME ) end
2013-11-22 18:05:51 +01:00
return true
end
2013-08-22 18:34:45 +02:00
--- Returns a UCI configuration key from the system section.
2013-11-04 22:34:09 +01:00
-- @string key The key for which to return the value, must be non-empty.
2013-12-23 15:33:55 +01:00
-- @return Requested value or false if it does not exist or nil on UCI error.
2013-08-22 18:34:45 +02:00
function M . getSystemKey ( key )
if type ( key ) ~= ' string ' or key : len ( ) == 0 then return nil end
2013-12-23 14:35:03 +01:00
local v , msg = uci : get ( UCI_CONFIG_NAME , UCI_CONFIG_SYSTEM_SECTION , key )
if not v and msg ~= nil then
local errorMSG = " Issue getting system setting ' " .. utils.dump ( key ) .. " ' in section ' " .. UCI_CONFIG_SYSTEM_SECTION .. " ': " .. utils.dump ( msg ) ;
return nil , errorMSG ;
end
2013-12-23 15:33:55 +01:00
2013-08-22 18:34:45 +02:00
return v or false
end
2013-11-04 22:34:09 +01:00
--- Sets the value of a UCI key in the system section.
2013-08-22 18:34:45 +02:00
-- Note that unlike the public settings, system keys are untyped and value must
-- be of type string; UCI generally uses '1' and '0' for boolean values.
2013-11-04 22:34:09 +01:00
-- @string key The key to set, must be non-empty.
-- @string value The value to set key to.
-- @return True on success or nil if key or value arguments are invalid.
2013-08-22 18:34:45 +02:00
function M . setSystemKey ( key , value )
if type ( key ) ~= ' string ' or key : len ( ) == 0 then return nil end
if type ( value ) ~= ' string ' then return nil end
2013-11-04 22:34:09 +01:00
2013-08-22 18:34:45 +02:00
local r = utils.create ( UCI_CONFIG_FILE ) -- make sure the file exists for uci to write to
uci : set ( UCI_CONFIG_NAME , UCI_CONFIG_SYSTEM_SECTION , UCI_CONFIG_TYPE )
uci : set ( UCI_CONFIG_NAME , UCI_CONFIG_SYSTEM_SECTION , key , value )
uci : commit ( UCI_CONFIG_NAME )
2013-11-04 22:34:09 +01:00
2013-08-22 18:34:45 +02:00
return true
end
2013-07-17 17:43:33 +02:00
return M