From 485e55e0b834586a960d25d4e7dbc76c4115525f Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Mon, 2 Jan 2023 00:55:37 +0100 Subject: [PATCH] Revert "consolidate test-ip definition, added missing Access-Control-Allow-Origin," This reverts commit 56cfeb732ec43adeb8809f09b1d8f290dbd68adb. --- .../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, 263 insertions(+), 266 deletions(-) create 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 5807072f..d03b03f6 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -212,8 +212,6 @@ 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, ""); @@ -346,6 +344,12 @@ 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) +"!"); @@ -430,8 +434,6 @@ 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) { @@ -612,8 +614,6 @@ 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,8 +764,6 @@ 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 728d800b..cd620cd1 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 20a6bb7d..2abb2eba 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -147,7 +147,6 @@ 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); @@ -180,8 +179,6 @@ 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); @@ -424,8 +421,6 @@ 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 da98c46c..754c2448 100644 --- a/sd-card/html/backup.html +++ b/sd-card/html/backup.html @@ -40,18 +40,20 @@ input[type=number] { -
- - - + + + Show graph



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

"; window.scrollBy(0,document.body.scrollHeight); - funcRequest(getDomainname() + '/data'); + funcRequest('data'); } async function funcRequest(url){ @@ -77,7 +76,7 @@ }); } - funcRequest(getDomainname() + '/data'); + funcRequest('data'); diff --git a/sd-card/html/edit_alignment.html b/sd-card/html/edit_alignment.html index 939c9403..1b405477 100644 --- a/sd-card/html/edit_alignment.html +++ b/sd-card/html/edit_alignment.html @@ -93,9 +93,9 @@ select { - - - + + + - - + + + - + + - + + - - + + + - - + + + - + - - + + + - - + + + @@ -103,13 +103,13 @@ table { var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), imageObj = new Image() - domainname = getDomainname(); + basepath = "http://192.168.178.26"; isActReference = false; param; function doReboot() { if (confirm("Are you sure you want to reboot? Did you save the config?")) { - var stringota = getDomainname() + "/reboot"; + var stringota = "/reboot"; window.location = stringota; window.location.href = stringota; window.location.assign(stringota); @@ -126,15 +126,15 @@ table { _brightness = document.getElementById("MakeImage_Brightness_value1").value; _contrast = document.getElementById("MakeImage_Contrast_value1").value; _saturation = document.getElementById("MakeImage_Saturation_value1").value; - url = getDomainname() + "/editflow?task=test_take&bri=" + _brightness; + url = basepath + "/editflow?task=test_take&bri=" + _brightness; url = url + "&con=" + _saturation + "&sat=" + _saturation + "&int=" + _intensity; } else { - url = domainname + "/editflow?task=test_take"; + url = basepath + "/editflow?task=test_take"; } - if (domainname.length > 0){ - url = url + "&host=" + domainname; + if (basepath.length > 0){ + url = url + "&host=" + basepath; } xhttp.open("GET", url, false); @@ -145,7 +145,7 @@ table { } function loadRawImage(){ - url = getDomainname() + "/img_tmp/raw.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1); + url = basepath + "/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 @@ table { } function showReference(_param){ - url = getDomainname() + "/fileserver/config/reference.jpg" + "?session=" + Math.floor((Math.random() * 1000000) + 1);; + url = basepath + "/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 @@ table { drawRotated(false); WriteConfigININew(); - SaveConfigToServer(getDomainname()); + SaveConfigToServer(basepath); - SaveCanvasToImage(canvas, "/config/reference.jpg", true, getDomainname()); + SaveCanvasToImage(canvas, "/config/reference.jpg", true, basepath); showReference(param); UpdatePage(); alert("Reference is updated!"); @@ -301,7 +301,8 @@ table { function init() { canvas.addEventListener('mousemove', mouseMove, false); - loadConfig(getDomainname()); + basepath = getbasepath(); + loadConfig(basepath); ParseConfig(); param = getConfigParameters(); diff --git a/sd-card/html/gethost.js b/sd-card/html/gethost.js new file mode 100644 index 00000000..d838b629 --- /dev/null +++ b/sd-card/html/gethost.js @@ -0,0 +1,41 @@ + +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 9dedef86..1c3dcd69 100644 --- a/sd-card/html/graph.html +++ b/sd-card/html/graph.html @@ -2,9 +2,9 @@ - - - + + + -
- - + +



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

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