Browse Source

Basic check of the uploaded config file

fastled
Xose Pérez 7 years ago
parent
commit
34116ac16d
2 changed files with 10 additions and 1 deletions
  1. +9
    -1
      code/espurna/web.ino
  2. +1
    -0
      code/html/custom.js

+ 9
- 1
code/espurna/web.ino View File

@ -91,11 +91,16 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (action.equals("reset")) ESP.reset(); if (action.equals("reset")) ESP.reset();
if (action.equals("restore") && root.containsKey("data")) { if (action.equals("restore") && root.containsKey("data")) {
JsonObject& data = root["data"];
if (!data.containsKey("app") || (data["app"] != APP_NAME)) {
ws.text(client_id, "{\"message\": \"The file does not look like a valid configuration backup.\"}");
return;
}
for (unsigned int i = EEPROM_DATA_END; i < SPI_FLASH_SEC_SIZE; i++) { for (unsigned int i = EEPROM_DATA_END; i < SPI_FLASH_SEC_SIZE; i++) {
EEPROM.write(i, 0xFF); EEPROM.write(i, 0xFF);
} }
JsonObject& data = root["data"];
for (auto element : data){ for (auto element : data){
setSetting(element.key, element.value.as<char*>()); setSetting(element.key, element.value.as<char*>());
} }
@ -731,6 +736,9 @@ void _onGetConfig(AsyncWebServerRequest *request) {
AsyncJsonResponse * response = new AsyncJsonResponse(); AsyncJsonResponse * response = new AsyncJsonResponse();
JsonObject& root = response->getRoot(); JsonObject& root = response->getRoot();
root["app"] = APP_NAME;
root["version"] = APP_VERSION;
unsigned int size = settingsKeyCount(); unsigned int size = settingsKeyCount();
for (unsigned int i=0; i<size; i++) { for (unsigned int i=0; i<size; i++) {
String key = settingsKeyName(i); String key = settingsKeyName(i);


+ 1
- 0
code/html/custom.js View File

@ -83,6 +83,7 @@ function onFileUpload(event) {
var inputFiles = this.files; var inputFiles = this.files;
if (inputFiles == undefined || inputFiles.length == 0) return false; if (inputFiles == undefined || inputFiles.length == 0) return false;
var inputFile = inputFiles[0]; var inputFile = inputFiles[0];
this.value = "";
var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?"); var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?");
if (response == false) return false; if (response == false) return false;


Loading…
Cancel
Save