This commit is contained in:
jomjol
2020-08-23 11:15:47 +02:00
parent b3c0a1e3aa
commit 34dde05741
13 changed files with 204 additions and 33 deletions

View File

@@ -13,7 +13,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
## Change log - latest version ## Change log - latest version
##### Rolling (2020-08-17) ##### Rolling (2020-08-23)
* Preparation for web configuration
* Security Issue: Remove access to "wlan.ini"
* Only editor for config.ini * Only editor for config.ini

View File

@@ -30,6 +30,8 @@
#include "server_help.h" #include "server_help.h"
#include "Helper.h"
/* Max length a file path can have on storage */ /* Max length a file path can have on storage */
// #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN) // #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
#define FILE_PATH_MAX (255) #define FILE_PATH_MAX (255)
@@ -154,36 +156,39 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath)
/* Iterate over all files / folders and fetch their names and sizes */ /* Iterate over all files / folders and fetch their names and sizes */
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
entrytype = (entry->d_type == DT_DIR ? "directory" : "file"); if (strcmp("wlan.ini", entry->d_name) != 0 ) // wlan.ini soll nicht angezeigt werden!
{
entrytype = (entry->d_type == DT_DIR ? "directory" : "file");
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len); strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
printf("Entrypath: %s\n", entrypath); printf("Entrypath: %s\n", 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=\"");
httpd_resp_sendstr_chunk(req, req->uri); httpd_resp_sendstr_chunk(req, req->uri);
httpd_resp_sendstr_chunk(req, entry->d_name); httpd_resp_sendstr_chunk(req, entry->d_name);
if (entry->d_type == DT_DIR) { if (entry->d_type == DT_DIR) {
httpd_resp_sendstr_chunk(req, "/"); httpd_resp_sendstr_chunk(req, "/");
}
httpd_resp_sendstr_chunk(req, "\">");
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "</a></td><td>");
httpd_resp_sendstr_chunk(req, entrytype);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, entrysize);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, "<form method=\"post\" action=\"/delete");
httpd_resp_sendstr_chunk(req, req->uri + strlen("/fileserver"));
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "\"><button type=\"submit\">Delete</button></form>");
httpd_resp_sendstr_chunk(req, "</td></tr>\n");
} }
httpd_resp_sendstr_chunk(req, "\">");
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "</a></td><td>");
httpd_resp_sendstr_chunk(req, entrytype);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, entrysize);
httpd_resp_sendstr_chunk(req, "</td><td>");
httpd_resp_sendstr_chunk(req, "<form method=\"post\" action=\"/delete");
httpd_resp_sendstr_chunk(req, req->uri + strlen("/fileserver"));
httpd_resp_sendstr_chunk(req, entry->d_name);
httpd_resp_sendstr_chunk(req, "\"><button type=\"submit\">Delete</button></form>");
httpd_resp_sendstr_chunk(req, "</td></tr>\n");
} }
closedir(dir); closedir(dir);
@@ -214,7 +219,7 @@ static esp_err_t download_get_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("/fileserver") - 1, sizeof(filepath)); req->uri + sizeof("/fileserver") - 1, sizeof(filepath));
printf("1 uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
// filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, // filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path,
// req->uri, sizeof(filepath)); // req->uri, sizeof(filepath));
@@ -231,7 +236,10 @@ static esp_err_t download_get_handler(httpd_req_t *req)
return http_resp_dir_html(req, filepath); return http_resp_dir_html(req, filepath);
} }
if (stat(filepath, &file_stat) == -1) { std::string testwlan = toUpper(std::string(filename));
if ((stat(filepath, &file_stat) == -1) || (testwlan.compare("/WLAN.INI") == 0 )) { // wlan.ini soll nicht angezeigt werden!
/* 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); ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
@@ -248,6 +256,8 @@ static esp_err_t download_get_handler(httpd_req_t *req)
return ESP_FAIL; return ESP_FAIL;
} }
esp_err_t res = 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);

View File

@@ -113,8 +113,20 @@ void CopyFile(string input, string output)
input = FormatFileName(input); input = FormatFileName(input);
output = FormatFileName(output); output = FormatFileName(output);
if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0)
{
printf("wlan.ini kann nicht kopiert werden!\n");
return;
}
char cTemp; char cTemp;
FILE* fpSourceFile = fopen(input.c_str(), "rb"); FILE* fpSourceFile = fopen(input.c_str(), "rb");
if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
{
printf("File %s existiert nicht!\n", input.c_str());
return;
}
FILE* fpTargetFile = fopen(output.c_str(), "wb"); FILE* fpTargetFile = fopen(output.c_str(), "wb");
// Code Section // Code Section

View File

@@ -384,6 +384,22 @@ CImageBasis::CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _he
this->externalImage = true; this->externalImage = true;
} }
void CImageBasis::Contrast(float _contrast) //input range [-100..100]
{
stbi_uc* p_source;
float contrast = (_contrast/100) + 1; //convert to decimal & shift range: [0..2]
float intercept = 128 * (1 - contrast);
for (int x = 0; x < width; ++x)
for (int y = 0; y < height; ++y)
{
p_source = this->rgb_image + (this->channels * (y * this->width + x));
for (int channels = 0; channels < this->channels; ++channels)
p_source[channels] = (uint8_t) std::min(255, std::max(0, (int) (p_source[channels] * contrast + intercept)));
}
}
CImageBasis::~CImageBasis() CImageBasis::~CImageBasis()
{ {
if (!this->externalImage) if (!this->externalImage)

View File

@@ -35,6 +35,7 @@ class CImageBasis
void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1); void drawLine(int x1, int y1, int x2, int y2, int r, int g, int b, int thickness = 1);
void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1); void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1);
void setPixelColor(int x, int y, int r, int g, int b); void setPixelColor(int x, int y, int r, int g, int b);
void Contrast(float _contrast);
CImageBasis(); CImageBasis();

View File

@@ -24,7 +24,7 @@ board_build.embed_files =
;board_build.partitions = partitions_singleapp.csv ;board_build.partitions = partitions_singleapp.csv
board_build.partitions = partition.csv board_build.partitions = partition.csv
lib_deps = connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile lib_deps = jomjol_helper, connect_wlan, conversions, driver, sensors, jomjol_image_proc, jomjol_controlcamera, jomjol_flowcontroll, jomjol_tfliteclass, tfmicro, jomjol_fileserver_ota, jomjol_time_sntp, jomjol_logfile
monitor_speed = 115200 monitor_speed = 115200
debug_tool = esp-prog debug_tool = esp-prog

View File

@@ -138,8 +138,12 @@ esp_err_t hello_main_handler(httpd_req_t *req)
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist"); httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
return ESP_FAIL; return ESP_FAIL;
} }
esp_err_t res;
res = httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (res != ESP_OK)
return res;
esp_err_t res = send_file(req, filetosend, &file_stat); res = send_file(req, filetosend, &file_stat);
if (res != ESP_OK) if (res != ESP_OK)
return res; return res;

View File

@@ -8,6 +8,8 @@
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include "Helper.h"
#include "esp_camera.h" #include "esp_camera.h"
#include "time_sntp.h" #include "time_sntp.h"
#include "ClassControllCamera.h" #include "ClassControllCamera.h"
@@ -125,6 +127,7 @@ esp_err_t handler_doflow(httpd_req_t *req)
esp_err_t handler_wasserzaehler(httpd_req_t *req) esp_err_t handler_wasserzaehler(httpd_req_t *req)
{ {
LogFile.WriteToFile("handler_wasserzaehler"); LogFile.WriteToFile("handler_wasserzaehler");
@@ -215,6 +218,121 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK;
};
esp_err_t handler_editflow(httpd_req_t *req)
{
LogFile.WriteToFile("handler_editflow");
const char* resp_str;
string zw;
bool _rawValue = false;
printf("handler_editflow uri:\n"); printf(req->uri); printf("\n");
char _query[200];
char _valuechar[30];
string _task;
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
printf("task is found"); printf(_valuechar); printf("\n");
_task = string(_valuechar);
}
}
if (_task.compare("copy") == 0)
{
string in, out, zw;
httpd_query_key_value(_query, "in", _valuechar, 30);
in = string(_valuechar);
printf("in: "); printf(in.c_str()); printf("\n");
httpd_query_key_value(_query, "out", _valuechar, 30);
out = string(_valuechar);
printf("out: "); printf(out.c_str()); printf("\n");
in = "/sdcard" + in;
out = "/sdcard" + out;
CopyFile(in, out);
zw = "Copy Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_task.compare("cutref") == 0)
{
string in, out, zw;
int x, y, dx, dy;
bool enhance = false;
httpd_query_key_value(_query, "in", _valuechar, 30);
in = string(_valuechar);
printf("in: "); printf(in.c_str()); printf("\n");
httpd_query_key_value(_query, "out", _valuechar, 30);
out = string(_valuechar);
printf("out: "); printf(out.c_str()); printf("\n");
httpd_query_key_value(_query, "x", _valuechar, 30);
zw = string(_valuechar);
x = stoi(zw);
printf("x: "); printf(zw.c_str()); printf("\n");
httpd_query_key_value(_query, "y", _valuechar, 30);
zw = string(_valuechar);
y = stoi(zw);
printf("y: "); printf(zw.c_str()); printf("\n");
httpd_query_key_value(_query, "dx", _valuechar, 30);
zw = string(_valuechar);
dx = stoi(zw);
printf("dx: "); printf(zw.c_str()); printf("\n");
httpd_query_key_value(_query, "dy", _valuechar, 30);
zw = string(_valuechar);
dy = stoi(zw);
printf("dy: "); printf(zw.c_str()); printf("\n");
if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
{
zw = string(_valuechar);
if (zw.compare("true") == 0)
{
enhance = true;
}
}
in = "/sdcard" + in;
out = "/sdcard" + out;
string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
CAlignAndCutImage *caic = new CAlignAndCutImage(in);
caic->CutAndSave(out2, x, y, dx, dy);
delete caic;
CImageBasis *cim = new CImageBasis(out2);
if (enhance)
{
cim->Contrast(90);
}
cim->SaveToFile(out);
delete cim;
zw = "CutImage Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
/* Respond with an empty chunk to signal HTTP response completion */ /* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_sendstr_chunk(req, NULL); httpd_resp_sendstr_chunk(req, NULL);
@@ -321,6 +439,12 @@ void register_server_tflite_uri(httpd_handle_t server)
camuri.user_ctx = (void*) "Light Off"; camuri.user_ctx = (void*) "Light Off";
httpd_register_uri_handler(server, &camuri); httpd_register_uri_handler(server, &camuri);
camuri.uri = "/editflow.html";
camuri.handler = handler_editflow;
camuri.user_ctx = (void*) "EditFlow";
httpd_register_uri_handler(server, &camuri);
camuri.uri = "/wasserzaehler.html"; camuri.uri = "/wasserzaehler.html";
camuri.handler = handler_wasserzaehler; camuri.handler = handler_wasserzaehler;
camuri.user_ctx = (void*) "Wasserzaehler"; camuri.user_ctx = (void*) "Wasserzaehler";

Binary file not shown.

Binary file not shown.