Merge branch 'pr2320' into dev
This commit is contained in:
commit
aa5087cc8a
@ -30,6 +30,7 @@ class WebApiClass {
|
||||
public:
|
||||
WebApiClass();
|
||||
void init(Scheduler& scheduler);
|
||||
void reload();
|
||||
|
||||
static bool checkCredentials(AsyncWebServerRequest* request);
|
||||
static bool checkCredentialsReadonly(AsyncWebServerRequest* request);
|
||||
|
||||
@ -8,9 +8,11 @@ class WebApiWsConsoleClass {
|
||||
public:
|
||||
WebApiWsConsoleClass();
|
||||
void init(AsyncWebServer& server, Scheduler& scheduler);
|
||||
void reload();
|
||||
|
||||
private:
|
||||
AsyncWebSocket _ws;
|
||||
AuthenticationMiddleware _simpleDigestAuth;
|
||||
|
||||
Task _wsCleanupTask;
|
||||
void wsCleanupTaskCb();
|
||||
|
||||
@ -11,6 +11,7 @@ class WebApiWsLiveClass {
|
||||
public:
|
||||
WebApiWsLiveClass();
|
||||
void init(AsyncWebServer& server, Scheduler& scheduler);
|
||||
void reload();
|
||||
|
||||
private:
|
||||
static void generateInverterCommonJsonResponse(JsonObject& root, std::shared_ptr<InverterAbstract> inv);
|
||||
@ -24,6 +25,7 @@ private:
|
||||
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
|
||||
|
||||
AsyncWebSocket _ws;
|
||||
AuthenticationMiddleware _simpleDigestAuth;
|
||||
|
||||
uint32_t _lastPublishStats[INV_MAX_COUNT] = { 0 };
|
||||
|
||||
|
||||
@ -39,6 +39,12 @@ void WebApiClass::init(Scheduler& scheduler)
|
||||
_server.begin();
|
||||
}
|
||||
|
||||
void WebApiClass::reload()
|
||||
{
|
||||
_webApiWsConsole.reload();
|
||||
_webApiWsLive.reload();
|
||||
}
|
||||
|
||||
bool WebApiClass::checkCredentials(AsyncWebServerRequest* request)
|
||||
{
|
||||
CONFIG_T& config = Configuration.get();
|
||||
|
||||
@ -71,6 +71,8 @@ void WebApiSecurityClass::onSecurityPost(AsyncWebServerRequest* request)
|
||||
WebApi.writeConfig(retMsg);
|
||||
|
||||
WebApi.sendJsonResponse(request, response, __FUNCTION__, __LINE__);
|
||||
|
||||
WebApi.reload();
|
||||
}
|
||||
|
||||
void WebApiSecurityClass::onAuthenticateGet(AsyncWebServerRequest* request)
|
||||
|
||||
@ -21,16 +21,30 @@ void WebApiWsConsoleClass::init(AsyncWebServer& server, Scheduler& scheduler)
|
||||
|
||||
scheduler.addTask(_wsCleanupTask);
|
||||
_wsCleanupTask.enable();
|
||||
|
||||
_simpleDigestAuth.setUsername(AUTH_USERNAME);
|
||||
_simpleDigestAuth.setRealm("console websocket");
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
void WebApiWsConsoleClass::reload()
|
||||
{
|
||||
_ws.removeMiddleware(&_simpleDigestAuth);
|
||||
|
||||
auto const& config = Configuration.get();
|
||||
|
||||
if (config.Security.AllowReadonly) { return; }
|
||||
|
||||
_ws.enable(false);
|
||||
_simpleDigestAuth.setPassword(config.Security.Password);
|
||||
_ws.addMiddleware(&_simpleDigestAuth);
|
||||
_ws.closeAll();
|
||||
_ws.enable(true);
|
||||
}
|
||||
|
||||
void WebApiWsConsoleClass::wsCleanupTaskCb()
|
||||
{
|
||||
// see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients
|
||||
_ws.cleanupClients();
|
||||
|
||||
if (Configuration.get().Security.AllowReadonly) {
|
||||
_ws.setAuthentication("", "");
|
||||
} else {
|
||||
_ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security.Password);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,18 +36,31 @@ void WebApiWsLiveClass::init(AsyncWebServer& server, Scheduler& scheduler)
|
||||
|
||||
scheduler.addTask(_sendDataTask);
|
||||
_sendDataTask.enable();
|
||||
_simpleDigestAuth.setUsername(AUTH_USERNAME);
|
||||
_simpleDigestAuth.setRealm("live websocket");
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
void WebApiWsLiveClass::reload()
|
||||
{
|
||||
_ws.removeMiddleware(&_simpleDigestAuth);
|
||||
|
||||
auto const& config = Configuration.get();
|
||||
|
||||
if (config.Security.AllowReadonly) { return; }
|
||||
|
||||
_ws.enable(false);
|
||||
_simpleDigestAuth.setPassword(config.Security.Password);
|
||||
_ws.addMiddleware(&_simpleDigestAuth);
|
||||
_ws.closeAll();
|
||||
_ws.enable(true);
|
||||
}
|
||||
|
||||
void WebApiWsLiveClass::wsCleanupTaskCb()
|
||||
{
|
||||
// see: https://github.com/me-no-dev/ESPAsyncWebServer#limiting-the-number-of-web-socket-clients
|
||||
_ws.cleanupClients();
|
||||
|
||||
if (Configuration.get().Security.AllowReadonly) {
|
||||
_ws.setAuthentication("", "");
|
||||
} else {
|
||||
_ws.setAuthentication(AUTH_USERNAME, Configuration.get().Security.Password);
|
||||
}
|
||||
}
|
||||
|
||||
void WebApiWsLiveClass::sendDataTaskCb()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user