Skip to content

Commit

Permalink
fix: add auth check on battery, huawei and powermeter API endpoints (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm authored Aug 8, 2024
1 parent 82b28e3 commit df11db1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/WebApi_Huawei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,12 @@ void WebApiHuaweiClass::onPost(AsyncWebServerRequest* request)
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
}




void WebApiHuaweiClass::onAdminGet(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
if (!WebApi.checkCredentials(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();
Expand All @@ -167,7 +164,7 @@ void WebApiHuaweiClass::onAdminGet(AsyncWebServerRequest* request)
root["voltage_limit"] = static_cast<int>(config.Huawei.Auto_Power_Voltage_Limit * 100) / 100.0;
root["enable_voltage_limit"] = static_cast<int>(config.Huawei.Auto_Power_Enable_Voltage_Limit * 100) / 100.0;
root["lower_power_limit"] = config.Huawei.Auto_Power_Lower_Power_Limit;
root["upper_power_limit"] = config.Huawei.Auto_Power_Upper_Power_Limit;
root["upper_power_limit"] = config.Huawei.Auto_Power_Upper_Power_Limit;
root["stop_batterysoc_threshold"] = config.Huawei.Auto_Power_Stop_BatterySoC_Threshold;
root["target_power_consumption"] = config.Huawei.Auto_Power_Target_Power_Consumption;

Expand Down Expand Up @@ -213,7 +210,7 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
config.Huawei.Auto_Power_Voltage_Limit = root["voltage_limit"].as<float>();
config.Huawei.Auto_Power_Enable_Voltage_Limit = root["enable_voltage_limit"].as<float>();
config.Huawei.Auto_Power_Lower_Power_Limit = root["lower_power_limit"].as<float>();
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
config.Huawei.Auto_Power_Stop_BatterySoC_Threshold = root["stop_batterysoc_threshold"];
config.Huawei.Auto_Power_Target_Power_Consumption = root["target_power_consumption"];

Expand Down
4 changes: 4 additions & 0 deletions src/WebApi_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ void WebApiBatteryClass::onStatus(AsyncWebServerRequest* request)

void WebApiBatteryClass::onAdminGet(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentials(request)) {
return;
}

onStatus(request);
}

Expand Down
4 changes: 4 additions & 0 deletions src/WebApi_powermeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void WebApiPowerMeterClass::init(AsyncWebServer& server, Scheduler& scheduler)

void WebApiPowerMeterClass::onStatus(AsyncWebServerRequest* request)
{
if (!WebApi.checkCredentialsReadonly(request)) {
return;
}

AsyncJsonResponse* response = new AsyncJsonResponse();
auto& root = response->getRoot();
const CONFIG_T& config = Configuration.get();
Expand Down

0 comments on commit df11db1

Please sign in to comment.