mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Signin every hour
This commit is contained in:
parent
af5598c606
commit
b042be5405
1
Makefile
1
Makefile
@ -99,6 +99,7 @@ define Package/wifibox/install
|
|||||||
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox # copy directly to init dir (required for post-inst enabling)
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox # copy directly to init dir (required for post-inst enabling)
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||||
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||||
|
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
||||||
|
|
||||||
|
@ -50,6 +50,14 @@ M.network_ap_netmask = {
|
|||||||
regex = '%d+\.%d+\.%d+\.%d+'
|
regex = '%d+\.%d+\.%d+\.%d+'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M.network_cl_wifiboxid = {
|
||||||
|
default = 'Doodle3D-%%MAC_ADDR_TAIL%%',
|
||||||
|
type = 'string',
|
||||||
|
description = 'Client mode WiFi box id',
|
||||||
|
min = 1,
|
||||||
|
max = 32
|
||||||
|
}
|
||||||
|
|
||||||
M.printer_type = {
|
M.printer_type = {
|
||||||
default = 'ultimaker',
|
default = 'ultimaker',
|
||||||
type = 'string',
|
type = 'string',
|
||||||
|
14
src/main.lua
14
src/main.lua
@ -8,6 +8,7 @@ local wifi = require('network.wlanconfig')
|
|||||||
local netconf = require('network.netconfig')
|
local netconf = require('network.netconfig')
|
||||||
local RequestClass = require('rest.request')
|
local RequestClass = require('rest.request')
|
||||||
local ResponseClass = require('rest.response')
|
local ResponseClass = require('rest.response')
|
||||||
|
local Signin = require('network.signin')
|
||||||
|
|
||||||
local postData = nil
|
local postData = nil
|
||||||
|
|
||||||
@ -172,6 +173,19 @@ local function main(environment)
|
|||||||
else
|
else
|
||||||
log:error("autowifi setup failed (" .. msg .. ")")
|
log:error("autowifi setup failed (" .. msg .. ")")
|
||||||
end
|
end
|
||||||
|
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
||||||
|
log:info("running in signin mode")
|
||||||
|
|
||||||
|
local ds = wifi.getDeviceState()
|
||||||
|
if ds.mode == "sta" then
|
||||||
|
local rv,msg = Signin.signin()
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[if rv then
|
||||||
|
log:info("autowifi setup done (" .. msg .. ")")
|
||||||
|
else
|
||||||
|
log:error("autowifi setup failed (" .. msg .. ")")
|
||||||
|
end]]--
|
||||||
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
|
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
|
||||||
-- 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>") .. " with arguments: " .. util.dump(rq:getAll()))
|
||||||
|
42
src/network/signin.lua
Normal file
42
src/network/signin.lua
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
local log = require('util.logger')
|
||||||
|
local utils = require('util.utils')
|
||||||
|
local uci = require('uci').cursor()
|
||||||
|
local iwinfo = require('iwinfo')
|
||||||
|
local settings = require('util.settings')
|
||||||
|
local wlanconfig = require("network.wlanconfig")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- TODO: this function has been duplicated from rest/api/api_system.lua
|
||||||
|
local function captureCommandOutput(cmd)
|
||||||
|
local f = assert(io.popen(cmd, 'r'))
|
||||||
|
local output = assert(f:read('*all'))
|
||||||
|
--TODO: test if this works to obtain the return code (http://stackoverflow.com/questions/7607384/getting-return-status-and-program-output)
|
||||||
|
--local rv = assert(f:close())
|
||||||
|
--return output,rv[3]
|
||||||
|
return output
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Signin to connect.doodle3d.com server
|
||||||
|
--
|
||||||
|
function M.signin()
|
||||||
|
local wifiboxid = "henk"
|
||||||
|
local localip = "10.0.0.99"
|
||||||
|
local baseurl = "http://192.168.5.220/connect.doodle3d.local/signin.php"
|
||||||
|
|
||||||
|
local ifconfig = captureCommandOutput("ifconfig wlan0");
|
||||||
|
--log:info("ifconfig: "..ifconfig)
|
||||||
|
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
||||||
|
--log:info("localip: "..utils.dump(localip))
|
||||||
|
|
||||||
|
local wifiboxid = wlanconfig.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||||
|
--log:info("wifiboxid: "..utils.dump(wifiboxid))
|
||||||
|
|
||||||
|
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||||
|
local output = captureCommandOutput(cmd);
|
||||||
|
log:info("signin: "..output)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
@ -175,7 +175,7 @@ function M.new(environment, postData, debugEnabled)
|
|||||||
self.pathArgs = arrayFromPath(environment['PATH_INFO'])
|
self.pathArgs = arrayFromPath(environment['PATH_INFO'])
|
||||||
|
|
||||||
-- override path arguments with command line parameter and allow to emulate GET/POST if debugging is enabled *and* if the autowifi special command wasn't mentioned
|
-- override path arguments with command line parameter and allow to emulate GET/POST if debugging is enabled *and* if the autowifi special command wasn't mentioned
|
||||||
if debugEnabled and self.requestMethod == 'CMDLINE' and self:get('autowifi') == nil then
|
if debugEnabled and self.requestMethod == 'CMDLINE' and self:get('autowifi') == nil and self:get('signin') == nil then
|
||||||
self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
|
self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
|
||||||
|
|
||||||
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then
|
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then
|
||||||
|
7
src/script/signin.sh
Executable file
7
src/script/signin.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null
|
||||||
|
|
||||||
|
sleep 1h
|
||||||
|
done
|
@ -8,6 +8,9 @@ LOGGER="logger -s -t autowifi -p 6"
|
|||||||
boot() {
|
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() {
|
||||||
@ -16,4 +19,4 @@ boot() {
|
|||||||
|
|
||||||
#stop() {
|
#stop() {
|
||||||
# $LOGGER "dummy stop"
|
# $LOGGER "dummy stop"
|
||||||
#}
|
#}
|
@ -97,20 +97,31 @@ end
|
|||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
function _M.parsequeryNoRegex (query, args)
|
function _M.parsequeryNoRegex (query, args)
|
||||||
if type(query) == "string" then
|
if type(query) == "string" then
|
||||||
|
local log = require('util.logger')
|
||||||
|
local util = require('util.utils')
|
||||||
|
log:info("parsequeryNoRegex")
|
||||||
|
--log:info(" query: " .. util.dump(query))
|
||||||
|
--log:info(" args: " .. util.dump(args))
|
||||||
|
|
||||||
local insertfield, unescape = _M.insertfield, _M.unescape
|
local insertfield, unescape = _M.insertfield, _M.unescape
|
||||||
|
|
||||||
local k = 1
|
local k = 1
|
||||||
while true do
|
while true do
|
||||||
local v = query:find('=', k+1, true) -- look for '=', assuming a key of at least 1 character and do not perform pattern matching
|
local v = query:find('=', k+1, true) -- look for '=', assuming a key of at least 1 character and do not perform pattern matching
|
||||||
|
--log:info(" v: " .. util.dump(v))
|
||||||
if not v then break end -- no k/v pairs left
|
if not v then break end -- no k/v pairs left
|
||||||
|
|
||||||
local key = query:sub(k, v-1)
|
local key = query:sub(k, v-1)
|
||||||
|
log:info(" key: " .. util.dump(key))
|
||||||
v = v + 1
|
v = v + 1
|
||||||
|
--log:info(" >v: " .. util.dump(v))
|
||||||
local ampersand = query:find('&', v, true)
|
local ampersand = query:find('&', v, true)
|
||||||
|
--log:info(" ampersand: " .. util.dump(ampersand))
|
||||||
if not ampersand then ampersand = 0 end -- 0 will become -1 in the substring call below...meaning end of string
|
if not ampersand then ampersand = 0 end -- 0 will become -1 in the substring call below...meaning end of string
|
||||||
|
|
||||||
|
|
||||||
local value = query:sub(v, ampersand - 1)
|
local value = query:sub(v, ampersand - 1)
|
||||||
|
--log:info(" value: " .. util.dump(value))
|
||||||
insertfield (args, unescape(key), unescape(value))
|
insertfield (args, unescape(key), unescape(value))
|
||||||
|
|
||||||
if ampersand == 0 then break end -- we couldn't find any ampersands anymore so this was the last k/v
|
if ampersand == 0 then break end -- we couldn't find any ampersands anymore so this was the last k/v
|
||||||
|
Loading…
Reference in New Issue
Block a user