tonyp7 / esp32-wifi-manager

Captive Portal for ESP32 that can connect to a saved wireless network or start an access point where you can connect to existing wifis.
MIT License
664 stars 217 forks source link

Forever 4 #36

Closed app-js closed 5 years ago

app-js commented 5 years ago

http_server.c line 169

if ((sizeof(host) > 0) && !strstr(host, DEFAULT_AP_IP)) {

should be

if (host && !strstr(host, DEFAULT_AP_IP)) { or if (lenH > 0 && !strstr(host, DEFAULT_AP_IP)) {

And if Wifi is running in STA mode, then it can't be accessed via the network.

tonyp7 commented 5 years ago

Looks about right, I mark it as bug Thanks for the report

tonyp7 commented 5 years ago

This is fixed in the latest version.

Now you can access the http server in STA mode. This wasn't an easy fix by any mean, this is what the code looks like now:

        /* captive portal functionality: redirect to access point IP for HOST that are not the access point IP OR the STA IP */
        int lenH = 0;
        char *host = http_server_get_header(save_ptr, "Host: ", &lenH);
        /* determine if Host is from the STA IP address */
        wifi_manager_lock_sta_ip_string(portMAX_DELAY);
        bool access_from_sta_ip = lenH > 0?strstr(host, wifi_manager_get_sta_ip_string()):false;
        wifi_manager_unlock_sta_ip_string();

        if (lenH > 0 && !strstr(host, DEFAULT_AP_IP) && !access_from_sta_ip) {