Skip to content

Commit a885afc

Browse files
committed
Update documentation
Remove SDFat2 warning Add several sanity check Fix some edge cases in authentication process Remove debug messages Clarify some status in http handler responses
1 parent 3331c47 commit a885afc

File tree

12 files changed

+652
-442
lines changed

12 files changed

+652
-442
lines changed

docs/Commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ label can be: light/framesize/quality/contrast/brightness/saturation/gainceiling
300300

301301
* Get state / Set Enable / Disable Serial Bridge Communication
302302
`[ESP930]<ENABLE/DISABLE> json=<no> pwd=<admin/user password>`
303+
303304
* Get / Set Serial Bridge Baud Rate
304305
`[ESP931]<BAUD RATE> json=<no> pwd=<admin/user password>`
305306

306-
307307
* Set quiet boot if strapping pin is High
308308
`[ESP999]QUIETBOOT pwd=<admin/user password>`

docs/Handlers.md

Lines changed: 137 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,161 @@
1-
# Web Handlers in ESP3D
1+
# Web Handlers
22

3-
#### /
3+
### /
44
root is the default handler where all files will be served, if no file is defined, it looks for index.html or index.html.gz (compressed)
55
if you call specific file, it will look for the filename and filename.gz (compressed)
66
if no file is defined and there is not index.html(.gz) it will display embedded page
77
another way to show the embedded page is /?forcefallback=yes
88

9-
#### /sd/
10-
it will serve any file from SD card if there is one
9+
### /sd/
10+
it will serve any file from SD card if there is one, it is only a wrapper to read SD card, no upload
1111

12-
#### /files
13-
this handler handle all commands for FS, including upload on FS
12+
### /files
13+
this handler handle all commands for FS, including upload on FS.
14+
possible options/arguments are:
15+
- `quiet=yes` can be used when you don't want list files but just upload them
16+
- `path=...` define the path to the file
17+
- `action=...` define the action to execute which can be:
18+
- delete
19+
delete the file defined by `filename=...` it will also use `path=...` to do full path
20+
- deletedir
21+
delete the directory defined by `filename=...` it will also use `path=...` to do full path
22+
- createdir
23+
create the directory defined by `filename=...` it will also use `path=...` to do full path
24+
- `createPath=yes` when doing upload and the path do not exists, it will create it, POST only
25+
- `<filename>S=...` give the size of uploaded file with <filename> name, need to be set before file is set in upload, POST only
1426

15-
#### /sdfiles
27+
the output is a json file:
28+
29+
```
30+
{
31+
"files":[ //the files list
32+
{
33+
"name":"index.html.gz", //the name of the file
34+
"size":"83.46 KB", //the formated size of the file
35+
"time":"2022-09-04 11:56:05" //the time when the file was modified last time, this one is optional and depend on (FILESYSTEM_TIMESTAMP_FEATURE)
36+
},
37+
{
38+
"name":"subdir", //the name of the file / directory
39+
"size":"-1", //the size is -1 because it is a directory
40+
"time":"" //no time for directories optional as depend on (FILESYSTEM_TIMESTAMP_FEATURE)
41+
}
42+
],
43+
"path":"/", //current path
44+
"occupation":"52", //% of occupation
45+
"status":"subdir created", //status
46+
"total":"192.00 KB", //Formated total space of Filesystem
47+
"used":"100.00 KB" //Formated used space of Filesystem
48+
}
49+
```
50+
### /sdfiles
1651
this handler handle all commands for SD, including upload on SD (only shared and direct SD)
52+
this handler handle all commands for FS, including upload on FS.
53+
possible options/arguments are:
54+
- `quiet=yes` can be used when you don't want list files but just upload them
55+
- `path=...` define the path to the file
56+
- `action=...` define the action to execute which can be:
57+
- list
58+
Will refresh the stats of the files
59+
- delete
60+
delete the file defined by `filename=...` it will also use `path=...` to do full path
61+
- deletedir
62+
delete the directory defined by `filename=...` it will also use `path=...` to do full path
63+
- createdir
64+
create the directory defined by `filename=...` it will also use `path=...` to do full path
65+
- `createPath=yes` when doing upload and the path do not exists, it will create it, POST only
66+
- `<filename>S=...` give the size of uploaded file with <filename> name, need to be set before file is set in upload, POST only
67+
68+
the output is a json file:
1769

18-
#### /upload
19-
this handler is for MKS boards using MKS communication protocol if enabled, it handle all commands for SD, including upload on SD
70+
```
71+
{
72+
"files":[ //the files list
73+
{
74+
"name":"3Oc-pika2.gco",//the name of the file
75+
"shortname":"3Oc-pika2.gco", //the 8.3 shortname if available, if not the name of the file
76+
"size":"83.46 KB", //the formated size of the file
77+
"time":"2022-09-04 11:56:05" //the time when the file was modified last time, this one is optional and depend on (SD_TIMESTAMP_FEATURE)
78+
},
79+
{
80+
"name":"subdir", //the name of the file / directory
81+
"size":"-1", //the size is -1 because it is a directory
82+
"time":"" //no time for directories optional as depend on (SD_TIMESTAMP_FEATURE)
83+
}
84+
],
85+
"path":"/", //current path
86+
"occupation":"52", //% of occupation
87+
"status":"subdir created", //status
88+
"total":"192.00 KB", //Formated total space of Filesystem
89+
"used":"100.00 KB" //Formated used space of Filesystem
90+
}
91+
```
92+
### /upload
93+
this handler is for MKS boards using MKS communication protocol if enabled, it handle only upload on SD
2094

21-
#### /command
22-
this handler is for all commands
95+
### /command
96+
this handler is for all commands the parameter is `cmd=...`
97+
if it is an `[ESPXXX]` command the answer is the `[ESPXXX]` response
98+
if it is not an `[ESPXXX]` command the answer is `ESP3D says: command forwarded` and can be ignored
2399

24-
#### /login
100+
### /login
25101
this handler is for authentication function if enabled
102+
possible options/arguments are:
103+
- `DISCONNECT=YES`
104+
it will clear current session, remove authentication cookie, set status to `disconnected` and response code to 401
105+
- `SUBMIT=YES`
106+
to login it will need also `PASSWORD=...` and `USER=...`, the answer will be 200 if success and 401 if failed
107+
if user is already authenticated it can use `NEWPASSWORD=...` instead of `PASSWORD=...` to change his password, if successful answer will be returned with code 200, otherwise code will be 500 if change failed or if password format is invalid
108+
109+
Output:
26110

27-
#### /config
28-
this handler is a shortcut to [ESP420] command
111+
- if authentified and no submission:
112+
`{"status":"Identified","authentication_lvl":"admin"}` and code 200
113+
- if not authenticated and no submission:
114+
`{"status":"Wrong authentication!","authentication_lvl":"guest"}` and code 401
29115

30-
#### /updatefw
116+
117+
### /config
118+
this handler is a shortcut to [ESP420] command in text mode, to get output in json add `json=yes`
119+
120+
### /updatefw
31121
this handler is for FW upload and update
122+
Answer output is :
123+
`{"status":"..."}` if upload is successful the ESP will restart
32124

33-
#### /snap
125+
### /snap
34126
this handler is on esp32cam with camera enabled to capture a Frame
127+
it answer by sending a jpg image
35128

36-
#### /description.xml
37-
this handler is for SSDP if enabled to present device informations
129+
### /description.xml
130+
this handler is for SSDP if enabled to present device informations
38131

39-
#### Captive portal bypass handlers
132+
```
133+
<root xmlns="urn:schemas-upnp-org:device-1-0">
134+
<specVersion>
135+
<major>1</major>
136+
<minor>0</minor>
137+
</specVersion>
138+
<URLBase>http://192.168.2.178:80/</URLBase>
139+
<device>
140+
<deviceType>urn:schemas-upnp-org:device:upnp:rootdevice:1</deviceType>
141+
<friendlyName>esp3d</friendlyName>
142+
<presentationURL>/</presentationURL>
143+
<serialNumber>52332</serialNumber>
144+
<modelName>ESP Board</modelName>
145+
<modelDescription/>
146+
<modelNumber>ESP3D 3.0</modelNumber>
147+
<modelURL>https://www.espressif.com/en/products/devkits</modelURL>
148+
<manufacturer>Espressif Systems</manufacturer>
149+
<manufacturerURL>https://www.espressif.com</manufacturerURL>
150+
<UDN>uuid:38323636-4558-4dda-9188-cda0e600cc6c</UDN>
151+
<serviceList/>
152+
<iconList/>
153+
</device>
154+
</root>
155+
```
156+
### Captive portal bypass handlers
40157
to avoid a redirect to index.html and so a refresh of the page, some classic handler have been added so they all go to / handler actually
41158
- /generate_204
42159
- /gconnectivitycheck.gstatic.com
43160
- /fwlink/
161+

esp3d/src/include/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _VERSION_ESP3D_H
2323

2424
//version and sources location
25-
#define FW_VERSION "3.0.0.a210"
25+
#define FW_VERSION "3.0.0.a211"
2626
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
2727

2828
#endif //_VERSION_ESP3D_H

esp3d/src/modules/http/handles/handle-SD-files.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void HTTP_Server::handleSDFileList ()
4848

4949
if (_webserver->hasArg ("quiet")) {
5050
if(_webserver->arg ("quiet") == "yes") {
51-
Serial.println("quiet");
52-
_webserver->send (200, "text/plain", "{\"status\":\"ok\"}");
51+
status = "{\"status\":\"" + status + "\"}";
52+
_webserver->send (200, "text/plain", status.c_str());
5353
return;
5454
}
5555
}
@@ -184,11 +184,13 @@ void HTTP_Server::handleSDFileList ()
184184
}
185185
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
186186
buffer2send+="\",\"time\":\"";
187-
time_t t = sub.getLastWrite();
188-
struct tm * tmstruct = localtime(&t);
189-
char str[20]; //buffer should be 20
190-
sprintf(str,"%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
191-
buffer2send+=str;
187+
if (!sub.isDirectory()) {
188+
time_t t = sub.getLastWrite();
189+
struct tm * tmstruct = localtime(&t);
190+
char str[20]; //buffer should be 20
191+
sprintf(str,"%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
192+
buffer2send+=str;
193+
}
192194
#endif //FILESYSTEM_TIMESTAMP_FEATURE
193195
buffer2send+="\"}";
194196
if (buffer2send.length() > 1100) {

esp3d/src/modules/http/handles/handle-config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void HTTP_Server::handle_config ()
3535
{
3636
level_authenticate_type auth_level = AuthenticationService::authenticated_level();
3737
String cmd = "[ESP420]";
38+
if (_webserver->hasArg("json")) {
39+
cmd = "[ESP420]json="+_webserver->arg("json");
40+
}
3841
ESP3DOutput output(_webserver);
3942
output.printMSGLine("<pre>");
4043
esp3d_commands.process((uint8_t*)cmd.c_str(), cmd.length(), &output, auth_level);

esp3d/src/modules/http/handles/handle-files.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ void HTTP_Server::handleFSFileList ()
5050
}
5151
if (_webserver->hasArg ("quiet")) {
5252
if(_webserver->arg ("quiet") == "yes") {
53-
Serial.println("quiet");
54-
_webserver->send (200, "text/plain", "{\"status\":\"ok\"}");
53+
status = "{\"status\":\"" + status + "\"}";
54+
_webserver->send (200, "text/plain", status.c_str());
5555
return;
5656
}
5757
}
@@ -165,7 +165,9 @@ void HTTP_Server::handleFSFileList ()
165165
}
166166
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
167167
buffer2send+="\",\"time\":\"";
168-
buffer2send+=timeserver.current_time(sub.getLastWrite());
168+
if (!sub.isDirectory()) {
169+
buffer2send+=timeserver.current_time(sub.getLastWrite());
170+
}
169171
#endif //FILESYSTEM_TIMESTAMP_FEATURE
170172
buffer2send+="\"}";
171173
if (buffer2send.length() > 1100) {

esp3d/src/modules/http/handles/handle-login.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void HTTP_Server::handle_login()
3737
int code = 401;
3838
String status = "Wrong authentication!";
3939
//Disconnect can be done anytime no need to check credential
40-
if (_webserver->hasArg("DISCONNECT")) {
40+
if (_webserver->hasArg("DISCONNECT") && _webserver->arg("DISCONNECT")=="YES") {
4141
AuthenticationService::ClearCurrentSession();
4242
_webserver->sendHeader("Set-Cookie","ESPSESSIONID=0");
4343
_webserver->sendHeader("Cache-Control","no-cache");
@@ -96,7 +96,12 @@ void HTTP_Server::handle_login()
9696
}
9797
}
9898
}
99-
}//SUBMIT
99+
} else {
100+
if (auth_level == LEVEL_USER || auth_level == LEVEL_ADMIN) {
101+
status = "Identified";
102+
code = 200;
103+
}
104+
}
100105
_webserver->sendHeader("Cache-Control","no-cache");
101106
String smsg = "{\"status\":\"";
102107
smsg+=status;
@@ -110,6 +115,7 @@ void HTTP_Server::handle_login()
110115
}
111116
smsg += "\"}";
112117
_webserver->send(code, "application/json", smsg);
118+
return;
113119
#else // No AUTHENTICATION_FEATURE
114120
_webserver->sendHeader("Cache-Control","no-cache");
115121
_webserver->send(200, "application/json", "{\"status\":\"ok\",\"authentication_lvl\":\"admin\"}");

esp3d/src/modules/http/handles/handle-updatefw.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@ void HTTP_Server::handleUpdate ()
3838
return;
3939
}
4040
String jsonfile = "{\"status\":\"" ;
41-
jsonfile += String(_upload_status);
41+
switch(_upload_status) {
42+
case UPLOAD_STATUS_NONE :
43+
jsonfile += "no file";
44+
break;
45+
case UPLOAD_STATUS_CANCELLED :
46+
jsonfile += "canceled";
47+
break;
48+
case UPLOAD_STATUS_SUCCESSFUL :
49+
jsonfile += "ok";
50+
break;
51+
default :
52+
jsonfile += "error";
53+
break;
54+
}
4255
jsonfile += "\"}";
4356
_webserver->sendHeader("Cache-Control", "no-cache");
4457
_webserver->send(200, "application/json", jsonfile);

esp3d/src/modules/network/netservices.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ bool NetServices::begin()
261261
SSDP.setSerialNumber (stmp.c_str());
262262
//Any customization could be here
263263
SSDP.setModelName (ESP_MODEL_NAME);
264+
#if defined(ESP_MODEL_DESCRIPTION)
265+
//this one is optional because windows doesn't care about this field
266+
SSDP.setModelDescription(ESP_MODEL_DESCRIPTION);
267+
#endif //ESP_MODEL_DESCRIPTION
264268
SSDP.setModelURL (ESP_MODEL_URL);
265269
SSDP.setModelNumber (ESP_MODEL_NUMBER);
266270
SSDP.setManufacturer (ESP_MANUFACTURER_NAME);

esp3d/src/modules/network/netservices.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ class NetServices
3434
{
3535
return _started;
3636
}
37-
static void start()
38-
{
39-
_restart=true;
40-
Serial.println("Restarting netservices");
41-
}
4237
private:
4338
static bool _started;
4439
static bool _restart;

0 commit comments

Comments
 (0)