|
|
@ -14,6 +14,7 @@ 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; |
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
@ -51,11 +52,20 @@ bool _telnetWrite(unsigned char clientId, void *data, size_t len) { |
|
|
|
unsigned char _telnetWrite(void *data, size_t len) { |
|
|
|
unsigned char count = 0; |
|
|
|
for (unsigned char i = 0; i < TELNET_MAX_CLIENTS; i++) { |
|
|
|
if (_telnetWrite(i, data, len)) ++count; |
|
|
|
|
|
|
|
// Do not send broadcast messages to unauthenticated clients
|
|
|
|
if (_authenticated[i]) { |
|
|
|
if (_telnetWrite(i, data, len)) ++count; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return count; |
|
|
|
} |
|
|
|
|
|
|
|
bool _telnetWrite(unsigned char clientId, const char * message) { |
|
|
|
_telnetWrite(clientId, (void *) message, strlen(message)); |
|
|
|
} |
|
|
|
|
|
|
|
void _telnetData(unsigned char clientId, void *data, size_t len) { |
|
|
|
|
|
|
|
// Skip first message since it's always garbage
|
|
|
@ -80,7 +90,20 @@ void _telnetData(unsigned char clientId, void *data, size_t len) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Inject into Embedis stream
|
|
|
|
// 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; |
|
|
|
} |
|
|
|
|
|
|
|
// Inject command
|
|
|
|
settingsInject(data, len); |
|
|
|
|
|
|
|
} |
|
|
@ -109,6 +132,7 @@ void _telnetNewClient(AsyncClient *client) { |
|
|
|
} |
|
|
|
|
|
|
|
for (unsigned char i = 0; i < TELNET_MAX_CLIENTS; i++) { |
|
|
|
|
|
|
|
if (!_telnetClients[i] || !_telnetClients[i]->connected()) { |
|
|
|
|
|
|
|
_telnetClients[i] = client; |
|
|
@ -144,6 +168,8 @@ void _telnetNewClient(AsyncClient *client) { |
|
|
|
#endif
|
|
|
|
|
|
|
|
_telnetFirst = true; |
|
|
|
_authenticated[i] = false; |
|
|
|
_telnetWrite(i, "Password: "); |
|
|
|
wifiReconnectCheck(); |
|
|
|
return; |
|
|
|
|
|
|
|