-->
Page 1 of 1

NODEMCU captive portal redirect HTTPS or display on connect?

PostPosted: Mon May 13, 2019 5:44 pm
by Nevets01
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: Select allsrv=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 alllocal 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) 

Re: NODEMCU captive portal redirect HTTPS or display on conn

PostPosted: Wed May 15, 2019 6:15 pm
by mel
hi, I think I have built something like this, well there are two parts to my build but one half might help you, my project opens a page on your phone after connecting to the esp8266 open wifi, but I program in Arduino IDE, anyway you can have a look if you like, its at http://www.merrittsoft.com its called Wifi Joke

Regards,
Melissa.