From 71790260b7c10323a04e8fd765e046664b5e4344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=A4mer?= Date: Thu, 23 Mar 2023 15:34:29 +0100 Subject: [PATCH] fixes after rebase --- code/components/jomjol_wlan/read_wlanini.cpp | 37 ++++++++++++-------- code/components/jomjol_wlan/read_wlanini.h | 2 ++ code/include/basic_auth.h | 8 ++--- code/main/basic_auth.cpp | 14 +++++--- code/main/main.cpp | 2 ++ code/platformio.ini | 1 - 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/code/components/jomjol_wlan/read_wlanini.cpp b/code/components/jomjol_wlan/read_wlanini.cpp index 9cf7f9b18..fae306131 100644 --- a/code/components/jomjol_wlan/read_wlanini.cpp +++ b/code/components/jomjol_wlan/read_wlanini.cpp @@ -145,6 +145,29 @@ int LoadWlanFromFile(std::string fn) wlan_config.dns = tmp; LogFile.WriteToFile(ESP_LOG_INFO, TAG, "DNS: " + wlan_config.dns); } + + else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_USERNAME")){ + tmp = splitted[1]; + if ((tmp[0] == '"') && (tmp[tmp.length()-1] == '"')){ + tmp = tmp.substr(1, tmp.length()-2); + } + wlan_config.http_username = tmp; + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_USERNAME: " + wlan_config.http_username); + } + + else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_PASSWORD")){ + tmp = splitted[1]; + if ((tmp[0] == '"') && (tmp[tmp.length()-1] == '"')){ + tmp = tmp.substr(1, tmp.length()-2); + } + wlan_config.http_password = tmp; + #ifndef __HIDE_PASSWORD + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_PASSWORD: " + wlan_config.http_password); + #else + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "HTTP_PASSWORD: XXXXXXXX"); + #endif + } + #if (defined WLAN_USE_ROAMING_BY_SCANNING || (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)) else if ((splitted.size() > 1) && (toUpper(splitted[0]) == "RSSITHRESHOLD")){ tmp = trim(splitted[1]); @@ -157,20 +180,6 @@ int LoadWlanFromFile(std::string fn) #endif } - if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_USERNAME")){ - http_username = splitted[1]; - if ((http_username[0] == '"') && (http_username[http_username.length()-1] == '"')){ - http_username = http_username.substr(1, http_username.length()-2); - } - } - - if ((splitted.size() > 1) && (toUpper(splitted[0]) == "HTTP_PASSWORD")){ - http_password = splitted[1]; - if ((http_password[0] == '"') && (http_password[http_password.length()-1] == '"')){ - http_password = http_password.substr(1, http_password.length()-2); - } - } - if (fgets(zw, 1024, pFile) == NULL) { line = ""; diff --git a/code/components/jomjol_wlan/read_wlanini.h b/code/components/jomjol_wlan/read_wlanini.h index 6a31490f7..759f68332 100644 --- a/code/components/jomjol_wlan/read_wlanini.h +++ b/code/components/jomjol_wlan/read_wlanini.h @@ -13,6 +13,8 @@ struct wlan_config { std::string gateway = ""; std::string netmask = ""; std::string dns = ""; + std::string http_username = ""; + std::string http_password = ""; int rssi_threshold = 0; // Default: 0 -> ROAMING disabled }; extern struct wlan_config wlan_config; diff --git a/code/include/basic_auth.h b/code/include/basic_auth.h index 82d3d07f5..ae6a7d346 100644 --- a/code/include/basic_auth.h +++ b/code/include/basic_auth.h @@ -1,10 +1,8 @@ -#ifndef BASIC_AUTH_H -#define BASIC_AUTH_H +#pragma once #include -void init_basic_auth(char *username, char *password); +void init_basic_auth(); esp_err_t basic_auth_request_filter(httpd_req_t *req, esp_err_t original_handler(httpd_req_t *)); -#define APPLY_BASIC_AUTH_FILTER(method) [](httpd_req_t *req){ return basic_auth_request_filter(req, method); } -#endif \ No newline at end of file +#define APPLY_BASIC_AUTH_FILTER(method) [](httpd_req_t *req){ return basic_auth_request_filter(req, method); } \ No newline at end of file diff --git a/code/main/basic_auth.cpp b/code/main/basic_auth.cpp index 07a70a837..8d467d090 100644 --- a/code/main/basic_auth.cpp +++ b/code/main/basic_auth.cpp @@ -1,21 +1,25 @@ #include "basic_auth.h" +#include "read_wlanini.h" #include #include + #define HTTPD_401 "401 UNAUTHORIZED" static const char *TAG = "HTTPAUTH"; typedef struct { - char *username; - char *password; + const char *username; + const char *password; } basic_auth_info_t; basic_auth_info_t basic_auth_info = { NULL, NULL }; -void init_basic_auth(char *username, char *password) { - basic_auth_info.username = username; - basic_auth_info.password = password; +void init_basic_auth() { + if (!wlan_config.http_username.empty() && !wlan_config.http_password.empty()) { + basic_auth_info.username = wlan_config.http_username.c_str(); + basic_auth_info.password = wlan_config.http_password.c_str(); + } } static char *http_auth_basic(const char *username, const char *password) diff --git a/code/main/main.cpp b/code/main/main.cpp index 5a8ba7291..411ee88b3 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -424,6 +424,8 @@ extern "C" void app_main(void) StatusLED(WLAN_INIT, 3, true); return; } + + init_basic_auth(); } else if (iWLANStatus == -1) { // wlan.ini not available, potentially empty or content not readable StatusLED(WLAN_INIT, 1, true); diff --git a/code/platformio.ini b/code/platformio.ini index ea924fb2f..6c9fd1f97 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -57,7 +57,6 @@ build_flags = ${flags:runtime.build_flags} ; ### Sofware options : (can be set in defines.h) -D ENABLE_MQTT - -D ENABLE_INFLUXDB -D ENABLE_SOFTAP board_build.partitions = partitions.csv monitor_speed = 115200