diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 5eb5e580..6233f85d 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -99,10 +99,10 @@ WebServer webServer(80); HTTPUpload* upload; static const char HTTP_MENU_BUTTON[] PROGMEM = - "

"; + "

"; const char MAIN_MENU_BUTTON[] PROGMEM = - "

"; + "

"; const char MIT_LICENSE[] PROGMEM = "
MIT License

"; const char HTTP_DOCTYPE[] PROGMEM = "
"); add_button(str, label, extra); @@ -256,7 +256,7 @@ void webSendPage(const char* nodename, uint32_t httpdatalength, bool gohome = fa haspGetVersion(buffer, sizeof(buffer)); /* Calculate Content Length upfront */ - uint16_t contentLength = strlen(buffer); // verion length + uint32_t contentLength = strlen(buffer); // version length contentLength += sizeof(HTTP_DOCTYPE) - 1; contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename); // -2 for %s contentLength += sizeof(HTTP_SCRIPT) - 1; @@ -349,29 +349,28 @@ void webHandleRoot() httpMessage += haspDevice.get_hostname(); httpMessage += F("
"); - httpMessage += F("

"); - httpMessage += F("

"); httpMessage += - F("

"); + F("

"); add_form_button(httpMessage, F(D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += F("

"); - httpMessage += F("

"); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - if(HASP_FS.exists(F("/edit.htm.gz"))) { - httpMessage += - F("

"); + if(HASP_FS.exists(F("/edit.htm.gz")) || HASP_FS.exists(F("/edit.htm"))) { + httpMessage += F("

"); } #endif - httpMessage += F("

"); webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); @@ -442,13 +441,13 @@ void webHandleScreenshot() // Automatic refresh httpMessage += F(" onload=\"aref(5)\" onerror=\"aref(5)\"/>

"); - httpMessage += F("

"); httpMessage += - F("

"); httpMessage += - F("

"); httpMessage += FPSTR(MAIN_MENU_BUTTON); @@ -981,22 +980,30 @@ void handleFileCreate() if(webServer.args() == 0) { return webServer.send(500, PSTR("text/plain"), PSTR("BAD ARGS")); } - String path = webServer.arg(0); - LOG_TRACE(TAG_HTTP, F("handleFileCreate: %s"), path.c_str()); - if(path == "/") { - return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); + + if(webServer.hasArg(F("path"))) { + String path = webServer.arg(F("path")); + LOG_TRACE(TAG_HTTP, F("handleFileCreate: %s"), path.c_str()); + if(path == "/") { + return webServer.send(500, PSTR("text/plain"), PSTR("BAD PATH")); + } + if(HASP_FS.exists(path)) { + return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS")); + } + File file = HASP_FS.open(path, "w"); + if(file) { + file.close(); + } else { + return webServer.send(500, PSTR("text/plain"), PSTR("CREATE FAILED")); + } } - if(HASP_FS.exists(path)) { - return webServer.send(500, PSTR("text/plain"), PSTR("FILE EXISTS")); + if(webServer.hasArg(F("init"))) { + hasp_init(); } - File file = HASP_FS.open(path, "w"); - if(file) { - file.close(); - } else { - return webServer.send(500, PSTR("text/plain"), PSTR("CREATE FAILED")); + if(webServer.hasArg(F("load"))) { + hasp_load_json(); } webServer.send(200, PSTR("text/plain"), ""); - path.clear(); } void handleFileList() @@ -1086,35 +1093,35 @@ void webHandleConfig() httpMessage += F("
"); #if HASP_USE_WIFI > 0 - httpMessage += F("

"); #endif #if HASP_USE_MQTT > 0 - httpMessage += F("

"); #endif - httpMessage += F("

"); - httpMessage += F("

"); // httpMessage += - // F("

"); #if HASP_USE_GPIO > 0 - httpMessage += F("

"); #endif - httpMessage += F("

"); httpMessage += - F("

"); httpMessage += FPSTR(MAIN_MENU_BUTTON); @@ -1168,7 +1175,7 @@ void webHandleMqttConfig() F("'>

"); add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); @@ -1256,24 +1263,19 @@ void webHandleGuiConfig() // F("

"); #if TOUCH_DRIVER == 2046 && defined(TOUCH_CS) - add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'")); + add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='cal' value='1'")); -// httpMessage += PSTR("

"); #endif add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - - // httpMessage += PSTR("

"); - webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); webServer.sendContent(httpMessage); } webSendFooter(); - if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); + if(webServer.hasArg(F("cal"))) dispatch_calibrate(NULL, NULL); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1306,7 +1308,7 @@ void webHandleWifiConfig() #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() == WIFI_STA) { add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); } @@ -1351,7 +1353,7 @@ void webHandleHttpConfig() // httpMessage += // F("'>

"); - // httpMessage += PSTR("

"); @@ -1366,7 +1368,7 @@ void webHandleHttpConfig() "Web Password (optional)" "" "

" - "

"), haspDevice.get_hostname(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(), settings[FPSTR(FP_CONFIG_PASS)].as().c_str()); @@ -1505,7 +1507,7 @@ void webHandleGpioConfig() } add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += F("

"); @@ -1608,7 +1610,7 @@ void webHandleGpioOptions() httpMessage += F("

"); - httpMessage += PSTR("

"); webSendPage(haspDevice.get_hostname(), httpMessage.length(), false); @@ -1616,7 +1618,7 @@ void webHandleGpioOptions() } webSendFooter(); - if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check + // if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check } #endif // HASP_USE_GPIO @@ -1676,7 +1678,7 @@ void webHandleDebugConfig() F("

"); add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); - // httpMessage += PSTR("

"); @@ -1702,7 +1704,7 @@ void webHandleHaspConfig() httpMessage += haspDevice.get_hostname(); httpMessage += F("
"); - httpMessage += F("

"); httpMessage += F("


"); @@ -1779,7 +1781,7 @@ void webHandleHaspConfig() F("

"); // httpMessage += - // F("

"); httpMessage += FPSTR(MAIN_MENU_BUTTON); @@ -1833,15 +1835,15 @@ void webHandleFirmware() httpMessage += haspDevice.get_hostname(); httpMessage += F("
"); - httpMessage += F("

"); httpMessage += F("

"); - // httpMessage += F("

"); // httpMessage += F("

"); - httpMessage += F("
"); + httpMessage += F(""); httpMessage += F("
Update ESP from URL"); httpMessage += F("
" + "


" "

" "


"); add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F("")); // httpMessage += - // PSTR("

"); }