Commit 5eaf0e40 authored by Ad Schellevis's avatar Ad Schellevis

cleanup unnecessary config functions

parent 6f022153
#!/usr/local/bin/php
<?php
/*
Copyright (C) 2004 Scott Ullrich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("config.inc");
conf_mount_ro();
#!/usr/local/bin/php
<?php
/*
Copyright (C) 2004 Scott Ullrich
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("config.inc");
conf_mount_rw();
......@@ -230,9 +230,17 @@ class Config extends Singleton
throw new ConfigException('empty file') ;
}
set_error_handler(
function() {
throw new ConfigException("invalid config xml") ;
}
);
$this->configxml = new \DOMDocument('1.0');
$this->configxml->loadXML($xml);
$this->simplexml = simplexml_import_dom($this->configxml);
restore_error_handler();
$this->isValid = true;
}
......@@ -261,10 +269,63 @@ class Config extends Singleton
$target_dir = dirname($this->config_file)."/backup/";
$target_filename = "config-".time().".xml";
if (!file_exists($target_dir)) {
// create backup directory if it's missing
mkdir($target_dir);
}
copy($this->config_file, $target_dir.$target_filename);
}
/**
* return list of config backups
* @return array list of backups
*/
public function getBackups()
{
$target_dir = dirname($this->config_file)."/backup/";
if (file_exists($target_dir)) {
copy($this->config_file, $target_dir.$target_filename);
$backups = glob($target_dir."config*.xml");
rsort($backups);
return $backups;
}
return array();
}
/**
* restore and load backup config
* @param $filename
* @return bool restored, valid config loaded
* @throws ConfigException no config loaded
*/
public function restoreBackup($filename)
{
if ($this->isValid) {
// if current config is valid,
$configxml = $this->configxml;
$simplexml = $this->simplexml;
try {
// try to restore config
copy($filename, $this->config_file) ;
$this->load();
return true;
} catch (ConfigException $e) {
// copy / load failed, restore previous version
$this->configxml = $configxml;
$this->simplexml = $simplexml;
$this->isValid = true;
$this->save(null, true);
}
} else {
// we don't have a valid config loaded, just copy and load the requested one
copy($filename, $this->config_file) ;
$this->load();
return true;
}
return false;
}
/**
......
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