mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-11-16 10:47:55 +01:00
Better response to invalid request method in rest api; fix creation of DHCP pool.
This commit is contained in:
parent
1acb559a1b
commit
6ee8b0193e
@ -151,7 +151,7 @@ end
|
|||||||
--[[ Add/remove DHCP pool for wireless net ]]
|
--[[ Add/remove DHCP pool for wireless net ]]
|
||||||
function reconf.dhcppool_add(dirtyList)
|
function reconf.dhcppool_add(dirtyList)
|
||||||
uci:set('dhcp', wifi.getDeviceName(), 'dhcp') --create section
|
uci:set('dhcp', wifi.getDeviceName(), 'dhcp') --create section
|
||||||
M.uciTableSet('dhcp', wifi.getDeviceName(), {
|
M.uciTableSet('dhcp', wifi.NET, {
|
||||||
interface = wifi.NET,
|
interface = wifi.NET,
|
||||||
start = '100',
|
start = '100',
|
||||||
limit = '150',
|
limit = '150',
|
||||||
|
@ -10,7 +10,7 @@ M.DFL_DEVICE = 'wlan0'
|
|||||||
M.DFL_DEVICE_FALLBACK = 'radio0'
|
M.DFL_DEVICE_FALLBACK = 'radio0'
|
||||||
M.NET = 'wlan'
|
M.NET = 'wlan'
|
||||||
|
|
||||||
-- NOTE: deviceApi is returned by iwinfo.tpe(deviceName)
|
-- NOTE: deviceApi is returned by iwinfo.type(deviceName)
|
||||||
local deviceName, deviceApi
|
local deviceName, deviceApi
|
||||||
|
|
||||||
-- if a substitution of baseApSsid is requested, cachedApSsid is returned if not nil
|
-- if a substitution of baseApSsid is requested, cachedApSsid is returned if not nil
|
||||||
|
@ -81,14 +81,17 @@ local function resolveApiModule(modname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Resolves a module/function name pair with appropiate access for the given request method.
|
--- Resolves a module/function name pair with appropiate access for the given request method.
|
||||||
-- First, the function name suffixed with the request method, if not found the plain
|
-- First, the function name suffixed with the request method is looked up, if not found the plain
|
||||||
-- function name is looked up.
|
-- function name is looked up.
|
||||||
-- Returned result data contains a 'func' key and if found, also 'blankArg'.
|
-- The returned table contains a 'func' key if resolution was successful.
|
||||||
-- @param modname Basename of the module to resolve funcname in.
|
-- A key 'accessType' will also be included indicating valid access methods (GET, POST or ANY), except of course when the function does not exist at all.
|
||||||
-- @param funcname Basename of the function to resolve.
|
-- If present, a key 'blankArg' will also be included.
|
||||||
-- @param requestMethod Method by which the request was received.
|
-- Finally, the key 'notfound' will be set to true if no function (even of invalid access type) could be found.
|
||||||
-- @return A table with resultData or nil on error.
|
--
|
||||||
-- @return A message on error (unresolvable or inaccessible).
|
-- @tparam string modname Basename of the module to resolve funcname in.
|
||||||
|
-- @tparam string funcname Basename of the function to resolve.
|
||||||
|
-- @tparam string requestMethod Method by which the request was received.
|
||||||
|
-- @treturn table A table with resultData.
|
||||||
-- @see resolveApiModule
|
-- @see resolveApiModule
|
||||||
local function resolveApiFunction(modname, funcname, requestMethod)
|
local function resolveApiFunction(modname, funcname, requestMethod)
|
||||||
local resultData = {}
|
local resultData = {}
|
||||||
@ -109,14 +112,33 @@ local function resolveApiFunction(modname, funcname, requestMethod)
|
|||||||
|
|
||||||
if (type(fWithMethod) == 'function') then
|
if (type(fWithMethod) == 'function') then
|
||||||
resultData.func = fWithMethod
|
resultData.func = fWithMethod
|
||||||
|
resultData.accessType = rqType
|
||||||
|
|
||||||
elseif (type(fGeneric) == 'function') then
|
elseif (type(fGeneric) == 'function') then
|
||||||
resultData.func = fGeneric
|
resultData.func = fGeneric
|
||||||
|
resultData.accessType = 'ANY'
|
||||||
|
|
||||||
elseif funcNumber ~= nil then
|
elseif funcNumber ~= nil then
|
||||||
resultData.func = mod[GLOBAL_API_FUNCTION_NAME .. '_' .. rqType]
|
resultData.func = mod[GLOBAL_API_FUNCTION_NAME .. '_' .. rqType]
|
||||||
if not resultData.func then resultData.func = mod[GLOBAL_API_FUNCTION_NAME] end
|
resultData.accessType = rqType
|
||||||
|
|
||||||
|
if not resultData.func then
|
||||||
|
resultData.func = mod[GLOBAL_API_FUNCTION_NAME]
|
||||||
|
resultData.accessType = 'ANY'
|
||||||
|
end
|
||||||
|
|
||||||
resultData.blankArg = funcNumber
|
resultData.blankArg = funcNumber
|
||||||
|
|
||||||
else
|
else
|
||||||
return nil, ("function '" .. funcname .. "' does not exist in API module '" .. modname .. "'")
|
local otherRqType = rqType == 'POST' and 'GET' or 'POST'
|
||||||
|
local fWithOtherMethod = mod[funcname .. '_' .. otherRqType]
|
||||||
|
if (type(fWithOtherMethod) == 'function') then
|
||||||
|
-- error is indicated by leaving out 'func' key
|
||||||
|
resultData.accessType = otherRqType
|
||||||
|
else
|
||||||
|
-- error is indicated by leaving out 'func' key and adding 'notfound'=true
|
||||||
|
resultData.notfound = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return resultData
|
return resultData
|
||||||
@ -174,9 +196,9 @@ function M.new(postData, debugEnabled)
|
|||||||
|
|
||||||
|
|
||||||
-- Perform module/function resolution
|
-- Perform module/function resolution
|
||||||
local rData, errMsg = resolveApiFunction(self:getRequestedApiModule(), self:getRequestedApiFunction(), self.requestMethod)
|
local rData = resolveApiFunction(self:getRequestedApiModule(), self:getRequestedApiFunction(), self.requestMethod)
|
||||||
|
|
||||||
if rData ~= nil and rData.func ~= nil then --function (possibly the global one) could be resolved
|
if rData.func ~= nil then --function (possibly the global one) could be resolved
|
||||||
self.resolvedApiFunction = rData.func
|
self.resolvedApiFunction = rData.func
|
||||||
if rData.blankArg ~= nil then --apparently it was the global one, and we received a 'blank argument'
|
if rData.blankArg ~= nil then --apparently it was the global one, and we received a 'blank argument'
|
||||||
self:setBlankArgument(rData.blankArg)
|
self:setBlankArgument(rData.blankArg)
|
||||||
@ -189,12 +211,12 @@ function M.new(postData, debugEnabled)
|
|||||||
self.realApiFunctionName = GLOBAL_API_FUNCTION_NAME
|
self.realApiFunctionName = GLOBAL_API_FUNCTION_NAME
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif rData.notfound == true then
|
||||||
|
self.resolutionError = "module/function '" .. self:getRequestedApiModule() .. "/" .. self:getRequestedApiFunction() .. "' does not exist"
|
||||||
else
|
else
|
||||||
--instead of throwing an error, save the message for handle() which is expected to return a response anyway
|
self.resolutionError = "module/function '" .. self:getRequestedApiModule() .. "/" .. self:getRequestedApiFunction() .. "' can only be accessed with the " .. rData.accessType .. " method"
|
||||||
self.resolutionError = errMsg
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -256,8 +278,8 @@ function M:handle()
|
|||||||
return resp, ("calling function '" .. self.realApiFunctionName .. "' in API module '" .. modname .. "' somehow failed ('" .. r .. "')")
|
return resp, ("calling function '" .. self.realApiFunctionName .. "' in API module '" .. modname .. "' somehow failed ('" .. r .. "')")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
resp:setError("function or module unknown '" .. (modname or "<empty>") .. "/" .. (self:getRequestedApiFunction() or "<empty>") .. "'")
|
resp:setError("cannot call function or module '" .. (modname or "<empty>") .. "/" .. (self:getRequestedApiFunction() or "<empty>") .. "' ('" .. self.resolutionError .. "')")
|
||||||
return resp, ("could not resolve requested API function ('" .. self.resolutionError .. "')")
|
return resp, ("cannot call requested API function ('" .. self.resolutionError .. "')")
|
||||||
end
|
end
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
Reference in New Issue
Block a user