Added dns forward to configuration web page.
This commit is contained in:
@@ -1,14 +1,24 @@
|
|||||||
#include "EggDuino.h"
|
#include "EggDuino.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
#include <DNSServer.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const char *kConfigPath = "/config.json";
|
const char *kConfigPath = "/config.json";
|
||||||
const size_t kConfigJsonCapacity = 4096;
|
const size_t kConfigJsonCapacity = 4096;
|
||||||
|
const byte kDnsPort = 53;
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
|
DNSServer dnsServer;
|
||||||
bool configStoreReady = false;
|
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)
|
bool isIntType(const ConfigParameter ¶m)
|
||||||
{
|
{
|
||||||
@@ -253,6 +263,11 @@ async function pollLogs() {
|
|||||||
|
|
||||||
void handleNotFound()
|
void handleNotFound()
|
||||||
{
|
{
|
||||||
|
if (apModeActive)
|
||||||
|
{
|
||||||
|
redirectToRoot();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (server.uri().startsWith("/api/"))
|
if (server.uri().startsWith("/api/"))
|
||||||
{
|
{
|
||||||
server.send(404, "text/plain", "API endpoint not found");
|
server.send(404, "text/plain", "API endpoint not found");
|
||||||
@@ -483,6 +498,8 @@ void startWebInterface()
|
|||||||
{
|
{
|
||||||
initConfigStore();
|
initConfigStore();
|
||||||
bool staConnected = false;
|
bool staConnected = false;
|
||||||
|
apModeActive = false;
|
||||||
|
dnsServer.stop();
|
||||||
|
|
||||||
if (!g_sWifiSsid.isEmpty())
|
if (!g_sWifiSsid.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -510,6 +527,8 @@ void startWebInterface()
|
|||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
if (WiFi.softAP("EggDuino"))
|
if (WiFi.softAP("EggDuino"))
|
||||||
{
|
{
|
||||||
|
apModeActive = true;
|
||||||
|
dnsServer.start(kDnsPort, "*", WiFi.softAPIP());
|
||||||
Serial.println(String("AP aktiv: EggDuino / http://") + WiFi.softAPIP().toString());
|
Serial.println(String("AP aktiv: EggDuino / http://") + WiFi.softAPIP().toString());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -522,11 +541,21 @@ void startWebInterface()
|
|||||||
server.on("/api/config", HTTP_GET, handleGetConfig);
|
server.on("/api/config", HTTP_GET, handleGetConfig);
|
||||||
server.on("/api/config", HTTP_POST, handlePostConfig);
|
server.on("/api/config", HTTP_POST, handlePostConfig);
|
||||||
server.on("/api/logs", HTTP_GET, handleGetLogs);
|
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.onNotFound(handleNotFound);
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleWebInterface()
|
void handleWebInterface()
|
||||||
{
|
{
|
||||||
|
if (apModeActive)
|
||||||
|
{
|
||||||
|
dnsServer.processNextRequest();
|
||||||
|
}
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user