diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 5f8eda32..1c5e7384 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -532,7 +532,8 @@ static void webHandleApiConfig() JsonObject settings; String contentType = getContentType(F(".json")); String endpoint((char*)0); - endpoint = webServer.pathArg(0); + endpoint = webServer.pathArg(0); + const char* endpoint_key = endpoint.c_str(); String postBody = webServer.arg("plain"); @@ -540,7 +541,7 @@ static void webHandleApiConfig() // Make sure we have a valid JsonObject to start from settings = doc.to(); - } else if(webServer.method() == HTTP_POST) { + } else if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) { DeserializationError jsonError = deserializeJson(doc, postBody); if(jsonError) { // Couldn't parse incoming JSON command dispatch_json_error(TAG_HTTP, jsonError); @@ -552,28 +553,49 @@ static void webHandleApiConfig() return; } - if(!strcasecmp_P(endpoint.c_str(), PSTR("wifi"))) { - wifiGetConfig(settings); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("mqtt"))) { - mqttGetConfig(settings); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("http"))) { - httpGetConfig(settings); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("gui"))) { - guiGetConfig(settings); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("debug"))) { - debugGetConfig(settings); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("time"))) { - if(webServer.method() == HTTP_POST) { - configOutput(settings, TAG_HTTP); + if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) { + configOutput(settings, TAG_HTTP); // Log input JSON config + + if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { + wifiSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) { + mqttSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) { + haspSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("http"))) { + httpSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { + guiSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { + debugSetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { timeSetConfig(settings); + } else { + LOG_WARNING(TAG_HTTP, F("Invalid module %s"), endpoint_key); + return; } - settings = doc.to(); + } + + settings = doc.to(); + if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { + wifiGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("mqtt"))) { + mqttGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) { + haspGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("http"))) { + httpGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { + guiGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { + debugGetConfig(settings); + } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { timeGetConfig(settings); - configOutput(settings, TAG_HTTP); } else { webServer.send(400, contentType, "Bad Request"); return; } + configOutput(settings, TAG_HTTP); // Log current JSON config LOG_WARNING(TAG_HTTP, "%s - %d", __FILE__, __LINE__); // Mask non-blank passwords @@ -1117,42 +1139,31 @@ static void webHandleMqttConfig() // Node Name httpMessage += F("
"); - httpMessage += - F("
"); + httpMessage += F("
"); // Group Name httpMessage += F("
"); httpMessage += F("
"); + "placeholder='Group Name' value=''>"); // Broker httpMessage += F("
"); httpMessage += F("
"); + httpMessage += F(" placeholder='Server Name' value=''>"); // Mqtt Port httpMessage += F("
"); httpMessage += F("
"); + "placeholder='1883' value=''>"); // Mqtt User httpMessage += F("
"); httpMessage += F("
"); + httpMessage += F(" placeholder='MQTT User' value=''>"); // Mqtt Password httpMessage += F("
"); @@ -1876,8 +1887,8 @@ static void webHandleHaspConfig() // File httpMessage += F("
"); - httpMessage += - F("
"); + httpMessage += F("
"); // Destination httpMessage += F("
"); @@ -1891,7 +1902,6 @@ static void webHandleHaspConfig() #endif // Form - // httpMessage += F("
"); httpMessage += F("
"); // Theme @@ -1918,13 +1928,19 @@ static void webHandleHaspConfig() httpMessage += F("
"); // Hue - httpMessage += F("
"); - httpMessage += F("
"); + // httpMessage += F("
"); + // httpMessage += F("
"); + + // Primary Color + httpMessage += F("
"); + httpMessage += F("
"); + + // Secondary Color + httpMessage += F("
"); + httpMessage += F("
"); // Font httpMessage += F("
"); @@ -1954,30 +1970,25 @@ static void webHandleHaspConfig() // Pages.jsonl httpMessage += F("
"); - httpMessage += - F("
"); + httpMessage += F("
"); // Startup Page httpMessage += F("
"); httpMessage += F("
"); + "name='startpage' type='number' min='1' max='12' value=''>
"); // Startup Brightness httpMessage += F("
"); - httpMessage += F("
"); + httpMessage += F("
"); // Submit & End Form httpMessage += F(""); httpMessage += F(""); httpMessage += FPSTR(MAIN_MENU_BUTTON); + httpMessage += F(""); webSendHeader(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); @@ -2141,11 +2152,11 @@ static void httpHandleResetConfig() } else { // Form httpMessage += F("
"); - httpMessage += - F("
Warning

This process will reset all settings to the default values. " - "The internal flash will be erased and the device is restarted. You may need to connect to the WiFi " - "AP displayed on the panel to reconfigure the device before accessing it again.

" - "

ALL FILES WILL BE LOST!

"); + httpMessage += F( + "
Warning

This process will reset all settings to the " + "default values. The internal flash will be erased and the device is restarted. You may need to " + "connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it again.

" + "

ALL FILES WILL BE LOST!

"); httpMessage += F("

");