diff --git a/post-install.sh b/post-install.sh index f95bf80..8942a26 100644 --- a/post-install.sh +++ b/post-install.sh @@ -88,9 +88,6 @@ else uci set wireless.@wifi-device[0].disabled=0 # TODO: add firewall net uci set network.wlan=interface - - #TEMP: quick hack to automatically configure AP mode - /usr/share/lua/wifibox/script/d3dapi r=POST p=/network/openap EOM echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device" diff --git a/src/main.lua b/src/main.lua index 2d6ea14..0a6ce60 100644 --- a/src/main.lua +++ b/src/main.lua @@ -12,15 +12,15 @@ local ResponseClass = require('rest.response') local postData = nil --- expects list with tables containing 'ssid' key as values and returns index key if found or nil if not found -local function findSsidInList(list, name) - for k,v in ipairs(list) do - if v.ssid == name then return k end - end - return nil -end - local function setupAutoWifiMode() + -- expects list with tables containing 'ssid' key as values and returns index key if found or nil if not found + local function findSsidInList(list, name) + for k,v in ipairs(list) do + if v.ssid == name then return k end + end + return nil + end + local wifiState = wifi.getDeviceState() local netName, netMode = wifiState.ssid, wifiState.mode @@ -46,7 +46,7 @@ local function setupAutoWifiMode() log:info("known networks: " .. table.concat(knownNet, ", ")) -- if the currently active network is client mode and is also visible, do nothing since it will connect automatically further along the boot process - if netMode == 'sta' and findSsidInList(scanList, netName) then + if netMode == 'sta' and netName ~= nil and netName ~= "" and findSsidInList(scanList, netName) then return true, "autowifi: no action - existing configuration found for currently wifi visible network (" .. netName .. ")" end @@ -60,7 +60,6 @@ local function setupAutoWifiMode() end if connectWith then - print("connectWith: " .. connectWith) --TEMP local rv,msg = netconf.associateSsid(connectWith) if rv then return true, "autowifi: associated -- client mode with ssid '" .. connectWith .. "'" @@ -163,15 +162,6 @@ end local function main(environment) local rq = RequestClass.new(environment, postData, confDefaults.DEBUG_API) --- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") --- .. "/" .. (rq:getRealApiFunctionName() or "") .. " with arguments: " .. util.dump(rq:getAll())) - log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") - .. "/" .. (rq:getRealApiFunctionName() or "")) - if rq:getRequestMethod() ~= 'CMDLINE' then - log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort()) - log:debug("user agent: " .. rq:getUserAgent()) - end - if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then log:info("running in autowifi mode") local rv,msg = setupAutoWifiMode() @@ -182,6 +172,15 @@ end log:error("autowifi setup failed (" .. msg .. ")") end elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then + -- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") + -- .. "/" .. (rq:getRealApiFunctionName() or "") .. " with arguments: " .. util.dump(rq:getAll())) + log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") + .. "/" .. (rq:getRealApiFunctionName() or "")) + if rq:getRequestMethod() ~= 'CMDLINE' then + log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort()) + log:debug("user agent: " .. rq:getUserAgent()) + end + local response, err = rq:handle() if err ~= nil then log:error(err) end