summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2010-12-30 19:44:37 +0000
committerErmal <eri@pfsense.org>2010-12-30 19:45:28 +0000
commit02e9880edd5db8168f0df90339c67af62d278dfe (patch)
treeb0ee49dcb488b1636e1221de8dca8f972aaa7520 /etc
parentf9626e574bc2d69beb866e478c2b1d37e9e24660 (diff)
downloadpfsense-02e9880edd5db8168f0df90339c67af62d278dfe.zip
pfsense-02e9880edd5db8168f0df90339c67af62d278dfe.tar.gz
Improve parse_config to not be recursive for no reason. This fixes some strange cases of config lock being left held and blocking GUI.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/config.lib.inc106
1 files changed, 52 insertions, 54 deletions
diff --git a/etc/inc/config.lib.inc b/etc/inc/config.lib.inc
index dbd8650..5424d96 100644
--- a/etc/inc/config.lib.inc
+++ b/etc/inc/config.lib.inc
@@ -53,30 +53,33 @@
******/
function encrypted_configxml() {
global $g, $config;
- if(file_exists($g['conf_path'] . "/config.xml")) {
- if($g['booting']) {
- $configtxt = file_get_contents($g['conf_path'] . "/config.xml");
- if(tagfile_deformat($configtxt, $configtxt, "config.xml")) {
- $fp = fopen('php://stdin', 'r');
+
+ if (!file_exists($g['conf_path'] . "/config.xml"))
+ return;
+
+ if (!$g['booting'])
+ return;
+
+ $configtxt = file_get_contents($g['conf_path'] . "/config.xml");
+ if(tagfile_deformat($configtxt, $configtxt, "config.xml")) {
+ $fp = fopen('php://stdin', 'r');
+ $data = "";
+ echo "\n\n*** Encrypted config.xml detected ***\n";
+ while($data == "") {
+ echo "\nEnter the password to decrypt config.xml: ";
+ $decrypt_password = chop(fgets($fp));
+ $data = decrypt_data($configtxt, $decrypt_password);
+ if(!strstr($data, "<pfsense>"))
$data = "";
- echo "\n\n*** Encrypted config.xml detected ***\n";
- while($data == "") {
- echo "\nEnter the password to decrypt config.xml: ";
- $decrypt_password = chop(fgets($fp));
- $data = decrypt_data($configtxt, $decrypt_password);
- if(!strstr($data, "<pfsense>"))
- $data = "";
- if($data) {
- $fd = fopen($g['conf_path'] . "/config.xml.tmp", "w");
- fwrite($fd, $data);
- fclose($fd);
- exec("/bin/mv {$g['conf_path']}/config.xml.tmp {$g['conf_path']}/config.xml");
- echo "\nConfig.xml unlocked.\n";
- fclose($fp);
- } else {
- echo "\nInvalid password entered. Please try again.\n";
- }
- }
+ if($data) {
+ $fd = fopen($g['conf_path'] . "/config.xml.tmp", "w");
+ fwrite($fd, $data);
+ fclose($fd);
+ exec("/bin/mv {$g['conf_path']}/config.xml.tmp {$g['conf_path']}/config.xml");
+ echo "\nConfig.xml unlocked.\n";
+ fclose($fp);
+ } else {
+ echo "\nInvalid password entered. Please try again.\n";
}
}
}
@@ -92,9 +95,10 @@ function encrypted_configxml() {
******/
function parse_config($parse = false) {
global $g, $config_parsed, $config_extra;
-
+
$lockkey = lock('config');
$config_parsed = false;
+
if (!file_exists("{$g['conf_path']}/config.xml") || filesize("{$g['conf_path']}/config.xml") == 0) {
$last_backup = discover_last_backup();
if($last_backup) {
@@ -106,37 +110,25 @@ function parse_config($parse = false) {
die("Config.xml is corrupted and is 0 bytes. Could not restore a previous backup.");
}
}
- if($g['booting']) echo ".";
+
+ if($g['booting'])
+ echo ".";
+
// Check for encrypted config.xml
encrypted_configxml();
+
if(!$parse) {
- if(file_exists($g['tmp_path'] . '/config.cache')) {
+ if (file_exists($g['tmp_path'] . '/config.cache')) {
$config = unserialize(file_get_contents($g['tmp_path'] . '/config.cache'));
- if(is_null($config)) {
- unlock($lockkey);
- parse_config(true);
- $lockkey = lock('config');
- }
- } else {
- if(!file_exists($g['conf_path'] . "/config.xml")) {
- log_error("No config.xml found, attempting last known config restore.");
- file_notice("config.xml", "No config.xml found, attempting last known config restore.", "pfSenseConfigurator", "");
- $last_backup = discover_last_backup();
- if ($last_backup)
- restore_backup("/cf/conf/backup/{$last_backup}");
- else {
- log_error("Could not restore config.xml.");
- unlock($lockkey);
- die("Config.xml is corrupted and is 0 bytes. Could not restore a previous backup.");
- }
- }
- unlock($lockkey);
- $config = parse_config(true);
- $lockkey = lock('config');
- }
- } else {
+ if (is_null($config))
+ $parse = true;
+ } else
+ $parse = true;
+ }
+ if ($parse == true) {
if(!file_exists($g['conf_path'] . "/config.xml")) {
- if($g['booting']) echo ".";
+ if($g['booting'])
+ echo ".";
log_error("No config.xml found, attempting last known config restore.");
file_notice("config.xml", "No config.xml found, attempting last known config restore.", "pfSenseConfigurator", "");
$last_backup = discover_last_backup();
@@ -149,7 +141,7 @@ function parse_config($parse = false) {
}
}
$config = parse_xml_config($g['conf_path'] . '/config.xml', array($g['xml_rootobj'], 'pfsense'));
- if($config == "-1") {
+ if($config == -1) {
$last_backup = discover_last_backup();
if ($last_backup)
restore_backup("/cf/conf/backup/{$last_backup}");
@@ -161,11 +153,15 @@ function parse_config($parse = false) {
}
generate_config_cache($config);
}
- if($g['booting']) echo ".";
- alias_make_table($config);
+
+ if($g['booting'])
+ echo ".";
+
$config_parsed = true;
unlock($lockkey);
+ alias_make_table($config);
+
return $config;
}
@@ -226,7 +222,8 @@ function restore_backup($file) {
function parse_config_bootup() {
global $config, $g;
- if($g['booting']) echo ".";
+ if($g['booting'])
+ echo ".";
$lockkey = lock('config');
if (!file_exists("{$g['conf_path']}/config.xml")) {
@@ -250,6 +247,7 @@ function parse_config_bootup() {
}
if(!file_exists("{$g['conf_path']}/config.xml")) {
echo "XML configuration file not found. {$g['product_name']} cannot continue booting.\n";
+ unlock($lockkey);
mwexec("/sbin/halt");
exit;
}
OpenPOWER on IntegriCloud