mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2025-05-10 19:13:22 +02:00
Add extra 'tools' to wifibox devel install. Improve logging.
This commit is contained in:
parent
37783f3f06
commit
8991845427
@ -3,17 +3,17 @@
|
|||||||
### This function makes sure the 'wlan' net is in the 'lan' zone
|
### This function makes sure the 'wlan' net is in the 'lan' zone
|
||||||
addFirewallNet() {
|
addFirewallNet() {
|
||||||
cfgChanged=0; zoneNum=-1; i=0
|
cfgChanged=0; zoneNum=-1; i=0
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
name=`uci get firewall.@zone[$i].name 2>&1`
|
name=`uci get firewall.@zone[$i].name 2>&1`
|
||||||
exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?`
|
exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?`
|
||||||
|
|
||||||
if [ $exists -eq 0 ]; then break; fi
|
if [ $exists -eq 0 ]; then break; fi
|
||||||
if [ "x$name" = "xlan" ]; then zoneNum=$i; fi
|
if [ "x$name" = "xlan" ]; then zoneNum=$i; fi
|
||||||
|
|
||||||
i=`expr $i + 1`
|
i=`expr $i + 1`
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $zoneNum -gt -1 ]; then
|
if [ $zoneNum -gt -1 ]; then
|
||||||
network=`uci get firewall.@zone[$zoneNum].network 2>&1`
|
network=`uci get firewall.@zone[$zoneNum].network 2>&1`
|
||||||
hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?`
|
hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?`
|
||||||
@ -24,7 +24,7 @@ addFirewallNet() {
|
|||||||
cfgChanged=1
|
cfgChanged=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $cfgChanged -eq 1 ]; then
|
if [ $cfgChanged -eq 1 ]; then
|
||||||
echo "Added network 'wlan' to zone lan."
|
echo "Added network 'wlan' to zone lan."
|
||||||
else
|
else
|
||||||
@ -38,7 +38,7 @@ if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
|
|||||||
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
||||||
cat <<-'EOM' > $IPKG_INSTROOT/etc/banner
|
cat <<-'EOM' > $IPKG_INSTROOT/etc/banner
|
||||||
........D o o d l e 3 D
|
........D o o d l e 3 D
|
||||||
.......________ _____ _____ v \$(PACKAGE_VERSION)
|
.......________ _____ _____ v \$(PACKAGE_VERSION)
|
||||||
....../ / / |__ / __/ / - /___ __
|
....../ / / |__ / __/ / - /___ __
|
||||||
...../ / / /--// _|-// --| . /v /
|
...../ / / /--// _|-// --| . /v /
|
||||||
..../________/__//__/__//____/___/_^_\
|
..../________/__//__/__//____/___/_^_\
|
||||||
@ -53,11 +53,17 @@ mkdir -p $IPKG_INSTROOT/root
|
|||||||
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
cat <<-EOM >> $IPKG_INSTROOT/root/.profile
|
cat <<-EOM >> $IPKG_INSTROOT/root/.profile
|
||||||
|
|
||||||
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
||||||
|
alias d='ls -la'
|
||||||
alias d3dapi='/usr/share/lua/wifibox/script/d3dapi'
|
alias d3dapi='/usr/share/lua/wifibox/script/d3dapi'
|
||||||
alias encore='ulimit -c unlimited'
|
alias encore='ulimit -c unlimited'
|
||||||
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
||||||
|
|
||||||
|
loop() {
|
||||||
|
if [ \$# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
||||||
|
DELAY=\$1; shift; while true; do \$@; sleep \$DELAY; done
|
||||||
|
}
|
||||||
EOM
|
EOM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -73,7 +79,7 @@ if [ -z "$IPKG_INSTROOT" ]; then
|
|||||||
|
|
||||||
echo "Adding network interface 'wlan'..."
|
echo "Adding network interface 'wlan'..."
|
||||||
uci set network.wlan=interface; uci commit network; /etc/init.d/network reload
|
uci set network.wlan=interface; uci commit network; /etc/init.d/network reload
|
||||||
|
|
||||||
else
|
else
|
||||||
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0
|
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0
|
||||||
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
||||||
@ -81,15 +87,15 @@ else
|
|||||||
uci set system.@system[0].log_size=64
|
uci set system.@system[0].log_size=64
|
||||||
uci set network.lan.ipaddr=192.168.5.1
|
uci set network.lan.ipaddr=192.168.5.1
|
||||||
echo -e "beta\nbeta" | passwd root
|
echo -e "beta\nbeta" | passwd root
|
||||||
|
|
||||||
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
||||||
uci set uhttpd.main.lua_prefix='/d3dapi'
|
uci set uhttpd.main.lua_prefix='/d3dapi'
|
||||||
|
|
||||||
uci set wireless.@wifi-device[0].disabled=0
|
uci set wireless.@wifi-device[0].disabled=0
|
||||||
# TODO: add firewall net
|
# TODO: add firewall net
|
||||||
uci set network.wlan=interface
|
uci set network.wlan=interface
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
17
src/main.lua
17
src/main.lua
@ -60,7 +60,7 @@ local function setupAutoWifiMode()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if connectWith then
|
if connectWith then
|
||||||
local rv,msg = netconf.associateSsid(connectWith)
|
local rv,msg = netconf.associateSsid(connectWith)
|
||||||
if rv then
|
if rv then
|
||||||
@ -137,14 +137,13 @@ local function init(environment)
|
|||||||
setupLogger()
|
setupLogger()
|
||||||
|
|
||||||
local dbgText = ""
|
local dbgText = ""
|
||||||
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall and api"
|
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall+api"
|
||||||
elseif confDefaults.DEBUG_API then dbgText = "api"
|
elseif confDefaults.DEBUG_API then dbgText = "api"
|
||||||
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
||||||
end
|
end
|
||||||
|
|
||||||
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging enabled)" end
|
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
|
||||||
log:info("===========================")
|
log:info("=======rest api" .. dbgText .. "=======")
|
||||||
log:info("Wifibox CGI handler started" .. dbgText)
|
|
||||||
|
|
||||||
if (environment['REQUEST_METHOD'] == 'POST') then
|
if (environment['REQUEST_METHOD'] == 'POST') then
|
||||||
local n = tonumber(environment['CONTENT_LENGTH'])
|
local n = tonumber(environment['CONTENT_LENGTH'])
|
||||||
@ -175,15 +174,15 @@ local function main(environment)
|
|||||||
end
|
end
|
||||||
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
||||||
log:info("running in signin mode")
|
log:info("running in signin mode")
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
log:info(" ds.mode: "..util.dump(ds.mode))
|
log:info(" ds.mode: "..util.dump(ds.mode))
|
||||||
if ds.mode == "sta" then
|
if ds.mode == "sta" then
|
||||||
log:info(" attempting signin")
|
log:info(" attempting signin")
|
||||||
local success,msg = Signin.signin()
|
local success,msg = Signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info("Signin successful")
|
log:info("Signin successful")
|
||||||
else
|
else
|
||||||
log:info("Signin failed: "..util.dump(msg))
|
log:info("Signin failed: "..util.dump(msg))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -194,7 +193,7 @@ local function main(environment)
|
|||||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
.. "/" .. (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())
|
||||||
end
|
end
|
||||||
|
|
||||||
local response, err = rq:handle()
|
local response, err = rq:handle()
|
||||||
|
@ -97,31 +97,22 @@ 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…
x
Reference in New Issue
Block a user