2020-03-25 09:00:55 +01:00
|
|
|
#include "wled.h"
|
2020-03-25 09:36:55 +01:00
|
|
|
|
2020-03-31 02:38:08 +02:00
|
|
|
/*
|
|
|
|
* Integrated HTTP web server page declarations
|
|
|
|
*/
|
2018-09-30 20:24:57 +02:00
|
|
|
|
2019-09-05 22:45:59 +02:00
|
|
|
//Is this an IP?
|
|
|
|
bool isIp(String str) {
|
|
|
|
for (size_t i = 0; i < str.length(); i++) {
|
|
|
|
int c = str.charAt(i);
|
|
|
|
if (c != '.' && (c < '0' || c > '9')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool captivePortal(AsyncWebServerRequest *request)
|
|
|
|
{
|
2019-09-12 12:40:06 +02:00
|
|
|
if (ON_STA_FILTER(request)) return false; //only serve captive in AP mode
|
2019-09-05 22:45:59 +02:00
|
|
|
String hostH;
|
|
|
|
if (!request->hasHeader("Host")) return false;
|
|
|
|
hostH = request->getHeader("Host")->value();
|
|
|
|
|
|
|
|
if (!isIp(hostH) && hostH.indexOf("wled.me") < 0 && hostH.indexOf(cmDNS) < 0) {
|
|
|
|
DEBUG_PRINTLN("Captive portal");
|
|
|
|
AsyncWebServerResponse *response = request->beginResponse(302);
|
2020-09-20 01:18:31 +02:00
|
|
|
response->addHeader(F("Location"), F("http://4.3.2.1"));
|
2019-09-05 22:45:59 +02:00
|
|
|
request->send(response);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-30 20:24:57 +02:00
|
|
|
void initServer()
|
|
|
|
{
|
2019-02-14 17:25:41 +01:00
|
|
|
//CORS compatiblity
|
2020-09-20 01:18:31 +02:00
|
|
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Origin"), "*");
|
|
|
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Methods"), "*");
|
|
|
|
DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Headers"), "*");
|
2019-11-30 19:17:25 +01:00
|
|
|
|
|
|
|
server.on("/liveview", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
request->send_P(200, "text/html", PAGE_liveview);
|
|
|
|
});
|
2019-02-14 17:25:41 +01:00
|
|
|
|
2018-09-30 20:24:57 +02:00
|
|
|
//settings page
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/settings", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
serveSettings(request);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-03-16 02:09:37 +01:00
|
|
|
if(!handleFileRead(request, "/favicon.ico"))
|
2018-09-30 20:24:57 +02:00
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
request->send_P(200, "image/x-icon", favicon, 156);
|
2018-09-30 20:24:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/sliders", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
serveIndex(request);
|
|
|
|
});
|
2018-09-30 20:24:57 +02:00
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/welcome", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
serveSettings(request);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-09-20 01:18:31 +02:00
|
|
|
serveMessage(request, 200,F("Rebooting now..."),F("Please wait ~10 seconds..."),129);
|
2019-02-17 17:11:10 +01:00
|
|
|
doReboot = true;
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
server.on("/settings", HTTP_POST, [](AsyncWebServerRequest *request){
|
|
|
|
serveSettings(request, true);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
2019-02-10 23:05:06 +01:00
|
|
|
|
2019-03-06 01:20:38 +01:00
|
|
|
server.on("/json", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
serveJson(request);
|
|
|
|
});
|
2019-02-20 23:44:34 +01:00
|
|
|
|
2019-12-18 00:41:45 +01:00
|
|
|
AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/json", [](AsyncWebServerRequest *request) {
|
|
|
|
bool verboseResponse = false;
|
2019-12-21 03:17:54 +01:00
|
|
|
{ //scope JsonDocument so it releases its buffer
|
2020-09-20 01:18:31 +02:00
|
|
|
DynamicJsonDocument jsonBuffer(JSON_BUFFER_SIZE);
|
2019-12-18 00:41:45 +01:00
|
|
|
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject));
|
|
|
|
JsonObject root = jsonBuffer.as<JsonObject>();
|
|
|
|
if (error || root.isNull()) {
|
2020-09-20 01:18:31 +02:00
|
|
|
request->send(400, "application/json", F("{\"error\":9}")); return;
|
2019-12-18 00:41:45 +01:00
|
|
|
}
|
|
|
|
verboseResponse = deserializeState(root);
|
|
|
|
}
|
|
|
|
if (verboseResponse) { //if JSON contains "v"
|
|
|
|
serveJson(request); return;
|
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
request->send(200, "application/json", F("{\"success\":true}"));
|
2019-03-06 01:20:38 +01:00
|
|
|
});
|
|
|
|
server.addHandler(handler);
|
2019-02-21 16:32:15 +01:00
|
|
|
|
|
|
|
//*******DEPRECATED*******
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-02-14 17:25:41 +01:00
|
|
|
request->send(200, "text/plain", (String)VERSION);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/uptime", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-02-14 17:25:41 +01:00
|
|
|
request->send(200, "text/plain", (String)millis());
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/freeheap", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-02-14 17:25:41 +01:00
|
|
|
request->send(200, "text/plain", (String)ESP.getFreeHeap());
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
2019-02-21 16:32:15 +01:00
|
|
|
//*******END*******/
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/u", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
request->send_P(200, "text/html", PAGE_usermod);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
2020-02-24 12:18:30 +01:00
|
|
|
server.on("/url", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
URL_response(request);
|
|
|
|
});
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/teapot", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 418, F("418. I'm a teapot."), F("(Tangible Embedded Advanced Project Of Twinkling)"), 254);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
//if OTA is allowed
|
|
|
|
if (!otaLock){
|
2019-03-16 02:09:37 +01:00
|
|
|
#if !defined WLED_DISABLE_FILESYSTEM && defined WLED_ENABLE_FS_EDITOR
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
server.addHandler(new SPIFFSEditor(SPIFFS));//http_username,http_password));
|
|
|
|
#else
|
|
|
|
server.addHandler(new SPIFFSEditor());//http_username,http_password));
|
|
|
|
#endif
|
|
|
|
#else
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/edit", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 501, "Not implemented", F("The SPIFFS editor is disabled in this build."), 254);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
#endif
|
|
|
|
//init ota page
|
2018-11-01 15:36:13 +01:00
|
|
|
#ifndef WLED_DISABLE_OTA
|
2019-02-17 17:11:10 +01:00
|
|
|
server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-12-02 12:41:35 +01:00
|
|
|
request->send_P(200, "text/html", PAGE_update);
|
2019-02-17 17:11:10 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
server.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
|
|
|
|
if (Update.hasError())
|
|
|
|
{
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 500, F("Failed updating firmware!"), F("Please check your file and retry!"), 254); return;
|
2019-02-17 17:11:10 +01:00
|
|
|
}
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 200, F("Successfully updated firmware!"), F("Please wait while the module reboots..."), 131);
|
2019-02-17 17:11:10 +01:00
|
|
|
doReboot = true;
|
|
|
|
},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
|
|
|
|
if(!index){
|
2020-09-20 01:18:31 +02:00
|
|
|
DEBUG_PRINTLN(F("OTA Update Start"));
|
2019-11-12 19:33:34 +01:00
|
|
|
#ifdef ESP8266
|
2019-02-17 17:11:10 +01:00
|
|
|
Update.runAsync(true);
|
|
|
|
#endif
|
|
|
|
Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
|
|
|
|
}
|
|
|
|
if(!Update.hasError()) Update.write(data, len);
|
|
|
|
if(final){
|
|
|
|
if(Update.end(true)){
|
2020-09-20 01:18:31 +02:00
|
|
|
DEBUG_PRINTLN(F("Update Success"));
|
2019-02-17 17:11:10 +01:00
|
|
|
} else {
|
2020-09-20 01:18:31 +02:00
|
|
|
DEBUG_PRINTLN(F("Update Failed"));
|
2019-02-17 17:11:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-01 15:36:13 +01:00
|
|
|
#else
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 501, "Not implemented", F("OTA updates are disabled in this build."), 254);
|
2018-11-01 15:36:13 +01:00
|
|
|
});
|
|
|
|
#endif
|
2018-09-30 20:24:57 +02:00
|
|
|
} else
|
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/edit", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-06-26 17:28:35 +02:00
|
|
|
serveMessage(request, 500, "Access Denied", F("Please unlock OTA in security settings!"), 254);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-06-26 17:28:35 +02:00
|
|
|
serveMessage(request, 500, "Access Denied", F("Please unlock OTA in security settings!"), 254);
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-23 22:24:51 +01:00
|
|
|
|
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
server.on("/dmxmap", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
request->send_P(200, "text/html", PAGE_dmxmap , dmxProcessor);
|
|
|
|
});
|
|
|
|
#else
|
|
|
|
server.on("/dmxmap", HTTP_GET, [](AsyncWebServerRequest *request){
|
2020-02-25 02:19:12 +01:00
|
|
|
serveMessage(request, 501, "Not implemented", F("DMX support is not enabled in this build."), 254);
|
2020-02-23 22:24:51 +01:00
|
|
|
});
|
|
|
|
#endif
|
2019-02-16 00:21:22 +01:00
|
|
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
2019-09-05 22:45:59 +02:00
|
|
|
if (captivePortal(request)) return;
|
2019-02-16 00:21:22 +01:00
|
|
|
serveIndexOrWelcome(request);
|
|
|
|
});
|
2020-06-26 17:28:35 +02:00
|
|
|
|
|
|
|
#ifdef WLED_ENABLE_WEBSOCKETS
|
|
|
|
server.addHandler(&ws);
|
|
|
|
#endif
|
2018-09-30 20:24:57 +02:00
|
|
|
|
|
|
|
//called when the url is not defined here, ajax-in; get-settings
|
2019-02-16 00:21:22 +01:00
|
|
|
server.onNotFound([](AsyncWebServerRequest *request){
|
2018-09-30 20:24:57 +02:00
|
|
|
DEBUG_PRINTLN("Not-Found HTTP call:");
|
2019-02-18 22:34:21 +01:00
|
|
|
DEBUG_PRINTLN("URI: " + request->url());
|
2019-09-05 22:45:59 +02:00
|
|
|
if (captivePortal(request)) return;
|
2018-09-30 20:24:57 +02:00
|
|
|
|
2019-01-18 01:20:36 +01:00
|
|
|
//make API CORS compatible
|
2019-02-16 00:21:22 +01:00
|
|
|
if (request->method() == HTTP_OPTIONS)
|
2019-01-18 01:20:36 +01:00
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
request->send(200); return;
|
2019-01-18 01:20:36 +01:00
|
|
|
}
|
2018-09-30 20:24:57 +02:00
|
|
|
|
2019-03-16 02:09:37 +01:00
|
|
|
if(handleSet(request, request->url())) return;
|
|
|
|
#ifndef WLED_DISABLE_ALEXA
|
|
|
|
if(espalexa.handleAlexaApiCall(request)) return;
|
|
|
|
#endif
|
|
|
|
#ifdef WLED_ENABLE_FS_SERVING
|
|
|
|
if(handleFileRead(request, request->url())) return;
|
|
|
|
#endif
|
|
|
|
request->send(404, "text/plain", "Not Found");
|
2018-09-30 20:24:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
void serveIndexOrWelcome(AsyncWebServerRequest *request)
|
2018-09-30 20:24:57 +02:00
|
|
|
{
|
|
|
|
if (!showWelcomePage){
|
2019-02-16 00:21:22 +01:00
|
|
|
serveIndex(request);
|
|
|
|
} else {
|
|
|
|
serveSettings(request);
|
2018-09-30 20:24:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
void serveIndex(AsyncWebServerRequest* request)
|
2018-09-30 20:24:57 +02:00
|
|
|
{
|
2019-03-16 02:09:37 +01:00
|
|
|
#ifdef WLED_ENABLE_FS_SERVING
|
2019-12-02 12:41:35 +01:00
|
|
|
if (handleFileRead(request, "/index.htm")) return;
|
2019-03-16 02:09:37 +01:00
|
|
|
#endif
|
|
|
|
|
2019-12-02 12:41:35 +01:00
|
|
|
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", PAGE_index, PAGE_index_L);
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
response->addHeader(F("Content-Encoding"),"gzip");
|
2018-11-09 17:00:36 +01:00
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
request->send(response);
|
2018-09-30 20:24:57 +02:00
|
|
|
}
|
|
|
|
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
String msgProcessor(const String& var)
|
|
|
|
{
|
|
|
|
if (var == "MSG") {
|
2019-03-09 21:41:23 +01:00
|
|
|
String messageBody = messageHead;
|
2020-09-20 01:18:31 +02:00
|
|
|
messageBody += F("</h2>");
|
2019-02-16 00:21:22 +01:00
|
|
|
messageBody += messageSub;
|
2019-02-20 23:44:34 +01:00
|
|
|
uint32_t optt = optionType;
|
2019-02-16 00:21:22 +01:00
|
|
|
|
2019-02-20 23:44:34 +01:00
|
|
|
if (optt < 60) //redirect to settings after optionType seconds
|
2019-02-16 00:21:22 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
messageBody += F("<script>setTimeout(RS,");
|
|
|
|
messageBody +=String(optt*1000);
|
|
|
|
messageBody += F(")</script>");
|
2019-02-20 23:44:34 +01:00
|
|
|
} else if (optt < 120) //redirect back after optionType-60 seconds, unused
|
2019-02-16 00:21:22 +01:00
|
|
|
{
|
2019-02-20 23:44:34 +01:00
|
|
|
//messageBody += "<script>setTimeout(B," + String((optt-60)*1000) + ")</script>";
|
|
|
|
} else if (optt < 180) //reload parent after optionType-120 seconds
|
2019-02-16 00:21:22 +01:00
|
|
|
{
|
2020-09-20 01:18:31 +02:00
|
|
|
messageBody += F("<script>setTimeout(RP,");
|
|
|
|
messageBody += String((optt-120)*1000);
|
|
|
|
messageBody += F(")</script>");
|
2019-02-20 23:44:34 +01:00
|
|
|
} else if (optt == 253)
|
2019-02-16 00:21:22 +01:00
|
|
|
{
|
2020-02-25 02:19:12 +01:00
|
|
|
messageBody += F("<br><br><form action=/settings><button class=\"bt\" type=submit>Back</button></form>"); //button to settings
|
2019-02-20 23:44:34 +01:00
|
|
|
} else if (optt == 254)
|
2019-02-16 00:21:22 +01:00
|
|
|
{
|
2020-02-25 02:19:12 +01:00
|
|
|
messageBody += F("<br><br><button type=\"button\" class=\"bt\" onclick=\"B()\">Back</button>");
|
2019-02-16 00:21:22 +01:00
|
|
|
}
|
|
|
|
return messageBody;
|
|
|
|
}
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
void serveMessage(AsyncWebServerRequest* request, uint16_t code, const String& headl, const String& subl, byte optionT)
|
2018-09-30 20:24:57 +02:00
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
messageHead = headl;
|
|
|
|
messageSub = subl;
|
|
|
|
optionType = optionT;
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2019-02-16 00:21:22 +01:00
|
|
|
request->send_P(code, "text/html", PAGE_msg, msgProcessor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String settingsProcessor(const String& var)
|
|
|
|
{
|
2019-03-11 19:30:49 +01:00
|
|
|
if (var == "CSS") {
|
2019-03-16 02:09:37 +01:00
|
|
|
char buf[2048];
|
|
|
|
getSettingsJS(optionType, buf);
|
|
|
|
return String(buf);
|
2019-03-11 19:30:49 +01:00
|
|
|
}
|
2020-02-23 22:24:51 +01:00
|
|
|
|
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
|
|
|
|
if (var == "DMXMENU") {
|
2020-02-25 02:19:12 +01:00
|
|
|
return String(F("<form action=/settings/dmx><button type=submit>DMX Output</button></form>"));
|
2020-02-23 22:24:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2019-08-21 01:18:25 +02:00
|
|
|
if (var == "SCSS") return String(FPSTR(PAGE_settingsCss));
|
2019-02-16 00:21:22 +01:00
|
|
|
return String();
|
2018-09-30 20:24:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-23 22:24:51 +01:00
|
|
|
String dmxProcessor(const String& var)
|
|
|
|
{
|
|
|
|
String mapJS;
|
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
if (var == "DMXVARS") {
|
|
|
|
mapJS += "\nCN=" + String(DMXChannels) + ";\n";
|
|
|
|
mapJS += "CS=" + String(DMXStart) + ";\n";
|
|
|
|
mapJS += "CG=" + String(DMXGap) + ";\n";
|
|
|
|
mapJS += "LC=" + String(ledCount) + ";\n";
|
|
|
|
mapJS += "var CH=[";
|
|
|
|
for (int i=0;i<15;i++) {
|
|
|
|
mapJS += String(DMXFixtureMap[i]) + ",";
|
|
|
|
}
|
|
|
|
mapJS += "0];";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return mapJS;
|
|
|
|
}
|
|
|
|
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2020-09-20 01:18:31 +02:00
|
|
|
void serveSettings(AsyncWebServerRequest* request, bool post)
|
2018-09-30 20:24:57 +02:00
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
byte subPage = 0;
|
2019-03-06 01:20:38 +01:00
|
|
|
const String& url = request->url();
|
2019-02-16 00:21:22 +01:00
|
|
|
if (url.indexOf("sett") >= 0)
|
|
|
|
{
|
|
|
|
if (url.indexOf("wifi") > 0) subPage = 1;
|
|
|
|
else if (url.indexOf("leds") > 0) subPage = 2;
|
|
|
|
else if (url.indexOf("ui") > 0) subPage = 3;
|
|
|
|
else if (url.indexOf("sync") > 0) subPage = 4;
|
|
|
|
else if (url.indexOf("time") > 0) subPage = 5;
|
|
|
|
else if (url.indexOf("sec") > 0) subPage = 6;
|
2020-02-23 22:24:51 +01:00
|
|
|
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
|
|
|
|
else if (url.indexOf("dmx") > 0) subPage = 7;
|
|
|
|
#endif
|
2019-02-16 00:21:22 +01:00
|
|
|
} else subPage = 255; //welcome page
|
|
|
|
|
|
|
|
if (subPage == 1 && wifiLock && otaLock)
|
|
|
|
{
|
2020-06-26 17:28:35 +02:00
|
|
|
serveMessage(request, 500, "Access Denied", F("Please unlock OTA in security settings!"), 254); return;
|
2019-02-16 00:21:22 +01:00
|
|
|
}
|
2020-09-20 01:18:31 +02:00
|
|
|
|
|
|
|
if (post) { //settings/set POST request, saving
|
|
|
|
if (subPage != 1 || !(wifiLock && otaLock)) handleSettingsSet(request, subPage);
|
|
|
|
|
|
|
|
char s[32];
|
|
|
|
char s2[45] = "";
|
|
|
|
|
|
|
|
switch (subPage) {
|
|
|
|
case 1: strcpy_P(s, PSTR("WiFi")); strcpy_P(s2, PSTR("Please connect to the new IP (if changed)")); forceReconnect = true; break;
|
|
|
|
case 2: strcpy_P(s, PSTR("LED")); break;
|
|
|
|
case 3: strcpy_P(s, PSTR("UI")); break;
|
|
|
|
case 4: strcpy_P(s, PSTR("Sync")); break;
|
|
|
|
case 5: strcpy_P(s, PSTR("Time")); break;
|
|
|
|
case 6: strcpy_P(s, PSTR("Security")); strcpy_P(s2, PSTR("Rebooting, please wait ~10 seconds...")); break;
|
|
|
|
case 7: strcpy_P(s, PSTR("DMX")); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat_P(s, PSTR(" settings saved."));
|
|
|
|
if (!s2[0]) strcpy_P(s2, PSTR("Redirecting..."));
|
|
|
|
|
|
|
|
if (!doReboot) serveMessage(request, 200, s, s2, (subPage == 1 || subPage == 6) ? 129 : 1);
|
|
|
|
if (subPage == 6) doReboot = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 17:00:36 +01:00
|
|
|
|
|
|
|
#ifdef WLED_DISABLE_MOBILE_UI //disable welcome page if not enough storage
|
2019-02-16 00:21:22 +01:00
|
|
|
if (subPage == 255) {serveIndex(request); return;}
|
2018-11-09 17:00:36 +01:00
|
|
|
#endif
|
2018-11-16 19:59:00 +01:00
|
|
|
|
2019-03-11 19:30:49 +01:00
|
|
|
optionType = subPage;
|
2018-11-09 17:00:36 +01:00
|
|
|
|
|
|
|
switch (subPage)
|
|
|
|
{
|
2019-02-16 00:21:22 +01:00
|
|
|
case 1: request->send_P(200, "text/html", PAGE_settings_wifi, settingsProcessor); break;
|
|
|
|
case 2: request->send_P(200, "text/html", PAGE_settings_leds, settingsProcessor); break;
|
|
|
|
case 3: request->send_P(200, "text/html", PAGE_settings_ui , settingsProcessor); break;
|
|
|
|
case 4: request->send_P(200, "text/html", PAGE_settings_sync, settingsProcessor); break;
|
|
|
|
case 5: request->send_P(200, "text/html", PAGE_settings_time, settingsProcessor); break;
|
|
|
|
case 6: request->send_P(200, "text/html", PAGE_settings_sec , settingsProcessor); break;
|
2020-02-23 22:24:51 +01:00
|
|
|
case 7: request->send_P(200, "text/html", PAGE_settings_dmx , settingsProcessor); break;
|
2019-09-12 12:40:06 +02:00
|
|
|
case 255: request->send_P(200, "text/html", PAGE_welcome); break;
|
2020-02-23 22:24:51 +01:00
|
|
|
default: request->send_P(200, "text/html", PAGE_settings , settingsProcessor);
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-09-30 20:24:57 +02:00
|
|
|
}
|