mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
added show users command - #435
This commit is contained in:
@@ -82,6 +82,7 @@ system
|
||||
set
|
||||
show
|
||||
show mqtt
|
||||
show users
|
||||
passwd
|
||||
restart
|
||||
set wifi hostname <name>
|
||||
|
||||
@@ -26,6 +26,7 @@ MAKE_PSTR_WORD(hostname)
|
||||
MAKE_PSTR_WORD(wifi)
|
||||
MAKE_PSTR_WORD(ssid)
|
||||
MAKE_PSTR_WORD(heartbeat)
|
||||
MAKE_PSTR_WORD(users)
|
||||
|
||||
MAKE_PSTR(host_fmt, "Host = %s")
|
||||
MAKE_PSTR(hostname_fmt, "WiFi Hostname = %s")
|
||||
@@ -221,17 +222,15 @@ void System::start() {
|
||||
}
|
||||
|
||||
// fetch settings
|
||||
std::string hostname;
|
||||
EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { tx_mode_ = settings.tx_mode; });
|
||||
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & settings) { system_heartbeat_ = settings.system_heartbeat; });
|
||||
EMSESP::esp8266React.getWiFiSettingsService()->read(
|
||||
[&](WiFiSettings & wifiSettings) { LOG_INFO(F("System %s booted (EMS-ESP version %s)"), wifiSettings.hostname, EMSESP_APP_VERSION); });
|
||||
|
||||
syslog_.log_level((uuid::log::Level)syslog_level_);
|
||||
syslog_init(); // init SysLog
|
||||
|
||||
#if defined(ESP32)
|
||||
LOG_INFO(F("System booted (EMS-ESP version %s ESP32)"), EMSESP_APP_VERSION);
|
||||
#else
|
||||
LOG_INFO(F("System booted (EMS-ESP version %s)"), EMSESP_APP_VERSION);
|
||||
#endif
|
||||
|
||||
if (LED_GPIO) {
|
||||
pinMode(LED_GPIO, OUTPUT); // LED pin, 0 means disabled
|
||||
}
|
||||
@@ -372,6 +371,19 @@ int8_t System::wifi_quality() {
|
||||
return 2 * (dBm + 100);
|
||||
}
|
||||
|
||||
// print users to console
|
||||
void System::show_users(uuid::console::Shell & shell) {
|
||||
shell.printfln(F("Users:"));
|
||||
|
||||
EMSESP::esp8266React.getSecuritySettingsService()->read([&](SecuritySettings & securitySettings) {
|
||||
for (User user : securitySettings.users) {
|
||||
shell.printfln(F(" username: %s password: %s is_admin: %s"), user.username, user.password, user.admin ? "yes" : "no");
|
||||
}
|
||||
});
|
||||
|
||||
shell.println();
|
||||
}
|
||||
|
||||
void System::show_system(uuid::console::Shell & shell) {
|
||||
shell.printfln(F("Uptime: %s"), uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str());
|
||||
|
||||
@@ -609,6 +621,11 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
flash_string_vector{F_(show), F_(mqtt)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) { Mqtt::show_mqtt(shell); });
|
||||
|
||||
EMSESPShell::commands->add_command(ShellContext::SYSTEM,
|
||||
CommandFlags::ADMIN,
|
||||
flash_string_vector{F_(show), F_(users)},
|
||||
[](Shell & shell, const std::vector<std::string> & arguments __attribute__((unused))) { System::show_users(shell); });
|
||||
|
||||
|
||||
// enter the context
|
||||
Console::enter_custom_context(shell, context);
|
||||
@@ -618,8 +635,7 @@ void System::console_commands(Shell & shell, unsigned int context) {
|
||||
void System::check_upgrade() {
|
||||
// check for v1.9. It uses SPIFFS and only on the ESP8266
|
||||
#if defined(ESP8266)
|
||||
|
||||
Serial.begin(115200); // TODO remove
|
||||
Serial.begin(115200); // TODO remove, just for debugging
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
@@ -50,8 +50,8 @@ class System {
|
||||
static void mqtt_commands(const char * message);
|
||||
|
||||
static uint8_t free_mem();
|
||||
static void upload_status(bool in_progress);
|
||||
static bool upload_status();
|
||||
static void upload_status(bool in_progress);
|
||||
static bool upload_status();
|
||||
|
||||
void syslog_init();
|
||||
|
||||
@@ -97,6 +97,7 @@ class System {
|
||||
void system_check();
|
||||
|
||||
static void show_system(uuid::console::Shell & shell);
|
||||
static void show_users(uuid::console::Shell & shell);
|
||||
static int8_t wifi_quality();
|
||||
|
||||
bool system_healthy_ = false;
|
||||
|
||||
Reference in New Issue
Block a user