NODEMCU captive portal redirect HTTPS or display on connect?
Posted: Mon May 13, 2019 5:44 pm
I am attempting to set up a captive portal similar to this, however, since the Web is mainly HTTPS now, and I apparently cannot reasonably spoof that, most sites simply are ignored and you get nothing. Since the point of this project is to make the index.html page as 'discoverable' as possible to a casual/curious visitor, how can I make it so a request to a HTTPS site (e.g. http://www.google.com) is met with some form of redirect to my index.html, or that the index.html presents itself upon connect, like a hotel wi-fi?
code portions I've modified, from server.lua:
[...]
[...]
[...]
code portions I've modified, from server.lua:
Code: Select all
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
local rnrn=0
local Status = 0
local DataToGet = 0
local method=""
local url=""
local vars=""
conn:on("receive",function(conn,payload)
if Status==0 then
_, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP")
-- print(method, url, vars)
end
[...]
Code: Select all
conn:send("HTTP/1.1 200 OK\r\n\r\n")
[...]
Code: Select all
local foundmatch = 0
file.open("urls.txt", "r")
print("potato")
for i = 108,1,-1 do
line = file.readline()
--print(line)
if string.match(line, url) then
foundmatch=1
print("found " .. url)
end
end
print("potato2")
file.close()
[...]
Code: Select all
conn:on("sent",function(conn)
print("sending data")
if DataToGet>=0 and method=="GET" then
if file.open(url, "r") then
file.seek("set", DataToGet)
local line=file.read(512)
file.close()
if line then
conn:send(line)
-- print ("sending:" .. DataToGet)
DataToGet = DataToGet + 512
if (string.len(line)==512) then
return
end
end
end
end
conn:close()
end)
end)