new command 'set admin password'

This commit is contained in:
proddy
2025-02-25 20:46:43 +01:00
parent 61b9bd7581
commit cfbd0168c3
4 changed files with 37 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ For more details go to [docs.emsesp.org](https://docs.emsesp.org/).
- CR11 thermostat [#2295](https://github.com/emsesp/EMS-ESP32/issues/2295)
- Show ESP32's CPU temp in Hardware Status
- vacation mode for the CR50 [#2403](https://github.com/emsesp/EMS-ESP32/issues/2403)
- new Console command "set admin password" to set WebUI admin password
## Fixed

View File

@@ -207,6 +207,40 @@ static void setup_commands(std::shared_ptr<Commands> const & commands) {
//
// SET commands
//
commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(admin), F_(password)},
[](Shell & shell, const std::vector<std::string> & arguments) {
shell.enter_password(F_(new_password_prompt1), [](Shell & shell, bool completed, const std::string & password1) {
if (completed) {
shell.enter_password(F_(new_password_prompt2), [password1](Shell & shell, bool completed, const std::string & password2) {
if (completed) {
if (password1 == password2) {
#ifndef EMSESP_STANDALONE
EMSESP::esp32React.getSecuritySettingsService()->updateWithoutPropagation(
[&](SecuritySettings & securitySettings) {
// find the username 'admin' and update its password
for (auto & user : securitySettings.users) {
if (user.username == "admin") {
user.password = password2.c_str();
return StateUpdateResult::CHANGED;
}
}
// otherwise add a new admin user
securitySettings.users.emplace_back(F_(admin), password2.c_str(), true);
return StateUpdateResult::CHANGED;
});
#endif
shell.println("Admin user's password updated.");
} else {
shell.println("Passwords do not match");
}
}
});
}
});
});
commands->add_command(ShellContext::MAIN,
CommandFlags::ADMIN,
string_vector{F_(set), F_(wifi), F_(password)},

View File

@@ -35,6 +35,7 @@ MAKE_WORD(show)
MAKE_WORD(su)
MAKE_WORD(scan)
MAKE_WORD(password)
MAKE_WORD(admin)
MAKE_WORD(read)
MAKE_WORD(values)
MAKE_WORD(system)

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.2-dev.22"
#define EMSESP_APP_VERSION "3.7.3-dev.23"