Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mac, cnt = string.gsub(wifi.ap.getmac(), "-", "")
- cfg={}
- cfg.ssid="LEDS:" .. mac
- cfg.pwd="shinylights"
- wifi.setmode(wifi.STATIONAP)
- wifi.ap.config(cfg)
- -- A simple http server
- srv=net.createServer(net.TCP)
- srv:listen(80,function(conn)
- conn:on("receive",function(client,payload)
- local sent = false
- local req = dofile("http.lua").parse(payload)
- if req["method"] == "GET" then
- if req["uri"] == "/" then
- dofile("index.lua").index(client)
- sent = true
- end
- end
- if sent == false then
- client:send("HTTP/1.1 400 Bad Request\r\n\r\n")
- end
- end)
- conn:on("sent",function(client) client:close() end)
- end)
- -- index.lua
- local moduleName = ...
- local M = {}
- function M.index(client)
- wifi.sta.getap(function(t)
- file.open("index", "r")
- s = file.read(100)
- while s ~= nil do
- client:send(s)
- s = file.read(100)
- end
- file.close()
- for ssid, v in pairs(t) do
- authmode, rssi, bssid, channel = string.match(v, "(%d),(-?%d+),(%x%x:%x%x:%x%x:%x%x:%x%x:%x%x),(%d+)")
- sssid = string.gsub(ssid, "\"", """)
- client:send("<div class=\"a")
- client:send(authmode)
- client:send("\"><label><input type=\"radio\" name=\"ssid\" value=\"")
- client:send(sssid .. "\">" .. ssid .. " (" .. rssi)
- client:send(")</label></div>")
- end
- client:send("<input type=\"password\" name=\"password\" placeholder=\"Password\">")
- client:send("<input type=\"submit\" value=\"Save\">")
- client:send("<span class=\"a0\">No security</span>")
- client:send("<span class=\"a1\">WEP</span>")
- client:send("<span class=\"a2\">WPA1-PSK</span>")
- client:send("<span class=\"a3\">WPA1/WPA2-PSK</span>")
- client:send("<span class=\"a4\">WPA2-PSK</span></form></body></html>")
- collectgarbage()
- end)
- end
- return M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement