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

@ -137,8 +137,11 @@ def generateCfg(inFile,outFile,addDirs=[]):
for item in config:
if not first:
data+=',\n'
first=False
data+=" new GwConfigItem(%s,\"%s\")"%(item.get('name'),item.get('default'))
first=False
secret="false";
if item.get('type') == 'password':
secret="true"
data+=" new GwConfigItem(%s,\"%s\",%s)"%(item.get('name'),item.get('default'),secret)
data+='};\n'
data+='};\n'
writeFileIfChanged(outFile,data)

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;
}

View File

@ -148,6 +148,9 @@ function checkApPass(v) {
return "password must be at least 8 characters";
}
}
function checkAdminPass(v){
return checkApPass(v);
}
function checkXDR(v,allValues){
if (! v) return;
@ -187,6 +190,10 @@ function changeConfig() {
let name = v.getAttribute('name');
if (!name) continue;
if (name.indexOf("_") >= 0) continue;
let def=getConfigDefition(name);
if (def.type === 'password' && v.value == '') {
continue;
}
let check = v.getAttribute('data-check');
if (check) {
if (typeof (self[check]) === 'function') {