Skip to content

Re-enable dns server for AP mode, fixes #81 #256

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

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/configServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <esp_ota_ops.h>
#include <esp_partition.h>
#include <utils/https.h>
#include <DNSServer.h>
#include "SPIFFS.h"
#include "HTTPMultipartBodyParser.hpp"
#include "Firmware.h"
Expand All @@ -53,6 +54,7 @@ static HTTPServer * insecureServer;
static SSLCert * serverSslCert;
static String OBS_ID;
static String OBS_ID_SHORT;
static DNSServer *dnsServer;

// TODO
// - Fix CSS Style for mobile && desktop
Expand Down Expand Up @@ -535,7 +537,7 @@ static void progressTick() {
displayTest->drawWaitBar(5, ticks++);
}

void createHttpServer() {
static void createHttpServer() {
if (!Https::existsCertificate()) {
displayTest->showTextOnGrid(1, 4, "");
displayTest->showTextOnGrid(0, 5, "");
Expand Down Expand Up @@ -636,41 +638,40 @@ String getIp() {
}

bool CreateWifiSoftAP() {
bool SoftAccOK;
bool softAccOK;
WiFi.disconnect();
Serial.print(F("Initalize SoftAP "));
String APName = OBS_ID;
String apName = OBS_ID;
String APPassword = "12345678";
SoftAccOK = WiFi.softAP(APName.c_str(), APPassword.c_str()); // Passwortlänge mindestens 8 Zeichen !
softAccOK = WiFi.softAP(apName.c_str(), APPassword.c_str(), 1, 0, 1); // Passwortlänge mindestens 8 Zeichen !
delay(2000); // Without delay I've seen the IP address blank
/* Soft AP network parameters */
IPAddress apIP(172, 20, 0, 1);
IPAddress netMsk(255, 255, 255, 0);

displayTest->showTextOnGrid(0, 1, "AP:");
displayTest->showTextOnGrid(1, 1, "");
displayTest->showTextOnGrid(0, 2, APName.c_str());
displayTest->showTextOnGrid(0, 2, apName.c_str());


WiFi.softAPConfig(apIP, apIP, netMsk);
if (SoftAccOK) {
/* Setup the DNS server redirecting all the domains to the apIP */
//dnsserver->setErrorReplyCode(DNSReplyCode::NoError);
//dnsserver->start(DNS_PORT, "*", apIP);
if (softAccOK) {
dnsServer = new DNSServer();
// with "*" we get a lot of requests from all sort of apps,
// use obs.local here
dnsServer->start(53, "obs.local", apIP);

Serial.println(F("AP successful."));
log_i("AP successful IP: %s", apIP.toString().c_str());

displayTest->showTextOnGrid(0, 3, "Pass:");
displayTest->showTextOnGrid(1, 3, APPassword);

displayTest->showTextOnGrid(0, 4, "IP:");
displayTest->showTextOnGrid(1, 4, WiFi.softAPIP().toString());
} else {
Serial.println(F("Soft AP Error."));
Serial.println(APName.c_str());
Serial.println(APPassword.c_str());
log_e("Soft AP Error. Name: %s Pass: %s", apName.c_str(), APPassword.c_str());
}
return SoftAccOK;
return softAccOK;
}

void startServer(ObsConfig *obsConfig) {
Expand Down Expand Up @@ -1758,18 +1759,20 @@ static void accessFilter(HTTPRequest * req, HTTPResponse * res, std::function<vo
static void handleHttpsRedirect(HTTPRequest *req, HTTPResponse *res) {
String html = createPage(httpsRedirect);
html = replaceDefault(html, "Https Redirect");
String linkHost(req->getHTTPHeaders()->getValue("linkHost").c_str());
// this could be more hardened?
if (!linkHost || linkHost == "") {
linkHost = getIp();
String host(req->getHeader("host").c_str());
if (!host || host == "") {
host = getIp();
}
html = replaceHtml(html, "{host}", linkHost);
html = replaceHtml(html, "{host}", host);
sendHtml(res, html);
}

void configServerHandle() {
server->loop();
insecureServer->loop();
if (dnsServer) {
dnsServer->processNextRequest();
}
}

std::vector<std::pair<String,String>> extractParameters(HTTPRequest *req) {
Expand Down