Przeglądaj źródła

Merge branch 'master' of https://192.168.14.200:3000/dtelenkov/bt-670x

TelenkovDmitry 7 lat temu
rodzic
commit
e8955f4390
2 zmienionych plików z 43 dodań i 34 usunięć
  1. 43 27
      modules/HTTP_Server/http_server.c
  2. 0 7
      modules/parameters.c

+ 43 - 27
modules/HTTP_Server/http_server.c

@@ -19,6 +19,7 @@
 #include "log.h"
 #include "hal.h"
 #include "radius_user.h"
+#include "sntp.h"
 
 #ifdef PRINTF_STDLIB
 #include <stdio.h>
@@ -792,16 +793,30 @@ void HTTP_SetSettings(char *buf, uint16_t lenBuf)
   SetROTypeActStr(value, 1);
   memset(value, 0, len);
 
-
+  GetParamValue(buf, "utc=", value, &valueLen);
+  SetSntpTimeZoneStr(value);
+  memset(value, 0, len);
+  
   // Параметры даты и времени
   GetParamValue(buf, "ntp=", value, &valueLen);
 
   if (strncmp(value, "1", 1) == 0)  // Если ntp on устанавливаем параметры
   {
+	bool old_sntp = false;
+	bool enable_old_sntp = sSettings.sSNTP.sntpEnable;
     memset(str, 0, len);
     GetParamValue(buf, "ntpservip=", str, &valueLen);
-    SetSntpServerIpStr(str);
+    if(strncmp(str, sSettings.sSNTP.ip, valueLen))
+    	old_sntp = true;
+    SetSntpServerIpStr(str);   
     SetSntpStateStr(value);
+    if(sSettings.sSNTP.sntpEnable != enable_old_sntp)
+    	old_sntp = true;
+	if(old_sntp){
+		SNTP_Init();
+		//vTaskDelay(7000);
+		SNTP_Poll();
+	}
     memset(value, 0, len);
     memset(str, 0, len);
   }
@@ -818,10 +833,6 @@ void HTTP_SetSettings(char *buf, uint16_t lenBuf)
       memset(value, 0, len);
       memset(str, 0, len);
   }
-
-  GetParamValue(buf, "utc=", value, &valueLen);
-  SetSntpTimeZoneStr(value);
-  memset(value, 0, len);
   
   /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
   if (GetStateWebReinit() == true)
@@ -1655,7 +1666,7 @@ static int my_set_session(ssl_context *ssl)
   return(0);
 }
 
-void ssl_server_read(void)
+int ssl_server_read(void)
 {
 	int ret;
 
@@ -1666,7 +1677,7 @@ void ssl_server_read(void)
 
         // Read decrypted application data
         ret = ssl_read(&ssl, (unsigned char*)receiveBuf, receivedBufLen);
-        printf("receive %s \r\n", receiveBuf);
+      //  printf("receive %s \r\n", receiveBuf);
 
         if(ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE)
             continue;
@@ -1684,14 +1695,15 @@ void ssl_server_read(void)
             break;
 
             default:
-                printf("\n\r ssl_read returned %d\n", ret);
+               // printf("\n\r ssl_read returned %d\n", ret);
             break;
             }
-            break;
+            return ret;
+            //break;
         }
         receivedBufLen = ret;
         // Display the length of read data
-        printf("\n\r Successfully read %d bytes from client \n\r",receivedBufLen);
+       // printf("\n\r Successfully read %d bytes from client \n\r",receivedBufLen);
     }while(0);
 }
 
@@ -1823,8 +1835,8 @@ void ssl_server(void *pvParameters)
 
         // 6. Read the HTTP Request 
         //printf("\n\r <= Read from client :");
-        ssl_server_read();
-
+        if(ssl_server_read() <= 0)
+        	goto accept;
     // -------------------------------------------------------------------------
         
         //receivedBufLen = p->tot_len;
@@ -1854,22 +1866,26 @@ void ssl_server(void *pvParameters)
         // Id of currently logged-in user 
         uint8_t user_id;
         
-        // Level of currently logged-in user 
-        seclevel = 0xFF;
-        for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
-            HTTP_GetUserCookie(user_id, CookieBuf, &idLen);
-            if (strncmp(id, CookieBuf, idLen) == 0 ) {
-                GetUserLevelInt(user_id, &seclevel);
-                Authenticated = true;
-                break;
-            }
-            Authenticated = false;
-            seclevel = 0xFF;
-        }
+       // if(sSettings.sRADIUS.Auth_enable == true){
+			// Level of currently logged-in user 
+			seclevel = 0xFF;
+			for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
+				HTTP_GetUserCookie(user_id, CookieBuf, &idLen);
+				if (strncmp(id, CookieBuf, idLen) == 0 ) {
+					GetUserLevelInt(user_id, &seclevel);
+					Authenticated = true;
+					break;
+				}
+				Authenticated = false;
+				seclevel = 0xFF;
+			}
+      //  }
 
         if ( Authenticated == false && sSettings.sRADIUS.Auth_enable == false)
-        {
-            HTTP_LOGIN(sendBuf, &sendBufLoadLen);
+        { 	
+        	//user_id = 0;
+          //  seclevel = 0;
+            HTTP_LOGIN(sendBuf, &sendBufLoadLen);          
             ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
         }
         else if ( Authenticated == false )//&& sSettings.sRADIUS.Auth_enable == true

+ 0 - 7
modules/parameters.c

@@ -986,18 +986,11 @@ void SetTimeStr(char *str)
   */
 void SetSntpStateStr(char *str)
 {
-	bool old_sntpEnable = sSettings.sSNTP.sntpEnable;
   if (strncmp(str, "1", 1) == 0){
 	sSettings.sSNTP.sntpEnable = true;
-	if(old_sntpEnable != sSettings.sSNTP.sntpEnable){
-		SNTP_Init();
-		//vTaskDelay(7000);
-		SNTP_Poll();
 	}
-  }
   else{
 	sSettings.sSNTP.sntpEnable = false;
-	SNTP_Enable(sSettings.sSNTP.sntpEnable);
   }
 }
 #endif