From 78b56ce9d4a8894c51b18d0c5b2bce113c017a7d Mon Sep 17 00:00:00 2001
From: jomjol <30766535+jomjol@users.noreply.github.com>
Date: Sun, 6 Sep 2020 21:21:04 +0200
Subject: [PATCH] update to v1.1.0
---
README.md | 28 +++-
.../lib/jomjol_fileserver_ota/server_file.cpp | 150 +++++++++++-------
code/lib/jomjol_fileserver_ota/server_ota.cpp | 8 +-
code/platformio.ini | 1 -
code/src/CMakeLists.txt | 2 +-
code/src/upload_script.html | 101 ------------
sd-card/html/file_server_upload_script.html | 82 ----------
sd-card/html/upload_script.html | 32 ++++
8 files changed, 156 insertions(+), 248 deletions(-)
delete mode 100644 code/src/upload_script.html
delete mode 100644 sd-card/html/file_server_upload_script.html
diff --git a/README.md b/README.md
index 7166a104..840ff918 100644
--- a/README.md
+++ b/README.md
@@ -11,9 +11,29 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
-
## Change log
+
+
+------
+
+### Known Issues
+
+* Parts of the web page only works correctly in **Firefox**!
+ With **Chrome** or **Edge** not all parts (especially the configuration) is **not full functional**.
+* spontaneous reboot, especially in case of intensive web server access
+
+------
+
+
+
+##### 1.1.0 (2020-09-06)
+
+* Implementation of "delete complete directory"
+ **Attention: beside the `firmware.bin`, also the content of `/html` needs to be updated!**
+
+
+
##### 1.0.2 (2020-09-06)
* Bug in configuration of analog ROIs corrected
@@ -40,12 +60,6 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
-## Known Issues
-
-* spontaneous reboot, especially in case of intensive web server access
-
-
-
## Solved topics
* n.a.
\ No newline at end of file
diff --git a/code/lib/jomjol_fileserver_ota/server_file.cpp b/code/lib/jomjol_fileserver_ota/server_file.cpp
index e83a8a25..7109d7dd 100644
--- a/code/lib/jomjol_fileserver_ota/server_file.cpp
+++ b/code/lib/jomjol_fileserver_ota/server_file.cpp
@@ -119,32 +119,25 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
/* Send HTML file header */
httpd_resp_sendstr_chunk(req, "
");
- /* Get handle to embedded file upload script */
- extern const unsigned char upload_script_start[] asm("_binary_upload_script_html_start");
- extern const unsigned char upload_script_end[] asm("_binary_upload_script_html_end");
- const size_t upload_script_size = (upload_script_end - upload_script_start);
-
- /* Add file upload form and script which on execution sends a POST request to /upload */
- httpd_resp_send_chunk(req, (const char *)upload_script_start, upload_script_size);
-
-
/////////////////////////////////////////////////
-/*
- FILE *fd = fopen("/sdcard/html/file_server_upload_script.html", "r");
+
+ FILE *fd = fopen("/sdcard/html/upload_script.html", "r");
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
size_t chunksize;
do {
chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd);
- if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
+// printf("Chunksize %d\n", chunksize);
+ if (chunksize > 0){
+ if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
ESP_LOGE(TAG, "File sending failed!");
return ESP_FAIL;
+ }
}
} while (chunksize != 0);
fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
- httpd_resp_send_chunk(req, NULL, 0);
-*/
+// ESP_LOGI(TAG, "File sending complete");
+
///////////////////////////////
@@ -152,7 +145,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
httpd_resp_sendstr_chunk(req,
""
" "
- "Name Type Size (Bytes) Delete "
+ "Name Type Size (Bytes) DeleteDELETE ALL! "
"");
/* Iterate over all files / folders and fetch their names and sizes */
@@ -434,51 +427,100 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
struct stat file_stat;
- /* Skip leading "/delete" from URI to get filename */
- /* Note sizeof() counts NULL termination hence the -1 */
- const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
- req->uri + sizeof("/delete") - 1, sizeof(filepath));
- if (!filename) {
- /* Respond with 500 Internal Server Error */
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
- return ESP_FAIL;
+//////////////////////////////////////////////////////////////
+ char _query[200];
+ char _filename[30];
+ char _valuechar[30];
+ std::string fn = "/sdcard/firmware/";
+ std::string _task;
+ std::string directory;
+ std::string zw;
+
+ if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
+ {
+ printf("Query: "); printf(_query); printf("\n");
+
+ if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
+ {
+ printf("task is found: "); printf(_valuechar); printf("\n");
+ _task = std::string(_valuechar);
+ }
}
- /* Filename cannot have a trailing '/' */
- if (filename[strlen(filename) - 1] == '/') {
- ESP_LOGE(TAG, "Invalid filename : %s", filename);
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
- return ESP_FAIL;
+ if (_task.compare("deldircontent") == 0)
+ {
+ /* Skip leading "/delete" from URI to get filename */
+ /* Note sizeof() counts NULL termination hence the -1 */
+ const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
+ req->uri + sizeof("/delete") - 1, sizeof(filepath));
+ if (!filename) {
+ /* Respond with 500 Internal Server Error */
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
+ return ESP_FAIL;
+ }
+ zw = std::string(filename);
+ zw = zw.substr(0, zw.length()-1);
+ zw = "/sdcard" + zw;
+ printf("Directory to delete: %s\n", zw.c_str());
+
+ delete_all_in_directory(zw);
+ directory = std::string(filepath);
+ printf("Location after delete directory content: %s\n", directory.c_str());
}
+ else
+ {
+ /* Skip leading "/delete" from URI to get filename */
+ /* Note sizeof() counts NULL termination hence the -1 */
+ const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
+ req->uri + sizeof("/delete") - 1, sizeof(filepath));
+ if (!filename) {
+ /* Respond with 500 Internal Server Error */
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
+ return ESP_FAIL;
+ }
- if (stat(filepath, &file_stat) == -1) {
- ESP_LOGE(TAG, "File does not exist : %s", filename);
- /* Respond with 400 Bad Request */
- httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist");
- return ESP_FAIL;
+ /* Filename cannot have a trailing '/' */
+ if (filename[strlen(filename) - 1] == '/') {
+ ESP_LOGE(TAG, "Invalid filename : %s", filename);
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
+ return ESP_FAIL;
+ }
+
+ if (stat(filepath, &file_stat) == -1) {
+ ESP_LOGE(TAG, "File does not exist : %s", filename);
+ /* Respond with 400 Bad Request */
+ httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist");
+ return ESP_FAIL;
+ }
+
+ ESP_LOGI(TAG, "Deleting file : %s", filename);
+ /* Delete file */
+ unlink(filepath);
+
+ directory = std::string(filepath);
+ size_t zw = directory.find("/");
+ size_t found = zw;
+ while (zw != std::string::npos)
+ {
+ zw = directory.find("/", found+1);
+ if (zw != std::string::npos)
+ found = zw;
+ }
+
+ int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
+ printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found);
+ directory = directory.substr(start_fn, found - start_fn + 1);
+ printf("Directory danach: %s\n", directory.c_str());
+
+ directory = "/fileserver" + directory;
+ printf("Directory danach: %s\n", directory.c_str());
}
+
- ESP_LOGI(TAG, "Deleting file : %s", filename);
- /* Delete file */
- unlink(filepath);
- std::string directory = std::string(filepath);
- size_t zw = directory.find("/");
- size_t found = zw;
- while (zw != std::string::npos)
- {
- zw = directory.find("/", found+1);
- if (zw != std::string::npos)
- found = zw;
- }
- int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path);
- printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found);
- directory = directory.substr(start_fn, found - start_fn + 1);
- printf("Directory danach: %s\n", directory.c_str());
- directory = "/fileserver" + directory;
- printf("Directory danach: %s\n", directory.c_str());
+//////////////////////////////////////////////////////////////
/* Redirect onto root to see the updated file list */
httpd_resp_set_status(req, "303 See Other");
@@ -502,7 +544,7 @@ void delete_all_in_directory(std::string _directory)
/* Iterate over all files / folders and fetch their names and sizes */
while ((entry = readdir(dir)) != NULL) {
if (!(entry->d_type == DT_DIR)){
- filename = _directory + std::string(entry->d_name);
+ filename = _directory + "/" + std::string(entry->d_name);
ESP_LOGI(TAG, "Deleting file : %s", filename.c_str());
/* Delete file */
unlink(filename.c_str());
@@ -524,6 +566,8 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
// static const char* s_Test_archive_filename = "testhtml.zip";
printf("miniz.c version: %s\n", MZ_VERSION);
+ printf("Zipfile: %s\n", _in_zip_file.c_str());
+ printf("Target Dir: %s\n", _target_directory.c_str());
// Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive));
diff --git a/code/lib/jomjol_fileserver_ota/server_ota.cpp b/code/lib/jomjol_fileserver_ota/server_ota.cpp
index 6806b332..e9ab7f6c 100644
--- a/code/lib/jomjol_fileserver_ota/server_ota.cpp
+++ b/code/lib/jomjol_fileserver_ota/server_ota.cpp
@@ -338,11 +338,13 @@ esp_err_t handler_ota_update(httpd_req_t *req)
std::string in, out, zw;
in = "/sdcard/firmware/html.zip";
- out = "/sdcard/html/";
+ out = "/sdcard/html2/";
unzip(in, out);
- zw = "Unzip html Done";
- httpd_resp_sendstr_chunk(req, zw.c_str());
+ zw = "HTML Update Successfull! No reboot necessary";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
+ httpd_resp_sendstr_chunk(req, NULL);
+ return ESP_OK;
}
diff --git a/code/platformio.ini b/code/platformio.ini
index b6f4c9fd..a95abebc 100644
--- a/code/platformio.ini
+++ b/code/platformio.ini
@@ -18,7 +18,6 @@ framework = espidf
board_build.embed_files =
src/favicon.ico
- src/upload_script.html
;board_build.partitions = partitions_singleapp.csv
diff --git a/code/src/CMakeLists.txt b/code/src/CMakeLists.txt
index e122799f..3a4eaf13 100644
--- a/code/src/CMakeLists.txt
+++ b/code/src/CMakeLists.txt
@@ -7,4 +7,4 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
- EMBED_FILES "favicon.ico" "upload_script.html")
+ EMBED_FILES "favicon.ico")
diff --git a/code/src/upload_script.html b/code/src/upload_script.html
deleted file mode 100644
index 758cbf76..00000000
--- a/code/src/upload_script.html
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
- ESP32 File Server
-
- Directory up
-
-
-
-
-
-
diff --git a/sd-card/html/file_server_upload_script.html b/sd-card/html/file_server_upload_script.html
deleted file mode 100644
index 544756a6..00000000
--- a/sd-card/html/file_server_upload_script.html
+++ /dev/null
@@ -1,82 +0,0 @@
-
-
-
- ESP32 File Server
-
-
-
-
-
diff --git a/sd-card/html/upload_script.html b/sd-card/html/upload_script.html
index 758cbf76..669f13e0 100644
--- a/sd-card/html/upload_script.html
+++ b/sd-card/html/upload_script.html
@@ -52,6 +52,38 @@ function dirup() {
window.location.href = res;
}
+function deleteall(){
+ var str = window.location.href;
+// str = str.substring(0, str.length-1);
+// str = str.substring(10, str.length);
+ str = str.replace("/fileserver/", "/delete/");
+ str = str + "?task=deldircontent";
+ if (confirm("This will delete ALL files in this directory!!!\n\nAre you sure?")) {
+ alert(str);
+
+ var xhttp = new XMLHttpRequest();
+ xhttp.onreadystatechange = function() {
+ if (xhttp.readyState == 4) {
+ if (xhttp.status == 200) {
+// document.open();
+// document.write(xhttp.responseText);
+// document.close();
+ location.reload();
+ } else if (xhttp.status == 0) {
+ alert("Server closed the connection abruptly!");
+ location.reload();
+ } else {
+// alert(xhttp.status + " Error!\n" + xhttp.responseText);
+ location.reload();
+ }
+ }
+ };
+ xhttp.open("POST", str, true);
+ xhttp.send();
+
+ }
+}
+
function upload() {
var filePath = document.getElementById("filepath").value;
var upload_path = "/upload/" + filePath;