remove GwConfigItem and write operations, log passwords on USB
This commit is contained in:
parent
feb6b8860a
commit
b591c7ff12
|
@ -132,7 +132,7 @@ def generateCfg(inFile,outFile,addDirs=[]):
|
||||||
raise Exception("%s: config names must be max 15 caracters"%n)
|
raise Exception("%s: config names must be max 15 caracters"%n)
|
||||||
data+=' const String %s=F("%s");\n'%(n,n)
|
data+=' const String %s=F("%s");\n'%(n,n)
|
||||||
data+=' protected:\n'
|
data+=' protected:\n'
|
||||||
data+=' GwConfigItem *configs[%d]={\n'%(l)
|
data+=' GwConfigInterface *configs[%d]={\n'%(l)
|
||||||
first=True
|
first=True
|
||||||
for item in config:
|
for item in config:
|
||||||
if not first:
|
if not first:
|
||||||
|
@ -141,7 +141,7 @@ def generateCfg(inFile,outFile,addDirs=[]):
|
||||||
secret="false";
|
secret="false";
|
||||||
if item.get('type') == 'password':
|
if item.get('type') == 'password':
|
||||||
secret="true"
|
secret="true"
|
||||||
data+=" new GwConfigItem(%s,\"%s\",%s)"%(item.get('name'),item.get('default'),secret)
|
data+=" new GwConfigInterface(%s,\"%s\",%s)"%(item.get('name'),item.get('default'),secret)
|
||||||
data+='};\n'
|
data+='};\n'
|
||||||
data+='};\n'
|
data+='};\n'
|
||||||
writeFileIfChanged(outFile,data)
|
writeFileIfChanged(outFile,data)
|
||||||
|
|
|
@ -8,13 +8,9 @@ bool isTrue(const char * value){
|
||||||
return (strcasecmp(value,"true") == 0);
|
return (strcasecmp(value,"true") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DummyConfig : public GwConfigItem{
|
class DummyConfig : public GwConfigInterface{
|
||||||
public:
|
public:
|
||||||
DummyConfig():GwConfigItem("dummy",""){}
|
DummyConfig():GwConfigInterface("dummy",""){}
|
||||||
virtual void fromString(const String v){
|
|
||||||
};
|
|
||||||
virtual void reset(){
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DummyConfig dummyConfig;
|
DummyConfig dummyConfig;
|
||||||
|
@ -46,13 +42,7 @@ String GwConfigHandler::toJson() const{
|
||||||
logger->logString("configJson: %s",rt.c_str());
|
logger->logString("configJson: %s",rt.c_str());
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
GwConfigItem * GwConfigHandler::findConfig(const String name, bool dummy){
|
|
||||||
for (int i=0;i<getNumConfig();i++){
|
|
||||||
if (configs[i]->getName() == name) return configs[i];
|
|
||||||
}
|
|
||||||
if (!dummy) return NULL;
|
|
||||||
return &dummyConfig;
|
|
||||||
}
|
|
||||||
GwConfigInterface * GwConfigHandler::getConfigItem(const String name, bool dummy) const{
|
GwConfigInterface * GwConfigHandler::getConfigItem(const String name, bool dummy) const{
|
||||||
for (int i=0;i<getNumConfig();i++){
|
for (int i=0;i<getNumConfig();i++){
|
||||||
if (configs[i]->getName() == name) return configs[i];
|
if (configs[i]->getName() == name) return configs[i];
|
||||||
|
@ -68,7 +58,7 @@ bool GwConfigHandler::loadConfig(){
|
||||||
prefs.begin(PREF_NAME,true);
|
prefs.begin(PREF_NAME,true);
|
||||||
for (int i=0;i<getNumConfig();i++){
|
for (int i=0;i<getNumConfig();i++){
|
||||||
String v=prefs.getString(configs[i]->getName().c_str(),configs[i]->getDefault());
|
String v=prefs.getString(configs[i]->getName().c_str(),configs[i]->getDefault());
|
||||||
configs[i]->fromString(v);
|
configs[i]->value=v;
|
||||||
}
|
}
|
||||||
prefs.end();
|
prefs.end();
|
||||||
return true;
|
return true;
|
||||||
|
@ -76,8 +66,13 @@ bool GwConfigHandler::loadConfig(){
|
||||||
bool GwConfigHandler::saveConfig(){
|
bool GwConfigHandler::saveConfig(){
|
||||||
prefs.begin(PREF_NAME,false);
|
prefs.begin(PREF_NAME,false);
|
||||||
for (int i=0;i<getNumConfig();i++){
|
for (int i=0;i<getNumConfig();i++){
|
||||||
logger->logString("saving %s=%s",configs[i]->getName().c_str(),configs[i]->asCString());
|
String val=configs[i]->asString();
|
||||||
prefs.putString(configs[i]->getName().c_str(),configs[i]->asString());
|
auto it=changedValues.find(configs[i]->getName());
|
||||||
|
if (it != changedValues.end()){
|
||||||
|
val=it->second;
|
||||||
|
}
|
||||||
|
logger->logString("saving %s=%s",configs[i]->getName().c_str(),val.c_str());
|
||||||
|
prefs.putString(configs[i]->getName().c_str(),val);
|
||||||
}
|
}
|
||||||
prefs.end();
|
prefs.end();
|
||||||
logger->logString("saved config");
|
logger->logString("saved config");
|
||||||
|
@ -85,21 +80,21 @@ bool GwConfigHandler::saveConfig(){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GwConfigHandler::updateValue(String name, String value){
|
bool GwConfigHandler::updateValue(String name, String value){
|
||||||
GwConfigItem *i=findConfig(name);
|
GwConfigInterface *i=getConfigItem(name);
|
||||||
if (i == NULL) return false;
|
if (i == NULL) return false;
|
||||||
if (i->isSecret() && value.isEmpty()){
|
if (i->isSecret() && value.isEmpty()){
|
||||||
LOG_DEBUG(GwLog::LOG,"skip empty password %s",name.c_str());
|
LOG_DEBUG(GwLog::LOG,"skip empty password %s",name.c_str());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
LOG_DEBUG(GwLog::LOG,"update config %s=>%s",name.c_str(),i->isSecret()?"***":value.c_str());
|
LOG_DEBUG(GwLog::LOG,"update config %s=>%s",name.c_str(),i->isSecret()?"***":value.c_str());
|
||||||
i->fromString(value);
|
changedValues[name]=value;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool GwConfigHandler::reset(bool save){
|
bool GwConfigHandler::reset(bool save){
|
||||||
logger->logString("reset config");
|
logger->logString("reset config");
|
||||||
for (int i=0;i<getNumConfig();i++){
|
for (int i=0;i<getNumConfig();i++){
|
||||||
configs[i]->reset();
|
changedValues[configs[i]->getName()]=configs[i]->getDefault();
|
||||||
}
|
}
|
||||||
if (!save) return true;
|
if (!save) return true;
|
||||||
return saveConfig();
|
return saveConfig();
|
||||||
|
|
|
@ -5,12 +5,15 @@
|
||||||
#include "GwLog.h"
|
#include "GwLog.h"
|
||||||
#include "GwConfigItem.h"
|
#include "GwConfigItem.h"
|
||||||
#include "GwConfigDefinitions.h"
|
#include "GwConfigDefinitions.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
class GwConfigHandler: public GwConfigDefinitions{
|
class GwConfigHandler: public GwConfigDefinitions{
|
||||||
private:
|
private:
|
||||||
Preferences prefs;
|
Preferences prefs;
|
||||||
GwLog *logger;
|
GwLog *logger;
|
||||||
|
typedef std::map<String,String> StringMap;
|
||||||
|
StringMap changedValues;
|
||||||
public:
|
public:
|
||||||
public:
|
public:
|
||||||
GwConfigHandler(GwLog *logger);
|
GwConfigHandler(GwLog *logger);
|
||||||
|
@ -23,7 +26,6 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
String getString(const String name,const String defaultv="") const;
|
String getString(const String name,const String defaultv="") const;
|
||||||
bool getBool(const String name,bool defaultv=false) const ;
|
bool getBool(const String name,bool defaultv=false) const ;
|
||||||
int getInt(const String name,int defaultv=0) const;
|
int getInt(const String name,int defaultv=0) const;
|
||||||
GwConfigItem * findConfig(const String name, bool dummy=false);
|
|
||||||
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
|
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,22 +2,16 @@
|
||||||
#define _GWCONFIGITEM_H
|
#define _GWCONFIGITEM_H
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class GwConfigHandler;
|
||||||
class GwConfigInterface{
|
class GwConfigInterface{
|
||||||
public:
|
|
||||||
virtual String asString() const=0;
|
|
||||||
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:
|
private:
|
||||||
String name;
|
String name;
|
||||||
String initialValue;
|
String initialValue;
|
||||||
String value;
|
String value;
|
||||||
bool secret=false;
|
bool secret=false;
|
||||||
public:
|
public:
|
||||||
GwConfigItem(const String &name, const String initialValue, bool secret=false){
|
GwConfigInterface(const String &name, const String initialValue, bool secret=false){
|
||||||
this->name=name;
|
this->name=name;
|
||||||
this->initialValue=initialValue;
|
this->initialValue=initialValue;
|
||||||
this->value=initialValue;
|
this->value=initialValue;
|
||||||
|
@ -29,9 +23,6 @@ class GwConfigItem: public GwConfigInterface{
|
||||||
virtual const char * asCString() const{
|
virtual const char * asCString() const{
|
||||||
return value.c_str();
|
return value.c_str();
|
||||||
};
|
};
|
||||||
virtual void fromString(const String v){
|
|
||||||
value=v;
|
|
||||||
};
|
|
||||||
virtual bool asBoolean() const{
|
virtual bool asBoolean() const{
|
||||||
return strcasecmp(value.c_str(),"true") == 0;
|
return strcasecmp(value.c_str(),"true") == 0;
|
||||||
}
|
}
|
||||||
|
@ -41,9 +32,6 @@ class GwConfigItem: public GwConfigInterface{
|
||||||
String getName() const{
|
String getName() const{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
virtual void reset(){
|
|
||||||
value=initialValue;
|
|
||||||
}
|
|
||||||
virtual bool isSecret() const{
|
virtual bool isSecret() const{
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +41,7 @@ class GwConfigItem: public GwConfigInterface{
|
||||||
String getDefault() const {
|
String getDefault() const {
|
||||||
return initialValue;
|
return initialValue;
|
||||||
}
|
}
|
||||||
|
friend class GwConfigHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GwNmeaFilter{
|
class GwNmeaFilter{
|
||||||
|
|
|
@ -894,7 +894,8 @@ void setup() {
|
||||||
GWSYNCHRONIZED(&mainLock);
|
GWSYNCHRONIZED(&mainLock);
|
||||||
userCodeHandler.startUserTasks(MIN_USER_TASK);
|
userCodeHandler.startUserTasks(MIN_USER_TASK);
|
||||||
}
|
}
|
||||||
|
logger.logDebug(GwLog::ERROR,"wifi AP pass: %s",config.getString(config.apPassword).c_str());
|
||||||
|
logger.logDebug(GwLog::ERROR,"admin pass: %s",config.getString(config.adminPassword).c_str());
|
||||||
logger.logDebug(GwLog::LOG,"setup done");
|
logger.logDebug(GwLog::LOG,"setup done");
|
||||||
}
|
}
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue