mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
added back format console command
This commit is contained in:
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
FactoryResetService::FactoryResetService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : fs(fs) {
|
FactoryResetService::FactoryResetService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
server->on(FACTORY_RESET_SERVICE_PATH,
|
: fs(fs) {
|
||||||
HTTP_POST,
|
server->on(FACTORY_RESET_SERVICE_PATH,
|
||||||
securityManager->wrapRequest(std::bind(&FactoryResetService::handleRequest, this, _1),
|
HTTP_POST,
|
||||||
AuthenticationPredicates::IS_ADMIN));
|
securityManager->wrapRequest(std::bind(&FactoryResetService::handleRequest, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FactoryResetService::handleRequest(AsyncWebServerRequest* request) {
|
void FactoryResetService::handleRequest(AsyncWebServerRequest * request) {
|
||||||
request->onDisconnect(std::bind(&FactoryResetService::factoryReset, this));
|
request->onDisconnect(std::bind(&FactoryResetService::factoryReset, this));
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,16 +19,16 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest* request) {
|
|||||||
*/
|
*/
|
||||||
void FactoryResetService::factoryReset() {
|
void FactoryResetService::factoryReset() {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
File root = fs->open(FS_CONFIG_DIRECTORY);
|
File root = fs->open(FS_CONFIG_DIRECTORY);
|
||||||
File file;
|
File file;
|
||||||
while (file = root.openNextFile()) {
|
while (file = root.openNextFile()) {
|
||||||
fs->remove(file.name());
|
fs->remove(file.name());
|
||||||
}
|
}
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
|
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
|
||||||
while (configDirectory.next()) {
|
while (configDirectory.next()) {
|
||||||
fs->remove(configDirectory.fileName());
|
fs->remove(configDirectory.fileName());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
RestartService::restartNow();
|
RestartService::restartNow();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,27 @@ void System::restart() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// format fs
|
||||||
|
// format the FS. Wipes everything.
|
||||||
|
void System::format(uuid::console::Shell & shell) {
|
||||||
|
auto msg = F("Resetting all settings to defaults");
|
||||||
|
shell.logger().warning(msg);
|
||||||
|
shell.flush();
|
||||||
|
|
||||||
|
#ifndef EMSESP_STANDALONE
|
||||||
|
EMSuart::stop();
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
LittleFS.format();
|
||||||
|
#elif defined(ESP32)
|
||||||
|
SPIFFS.format();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
System::restart();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// return free heap mem as a percentage
|
// return free heap mem as a percentage
|
||||||
uint8_t System::free_mem() {
|
uint8_t System::free_mem() {
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
@@ -444,6 +465,23 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
|||||||
restart();
|
restart();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||||
|
CommandFlags::ADMIN,
|
||||||
|
flash_string_vector{F_(format)},
|
||||||
|
[](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) {
|
||||||
|
shell.enter_password(F_(password_prompt), [=](Shell & shell, bool completed, const std::string & password) {
|
||||||
|
if (completed) {
|
||||||
|
EMSESP::esp8266React.getSecuritySettingsService()->read([&](SecuritySettings & securitySettings) {
|
||||||
|
if (securitySettings.jwtSecret.equals(password.c_str())) {
|
||||||
|
format(shell);
|
||||||
|
} else {
|
||||||
|
shell.println(F("incorrect password"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||||
CommandFlags::ADMIN,
|
CommandFlags::ADMIN,
|
||||||
flash_string_vector{F_(passwd)},
|
flash_string_vector{F_(passwd)},
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class System {
|
|||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
static void restart();
|
static void restart();
|
||||||
|
static void format(uuid::console::Shell & shell);
|
||||||
static uint8_t free_mem();
|
static uint8_t free_mem();
|
||||||
void syslog_init();
|
void syslog_init();
|
||||||
void set_heartbeat(bool system_heartbeat);
|
void set_heartbeat(bool system_heartbeat);
|
||||||
|
|||||||
Reference in New Issue
Block a user