Advertisement
Guest User

Untitled

a guest
May 25th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. mac, cnt = string.gsub(wifi.ap.getmac(), "-", "")
  2. cfg={}
  3. cfg.ssid="LEDS:" .. mac
  4. cfg.pwd="shinylights"
  5. wifi.setmode(wifi.STATIONAP)
  6. wifi.ap.config(cfg)
  7.  
  8. -- A simple http server
  9. srv=net.createServer(net.TCP)
  10. srv:listen(80,function(conn)
  11.     conn:on("receive",function(client,payload)
  12.         local sent = false
  13.         local req = dofile("http.lua").parse(payload)
  14.         if req["method"] == "GET" then
  15.             if req["uri"] == "/" then
  16.                 dofile("index.lua").index(client)
  17.                 sent = true
  18.             end
  19.         end
  20.         if sent == false then
  21.             client:send("HTTP/1.1 400 Bad Request\r\n\r\n")
  22.         end
  23.     end)
  24.     conn:on("sent",function(client) client:close() end)
  25. end)
  26.  
  27.  
  28.  
  29. -- index.lua
  30. local moduleName = ...
  31. local M = {}
  32.  
  33. function M.index(client)
  34.     wifi.sta.getap(function(t)
  35.         file.open("index", "r")
  36.         s = file.read(100)
  37.         while s ~= nil do
  38.             client:send(s)
  39.             s = file.read(100)
  40.         end
  41.         file.close()
  42.         for ssid, v in pairs(t) do
  43.             authmode, rssi, bssid, channel = string.match(v, "(%d),(-?%d+),(%x%x:%x%x:%x%x:%x%x:%x%x:%x%x),(%d+)")
  44.             sssid = string.gsub(ssid, "\"", """)
  45.             client:send("<div class=\"a")
  46.             client:send(authmode)
  47.             client:send("\"><label><input type=\"radio\" name=\"ssid\" value=\"")
  48.             client:send(sssid .. "\">" .. ssid .. " (" .. rssi)
  49.             client:send(")</label></div>")
  50.         end
  51.         client:send("<input type=\"password\" name=\"password\" placeholder=\"Password\">")
  52.         client:send("<input type=\"submit\" value=\"Save\">")
  53.         client:send("<span class=\"a0\">No security</span>")
  54.         client:send("<span class=\"a1\">WEP</span>")
  55.         client:send("<span class=\"a2\">WPA1-PSK</span>")
  56.         client:send("<span class=\"a3\">WPA1/WPA2-PSK</span>")
  57.         client:send("<span class=\"a4\">WPA2-PSK</span></form></body></html>")
  58.         collectgarbage()
  59.     end)
  60. end
  61.  
  62. return M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement