diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2006-01-03 19:15:10 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2006-01-03 19:15:10 +0000 |
commit | 5af3e20672c93c4da557e23895b6956ae4a9d0c6 (patch) | |
tree | 7826252faafe29e1da73838fd3bd2c8bdafa6293 /etc | |
parent | d941324173eec466b3d8b4b651b5f8368c873d89 (diff) | |
download | pfsense-5af3e20672c93c4da557e23895b6956ae4a9d0c6.zip pfsense-5af3e20672c93c4da557e23895b6956ae4a9d0c6.tar.gz |
Validate config.xml after changing m0n0wall -> pfsense
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/config.inc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/etc/inc/config.inc b/etc/inc/config.inc index e48d390..c3d0f01 100644 --- a/etc/inc/config.inc +++ b/etc/inc/config.inc @@ -70,6 +70,8 @@ if(file_exists("/cf/conf/config.xml")) { /* user has just upgraded to m0n0wall, replace root xml tags */ echo "Upgrading m0n0wall configuration to pfSense... "; $config_contents = str_replace("m0n0wall","pfsense", $config_contents); + if (!config_validate($config_contents)) + log_error("ERROR! Could not convert m0n0wall -> pfsense in config.xml"); $fd = fopen("/cf/conf/config.xml", "w"); fwrite($fd, $config_contents); fclose($fd); @@ -865,6 +867,9 @@ function config_install($conffile) { if (!file_exists($conffile)) return 1; + if (!config_validate($conffile)) + return 1; + if($g['booting'] == true) echo "Installing configuration...\n"; @@ -884,6 +889,32 @@ function config_install($conffile) { return 0; } +function config_validate($conffile) { + + global $g, $xmlerr; + + $xml_parser = xml_parser_create(); + + if (!($fp = fopen($conffile, "r"))) { + $xmlerr = "XML error: unable to open file"; + return false; + } + + while ($data = fread($fp, 4096)) { + if (!xml_parse($xml_parser, $data, feof($fp))) { + $xmlerr = sprintf("%s at line %d", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser)); + return false; + } + } + xml_parser_free($xml_parser); + + fclose($fp); + + return true; +} + /* lock configuration file, decide that the lock file is stale after 10 seconds */ function config_lock() { |