s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266
https://valencia.lbsfilm.at/midterm-presentation/
Other
889 stars 166 forks source link

Fixed a bug with iOS Captive Portal Not Loading #271

Open blackpressinc opened 9 months ago

blackpressinc commented 9 months ago

Sorry, I'm very new to github and I don't know how to do pull/push(?) requests. I was working on a project where I needed a captive portal to pop up in android and ios. By default the ESPUI does not pop up in iOS (Tested on my iphone 14). I fixed this by changing lines 1493 in ESPUI.ccp. iOS expects some content or else it wont follow the captive portal request. I just added a simple script to pop up a link followed by a redirect to the default ESPUI

server->onNotFound([this](AsyncWebServerRequest* request) {
    if (captivePortal)
    {
        AsyncResponseStream *response = request->beginResponseStream("text/html");
        response->print("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
        response->printf("<p>If site does not re-direct click here <a href='http://%s'>this link</a></p>", WiFi.softAPIP().toString().c_str());
        response->print("</body></html>");
        response->print("<head>");
        response->printf("<meta http-equiv=\"Refresh\" content=\"0; URL='http://%s'\" />", WiFi.softAPIP().toString().c_str());
        response->print("</head>");
        request->send(response);
        request->redirect("/");
    }
    else
    {
        request->send(404);
    }
});
s00500 commented 9 months ago

Hey, that is a cool input. Please make a fork of the project, then make the change on your fork and finally open a Pull Request on github.

AWSW-de commented 7 months ago

Hello, this is defenatelly a good bug fix which solved the problem for iOS and macOS for me too. On Windows 10/11 it is still not showing the correct page, but this seems to be related to the Windows OS...

Thanks in advance for adding this to the general function. =)

Jaykrishnak commented 7 months ago

Hi AWSW-de, I have a similar challenge in Mac that captive portal not loading. could u please help me with that

blackpressinc commented 7 months ago

Hello all. I'd love to help but my time is super limited. Working two jobs and taking care of a disabled partner. While looking for a problem related to Samsung phones not seeing the captive portal I've basically found that every is and many manufacturers have their own protocols for handling captive portals.

iOS needs to see some valid content or else it won't process the request. I fixed this by what I posted before. Most androids just work but Samsung requires custom DNS stuff.

https://github.com/tonyp7/esp32-wifi-manager/issues/57

I don't own a Mac but I would bet it also has a quirk or some specific thing it's looking for. I would try searching for any known issues and then tinker with the code in the same place I did. Soon I'll get GitHub setup and try pushing(?) some connection updates I have made to ESPUI.

On Wed, Jan 10, 2024, 6:09 AM Jaykrishna Kumar @.***> wrote:

Hi AWSW-de, I have a similar challenge in Mac that captive portal not loading. could u please help me with that

— Reply to this email directly, view it on GitHub https://github.com/s00500/ESPUI/issues/271#issuecomment-1884641917, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDSB7QE6CY42LBMLVNJFMDYNZZFRAVCNFSM6AAAAAA7VRO6FCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBUGY2DCOJRG4 . You are receiving this because you authored the thread.Message ID: @.***>

AWSW-de commented 7 months ago

Hi AWSW-de, I have a similar challenge in Mac that captive portal not loading. could u please help me with that

Hi, I just changed the lines 1493 in ESPUI.ccp like named in the 1st post from blackpressinc.

In my “void OfflinePotalSetup()“ in here https://github.com/AWSW-de/WordClock-16x16-LED-matrix-2023/blob/main/Code/Code.ino#L4298 You will find a working captive portal function.

@blackpressinc: If you like I can try to create the pull request for the change if you don’t find the time.

Hope to help.

Kind regards AWSW

Jaykrishnak commented 7 months ago

how we can implement this in our mac through MDM?

AWSW-de commented 7 months ago

how we can implement this in our mac through MDM?

Such captive portal actions are part of every modern operating system/browser.

They just try a bunch of known pages / URLs to see if this is a captive portal WiFi. The challenge seems to be that there is no full list of different URLs to react on - or let’s say I could not find one even with a long period of searching…

How it works (with this patch) with ESPUI is shown here: https://youtu.be/-pJWRE3K3IY?si=d-3nyKEezCBAAnmj&t=115

MartinMueller2003 commented 7 months ago

Not sure how you are making your changes. ESPUI.cpp is only 1452 lines long.

I would propose this as an alternative coding that uses less ram at runtime.

        AsyncResponseStream *response = request->beginResponseStream("text/html");
        String responseText;
        responseText.reserve(1024);
        responseText += F("<!DOCTYPE html><html><head><title>Captive Portal</title></head><body>");
        responseText += ("<p>If site does not re-direct click here <a href='http://" +  WiFi.softAPIP().toString() + "'>this link</a></p>");
        responseText += ("</body></html><head><meta http-equiv=\"Refresh\" content=\"0; URL='http://" +  WiFi.softAPIP().toString() + "'\" /></head>");
        response->write(responseText.c_str(), responseText.length());
        request->send(response);
        request->redirect("/");