mirror of https://github.com/aredn/aredn.git
Compare commits
2 Commits
dae38b1611
...
d8c29d60e9
Author | SHA1 | Date |
---|---|---|
Tim Wilkinson | d8c29d60e9 | |
Tim Wilkinson | c77a63eca3 |
|
@ -35,6 +35,7 @@
|
|||
|
||||
--]]
|
||||
|
||||
require("nixio")
|
||||
require("aredn.http")
|
||||
require("aredn.hardware")
|
||||
require("aredn.utils")
|
||||
|
@ -47,9 +48,11 @@ if not node then
|
|||
end
|
||||
local wifiiface = aredn.hardware.get_iface_name("wifi")
|
||||
local nf = iwinfo.nl80211.noise(wifiiface) or -95
|
||||
local myfreq = tonumber(aredn_info.getFreq(aredn_info.getMeshRadioDevice()))
|
||||
|
||||
if not nixio.fs.stat("/tmp/web") then
|
||||
nixio.fs.mkdir("/tmp/web")
|
||||
local board_type = aredn.hardware.get_board_type()
|
||||
if board_type:match("^ubnt,") and board_type:match("ac") then
|
||||
ubnt_ac = true
|
||||
end
|
||||
|
||||
local channels = aredn.hardware.get_rfchannels(wifiiface)
|
||||
|
@ -62,6 +65,57 @@ end
|
|||
-- scan start
|
||||
|
||||
local scanned = {}
|
||||
|
||||
local f = io.popen("iw dev " .. wifiiface .. " station dump")
|
||||
if f then
|
||||
local scan = {}
|
||||
local myssid = aredn_info.getSSID()
|
||||
for line in f:lines()
|
||||
do
|
||||
local m = line:match("^Station ([%da-fA-F:]+) %(on " .. wifiiface .. "%)")
|
||||
if m then
|
||||
scan = scanned[m]
|
||||
if not scan then
|
||||
scan = {
|
||||
mac = m,
|
||||
signal = 9999,
|
||||
freq = {},
|
||||
key = "",
|
||||
joined = false
|
||||
}
|
||||
scanned[m] = scan
|
||||
end
|
||||
scan.mode = "Connected Ad-Hoc Station"
|
||||
scan.ssid = myssid
|
||||
scan.freq[myfreq] = true
|
||||
end
|
||||
m = line:match("signal avg:%s+([%d%-]+)")
|
||||
if m then
|
||||
scan.signal = tonumber(m)
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- Ubiquiti AC device workaround
|
||||
if ubnt_ac then
|
||||
os.execute("iw dev " .. wifiiface .. " ibss leave > /dev/null 2>&1")
|
||||
os.execute("wifi up > /dev/null 2>&1")
|
||||
local attempt = 10
|
||||
while attempt > 0
|
||||
do
|
||||
attempt = attempt - 1
|
||||
for line in io.popen("iw dev " .. wifiiface .. " scan"):lines()
|
||||
do
|
||||
if line:match("^BSS ") then
|
||||
attempt = 0
|
||||
end
|
||||
break
|
||||
end
|
||||
nixio.nanosleep(2, 0)
|
||||
end
|
||||
end
|
||||
|
||||
local f = io.popen("iw dev " .. wifiiface .. " scan freq" .. scan_list .. " passive")
|
||||
if f then
|
||||
local scan = {}
|
||||
|
@ -75,7 +129,7 @@ if f then
|
|||
mac = m,
|
||||
mode = "AP",
|
||||
ssid = "",
|
||||
signal = 0,
|
||||
signal = 9999,
|
||||
freq = {},
|
||||
key = "",
|
||||
joined = false
|
||||
|
@ -94,6 +148,10 @@ if f then
|
|||
m = line:match("freq: (%d+)")
|
||||
if m then
|
||||
scan.freq[m] = true
|
||||
if tonumber(m) == myfreq and scan.mode == "AP" then
|
||||
scan.mode = "My Ad-Hoc Network"
|
||||
scan.joined = true
|
||||
end
|
||||
end
|
||||
m = line:match("SSID: (.+)")
|
||||
if m then
|
||||
|
@ -114,65 +172,14 @@ if f then
|
|||
f:close()
|
||||
end
|
||||
|
||||
local f = io.popen("iw dev " .. wifiiface .. " station dump")
|
||||
if f then
|
||||
local scan = {}
|
||||
local myssid = aredn_info.getSSID()
|
||||
local myfreq = tonumber(aredn_info.getFreq(aredn_info.getMeshRadioDevice()))
|
||||
for line in f:lines()
|
||||
do
|
||||
local m = line:match("^Station ([%da-fA-F:]+) %(on " .. wifiiface .. "%)")
|
||||
if m then
|
||||
scan = scanned[m]
|
||||
if not scan then
|
||||
scan = {
|
||||
mac = m,
|
||||
signal = 0,
|
||||
freq = {},
|
||||
key = "",
|
||||
joined = false
|
||||
}
|
||||
scanned[m] = scan
|
||||
end
|
||||
scan.mode = "Connected Ad-Hoc Station"
|
||||
scan.ssid = myssid
|
||||
scan.freq[myfreq] = true
|
||||
end
|
||||
m = line:match("signal avg:%s+([%d%-]+)")
|
||||
if m then
|
||||
scan.signal = tonumber(m)
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- scan end
|
||||
|
||||
if os.getenv("REQUEST_METHOD") == "POST" then
|
||||
require('luci.http')
|
||||
local request = luci.http.Request(nixio.getenv(),
|
||||
function()
|
||||
local v = io.read(1024)
|
||||
if not v then
|
||||
io.close()
|
||||
end
|
||||
return v
|
||||
end
|
||||
)
|
||||
if request:formvalue("auto") then
|
||||
io.open("/tmp/web/autoscan", "w"):close()
|
||||
end
|
||||
if request:formvalue("stop") then
|
||||
os.remove("/tmp/web/autoscan")
|
||||
end
|
||||
end
|
||||
|
||||
-- generate page
|
||||
http_header()
|
||||
html.header(node .. " WiFi scan", false)
|
||||
local autoscan = nixio.fs.stat("/tmp/web/autoscan");
|
||||
local autoscan = string.find((nixio.getenv("QUERY_STRING") or ""):lower(),"autoscan=1")
|
||||
if autoscan then
|
||||
html.print("<meta http-equiv='refresh' content='5;url=/cgi-bin/scan'>")
|
||||
html.print("<script>setTimeout(function(){ window.location.reload(); }, 10000);</script>")
|
||||
end
|
||||
html.print([[
|
||||
<script src="/js/sorttable-min.js"></script>
|
||||
|
@ -196,11 +203,11 @@ html.alert_banner()
|
|||
html.print("<h1>" .. node .. " WiFi scan</h1><hr>")
|
||||
|
||||
if autoscan then
|
||||
html.print("<input type=submit name=stop value=Stop title='Abort continuous scan'>")
|
||||
html.print("<input type=button name=stop value=Stop title='Abort continuous scan' onclick='window.location = window.location.origin + window.location.pathname'>")
|
||||
else
|
||||
html.print("<input type=button name=refresh value=Refresh title='Refresh this page' onclick='window.location.reload();'>")
|
||||
html.print(" ")
|
||||
html.print("<input type=submit name=auto value=Auto title='Begin continuous scan'>")
|
||||
html.print([[<input type=button name=auto value=Auto title='Begin continuous scan' onclick='window.location = window.location.origin + window.location.pathname + "?autoscan=1"'>]])
|
||||
end
|
||||
|
||||
html.print(" ")
|
||||
|
@ -219,7 +226,7 @@ end)
|
|||
local scanlist = {}
|
||||
for _, v in pairs(scanned)
|
||||
do
|
||||
if v.signal ~= 0 or v.joined then
|
||||
if v.signal ~= 9999 or v.joined then
|
||||
scanlist[#scanlist + 1] = v
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue