Mask config.json passwords

This commit is contained in:
fvanroie 2021-05-01 01:39:43 +02:00
parent 44079e1468
commit 9db554e6d7

View File

@ -912,14 +912,31 @@ bool handleFileRead(String path)
configFile.reserve(32); configFile.reserve(32);
configFile = String(FPSTR(FP_HASP_CONFIG_FILE)); configFile = String(FPSTR(FP_HASP_CONFIG_FILE));
String contentType;
if(webServer.hasArg(F("download")))
contentType = F("application/octet-stream");
else
contentType = getContentType(path);
if(!strncasecmp(file.name(), configFile.c_str(), configFile.length())) { if(!strncasecmp(file.name(), configFile.c_str(), configFile.length())) {
file.close();
DynamicJsonDocument settings(8 * 256);
DeserializationError error = configParseFile(configFile, settings);
if(!error) {
LOG_TRACE(TAG_CONF, F(D_FILE_LOADING), configFile.c_str());
// Output settings in log with masked passwords
configMaskPasswords(settings);
char buffer[800];
size_t len = serializeJson(settings, buffer, sizeof(buffer));
LOG_VERBOSE(TAG_CONF, buffer);
webServer.setContentLength(len);
webServer.send(200, contentType, "");
webServer.sendContent(buffer, len);
} else {
}
} else { } else {
String contentType;
if(webServer.hasArg(F("download")))
contentType = F("application/octet-stream");
else
contentType = getContentType(path);
webServer.streamFile(file, contentType); webServer.streamFile(file, contentType);
file.close(); file.close();
@ -950,7 +967,7 @@ void handleFileUpload()
if(!httpIsAuthenticated(F("fileupload"))) return; if(!httpIsAuthenticated(F("fileupload"))) return;
LOG_INFO(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str()); LOG_INFO(TAG_HTTP, F("Total size: %s"), webServer.headerName(0).c_str());
String filename((char*)0); String filename((char*)0);
filename.reserve(128); filename.reserve(64);
filename = upload->filename; filename = upload->filename;
if(!filename.startsWith("/")) { if(!filename.startsWith("/")) {
filename = "/"; filename = "/";
@ -1943,7 +1960,6 @@ void httpHandleEspFirmware()
void webHandleSaveConfig() void webHandleSaveConfig()
{ {
if(!httpIsAuthenticated(F("saveConfig"))) return; if(!httpIsAuthenticated(F("saveConfig"))) return;
configWrite(); configWrite();
} }