summaryrefslogtreecommitdiffstats
path: root/etc/ecl.php
diff options
context:
space:
mode:
Diffstat (limited to 'etc/ecl.php')
-rwxr-xr-xetc/ecl.php72
1 files changed, 43 insertions, 29 deletions
diff --git a/etc/ecl.php b/etc/ecl.php
index 9aa07d5..15205f1 100755
--- a/etc/ecl.php
+++ b/etc/ecl.php
@@ -1,5 +1,5 @@
<?php
-/*
+/*
external config loader
Copyright (C) 2010 Scott Ullrich
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
@@ -25,7 +25,7 @@
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.
-
+
Currently supported file system types: MS-Dos, FreeBSD UFS
*/
@@ -53,8 +53,9 @@ function get_disk_slices($disk) {
$slices_array = array();
$slices = trim(exec("/bin/ls " . escapeshellarg("/dev/" . $disk . "s*") . " 2>/dev/null"));
$slices = str_replace("/dev/", "", $slices);
- if($slices == "ls: No match.")
+ if ($slices == "ls: No match.") {
return;
+ }
$slices_array = explode(" ", $slices);
return $slices_array;
}
@@ -63,44 +64,50 @@ function get_disks() {
global $g, $debug;
$disks_array = array();
$disks_s = explode(" ", get_single_sysctl("kern.disks"));
- foreach($disks_s as $disk)
- if(trim($disk))
+ foreach ($disks_s as $disk) {
+ if (trim($disk)) {
$disks_array[] = $disk;
+ }
+ }
return $disks_array;
}
function discover_config($mountpoint) {
global $g, $debug;
$locations_to_check = array("/", "/config");
- foreach($locations_to_check as $ltc) {
+ foreach ($locations_to_check as $ltc) {
$tocheck = "/tmp/mnt/cf{$ltc}config.xml";
- if($debug) {
+ if ($debug) {
echo "\nChecking for $tocheck";
- if(file_exists($tocheck))
+ if (file_exists($tocheck)) {
echo " -> found!";
+ }
}
- if(file_exists($tocheck))
+ if (file_exists($tocheck)) {
return $tocheck;
+ }
}
return "";
}
function test_config($file_location) {
global $g, $debug;
- if(!$file_location)
+ if (!$file_location) {
return;
+ }
// config.xml was found. ensure it is sound.
$root_obj = trim("<{$g['xml_rootobj']}>");
$xml_file_head = exec("/usr/bin/head -2 " . escapeshellarg($file_location) . " | /usr/bin/tail -n1");
- if($debug) {
+ if ($debug) {
echo "\nroot obj = $root_obj";
echo "\nfile head = $xml_file_head";
}
- if($xml_file_head == $root_obj) {
+ if ($xml_file_head == $root_obj) {
// Now parse config to make sure
$config_status = config_validate($file_location);
- if($config_status)
+ if ($config_status) {
return true;
+ }
}
return false;
}
@@ -110,46 +117,53 @@ function find_config_xml() {
global $g, $debug;
$disks = get_disks();
// Safety check.
- if(!is_array($disks))
+ if (!is_array($disks)) {
return;
+ }
$boot_disk = get_boot_disk();
$swap_disks = get_swap_disks();
exec("/bin/mkdir -p /tmp/mnt/cf");
- foreach($disks as $disk) {
+ foreach ($disks as $disk) {
$slices = get_disk_slices($disk);
- if(is_array($slices)) {
- foreach($slices as $slice) {
- if($slice == "")
+ if (is_array($slices)) {
+ foreach ($slices as $slice) {
+ if ($slice == "") {
continue;
- if(stristr($slice, $boot_disk)) {
- if($debug)
+ }
+ if (stristr($slice, $boot_disk)) {
+ if ($debug) {
echo "\nSkipping boot device slice $slice";
+ }
continue;
}
- if(in_array($slice, $swap_disks)) {
- if($debug)
+ if (in_array($slice, $swap_disks)) {
+ if ($debug) {
echo "\nSkipping swap device slice $slice";
+ }
continue;
}
echo " $slice";
// First try msdos fs
- if($debug)
+ if ($debug) {
echo "\n/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
+ }
$result = exec("/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
// Next try regular fs (ufs)
- if(!$result) {
- if($debug)
+ if (!$result) {
+ if ($debug) {
echo "\n/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
+ }
$result = exec("/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
}
$mounted = trim(exec("/sbin/mount | /usr/bin/grep -v grep | /usr/bin/grep '/tmp/mnt/cf' | /usr/bin/wc -l"));
- if($debug)
+ if ($debug) {
echo "\nmounted: $mounted ";
- if(intval($mounted) > 0) {
+ }
+ if (intval($mounted) > 0) {
// Item was mounted - look for config.xml file
$config_location = discover_config($slice);
- if($config_location) {
- if(test_config($config_location)) {
+ if ($config_location) {
+ if (test_config($config_location)) {
// We have a valid configuration. Install it.
echo " -> found config.xml\n";
echo "Backing up old configuration...\n";
OpenPOWER on IntegriCloud