Browse Source

Option to disable password in telnet connections, default is enabled

webui
Xose Pérez 6 years ago
parent
commit
261748e5e8
2 changed files with 32 additions and 16 deletions
  1. +4
    -0
      code/espurna/config/general.h
  2. +28
    -16
      code/espurna/telnet.ino

+ 4
- 0
code/espurna/config/general.h View File

@ -110,6 +110,10 @@
#define TELNET_STA 0 // By default, disallow connections via STA interface
#endif
#ifndef TELNET_PASSWORD
#define TELNET_PASSWORD 1 // Request password to start telnet session by default
#endif
#define TELNET_PORT 23 // Port to listen to telnet clients
#define TELNET_MAX_CLIENTS 1 // Max number of concurrent telnet clients


+ 28
- 16
code/espurna/telnet.ino View File

@ -14,8 +14,10 @@ Parts of the code have been borrowed from Thomas Sarlandie's NetServer
AsyncServer * _telnetServer;
AsyncClient * _telnetClients[TELNET_MAX_CLIENTS];
bool _authenticated[TELNET_MAX_CLIENTS];
bool _telnetFirst = true;
#if TELNET_PASSWORD
bool _authenticated[TELNET_MAX_CLIENTS];
#endif
// -----------------------------------------------------------------------------
// Private methods
@ -53,10 +55,14 @@ unsigned char _telnetWrite(void *data, size_t len) {
unsigned char count = 0;
for (unsigned char i = 0; i < TELNET_MAX_CLIENTS; i++) {
// Do not send broadcast messages to unauthenticated clients
if (_authenticated[i]) {
#if TELNET_PASSWORD
// Do not send broadcast messages to unauthenticated clients
if (_authenticated[i]) {
if (_telnetWrite(i, data, len)) ++count;
}
#else
if (_telnetWrite(i, data, len)) ++count;
}
#endif
}
return count;
@ -91,17 +97,19 @@ void _telnetData(unsigned char clientId, void *data, size_t len) {
}
// Password
if (!_authenticated[clientId]) {
String password = getAdminPass();
if (strncmp(p, password.c_str(), password.length()) == 0) {
DEBUG_MSG_P(PSTR("[TELNET] Client #%d authenticated\n"), clientId);
_telnetWrite(clientId, "Welcome!\n");
_authenticated[clientId] = true;
} else {
_telnetWrite(clientId, "Password: ");
#if TELNET_PASSWORD
if (!_authenticated[clientId]) {
String password = getAdminPass();
if (strncmp(p, password.c_str(), password.length()) == 0) {
DEBUG_MSG_P(PSTR("[TELNET] Client #%d authenticated\n"), clientId);
_telnetWrite(clientId, "Welcome!\n");
_authenticated[clientId] = true;
} else {
_telnetWrite(clientId, "Password: ");
}
return;
}
return;
}
#endif // TELNET_PASSWORD
// Inject command
settingsInject(data, len);
@ -167,10 +175,14 @@ void _telnetNewClient(AsyncClient *client) {
debugClearCrashInfo();
#endif
#if TELNET_PASSWORD
_authenticated[i] = false;
_telnetWrite(i, "Password: ");
#endif
_telnetFirst = true;
_authenticated[i] = false;
_telnetWrite(i, "Password: ");
wifiReconnectCheck();
return;
}


Loading…
Cancel
Save