mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
replace restart/format endpoints with system calls
This commit is contained in:
@@ -14,9 +14,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
|
||||
, _uploadFileService(server, &_securitySettingsService)
|
||||
, _mqttSettingsService(server, fs, &_securitySettingsService)
|
||||
, _mqttStatus(server, &_mqttSettingsService, &_securitySettingsService)
|
||||
, _authenticationService(server, &_securitySettingsService)
|
||||
, _restartService(server, &_securitySettingsService)
|
||||
, _factoryResetService(server, fs, &_securitySettingsService) {
|
||||
, _authenticationService(server, &_securitySettingsService) {
|
||||
//
|
||||
// Serve static web resources
|
||||
//
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
#include "APSettingsService.h"
|
||||
#include "APStatus.h"
|
||||
#include "AuthenticationService.h"
|
||||
#include "FactoryResetService.h"
|
||||
#include "MqttSettingsService.h"
|
||||
#include "MqttStatus.h"
|
||||
#include "NTPSettingsService.h"
|
||||
#include "NTPStatus.h"
|
||||
#include "UploadFileService.h"
|
||||
#include "RestartService.h"
|
||||
#include "SecuritySettingsService.h"
|
||||
#include "WiFiScanner.h"
|
||||
#include "NetworkSettingsService.h"
|
||||
@@ -68,12 +66,6 @@ class ESP8266React {
|
||||
return _apSettingsService.getAPNetworkStatus() == APNetworkStatus::ACTIVE;
|
||||
}
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
void factoryReset() {
|
||||
_factoryResetService.factoryReset();
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
SecuritySettingsService _securitySettingsService;
|
||||
NetworkSettingsService _networkSettingsService;
|
||||
@@ -87,8 +79,6 @@ class ESP8266React {
|
||||
MqttSettingsService _mqttSettingsService;
|
||||
MqttStatus _mqttStatus;
|
||||
AuthenticationService _authenticationService;
|
||||
RestartService _restartService;
|
||||
FactoryResetService _factoryResetService;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "FactoryResetService.h"
|
||||
|
||||
FactoryResetService::FactoryResetService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||
: fs(fs) {
|
||||
server->on(FACTORY_RESET_SERVICE_PATH,
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { handleRequest(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
}
|
||||
|
||||
void FactoryResetService::handleRequest(AsyncWebServerRequest * request) {
|
||||
request->onDisconnect([this] { factoryReset(); });
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete function assumes that all files are stored flat, within the config directory.
|
||||
*/
|
||||
void FactoryResetService::factoryReset() {
|
||||
// TODO To replaced with fs.rmdir(FS_CONFIG_DIRECTORY) now we're using IDF 4.2
|
||||
File root = fs->open(FS_CONFIG_DIRECTORY);
|
||||
File file;
|
||||
while ((file = root.openNextFile())) {
|
||||
String path = file.path();
|
||||
file.close();
|
||||
fs->remove(path);
|
||||
}
|
||||
|
||||
RestartService::restartNow();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef FactoryResetService_h
|
||||
#define FactoryResetService_h
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <FS.h>
|
||||
|
||||
#include "SecurityManager.h"
|
||||
#include "RestartService.h"
|
||||
|
||||
#define FS_CONFIG_DIRECTORY "/config"
|
||||
#define FACTORY_RESET_SERVICE_PATH "/rest/factoryReset"
|
||||
|
||||
class FactoryResetService {
|
||||
public:
|
||||
FactoryResetService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager);
|
||||
|
||||
void factoryReset();
|
||||
|
||||
private:
|
||||
FS * fs;
|
||||
void handleRequest(AsyncWebServerRequest * request);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "RestartService.h"
|
||||
|
||||
#include <esp_ota_ops.h>
|
||||
|
||||
#include "../../src/emsesp_stub.hpp"
|
||||
|
||||
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||
server->on(RESTART_SERVICE_PATH,
|
||||
HTTP_POST,
|
||||
securityManager->wrapRequest([this](AsyncWebServerRequest * request) { restart(request); }, AuthenticationPredicates::IS_ADMIN));
|
||||
}
|
||||
|
||||
void RestartService::restartNow() {
|
||||
emsesp::EMSESP::system_.restart_requested(true); // will be handled by the main loop
|
||||
}
|
||||
|
||||
void RestartService::restart(AsyncWebServerRequest * request) {
|
||||
request->onDisconnect(RestartService::restartNow);
|
||||
request->send(200);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef RestartService_h
|
||||
#define RestartService_h
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#include "SecurityManager.h"
|
||||
|
||||
#define RESTART_SERVICE_PATH "/rest/restart"
|
||||
|
||||
class RestartService {
|
||||
public:
|
||||
RestartService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
|
||||
static void restartNow();
|
||||
|
||||
private:
|
||||
void restart(AsyncWebServerRequest * request);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef UploadFileService_h
|
||||
#define UploadFileService_h
|
||||
|
||||
#include "RestartService.h"
|
||||
#include "SecurityManager.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
Reference in New Issue
Block a user