From 570ed76bd2851e5de27fff664bb8002545f6ba0f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sun, 29 Nov 2020 00:36:30 +0100 Subject: [PATCH] Added "config_backup" and "config_restore" API calls, moved "save" API call to always be last executed (guaranteeing same-call edits are part of the saved version) --- src/controller/controller_api.cpp | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index c8508db9..48c97688 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -509,6 +509,33 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){ } } /*LTS-END*/ + + if (Request.isMember("config_backup")){ + std::set skip; + skip.insert("log"); + skip.insert("online"); + skip.insert("error"); + Response["config_backup"].assignFrom(Controller::Storage, skip); + } + + if (Request.isMember("config_restore")){ + std::set skip; + skip.insert("log"); + skip.insert("online"); + skip.insert("error"); + Controller::CheckStreams(Request["config_restore"]["streams"], Controller::Storage["streams"]); + Request["config_restore"]["streams"] = Controller::Storage["streams"]; + Controller::Storage.assignFrom(Request["config_restore"], skip); + removeDuplicateProtocols(); + Controller::accesslog = Controller::Storage["config"]["accesslog"].asStringRef(); + Controller::prometheus = Controller::Storage["config"]["prometheus"].asStringRef(); + if (Util::printDebugLevel != (Controller::Storage["config"]["debug"].isInt() ? Controller::Storage["config"]["debug"].asInt() : DEBUG)){ + Util::printDebugLevel = (Controller::Storage["config"]["debug"].isInt() ? Controller::Storage["config"]["debug"].asInt() : DEBUG); + INFO_MSG("Debug level set to %u", Util::printDebugLevel); + } + WARN_MSG("Restored configuration over API, replacing previous configuration entirely"); + } + // Parse config and streams from the request. if (Request.isMember("config") && Request["config"].isObject()){ const JSON::Value &in = Request["config"]; @@ -810,11 +837,6 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){ } } - if (Request.isMember("save")){ - Controller::Log("CONF", "Writing config to file on request through API"); - Controller::writeConfigToDisk(); - } - if (Request.isMember("ui_settings")){ if (Request["ui_settings"].isObject()){Storage["ui_settings"] = Request["ui_settings"];} Response["ui_settings"] = Storage["ui_settings"]; @@ -1049,4 +1071,10 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){ Controller::writeConfig(); Controller::configChanged = false; + + if (Request.isMember("save")){ + Controller::Log("CONF", "Writing config to file on request through API"); + Controller::writeConfigToDisk(); + } + }