Browse Source

Rolling 20220928

jomjol 3 năm trước cách đây
mục cha
commit
88a074dfa9

+ 1 - 0
Changelog.md

@@ -34,6 +34,7 @@ If anything bricks you can try to
 - Update used libraries (`tflite`, `esp32-cam`, `esp-nn`, as of 20220924) 
 ### Fixed
 
+- [\#1092](https://github.com/jomjol/AI-on-the-edge-device/issues/1092) censor passwords in log outputs 
 - [\#1029](https://github.com/jomjol/AI-on-the-edge-device/issues/1029) wrong change of `checkDigitConsistency` now working like releases before `11.3.1` 
 - Spelling corrections (**[cristianmitran](https://github.com/cristianmitran)**) 
 

+ 11 - 21
code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp

@@ -10,6 +10,8 @@
 
 #include <time.h>
 
+#define __HIDE_PASSWORD
+
 void ClassFlowMQTT::SetInitialParameter(void)
 {
     uri = "";
@@ -117,12 +119,21 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
         }
     }
 
+#ifdef __HIDE_PASSWORD
+    printf("Init Read with uri: %s, clientname: %s, user: %s, password: XXXXXX, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str());
+#else
     printf("Init Read with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str());
+#endif
+
     if (!MQTTisConnected() && (uri.length() > 0) && (maintopic.length() > 0)) 
     { 
         printf("InitMQTTInit\n");
         mainerrortopic = maintopic + "/connection";
+#ifdef __HIDE_PASSWORD
+        printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: XXXXXXXX, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str());
+#else
         printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str());
+#endif
         if (!MQTTInit(uri, clientname, user, password, mainerrortopic, keepAlive))
         { // Failed
             MQTTenable = false;
@@ -179,27 +190,6 @@ string ClassFlowMQTT::GetMQTTMainTopic()
 
 bool ClassFlowMQTT::doFlow(string zwtime)
 {
-  //  if (!MQTTenable) {
-  //      LogFile.WriteToFile("MQTT not enabled!");
-  //
-  //      // Try again to init it
-  //   if (!MQTTInit(this->uri, this->clientname, this->user, this->password, this->mainerrortopic, keepAlive))
-  //      { // Failed
-  //          MQTTenable = false;
-  //          return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
-  //      } 
-  //
-  //     if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
-  //      { // Failed
-  //          MQTTenable = false;
-  //          return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
-  //      }
-  //      
-  //      LogFile.WriteToFile("MQTT is now enabled");
-  //      MQTTenable = true;
-  //  }
-
-
     // Try sending mainerrortopic. If it fails, re-run init
     if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
     { // Failed

+ 7 - 24
code/components/jomjol_mqtt/interface_mqtt.cpp

@@ -5,6 +5,8 @@
 #include "mqtt_client.h"
 #include "ClassLogFile.h"
 
+#define __HIDE_PASSWORD
+
 static const char *TAG_INTERFACEMQTT = "interface_mqtt";
 
 std::map<std::string, std::function<void()>>* connectFunktionMap = NULL;  
@@ -21,30 +23,6 @@ esp_mqtt_client_handle_t client = NULL;
 
 bool MQTTPublish(std::string _key, std::string _content, int retained_flag){
   
-  //  if (!client) {
-  //      LogFile.WriteToFile("MQTT - client not initialized!");  
-  //      return false;      
-  //  }
-  //  LogFile.WriteToFile("MQTT - client initialized!");  // Debug
-  //
-  //  if (!mqtt_connected) {
-  //      LogFile.WriteToFile("MQTT - Can not publish, not connected!");
-  //      ESP_LOGW(TAG_INTERFACEMQTT, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
-  //      return false;            
-  //  }
-  //  LogFile.WriteToFile("MQTT - connected!");  // Debug
-
- /*   if (client && mqtt_connected) {
-        LogFile.WriteToFile("MQTT - connected!");  // Debug
-    }
-    else { // init needed
-        if (!MQTTInit(this->uri, this->clientname, this->user, password, mainerrortopic, keepAlive)) // validate{
-        { // Failed
-            return false;
-        }
-    }*/
-
-
     int msg_id;
     std::string zw;
     msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
@@ -147,7 +125,12 @@ bool MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
     if (_user.length() && _password.length()){
         mqtt_cfg.username = _user.c_str();
         mqtt_cfg.password = _password.c_str();
+
+#ifdef __HIDE_PASSWORD
+        ESP_LOGI(TAG_INTERFACEMQTT, "Connect to MQTT: %s, XXXXXXXX", mqtt_cfg.username);
+#else
         ESP_LOGI(TAG_INTERFACEMQTT, "Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
+#endif        
     };
 
     MQTTdestroy();

+ 0 - 2
code/components/jomjol_mqtt/interface_mqtt.h

@@ -8,8 +8,6 @@
 bool MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _LWTContext, int _keepalive);
 void MQTTdestroy();
 
-//void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = "");
-
 bool MQTTPublish(std::string _key, std::string _content, int retained_flag = 1);            // retained Flag as Standart
 
 bool MQTTisConnected();

+ 12 - 4
code/components/jomjol_wlan/connect_wlan.cpp

@@ -20,6 +20,8 @@
 #include <sstream>
 #include <iostream>
 
+#define __HIDE_PASSWORD
+
 
 
 #define EXAMPLE_ESP_MAXIMUM_RETRY  1000
@@ -247,11 +249,17 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna
     /* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
      * happened. */
     if (bits & WIFI_CONNECTED_BIT) {
-        ESP_LOGI(TAG, "connected to ap SSID: %s, password:%s",
-                 _ssid, _password);
+#ifdef __HIDE_PASSWORD
+        ESP_LOGI(TAG, "connected to ap SSID: %s, password: XXXXXXX", _ssid);
+#else
+        ESP_LOGI(TAG, "connected to ap SSID: %s, password: %s", _ssid, _password);
+#endif        
     } else if (bits & WIFI_FAIL_BIT) {
-        ESP_LOGI(TAG, "Failed to connect to SSID: %s, password:%s",
-                 _ssid, _password);
+#ifdef __HIDE_PASSWORD
+        ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: XXXXXXXX", _ssid);
+#else
+        ESP_LOGI(TAG, "Failed to connect to SSID: %s, password: %s", _ssid, _password);
+#endif        
     } else {
         ESP_LOGE(TAG, "UNEXPECTED EVENT");
     }

+ 8 - 0
code/main/main.cpp

@@ -34,6 +34,9 @@ extern const char* GIT_REV;
 extern const char* GIT_BRANCH;
 extern const char* BUILD_TIME;
 
+
+#define __HIDE_PASSWORD
+
 // #include "jomjol_WS2812Slow.h"
 #include "SmartLeds.h"
 
@@ -165,7 +168,12 @@ extern "C" void app_main(void)
     LoadWlanFromFile("/sdcard/wlan.ini", ssid, passwd, hostname, ip, gateway, netmask, dns);
 
     if (ssid != NULL && passwd != NULL)
+#ifdef __HIDE_PASSWORD
+        printf("\nWLan: %s, XXXXXX\n", ssid);
+#else
         printf("\nWLan: %s, %s\n", ssid, passwd);
+#endif        
+
     else
         printf("No SSID and PASSWORD set!!!");