intermediate: hide passwords in config, admin password
This commit is contained in:
parent
c38964e8b0
commit
df4b49ad5b
|
@ -138,7 +138,10 @@ def generateCfg(inFile,outFile,addDirs=[]):
|
||||||
if not first:
|
if not first:
|
||||||
data+=',\n'
|
data+=',\n'
|
||||||
first=False
|
first=False
|
||||||
data+=" new GwConfigItem(%s,\"%s\")"%(item.get('name'),item.get('default'))
|
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'
|
||||||
data+='};\n'
|
data+='};\n'
|
||||||
writeFileIfChanged(outFile,data)
|
writeFileIfChanged(outFile,data)
|
||||||
|
|
|
@ -35,7 +35,12 @@ String GwConfigHandler::toJson() const{
|
||||||
int num=getNumConfig();
|
int num=getNumConfig();
|
||||||
DynamicJsonDocument jdoc(JSON_OBJECT_SIZE(num*2));
|
DynamicJsonDocument jdoc(JSON_OBJECT_SIZE(num*2));
|
||||||
for (int i=0;i<num;i++){
|
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);
|
serializeJson(jdoc,rt);
|
||||||
logger->logString("configJson: %s",rt.c_str());
|
logger->logString("configJson: %s",rt.c_str());
|
||||||
|
@ -78,18 +83,17 @@ bool GwConfigHandler::saveConfig(){
|
||||||
logger->logString("saved config");
|
logger->logString("saved config");
|
||||||
return true;
|
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){
|
bool GwConfigHandler::updateValue(String name, String value){
|
||||||
GwConfigItem *i=findConfig(name);
|
GwConfigItem *i=findConfig(name);
|
||||||
if (i == NULL) return false;
|
if (i == NULL) return false;
|
||||||
logger->logString("update config %s=>%s",name.c_str(),value.c_str());
|
if (i->isSecret() && value.isEmpty()){
|
||||||
i->fromString(value);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
bool GwConfigHandler::reset(bool save){
|
bool GwConfigHandler::reset(bool save){
|
||||||
|
|
|
@ -16,7 +16,6 @@ class GwConfigHandler: public GwConfigDefinitions{
|
||||||
GwConfigHandler(GwLog *logger);
|
GwConfigHandler(GwLog *logger);
|
||||||
bool loadConfig();
|
bool loadConfig();
|
||||||
bool saveConfig();
|
bool saveConfig();
|
||||||
bool updateValue(const char *name, const char * value);
|
|
||||||
bool updateValue(String name, String value);
|
bool updateValue(String name, String value);
|
||||||
bool reset(bool save);
|
bool reset(bool save);
|
||||||
String toString() const;
|
String toString() const;
|
||||||
|
|
|
@ -8,17 +8,20 @@ class GwConfigInterface{
|
||||||
virtual const char * asCString() const =0;
|
virtual const char * asCString() const =0;
|
||||||
virtual bool asBoolean() const = 0;
|
virtual bool asBoolean() const = 0;
|
||||||
virtual int asInt() const = 0;
|
virtual int asInt() const = 0;
|
||||||
|
virtual bool isSecret() const =0;
|
||||||
};
|
};
|
||||||
class GwConfigItem: public GwConfigInterface{
|
class GwConfigItem: public GwConfigInterface{
|
||||||
private:
|
private:
|
||||||
String name;
|
String name;
|
||||||
String initialValue;
|
String initialValue;
|
||||||
String value;
|
String value;
|
||||||
|
bool secret=false;
|
||||||
public:
|
public:
|
||||||
GwConfigItem(const String &name, const String initialValue){
|
GwConfigItem(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;
|
||||||
|
this->secret=secret;
|
||||||
}
|
}
|
||||||
virtual String asString() const{
|
virtual String asString() const{
|
||||||
return value;
|
return value;
|
||||||
|
@ -41,6 +44,9 @@ class GwConfigItem: public GwConfigInterface{
|
||||||
virtual void reset(){
|
virtual void reset(){
|
||||||
value=initialValue;
|
value=initialValue;
|
||||||
}
|
}
|
||||||
|
virtual bool isSecret() const{
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
bool changed() const{
|
bool changed() const{
|
||||||
return value != initialValue;
|
return value != initialValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,9 @@ function checkApPass(v) {
|
||||||
return "password must be at least 8 characters";
|
return "password must be at least 8 characters";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function checkAdminPass(v){
|
||||||
|
return checkApPass(v);
|
||||||
|
}
|
||||||
|
|
||||||
function checkXDR(v,allValues){
|
function checkXDR(v,allValues){
|
||||||
if (! v) return;
|
if (! v) return;
|
||||||
|
@ -187,6 +190,10 @@ function changeConfig() {
|
||||||
let name = v.getAttribute('name');
|
let name = v.getAttribute('name');
|
||||||
if (!name) continue;
|
if (!name) continue;
|
||||||
if (name.indexOf("_") >= 0) continue;
|
if (name.indexOf("_") >= 0) continue;
|
||||||
|
let def=getConfigDefition(name);
|
||||||
|
if (def.type === 'password' && v.value == '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let check = v.getAttribute('data-check');
|
let check = v.getAttribute('data-check');
|
||||||
if (check) {
|
if (check) {
|
||||||
if (typeof (self[check]) === 'function') {
|
if (typeof (self[check]) === 'function') {
|
||||||
|
|
Loading…
Reference in New Issue