mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Implemented signin attempts system and signing response check
This commit is contained in:
parent
8e34f338c2
commit
4d782681df
@ -59,7 +59,7 @@ local function setupAutoWifiMode()
|
|||||||
return nil, "autowifi: could not scan wifi networks (" .. msg .. ")"
|
return nil, "autowifi: could not scan wifi networks (" .. msg .. ")"
|
||||||
end
|
end
|
||||||
|
|
||||||
log:info("current wifi name/mode: " .. (netName or "<nil>") .. "/" .. netMode .. ", ssid of self: " .. apSsid)
|
log:info("current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid)
|
||||||
local visNet, knownNet = {}, {}
|
local visNet, knownNet = {}, {}
|
||||||
for _,sn in ipairs(scanList) do
|
for _,sn in ipairs(scanList) do
|
||||||
table.insert(visNet, sn.ssid)
|
table.insert(visNet, sn.ssid)
|
||||||
@ -93,6 +93,7 @@ local function setupAutoWifiMode()
|
|||||||
return nil, "autowifi: could not associate with ssid '" .. connectWith .. "' (" .. msg .. ")"
|
return nil, "autowifi: could not associate with ssid '" .. connectWith .. "' (" .. msg .. ")"
|
||||||
end
|
end
|
||||||
elseif netMode ~= 'ap' or netName ~= apSsid then
|
elseif netMode ~= 'ap' or netName ~= apSsid then
|
||||||
|
log:info("falling back to access point mode")
|
||||||
local rv,msg = netconf.setupAccessPoint(apSsid)
|
local rv,msg = netconf.setupAccessPoint(apSsid)
|
||||||
if rv then
|
if rv then
|
||||||
return true, "autowifi: configured as access point with ssid '" .. apSsid .. "'"
|
return true, "autowifi: configured as access point with ssid '" .. apSsid .. "'"
|
||||||
|
@ -95,7 +95,7 @@ function M.reloadComponent(c, silent, boot)
|
|||||||
os.execute(cmd)
|
os.execute(cmd)
|
||||||
else
|
else
|
||||||
rv = utils.captureCommandOutput(cmd)
|
rv = utils.captureCommandOutput(cmd)
|
||||||
log:info(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
log:debug(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -375,13 +375,6 @@ function M.associateSsid(ssid, passphrase, recreate, boot)
|
|||||||
return nil,msg
|
return nil,msg
|
||||||
end
|
end
|
||||||
|
|
||||||
log:info(" waiting for network configuration to finish")
|
|
||||||
local waitTime = 1
|
|
||||||
local endTime = os.time() + waitTime
|
|
||||||
while os.time() <= endTime do
|
|
||||||
-- waiting...
|
|
||||||
end
|
|
||||||
|
|
||||||
M.setStatus(M.CONNECTED,"Connected");
|
M.setStatus(M.CONNECTED,"Connected");
|
||||||
|
|
||||||
-- signin to connect.doodle3d.com
|
-- signin to connect.doodle3d.com
|
||||||
|
@ -42,24 +42,57 @@ function M.signin()
|
|||||||
M.setStatus(SIGNING_IN_STATUS,"signing in")
|
M.setStatus(SIGNING_IN_STATUS,"signing in")
|
||||||
|
|
||||||
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
||||||
|
|
||||||
local localip = wifi.getLocalIP();
|
local attemptInterval = 1
|
||||||
if localip == nil then
|
local maxAttempts = 20
|
||||||
log:error("signin failed no local ip found")
|
local attempt = 0
|
||||||
M.setStatus(IDLE_STATUS,"idle")
|
|
||||||
return false
|
local nextAttemptTime = os.time()
|
||||||
|
|
||||||
|
local localip = ""
|
||||||
|
local signinResponse = ""
|
||||||
|
while true do
|
||||||
|
if os.time() > nextAttemptTime then
|
||||||
|
log:debug("signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||||
|
local signedin = false
|
||||||
|
local localip = wifi.getLocalIP();
|
||||||
|
log:debug(" localip: "..utils.dump(localip))
|
||||||
|
if localip ~= nil then
|
||||||
|
|
||||||
|
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||||
|
wifiboxid = urlcode.escape(wifiboxid)
|
||||||
|
|
||||||
|
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||||
|
signinResponse = utils.captureCommandOutput(cmd);
|
||||||
|
log:debug(" signin response: \n"..utils.dump(signinResponse))
|
||||||
|
local success = signinResponse:match('"status":"success"')
|
||||||
|
log:debug(" success: "..utils.dump(success))
|
||||||
|
if success ~= nil then
|
||||||
|
signedin = true
|
||||||
|
else
|
||||||
|
log:warn("signin failed request failed (response: "..utils.dump(signinResponse)..")")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
log:warn("signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
||||||
|
end
|
||||||
|
|
||||||
|
if signedin then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
attempt = attempt+1
|
||||||
|
if attempt >= maxAttempts then
|
||||||
|
-- still no localIP; fail
|
||||||
|
M.setStatus(IDLE_STATUS,"idle")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
nextAttemptTime = os.time() + attemptInterval
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
|
||||||
wifiboxid = urlcode.escape(wifiboxid)
|
|
||||||
|
|
||||||
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
|
||||||
local output = utils.captureCommandOutput(cmd);
|
|
||||||
log:info("signin: "..output)
|
|
||||||
|
|
||||||
M.setStatus(IDLE_STATUS,"idle")
|
M.setStatus(IDLE_STATUS,"idle")
|
||||||
|
return string.len(signinResponse) > 0, signinResponse
|
||||||
return string.len(output) > 0, output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.getStatus()
|
function M.getStatus()
|
||||||
|
@ -124,6 +124,7 @@ end
|
|||||||
--returns the wireless local ip address
|
--returns the wireless local ip address
|
||||||
function M.getLocalIP()
|
function M.getLocalIP()
|
||||||
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
||||||
|
--log:debug(" ifconfig: \n"..utils.dump(ifconfig));
|
||||||
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
||||||
return localip;
|
return localip;
|
||||||
end
|
end
|
||||||
|
@ -15,9 +15,6 @@ boot() {
|
|||||||
|
|
||||||
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
|
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
|
||||||
/usr/share/lua/wifibox/script/d3dapi autowifi
|
/usr/share/lua/wifibox/script/d3dapi autowifi
|
||||||
|
|
||||||
$LOGGER "Start signing in..."
|
|
||||||
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
Loading…
Reference in New Issue
Block a user