From f862672a81187bddee7f38e0ae8f84c648b309d3 Mon Sep 17 00:00:00 2001 From: Holger Weber Date: Sun, 22 Feb 2026 23:01:38 +0100 Subject: [PATCH] Added dns forward to configuration web page. --- src/Config_Web.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Config_Web.cpp b/src/Config_Web.cpp index dc8e4dd..9ca5651 100644 --- a/src/Config_Web.cpp +++ b/src/Config_Web.cpp @@ -1,14 +1,24 @@ #include "EggDuino.h" #include +#include #include namespace { const char *kConfigPath = "/config.json"; const size_t kConfigJsonCapacity = 4096; + const byte kDnsPort = 53; WebServer server(80); + DNSServer dnsServer; bool configStoreReady = false; + bool apModeActive = false; + + void redirectToRoot() + { + server.sendHeader("Location", String("http://") + WiFi.softAPIP().toString() + "/", true); + server.send(302, "text/plain", ""); + } bool isIntType(const ConfigParameter ¶m) { @@ -253,6 +263,11 @@ async function pollLogs() { void handleNotFound() { + if (apModeActive) + { + redirectToRoot(); + return; + } if (server.uri().startsWith("/api/")) { server.send(404, "text/plain", "API endpoint not found"); @@ -483,6 +498,8 @@ void startWebInterface() { initConfigStore(); bool staConnected = false; + apModeActive = false; + dnsServer.stop(); if (!g_sWifiSsid.isEmpty()) { @@ -510,6 +527,8 @@ void startWebInterface() WiFi.mode(WIFI_AP); if (WiFi.softAP("EggDuino")) { + apModeActive = true; + dnsServer.start(kDnsPort, "*", WiFi.softAPIP()); Serial.println(String("AP aktiv: EggDuino / http://") + WiFi.softAPIP().toString()); } else @@ -522,11 +541,21 @@ void startWebInterface() server.on("/api/config", HTTP_GET, handleGetConfig); server.on("/api/config", HTTP_POST, handlePostConfig); server.on("/api/logs", HTTP_GET, handleGetLogs); + server.on("/generate_204", HTTP_GET, redirectToRoot); + server.on("/gen_204", HTTP_GET, redirectToRoot); + server.on("/hotspot-detect.html", HTTP_GET, redirectToRoot); + server.on("/connecttest.txt", HTTP_GET, redirectToRoot); + server.on("/ncsi.txt", HTTP_GET, redirectToRoot); + server.on("/fwlink", HTTP_GET, redirectToRoot); server.onNotFound(handleNotFound); server.begin(); } void handleWebInterface() { + if (apModeActive) + { + dnsServer.processNextRequest(); + } server.handleClient(); }