Commit 96820738 authored by Franco Fichtner's avatar Franco Fichtner

backup: switch to new config load facility for section restore #471

Now always restore from a full backup only, the standard has already
been switched in the scope of this ticket a while back.  The section
restore could be improved, but it's not really worth doing this in
the old code anymore.  Hopefully the last change of its kind here.
parent ab5cb92d
......@@ -128,13 +128,6 @@ function cData($parser, $data)
}
}
function parse_xml_config($cffile, $rootobj, $isstring = "false")
{
global $listtags;
$listtags = listtags();
return parse_xml_config_raw($cffile, $rootobj, $isstring);
}
function parse_xml_config_raw($cffile, $rootobj, $isstring = "false")
{
global $depth, $curpath, $parsedcfg, $havedata, $listtags;
......
......@@ -44,42 +44,24 @@ require_once("system.inc");
function restore_config_section($section_name, $new_contents)
{
global $config;
$tmpxml = '/tmp/tmpxml';
$fout = fopen($tmpxml, 'w');
fwrite($fout, $new_contents);
fclose($fout);
file_put_contents($tmpxml, $new_contents);
$xml = load_config_from_file($tmpxml);
@unlink($tmpxml);
$xml = parse_xml_config($tmpxml, null);
if ($xml === -1) {
if (!is_array($xml) || !isset($xml[0])) {
return false;
}
$section_xml = -1;
/*
* So, we're looking for a non-root tag written as a
* root tag, or a proper config where we cherry-pick
* a specific matching section... ok...
*/
foreach ($xml as $xml_strip_root) {
if (isset($xml_strip_root[$section])) {
$section_xml = $xml_strip_root[$section];
break;
}
}
if ($section_xml = -1 && isset($xml[$section_name])) {
$section_xml = $xml[$section_name];
}
@unlink($tmpxml);
$xml = $xml[0];
if ($section_xml === -1) {
if (!isset($xml[$section_name])) {
return false;
}
$config[$section_name] = &$section_xml;
$config[$section_name] = $xml[$section_name];
write_config(sprintf(gettext("Restored %s of config file"), $section_name));
disable_security_checks();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment