Merge pull request #200 from bobbycar-graz/more-configs-in-newsettings

Move more configs into newSettings
This commit is contained in:
2021-12-29 06:30:51 +01:00
committed by GitHub
6 changed files with 16 additions and 23 deletions

View File

@ -112,6 +112,8 @@ public:
ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" }; ConfigWrapper<std::string> udpCloudHost {std::string{}, DoReset, {}, "udpCloudHost" };
ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" }; ConfigWrapper<std::string> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
#define NEW_SETTINGS(x) \ #define NEW_SETTINGS(x) \
x(baseMacAddressOverride) \ x(baseMacAddressOverride) \
x(hostname) \ x(hostname) \
@ -249,7 +251,9 @@ public:
\ \
x(cloudUrl) \ x(cloudUrl) \
x(udpCloudHost) \ x(udpCloudHost) \
// x(otaUrl) x(otaUrl) \
\
// x(webserverPassword)
template<typename T> template<typename T>
void callForEveryConfig(T &&callback) void callForEveryConfig(T &&callback)
@ -257,7 +261,7 @@ public:
#define HELPER(x) callback(x); #define HELPER(x) callback(x);
NEW_SETTINGS(HELPER) NEW_SETTINGS(HELPER)
#undef HELPER #undef HELPER
callback(otaUrl); callback(webserverPassword);
} }
auto getAllConfigParams() auto getAllConfigParams()
@ -266,7 +270,7 @@ public:
#define HELPER(x) std::ref<ConfigWrapperInterface>(x), #define HELPER(x) std::ref<ConfigWrapperInterface>(x),
NEW_SETTINGS(HELPER) NEW_SETTINGS(HELPER)
#undef HELPER #undef HELPER
std::ref<ConfigWrapperInterface>(otaUrl) std::ref<ConfigWrapperInterface>(webserverPassword)
); );
} }
}; };

View File

@ -9,9 +9,6 @@ StringSettings makeDefaultStringSettings()
#endif #endif
return { return {
#ifdef FEATURE_GARAGE
.garageUrl = {},
#endif
#ifdef FEATURE_NTP #ifdef FEATURE_NTP
.timeServer = "europe.pool.ntp.org", .timeServer = "europe.pool.ntp.org",
#endif #endif
@ -33,7 +30,6 @@ StringSettings makeDefaultStringSettings()
#ifdef FEATURE_OTA #ifdef FEATURE_OTA
.otaServerBranch = {}, .otaServerBranch = {},
#endif #endif
.webserver_password = {},
}; };
} }
} // namespace presets } // namespace presets

View File

@ -6,10 +6,6 @@
struct StringSettings struct StringSettings
{ {
#ifdef FEATURE_GARAGE
std::string garageUrl;
#endif
#ifdef FEATURE_NTP #ifdef FEATURE_NTP
std::string timeServer; std::string timeServer;
#endif #endif
@ -35,15 +31,11 @@ struct StringSettings
#ifdef FEATURE_OTA #ifdef FEATURE_OTA
std::string otaServerBranch; std::string otaServerBranch;
#endif #endif
std::string webserver_password;
}; };
template<typename T> template<typename T>
void StringSettings::executeForEveryCommonSetting(T &&callable) void StringSettings::executeForEveryCommonSetting(T &&callable)
{ {
#ifdef FEATURE_GARAGE
callable("garageUrl", garageUrl);
#endif
#ifdef FEATURE_NTP #ifdef FEATURE_NTP
callable("timeServer", timeServer); callable("timeServer", timeServer);
#endif #endif
@ -75,7 +67,6 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
#ifdef FEATURE_DNS_NS #ifdef FEATURE_DNS_NS
callable("dnskey", dns_key); callable("dnskey", dns_key);
#endif #endif
callable("webpw", webserver_password);
} }
template<typename T> template<typename T>

View File

@ -30,6 +30,7 @@
#include "webserver_dumpnvs.h" #include "webserver_dumpnvs.h"
#endif #endif
#include "globals.h" #include "globals.h"
#include "newsettings.h"
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -188,7 +189,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
char tmpBuf[256]; char tmpBuf[256];
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) if (key_result == ESP_OK && (configs.webserverPassword.value.empty() || configs.webserverPassword.value == tmpBuf))
{ {
if (!menuDisplayChanged()) if (!menuDisplayChanged())
{ {

View File

@ -23,6 +23,7 @@
#include "buttons.h" #include "buttons.h"
#include "globals.h" #include "globals.h"
#include "webserver_lock.h" #include "webserver_lock.h"
#include "newsettings.h"
#ifdef FEATURE_WEBSERVER #ifdef FEATURE_WEBSERVER
using esphttpdutils::HtmlTag; using esphttpdutils::HtmlTag;
@ -57,7 +58,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
char tmpBuf[256]; char tmpBuf[256];
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) if (key_result == ESP_OK && (configs.webserverPassword.value.empty() || configs.webserverPassword.value == tmpBuf))
{ {
body += "{"; body += "{";
@ -148,7 +149,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
body = body.erase(lastEckig+1, 1); body = body.erase(lastEckig+1, 1);
} }
else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password) else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != configs.webserverPassword.value)
{ {
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", "");
} }

View File

@ -58,7 +58,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
char tmpBuf[256]; char tmpBuf[256];
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) if (key_result == ESP_OK && (configs.webserverPassword.value.empty() || configs.webserverPassword.value == tmpBuf))
{ {
body += "{"; body += "{";
if (asyncOta) if (asyncOta)
@ -75,7 +75,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
body += "}"; body += "}";
} }
else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password) else if (key_result != ESP_ERR_NOT_FOUND && configs.webserverPassword.value == tmpBuf)
{ {
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", "");
} }
@ -116,7 +116,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
char tmpBuf[256]; char tmpBuf[256];
const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256);
if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) if (key_result == ESP_OK && (configs.webserverPassword.value.empty() || configs.webserverPassword.value == tmpBuf))
{ {
body += "{"; body += "{";
@ -176,7 +176,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
if (std::string::npos != lastEckig) if (std::string::npos != lastEckig)
body = body.erase(lastEckig+1, 1); body = body.erase(lastEckig+1, 1);
} }
else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password) else if (key_result != ESP_ERR_NOT_FOUND && configs.webserverPassword.value == tmpBuf)
{ {
CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", "");