diff --git a/src/README b/src/README index e43124d..11a8b94 100644 --- a/src/README +++ b/src/README @@ -1,17 +1,19 @@ Installation: -- place the autowifi directory in /usr/share/lua +- place the src directory in /usr/share/lua and name it 'autowifi' - create a symlink to ext/wfcf in /www/cgi-bin (make sure the file is executable) -- create a symlink to ext/autowifi.html in /www -- create a symlink to ext/autowifi.css in /www -- create a symlink to ext/autowifi.js in /www -- create a symlink to ext/autowifi_init in /etc/rc.d and name it S19autowifi_init -- enable init script by calling it with 'enable' argument? +- create a symlink to admin in /www +- create a symlink to ext/autowifi_init in /etc/rc.d and name it S18autowifi_init +- (not necessary) enable init script by calling it with 'enable' argument? - make sure radio0 in /etc/config/wireless is not disabled +- the wlan net must also be added to firewall in the lan zone + +== these two items are now handled by the script - create a wlan network in /etc/config/network as follows < $TGT_DIR..." + cp -a $path $TGT_DIR +done + +echo "compressing $TGT_DIR into $BASE_NAME.tar.gz..." +tar czf $BASE_NAME.tar.gz $BASE_NAME + +echo "removing staging dir..." +rm -rf $TGT_DIR + +echo "done." diff --git a/src/misc/old/post b/src/misc/old/post deleted file mode 100755 index f4f9001..0000000 --- a/src/misc/old/post +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -echo "Content-type: text/plain" -echo "" -read QUERY_STRING -eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}') - -#escaped -#echo $txtOutput - -#unescaped -txtOutput=`uhttpd -d $txtOutput` -echo $txtOutput diff --git a/src/misc/old/test b/src/misc/old/test deleted file mode 100755 index 1f9f751..0000000 --- a/src/misc/old/test +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -echo "Content-type: text/plain" -echo "" -echo "Sample CGI Output" -echo "" -echo "" -env -echo "" -echo "" diff --git a/src/misc/old/wifi-list.html b/src/misc/old/wifi-list.html deleted file mode 100644 index 5582d7d..0000000 --- a/src/misc/old/wifi-list.html +++ /dev/null @@ -1,63 +0,0 @@ - - - Doodle3D - - - - - - - - -
- WiFi mode -
- -
- Available networks - - - -
- -
- Known networks -
- - diff --git a/src/misc/old/wifi-scan b/src/misc/old/wifi-scan deleted file mode 100755 index 3ea3a1e..0000000 --- a/src/misc/old/wifi-scan +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -# avoiding "Device or resource busy" error as per https://forum.openwrt.org/viewtopic.php?pid=121485#p121485 -# note that iwinfo takes care of this internally - -echo "Content-type: text/plain" -echo "" - -DEV="${1:-wlan0}" - -ifconfig $DEV down -iw dev $DEV interface add scan.$DEV type station -ifconfig scan.$DEV up - -iwlist scan.$DEV scan | grep ESSID | cut -c 27- | tr -d '"' - -ifconfig scan.$DEV down -iw dev scan.$DEV del -ifconfig $DEV up diff --git a/src/misc/temp b/src/misc/temp deleted file mode 100644 index 646e428..0000000 --- a/src/misc/temp +++ /dev/null @@ -1,33 +0,0 @@ -[[1: { ["encryption"] = - { ["enabled"] = true, - ["auth_algs"] = { } , - ["description"] = mixed WPA/WPA2 PSK (TKIP), - ["wep"] = false, - ["auth_suites"] = - { [1] = PSK,} , - ["wpa"] = 3, - ["pair_ciphers"] = - { [1] = TKIP, - [2] = CCMP, - } , - ["group_ciphers"] = - { [1] = TKIP,} , - } , - ["quality_max"] = 70, - ["ssid"] = happiesnappie2, - ["channel"] = 9, - ["signal"] = -35, - ["bssid"] = 00:22:6B:EF:BB:99, - ["mode"] = Master, - ["quality"] = 70, -} ]] - -config wifi-iface - option network 'lan' - option ssid 'happiesnappie2' - option encryption 'psk2' - option device 'radio0' - option mode 'sta' - option bssid '00:22:6B:EF:BB:99' - option key 'pr4ppal4trappa' - option disabled '1' diff --git a/src/reconf.lua b/src/reconf.lua index 4f18cc7..7669fc0 100644 --- a/src/reconf.lua +++ b/src/reconf.lua @@ -10,6 +10,8 @@ M.WWW_CAPTIVE_PATH = "/usr/share/lua/autowifi/ext/www" M.WWW_CAPTIVE_INDICATOR = "/www/.autowifi-inplace" M.WWW_RENAME_NAME = "/www-regular" + + local function reloadBit(dlist, itemname) if dlist[itemname] == nil then dlist[itemname] = "" end if dlist[itemname] == "" then dlist[itemname] = "r" @@ -24,6 +26,8 @@ local function commitBit(dlist, itemname) end local function bothBits(dlist, itemname) dlist[itemname] = "b" end + + function M.init(wifiInstance, reloadSilent) wifi = wifiInstance silent = reloadSilent or false @@ -82,10 +86,10 @@ function reconf.wireless_reload(dirtyList) reloadBit(dirtyList, "wireless") end --[[ Add wlan interface declaration to /etc/config/network ]] function reconf.wifiiface_add(dirtyList) uci:set("network", wifi.NET, "interface") --- uci:set("network", wifi.NET, "proto", "dhcp") commitBit(dirtyList, "network") end + --[[ Add/remove access point network ]] function reconf.apnet_add_noreload(dirtyList) reconf.apnet_add(dirtyList, true) end function reconf.apnet_add(dirtyList, noReload) @@ -116,6 +120,7 @@ function reconf.apnet_rm(dirtyList) reloadBit(dirtyList, "network"); commitBit(dirtyList, "wireless") end + --[[ Switch between wireless static IP and DHCP ]] function reconf.staticaddr_add(dirtyList) uci:set("network", wifi.NET, "interface") @@ -137,6 +142,7 @@ function reconf.staticaddr_rm(dirtyList) bothBits(dirtyList, "network") end + --[[ Add/remove DHCP pool for wireless net ]] function reconf.dhcppool_add(dirtyList) uci:set("dhcp", wifi.NET, "dhcp") --create section @@ -153,6 +159,7 @@ function reconf.dhcppool_rm(dirtyList) commitBit(dirtyList, "dhcp"); reloadBit(dirtyList, "dnsmasq") end + --[[ Add/remove webserver 404 redirection and denial of dirlisting ]] function reconf.wwwredir_add(dirtyList) uci:set("uhttpd", "main", "error_page", "/admin/autowifi.html") @@ -165,6 +172,7 @@ function reconf.wwwredir_rm(dirtyList) bothBits(dirtyList, "uhttpd") end + --[[ Add/remove redirecton of all DNS requests to self ]] function reconf.dnsredir_add(dirtyList) local redirText = "/#/" .. wifi.AP_ADDRESS @@ -183,21 +191,29 @@ function reconf.dnsredir_rm(dirtyList) commitBit(dirtyList, "dhcp"); reloadBit(dirtyList, "dnsmasq") end + --TODO: handle os.rename() return values (nil+msg on error) function reconf.wwwcaptive_add(dirtyList) if u.exists(M.WWW_CAPTIVE_INDICATOR) then return u:logdebug("WWW captive directory already in place, not redoing", false) end - os.rename("/www", M.WWW_RENAME_NAME) - u.symlink(M.WWW_CAPTIVE_PATH, "/www") - return true + if os.rename("/www", M.WWW_RENAME_NAME) == true then + u.symlink(M.WWW_CAPTIVE_PATH, "/www") + return true + else + return u:logerror("Could not rename /www to " .. M.WWW_RENAME_NAME) + end end function reconf.wwwcaptive_rm(dirtyList) if not u.exists(M.WWW_CAPTIVE_INDICATOR) then return u:logdebug("WWW captive directory not in place, not undoing", false) end os.remove("/www") - return os.rename(M.WWW_RENAME_NAME, "/www") + if os.rename(M.WWW_RENAME_NAME, "/www") ~= true then + return u:logerror("Could not rename " .. M.WWW_RENAME_NAME .. " to /www") + end + return true end + --[[ Setup/remove NAT reflection to redirect all IPs ]] function reconf.natreflect_add(dirtyList) uci:set("firewall", "portalreflect", "redirect"); diff --git a/src/wifihelper.lua b/src/wifihelper.lua index 2d8cc5e..ae19c8b 100644 --- a/src/wifihelper.lua +++ b/src/wifihelper.lua @@ -143,6 +143,14 @@ function M.createConfigFromScanInfo(info, passphrase, disabled) if passphrase ~= nil then apconfig.key = passphrase end apconfig.disabled = disabled ~= nil and disabled and 1 or 0 + uci:foreach("wireless", "wifi-iface", function(s) + if s.bssid == info.bssid then + util:logdebug("removing old wireless config for net '" .. s.ssid .. "(bssid: " .. s.bssid .. ")'") + uci:delete("wireless", s[".name"]) +-- return false --keep looking, just in case multiple entries with this bssid exist + end + end) + local sname = uci:add("wireless", "wifi-iface"); for k, v in pairs(apconfig) do uci:set("wireless", sname, k, v)