From 56cfeb732ec43adeb8809f09b1d8f290dbd68adb Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Mon, 2 Jan 2023 00:53:14 +0100 Subject: [PATCH] consolidate test-ip definition, added missing Access-Control-Allow-Origin, --- .../jomjol_fileserver_ota/server_file.cpp | 14 +++-- .../jomjol_fileserver_ota/server_ota.cpp | 2 +- .../jomjol_tfliteclass/server_tflite.cpp | 5 ++ sd-card/html/backup.html | 10 ++-- sd-card/html/common.js | 59 ++++++++++++++++--- sd-card/html/data.html | 17 +++--- sd-card/html/edit_alignment.html | 31 +++++----- sd-card/html/edit_analog.html | 18 +++--- sd-card/html/edit_check.html | 38 ++++++------ sd-card/html/edit_config.html | 14 ++--- sd-card/html/edit_config_param.html | 18 +++--- sd-card/html/edit_digits.html | 20 +++---- sd-card/html/edit_explain_6.html | 14 ++--- sd-card/html/edit_reference.html | 29 +++++---- sd-card/html/gethost.js | 41 ------------- sd-card/html/graph.html | 12 ++-- sd-card/html/index.html | 6 +- sd-card/html/log.html | 13 ++-- sd-card/html/ota_page.html | 10 ++-- sd-card/html/overview.html | 24 ++++---- sd-card/html/prevalue_set.html | 26 ++++---- sd-card/html/readconfigcommon.js | 48 +++++++-------- sd-card/html/readconfigparam.js | 42 ++++++------- sd-card/html/reboot_page.html | 3 +- sd-card/html/setup.html | 3 +- sd-card/html/test.html | 8 +-- sd-card/html/upload_script.html | 2 +- sd-card/html/wlan_config.html | 2 +- 28 files changed, 266 insertions(+), 263 deletions(-) delete mode 100644 sd-card/html/gethost.js diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index d03b03f69..5807072fb 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -212,6 +212,8 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const return ESP_FAIL; } + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + /* Send HTML file header */ httpd_resp_sendstr_chunk(req, ""); @@ -344,12 +346,6 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file) ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); - - - // Since the log file is still could open for writing, we need to close it first - LogFile.CloseLogFileAppendHandle(); - fd = fopen(currentfilename.c_str(), "r"); if (!fd) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to read existing file: " + std::string(filepath) +"!"); @@ -434,6 +430,8 @@ static esp_err_t send_logfile(httpd_req_t *req, bool send_full_file) ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); + // Since the log file is still could open for writing, we need to close it first + LogFile.CloseLogFileAppendHandle(); fd = fopen(currentfilename.c_str(), "r"); if (!fd) { @@ -614,6 +612,8 @@ static esp_err_t upload_post_handler(httpd_req_t *req) FILE *fd = NULL; struct stat file_stat; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + /* Skip leading "/upload" 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, @@ -764,6 +764,8 @@ static esp_err_t delete_post_handler(httpd_req_t *req) std::string directory; std::string zw; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { ESP_LOGD(TAG, "Query: %s", _query); diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index cd620cd10..728d800b7 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -666,7 +666,7 @@ esp_err_t handler_reboot(httpd_req_t *req) LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_reboot"); ESP_LOGI(TAG, "!!! System will restart within 5 sec!!!"); - const char* resp_str = "

"; + const char* resp_str = "

"; httpd_resp_send(req, resp_str, strlen(resp_str)); doReboot(); diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 2abb2eba1..20a6bb7d7 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -147,6 +147,7 @@ esp_err_t handler_init(httpd_req_t *req) doInit(); resp_str = "Init done
"; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp_str, strlen(resp_str)); /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); @@ -179,6 +180,8 @@ esp_err_t handler_flow_start(httpd_req_t *req) { httpd_resp_send(req, resp_str, strlen(resp_str)); } + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + /* Respond with an empty chunk to signal HTTP response completion */ httpd_resp_send_chunk(req, NULL, 0); @@ -421,6 +424,8 @@ esp_err_t handler_editflow(httpd_req_t *req) char _valuechar[30]; string _task; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) diff --git a/sd-card/html/backup.html b/sd-card/html/backup.html index 754c24483..da98c46ca 100644 --- a/sd-card/html/backup.html +++ b/sd-card/html/backup.html @@ -40,20 +40,18 @@

Restore Configuration

+
- - - Show graph + + +



Loading Data file, please wait...
@@ -53,7 +54,7 @@ function reload() { document.getElementById('data').innerHTML += "
Reloading...

"; window.scrollBy(0,document.body.scrollHeight); - funcRequest('data'); + funcRequest(getDomainname() + '/data'); } async function funcRequest(url){ @@ -76,7 +77,7 @@ }); } - funcRequest('data'); + funcRequest(getDomainname() + '/data'); diff --git a/sd-card/html/edit_alignment.html b/sd-card/html/edit_alignment.html index 1b4054776..939c94038 100644 --- a/sd-card/html/edit_alignment.html +++ b/sd-card/html/edit_alignment.html @@ -93,9 +93,9 @@

Define Alignment Structure in Reference Image

- - - + + + - - + + + - + + - + + - - + + + - - + + + - + - - + + + - - + + + @@ -103,13 +103,13 @@

Create Reference out of Raw Image

var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), imageObj = new Image() - basepath = "http://192.168.178.26"; + domainname = getDomainname(); isActReference = false; param; function doReboot() { if (confirm("Are you sure you want to reboot? Did you save the config?")) { - var stringota = "/reboot"; + var stringota = getDomainname() + "/reboot"; window.location = stringota; window.location.href = stringota; window.location.assign(stringota); @@ -126,15 +126,15 @@

Create Reference out of Raw Image

_brightness = document.getElementById("MakeImage_Brightness_value1").value; _contrast = document.getElementById("MakeImage_Contrast_value1").value; _saturation = document.getElementById("MakeImage_Saturation_value1").value; - url = basepath + "/editflow?task=test_take&bri=" + _brightness; + url = getDomainname() + "/editflow?task=test_take&bri=" + _brightness; url = url + "&con=" + _saturation + "&sat=" + _saturation + "&int=" + _intensity; } else { - url = basepath + "/editflow?task=test_take"; + url = domainname + "/editflow?task=test_take"; } - if (basepath.length > 0){ - url = url + "&host=" + basepath; + if (domainname.length > 0){ + url = url + "&host=" + domainname; } xhttp.open("GET", url, false); @@ -145,7 +145,7 @@

Create Reference out of Raw Image

} function loadRawImage(){ - url = basepath + "/img_tmp/raw.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1); + url = getDomainname() + "/img_tmp/raw.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1); document.getElementById("finerotate").disabled = false; document.getElementById("prerotateangle").disabled = false; document.getElementById("updatereferenceimage").disabled = false; @@ -189,7 +189,7 @@

Create Reference out of Raw Image

} function showReference(_param){ - url = basepath + "/fileserver/config/reference.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1);; + url = getDomainname() + "/fileserver/config/reference.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1);; document.getElementById("finerotate").value = 0; document.getElementById("prerotateangle").value = _param["Alignment"]["InitialRotate"].value1; @@ -263,9 +263,9 @@

Create Reference out of Raw Image

drawRotated(false); WriteConfigININew(); - SaveConfigToServer(basepath); + SaveConfigToServer(getDomainname()); - SaveCanvasToImage(canvas, "/config/reference.jpg", true, basepath); + SaveCanvasToImage(canvas, "/config/reference.jpg", true, getDomainname()); showReference(param); UpdatePage(); alert("Reference is updated!"); @@ -301,8 +301,7 @@

Create Reference out of Raw Image

function init() { canvas.addEventListener('mousemove', mouseMove, false); - basepath = getbasepath(); - loadConfig(basepath); + loadConfig(getDomainname()); ParseConfig(); param = getConfigParameters(); diff --git a/sd-card/html/gethost.js b/sd-card/html/gethost.js deleted file mode 100644 index d838b6294..000000000 --- a/sd-card/html/gethost.js +++ /dev/null @@ -1,41 +0,0 @@ - -function gethost_Version(){ - return "1.0.0 - 20200910"; -} - - -function getbasepath(){ - var host = window.location.hostname; - if (((host == "127.0.0.1") || (host == "localhost") || (host == "")) -// && ((window.location.port == "80") || (window.location.port == "")) - ) - - { -// host = "http://192.168.2.219"; // jomjol interner test -// host = "http://192.168.178.46"; // jomjol interner test - host = "http://192.168.178.44"; // jomjol interner Real -// host = "http://192.168.43.191"; -// host = "."; // jomjol interner localhost - - } - else - { - host = window.location.protocol + "//" + host; - if (window.location.port != "") { - host = host + ":" + window.location.port; - } - } - - return host; -} - -function UpdatePage(_dosession = true){ - var zw = location.href; - zw = zw.substr(0, zw.indexOf("?")); - if (_dosession) { - window.location = zw + '?session=' + Math.floor((Math.random() * 1000000) + 1); - } - else { - window.location = zw; - } -} diff --git a/sd-card/html/graph.html b/sd-card/html/graph.html index 1c3dcd692..9dedef862 100644 --- a/sd-card/html/graph.html +++ b/sd-card/html/graph.html @@ -2,9 +2,9 @@ - - - + + + +
- - + +



Loading Logfile, please wait...
@@ -52,7 +53,7 @@ // document.getElementById('log').innerHTML += "
Reloading...

"; document.getElementById('log').innerHTML += "Reloading..."; window.scrollBy(0,document.body.scrollHeight); - funcRequest('log'); + funcRequest(getDomainname() + '/log'); } @@ -102,7 +103,7 @@ }); } - funcRequest('log'); + funcRequest(getDomainname() + '/log'); diff --git a/sd-card/html/ota_page.html b/sd-card/html/ota_page.html index eb58743d1..805e584d9 100644 --- a/sd-card/html/ota_page.html +++ b/sd-card/html/ota_page.html @@ -5,7 +5,7 @@ OTA Update - + + @@ -35,7 +36,7 @@

Do you really want to reboot your ESP32 now?

+