webdav part 1

This commit is contained in:
Luc 2021-01-24 13:22:41 +01:00
parent 1f8d4405c1
commit 59e766b0b8
36 changed files with 2704 additions and 15 deletions

View File

@ -72,6 +72,12 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
* Get/Set Ftp ports * Get/Set Ftp ports
[ESP181]ctrl=<port> active=<port> passive=<port> pwd=<admin password> [ESP181]ctrl=<port> active=<port> passive=<port> pwd=<admin password>
* Get/Set WebDav state which can be ON, OFF, CLOSE
[ESP190]<state>pwd=<admin password>
* Get/Set WebDav port
[ESP191]<port>pwd=<admin password>
* Get SD Card Status * Get SD Card Status
[ESP200] pwd=<user/admin password> [ESP200] pwd=<user/admin password>
@ -169,6 +175,9 @@ ESP_FTP_DATA_ACTIVE_PORT 1013 //4 bytes = int
ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int ESP_FTP_DATA_PASSIVE_PORT 1017 //4 bytes = int
ESP_FTP_ON 1021 //1 byte = flag ESP_FTP_ON 1021 //1 byte = flag
ESP_AUTO_NOTIFICATION 1022 //1 byte = flag ESP_AUTO_NOTIFICATION 1022 //1 byte = flag
ESP_VERBOSE_BOOT 1023 //1 byte = flag
ESP_WEBDAV_ON 1024 //1 byte = flag
ESP_WEBDAV_PORT 1025 //4 bytes = int
* Get/Set Check update at boot state which can be ON, OFF * Get/Set Check update at boot state which can be ON, OFF
[ESP402]<state>pwd=<admin password> [ESP402]<state>pwd=<admin password>

View File

@ -54,6 +54,12 @@ WebSocket_active = Yes
#WebSocket Port #WebSocket Port
WebSocket_Port = 8282 WebSocket_Port = 8282
#Active or not WebDav Yes / No
WebDav_active = Yes
#WebSocket Port
WebDav_Port = 8282
#Active or not FTP Yes / No #Active or not FTP Yes / No
FTP_active = Yes FTP_active = Yes

View File

@ -61,7 +61,7 @@
#define TELNET_FEATURE #define TELNET_FEATURE
//WS_DATA_FEATURE: allow to connect serial from Websocket //WS_DATA_FEATURE: allow to connect serial from Websocket
#define WS_DATA_FEATURE //#define WS_DATA_FEATURE
//DISPLAY_DEVICE: allow screen output //DISPLAY_DEVICE: allow screen output
//OLED_I2C_SSD1306 1 //OLED_I2C_SSD1306 1
@ -157,14 +157,22 @@
#define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM #define FILESYSTEM_FEATURE ESP_LITTLEFS_FILESYSTEM
//Allows to mount /FS and /SD under / for FTP server //Allows to mount /FS and /SD under / for FTP server
#define GLOBAL_FILESYSTEM_FEATURE //#define GLOBAL_FILESYSTEM_FEATURE
//WEBDAV_FEATURE : enable WebDav feature
//FS_ROOT mount all FS
//FS_FLASH mount Flash FS
//FS_SD mount SD FS
//FS_USBDISK mount USB disk FS
#define WEBDAV_FEATURE FS_FLASH
//FTP_FEATURE : enable FTP feature //FTP_FEATURE : enable FTP feature
//FS_ROOT mount all FS //FS_ROOT mount all FS
//FS_FLASH mount Flash FS //FS_FLASH mount Flash FS
//FS_SD mount SD FS //FS_SD mount SD FS
//FS_USBDISK mount USB disk FS //FS_USBDISK mount USB disk FS
#define FTP_FEATURE FS_ROOT //#define FTP_FEATURE FS_ROOT
//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command //DIRECT_PIN_FEATURE: allow to access pin using ESP201 command
#define DIRECT_PIN_FEATURE #define DIRECT_PIN_FEATURE
@ -190,7 +198,7 @@
#define CAPTIVE_PORTAL_FEATURE #define CAPTIVE_PORTAL_FEATURE
//OTA_FEATURE: this feature is arduino update over the air //OTA_FEATURE: this feature is arduino update over the air
#define OTA_FEATURE //#define OTA_FEATURE
//WEB_UPDATE_FEATURE: allow to flash fw using web UI //WEB_UPDATE_FEATURE: allow to flash fw using web UI
#define WEB_UPDATE_FEATURE #define WEB_UPDATE_FEATURE
@ -252,7 +260,7 @@
//DEBUG_OUTPUT_SERIAL2 3 //DEBUG_OUTPUT_SERIAL2 3
//DEBUG_OUTPUT_TELNET 4 //DEBUG_OUTPUT_TELNET 4
//DEBUG_OUTPUT_WEBSOCKET 5 //DEBUG_OUTPUT_WEBSOCKET 5
//#define ESP_DEBUG_FEATURE DEBUG_OUTPUT_TELNET #define ESP_DEBUG_FEATURE DEBUG_OUTPUT_SERIAL0
#ifdef ESP_DEBUG_FEATURE #ifdef ESP_DEBUG_FEATURE
#define DEBUG_BAUDRATE 115200 #define DEBUG_BAUDRATE 115200

View File

@ -408,6 +408,18 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
response = ESP181(cmd_params, auth_type, output); response = ESP181(cmd_params, auth_type, output);
break; break;
#endif //FTP_FEATURE #endif //FTP_FEATURE
#ifdef WEBDAV_FEATURE
//Set webdav state which can be ON, OFF
//[ESP190]<state>pwd=<admin password>
case 190:
response = ESP190(cmd_params, auth_type, output);
break;
//Set/get webdav port
//[ESP191]ctrl=<port> active=<port> passive=<port> pwd=<admin password>
case 191:
response = ESP191(cmd_params, auth_type, output);
break;
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE) #if defined (SD_DEVICE)
//Get SD Card Status //Get SD Card Status
//[ESP200] pwd=<user/admin password> //[ESP200] pwd=<user/admin password>

View File

@ -84,6 +84,10 @@ public:
bool ESP180(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP180(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP181(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP181(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //FTP_FEATURE #endif //FTP_FEATURE
#if defined(WEBDAV_FEATURE)
bool ESP190(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP191(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE) #if defined (SD_DEVICE)
bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP200(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP202(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output); bool ESP202(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);

View File

@ -53,7 +53,7 @@ extern void initDebug();
#undef DEBUG_ESP3D_INIT #undef DEBUG_ESP3D_INIT
#define DEBUG_ESP3D_INIT initDebug(); #define DEBUG_ESP3D_INIT initDebug();
#define log_esp3d(format, ...) DEBUG_OUTPUT_SERIAL.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) #define log_esp3d(format, ...) DEBUG_OUTPUT_SERIAL.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define log_esp3dS(format, ...) DEBUG_OUTPUT_SERIAL.printf(format "\r\n", ##__VA_ARGS__) #define log_esp3ds(format, ...) DEBUG_OUTPUT_SERIAL.printf(format, ##__VA_ARGS__)
#endif //DEBUG_OUTPUT_SERIAL0 || DEBUG_OUTPUT_SERIAL1 || DEBUG_OUTPUT_SERIAL2 #endif //DEBUG_OUTPUT_SERIAL0 || DEBUG_OUTPUT_SERIAL1 || DEBUG_OUTPUT_SERIAL2
//Telnet //Telnet
@ -67,7 +67,7 @@ extern Telnet_Server telnet_debug;
#define DEBUG_ESP3D_NETWORK_HANDLE telnet_debug.handle(); #define DEBUG_ESP3D_NETWORK_HANDLE telnet_debug.handle();
#define DEBUG_ESP3D_NETWORK_END telnet_debug.end(); #define DEBUG_ESP3D_NETWORK_END telnet_debug.end();
#define log_esp3d(format, ...) if(telnet_debug.isConnected())telnet_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) #define log_esp3d(format, ...) if(telnet_debug.isConnected())telnet_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define log_esp3dS(format, ...) if(telnet_debug.isConnected())telnet_debug.printf(format "\r\n", ##__VA_ARGS__) #define log_esp3dS(format, ...) if(telnet_debug.isConnected())telnet_debug.printf(format , ##__VA_ARGS__)
#endif // DEBUG_OUTPUT_TELNET #endif // DEBUG_OUTPUT_TELNET
//Telnet //Telnet
@ -81,11 +81,11 @@ extern WebSocket_Server websocket_debug;
#define DEBUG_ESP3D_NETWORK_HANDLE websocket_debug.handle(); #define DEBUG_ESP3D_NETWORK_HANDLE websocket_debug.handle();
#define DEBUG_ESP3D_NETWORK_END websocket_debug.end(); #define DEBUG_ESP3D_NETWORK_END websocket_debug.end();
#define log_esp3d(format, ...) websocket_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) #define log_esp3d(format, ...) websocket_debug.printf("[ESP3D][%s:%u] %s(): " format "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define log_esp3dS(format, ...) websocket_debug.printf(format "\r\n", ##__VA_ARGS__) #define log_esp3dS(format, ...) websocket_debug.printf(format, ##__VA_ARGS__)
#endif // DEBUG_OUTPUT_WEBSOCKET #endif // DEBUG_OUTPUT_WEBSOCKET
#else #else
#define log_esp3d(format, ...) #define log_esp3d(format, ...)
#define log_esp3dS(format, ...) #define log_esp3ds(format, ...)
#endif //ESP_DEBUG_FEATURE #endif //ESP_DEBUG_FEATURE
#endif //_DEBUG_ESP3D_H #endif //_DEBUG_ESP3D_H

View File

@ -70,6 +70,10 @@ const char * help[]= {"[ESP] - display this help",
"[ESP180](State) - display/set FTP state which can be ON, OFF", "[ESP180](State) - display/set FTP state which can be ON, OFF",
"[ESP181](ctrl=xxxx) (active=xxxx) (passive=xxxx) - display/set FTP ports", "[ESP181](ctrl=xxxx) (active=xxxx) (passive=xxxx) - display/set FTP ports",
#endif //FTP_FEATURE #endif //FTP_FEATURE
#if defined(WEBDAV_FEATURE)
"[ESP190](State) - display/set WebDav state which can be ON, OFF",
"[ESP191](Port) - display/set WebDav port",
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE) #if defined (SD_DEVICE)
"[ESP200] - display SD Card Status", "[ESP200] - display SD Card Status",
#endif //SD_DEVICE #endif //SD_DEVICE
@ -191,6 +195,10 @@ const uint cmdlist[]= {0,
180, 180,
181, 181,
#endif //FTP_FEATURE #endif //FTP_FEATURE
#if defined(WEBDAV_FEATURE)
190,
111,
#endif //WEBDAV_FEATURE
#if defined (SD_DEVICE) #if defined (SD_DEVICE)
200, 200,
#endif //SD_DEVICE #endif //SD_DEVICE

View File

@ -0,0 +1,74 @@
/*
ESP190.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/webdav/webdav_server.h"
//Set WebDav state which can be ON, OFF, CLOSE
//[ESP190]<state>pwd=<admin password>
bool Commands::ESP190(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool response = true;
String parameter;
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
output->printMSG((Settings_ESP3D::read_byte(ESP_WEBDAV_ON) == 0)?"OFF":"ON");
webdav_server.dir();
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#endif //AUTHENTICATION_FEATURE
parameter.toUpperCase();
if (!((parameter == "ON") || (parameter == "OFF") || (parameter == "CLOSE"))) {
output->printERROR("Only ON or OFF or CLOSE mode supported!");
return false;
} else {
if (parameter == "CLOSE") {
webdav_server.closeClient();
output->printMSG ("ok");
} else {
if (!Settings_ESP3D::write_byte (ESP_WEBDAV_ON, (parameter == "ON")?1:0)) {
output->printERROR ("Set failed!");
response = false;
}
output->printMSG ("ok");
}
}
}
return response;
}
#endif //WEBDAV_FEATURE

View File

@ -0,0 +1,66 @@
/*
ESP191.cpp - ESP3D command class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
//Set webdav port
//[ESP191]<port>pwd=<admin password>
bool Commands::ESP191(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
{
bool response = true;
String parameter;
#ifdef AUTHENTICATION_FEATURE
if (auth_type == LEVEL_GUEST) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#else
(void)auth_type;
#endif //AUTHENTICATION_FEATURE
parameter = get_param (cmd_params, "");
//get
if (parameter.length() == 0) {
output->printMSG(String(Settings_ESP3D::read_uint32(ESP_WEBDAV_PORT)).c_str());
} else { //set
#ifdef AUTHENTICATION_FEATURE
if (auth_type != LEVEL_ADMIN) {
output->printERROR("Wrong authentication!", 401);
return false;
}
#endif //AUTHENTICATION_FEATURE
uint ibuf = parameter.toInt();
if ((ibuf > Settings_ESP3D::get_max_int32_value(ESP_WEBDAV_PORT)) || (ibuf < Settings_ESP3D::get_min_int32_value(ESP_WEBDAV_PORT))) {
output->printERROR ("Incorrect port!");
return false;
}
if (!Settings_ESP3D::write_uint32 (ESP_WEBDAV_PORT, ibuf)) {
output->printERROR ("Set failed!");
response = false;
} else {
output->printMSG ("ok");
}
}
return response;
}
#endif //WEBDAV_FEATURE

View File

@ -262,7 +262,25 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type,
output->print (Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT)); output->print (Settings_ESP3D::get_min_int32_value(ESP_WEBSOCKET_PORT));
output->print ("\"}"); output->print ("\"}");
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
//WebDav On service
output->print (",{\"F\":\"service/webdavp\",\"P\":\"");
output->print (ESP_WEBDAV_ON);
output->print ("\",\"T\":\"B\",\"V\":\"");
output->print (Settings_ESP3D::read_byte(ESP_WEBDAV_ON));
output->print ("\",\"H\":\"enable\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}");
//WebDav Port
output->print (",{\"F\":\"service/webdavp\",\"P\":\"");
output->print (ESP_WEBDAV_PORT);
output->print ("\",\"T\":\"I\",\"V\":\"");
output->print (Settings_ESP3D::read_uint32(ESP_WEBDAV_PORT));
output->print ("\",\"H\":\"port\",\"S\":\"");
output->print (Settings_ESP3D::get_max_int32_value(ESP_WEBDAV_PORT));
output->print ("\",\"M\":\"");
output->print (Settings_ESP3D::get_min_int32_value(ESP_WEBDAV_PORT));
output->print ("\"}");
#endif //WEBDAV_FEATURE
#ifdef FTP_FEATURE #ifdef FTP_FEATURE
//FTP On service/ftp //FTP On service/ftp
output->print (",{\"F\":\"service/ftp\",\"P\":\""); output->print (",{\"F\":\"service/ftp\",\"P\":\"");

View File

@ -50,6 +50,9 @@
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
#include "../../modules/websocket/websocket_server.h" #include "../../modules/websocket/websocket_server.h"
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
#include "../../modules/webdav/webdav_server.h"
#endif //WEBDAV_FEATURE
#if defined (TIMESTAMP_FEATURE) #if defined (TIMESTAMP_FEATURE)
#include "../../modules/time/time_server.h" #include "../../modules/time/time_server.h"
#endif //TIMESTAMP_FEATURE #endif //TIMESTAMP_FEATURE
@ -418,6 +421,43 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
} }
} }
#endif //TELNET_FEATURE #endif //TELNET_FEATURE
#if defined (WEBDAV_FEATURE)
if (webdav_server.started()) {
//WebDav port
if (!plain) {
output->print (",{\"id\":\"");
}
output->print ("WebDav port");
if (!plain) {
output->print ("\",\"value\":\"");
} else {
output->print (": ");
}
output->printf ("%d",webdav_server.port());
if (!plain) {
output->print ("\"}");
} else {
output->printLN("");
}
}
if (webdav_server.isConnected()) {
if (!plain) {
output->print (",{\"id\":\"");
}
output->print ("WebDav Client");
if (!plain) {
output->print ("\",\"value\":\"");
} else {
output->print (": ");
}
output->printf ("%s",webdav_server.clientIPAddress());
if (!plain) {
output->print ("\"}");
} else {
output->printLN("");
}
}
#endif //WEBDAV_FEATURE
#if defined (FTP_FEATURE) #if defined (FTP_FEATURE)
if (ftp_server.started()) { if (ftp_server.started()) {
//ftp ports //ftp ports

View File

@ -110,6 +110,7 @@
#define DEFAULT_SENSOR_TYPE NO_SENSOR_DEVICE #define DEFAULT_SENSOR_TYPE NO_SENSOR_DEVICE
#define DEFAULT_HTTP_ON 1 #define DEFAULT_HTTP_ON 1
#define DEFAULT_FTP_ON 1 #define DEFAULT_FTP_ON 1
#define DEFAULT_WEBDAV_ON 1
#define DEFAULT_TELNET_ON 1 #define DEFAULT_TELNET_ON 1
#define DEFAULT_WEBSOCKET_ON 1 #define DEFAULT_WEBSOCKET_ON 1
#define DEFAULT_NOTIFICATION_TYPE 0 #define DEFAULT_NOTIFICATION_TYPE 0
@ -127,6 +128,7 @@
#define DEFAULT_FTP_ACTIVE_PORT 20L #define DEFAULT_FTP_ACTIVE_PORT 20L
#define DEFAULT_FTP_PASSIVE_PORT 55600L #define DEFAULT_FTP_PASSIVE_PORT 55600L
#define DEFAULT_WEBSOCKET_PORT 8282L #define DEFAULT_WEBSOCKET_PORT 8282L
#define DEFAULT_WEBDAV_PORT 8181L
#define DEFAULT_TELNET_PORT 23L #define DEFAULT_TELNET_PORT 23L
#define DEFAULT_SENSOR_INTERVAL 30000L #define DEFAULT_SENSOR_INTERVAL 30000L
#define DEFAULT_BOOT_DELAY 10000L #define DEFAULT_BOOT_DELAY 10000L
@ -316,6 +318,11 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos)
res = DEFAULT_WEBSOCKET_ON; res = DEFAULT_WEBSOCKET_ON;
break; break;
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
case ESP_WEBDAV_ON:
res = DEFAULT_WEBDAV_ON;
break;
#endif //WEBDAV_FEATURE
#ifdef SD_DEVICE #ifdef SD_DEVICE
case ESP_SD_SPEED_DIV: case ESP_SD_SPEED_DIV:
res = DEFAULT_SDREADER_SPEED; res = DEFAULT_SDREADER_SPEED;
@ -413,6 +420,11 @@ uint32_t Settings_ESP3D::get_default_int32_value(int pos)
res = DEFAULT_WEBSOCKET_PORT; res = DEFAULT_WEBSOCKET_PORT;
break; break;
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
case ESP_WEBDAV_PORT:
res = DEFAULT_WEBDAV_PORT;
break;
#endif //WEBDAV_FEATURE
#if defined(SENSOR_DEVICE) #if defined(SENSOR_DEVICE)
case ESP_SENSOR_INTERVAL: case ESP_SENSOR_INTERVAL:
res = DEFAULT_SENSOR_INTERVAL; res = DEFAULT_SENSOR_INTERVAL;
@ -449,6 +461,11 @@ uint32_t Settings_ESP3D::get_max_int32_value(int pos)
res = MAX_TELNET_PORT; res = MAX_TELNET_PORT;
break; break;
#endif //TELNET_FEATURE #endif //TELNET_FEATURE
#ifdef WEBDAV_FEATURE
case ESP_WEBDAV_PORT:
res = MAX_WEBDAV_PORT;
break;
#endif //WEBDAV_FEATURE
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
case ESP_WEBSOCKET_PORT: case ESP_WEBSOCKET_PORT:
res = MAX_WEBSOCKET_PORT; res = MAX_WEBSOCKET_PORT;
@ -495,6 +512,11 @@ uint32_t Settings_ESP3D::get_min_int32_value(int pos)
res = MIN_WEBSOCKET_PORT; res = MIN_WEBSOCKET_PORT;
break; break;
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
case ESP_WEBDAV_PORT:
res = MIN_WEBDAV_PORT;
break;
#endif //WEBDAV_FEATURE
#if defined(SENSOR_DEVICE) #if defined(SENSOR_DEVICE)
case ESP_SENSOR_INTERVAL: case ESP_SENSOR_INTERVAL:
res = MIN_SENSOR_INTERVAL; res = MIN_SENSOR_INTERVAL;
@ -1125,13 +1147,18 @@ bool Settings_ESP3D::reset(bool networkonly)
//TELNET Port //TELNET Port
Settings_ESP3D::write_uint32 (ESP_TELNET_PORT, Settings_ESP3D::get_default_int32_value(ESP_TELNET_PORT)); Settings_ESP3D::write_uint32 (ESP_TELNET_PORT, Settings_ESP3D::get_default_int32_value(ESP_TELNET_PORT));
#endif //TELNET #endif //TELNET
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
//Websocket On //Websocket On
Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_ON)); Settings_ESP3D::write_byte(ESP_WEBSOCKET_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBSOCKET_ON));
//Websocket Port //Websocket Port
Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBSOCKET_PORT)); Settings_ESP3D::write_uint32 (ESP_WEBSOCKET_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBSOCKET_PORT));
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
//WebDav On
Settings_ESP3D::write_byte(ESP_WEBDAV_ON,Settings_ESP3D::get_default_byte_value(ESP_WEBDAV_ON));
//WebDav Port
Settings_ESP3D::write_uint32 (ESP_WEBDAV_PORT, Settings_ESP3D::get_default_int32_value(ESP_WEBDAV_PORT));
#endif //WEBDAV_FEATURE
#ifdef AUTHENTICATION_FEATURE #ifdef AUTHENTICATION_FEATURE
//Admin password //Admin password
Settings_ESP3D::write_string(ESP_ADMIN_PWD,Settings_ESP3D::get_default_string_value(ESP_ADMIN_PWD).c_str()); Settings_ESP3D::write_string(ESP_ADMIN_PWD,Settings_ESP3D::get_default_string_value(ESP_ADMIN_PWD).c_str());

View File

@ -102,7 +102,8 @@
#define ESP_FTP_ON 1021 //1 byte = flag #define ESP_FTP_ON 1021 //1 byte = flag
#define ESP_AUTO_NOTIFICATION 1022 //1 byte = flag #define ESP_AUTO_NOTIFICATION 1022 //1 byte = flag
#define ESP_VERBOSE_BOOT 1023 //1 byte = flag #define ESP_VERBOSE_BOOT 1023 //1 byte = flag
#define ESP_WEBDAV_ON 1024 //1 byte = flag
#define ESP_WEBDAV_PORT 1025 //4 bytes= int
//Hidden password //Hidden password
#define HIDDEN_PASSWORD "********" #define HIDDEN_PASSWORD "********"

View File

@ -151,6 +151,10 @@
#define ESP_FILE_WRITE 1 #define ESP_FILE_WRITE 1
#define ESP_FILE_APPEND 2 #define ESP_FILE_APPEND 2
#define ESP_SEEK_SET 0
#define ESP_SEEK_CUR 1
#define ESP_SEEK_END 2
#define FS_ROOT 0 #define FS_ROOT 0
#define FS_FLASH 1 #define FS_FLASH 1
#define FS_SD 2 #define FS_SD 2

View File

@ -133,6 +133,27 @@
#endif #endif
#endif #endif
/**************************
* WebDav
* ***********************/
#if defined(WEBDAV_FEATURE) && !defined(GLOBAL_FILESYSTEM_FEATURE)
#if WEBDAV_FEATURE == FS_ROOT
#error WEBDAV_FEATURE == FS_ROOT is not available because GLOBAL_FILESYSTEM_FEATURE is not enabled
#endif
#endif
#if defined(WEBDAV_FEATURE) && !defined(FILESYSTEM_FEATURE)
#if WEBDAV_FEATURE == FS_FLASH
#error WEBDAV_FEATURE == FS_FLASH is not available because FILESYSTEM_FEATURE is not enabled
#endif
#endif
#if defined(WEBDAV_FEATURE) && !defined(SD_DEVICE)
#if WEBDAV_FEATURE == FS_SD
#error WEBDAV_FEATURE == FS_SD is not available because SD_DEVICE is not enabled
#endif
#endif
/************************** /**************************
* Update * Update
* ***********************/ * ***********************/

View File

@ -35,6 +35,7 @@ public:
~ESP_File(); ~ESP_File();
operator bool() const; operator bool() const;
bool isDirectory(); bool isDirectory();
bool seek(uint32_t pos, uint8_t mode = ESP_SEEK_SET);
const char* name() const; const char* name() const;
const char* filename() const; const char* filename() const;
void close(); void close();
@ -70,6 +71,7 @@ public:
static size_t totalBytes(); static size_t totalBytes();
static size_t usedBytes(); static size_t usedBytes();
static size_t freeBytes(); static size_t freeBytes();
static uint maxPathLength();
static size_t max_update_size(); static size_t max_update_size();
static const char * FilesystemName(); static const char * FilesystemName();
static bool format(); static bool format();

View File

@ -102,6 +102,22 @@ uint64_t ESP_GBFS::usedBytes(uint8_t FS)
return 0; return 0;
} }
uint ESP_GBFS::maxPathLength()
{
uint size = 255;
#ifdef FILESYSTEM_FEATURE
if(size >32) {
size =32;
}
#endif //FILESYSTEM_FEATURE
#ifdef SD_DEVICE
if(size >255) {
size =255;
}
#endif //SD_DEVICE
return size;
}
uint64_t ESP_GBFS::freeBytes(uint8_t FS) uint64_t ESP_GBFS::freeBytes(uint8_t FS)
{ {
#ifdef FILESYSTEM_FEATURE #ifdef FILESYSTEM_FEATURE
@ -431,6 +447,25 @@ ESP_GBFile::operator bool() const
return false; return false;
} }
bool ESP_GBFile::seek(uint32_t pos, uint8_t mode)
{
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)
if (_type == FS_ROOT) {
//TBD
}
#endif //FILESYSTEM_FEATURE || SD_DEVICE
#ifdef FILESYSTEM_FEATURE
if (_type == FS_FLASH) {
_flashFile.seek(pos,mode);
}
#endif //FILESYSTEM_FEATURE
#ifdef SD_DEVICE
if (_type == FS_SD) {
return _sdFile.seek(pos,mode);
}
#endif //SD_DEVICE
}
void ESP_GBFile::close() void ESP_GBFile::close()
{ {
#if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE) #if defined(FILESYSTEM_FEATURE) || defined(SD_DEVICE)

View File

@ -45,6 +45,7 @@ public:
~ESP_GBFile(); ~ESP_GBFile();
operator bool() const; operator bool() const;
bool isDirectory(); bool isDirectory();
bool seek(uint32_t pos, uint8_t mode = ESP_SEEK_SET);
const char* name() const; const char* name() const;
const char* shortname() const; const char* shortname() const;
const char* filename() const; const char* filename() const;
@ -80,10 +81,11 @@ private:
class ESP_GBFS class ESP_GBFS
{ {
public: public:
static bool isavailable(uint8_t FS); static bool isavailable(uint8_t FS=FS_UNKNOWN);
static uint64_t totalBytes(uint8_t FS); static uint64_t totalBytes(uint8_t FS=FS_UNKNOWN);
static uint64_t usedBytes(uint8_t FS); static uint64_t usedBytes(uint8_t FS=FS_UNKNOWN);
static uint64_t freeBytes(uint8_t FS); static uint64_t freeBytes(uint8_t FS=FS_UNKNOWN);
static uint maxPathLength();
static bool format(uint8_t FS, ESP3DOutput * output = nullptr); static bool format(uint8_t FS, ESP3DOutput * output = nullptr);
static ESP_GBFile open(const char* path, uint8_t mode = ESP_FILE_READ); static ESP_GBFile open(const char* path, uint8_t mode = ESP_FILE_READ);
static bool exists(const char* path); static bool exists(const char* path);

View File

@ -36,6 +36,7 @@ public:
~ESP_SDFile(); ~ESP_SDFile();
operator bool() const; operator bool() const;
bool isDirectory(); bool isDirectory();
bool seek(uint32_t pos, uint8_t mode = ESP_SEEK_SET);
const char* name() const; const char* name() const;
const char* shortname() const; const char* shortname() const;
const char* filename() const; const char* filename() const;
@ -76,6 +77,7 @@ public:
static uint64_t totalBytes(); static uint64_t totalBytes();
static uint64_t usedBytes(); static uint64_t usedBytes();
static uint64_t freeBytes(); static uint64_t freeBytes();
static uint maxPathLength();
static const char * FilesystemName(); static const char * FilesystemName();
static bool format(ESP3DOutput * output = nullptr); static bool format(ESP3DOutput * output = nullptr);
static ESP_SDFile open(const char* path, uint8_t mode = ESP_FILE_READ); static ESP_SDFile open(const char* path, uint8_t mode = ESP_FILE_READ);

View File

@ -53,6 +53,11 @@ size_t ESP_FileSystem::usedBytes()
return (FFat.totalBytes() - FFat.freeBytes()); return (FFat.totalBytes() - FFat.freeBytes());
} }
uint ESP_FileSystem::maxPathLength()
{
return 32;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{ {
return FFat.rename(oldpath,newpath); return FFat.rename(oldpath,newpath);
@ -235,6 +240,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
} }
} }
bool ESP_File::seek(uint32_t pos, uint8_t mode)
{
return tFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -57,6 +57,11 @@ size_t ESP_FileSystem::usedBytes()
return info.usedBytes; return info.usedBytes;
} }
uint ESP_FileSystem::maxPathLength()
{
return 32;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{ {
return LittleFS.rename(oldpath,newpath); return LittleFS.rename(oldpath,newpath);
@ -264,6 +269,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
} }
} }
bool ESP_File::seek(uint32_t pos, uint8_t mode)
{
return tFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -51,6 +51,11 @@ size_t ESP_FileSystem::usedBytes()
return SPIFFS.usedBytes(); return SPIFFS.usedBytes();
} }
uint ESP_FileSystem::maxPathLength()
{
return 32;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{ {
return SPIFFS.rename(oldpath,newpath); return SPIFFS.rename(oldpath,newpath);
@ -259,6 +264,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
} }
} }
bool ESP_File::seek(uint32_t pos, uint8_t mode)
{
return tFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -55,6 +55,11 @@ size_t ESP_FileSystem::usedBytes()
return info.usedBytes; return info.usedBytes;
} }
uint ESP_FileSystem::maxPathLength()
{
return 32;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath) bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{ {
return SPIFFS.rename(oldpath,newpath); return SPIFFS.rename(oldpath,newpath);
@ -284,6 +289,11 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
} }
} }
bool ESP_File::seek(uint32_t pos, uint8_t mode)
{
return tFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_File::close() void ESP_File::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -115,6 +115,11 @@ uint64_t ESP_SD::freeBytes()
return (SD.totalBytes() - SD.usedBytes()); return (SD.totalBytes() - SD.usedBytes());
} }
uint ESP_SD::maxPathLength()
{
return 255;
}
bool ESP_SD::rename(const char *oldpath, const char *newpath) bool ESP_SD::rename(const char *oldpath, const char *newpath)
{ {
return SD.rename(oldpath,newpath); return SD.rename(oldpath,newpath);
@ -283,6 +288,11 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
} }
} }
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
{
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_SDFile::close() void ESP_SDFile::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -171,6 +171,11 @@ uint64_t ESP_SD::freeBytes()
return volFree * blocks * 512; return volFree * blocks * 512;
} }
uint ESP_SD::maxPathLength()
{
return 255;
}
bool ESP_SD::rename(const char *oldpath, const char *newpath) bool ESP_SD::rename(const char *oldpath, const char *newpath)
{ {
return SD.rename(oldpath,newpath); return SD.rename(oldpath,newpath);
@ -712,6 +717,11 @@ bool ESP_SD::rmdir(const char *path)
return res; return res;
} }
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
{
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_SD::closeAll() void ESP_SD::closeAll()
{ {
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {

View File

@ -150,6 +150,11 @@ uint64_t ESP_SD::usedBytes()
return totalBytes() - freeBytes(); return totalBytes() - freeBytes();
} }
uint ESP_SD::maxPathLength()
{
return 255;
}
uint64_t ESP_SD::freeBytes() uint64_t ESP_SD::freeBytes()
{ {
static uint64_t volFree; static uint64_t volFree;
@ -711,6 +716,14 @@ void ESP_SD::closeAll()
} }
} }
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
{
if (mode == SeekEnd) {
return tSDFile_handle[_index].seek(-pos); //based on SDFS comment
}
return tSDFile_handle[_index].seek(pos);
}
ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path) ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * path)
{ {
_isdir = isdir; _isdir = isdir;

View File

@ -134,6 +134,11 @@ uint64_t ESP_SD::freeBytes()
return (SD_MMC.totalBytes() - SD_MMC.usedBytes()); return (SD_MMC.totalBytes() - SD_MMC.usedBytes());
} }
uint ESP_SD::maxPathLength()
{
return 255;
}
bool ESP_SD::rename(const char *oldpath, const char *newpath) bool ESP_SD::rename(const char *oldpath, const char *newpath)
{ {
return SD_MMC.rename(oldpath,newpath); return SD_MMC.rename(oldpath,newpath);
@ -305,6 +310,11 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
} }
} }
bool ESP_SDFile::seek(uint32_t pos, uint8_t mode)
{
return tSDFile_handle[_index].seek(pos, (SeekMode)mode);
}
void ESP_SDFile::close() void ESP_SDFile::close()
{ {
if (_index != -1) { if (_index != -1) {

View File

@ -21,6 +21,8 @@
//boundaries //boundaries
#define MAX_WEBDAV_PORT 65001
#define MIN_WEBDAV_PORT 1
#define MAX_HTTP_PORT 65001 #define MAX_HTTP_PORT 65001
#define MIN_HTTP_PORT 1 #define MIN_HTTP_PORT 1
#define MAX_FTP_PORT 65001 #define MAX_FTP_PORT 65001

View File

@ -52,6 +52,9 @@
#ifdef FTP_FEATURE #ifdef FTP_FEATURE
#include "../ftp/FtpServer.h" #include "../ftp/FtpServer.h"
#endif //FP_FEATURE #endif //FP_FEATURE
#ifdef WEBDAV_FEATURE
#include "../webdav/webdav_server.h"
#endif //WEBDAV_FEATURE
#ifdef HTTP_FEATURE #ifdef HTTP_FEATURE
#include "../http/http_server.h" #include "../http/http_server.h"
#endif //HTTP_FEATURE #endif //HTTP_FEATURE
@ -253,6 +256,18 @@ bool NetServices::begin()
} }
} }
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE
#ifdef WEBDAV_FEATURE
if (!webdav_server.begin()) {
output.printMSG("Failed start Terminal Web Socket");
} else {
if (webdav_server.started()) {
String stmp = "WebDav server started port " + String(webdav_server.port());
if (Settings_ESP3D::isVerboseBoot()) {
output.printMSG(stmp.c_str());
}
}
}
#endif //WEBDAV_FEATURE
#if defined(HTTP_FEATURE) #if defined(HTTP_FEATURE)
if (!websocket_terminal_server.begin()) { if (!websocket_terminal_server.begin()) {
output.printMSG("Failed start Terminal Web Socket"); output.printMSG("Failed start Terminal Web Socket");
@ -366,6 +381,9 @@ void NetServices::end()
#if defined(HTTP_FEATURE) #if defined(HTTP_FEATURE)
websocket_terminal_server.end(); websocket_terminal_server.end();
#endif //HTTP_FEATURE #endif //HTTP_FEATURE
#ifdef WEBDAV_FEATURE
webdav_server.end();
#endif //WEBDAV_FEATURE
#ifdef HTTP_FEATURE #ifdef HTTP_FEATURE
HTTP_Server::end(); HTTP_Server::end();
#endif //HTTP_FEATURE #endif //HTTP_FEATURE
@ -402,6 +420,9 @@ void NetServices::handle()
#ifdef HTTP_FEATURE #ifdef HTTP_FEATURE
HTTP_Server::handle(); HTTP_Server::handle();
#endif //HTTP_FEATURE #endif //HTTP_FEATURE
#ifdef WEBDAV_FEATURE
webdav_server.handle();
#endif //WEBDAV_FEATURE
#ifdef WS_DATA_FEATURE #ifdef WS_DATA_FEATURE
websocket_data_server.handle(); websocket_data_server.handle();
#endif //WS_DATA_FEATURE #endif //WS_DATA_FEATURE

View File

@ -95,6 +95,7 @@ const char * ServintKeysVal[] = {
"TELNET_Port", "TELNET_Port",
"SENSOR_INTERVAL", "SENSOR_INTERVAL",
"WebSocket_Port", "WebSocket_Port",
"WebDav_Port",
"FTP_Control_Port", "FTP_Control_Port",
"FTP_Active_Port ", "FTP_Active_Port ",
"FTP_Passive_Port" "FTP_Passive_Port"
@ -105,6 +106,7 @@ const uint16_t ServintKeysPos[] = {
ESP_TELNET_PORT, ESP_TELNET_PORT,
ESP_SENSOR_INTERVAL, ESP_SENSOR_INTERVAL,
ESP_WEBSOCKET_PORT, ESP_WEBSOCKET_PORT,
ESP_WEBDAV_PORT,
ESP_FTP_CTRL_PORT, ESP_FTP_CTRL_PORT,
ESP_FTP_DATA_ACTIVE_PORT, ESP_FTP_DATA_ACTIVE_PORT,
ESP_FTP_DATA_PASSIVE_PORT ESP_FTP_DATA_PASSIVE_PORT
@ -121,6 +123,7 @@ const uint16_t SysintKeysPos[] = {ESP_BAUD_RATE,
const char * ServboolKeysVal[] = {"HTTP_active", const char * ServboolKeysVal[] = {"HTTP_active",
"TELNET_active", "TELNET_active",
"WebSocket_active", "WebSocket_active",
"WebDav_active",
"Time_DST", "Time_DST",
"CHECK_FOR_UPDATE", "CHECK_FOR_UPDATE",
"Active_buzzer", "Active_buzzer",
@ -130,6 +133,7 @@ const char * ServboolKeysVal[] = {"HTTP_active",
const uint16_t ServboolKeysPos[] = {ESP_HTTP_ON, const uint16_t ServboolKeysPos[] = {ESP_HTTP_ON,
ESP_TELNET_ON, ESP_TELNET_ON,
ESP_WEBSOCKET_ON, ESP_WEBSOCKET_ON,
ESP_WEBDAV_ON,
ESP_TIME_IS_DST, ESP_TIME_IS_DST,
ESP_SD_CHECK_UPDATE_AT_BOOT, ESP_SD_CHECK_UPDATE_AT_BOOT,
ESP_BUZZER, ESP_BUZZER,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,230 @@
/*
Copyright (c) 2018 Gurpreet Bal https://github.com/ardyesp/ESPWebDAV
Copyright (c) 2020 David Gauchard https://github.com/d-a-v/ESPWebDAV
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
#ifndef __ESPWEBDAV_H
#define __ESPWEBDAV_H
#if defined(WEBDAV_LOCK_SUPPORT) || defined(DBG_WEBDAV)
#error WEBDAV_LOCK_SUPPORT or DBG_WEBDAV: cannot be defined by user
#endif
// LOCK support is not mandatory
// WEBDAV_LOCK_SUPPORT
// = 0: no support
// = 1: fake support
// > 1: supported with a std::map<>
#define WEBDAV_LOCK_SUPPORT 2
// constants for WebServer
#define CONTENT_LENGTH_UNKNOWN ((size_t) -1)
#define CONTENT_LENGTH_NOT_SET ((size_t) -2)
#define HTTP_MAX_POST_WAIT 5000
#if WEBDAV_LOCK_SUPPORT > 1
#include <map>
#endif
#include <functional>
#include <StreamString.h>
#include "../../include/esp3d_config.h"
class WiFiServer;
class WiFiClient;
#if WEBDAV_FEATURE == FS_ROOT
#include "../filesystem/esp_globalFS.h"
typedef ESP_GBFile WebDavFile;
typedef ESP_GBFS WebDavFS;
#endif //WEBDAV_FEATURE == FS_ROOT
#if WEBDAV_FEATURE == FS_FLASH
#include "../filesystem/esp_filesystem.h"
typedef ESP_File WebDavFile;
typedef ESP_FileSystem WebDavFS;
#endif //WEBDAV_FEATURE == FS_FLASH
#if WEBDAV_FEATURE == FS_SD
#include "../filesystem/esp_sd.h"
typedef ESP_SDFile WebDavFile;
typedef ESP_SD WebDavFS;
#endif //WEBDAV_FEATURE == FS_SD
class ESPWebDAVCore
{
public:
enum ResourceType { RESOURCE_NONE, RESOURCE_FILE, RESOURCE_DIR };
enum DepthType { DEPTH_NONE, DEPTH_CHILD, DEPTH_ALL };
typedef String(*ContentTypeFunction)(const String&);
using TransferStatusCallback = std::function<void(const char* name, int percent, bool receive)>;
void begin();
bool dirAction(
const String& path,
bool recursive,
const std::function<bool(int depth, const String& parent, WebDavFile& entry)>& cb,
bool callAfter = true,
int depth = 0);
void dir(const String& path, Print* out);
bool parseRequest(const String& method, const String& uri, WiFiClient* client, ContentTypeFunction contentType);
void setTransferStatusCallback(const TransferStatusCallback& cb)
{
transferStatusFn = cb;
}
static void stripSlashes(String& name);
static String date2date(time_t date);
static String enc2c(const String& encoded);
static String c2enc(const String& decoded);
protected:
static int htoi(char c);
static int hhtoi(const char* c);
static char itoH(int c);
//XXXFIXME this function must be replaced by some Stream::to()
size_t readBytesWithTimeout(uint8_t *buf, size_t size);
typedef void (ESPWebDAVCore::*THandlerFunction)(const String&);
bool copyFile(WebDavFile file, const String& destName);
bool deleteDir(const String& dir);
bool mkFullDir(String fullDir);
void processClient(THandlerFunction handler, const String& message);
void handleIssue(int code, const char* text);
//void handleReject(const String& rejectMessage);
void handleRequest();
void handleOptions(ResourceType resource);
void handleLock(ResourceType resource);
void handleUnlock(ResourceType resource);
void handlePropPatch(ResourceType resource, WebDavFile& file);
void handleProp(ResourceType resource, WebDavFile& file);
void handleGet(ResourceType resource, WebDavFile& file, bool isGet);
void handlePut(ResourceType resource);
void handleWriteError(const String& message, WebDavFile& wFile);
void handleDirectoryCreate(ResourceType resource);
void handleMove(ResourceType resource, WebDavFile& file);
void handleDelete(ResourceType resource);
void handleCopy(ResourceType resource, WebDavFile& file);
void sendPropResponse(bool isDir, const String& name, size_t size, time_t lastWrite, time_t creationTime);
void sendContentProp(const String& what, const String& response);
void sendHeader(const String& name, const String& value, bool first = false);
void send(const String& code, const char* content_type, const String& content);
void _prepareHeader(String& response, const String& code, const char* content_type, size_t contentLength);
bool sendContent(const String& content);
bool sendContent_P(PGM_P content);
bool sendContent(const char* data, size_t size);
void setContentLength(size_t len);
void processRange(const String& range);
int allowed(const String& uri, uint32_t ownash);
int allowed(const String& uri, const String& xml = emptyString);
void makeToken(String& ret, uint32_t pash, uint32_t ownash);
int extractLockToken(const String& someHeader, const char* start, const char* end, uint32_t& pash, uint32_t& ownash);
bool getPayload(StreamString& payload);
void stripName(String& name);
void stripHost(String& name);
String urlToUri(const String& url);
enum virt_e { VIRT_NONE, VIRT_PROC };
virt_e isVirtual(const String& uri);
size_t makeVirtual(virt_e v, String& internal);
// variables pertaining to current most HTTP request being serviced
constexpr static int m_persistent_timer_init_ms = 5000;
long unsigned int m_persistent_timer_ms;
bool m_persistent;
int _maxPathLength;
String method;
String uri;
StreamString payload;
WiFiClient* client = nullptr;
size_t contentLengthHeader;
String depthHeader;
String hostHeader;
String destinationHeader;
String overwrite;
String ifHeader;
String lockTokenHeader;
DepthType depth;
String _responseHeaders;
bool _chunked;
int _contentLengthAnswer;
int _rangeStart;
int _rangeEnd;
#if WEBDAV_LOCK_SUPPORT > 1
// infinite-depth exclusive locks
// map<crc32(path),crc32(owner)>
std::map<uint32_t, uint32_t> _locks;
#endif
ContentTypeFunction contentTypeFn = nullptr;
TransferStatusCallback transferStatusFn = nullptr;
};
class ESPWebDAV: public ESPWebDAVCore
{
public:
void begin(WiFiServer* srv)
{
ESPWebDAVCore::begin();
this->server = srv;
}
void end()
{
this->server = nullptr;
}
void handleClient();
WiFiClient & Client()
{
return locClient;
}
protected:
// Sections are copied from ESP8266Webserver
static String getMimeType(const String& path);
String urlDecode(const String& text);
bool parseRequest();
WiFiServer* server = nullptr;
WiFiClient locClient;
};
#endif // __ESPWEBDAV_H

View File

@ -0,0 +1,27 @@
#ifndef __POLLEDTIMING_H__
#define __POLLEDTIMING_H__
#include <Arduino.h>
class PolledTimeout
{
public:
PolledTimeout(uint32_t timeout)
{
_timeOut = timeout;
_startMS = millis();
}
operator bool() const
{
return ((millis() - _startMS) > _timeOut);
}
void reset()
{
_startMS = millis();
}
private:
uint32_t _startMS;
uint32_t _timeOut;
};
#endif

View File

@ -0,0 +1,162 @@
/*
Dead simple web-server.
Supports only one simultaneous client, knows how to handle GET and POST.
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
Simplified/Adapted for ESPWebDav:
Copyright (c) 2018 Gurpreet Bal https://github.com/ardyesp/ESPWebDAV
Copyright (c) 2020 David Gauchard https://github.com/d-a-v/ESPWebDAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
Modified 22 Jan 2021 by Luc Lebosse (ESP3D Integration)
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#include "ESPWebDAV.h"
// Sections are copied from ESP8266Webserver
String ESPWebDAV::getMimeType(const String& path)
{
if (path.endsWith(".html")) {
return "text/html";
} else if (path.endsWith(".htm")) {
return "text/html";
} else if (path.endsWith(".css")) {
return "text/css";
} else if (path.endsWith(".txt")) {
return "text/plain";
} else if (path.endsWith(".js")) {
return "application/javascript";
} else if (path.endsWith(".json")) {
return "application/json";
} else if (path.endsWith(".png")) {
return "image/png";
} else if (path.endsWith(".gif")) {
return "image/gif";
} else if (path.endsWith(".jpg")) {
return "image/jpeg";
} else if (path.endsWith(".ico")) {
return "image/x-icon";
} else if (path.endsWith(".svg")) {
return "image/svg+xml";
} else if (path.endsWith(".ttf")) {
return "application/x-font-ttf";
} else if (path.endsWith(".otf")) {
return "application/x-font-opentype";
} else if (path.endsWith(".woff")) {
return "application/font-woff";
} else if (path.endsWith(".woff2")) {
return "application/font-woff2";
} else if (path.endsWith(".eot")) {
return "application/vnd.ms-fontobject";
} else if (path.endsWith(".sfnt")) {
return "application/font-sfnt";
} else if (path.endsWith(".xml")) {
return "text/xml";
} else if (path.endsWith(".pdf")) {
return "application/pdf";
} else if (path.endsWith(".zip")) {
return "application/zip";
} else if (path.endsWith(".gz")) {
return "application/x-gzip";
} else if (path.endsWith(".appcache")) {
return "text/cache-manifest";
}
return "application/octet-stream";
}
String ESPWebDAV::urlDecode(const String& text)
{
String decoded = "";
char temp[] = "0x00";
unsigned int len = text.length();
unsigned int i = 0;
while (i < len) {
char decodedChar;
char encodedChar = text.charAt(i++);
if ((encodedChar == '%') && (i + 1 < len)) {
temp[2] = text.charAt(i++);
temp[3] = text.charAt(i++);
decodedChar = strtol(temp, NULL, 16);
} else {
if (encodedChar == '+') {
decodedChar = ' ';
} else {
decodedChar = encodedChar; // normal ascii char
}
}
decoded += decodedChar;
}
return decoded;
}
void ESPWebDAV::handleClient()
{
if (!server) {
return;
}
if (server->hasClient()) {
if (!locClient || !locClient.available()) {
// no or sleeping current client
// take it over
locClient = server->available();
m_persistent_timer_ms = millis();
log_esp3d("NEW CLIENT-------------------------------------------------------");
}
}
if (!locClient || !locClient.available()) {
return;
}
// extract uri, headers etc
parseRequest();
if (!m_persistent)
// close the connection
{
locClient.stop();
}
}
bool ESPWebDAV::parseRequest()
{
// Read the first line of HTTP request
String req = locClient.readStringUntil('\r');
locClient.readStringUntil('\n');
// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
return false;
}
method = req.substring(0, addr_start);
uri = urlDecode(req.substring(addr_start + 1, addr_end));
return ESPWebDAVCore::parseRequest(method, uri, &locClient, getMimeType);
}
#endif //WEBDAV_FEATURE

View File

@ -0,0 +1,116 @@
/*
webdav_server.cpp - webdav server functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (WEBDAV_FEATURE)
#include <WiFiServer.h>
#include <WiFiClient.h>
#include "webdav_server.h"
#include "../../core/settings_esp3d.h"
#include "../../core/esp3doutput.h"
#include "../../core/commands.h"
Webdav_Server webdav_server;
void Webdav_Server::closeClient()
{
if(_dav.Client()) {
_dav.Client().stop();
}
}
void Webdav_Server::dir()
{
_dav.dir("/", &Serial);
};
bool Webdav_Server::isConnected()
{
if ( !_started) {
return false;
}
if (_dav.Client()) {
return (_dav.Client().connected());
}
return false;
}
const char* Webdav_Server::clientIPAddress()
{
static String res;
res = "0.0.0.0";
if (_dav.Client() && _dav.Client().connected()) {
res = _dav.Client().remoteIP().toString();
}
return res.c_str();
}
Webdav_Server::Webdav_Server()
{
_started = false;
_port = 0;
}
Webdav_Server::~Webdav_Server()
{
end();
}
/**
* begin WebDav setup
*/
bool Webdav_Server::begin()
{
end();
if (Settings_ESP3D::read_byte(ESP_WEBDAV_ON) !=1) {
return true;
}
_port = Settings_ESP3D::read_uint32(ESP_WEBDAV_PORT);
_tcpserver.begin(_port);
_dav.begin(&_tcpserver);
_started = true;
return _started;
}
/**
* End WebDav
*/
void Webdav_Server::end()
{
_started = false;
_port = 0;
closeClient();
_tcpserver.stop();
_dav.end();
}
bool Webdav_Server::started()
{
return _started;
}
void Webdav_Server::handle()
{
_dav.handleClient();
}
#endif //WEBDAV_FEATURE

View File

@ -0,0 +1,54 @@
/*
webdav_server.h - webdav service functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with This code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _WEBDAV_SERVER_H
#define _WEBDAV_SERVER_H
#include "ESPWebDAV.h"
class WiFiServer;
class Webdav_Server
{
public:
Webdav_Server();
~Webdav_Server();
bool begin();
void end();
void handle();
bool started();
bool isConnected();
const char* clientIPAddress();
uint16_t port()
{
return _port;
}
void dir();
void closeClient();
private:
bool _started;
uint16_t _port;
WiFiServer _tcpserver;
ESPWebDAV _dav;
};
extern Webdav_Server webdav_server;
#endif