diff --git a/esp-link/cgitelnet.c b/esp-link/cgitelnet.c index 0530fc8..2791e34 100644 --- a/esp-link/cgitelnet.c +++ b/esp-link/cgitelnet.c @@ -3,6 +3,8 @@ #include "config.h" #include "serbridge.h" +static char *portMode[] = { "open", "disabled", "secure" }; + // Cgi to return choice of Telnet ports int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) { char buff[80]; @@ -96,3 +98,23 @@ int ICACHE_FLASH_ATTR cgiTelnet(HttpdConnData *connData) { return HTTPD_CGI_DONE; } } + +static char *portMode2string(int8_t m) { //Should we put this into flash? + if (m < 0 || m > 2) return "?"; + return portMode[m]; + } + + // print various Telnet information into json buffer + int ICACHE_FLASH_ATTR printTelnetSecurity(char *buff) { + int len; + + len = os_sprintf(buff, + "{ \"port0mode\": \"%s\", \"port0portnumber\": \"%d\", \"port0pwd\": \"%s\", " + "\"port1mode\": \"%s\", \"port1portnumber\": \"%d\", \"port1pwd\": \"%s\" }", + portMode2string(flashConfig.telnet_port0mode), flashConfig.telnet_port0, flashConfig.telnet_port0pass, + portMode2string(flashConfig.telnet_port1mode), flashConfig.telnet_port1, flashConfig.telnet_port1pass + ); + + return len; + } + \ No newline at end of file diff --git a/esp-link/config.c b/esp-link/config.c index ab0f385..40a456b 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -39,6 +39,8 @@ FlashConfig flashDefault = { .telnet_port1 = 2323, .telnet_port0mode = 0, .telnet_port1mode = 0, + .telnet_port0pass = "123456", + .telnet_port1pass = "123456", }; typedef union { @@ -166,8 +168,16 @@ bool ICACHE_FLASH_ATTR configRestore(void) { flashConfig.stop_bits = flashDefault.stop_bits; } - if (flashConfig.telnet_port0 == 0) { flashConfig.telnet_port0 = flashDefault.telnet_port0; } - if (flashConfig.telnet_port1 == 0) { flashConfig.telnet_port1 = flashDefault.telnet_port1; } + if (flashConfig.telnet_port0 == 0) { + flashConfig.telnet_port0 = flashDefault.telnet_port0; + flashConfig.telnet_port0mode = flashDefault.telnet_port0mode; + flashConfig.telnet_port0pass = flashDefault.telnet_port0pass; + } + if (flashConfig.telnet_port1 == 0) { + flashConfig.telnet_port1 = flashDefault.telnet_port1; + flashConfig.telnet_port1mode = flashDefault.telnet_port1mode; + flashConfig.telnet_port1pass = flashDefault.telnet_port1pass; + } return true; } diff --git a/esp-link/config.h b/esp-link/config.h index 094c044..5998215 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -45,6 +45,8 @@ typedef struct { telnet_port1; int8_t telnet_port0mode, telnet_port1mode; + char telnet_port0pass[32], + telnet_port1pass[32]; } FlashConfig; extern FlashConfig flashConfig; extern FlashConfig flashDefault; diff --git a/esp-link/main.c b/esp-link/main.c index 90202fa..38a6817 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -180,7 +180,7 @@ user_init(void) { httpdInit(builtInUrls, 80); WEB_Init(); - // init the wifi-serial transparent bridge (port 23) + // init the wifi-serial configurable transparent bridge (port defaults 23&2323) serbridgeInit(); serbridgeStart(0, flashConfig.telnet_port0, flashDefault.telnet_port0mode); serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode);