Fix cookie usage, use correct http response codes, add 404 page (#1495)

* replaced some HTTP response code with better matching codes

* add custom 404 page, add log entry for debugging

* fix cookie

* replace non-necessary whitespace

* .

Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
CaCO3
2022-12-06 06:53:05 +01:00
committed by GitHub
parent fa406d8989
commit 4f07c88769
12 changed files with 82 additions and 67 deletions

View File

@@ -425,7 +425,7 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
nm = FormatFileName(nm); nm = FormatFileName(nm);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Save Camera to : %s", nm.c_str()); ESP_LOGD(TAG, "Save Camera to: %s", nm.c_str());
#endif #endif
ftype = toUpper(getFileType(nm)); ftype = toUpper(getFileType(nm));

View File

@@ -219,9 +219,9 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
ESP_LOGD(TAG, "entrypath: <%s>", entrypath); ESP_LOGD(TAG, "entrypath: <%s>", entrypath);
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", dirpath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to stat dir: %s", dirpath);
/* Respond with 404 Not Found */ /* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "Directory does not exist"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
@@ -278,11 +278,11 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len); strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
ESP_LOGD(TAG, "Entrypath: %s", entrypath); ESP_LOGD(TAG, "Entrypath: %s", entrypath);
if (stat(entrypath, &entry_stat) == -1) { if (stat(entrypath, &entry_stat) == -1) {
ESP_LOGE(TAG, "Failed to stat %s : %s", entrytype, entry->d_name); ESP_LOGE(TAG, "Failed to stat %s: %s", entrytype, entry->d_name);
continue; continue;
} }
sprintf(entrysize, "%ld", entry_stat.st_size); sprintf(entrysize, "%ld", entry_stat.st_size);
ESP_LOGI(TAG, "Found %s : %s (%s bytes)", entrytype, entry->d_name, entrysize); ESP_LOGI(TAG, "Found %s: %s (%s bytes)", entrytype, entry->d_name, entrysize);
/* Send chunk of HTML file containing table entries with file name and size */ /* Send chunk of HTML file containing table entries with file name and size */
httpd_resp_sendstr_chunk(req, "<tr><td><a href=\""); httpd_resp_sendstr_chunk(req, "<tr><td><a href=\"");
@@ -361,15 +361,15 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file)
fd = OpenFileAndWait(currentfilename.c_str(), "r"); fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) { if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read existing file: %s", filepath);
/* Respond with 500 Internal Server Error */ /* Respond with 404 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size); // ESP_LOGI(TAG, "Sending file: %s (%ld bytes)...", &filename, file_stat.st_size);
set_content_type_from_file(req, filename); set_content_type_from_file(req, filename);
if (!send_full_file) { // Send only last part of file if (!send_full_file) { // Send only last part of file
@@ -446,15 +446,15 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file)
fd = OpenFileAndWait(currentfilename.c_str(), "r"); fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) { if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read existing file: %s", filepath);
/* Respond with 500 Internal Server Error */ /* Respond with 404 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size); // ESP_LOGI(TAG, "Sending file: %s (%ld bytes)...", &filename, file_stat.st_size);
set_content_type_from_file(req, filename); set_content_type_from_file(req, filename);
if (!send_full_file) { // Send only last part of file if (!send_full_file) { // Send only last part of file
@@ -534,8 +534,8 @@ static esp_err_t download_get_handler(httpd_req_t *req)
if (!filename) { if (!filename) {
ESP_LOGE(TAG, "Filename is too long"); ESP_LOGE(TAG, "Filename is too long");
/* Respond with 500 Internal Server Error */ /* Respond with 414 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long"); httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long");
return ESP_FAIL; return ESP_FAIL;
} }
@@ -566,23 +566,23 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* If file not present on SPIFFS check if URI /* If file not present on SPIFFS check if URI
* corresponds to one of the hardcoded paths */ * corresponds to one of the hardcoded paths */
ESP_LOGE(TAG, "Failed to stat file : %s", filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to stat file: %s!", filepath);
/* Respond with 404 Not Found */ /* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
fd = OpenFileAndWait(filepath, "r"); fd = OpenFileAndWait(filepath, "r");
if (!fd) { if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filepath); LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read existing file: %s!", filepath);
/* Respond with 500 Internal Server Error */ /* Respond with 404 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
ESP_LOGD(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size); ESP_LOGD(TAG, "Sending file: %s (%ld bytes)...", filename, file_stat.st_size);
set_content_type_from_file(req, filename); set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */ /* Retrieve the pointer to scratch buffer for temporary storage */
@@ -599,7 +599,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Abort sending file */ /* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL); httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */ /* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file"); httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file!");
return ESP_FAIL; return ESP_FAIL;
} }
@@ -628,20 +628,21 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
req->uri + sizeof("/upload") - 1, sizeof(filepath)); req->uri + sizeof("/upload") - 1, sizeof(filepath));
if (!filename) { if (!filename) {
/* Respond with 500 Internal Server Error */ /* Respond with 413 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long"); httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long");
return ESP_FAIL; return ESP_FAIL;
} }
/* Filename cannot have a trailing '/' */ /* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') { if (filename[strlen(filename) - 1] == '/') {
ESP_LOGE(TAG, "Invalid filename : %s", filename); ESP_LOGE(TAG, "Invalid filename: %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename"); /* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Invalid filename");
return ESP_FAIL; return ESP_FAIL;
} }
if (stat(filepath, &file_stat) == 0) { if (stat(filepath, &file_stat) == 0) {
ESP_LOGE(TAG, "File already exists : %s", filepath); ESP_LOGE(TAG, "File already exists: %s", filepath);
/* Respond with 400 Bad Request */ /* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File already exists"); httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File already exists");
return ESP_FAIL; return ESP_FAIL;
@@ -649,7 +650,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* File cannot be larger than a limit */ /* File cannot be larger than a limit */
if (req->content_len > MAX_FILE_SIZE) { if (req->content_len > MAX_FILE_SIZE) {
ESP_LOGE(TAG, "File too large : %d bytes", req->content_len); ESP_LOGE(TAG, "File too large: %d bytes", req->content_len);
/* Respond with 400 Bad Request */ /* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
"File size must be less than " "File size must be less than "
@@ -661,13 +662,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fd = OpenFileAndWait(filepath, "w"); fd = OpenFileAndWait(filepath, "w");
if (!fd) { if (!fd) {
ESP_LOGE(TAG, "Failed to create file : %s", filepath); ESP_LOGE(TAG, "Failed to create file: %s", filepath);
/* Respond with 500 Internal Server Error */ /* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file"); httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file");
return ESP_FAIL; return ESP_FAIL;
} }
ESP_LOGI(TAG, "Receiving file : %s...", filename); ESP_LOGI(TAG, "Receiving file: %s...", filename);
/* Retrieve the pointer to scratch buffer for temporary storage */ /* Retrieve the pointer to scratch buffer for temporary storage */
char *buf = ((struct file_server_data *)req->user_ctx)->scratch; char *buf = ((struct file_server_data *)req->user_ctx)->scratch;
@@ -679,7 +680,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
while (remaining > 0) { while (remaining > 0) {
ESP_LOGI(TAG, "Remaining size : %d", remaining); ESP_LOGI(TAG, "Remaining size: %d", remaining);
/* Receive the file part by part into a buffer */ /* Receive the file part by part into a buffer */
if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) { if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
if (received == HTTPD_SOCK_ERR_TIMEOUT) { if (received == HTTPD_SOCK_ERR_TIMEOUT) {
@@ -790,8 +791,8 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
req->uri + sizeof("/delete") - 1, sizeof(filepath)); req->uri + sizeof("/delete") - 1, sizeof(filepath));
if (!filename) { if (!filename) {
/* Respond with 500 Internal Server Error */ /* Respond with 414 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long"); httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long");
return ESP_FAIL; return ESP_FAIL;
} }
zw = std::string(filename); zw = std::string(filename);
@@ -824,19 +825,20 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
/* Filename cannot have a trailing '/' */ /* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') { if (filename[strlen(filename) - 1] == '/') {
ESP_LOGE(TAG, "Invalid filename : %s", filename); ESP_LOGE(TAG, "Invalid filename: %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename"); /* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Invalid filename");
return ESP_FAIL; return ESP_FAIL;
} }
if (stat(filepath, &file_stat) == -1) { if (stat(filepath, &file_stat) == -1) {
ESP_LOGE(TAG, "File does not exist : %s", filename); ESP_LOGE(TAG, "File does not exist: %s", filename);
/* Respond with 400 Bad Request */ /* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist"); httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist");
return ESP_FAIL; return ESP_FAIL;
} }
ESP_LOGI(TAG, "Deleting file : %s", filename); ESP_LOGI(TAG, "Deleting file: %s", filename);
/* Delete file */ /* Delete file */
unlink(filepath); unlink(filepath);
@@ -878,7 +880,7 @@ void delete_all_in_directory(std::string _directory)
std::string filename; std::string filename;
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", _directory.c_str()); ESP_LOGE(TAG, "Failed to stat dir: %s", _directory.c_str());
return; return;
} }
@@ -887,7 +889,7 @@ void delete_all_in_directory(std::string _directory)
if (!(entry->d_type == DT_DIR)){ if (!(entry->d_type == DT_DIR)){
if (strcmp("wlan.ini", entry->d_name) != 0){ // auf wlan.ini soll nicht zugegriffen werden !!! if (strcmp("wlan.ini", entry->d_name) != 0){ // auf wlan.ini soll nicht zugegriffen werden !!!
filename = _directory + "/" + std::string(entry->d_name); filename = _directory + "/" + std::string(entry->d_name);
ESP_LOGI(TAG, "Deleting file : %s", filename.c_str()); ESP_LOGI(TAG, "Deleting file: %s", filename.c_str());
/* Delete file */ /* Delete file */
unlink(filename.c_str()); unlink(filename.c_str());
} }

View File

@@ -36,13 +36,13 @@ esp_err_t send_file(httpd_req_t *req, std::string filename)
{ {
FILE *fd = OpenFileAndWait(filename.c_str(), "r"); FILE *fd = OpenFileAndWait(filename.c_str(), "r");
if (!fd) { if (!fd) {
ESP_LOGE(TAG, "Failed to read existing file : %s", filename.c_str()); ESP_LOGE(TAG, "Failed to read existing file: %s", filename.c_str());
/* Respond with 500 Internal Server Error */ /* Respond with 404 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, get404());
return ESP_FAIL; return ESP_FAIL;
} }
ESP_LOGD(TAG, "Sending file : %s ...", filename.c_str()); ESP_LOGD(TAG, "Sending file: %s ...", filename.c_str());
// httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); // httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
set_content_type_from_file(req, filename.c_str()); set_content_type_from_file(req, filename.c_str());

View File

@@ -530,7 +530,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
int _result = stat(fn.c_str(), &file_stat); int _result = stat(fn.c_str(), &file_stat);
ESP_LOGD(TAG, "Ergebnis %d\n", _result); ESP_LOGD(TAG, "Ergebnis %d\n", _result);
if (_result == 0) { if (_result == 0) {
ESP_LOGD(TAG, "Deleting file : %s", fn.c_str()); ESP_LOGD(TAG, "Deleting file: %s", fn.c_str());
/* Delete file */ /* Delete file */
unlink(fn.c_str()); unlink(fn.c_str());
} }

View File

@@ -569,10 +569,10 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
int ClassFlowControll::CleanTempFolder() { int ClassFlowControll::CleanTempFolder() {
const char* folderPath = "/sdcard/img_tmp"; const char* folderPath = "/sdcard/img_tmp";
ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors : %s", folderPath); ESP_LOGD(TAG, "Clean up temporary folder to avoid damage of sdcard sectors: %s", folderPath);
DIR *dir = opendir(folderPath); DIR *dir = opendir(folderPath);
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", folderPath); ESP_LOGE(TAG, "Failed to stat dir: %s", folderPath);
return -1; return -1;
} }
@@ -584,7 +584,7 @@ int ClassFlowControll::CleanTempFolder() {
if (unlink(path.c_str()) == 0) { if (unlink(path.c_str()) == 0) {
deleted ++; deleted ++;
} else { } else {
ESP_LOGE(TAG, "can't delete file : %s", path.c_str()); ESP_LOGE(TAG, "can't delete file: %s", path.c_str());
} }
} else if (entry->d_type == DT_DIR) { } else if (entry->d_type == DT_DIR) {
deleted += removeFolder(path.c_str(), TAG); deleted += removeFolder(path.c_str(), TAG);
@@ -679,7 +679,7 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
if (_send) if (_send)
{ {
ESP_LOGD(TAG, "Sending file : %s ...", _fn.c_str()); ESP_LOGD(TAG, "Sending file: %s ...", _fn.c_str());
set_content_type_from_file(req, _fn.c_str()); set_content_type_from_file(req, _fn.c_str());
result = _send->SendJPGtoHTTP(req); result = _send->SendJPGtoHTTP(req);
ESP_LOGD(TAG, "File sending complete"); ESP_LOGD(TAG, "File sending complete");

View File

@@ -113,7 +113,7 @@ void ClassFlowImage::RemoveOldLogs()
DIR *dir = opendir(LogImageLocation.c_str()); DIR *dir = opendir(LogImageLocation.c_str());
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", LogImageLocation.c_str()); ESP_LOGE(TAG, "Failed to stat dir: %s", LogImageLocation.c_str());
return; return;
} }

View File

@@ -304,7 +304,7 @@ size_t findDelimiterPos(string input, string delimiter)
bool RenameFile(string from, string to) bool RenameFile(string from, string to)
{ {
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); // ESP_LOGI(logTag, "Deleting file: %s", fn.c_str());
/* Delete file */ /* Delete file */
FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb"); FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
@@ -321,7 +321,7 @@ bool RenameFile(string from, string to)
bool DeleteFile(string fn) bool DeleteFile(string fn)
{ {
// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str()); // ESP_LOGI(logTag, "Deleting file: %s", fn.c_str());
/* Delete file */ /* Delete file */
FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb"); FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
@@ -512,7 +512,7 @@ int removeFolder(const char* folderPath, const char* logTag) {
DIR *dir = opendir(folderPath); DIR *dir = opendir(folderPath);
if (!dir) { if (!dir) {
ESP_LOGE(logTag, "Failed to stat dir : %s", folderPath); ESP_LOGE(logTag, "Failed to stat dir: %s", folderPath);
return -1; return -1;
} }
@@ -525,7 +525,7 @@ int removeFolder(const char* folderPath, const char* logTag) {
if (unlink(path.c_str()) == 0) { if (unlink(path.c_str()) == 0) {
deleted ++; deleted ++;
} else { } else {
ESP_LOGE(logTag, "can't delete file : %s", path.c_str()); ESP_LOGE(logTag, "can't delete file: %s", path.c_str());
} }
} else if (entry->d_type == DT_DIR) { } else if (entry->d_type == DT_DIR) {
deleted += removeFolder(path.c_str(), logTag); deleted += removeFolder(path.c_str(), logTag);
@@ -534,7 +534,7 @@ int removeFolder(const char* folderPath, const char* logTag) {
closedir(dir); closedir(dir);
if (rmdir(folderPath) != 0) { if (rmdir(folderPath) != 0) {
ESP_LOGE(logTag, "can't delete folder : %s", folderPath); ESP_LOGE(logTag, "can't delete folder: %s", folderPath);
} }
ESP_LOGD(logTag, "%d files in folder %s deleted.", deleted, folderPath); ESP_LOGD(logTag, "%d files in folder %s deleted.", deleted, folderPath);
@@ -791,3 +791,14 @@ string getResetReason(void) {
} }
return reasonText; return reasonText;
} }
const char* get404(void) {
return
"<pre>\n\n\n\n"
" _\n"
" .__(.)< ( oh oh! This page does not exist! )\n"
" \\___)\n"
"\n\n"
" You could try your <a href=index.html target=_parent>luck</a> here!</pre>\n"
"<script>document.cookie = \"page=overview.html\"</script>"; // Make sure we load the overview page
}

View File

@@ -64,3 +64,5 @@ string getSDCardSectorSize();
string getMac(void); string getMac(void);
string getResetReason(void); string getResetReason(void);
const char* get404(void);

View File

@@ -453,7 +453,7 @@ CImageBasis::CImageBasis(std::string _image)
RGBImageRelease(); RGBImageRelease();
zwld = esp_get_free_heap_size(); zwld = esp_get_free_heap_size();
ESP_LOGD(TAG, "freeheapsize after : %ld", zwld); ESP_LOGD(TAG, "freeheapsize after: %ld", zwld);
std::string zw = "Image Load failed:" + _image; std::string zw = "Image Load failed:" + _image;
if (rgb_image == NULL) if (rgb_image == NULL)

View File

@@ -315,7 +315,7 @@ void ClassLogFile::RemoveOldLogFile()
DIR *dir = opendir(logroot.c_str()); DIR *dir = opendir(logroot.c_str());
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", logroot.c_str()); ESP_LOGE(TAG, "Failed to stat dir: %s", logroot.c_str());
return; return;
} }
@@ -324,14 +324,14 @@ void ClassLogFile::RemoveOldLogFile()
int notDeleted = 0; int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) { if (entry->d_type == DT_REG) {
//ESP_LOGD(TAG, "compare log file : %s to %s", entry->d_name, cmpfilename); //ESP_LOGD(TAG, "compare log file: %s to %s", entry->d_name, cmpfilename);
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
//ESP_LOGD(TAG, "delete log file : %s", entry->d_name); //ESP_LOGD(TAG, "delete log file: %s", entry->d_name);
std::string filepath = logroot + "/" + entry->d_name; std::string filepath = logroot + "/" + entry->d_name;
if (unlink(filepath.c_str()) == 0) { if (unlink(filepath.c_str()) == 0) {
deleted ++; deleted ++;
} else { } else {
ESP_LOGE(TAG, "can't delete file : %s", entry->d_name); ESP_LOGE(TAG, "can't delete file: %s", entry->d_name);
notDeleted ++; notDeleted ++;
} }
} else { } else {
@@ -366,7 +366,7 @@ void ClassLogFile::RemoveOldDataLog()
DIR *dir = opendir(dataroot.c_str()); DIR *dir = opendir(dataroot.c_str());
if (!dir) { if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", dataroot.c_str()); ESP_LOGE(TAG, "Failed to stat dir: %s", dataroot.c_str());
return; return;
} }
@@ -375,14 +375,14 @@ void ClassLogFile::RemoveOldDataLog()
int notDeleted = 0; int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) { if (entry->d_type == DT_REG) {
//ESP_LOGD(TAG, "Compare data file : %s to %s", entry->d_name, cmpfilename); //ESP_LOGD(TAG, "Compare data file: %s to %s", entry->d_name, cmpfilename);
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
//ESP_LOGD(TAG, "delete data file : %s", entry->d_name); //ESP_LOGD(TAG, "delete data file: %s", entry->d_name);
std::string filepath = dataroot + "/" + entry->d_name; std::string filepath = dataroot + "/" + entry->d_name;
if (unlink(filepath.c_str()) == 0) { if (unlink(filepath.c_str()) == 0) {
deleted ++; deleted ++;
} else { } else {
ESP_LOGE(TAG, "can't delete file : %s", entry->d_name); ESP_LOGE(TAG, "can't delete file: %s", entry->d_name);
notDeleted ++; notDeleted ++;
} }
} else { } else {

View File

@@ -241,8 +241,8 @@ esp_err_t hello_main_handler(httpd_req_t *req)
if (!filename) { if (!filename) {
ESP_LOGE(TAG, "Filename is too long"); ESP_LOGE(TAG, "Filename is too long");
/* Respond with 500 Internal Server Error */ /* Respond with 414 Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long"); httpd_resp_send_err(req, HTTPD_414_URI_TOO_LONG, "Filename too long");
return ESP_FAIL; return ESP_FAIL;
} }

View File

@@ -15,7 +15,7 @@
<script> <script>
async function loadPage(page) { async function loadPage(page) {
console.log("loadPage(" + page + ")"); console.log("loadPage(" + page + ")");
document.cookie = page; document.cookie = "page="+page;
document.getElementById('maincontent').src = page; document.getElementById('maincontent').src = page;
[].forEach.call(document.querySelectorAll('.submenu'), function (el) { [].forEach.call(document.querySelectorAll('.submenu'), function (el) {