Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug with iOS Captive Portal Not Loading #271

Open
blackpressinc opened this issue Nov 22, 2023 · 8 comments
Open

Fixed a bug with iOS Captive Portal Not Loading #271

blackpressinc opened this issue Nov 22, 2023 · 8 comments

Comments

@blackpressinc
Copy link

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
Copy link
Owner

s00500 commented Nov 22, 2023

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
Copy link

AWSW-de commented Jan 5, 2024

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
Copy link

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

@blackpressinc
Copy link
Author

blackpressinc commented Jan 10, 2024 via email

@AWSW-de
Copy link

AWSW-de commented Jan 10, 2024

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
Copy link

Jaykrishnak commented Jan 10, 2024

how we can implement this in our mac through MDM?

@AWSW-de
Copy link

AWSW-de commented Jan 10, 2024

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
Copy link
Collaborator

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("/");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants