summaryrefslogtreecommitdiffstats
path: root/etc/ecl.php
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2010-11-28 14:03:33 -0500
committerScott Ullrich <sullrich@pfsense.org>2010-11-28 14:03:51 -0500
commit206f684d915fffb3900bb6537c037cbd3da257f8 (patch)
tree8c01ff8c1767dd2e41d1132d8b1648662772858b /etc/ecl.php
parent0ba17c67a0d79b8e87884669c8b456f7515a884e (diff)
downloadpfsense-206f684d915fffb3900bb6537c037cbd3da257f8.zip
pfsense-206f684d915fffb3900bb6537c037cbd3da257f8.tar.gz
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()
Diffstat (limited to 'etc/ecl.php')
-rwxr-xr-xetc/ecl.php110
1 files changed, 110 insertions, 0 deletions
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 @@
+<?php
+/*
+ external config loader
+ Copyright (C) 2010 Scott Ullrich
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+require("globals.inc");
+require("functions.inc");
+
+function get_boot_disk() {
+ global $g;
+ $disk = `/sbin/mount | /usr/bin/grep "on / " | /usr/bin/cut -d'/' -f3 | /usr/bin/cut -d' ' -f1`;
+ return $disk;
+}
+
+function get_disks() {
+ global $g;
+ $disks_array = array();
+ $disks = `/sbin/sysctl kern.disks | cut -d':' -f2`;
+ $disks_s = explode(" ", $disks);
+ foreach($disks_s as $disk)
+ if(trim($disk))
+ $disks_array[] = $disk;
+ return $disks_array;
+}
+
+// Probes all disks looking for config.xml
+function find_config_xml() {
+ global $g;
+ $disks = get_disks();
+ $boot_disk = get_boot_disk();
+ exec("mkdir -p /tmp/mnt/cf");
+ $found_config = false;
+ foreach($disks as $disk) {
+ echo " $disk";
+ // First try msdos fs
+ $result = exec("/sbin/mount -t msdos /dev/{$disk} /tmp/mnt/cf 2>/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
OpenPOWER on IntegriCloud