mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Reorder SoftAP setup
This commit is contained in:
parent
220b0f39a0
commit
bde590394d
@ -195,7 +195,7 @@ void httpHandleReboot()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void webHandleScreenshot()
|
void webHandleScreenshot()
|
||||||
{ // http://plate01/about
|
{ // http://plate01/screenshot
|
||||||
if(!httpIsAuthenticated(F("/screenshot"))) return;
|
if(!httpIsAuthenticated(F("/screenshot"))) return;
|
||||||
|
|
||||||
if(webServer.hasArg(F("q"))) {
|
if(webServer.hasArg(F("q"))) {
|
||||||
@ -222,6 +222,7 @@ void webHandleScreenshot()
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void webHandleAbout()
|
void webHandleAbout()
|
||||||
{ // http://plate01/about
|
{ // http://plate01/about
|
||||||
if(!httpIsAuthenticated(F("/about"))) return;
|
if(!httpIsAuthenticated(F("/about"))) return;
|
||||||
@ -261,6 +262,7 @@ void webHandleAbout()
|
|||||||
webServer.sendContent(httpMessage); // len
|
webServer.sendContent(httpMessage); // len
|
||||||
webServer.sendContent_P(HTTP_END); // 20
|
webServer.sendContent_P(HTTP_END); // 20
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void webHandleInfo()
|
void webHandleInfo()
|
||||||
{ // http://plate01/
|
{ // http://plate01/
|
||||||
@ -336,8 +338,8 @@ void webHandleInfo()
|
|||||||
httpMessage += FPSTR(MAIN_MENU_BUTTON);
|
httpMessage += FPSTR(MAIN_MENU_BUTTON);
|
||||||
|
|
||||||
webSendPage(nodename, httpMessage.length(), false);
|
webSendPage(nodename, httpMessage.length(), false);
|
||||||
webServer.sendContent(httpMessage); // len
|
webServer.sendContent(httpMessage);
|
||||||
webServer.sendContent_P(HTTP_END); // 20
|
webServer.sendContent_P(HTTP_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getContentType(String filename)
|
String getContentType(String filename)
|
||||||
@ -370,7 +372,7 @@ String getContentType(String filename)
|
|||||||
return F("text/plain");
|
return F("text/plain");
|
||||||
}
|
}
|
||||||
|
|
||||||
String urldecode(String str)
|
/* String urldecode(String str)
|
||||||
{
|
{
|
||||||
String encodedString = "";
|
String encodedString = "";
|
||||||
char c;
|
char c;
|
||||||
@ -394,13 +396,14 @@ String urldecode(String str)
|
|||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
return encodedString;
|
return encodedString;
|
||||||
}
|
} */
|
||||||
|
|
||||||
bool handleFileRead(String path)
|
bool handleFileRead(String path)
|
||||||
{
|
{
|
||||||
if(!httpIsAuthenticated(F("fileread"))) return false;
|
if(!httpIsAuthenticated(F("fileread"))) return false;
|
||||||
|
|
||||||
path = urldecode(path).substring(0, 31);
|
// path = urldecode(path).substring(0, 31);
|
||||||
|
path = webServer.urlDecode(path);
|
||||||
if(!httpIsAuthenticated(path)) return false;
|
if(!httpIsAuthenticated(path)) return false;
|
||||||
|
|
||||||
if(path.endsWith("/")) {
|
if(path.endsWith("/")) {
|
||||||
@ -988,54 +991,62 @@ void httpHandleResetConfig()
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
void httpSetup(const JsonObject & settings)
|
void httpSetup(const JsonObject & settings)
|
||||||
{
|
{
|
||||||
webServer.on(F("/page/"), []() {
|
if(WiFi.getMode() == WIFI_AP) {
|
||||||
String pageid = webServer.arg(F("page"));
|
debugPrintln(F("HTTP: Wifi access point"));
|
||||||
webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
|
webServer.on(F("/"), webHandleWifiConfig);
|
||||||
haspSetPage(pageid.toInt());
|
webServer.on(F("/config"), webHandleConfig);
|
||||||
});
|
webServer.onNotFound(httpHandleNotFound);
|
||||||
|
} else {
|
||||||
|
|
||||||
webServer.on("/list", HTTP_GET, handleFileList);
|
webServer.on(F("/page/"), []() {
|
||||||
// load editor
|
String pageid = webServer.arg(F("page"));
|
||||||
webServer.on("/edit", HTTP_GET, []() {
|
webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
|
||||||
if(!handleFileRead("/edit.htm")) {
|
haspSetPage(pageid.toInt());
|
||||||
webServer.send(404, "text/plain", "FileNotFound");
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
webServer.on("/edit", HTTP_PUT, handleFileCreate);
|
|
||||||
webServer.on("/edit", HTTP_DELETE, handleFileDelete);
|
|
||||||
// first callback is called after the request has ended with all parsed arguments
|
|
||||||
// second callback handles file uploads at that location
|
|
||||||
webServer.on("/edit", HTTP_POST, []() { webServer.send(200, "text/plain", ""); }, handleFileUpload);
|
|
||||||
// get heap status, analog input value and all GPIO statuses in one json call
|
|
||||||
webServer.on("/all", HTTP_GET, []() {
|
|
||||||
String json('{');
|
|
||||||
json += "\"heap\":" + String(ESP.getFreeHeap());
|
|
||||||
json += ", \"analog\":" + String(analogRead(A0));
|
|
||||||
json += "}";
|
|
||||||
webServer.send(200, "text/json", json);
|
|
||||||
json.clear();
|
|
||||||
});
|
|
||||||
|
|
||||||
webServer.on(F("/"), webHandleRoot);
|
webServer.on("/list", HTTP_GET, handleFileList);
|
||||||
webServer.on(F("/about"), webHandleAbout);
|
// load editor
|
||||||
webServer.on(F("/info"), webHandleInfo);
|
webServer.on("/edit", HTTP_GET, []() {
|
||||||
webServer.on(F("/config"), webHandleConfig);
|
if(!handleFileRead("/edit.htm")) {
|
||||||
webServer.on(F("/config/hasp"), webHandleHaspConfig);
|
webServer.send(404, "text/plain", "FileNotFound");
|
||||||
webServer.on(F("/config/http"), webHandleHttpConfig);
|
}
|
||||||
webServer.on(F("/config/gui"), webHandleGuiConfig);
|
});
|
||||||
|
webServer.on("/edit", HTTP_PUT, handleFileCreate);
|
||||||
|
webServer.on("/edit", HTTP_DELETE, handleFileDelete);
|
||||||
|
// first callback is called after the request has ended with all parsed arguments
|
||||||
|
// second callback handles file uploads at that location
|
||||||
|
webServer.on("/edit", HTTP_POST, []() { webServer.send(200, "text/plain", ""); }, handleFileUpload);
|
||||||
|
// get heap status, analog input value and all GPIO statuses in one json call
|
||||||
|
webServer.on("/all", HTTP_GET, []() {
|
||||||
|
String json('{');
|
||||||
|
json += "\"heap\":" + String(ESP.getFreeHeap());
|
||||||
|
json += ", \"analog\":" + String(analogRead(A0));
|
||||||
|
json += "}";
|
||||||
|
webServer.send(200, "text/json", json);
|
||||||
|
json.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
webServer.on(F("/"), webHandleRoot);
|
||||||
|
webServer.on(F("/about"), webHandleAbout);
|
||||||
|
webServer.on(F("/info"), webHandleInfo);
|
||||||
|
webServer.on(F("/config"), webHandleConfig);
|
||||||
|
webServer.on(F("/config/hasp"), webHandleHaspConfig);
|
||||||
|
webServer.on(F("/config/http"), webHandleHttpConfig);
|
||||||
|
webServer.on(F("/config/gui"), webHandleGuiConfig);
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
webServer.on(F("/config/mqtt"), webHandleMqttConfig);
|
webServer.on(F("/config/mqtt"), webHandleMqttConfig);
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_WIFI > 0
|
#if HASP_USE_WIFI > 0
|
||||||
webServer.on(F("/config/wifi"), webHandleWifiConfig);
|
webServer.on(F("/config/wifi"), webHandleWifiConfig);
|
||||||
#endif
|
#endif
|
||||||
webServer.on(F("/screenshot"), webHandleScreenshot);
|
webServer.on(F("/screenshot"), webHandleScreenshot);
|
||||||
webServer.on(F("/saveConfig"), webHandleSaveConfig);
|
webServer.on(F("/saveConfig"), webHandleSaveConfig);
|
||||||
webServer.on(F("/resetConfig"), httpHandleResetConfig);
|
webServer.on(F("/resetConfig"), httpHandleResetConfig);
|
||||||
webServer.on(F("/firmware"), webHandleFirmware);
|
webServer.on(F("/firmware"), webHandleFirmware);
|
||||||
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
|
webServer.on(F("/espfirmware"), httpHandleEspFirmware);
|
||||||
webServer.on(F("/reboot"), httpHandleReboot);
|
webServer.on(F("/reboot"), httpHandleReboot);
|
||||||
webServer.onNotFound(httpHandleNotFound);
|
webServer.onNotFound(httpHandleNotFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -1043,16 +1054,16 @@ void httpReconnect()
|
|||||||
{
|
{
|
||||||
if(!httpEnable) return;
|
if(!httpEnable) return;
|
||||||
|
|
||||||
if(WiFi.getMode() == WIFI_AP) {
|
|
||||||
webServer.on(F("/"), webHandleWifiConfig);
|
|
||||||
webServer.on(F("/config"), webHandleConfig);
|
|
||||||
webServer.onNotFound(webHandleWifiConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
webServer.stop();
|
webServer.stop();
|
||||||
webServerStarted = false;
|
webServerStarted = false;
|
||||||
|
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
if(WiFi.getMode() == WIFI_AP) {
|
||||||
|
webServer.on(F("/"), webHandleWifiConfig);
|
||||||
|
webServer.on(F("/config"), webHandleConfig);
|
||||||
|
webServer.onNotFound(httpHandleNotFound);
|
||||||
|
} else {
|
||||||
|
if(WiFi.status() != WL_CONNECTED) return;
|
||||||
|
}
|
||||||
|
|
||||||
webServer.begin();
|
webServer.begin();
|
||||||
webServerStarted = true;
|
webServerStarted = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user