Browse Source

[ssh]reboot controller after changing ssh configuration

balbekova 4 years ago
parent
commit
d98e8a27d6
3 changed files with 28 additions and 2 deletions
  1. 3 1
      modules/HTTP_Server/http_server.c
  2. 19 1
      modules/parameters.c
  3. 6 0
      modules/parameters.h

+ 3 - 1
modules/HTTP_Server/http_server.c

@@ -263,7 +263,9 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
     web_func_handler_t *h;
 
     hs = arg;
-
+    if (GetRebootStatus() == true) {;
+        Reboot(WEB_ACT);
+    }
     if (err == ERR_OK && p != NULL) {
         tcp_recved(pcb, p->tot_len);
 

+ 19 - 1
modules/parameters.c

@@ -48,6 +48,10 @@
 #ifdef NOTIFICATION_CONTROL_ENABLE
 extern const char* name_traps[];
 #endif
+
+
+static bool flag_reboot = false; // флаг перезагрузки контроллера (устанавливается при смене настроек ssh)
+
 /**
   * @brief  Структура для хранения состояний дискретных входов
   */
@@ -67,6 +71,16 @@ extern WEB_PARAMS_t sTempWebParams;
   * @brief  Флаг подтверждения новых сетевых параметров пользователем
   */
 extern bool fConfirmWebParams;
+
+/**
+  * @brief 
+  */
+bool GetRebootStatus(void)
+{
+  return flag_reboot;
+}
+
+
 #ifndef BT6702_SERVICE
 
 // ************************************************************************** //
@@ -2365,6 +2379,7 @@ void SetSSHPortStr(char *str)
     bool port_changed = new_port != sSettings.sSSH.port;
     sSettings.sSSH.port = new_port;
     if (port_changed) {
+        flag_reboot = true;
         ssh_server_restart();
     }
 }
@@ -2374,8 +2389,8 @@ void SetSSHPortStr(char *str)
   */
 void SetSSHEnableStateStr(char *str)
 {
+    bool old_state = sSettings.sSSH.SSHEnable;
     if (strncmp(str, "on", 2) == 0) {
-        bool old_state = sSettings.sSSH.SSHEnable;
         sSettings.sSSH.SSHEnable = 1;
         if (old_state != true && fl_reinit_ssh == true) {
             ssh_server_init();
@@ -2384,6 +2399,9 @@ void SetSSHEnableStateStr(char *str)
         sSettings.sSSH.SSHEnable = 0;
         ssh_server_restart();
     }
+    if(old_state != sSettings.sSSH.SSHEnable) {
+        flag_reboot = true;
+    }
 }
 #endif // SSH_ENABLE
 #endif // !BT6702_SERVICE

+ 6 - 0
modules/parameters.h

@@ -16,6 +16,12 @@
 
 #include <stdbool.h>
 #include "common_config.h"
+
+/**
+  * @brief 
+  */
+bool GetRebootStatus(void);
+
 // ************************************************************************** //
 //                        Параметры UPS