|
|
|
@@ -65,6 +65,7 @@ TelemetrySettings *active_settings = nullptr;
|
|
|
|
|
bool restart_after_update = false;
|
|
|
|
|
bool update_failed = false;
|
|
|
|
|
bool access_point_restart_pending = false;
|
|
|
|
|
bool access_point_active = false;
|
|
|
|
|
unsigned long access_point_started_ms = 0UL;
|
|
|
|
|
|
|
|
|
|
String html_escape(const String &value)
|
|
|
|
@@ -78,6 +79,51 @@ String html_escape(const String &value)
|
|
|
|
|
return escaped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_captive_portal_target(const String &host, const String &uri)
|
|
|
|
|
{
|
|
|
|
|
String lowercase_host = host;
|
|
|
|
|
lowercase_host.toLowerCase();
|
|
|
|
|
|
|
|
|
|
String lowercase_uri = uri;
|
|
|
|
|
lowercase_uri.toLowerCase();
|
|
|
|
|
|
|
|
|
|
static const char *captive_hosts[] = {
|
|
|
|
|
"connectivitycheck.gstatic.com",
|
|
|
|
|
"clients3.google.com",
|
|
|
|
|
"google.com",
|
|
|
|
|
"www.google.com",
|
|
|
|
|
"msftconnecttest.com",
|
|
|
|
|
"msftncsi.com",
|
|
|
|
|
"captive.apple.com",
|
|
|
|
|
"www.apple.com",
|
|
|
|
|
"apple.com",
|
|
|
|
|
"connectivitycheck.android.com"};
|
|
|
|
|
|
|
|
|
|
for (const char *candidate : captive_hosts)
|
|
|
|
|
{
|
|
|
|
|
if (lowercase_host == candidate)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *captive_paths[] = {
|
|
|
|
|
"/generate_204",
|
|
|
|
|
"/hotspot-detect.html",
|
|
|
|
|
"/library/test/success.html",
|
|
|
|
|
"/connecttest.txt",
|
|
|
|
|
"/redirect",
|
|
|
|
|
"/ncsi.txt",
|
|
|
|
|
"/success.txt",
|
|
|
|
|
"/wap"};
|
|
|
|
|
|
|
|
|
|
for (const char *candidate : captive_paths)
|
|
|
|
|
{
|
|
|
|
|
if (lowercase_uri == candidate)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void redirect_to_root(const String &message, bool success)
|
|
|
|
|
{
|
|
|
|
|
String location = String("/?status=") + (success ? "success" : "error") + "&msg=" + url_encode(message);
|
|
|
|
@@ -85,6 +131,21 @@ void redirect_to_root(const String &message, bool success)
|
|
|
|
|
server.send(303, "text/plain; charset=utf-8", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_captive_portal_redirect()
|
|
|
|
|
{
|
|
|
|
|
String host = server.hostHeader();
|
|
|
|
|
String uri = server.uri();
|
|
|
|
|
|
|
|
|
|
if (is_captive_portal_target(host, uri))
|
|
|
|
|
{
|
|
|
|
|
server.sendHeader("Location", "/", true);
|
|
|
|
|
server.send(302, "text/plain; charset=utf-8", "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server.send(404, "text/plain; charset=utf-8", "Not Found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void send_page(const String &message = String())
|
|
|
|
|
{
|
|
|
|
|
String page;
|
|
|
|
@@ -174,6 +235,9 @@ void handle_settings()
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool ap_name_changed = active_settings->access_point_name != updated.access_point_name;
|
|
|
|
|
const bool ap_password_changed = active_settings->access_point_password != updated.access_point_password;
|
|
|
|
|
|
|
|
|
|
active_settings->callsign = updated.callsign;
|
|
|
|
|
active_settings->access_point_name = updated.access_point_name;
|
|
|
|
|
active_settings->access_point_password = updated.access_point_password;
|
|
|
|
@@ -186,7 +250,10 @@ void handle_settings()
|
|
|
|
|
preferences.putInt("min", active_settings->min_speed);
|
|
|
|
|
preferences.putInt("max", active_settings->max_speed);
|
|
|
|
|
preferences.putUInt("active_time", active_settings->active_time_seconds);
|
|
|
|
|
access_point_restart_pending = true;
|
|
|
|
|
|
|
|
|
|
if (ap_name_changed || ap_password_changed)
|
|
|
|
|
access_point_restart_pending = true;
|
|
|
|
|
|
|
|
|
|
redirect_to_root("Einstellungen gespeichert.", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -282,11 +349,24 @@ bool webinterface_begin(TelemetrySettings &settings)
|
|
|
|
|
if (!ap_started)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
access_point_active = true;
|
|
|
|
|
access_point_started_ms = millis();
|
|
|
|
|
dns_server.start(53, "connectivitycheck.gstatic.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "clients3.google.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "msftconnecttest.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "msftncsi.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "captive.apple.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "apple.com", WiFi.softAPIP());
|
|
|
|
|
dns_server.start(53, "*", WiFi.softAPIP());
|
|
|
|
|
server.on("/", HTTP_GET, handle_root);
|
|
|
|
|
server.on("/generate_204", HTTP_GET, handle_captive_portal_redirect);
|
|
|
|
|
server.on("/hotspot-detect.html", HTTP_GET, handle_captive_portal_redirect);
|
|
|
|
|
server.on("/connecttest.txt", HTTP_GET, handle_captive_portal_redirect);
|
|
|
|
|
server.on("/ncsi.txt", HTTP_GET, handle_captive_portal_redirect);
|
|
|
|
|
server.on("/success.txt", HTTP_GET, handle_captive_portal_redirect);
|
|
|
|
|
server.on("/settings", HTTP_POST, handle_settings);
|
|
|
|
|
server.on("/update", HTTP_POST, handle_update_result, handle_update_upload);
|
|
|
|
|
server.onNotFound(handle_captive_portal_redirect);
|
|
|
|
|
server.begin();
|
|
|
|
|
Serial.print("Firmware-Version: ");
|
|
|
|
|
Serial.println(firmware_version_string());
|
|
|
|
@@ -303,16 +383,20 @@ void webinterface_handle(void)
|
|
|
|
|
{
|
|
|
|
|
access_point_restart_pending = false;
|
|
|
|
|
WiFi.softAPdisconnect(true);
|
|
|
|
|
access_point_active = false;
|
|
|
|
|
delay(100);
|
|
|
|
|
if (!WiFi.softAP(active_settings->access_point_name, active_settings->access_point_password))
|
|
|
|
|
Serial.println("Access Point konnte nicht neu gestartet werden");
|
|
|
|
|
else
|
|
|
|
|
access_point_active = true;
|
|
|
|
|
access_point_started_ms = millis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (WiFi.softAPgetStationNum() == 0 && (millis() - access_point_started_ms) >= access_point_timeout_ms)
|
|
|
|
|
if (access_point_active && WiFi.softAPgetStationNum() == 0 && (millis() - access_point_started_ms) >= access_point_timeout_ms)
|
|
|
|
|
{
|
|
|
|
|
Serial.println("Access Point nach 5 Minuten ohne Client deaktiviert");
|
|
|
|
|
WiFi.softAPdisconnect(true);
|
|
|
|
|
access_point_active = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|