0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-07-13 19:00:43 +02:00

Fix request initialization to handle autowifi command-line invocation correctly; fix installation and execution of openwrt init script; partially implement autowifi switching; fixes to package (de-)installation.

This commit is contained in:
Wouter R 2013-08-20 22:38:16 +02:00
parent 6f431942cc
commit d59d2da938
8 changed files with 98 additions and 26 deletions

View File

@ -16,7 +16,7 @@ IncludeWithNewlines = $(subst
# Name and release number of this package
PKG_NAME := wifibox
PKG_VERSION := 0.1.0
PKG_RELEASE := 6
PKG_RELEASE := 7
# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
@ -85,7 +85,6 @@ define Package/wifibox/install
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/rest/api
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/script
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/util
$(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/www
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/www/cgi-bin
@ -98,11 +97,12 @@ define Package/wifibox/install
$(CP) $(WIFIBOX_BASE_DIR)/rest/api/*.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/rest/api/
$(CP) $(WIFIBOX_BASE_DIR)/util/*.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/util/
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/$(TGT_LUA_DIR_SUFFIX)/script
$(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_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/www
# $(CP) $(WIFIBOX_BASE_DIR)/www/* $(1)/$(TGT_LUA_DIR_SUFFIX)/www/
$(CP) $(WIFIBOX_BASE_DIR)/www/* $(1)/www/ #copy www files directly to /www
$(CP) $(WIFIBOX_BASE_DIR)/www/* $(1)/www/ #copy www files directly to /www
ifeq ($(CONFIG_WIFIBOX_DEVEL_PACKAGE),y)
# $(INSTALL_DIR) $(1)/$(TGT_LUA_DIR_SUFFIX)/misc
@ -115,9 +115,7 @@ endif
### create links elsewhere in the system (autowifi)
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3dapi $(1)/www/cgi-bin
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/wifibox_init $(1)/etc/init.d/wifibox
### install gpx utility
$(INSTALL_DIR) $(1)/usr/bin

View File

@ -49,7 +49,7 @@ EOM
fi
### Add some convenience aliases to root's profile
mkdir $IPKG_INSTROOT/root
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
@ -63,7 +63,7 @@ fi
### Finally make sure basic configuration is set correctly
/etc/init.d/wifibox enable
$IPKG_INSTROOT/etc/init.d/wifibox enable
if [ -z "$IPKG_INSTROOT" ]; then
echo "Enabling wifi device..."

View File

@ -4,15 +4,25 @@ if [ -f /etc/banner.default ]; then
mv /etc/banner.default /etc/banner
fi
rmdir /usr/share/lua/wifibox/www/wifibox
rmdir /usr/share/lua/wifibox/www
rmdir /usr/share/lua/wifibox/network
rmdir /usr/share/lua/wifibox/rest/api
rmdir /usr/share/lua/wifibox/rest
rmdir /usr/share/lua/wifibox/script
rmdir /usr/share/lua/wifibox/test/www 2> /dev/null
rmdir /usr/share/lua/wifibox/test 2> /dev/null
rmdir /usr/share/lua/wifibox/util
rmdir /usr/share/lua/wifibox
rmdir /usr/share/lua
# Try to remove all www directories used by the package, and intentionally leave anything non-empty alone
rmdir /www/js/libs
rmdir /www/js
rmdir /www/img/buttons
rmdir /www/img
rmdir /www/css
rm /www/test 2> /dev/null
rmdir /www/cgi-bin
echo "The wifibox banner has been removed. Changes to the root profile however, have"
echo "not been reverted, as haven't the wlan firewall zone and the radio0 device state."
echo "NOTE: config changes have not been implemented yet."

View File

@ -1,7 +1,5 @@
#!/bin/sh
if [ -z "$$IPKG_INSTROOT" ]; then
/etc/init.d/wifibox disable
fi
$IPKG_INSTROOT/etc/init.d/wifibox disable
exit 0

View File

@ -1,8 +1,9 @@
package.path = package.path .. ';/usr/share/lua/wifibox/?.lua'
local confDefaults = require('conf_defaults')
local util = require('util.utils')
local log = require('util.logger')
local settings = require('util.settings')
local util = require('util.utils')
local wifi = require('network.wlanconfig')
local netconf = require('network.netconfig')
local RequestClass = require('rest.request')
@ -11,8 +12,66 @@ 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()
io.write("--TODO: join known network if present, fall back to access point otherwise\n")
local wifiState = wifi.getDeviceState()
local netName, netMode = wifiState.ssid, wifiState.mode
local apSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
local apMode = (apSsid == netName) and netMode == 'ap'
local scanList,msg = wifi.getScanInfo()
local knownSsids = wifi.getConfigs()
if not scanList then
return nil, "autowifi: could not scan wifi networks (" .. msg .. ")"
end
-- START TEMP -- mode should be ap or sta
print("wifi name: " .. netName .. ", wifi mode: " .. netMode .. ", expected AP ssid: " .. apSsid .. ", apmode: " .. (apMode and "yes" or "no"))
for _,sn in ipairs(scanList) do
print("avl net: " .. sn.ssid)
end
for _,kn in ipairs(knownSsids) do
print("known net: " .. kn.ssid .. " (mode: " .. kn.mode .. ")")
end
-- END TEMP
-- 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
return true, "autowifi: no action - existing configuration found for currently wifi visible network (" .. netName .. ")"
end
-- try to find a known network which is also visible (ordered by known network definitions)
local connectWith = nil
for _,kn in ipairs(knownSsids) do
if findSsidInList(scanList, kn.ssid) then
connectWith = kn.ssid
break
end
end
if connectWith then
print("connectWith: " .. connectWith) --TEMP
-- TODO: refactor connect stuff into network:connect() function and adapt api_network_associate as well (and others?)
-- TODO: connect with network
-- return true, "autowifi: associated -- client mode with ssid '" .. connectWith .. "'"
elseif netMode ~= 'ap' then
print("shouldBeAp") --TEMP
-- TODO: setup AP (refactor into network like with client connect)
-- return true, "autowifi: configured as access point with ssid '" .. apSsid .. "'"
else
return true, "autowifi: no action - no known networks found, already in access point mode"
end
return nil, "autowifi: uh oh - bad situation in autowifi function"
end
local function init()
@ -57,7 +116,14 @@ end
end
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
setupAutoWifiMode()
log:info("running in autowifi mode")
local rv,msg = setupAutoWifiMode()
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
local response, err = rq:handle()

View File

@ -174,8 +174,8 @@ function M.new(postData, debugEnabled)
self.postArgs = kvTableFromUrlEncodedString(postData)
self.pathArgs = arrayFromPath(os.getenv('PATH_INFO'))
-- override path arguments with command line parameter and allow to emulate GET/POST if debugging is enabled
if debugEnabled and self.requestMethod == 'CMDLINE' then
-- 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
self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then

View File

@ -4,14 +4,14 @@ START=18
LOGGER="logger -s -t autowifi -p 6"
boot() {
$LOGGER "dummy boot"
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
/usr/share/lua/wifibox/script/d3dapi autowifi
}
start() {
$LOGGER "dummy start"
}
#start() {
# $LOGGER "dummy start"
#}
stop() {
$LOGGER "dummy stop"
}
#stop() {
# $LOGGER "dummy stop"
#}

View File

@ -10,7 +10,7 @@
#include <string.h>
#include <unistd.h>
/* these includes are for ioctl() and cfmakeraw() but disabled to avoid conflicts with asm/* includes */
//these includes are for ioctl() and cfmakeraw() but disabled to avoid conflicts with asm/* includes
//#include <sys/ioctl.h>
//#include <termios.h>