From 61a711c8f6b85667a80fbe38ee6de3f82730b874 Mon Sep 17 00:00:00 2001 From: proddy Date: Sat, 25 Jul 2020 18:24:45 +0200 Subject: [PATCH] added show users command - #435 --- README.md | 1 + src/system.cpp | 32 ++++++++++++++++++++++++-------- src/system.h | 5 +++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 946a83629..72da0e0d8 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ system set show show mqtt + show users passwd restart set wifi hostname diff --git a/src/system.cpp b/src/system.cpp index 284c8b939..0b5bedb27 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -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 & 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 & 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" diff --git a/src/system.h b/src/system.h index 3b3cd0d52..3aa20de2e 100644 --- a/src/system.h +++ b/src/system.h @@ -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;