Moved webserverPassword into newSettings

This commit is contained in:
2021-12-29 06:19:09 +01:00
parent b013bbd693
commit 4e1943dbc8
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> otaUrl {std::string{}, DoReset, StringOr<StringEmpty, StringValidUrl>, "otaUrl" };
ConfigWrapper<std::string> webserverPassword {std::string{}, DoReset, {}, "websPassword" };
#define NEW_SETTINGS(x) \
x(baseMacAddressOverride) \
x(hostname) \
@ -249,7 +251,9 @@ public:
\
x(cloudUrl) \
x(udpCloudHost) \
// x(otaUrl)
x(otaUrl) \
\
// x(webserverPassword)
template<typename T>
void callForEveryConfig(T &&callback)
@ -257,7 +261,7 @@ public:
#define HELPER(x) callback(x);
NEW_SETTINGS(HELPER)
#undef HELPER
callback(otaUrl);
callback(webserverPassword);
}
auto getAllConfigParams()
@ -266,7 +270,7 @@ public:
#define HELPER(x) std::ref<ConfigWrapperInterface>(x),
NEW_SETTINGS(HELPER)
#undef HELPER
std::ref<ConfigWrapperInterface>(otaUrl)
std::ref<ConfigWrapperInterface>(webserverPassword)
);
}
};

View File

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

View File

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

View File

@ -30,6 +30,7 @@
#include "webserver_dumpnvs.h"
#endif
#include "globals.h"
#include "newsettings.h"
using namespace std::chrono_literals;
@ -188,7 +189,7 @@ esp_err_t webserver_status_handler(httpd_req_t *req)
char 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())
{

View File

@ -23,6 +23,7 @@
#include "buttons.h"
#include "globals.h"
#include "webserver_lock.h"
#include "newsettings.h"
#ifdef FEATURE_WEBSERVER
using esphttpdutils::HtmlTag;
@ -57,7 +58,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
char 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 += "{";
@ -148,7 +149,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req)
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", "");
}

View File

@ -58,7 +58,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
char 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 += "{";
if (asyncOta)
@ -75,7 +75,7 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req)
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", "");
}
@ -116,7 +116,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
char 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 += "{";
@ -176,7 +176,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req)
if (std::string::npos != lastEckig)
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", "");