From 206f684d915fffb3900bb6537c037cbd3da257f8 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Sun, 28 Nov 2010 14:03:33 -0500 Subject: Adding external configuration loader which will look on all found disks except bootup disk for config.xml. If tconfig.xml is found on an external disk then it tests the roobobj to ensure its a valid file then calls test_config() to ensure it is a valid xml file. Once the file is validated a backup_config() is called to backup the current configuration and finally the file is installed using restore_backup() --- etc/ecl.php | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 etc/ecl.php (limited to 'etc/ecl.php') diff --git a/etc/ecl.php b/etc/ecl.php new file mode 100755 index 0000000..f55b615 --- /dev/null +++ b/etc/ecl.php @@ -0,0 +1,110 @@ +/dev/null"); + // Next try regular fs (ufs) + if(!$result) + $result = exec("/sbin/mount /dev/{$disk} /tmp/mnt/cf 2>/dev/null"); + if($result == "0") { + // Item was mounted - look for config.xml file + $config_location = discover_config($disk); + if($config_location) { + if(test_config($config_location)) { + // We have a valid configuration. Install it. + echo " -> found "; + backup_config(); + restore_backup($config_location); + exec("/sbin/unount /tmp/mnt/cf"); + break; + } + } + } + } +} + +function discover_config($mountpoint) { + global $g; + $locations_to_check = array("/", "/conf", "/conf.default", "/config"); + foreach($locations_to_check as $ltc) { + $tocheck = "{$mountpoint}{$ltc}/config.xml"; + if(file_exists($tocheck)) + return $tocheck; + } + return ""; +} + +function test_config($file_location) { + global $g; + // config.xml was found. ensure it is sound. + $root_obj = $g['xml_rootobj']; + $xml_file_head = trim(`/bin/cat {$file_location} | /usr/bin/head -n1`); + if($xml_file_head == $root_obj) { + // Now parse config to make sure + $config_status = config_validate($file_location); + if($config_status) + return true; + } + return false; +} + +echo "External config loader 1.0 is now starting..."; +find_config_xml(); +echo "\n"; + +?> \ No newline at end of file -- cgit v1.1