1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

intermediate: hide passwords in config, admin password

This commit is contained in:
wellenvogel
2021-12-13 16:44:02 +01:00
parent c38964e8b0
commit df4b49ad5b
5 changed files with 33 additions and 14 deletions

View File

@@ -35,7 +35,12 @@ String GwConfigHandler::toJson() const{
int num=getNumConfig();
DynamicJsonDocument jdoc(JSON_OBJECT_SIZE(num*2));
for (int i=0;i<num;i++){
jdoc[configs[i]->getName()]=configs[i]->asCString();
if (configs[i]->isSecret()){
jdoc[configs[i]->getName()]="";
}
else{
jdoc[configs[i]->getName()]=configs[i]->asCString();
}
}
serializeJson(jdoc,rt);
logger->logString("configJson: %s",rt.c_str());
@@ -78,18 +83,17 @@ bool GwConfigHandler::saveConfig(){
logger->logString("saved config");
return true;
}
bool GwConfigHandler::updateValue(const char *name, const char * value){
GwConfigItem *i=findConfig(name);
if (i == NULL) return false;
logger->logString("update config %s=>%s",name,value);
i->fromString(value);
return true;
}
bool GwConfigHandler::updateValue(String name, String value){
GwConfigItem *i=findConfig(name);
if (i == NULL) return false;
logger->logString("update config %s=>%s",name.c_str(),value.c_str());
i->fromString(value);
if (i->isSecret() && value.isEmpty()){
LOG_DEBUG(GwLog::LOG,"skip empty password %s",name.c_str());
}
else{
LOG_DEBUG(GwLog::LOG,"update config %s=>%s",name.c_str(),i->isSecret()?"***":value.c_str());
i->fromString(value);
}
return true;
}
bool GwConfigHandler::reset(bool save){

View File

@@ -16,7 +16,6 @@ class GwConfigHandler: public GwConfigDefinitions{
GwConfigHandler(GwLog *logger);
bool loadConfig();
bool saveConfig();
bool updateValue(const char *name, const char * value);
bool updateValue(String name, String value);
bool reset(bool save);
String toString() const;

View File

@@ -8,17 +8,20 @@ class GwConfigInterface{
virtual const char * asCString() const =0;
virtual bool asBoolean() const = 0;
virtual int asInt() const = 0;
virtual bool isSecret() const =0;
};
class GwConfigItem: public GwConfigInterface{
private:
String name;
String initialValue;
String value;
bool secret=false;
public:
GwConfigItem(const String &name, const String initialValue){
GwConfigItem(const String &name, const String initialValue, bool secret=false){
this->name=name;
this->initialValue=initialValue;
this->value=initialValue;
this->secret=secret;
}
virtual String asString() const{
return value;
@@ -41,6 +44,9 @@ class GwConfigItem: public GwConfigInterface{
virtual void reset(){
value=initialValue;
}
virtual bool isSecret() const{
return secret;
}
bool changed() const{
return value != initialValue;
}