37 #if __has_include ("Commander-API.hpp")
38 #include "Commander-API.hpp"
42#ifdef SHELLMINATOR_ENABLE_WEBSOCKET_MODULE
43#include <WebSocketsServer.h>
48#ifdef SHELLMINATOR_USE_WIFI_CLIENT
51 #define CLIENT_STATE client.connected()
55 #define CLIENT_STATE ( client.status() == ESTABLISHED )
58const uint8_t Shellminator::TELNET_IAC_DONT_LINEMODE[] = { 255, 254, 34 };
59const uint8_t Shellminator::TELNET_IAC_WILL_ECHO[] = { 255, 251, 1 };
60const uint8_t Shellminator::TELNET_IAC_DONT_ECHO[] = { 255, 254, 1 };
61const uint8_t Shellminator::TELNET_IAC_WILL_SUPRESS_GO_AHEAD[] = { 255, 251, 3 };
62const uint8_t Shellminator::TELNET_IAC_DO_SUPRESS_GO_AHEAD[] = { 255, 253, 3 };
76 cmd_buff[ 0 ][ 0 ] =
'\0';
96 cmd_buff[ 0 ][ 0 ] =
'\0';
99 execution_fn = execution_fn_p;
108 server -> setNoDelay(
true );
126 clientTimeout = clientTimeout_p;
134const char Shellminator::helpText[]
PROGMEM = {
136 "\033[1;31m----\033[1;32m Shortcut Keys \033[1;31m----\033[0;37m\r\n"
138 "\033[1;31mCtrl-A\033[1;32m : Jumps the cursor to the beginning of the line.\r\n"
139 "\033[1;31mCtrl-E\033[1;32m : Jumps the cursor to the end of the line.\r\n"
140 "\033[1;31mCtrl-D\033[1;32m : Log Out.\r\n"
141 "\033[1;31mCtrl-R\033[1;32m : Reverse-i-search.\r\n"
142 "\033[1;31mPg-Up\033[1;32m : History search backwards and auto completion.\r\n"
143 "\033[1;31mPg-Down\033[1;32m: History search forward and auto completion.\r\n"
144 "\033[1;31mHome\033[1;32m : Jumps the cursor to the beginning of the line.\r\n"
145 "\033[1;31mEnd\033[1;32m : Jumps the cursor to the end of the line.\r\n"
151const char Shellminator::helpText[] = {
153 "\033[1;31m----\033[1;32m Shortcut Keys \033[1;31m----\033[0;37m\r\n"
155 "\033[1;31mCtrl-A\033[1;32m : Jumps the cursor to the beginning of the line.\r\n"
156 "\033[1;31mCtrl-E\033[1;32m : Jumps the cursor to the end of the line.\r\n"
157 "\033[1;31mCtrl-D\033[1;32m : Log Out.\r\n"
158 "\033[1;31mCtrl-R\033[1;32m : Reverse-i-search.\r\n"
159 "\033[1;31mPg-Up\033[1;32m : History search backwards and auto completion.\r\n"
160 "\033[1;31mPg-Down\033[1;32m: History search forward and auto completion.\r\n"
161 "\033[1;31mHome\033[1;32m : Jumps the cursor to the beginning of the line.\r\n"
162 "\033[1;31mEnd\033[1;32m : Jumps the cursor to the end of the line.\r\n"
168#ifdef SHELLMINATOR_ENABLE_WEBSOCKET_MODULE
172 wsServer = wsServer_p;
173 serverID = serverID_p;
174 webSocketChannel.select( wsServer, serverID );
175 webSocketChannel.setTimeout( 10 );
176 channel = &webSocketChannel;
186 cmd_buff[ 0 ][ 0 ] =
'\0';
196 wsServer = wsServer_p;
198 webSocketChannel.select( wsServer, serverID );
199 webSocketChannel.setTimeout( 10 );
200 channel = &webSocketChannel;
210 cmd_buff[ 0 ][ 0 ] =
'\0';
220 wsServer = wsServer_p;
221 serverID = serverID_p;
222 webSocketChannel.select( wsServer, serverID );
223 channel = &webSocketChannel;
233 cmd_buff[ 0 ][ 0 ] =
'\0';
236 execution_fn = execution_fn_p;
240void Shellminator::webSocketPush( uint8_t data ){
241 webSocketChannel.push( data );
244void Shellminator::webSocketPush( uint8_t* data,
size_t size ){
245 webSocketChannel.push( data, size );
248void Shellminator::websocketDisconnect(){
251 wsServer -> disconnect( serverID );
270 cmd_buff[ 0 ][ 0 ] =
'\0';
290 cmd_buff[ 0 ][ 0 ] =
'\0';
294 execution_fn = execution_fn_p;
347 progmemLogo = progmemLogo_p;
354 logo = (
char*)logo_p;
361 execution_fn = execution_fn_p;
368 channel -> write( 27 );
369 channel -> print( (
const char*)
"[H" );
370 channel -> write( 27 );
371 channel -> print( (
const char*)
"[J" );
385 lastBannerSize += channel -> print( banner );
390 lastBannerSize += channel -> print(
':' );
394 lastBannerSize += channel -> print( bannerPath );
398 lastBannerSize += channel -> print(
' ' );
405 uint32_t firstBuffDim = 1;
412 if( cmd_buff[ i ][ 0 ] ==
'\0' ){
413 firstBuffDim = i - 1;
420 if( firstBuffDim == 0 ){
431 for( i = firstBuffDim; i > 0; i-- ){
433 index = firstBuffDim - i + 1;
435 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
437 sprintf( acceleratorBuffer,
" \033[1;35m%3d \033[0;37m%s\r\n", index, cmd_buff[ i ] );
438 channel -> print( acceleratorBuffer );
443 channel -> print(
' ' );
444 channel -> print(
' ' );
449 channel -> print(
' ' );
450 channel -> print(
' ' );
455 else if( index < 100 ){
457 channel -> print(
' ' );
463 channel -> print( index );
465 channel -> print(
' ' );
466 channel -> print(
' ' );
467 channel -> println( cmd_buff[ i ] );
481 for( i = 0; i < strlen_P( helpText ); i++ ){
483 char c = pgm_read_byte_near( helpText + i );
484 channel -> print( c );
490 channel -> print( helpText );
494 #ifdef COMMANDER_API_VERSION
496 if( commander != NULL ){
544 channel -> print( (
const char*)
"\b \b" );
548void Shellminator::redrawLine(){
551 #ifdef COMMANDER_API_VERSION
559 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
563 redrawHistorySearch();
579 cmd_buff[ 0 ][ cmd_buff_cntr ] =
'\0';
581 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
583 acceleratorBufferPtr = acceleratorBuffer;
585 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\r\033[1;32m%s\033[1;37m:\033[1;34m%s\033[0;37m \033[0K", banner, bannerPath );
591 channel -> print(
'\r' );
602 channel -> write( 27 );
603 channel -> print(
"[0K" );
607 #ifdef COMMANDER_API_VERSION
614 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
617 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
625 for( i = 0; i < cmd_buff_cntr; i++ ){
629 if( cmd_buff[ 0 ][ i ] ==
' ' ){
632 cmd_buff[ 0 ][ i ] =
'\0';
643 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
646 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
658 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
660 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"%s", (
char*) &cmd_buff[ 0 ] );
664 channel -> print( (
char*) &cmd_buff[ 0 ] );
670 cmd_buff[ 0 ][ j ] =
' ';
672 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
675 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
676 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"%s", (
char*) &cmd_buff[ 0 ][ j ] );
681 channel -> print( (
char*) &cmd_buff[ 0 ][ j ] );
689 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
691 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\033[0K" );
695 channel -> write( 27 );
696 channel -> print(
"[0K" );
702 if( cmd_buff_cntr > cursor ){
705 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
707 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\033[%dD", uint8_t( cmd_buff_cntr - cursor ) );
711 channel -> write( 27 );
712 channel -> print(
'[' );
713 channel -> print( uint8_t( cmd_buff_cntr - cursor ) );
714 channel -> print(
'D' );
720 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
723 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
724 channel -> print( acceleratorBuffer );
734void Shellminator::process(
char new_char ) {
752 if( new_char ==
'\0' ){
756 if( new_char ==
'\n' ){
762 if ( ( new_char ==
'\b' ) || ( new_char == 127 ) ) {
776 if ( cursor == cmd_buff_cntr ) {
778 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
781 cmd_buff[ 0 ][ cursor + 1 ] =
'\0';
789 channel -> print(
"\b \b");
790 cmd_buff[ 0 ][ cursor + 1 ] =
'\0';
792 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
803 for( i = cursor; i < cmd_buff_cntr; i++ ) {
805 cmd_buff[ 0 ][ i ] = cmd_buff[ 0 ][ i + 1 ];
822 else if ( new_char ==
'\r' ) {
827 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
831 if( searchMatch > 0 ){
835 cmd_buff_cntr = strlen( cmd_buff[ 0 ] );
851 cmd_buff[ 0 ][ cmd_buff_cntr ] =
'\0';
854 channel -> print(
'\r' );
855 channel -> print(
'\n' );
857 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
864 if ( cmd_buff_cntr > 0 ) {
866 if( ( strcmp( cmd_buff[ 0 ],
"help" ) == 0 ) || ( strcmp( cmd_buff[ 0 ],
"?" ) == 0 ) ){
872 else if( strcmp( cmd_buff[ 0 ],
"history" ) == 0 ){
879 else if( execution_fn != NULL ){
882 execution_fn( cmd_buff[ 0 ] );
886 #ifdef COMMANDER_API_VERSION
890 else if( commander != NULL ){
892 commander -> execute( cmd_buff[ 0 ], channel );
900 channel -> print( (
const char*)
"cmd: " );
901 channel -> print( cmd_buff[ 0 ] );
907 channel -> print(
'\r' );
908 channel -> print(
'\n' );
938 else if ( new_char == 27 ) {
949 else if ( escape_state == 1 ) {
952 if ( new_char ==
'[' ) {
981 else if ( escape_state == 2 ) {
984 switch ( new_char ) {
993 if( upArrowOverrideFunc ){
995 upArrowOverrideFunc();
1004 if ( cmd_buff[ cmd_buff_dim ][0] ==
'\0' ) {
1019 cmd_buff_cntr = strlen( cmd_buff[ 0 ] );
1020 cursor = cmd_buff_cntr;
1043 if( downArrowOverrideFunc ){
1045 downArrowOverrideFunc();
1052 if ( cmd_buff_dim > 2 ) {
1066 cmd_buff_cntr = strlen( cmd_buff[ 0 ] );
1067 cursor = cmd_buff_cntr;
1076 else if ( cmd_buff_dim == 2 ) {
1100 if( rightArrowOverrideFunc ){
1102 rightArrowOverrideFunc();
1108 if( cursor < cmd_buff_cntr ){
1110 channel -> write( 27 );
1111 channel -> print(
'[' );
1112 channel -> print(
'1' );
1113 channel -> print(
'C' );
1131 if( leftArrowOverrideFunc ){
1133 leftArrowOverrideFunc();
1141 channel -> write( 27 );
1142 channel -> print(
'[' );
1143 channel -> print(
'1' );
1144 channel -> print(
'D' );
1183 cursor = cmd_buff_cntr;
1230 else if ( escape_state == 3 ) {
1232 if( new_char ==
'~' ){
1240 if ( cursor != cmd_buff_cntr ) {
1242 for( i = cursor; i < ( cmd_buff_cntr - 1 ); i++ ){
1244 cmd_buff[ 0 ][ i ] = cmd_buff[ 0 ][ i + 1 ];
1265 else if ( escape_state == 4 ) {
1269 if( new_char ==
'~' ) {
1279 cursor = cmd_buff_cntr;
1289 else if ( escape_state == 5 ) {
1293 if( new_char ==
'~' ){
1312 else if( escape_state == 6 ){
1316 if( new_char ==
'~' ){
1318 if( pageUpKeyFunc ){
1325 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1327 historySearchBackward();
1337 else if( escape_state == 7 ){
1341 if( new_char ==
'~' ){
1343 if( pageDownKeyFunc ){
1350 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1352 historySearchForward();
1362 else if( new_char == 0x01 ){
1368 else if( new_char == 0x05 ){
1369 cursor = cmd_buff_cntr;
1374 else if( new_char == 0x04 ){
1376 if( logoutKeyFunc ){
1383 #ifdef SHELLMINATOR_USE_WIFI_CLIENT
1389 #ifdef SHELLMINATOR_ENABLE_WEBSOCKET_MODULE
1391 websocketDisconnect();
1398 else if( new_char == 0x12 ){
1400 if( searchKeyFunc ){
1407 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1409 inSearch = !inSearch;
1418 else if( new_char == 0x0C ){
1426 else if( new_char ==
'\t' ){
1429 #ifdef COMMANDER_API_VERSION
1434 cursor = cmd_buff_cntr;
1437 Commander::API_t *commandAddress;
1447 bool conflict =
false;
1450 if( commander -> memoryType != Commander::MEMORY_REGULAR ){
1464 commandAddress = commander -> operator[]( (
int)i );
1470 while( commandAddress ){
1473 if( strncmp( (
const char*)cmd_buff[ 0 ], commandAddress -> name, cmd_buff_cntr ) == 0 ){
1476 if( ( nextChar ==
'\0' ) && ( cmd_buff_cntr < COMMANDER_MAX_COMMAND_SIZE ) && ( commandAddress -> name[ cmd_buff_cntr ] !=
'\0' ) ){
1479 nextChar = commandAddress -> name[ cmd_buff_cntr ];
1487 if( commandAddress -> name[ cmd_buff_cntr ] != nextChar ){
1502 commandAddress = commander -> operator[]( (
int)i );
1508 if( nextChar ==
'\0' ){
1519 process( nextChar );
1534 else if( new_char == 0x03 ){
1542 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1552 channel -> print(
'\r' );
1553 channel -> print(
'\n' );
1569 if( cursor == cmd_buff_cntr ){
1571 cmd_buff[ 0 ][ cmd_buff_cntr ] = new_char;
1580 for( i = cmd_buff_cntr; i > cursor; i-- ){
1582 cmd_buff[ 0 ][ i ] = cmd_buff[ 0 ][ i - 1 ];
1587 cmd_buff[ 0 ][ cursor ] = new_char;
1597 if ( cursor == cmd_buff_cntr ) {
1601 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1620 channel -> print(new_char);
1622 #ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
1636 if ( cursor != cmd_buff_cntr ) {
1669 upArrowOverrideFunc = func;
1675 downArrowOverrideFunc = func;
1681 leftArrowOverrideFunc = func;
1687 rightArrowOverrideFunc = func;
1693 abortKeyFunc = func;
1699 pageUpKeyFunc = func;
1705 pageDownKeyFunc = func;
1723 logoutKeyFunc = func;
1729 logoutKeyFunc = func;
1735 upArrowOverrideFunc = NULL;
1741 downArrowOverrideFunc = NULL;
1747 leftArrowOverrideFunc = NULL;
1753 rightArrowOverrideFunc = NULL;
1759 abortKeyFunc = NULL;
1765 pageUpKeyFunc = NULL;
1771 pageDownKeyFunc = NULL;
1789 logoutKeyFunc = NULL;
1795 searchKeyFunc = NULL;
1799#ifdef SHELLMINATOR_USE_WIFI_CLIENT
1803 if( clientConnected && client.connected() ){
1805 client.println(
"Logout!" );
1819 #ifdef SHELLMINATOR_USE_WIFI_CLIENT
1823 if( server -> hasClient() ){
1829 server -> available().stop();
1836 client = server -> available();
1837 client.setNoDelay(
false);
1838 client.setTimeout( 1000 );
1839 clientConnected =
true;
1841 client.write( TELNET_IAC_DONT_LINEMODE, 3 );
1842 client.write( TELNET_IAC_WILL_ECHO, 3 );
1843 client.write( TELNET_IAC_DONT_ECHO, 3 );
1844 client.write( TELNET_IAC_WILL_SUPRESS_GO_AHEAD, 3 );
1845 client.write( TELNET_IAC_DO_SUPRESS_GO_AHEAD, 3 );
1872 while( client.available() ){
1877 clientConnected =
false;
1885 if( client.available() ){
1888 switch( telnetNegotiationState ){
1897 if( client.peek() == 0xFF ){
1903 telnetNegotiationState = 1;
1907 channel = &defaultChannel;
1929 telnetNegotiationState = 2;
1933 channel = &defaultChannel;
1946 telnetNegotiationState = 0;
1951 channel = &defaultChannel;
1956 telnetNegotiationState = 0;
1970 channel = &defaultChannel;
1979 while ( channel -> available() ) {
1982 c = (char)channel -> read();
1987 #ifdef COMMANDER_API_VERSION
1988 commandCheckTimerStart = millis();
1989 commandChecked =
false;
1994 #ifdef COMMANDER_API_VERSION
1997 Commander::API_t *commandAddress;
2001 if( commander && !commandChecked ){
2002 bool previousCommandFound = commandFound;
2005 if( ( millis() - commandCheckTimerStart ) > 100 ){
2019 for( i = 0; i <= cmd_buff_cntr; i++ ){
2021 if( ( cmd_buff[ 0 ][ i ] ==
' ' ) || ( i == cmd_buff_cntr ) ){
2023 charCopy = cmd_buff[ 0 ][ i ];
2024 cmd_buff[ 0 ][ i ] =
'\0';
2032 commandAddress = commander -> operator[]( cmd_buff[0] );
2036 if( commandAddress ){
2037 commandFound =
true;
2039 commandFound =
false;
2043 cmd_buff[ 0 ][ i ] = charCopy;
2046 commandChecked =
true;
2050 if (previousCommandFound != commandFound) {
2071 channel -> write( 27 );
2072 channel -> print(
'[' );
2073 channel -> print( style );
2074 channel -> print(
';' );
2075 channel -> print( color );
2076 channel -> print(
'm' );
2094 sprintf( buff,
"\033[%d;%dm", style, color );
2101 stream_p -> write( 27 );
2102 stream_p -> print(
'[' );
2103 stream_p -> print( style );
2104 stream_p -> print(
';' );
2105 stream_p -> print( color );
2106 stream_p -> print(
'm' );
2118 channel -> print( logo );
2127 else if( progmemLogo ){
2133 channel -> print( progmemLogo );
2149 channel -> print(
'\a' );
2155#ifdef SHELLMINATOR_ENABLE_SEARCH_MODULE
2157void Shellminator::historySearchBackward(){
2162 uint32_t cmd_buff_dim_save;
2165 cmd_buff_dim_save = cmd_buff_dim;
2171 if( strncmp( cmd_buff[ 0 ], cmd_buff[ cmd_buff_dim_save ], cursor ) == 0 ){
2174 cmd_buff_dim = cmd_buff_dim_save;
2182 cmd_buff_cntr = strlen( cmd_buff[ 0 ] );
2197 cmd_buff_dim_save++;
2207void Shellminator::historySearchForward(){
2209 uint32_t cmd_buff_dim_save;
2211 cmd_buff_dim_save = cmd_buff_dim;
2213 while( cmd_buff_dim_save > 2 ){
2215 cmd_buff_dim_save--;
2217 if( strncmp( cmd_buff[ 0 ], cmd_buff[ cmd_buff_dim_save - 1 ], cursor ) == 0 ){
2219 cmd_buff_dim = cmd_buff_dim_save;
2223 cmd_buff_cntr = strlen( cmd_buff[ 0 ] );
2238void Shellminator::redrawHistorySearch(){
2242 bool highlighted =
false;
2243 int32_t searchResult;
2255 cmd_buff[ 0 ][ cmd_buff_cntr ] =
'\0';
2257 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2259 acceleratorBufferPtr = acceleratorBuffer;
2261 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\r\033[0;37m(reverse-i-search)'\033[1;33m%s\033[0;37m': \033[0K", cmd_buff[ 0 ] );
2265 channel -> print(
'\r' );
2267 channel -> print(
"(reverse-i-search)'" );
2269 channel -> print( cmd_buff[ 0 ] );
2271 channel -> print(
"': \033[0K" );
2275 if( cmd_buff_cntr == 0 ){
2277 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2279 channel -> print(acceleratorBuffer);
2289 searchResult = substring( cmd_buff[ 0 ], cmd_buff[ i ] );
2290 if( searchResult >= 0 ){
2303 for( j = 0; j < strlen( cmd_buff[ i ] ); j++ ){
2305 if( !highlighted && ( j == searchResult ) ){
2307 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2310 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
2322 if( highlighted && ( j == ( searchResult + strlen( cmd_buff[ 0 ] ) ) ) ){
2324 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2327 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
2335 highlighted =
false;
2339 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2341 *acceleratorBufferPtr = cmd_buff[ i ][ j ];
2342 acceleratorBufferPtr++;
2346 channel -> print( cmd_buff[ i ][ j ] );
2354 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2357 acceleratorBufferPtr = acceleratorBuffer + strlen( acceleratorBuffer );
2367 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2369 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\r\033[%dC", uint8_t( 19 + cursor ) );
2370 channel -> print( acceleratorBuffer );
2374 channel -> print(
'\r' );
2376 channel -> write( 27 );
2377 channel -> print(
'[' );
2378 channel -> print( uint8_t( 19 + cursor ) );
2379 channel -> print(
'C' );
2389 #ifdef SHELLMINATOR_ENABLE_HIGH_MEMORY_USAGE
2391 acceleratorBufferPtr += sprintf( acceleratorBufferPtr,
"\r\033[%dC", uint8_t( 19 + cursor ) );
2392 channel -> print( acceleratorBuffer );
2396 channel -> print(
'\r' );
2398 channel -> write( 27 );
2399 channel -> print(
'[' );
2400 channel -> print( uint8_t( 19 + cursor ) );
2401 channel -> print(
'C' );
2407int Shellminator::substring(
char* str1,
char* str2 ){
2414 int m = strlen( str1 );
2415 int n = strlen( str2 );
2417 for( i = 0; i <= ( n - m ); i++ ){
2419 for( j = 0; j < m; j++ ){
2421 if( str2[ i + j ] != str1[ j ] ){
2441#ifdef COMMANDER_API_VERSION
2443void Shellminator::attachCommander( Commander* commander_p ){
2445 commander = commander_p;
2451#ifdef SHELLMINATOR_ENABLE_PASSWORD_MODULE
2453void Shellminator::enablePasswordProtection( uint8_t* passwordHashAddress_p ){
2455 passwordHashAddress = passwordHashAddress_p;
2459void Shellminator::enablePasswordProtection(
const uint8_t* passwordHashAddress_p ){
2461 passwordHashAddress = (uint8_t*)passwordHashAddress_p;
2465void Shellminator::enablePasswordProtection(
char* passwordHashAddress_p ){
2467 passwordHashAddress = (uint8_t*)passwordHashAddress_p;
2471void Shellminator::enablePasswordProtection(
const char* passwordHashAddress_p ){
2473 passwordHashAddress = (uint8_t*)passwordHashAddress_p;
2477void Shellminator::disablePasswordProtection(){
2479 passwordHashAddress = NULL;
2483bool Shellminator::checkPassword( uint8_t* pwStr ){
2485 terminal_sha256_init( &passwordHashCtx );
2486 terminal_sha256_update( &passwordHashCtx, pwStr, strlen( (
const char*)pwStr ) );
2487 terminal_sha256_final( &passwordHashCtx, passwordHashBuffer );
2489 return memcmp( passwordHashAddress, passwordHashBuffer, SHA256_BLOCK_SIZE );
2493bool Shellminator::checkPassword(
const uint8_t* pwStr ){
2495 checkPassword( (uint8_t*)pwStr );
2499bool Shellminator::checkPassword(
char* pwStr ){
2501 checkPassword( (uint8_t*)pwStr );
2505bool Shellminator::checkPassword(
const char* pwStr ){
2507 checkPassword( (uint8_t*)pwStr );
2515#ifdef SHELLMINATOR_ENABLE_QR_SUPPORT
2569 for( y = 0; y < ( qr_size / 2 ); y++ ){
2572 channel -> print(
"\r\n" );
2575 for( x = 0; x < qr_size; x++ ){
2586 if( upper_pixel && lower_pixel ){
2588 channel -> print(
"\u2588" );
2594 if( upper_pixel && ( !lower_pixel ) ){
2596 channel -> print(
"\u2580" );
2602 if( ( !upper_pixel ) && lower_pixel ){
2604 channel -> print(
"\u2584" );
2611 channel -> print(
" " );
2619 if( ( qr_size % 2 ) != 0 ){
2622 channel -> print(
"\r\n" );
2625 for( x = 0; x < qr_size; x++ ){
2634 channel -> print(
"\u2580" );
2641 channel -> print(
" " );
2648 channel -> print(
"\r\n" );
#define SHELLMINATOR_BANNER_PATH_LEN
#define SHELLMINATOR_BUFF_LEN
#define SHELLMINATOR_BANNER_LEN
#define SHELLMINATOR_LOGO_COLOR
Style of the startup logo.
#define SHELLMINATOR_BUFF_DIM
#define SHELLMINATOR_LOGO_FONT_STYLE
Definition of the maximum length of each command.
const char Shellminator::helpText[] PROGMEM
#define SHELLMINATOR_VERSION
+---— Custom configuration ---—+ | | | This is where you have to config | | your defines!...
void begin(char *banner_p)
Shellminator initialization function.
void overrideHomeKey(void(*func)(void))
Override Home key behaviour.
void generateQRText(char *text)
This function generates a QR-code from text.
void overrideLogoutKey(void(*func)(void))
Override Logout key behaviour.
void clear()
Clear screen.
void freeLeftArrow()
Reset left arrow key functionality to default.
void overrideUpArrow(void(*func)(void))
Override up arrow key behaviour.
void update()
Update function.
void addExecFunc(void(*execution_fn_p)(char *))
Execution function adder function.
bool enableFormatting
This flag enables or disables character formatting.
void overrideRightArrow(void(*func)(void))
Override right arrow key behaviour.
void freeAbortKey()
Reset abort key functionality to default.
void freePageUpKey()
Reset Page-Up key functionality to default.
void clientDisconnect()
Disconnect WiFiClient telnet client.
void freeLogoutKey()
Reset Logout key functionality to default.
void freeEndKey()
Reset End key functionality to default.
void sendBackspace()
Sends a backspace.
void overrideEndKey(void(*func)(void))
Override End key behaviour.
void printBanner()
This function prints the banner text.
Shellminator(WiFiServer *server_p)
void freeUpArrow()
Reset up arrow key functionality to default.
void overrideDownArrow(void(*func)(void))
Override down arrow key behaviour.
void freeHomeKey()
Reset Home key functionality to default.
void beep()
Generate a beep sound on the terminal device.
void overridePageDownKey(void(*func)(void))
Override Page-Down key behaviour.
void setBannerPathText(char *bannerPath_p)
void overridePageUpKey(void(*func)(void))
Override Page-Up key behaviour.
void overrideSearchKey(void(*func)(void))
Override Search key behaviour.
void overrideAbortKey(void(*func)(void))
Override abort key behaviour.
void attachLogo(char *logo_p)
This function attaches a logo to the terminal.
void overrideLeftArrow(void(*func)(void))
Override left arrow key behaviour.
void setTerminalCharacterColor(uint8_t style, uint8_t color)
Bring some color into your code.
void freeRightArrow()
Reset right arrow key functionality to default.
void drawLogo()
Draws the startup logo.
void setBannerText(char *banner_p)
This function sets the banner text.
void setClientTimeout(uint16_t clientTimeout_p)
void freeSearchKey()
Reset Search key functionality to default.
void freeDownArrow()
Reset down arrow key functionality to default.
static const char * version
String that holds the version information.
void freePageDownKey()
Reset Page-Down key functionality to default.
bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y)
int qrcodegen_getSize(const uint8_t qrcode[])
#define qrcodegen_VERSION_MAX
#define qrcodegen_VERSION_MIN