telnet_server.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * telnet_server.c
  3. *
  4. * Created on: 24.11.2017
  5. * Author: balbekova
  6. */
  7. /* Standard includes. */
  8. #include <string.h>
  9. /* lwIP core includes */
  10. #include "lwip/opt.h"
  11. #include "lwip/sockets.h"
  12. /* FreeRTOS includes. */
  13. #include "FreeRTOS.h"
  14. #include "task.h"
  15. #include "fr_timers.h"
  16. /* Utils includes. */
  17. #include "FreeRTOS_CLI.h"
  18. #include "CLI_Commands.h"
  19. #include "telnet_server.h"
  20. #include "settings_api.h"
  21. #include "parameters.h"
  22. #include "control_symbol.h"
  23. #include "log.h"
  24. #include "web_params_api.h"
  25. /* Dimensions the buffer into which input characters are placed. */
  26. #define cmdMAX_INPUT_SIZE 144
  27. /* Repeat Login timeout, 1 seconds */
  28. #define REPEAT_SENSOR_INFO_TIME configTICK_RATE_HZ*1*1
  29. static portBASE_TYPE FreeRTOS_CLIAuthProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer );
  30. static portBASE_TYPE FreeRTOS_ChangePWDProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer );
  31. void SensorInfoTimerCallback(TimerHandle_t pxTimer);
  32. TimerHandle_t RepeatSensorInfoTimer;
  33. state_telnet_server_t telnetState = TELNET_AUTH;
  34. uint8_t id_change_pwd = 0;
  35. user_level_t telnet_code_auth = USER;
  36. static int32_t lClientFd;
  37. static int32_t lSocket;
  38. static int8_t *pcOutputString;
  39. static bool flagTelnetChange = false;
  40. static struct fd_set master_set, read_set, write_set;
  41. static int max_sd;
  42. static struct sockaddr_in sa;
  43. #ifdef HARDWARE_BT6708
  44. extern bool white_list_check(uint32_t check_remote_addr);
  45. static bool flagWhiteListTelnet = false;
  46. #endif
  47. /**
  48. * @brief Общая структура настроек
  49. */
  50. extern SETTINGS_t sSettings;
  51. /*-----------------------------------------------------------*/
  52. /* Stop server */
  53. static void stop_server(void) {
  54. /* Clean up all of the sockets that are open */
  55. for (int i = 0; i <= max_sd; ++i)
  56. {
  57. if (FD_ISSET(i, &master_set)) {
  58. DBG printf("Close sock %d\n", i);
  59. closesocket(i);
  60. FD_CLR(i, &master_set);
  61. }
  62. }
  63. DBG printf("Portgw stopped\n");
  64. }
  65. /* Start server */
  66. static bool start_server(uint16_t port)
  67. {
  68. int res;
  69. lSocket = socket(PF_INET, SOCK_STREAM, 0);
  70. if (lSocket < 0) {
  71. DBG printf("Socket create failed\r\n");
  72. return false;
  73. }
  74. res = fcntl(lSocket, F_SETFL, O_NONBLOCK);
  75. if (res < 0) {
  76. DBG printf("fcntl() failed");
  77. closesocket(lSocket);
  78. return false;
  79. }
  80. memset(&sa, 0, sizeof(struct sockaddr_in));
  81. sa.sin_family = AF_INET;
  82. sa.sin_addr.s_addr = IPADDR_ANY;
  83. sa.sin_port = htons(port);
  84. if (bind(lSocket, (struct sockaddr *)&sa, sizeof(sa)) == -1)
  85. {
  86. DBG printf("Bind to port %d failed\n", port);
  87. closesocket(lSocket);
  88. return false;
  89. }
  90. res = listen(lSocket, 20);
  91. if (res < 0) {
  92. DBG printf("Listen failed failed\r\n");
  93. closesocket(lSocket);
  94. return false;
  95. }
  96. FD_ZERO(&master_set);
  97. max_sd = lSocket;
  98. FD_SET(lSocket, &master_set);
  99. DBG printf("Port %d opened\n", port);
  100. return true;
  101. }
  102. void vBasicSocketsCommandInterpreterTask( void *pvParameters )
  103. {
  104. int32_t lBytes, lAddrLen = sizeof( struct sockaddr_in );
  105. struct sockaddr_in sLocalAddr;
  106. struct sockaddr_in client_addr;
  107. const int8_t * const pcWelcomeMessage = ( const int8_t * ) "BT6706 command server - connection accepted.\r\nlogin:";
  108. static const int8_t * const pcEndOfCommandOutputString = ( int8_t * ) "\r\n[Нажмите клавишу ENTER для повторного выполнения предыдущей команды]\r\n>";
  109. int8_t cInChar, cInputIndex;
  110. static int8_t cInputString[ cmdMAX_INPUT_SIZE ] = { 0 }, cLastInputString[ cmdMAX_INPUT_SIZE ] = { 0 };
  111. portBASE_TYPE xReturned;
  112. int new_sd;
  113. int desc_ready, rc;
  114. struct timeval timeout;
  115. bool close_conn;
  116. uint16_t port;
  117. bool enabled;
  118. bool firstrun = true;
  119. #ifdef HARDWARE_BT6708
  120. struct sockaddr_in sa_temp;
  121. socklen_t len;
  122. #endif
  123. FD_ZERO(&master_set);
  124. timeout.tv_sec = 5;
  125. timeout.tv_usec = 0;
  126. ( void ) pvParameters;
  127. pcOutputString = FreeRTOS_CLIGetOutputBuffer();
  128. enabled = sSettings.sTelnet.TelnetEnable;
  129. port = ( uint16_t ) sSettings.sTelnet.port;
  130. while (1) {
  131. /* Check if network settings was changed */
  132. if ((sSettings.sTelnet.port != port) ||
  133. (sSettings.sTelnet.TelnetEnable != enabled) ||
  134. (firstrun))
  135. {
  136. if (!firstrun || sSettings.sTelnet.port != port) {
  137. /* Stop server */
  138. stop_server();
  139. }
  140. if (sSettings.sTelnet.TelnetEnable) {
  141. /* (Re)start server */
  142. if (!start_server(sSettings.sTelnet.port)) {
  143. DBG printf("Server start error\n");
  144. firstrun = true;
  145. vTaskDelay(5000);
  146. continue;
  147. }
  148. }
  149. else {
  150. /* Obtain the address of the output buffer. Note there is no mutual
  151. exclusion on this buffer as it is assumed only one command console
  152. interface will be used at any one time. */
  153. firstrun = true;
  154. vTaskDelay(5000);
  155. continue;
  156. }
  157. firstrun = false;
  158. port = sSettings.sTelnet.port;
  159. enabled = sSettings.sTelnet.TelnetEnable;
  160. }
  161. if (!enabled) {
  162. firstrun = true;
  163. vTaskDelay(5000);
  164. continue;
  165. }
  166. memcpy(&read_set, &master_set, sizeof(master_set));
  167. DBG printf("Waiting on select()...\n");
  168. rc = select(max_sd + 1, &read_set, NULL, NULL, &timeout);
  169. DBG printf(" select() returned %d\n", rc);
  170. if (rc < 0) {
  171. DBG printf(" select() failed\n");
  172. }
  173. if (rc == 0) {
  174. DBG printf(" select() timed out.\n");
  175. }
  176. /* One or more descriptors are readable. Need to \
  177. * determine which ones they are. */
  178. desc_ready = rc;
  179. for (int i=0; i <= max_sd && desc_ready > 0; ++i) {
  180. /*******************************************************/
  181. /* Check to see if this descriptor is ready */
  182. /*******************************************************/
  183. if (FD_ISSET(i, &read_set)) {
  184. /* A descriptor was found that was readable - one \
  185. * less has to be looked for. This is being done \
  186. * so that we can stop looking at the working set \
  187. * once we have found all of the descriptors that \
  188. * were ready. */
  189. desc_ready -= 1;
  190. /* Check to see if this is the listening socket */
  191. if (i == lSocket) {
  192. DBG printf(" Listening socket is readable\n");
  193. /* Accept all incoming connections that are */
  194. /* queued up on the listening socket before we */
  195. /* loop back and call select again. */
  196. do {
  197. /* Accept each incoming connection. If */
  198. /* accept fails with EWOULDBLOCK, then we */
  199. /* have accepted all of them. Any other */
  200. /* failure on accept will cause us to end the */
  201. /* server. */
  202. new_sd = accept(lSocket, NULL, NULL);
  203. if (new_sd < 0) {
  204. if (errno != EWOULDBLOCK) {
  205. DBG printf(" accept() failed\n");
  206. }
  207. break;
  208. }
  209. /* Add the new incoming connection to the */
  210. /* master read set */
  211. printf(" New incoming connection - %d\n", new_sd);
  212. FD_SET(new_sd, &master_set);
  213. if (new_sd > max_sd) {
  214. max_sd = new_sd;
  215. #ifdef HARDWARE_BT6708
  216. lwip_getpeername(new_sd, &sa_temp, &len);
  217. flagWhiteListTelnet = white_list_check(sa_temp.sin_addr.s_addr);
  218. #endif
  219. recv( new_sd, cInputString, 27, 0 );
  220. telnetState = TELNET_AUTH;
  221. send( new_sd, pcWelcomeMessage, strlen( ( const char * ) pcWelcomeMessage ), 0 );
  222. cInputIndex = 0;
  223. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  224. }
  225. /* Loop back up and accept another incoming */
  226. /* connection */
  227. } while (new_sd != -1);
  228. }
  229. /* This is not the listening socket, therefore an */
  230. /* existing connection must be readable */
  231. else {
  232. DBG printf(" Descriptor %d is readable\n", i);
  233. close_conn = false;
  234. /* Receive data on this connection until the */
  235. /* recv fails with EWOULDBLOCK. If any other */
  236. /* failure occurs, we will close the */
  237. /* connection. */
  238. if ((lBytes = recv(i, &cInChar, sizeof( cInChar ), 0 )) > 0) {
  239. if( lBytes > 0L )
  240. {
  241. if( cInChar == '\n' )
  242. {
  243. switch(telnetState){
  244. case TELNET_AUTH:
  245. if(FreeRTOS_CLIAuthProcess(cInputString, pcOutputString)){
  246. send( i, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
  247. cInputIndex = 0;
  248. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  249. }
  250. else{
  251. /* Set lBytes to 0 to close the connection. */
  252. lBytes = 0L;
  253. }
  254. break;
  255. case TELNET_CMD:
  256. /* The input string has been terminated. Was the
  257. input a quit command? */
  258. if( strcmp( "quit", ( const char * ) cInputString ) == 0 )
  259. {
  260. /* Set lBytes to 0 to close the connection. */
  261. lBytes = 0L;
  262. }
  263. else
  264. {
  265. /* The input string was not a quit command.
  266. Pass the string to the command interpreter. */
  267. /* See if the command is empty, indicating that the last command is
  268. to be executed again. */
  269. if( cInputIndex == 0 )
  270. {
  271. strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
  272. }
  273. /* Transmit a line separator, just to make the
  274. output easier to read. */
  275. lwip_send( lClientFd, "\r\n", strlen( "\r\n" ), 0 );
  276. do
  277. {
  278. /* Ensure there is not a string lingering in
  279. the output buffer. */
  280. pcOutputString[ 0 ] = 0x00;
  281. xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
  282. send( i, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
  283. } while( xReturned != pdFALSE );
  284. if( strcmp( "sensor info", ( const char * ) cInputString ) == 0 ){
  285. strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
  286. cInputIndex = 0;
  287. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  288. lClientFd = i;
  289. xTimerStart(RepeatSensorInfoTimer, 0);
  290. }
  291. else{
  292. /* All the strings generated by the input
  293. command have been sent. Clear the input
  294. string ready to receive the next command.
  295. Remember the command that was just processed
  296. first in case it is to be processed again. */
  297. strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
  298. cInputIndex = 0;
  299. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  300. if(telnetState != TELNET_CHANGE_PWD)
  301. send( i, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
  302. }
  303. }
  304. break;
  305. case TELNET_CHANGE_PWD:
  306. FreeRTOS_ChangePWDProcess(cInputString, pcOutputString);
  307. send( i, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
  308. cInputIndex = 0;
  309. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  310. break;
  311. }
  312. }
  313. else
  314. {
  315. if( cInChar == '\r' )
  316. {
  317. /* Ignore the character. */
  318. }
  319. else if( cInChar == '\b' )
  320. {
  321. /* Backspace was pressed. Erase the last
  322. character in the string - if any. */
  323. if( cInputIndex > 0 )
  324. {
  325. cInputIndex--;
  326. cInputString[ cInputIndex ] = '\0';
  327. }
  328. }
  329. else if( cInChar == '\t' ){
  330. /*FreeRTOS_CLICompleteCMDCommand(cInputString, pcOutputString);
  331. strcpy((char *)cInputString, (char *)pcOutputString);
  332. send( i, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );*/
  333. }
  334. else
  335. {
  336. /* A character was entered. Add it to the string
  337. entered so far. When a \n is entered the complete
  338. string will be passed to the command interpreter. */
  339. if( cInputIndex < cmdMAX_INPUT_SIZE )
  340. {
  341. cInputString[ cInputIndex ] = cInChar;
  342. cInputIndex++;
  343. }
  344. if( strcmp( "\377\364\377\375\006", ( const char * ) cInputString ) == 0 ){
  345. xTimerStop(RepeatSensorInfoTimer, 0);
  346. cInputIndex = 0;
  347. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  348. cInputString[0] = 255;
  349. cInputString[1] = 251;
  350. cInputString[2] = 6;
  351. cInputString[3] = 255;
  352. cInputString[4] = 242;
  353. //if(telnetState != TELNET_CHANGE_PWD)
  354. //lwip_send( lClientFd, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
  355. send( i, cInputString, strlen( ( const char * ) cInputString ), 0 );
  356. memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
  357. if(telnetState != TELNET_CHANGE_PWD)
  358. send( i, pcEndOfCommandOutputString, strlen( ( const char * ) pcEndOfCommandOutputString ), 0 );
  359. }
  360. }
  361. }
  362. }
  363. }
  364. if (lBytes < 0) {
  365. if (errno != EWOULDBLOCK){
  366. DBG printf(" recv() failed\n");
  367. close_conn = true;
  368. }
  369. }
  370. /* Check to see if the connection has been */
  371. /* closed by the client */
  372. if (lBytes == 0) {
  373. DBG printf(" Connection closed\n");
  374. close_conn = true;
  375. }
  376. /* If the close_conn flag was turned on, we need */
  377. /* to clean up this active connection. This */
  378. /* clean up process includes removing the */
  379. /* descriptor from the master set and */
  380. /* determining the new maximum descriptor value */
  381. /* based on the bits that are still turned on in */
  382. /* the master set. */
  383. if (close_conn) {
  384. closesocket(i);
  385. FD_CLR(i, &master_set);
  386. if (i == max_sd) {
  387. while (FD_ISSET(max_sd, &master_set) == false) {
  388. max_sd -= 1;
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. void telnet_server_init(void) {
  398. vRegisterCLICommands();
  399. xTaskCreate(vBasicSocketsCommandInterpreterTask, ( char * ) "vBasicSocketsCommandInterpreterTask", 8*configMINIMAL_STACK_SIZE , NULL, tskIDLE_PRIORITY + 1, NULL);
  400. RepeatSensorInfoTimer = xTimerCreate("SensorInfoTmr", REPEAT_SENSOR_INFO_TIME, pdFALSE, ( void * ) 0, SensorInfoTimerCallback);
  401. }
  402. void SensorInfoTimerCallback(TimerHandle_t pxTimer) {
  403. portBASE_TYPE xReturned = pdTRUE;
  404. do
  405. {
  406. /* Ensure there is not a string lingering in
  407. the output buffer. */
  408. pcOutputString[ 0 ] = 0x00;
  409. xReturned = FreeRTOS_CLIProcessCommand( "sensor info", pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
  410. lwip_send( lClientFd, pcOutputString, strlen( ( const char * ) pcOutputString ), 0 );
  411. } while( xReturned != pdFALSE );
  412. xTimerStart(RepeatSensorInfoTimer, 0);
  413. }
  414. static portBASE_TYPE FreeRTOS_CLIAuthProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer )
  415. {
  416. portBASE_TYPE xReturn = pdTRUE;
  417. uint32_t len;
  418. uint8_t valueLen, user_id;
  419. char WebPassword[MAX_WEB_PASSWD_LEN];
  420. char WebLogin[MAX_WEB_LOGIN_LEN];
  421. static uint8_t login_err = 0;
  422. static uint8_t telnet_state_auth = 0;
  423. static char login[ cmdMAX_INPUT_SIZE ] = { 0 };
  424. char password[ cmdMAX_INPUT_SIZE ] = { 0 };
  425. const int8_t * const pcPSWHeader = ( int8_t * ) "\r\npassword:";
  426. const int8_t * const pcLoginHeader = ( int8_t * ) "\r\nlogin:";
  427. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  428. if(telnet_state_auth == 0){
  429. telnet_state_auth = 1;
  430. memset(login, 0, cmdMAX_INPUT_SIZE);
  431. len = strlen((char *)pcCommandInput);
  432. strncpy(login, (char *)pcCommandInput, len);
  433. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcPSWHeader, strlen( ( char * ) pcPSWHeader ) );
  434. xReturn = pdTRUE;
  435. }
  436. else{
  437. memset(name_login_telnet, 0, 50);
  438. telnet_state_auth = 0;
  439. memset(password, 0, cmdMAX_INPUT_SIZE);
  440. len = strlen((char *)pcCommandInput);
  441. strncpy(password, (char *)pcCommandInput, len);
  442. #ifdef HARDWARE_BT6708
  443. if(!flagWhiteListTelnet){
  444. xReturn = pdFALSE;
  445. }
  446. else
  447. #endif
  448. {
  449. for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
  450. GetUserLogin(user_id, WebLogin, &valueLen);
  451. GetUserPassword(user_id, WebPassword, &valueLen);
  452. /* Check login and password */
  453. if ((strncmp(WebLogin, login, MAX_WEB_LOGIN_LEN) == 0) &&
  454. (strncmp(WebPassword, password, MAX_WEB_PASSWD_LEN) == 0)) {
  455. /* Login and pass are valid */
  456. telnet_code_auth = user_id;
  457. login_err = 0;
  458. strcpy( ( char * ) pcWriteBuffer, "\r\nАвторизация успешно пройдена\r\n>" );
  459. telnetState = TELNET_CMD;
  460. xReturn = pdTRUE;
  461. break;
  462. }
  463. else{
  464. xReturn = pdFALSE;
  465. }
  466. }
  467. }
  468. if(xReturn == pdFALSE){
  469. if(login_err < 4){
  470. login_err ++;
  471. #ifdef HARDWARE_BT6708
  472. if(!flagWhiteListTelnet)
  473. strcpy( ( char * ) pcWriteBuffer, "\r\nДоступ запрешен! Ваш IP-адрес находится вне диапазона доверительных хостов\r\n" );
  474. else
  475. #endif
  476. strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка авторизации\r\n" );
  477. strncat( ( char * ) pcWriteBuffer, ( const char * ) pcLoginHeader, strlen( ( char * ) pcLoginHeader ) );
  478. xReturn = pdTRUE;
  479. }
  480. else{
  481. login_err = 0;
  482. xReturn = pdFALSE;
  483. }
  484. }
  485. switch (user_id) {
  486. case 0:
  487. snprintf(name_login_telnet, sizeof(name_login_telnet), "Администратор");
  488. break;
  489. case 1:
  490. snprintf(name_login_telnet, sizeof(name_login_telnet), "Пользователь");
  491. break;
  492. default:
  493. break;
  494. }
  495. log_event_data(LOG_LOGIN_TELNET, name_login_telnet);
  496. }
  497. return xReturn;
  498. }
  499. static portBASE_TYPE FreeRTOS_ChangePWDProcess( const int8_t * const pcCommandInput, int8_t * pcWriteBuffer )
  500. {
  501. portBASE_TYPE xReturn = pdTRUE;
  502. uint32_t len;
  503. static uint8_t telnet_state_change_pwd = 0;
  504. static char password[ MAX_WEB_LOGIN_LEN ] = { 0 };
  505. char password2[ MAX_WEB_LOGIN_LEN ] = { 0 };
  506. const int8_t * const pcNewPSWHeader = ( int8_t * ) "\r\nВведите повторно новый пароль:";
  507. memset(pcWriteBuffer, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);
  508. if(telnet_state_change_pwd == 0){
  509. telnet_state_change_pwd = 1;
  510. memset(password, 0, MAX_WEB_LOGIN_LEN);
  511. len = strlen((char *)pcCommandInput);
  512. if(len >= MAX_WEB_LOGIN_LEN){
  513. strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
  514. telnetState = TELNET_CMD;
  515. }
  516. else{
  517. if(!control_string_en_digit((char *)pcCommandInput, len)){
  518. strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
  519. telnetState = TELNET_CMD;
  520. }
  521. else{
  522. strncpy(password, (char *)pcCommandInput, len);
  523. strncpy( ( char * ) pcWriteBuffer, ( const char * ) pcNewPSWHeader, strlen( ( char * ) pcNewPSWHeader ) );
  524. }
  525. }
  526. }
  527. else{
  528. telnet_state_change_pwd = 0;
  529. memset(password2, 0, cmdMAX_INPUT_SIZE);
  530. len = strlen((char *)pcCommandInput);
  531. if(len >= MAX_WEB_LOGIN_LEN){
  532. strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
  533. telnetState = TELNET_CMD;
  534. }
  535. else{
  536. strncpy(password2, (char *)pcCommandInput, len);
  537. if (strncmp(password, password2, MAX_WEB_PASSWD_LEN) == 0) {
  538. memcpy(sSettings.sAuth[id_change_pwd].password, password, 11);
  539. telnet_act = true;
  540. HTTP_SaveSettings();
  541. log_event_data(LOG_PSW_CHANGE, name_login_telnet);
  542. strcpy( ( char * ) pcWriteBuffer, "\r\nПароль успешно изменен\r\n>" );
  543. telnetState = TELNET_CMD;
  544. xReturn = pdTRUE;
  545. }
  546. else{
  547. strcpy( ( char * ) pcWriteBuffer, "\r\nОшибка при вводе нового пароля\r\n>" );
  548. telnetState = TELNET_CMD;
  549. }
  550. }
  551. }
  552. return xReturn;
  553. }