mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Fix outdated configuration key names; add API function to get all configuration keys at once; remove logging of request arguments to prevent printing large blocks of gcode.
This commit is contained in:
parent
0f4b938444
commit
efaf58c880
@ -47,8 +47,10 @@ end
|
|||||||
local function main()
|
local function main()
|
||||||
local rq = RequestClass.new(postData, confDefaults.DEBUG_API)
|
local rq = RequestClass.new(postData, confDefaults.DEBUG_API)
|
||||||
|
|
||||||
|
-- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||||
|
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
|
||||||
log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
|
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
||||||
if rq:getRequestMethod() ~= 'CMDLINE' then
|
if rq:getRequestMethod() ~= 'CMDLINE' then
|
||||||
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
||||||
log:debug("user agent: " .. rq:getUserAgent())
|
log:debug("user agent: " .. rq:getUserAgent())
|
||||||
|
@ -96,7 +96,7 @@ end
|
|||||||
--[[ Add/remove access point network ]]
|
--[[ Add/remove access point network ]]
|
||||||
function reconf.apnet_add_noreload(dirtyList) reconf.apnet_add(dirtyList, true) end
|
function reconf.apnet_add_noreload(dirtyList) reconf.apnet_add(dirtyList, true) end
|
||||||
function reconf.apnet_add(dirtyList, noReload)
|
function reconf.apnet_add(dirtyList, noReload)
|
||||||
local ourSsid = wifi.getSubstitutedSsid(settings.get('apSsid'))
|
local ourSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||||
local sname = nil
|
local sname = nil
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
if s.ssid == ourSsid then sname = s['.name']; return false end
|
if s.ssid == ourSsid then sname = s['.name']; return false end
|
||||||
@ -117,7 +117,7 @@ end
|
|||||||
function reconf.apnet_rm(dirtyList)
|
function reconf.apnet_rm(dirtyList)
|
||||||
local sname = nil
|
local sname = nil
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
if s.ssid == wifi.getSubstitutedSsid(settings.get('apSsid')) then sname = s['.name']; return false end
|
if s.ssid == wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then sname = s['.name']; return false end
|
||||||
end)
|
end)
|
||||||
if sname == nil then return log:info("AP network configuration does not exist, nothing to remove") end
|
if sname == nil then return log:info("AP network configuration does not exist, nothing to remove") end
|
||||||
uci:delete('wireless', sname)
|
uci:delete('wireless', sname)
|
||||||
@ -132,8 +132,8 @@ function reconf.staticaddr_add(dirtyList)
|
|||||||
--NOTE: 'type = "bridge"' should -not- be added as this prevents defining a separate dhcp pool (http://wiki.openwrt.org/doc/recipes/routedap)
|
--NOTE: 'type = "bridge"' should -not- be added as this prevents defining a separate dhcp pool (http://wiki.openwrt.org/doc/recipes/routedap)
|
||||||
M.uciTableSet('network', wifi.NET, {
|
M.uciTableSet('network', wifi.NET, {
|
||||||
proto = 'static',
|
proto = 'static',
|
||||||
ipaddr = settings.get('apAddress'),
|
ipaddr = settings.get('network.ap.address'),
|
||||||
netmask = settings.get('apNetmask')
|
netmask = settings.get('network.ap.netmask')
|
||||||
})
|
})
|
||||||
bothBits(dirtyList, 'network')
|
bothBits(dirtyList, 'network')
|
||||||
end
|
end
|
||||||
@ -180,7 +180,7 @@ end
|
|||||||
|
|
||||||
--[[ Add/remove redirecton of all DNS requests to self ]]
|
--[[ Add/remove redirecton of all DNS requests to self ]]
|
||||||
function reconf.dnsredir_add(dirtyList)
|
function reconf.dnsredir_add(dirtyList)
|
||||||
local redirText = '/#/' .. settings.get('apAddress')
|
local redirText = '/#/' .. settings.get('network.ap.address')
|
||||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||||
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||||
if uci:get('dhcp', sname, 'address') ~= nil then return log:debug("DNS address redirection already in place, not re-adding", false) end
|
if uci:get('dhcp', sname, 'address') ~= nil then return log:debug("DNS address redirection already in place, not re-adding", false) end
|
||||||
@ -228,7 +228,7 @@ function reconf.natreflect_add(dirtyList)
|
|||||||
proto = 'tcp',
|
proto = 'tcp',
|
||||||
src_dport = '80',
|
src_dport = '80',
|
||||||
dest_port = '80',
|
dest_port = '80',
|
||||||
dest_ip = settings.get('apAddress'),
|
dest_ip = settings.get('network.ap.address'),
|
||||||
target = 'DNAT'
|
target = 'DNAT'
|
||||||
})
|
})
|
||||||
bothBits(dirtyList, 'firewall')
|
bothBits(dirtyList, 'firewall')
|
||||||
|
@ -8,7 +8,6 @@ local M = {
|
|||||||
|
|
||||||
function M._global_GET(request, response)
|
function M._global_GET(request, response)
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
--TODO: we need a function to list all configuration keys
|
|
||||||
for k,v in pairs(request:getAll()) do
|
for k,v in pairs(request:getAll()) do
|
||||||
local r,m = settings.get(k)
|
local r,m = settings.get(k)
|
||||||
|
|
||||||
@ -30,4 +29,10 @@ function M._global_POST(request, response)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.all_GET(request, response)
|
||||||
|
for k,v in pairs(settings.getAll()) do
|
||||||
|
response:addData(k,v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
local s = require("util.settings")
|
local settings = require("util.settings")
|
||||||
local u = require("util.utils")
|
local utils = require("util.utils")
|
||||||
local l = require("util.logger")
|
|
||||||
local netconf = require("network.netconfig")
|
local netconf = require("network.netconfig")
|
||||||
local wifi = require("network.wlanconfig")
|
local wifi = require("network.wlanconfig")
|
||||||
local ResponseClass = require("rest.response")
|
local ResponseClass = require("rest.response")
|
||||||
@ -17,8 +16,8 @@ end
|
|||||||
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
||||||
--accepts with_raw(bool) to include raw table dump
|
--accepts with_raw(bool) to include raw table dump
|
||||||
function M.scan(request, response)
|
function M.scan(request, response)
|
||||||
local noFilter = u.toboolean(request:get("nofilter"))
|
local noFilter = utils.toboolean(request:get("nofilter"))
|
||||||
local withRaw = u.toboolean(request:get("with_raw"))
|
local withRaw = utils.toboolean(request:get("with_raw"))
|
||||||
local sr = wifi.getScanInfo()
|
local sr = wifi.getScanInfo()
|
||||||
local si, se
|
local si, se
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ function M.scan(request, response)
|
|||||||
response:setSuccess("")
|
response:setSuccess("")
|
||||||
local netInfoList = {}
|
local netInfoList = {}
|
||||||
for _, se in ipairs(sr) do
|
for _, se in ipairs(sr) do
|
||||||
if noFilter or se.mode ~= "ap" and se.ssid ~= wifi.getSubstitutedSsid(s.get('apSsid')) then
|
if noFilter or se.mode ~= "ap" and se.ssid ~= wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then
|
||||||
local netInfo = {}
|
local netInfo = {}
|
||||||
|
|
||||||
netInfo["ssid"] = se.ssid
|
netInfo["ssid"] = se.ssid
|
||||||
@ -37,7 +36,7 @@ function M.scan(request, response)
|
|||||||
netInfo["signal"] = se.signal
|
netInfo["signal"] = se.signal
|
||||||
netInfo["quality"] = se.quality
|
netInfo["quality"] = se.quality
|
||||||
netInfo["quality_max"] = se.quality_max
|
netInfo["quality_max"] = se.quality_max
|
||||||
if withRaw then netInfo["_raw"] = u.dump(se) end
|
if withRaw then netInfo["_raw"] = utils.dump(se) end
|
||||||
|
|
||||||
table.insert(netInfoList, netInfo)
|
table.insert(netInfoList, netInfo)
|
||||||
end
|
end
|
||||||
@ -52,8 +51,8 @@ end
|
|||||||
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
--accepts API argument 'nofilter'(bool) to disable filtering of APs and 'self'
|
||||||
--accepts with_raw(bool) to include raw table dump
|
--accepts with_raw(bool) to include raw table dump
|
||||||
function M.known(request, response)
|
function M.known(request, response)
|
||||||
local noFilter = u.toboolean(request:get("nofilter"))
|
local noFilter = utils.toboolean(request:get("nofilter"))
|
||||||
local withRaw = u.toboolean(request:get("with_raw"))
|
local withRaw = utils.toboolean(request:get("with_raw"))
|
||||||
|
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
local netInfoList = {}
|
local netInfoList = {}
|
||||||
@ -64,7 +63,7 @@ function M.known(request, response)
|
|||||||
netInfo["bssid"] = net.bssid or ""
|
netInfo["bssid"] = net.bssid or ""
|
||||||
netInfo["channel"] = net.channel or ""
|
netInfo["channel"] = net.channel or ""
|
||||||
netInfo["encryption"] = net.encryption
|
netInfo["encryption"] = net.encryption
|
||||||
if withRaw then netInfo["_raw"] = u.dump(net) end
|
if withRaw then netInfo["_raw"] = utils.dump(net) end
|
||||||
table.insert(netInfoList, netInfo)
|
table.insert(netInfoList, netInfo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -74,7 +73,7 @@ end
|
|||||||
|
|
||||||
--accepts with_raw(bool) to include raw table dump
|
--accepts with_raw(bool) to include raw table dump
|
||||||
function M.status(request, response)
|
function M.status(request, response)
|
||||||
local withRaw = u.toboolean(request:get("with_raw"))
|
local withRaw = utils.toboolean(request:get("with_raw"))
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
|
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
@ -88,10 +87,9 @@ function M.status(request, response)
|
|||||||
response:addData("txpower", ds.txpower)
|
response:addData("txpower", ds.txpower)
|
||||||
response:addData("signal", ds.signal)
|
response:addData("signal", ds.signal)
|
||||||
response:addData("noise", ds.noise)
|
response:addData("noise", ds.noise)
|
||||||
if withRaw then response:addData("_raw", u.dump(ds)) end
|
if withRaw then response:addData("_raw", utils.dump(ds)) end
|
||||||
end
|
end
|
||||||
|
|
||||||
--UNTESTED
|
|
||||||
--requires ssid(string), accepts phrase(string), recreate(bool)
|
--requires ssid(string), accepts phrase(string), recreate(bool)
|
||||||
function M.associate_POST(request, response)
|
function M.associate_POST(request, response)
|
||||||
local argSsid = request:get("ssid")
|
local argSsid = request:get("ssid")
|
||||||
@ -138,9 +136,8 @@ function M.disassociate_POST(request, response)
|
|||||||
response:addData("wifi_restart_result", rv)
|
response:addData("wifi_restart_result", rv)
|
||||||
end
|
end
|
||||||
|
|
||||||
--UNTESTED
|
|
||||||
function M.openap_POST(request, response)
|
function M.openap_POST(request, response)
|
||||||
local ssid = wifi.getSubstitutedSsid(s.get('apSsid'))
|
local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||||
netconf.switchConfiguration{apnet="add_noreload"}
|
netconf.switchConfiguration{apnet="add_noreload"}
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
netconf.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add", wwwredir="add", dnsredir="add" }
|
netconf.switchConfiguration{ wifiiface="add", network="reload", staticaddr="add", dhcppool="add", wwwredir="add", dnsredir="add" }
|
||||||
|
@ -27,7 +27,15 @@ local ERR_NO_SUCH_KEY = "key does not exist"
|
|||||||
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
|
-- @return The substituted key, or the key parameter itself if it is not of type 'string'.
|
||||||
local function replaceDots(key)
|
local function replaceDots(key)
|
||||||
if type(key) ~= 'string' then return key end
|
if type(key) ~= 'string' then return key end
|
||||||
return key:gsub('%.', '_')
|
local r = key:gsub('%.', '_')
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
-- The inverse of replaceDots()
|
||||||
|
local function replaceUnderscores(key)
|
||||||
|
if type(key) ~= 'string' then return key end
|
||||||
|
local r = key:gsub('_', '%.')
|
||||||
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
local function toUciValue(v, vType)
|
local function toUciValue(v, vType)
|
||||||
@ -97,6 +105,17 @@ function M.get(key)
|
|||||||
return actualV
|
return actualV
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
result[key] = M.get(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
function M.exists(key)
|
function M.exists(key)
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
return getBaseKeyTable(key) ~= nil
|
return getBaseKeyTable(key) ~= nil
|
||||||
|
Loading…
Reference in New Issue
Block a user