mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
(config) automatic recovery when config is broken, closes https://github.com/opnsense/core/issues/701
This commit is contained in:
parent
a0fc098595
commit
6e8f51d434
@ -65,19 +65,6 @@ function alias_make_table($config)
|
||||
function parse_config()
|
||||
{
|
||||
$cnf = OPNsense\Core\Config::getInstance();
|
||||
if (!$cnf->isValid()) {
|
||||
// there was an issue with loading the config, try to restore the last backup
|
||||
$backups = $cnf->getBackups();
|
||||
if (count($backups) > 0) {
|
||||
// load last backup
|
||||
syslog(LOG_ERR, gettext('No valid config.xml found, attempting last known config restore.'));
|
||||
$cnf->restoreBackup($backups[0]);
|
||||
} else {
|
||||
// we don't have backups, try to load the default
|
||||
syslog(LOG_ERR, gettext('No valid config.xml found, attempting to restore factory config.'));
|
||||
$cnf->restoreBackup('/usr/local/etc/config.xml');
|
||||
}
|
||||
}
|
||||
|
||||
// return config data as array, use old "listags" construction to mark certain elements as array (even if they're not recurring)
|
||||
$config=$cnf->toArray(listtags());
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
namespace OPNsense\Core;
|
||||
|
||||
use \Phalcon\DI\FactoryDefault;
|
||||
use \Phalcon\Logger\Adapter\Syslog;
|
||||
|
||||
/**
|
||||
* Class Config provides access to systems config xml
|
||||
@ -255,7 +256,6 @@ class Config extends Singleton
|
||||
return $this->simplexml;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init new config object, try to load current configuration
|
||||
* (executed via Singleton)
|
||||
@ -267,8 +267,19 @@ class Config extends Singleton
|
||||
$this->load();
|
||||
} catch (\Exception $e) {
|
||||
$this->simplexml = null ;
|
||||
// there was an issue with loading the config, try to restore the last backup
|
||||
$backups = $this->getBackups();
|
||||
$logger = new Syslog("config", array('option' => LOG_PID, 'facility' => LOG_LOCAL4));
|
||||
if (count($backups) > 0) {
|
||||
// load last backup
|
||||
$logger->error(gettext('No valid config.xml found, attempting last known config restore.'));
|
||||
$this->restoreBackup($backups[0]);
|
||||
} else {
|
||||
// in case there are no backups, restore defaults.
|
||||
$logger->error(gettext('No valid config.xml found, attempting to restore factory config.'));
|
||||
$this->restoreBackup('/usr/local/etc/config.xml');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,6 +315,7 @@ class Config extends Singleton
|
||||
$this->simplexml = simplexml_load_string($xml);
|
||||
|
||||
if ($this->simplexml == null) {
|
||||
restore_error_handler();
|
||||
throw new ConfigException("invalid config xml") ;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user