Add extra 'tools' to wifibox devel install. Improve logging.

This commit is contained in:
Wouter R 2013-10-08 16:55:50 +02:00
parent 37783f3f06
commit 8991845427
3 changed files with 28 additions and 32 deletions

View File

@ -3,17 +3,17 @@
### This function makes sure the 'wlan' net is in the 'lan' zone
addFirewallNet() {
cfgChanged=0; zoneNum=-1; i=0
while true; do
name=`uci get firewall.@zone[$i].name 2>&1`
exists=`echo "$name" | grep "Entry not found" >/dev/null 2>&1; echo $?`
if [ $exists -eq 0 ]; then break; fi
if [ "x$name" = "xlan" ]; then zoneNum=$i; fi
i=`expr $i + 1`
done
if [ $zoneNum -gt -1 ]; then
network=`uci get firewall.@zone[$zoneNum].network 2>&1`
hasWlan=`echo $network | grep "wlan" >/dev/null 2>&1; echo $?`
@ -24,7 +24,7 @@ addFirewallNet() {
cfgChanged=1
fi
fi
if [ $cfgChanged -eq 1 ]; then
echo "Added network 'wlan' to zone lan."
else
@ -38,7 +38,7 @@ if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
cat <<-'EOM' > $IPKG_INSTROOT/etc/banner
........D o o d l e 3 D
.......________ _____ _____ v \$(PACKAGE_VERSION)
.......________ _____ _____ v \$(PACKAGE_VERSION)
....../ / / |__ / __/ / - /___ __
...../ / / /--// _|-// --| . /v /
..../________/__//__/__//____/___/_^_\
@ -53,11 +53,17 @@ mkdir -p $IPKG_INSTROOT/root
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
if [ $? -gt 0 ]; then
cat <<-EOM >> $IPKG_INSTROOT/root/.profile
# 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 encore='ulimit -c unlimited'
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
fi
@ -73,7 +79,7 @@ if [ -z "$IPKG_INSTROOT" ]; then
echo "Adding network interface 'wlan'..."
uci set network.wlan=interface; uci commit network; /etc/init.d/network reload
else
# 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
@ -81,15 +87,15 @@ else
uci set system.@system[0].log_size=64
uci set network.lan.ipaddr=192.168.5.1
echo -e "beta\nbeta" | passwd root
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
uci set uhttpd.main.lua_prefix='/d3dapi'
uci set wireless.@wifi-device[0].disabled=0
# TODO: add firewall net
uci set network.wlan=interface
EOM
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
fi

View File

@ -60,7 +60,7 @@ local function setupAutoWifiMode()
break
end
end
if connectWith then
local rv,msg = netconf.associateSsid(connectWith)
if rv then
@ -137,14 +137,13 @@ local function init(environment)
setupLogger()
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_PCALL then dbgText = "pcall"
end
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging enabled)" end
log:info("===========================")
log:info("Wifibox CGI handler started" .. dbgText)
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
log:info("=======rest api" .. dbgText .. "=======")
if (environment['REQUEST_METHOD'] == 'POST') then
local n = tonumber(environment['CONTENT_LENGTH'])
@ -175,15 +174,15 @@ local function main(environment)
end
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
log:info("running in signin mode")
local ds = wifi.getDeviceState()
log:info(" ds.mode: "..util.dump(ds.mode))
if ds.mode == "sta" then
if ds.mode == "sta" then
log:info(" attempting signin")
local success,msg = Signin.signin()
if success then
log:info("Signin successful")
else
else
log:info("Signin failed: "..util.dump(msg))
end
end
@ -194,7 +193,7 @@ local function main(environment)
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
if rq:getRequestMethod() ~= 'CMDLINE' then
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
log:debug("user agent: " .. rq:getUserAgent())
--log:debug("user agent: " .. rq:getUserAgent())
end
local response, err = rq:handle()

View File

@ -97,31 +97,22 @@ end
----------------------------------------------------------------------------
function _M.parsequeryNoRegex (query, args)
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 k = 1
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
--log:info(" v: " .. util.dump(v))
if not v then break end -- no k/v pairs left
local key = query:sub(k, v-1)
log:info(" key: " .. util.dump(key))
v = v + 1
--log:info(" >v: " .. util.dump(v))
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
local value = query:sub(v, ampersand - 1)
--log:info(" value: " .. util.dump(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