@@ -107,42 +60,6 @@ function parse_config($parse = false)
return$cnf->toArray();
}
functiongenerate_config_cache($config)
{
$configcache=fopen('/tmp/config.cache','w');
fwrite($configcache,serialize($config));
fclose($configcache);
unset($configcache);
}
functiondiscover_last_backup()
{
$backups=glob('/conf/backup/*.xml');
$last_backup='';
$last_mtime=0;
foreach($backupsas$backup){
if(filemtime($backup)>$last_mtime){
$last_mtime=filemtime($backup);
$last_backup=$backup;
}
}
returnbasename($last_backup);
}
functionrestore_backup($file)
{
global$g;
if(file_exists($file)){
@unlink('/tmp/config.cache');
copy($file,'/conf/config.xml');
disable_security_checks();
log_error(sprintf(gettext('%1$s is restoring the configuration %2$s'),$g['product_name'],$file));
file_notice("config.xml",sprintf(gettext('%1$s is restoring the configuration %2$s'),$g['product_name'],$file),"pfSenseConfigurator","");
}
}
/****f* config/parse_config_bootup
* NAME
...
...
@@ -156,7 +73,6 @@ function parse_config_bootup()
$config_xml='/conf/config.xml';
$lockkey=lock('config');
if(!file_exists($config_xml)){
if(file_exists("/var/run/booting")){
if(strstr($g['platform'],"cdrom")){
...
...
@@ -170,15 +86,14 @@ function parse_config_bootup()
"on reboot.\n");
}
}else{
$last_backup=discover_last_backup();
if($last_backup){
$cnf=OPNsense\Core\Config::getInstance();
$backups=$cnf->getBackups();
if(count($backups)>0){
log_error("No config.xml found, attempting last known config restore.");
file_notice("config.xml",gettext("No config.xml found, attempting last known config restore."),"pfSenseConfigurator","");
restore_backup("/conf/backup/{$last_backup}");
}
if(!file_exists($config_xml)){
$cnf->restoreBackup($backups[0]);
}else{
echosprintf(gettext("XML configuration file not found. %s cannot continue booting."),$g['product_name'])."\n";
unlock($lockkey);
mwexec("/sbin/halt");
exit;
}
...
...
@@ -186,24 +101,11 @@ function parse_config_bootup()
file_notice("config.xml",gettext("Last known config found and restored. Please double check your configuration file for accuracy."),"pfSenseConfigurator","");
}
}else{
unlock($lockkey);
log_error(gettext("Could not find a usable configuration file! Exiting...."));
exit(0);
}
}
if(filesize($config_xml)==0){
$last_backup=discover_last_backup();
if($last_backup){
log_error(gettext("No config.xml found, attempting last known config restore."));
file_notice("config.xml",gettext("No config.xml found, attempting last known config restore."),"pfSenseConfigurator","");
restore_backup("/conf/backup/{$last_backup}");
}else{
log_error(gettext('No config.xml found, attempting to restore factory config.'));
restore_backup('/usr/local/etc/config.xml');
}
}
unlock($lockkey);
$config=parse_config(true);
...
...
@@ -287,49 +189,6 @@ function convert_config() {
write_config(sprintf(gettext('Upgraded config version level from %1$s to %2$s'),$prev_version,$config['version']));
}
/****f* config/safe_write_file
* NAME
* safe_write_file - Write a file out atomically
* DESCRIPTION
* safe_write_file() Writes a file out atomically by first writing to a
* temporary file of the same name but ending with the pid of the current
* process, them renaming the temporary file over the original.
* INPUTS
* $filename - string containing the filename of the file to write
* $content - string containing the file content to write to file
* $force_binary - boolean denoting whether we should force binary