From 7adc2dd35c0629bdf055dd6bcea03e591827a179 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Fri, 19 Apr 2013 13:55:38 +0200 Subject: [PATCH] Update version_compare function; fix syntax-error in bind-config generation, thx to monumentum Signed-off-by: Michael Kaufmann (d00p) --- admin_index.php | 2 +- install/updates/preconfig.php | 104 ------------------ .../froxlor/function.version_compare2.php | 90 +++++++++++++++ scripts/jobs/cron_tasks.inc.dns.10.bind.php | 10 +- 4 files changed, 94 insertions(+), 112 deletions(-) create mode 100644 lib/functions/froxlor/function.version_compare2.php diff --git a/admin_index.php b/admin_index.php index e233e274..c2623832 100644 --- a/admin_index.php +++ b/admin_index.php @@ -110,7 +110,7 @@ if($page == 'overview') $lookfornewversion_link = $_link; $lookfornewversion_addinfo = $_message; - if (version_compare($version, $_version) == -1) { + if (version_compare2($version, $_version) == -1) { $isnewerversion = 1; } else { $isnewerversion = 0; diff --git a/install/updates/preconfig.php b/install/updates/preconfig.php index c51aea08..cd997652 100644 --- a/install/updates/preconfig.php +++ b/install/updates/preconfig.php @@ -53,107 +53,3 @@ function versionInUpdate($current_version, $version_to_check) return (version_compare2($current_version, $version_to_check) == -1 ? true : false); } -/** - * compare of froxlor versions - * - * @param string $a - * @param string $b - * - * @return integer 0 if equal, 1 if a>b and -1 if b>a - */ -function version_compare2($a, $b) { - - // split version into pieces and remove trailing .0 - $a = explode(".", rtrim($a, ".0")); - $b = explode(".", rtrim($b, ".0")); - - // -svn or -dev or -rc ? - if (stripos($a[count($a)-1], '-') !== false) { - $x = explode("-", $a[count($a)-1]); - $a[count($a)-1] = $x[0]; - if (stripos($x[1], 'rc') !== false) { - $a[] = '0'; - $a[] = '2'; // rc > dev > svn - // number of rc - $a[] = substr($x[1], 2); - } - else if (stripos($x[1], 'dev') !== false) { - $a[] = '0'; - $a[] = '1'; // svn < dev < rc - // number of dev - $a[] = substr($x[1], 3); - } - // -svn version are deprecated - else if (stripos($x[1], 'svn') !== false) { - $a[] = '0'; - $a[] = '0'; // svn < dev < rc - // number of svn - $a[] = substr($x[1], 3); - } - else { - // unknown version string - return 0; - } - } - // same with $b - if (stripos($b[count($b)-1], '-') !== false) { - $x = explode("-", $b[count($b)-1]); - $b[count($b)-1] = $x[0]; - if (stripos($x[1], 'rc') !== false) { - $b[] = '0'; - $b[] = '2'; // rc > dev > svn - // number of rc - $b[] = substr($x[1], 2); - } - else if (stripos($x[1], 'dev') !== false) { - $b[] = '0'; - $b[] = '1'; // svn < dev < rc - // number of dev - $b[] = substr($x[1], 3); - } - // -svn version are deprecated - else if (stripos($x[1], 'svn') !== false) { - $b[] = '0'; - $b[] = '0'; // svn < dev < rc - // number of svn - $b[] = substr($x[1], 3); - } - else { - // unknown version string - return 0; - } - } - - /* - if (count($a) > count($b)) { - if ($a[count($b)-1] == $b[count($b)-1]) { - return -1; - } - } - if (count($b) > count($a)) { - if ($b[count($a)-1] == $a[count($a)-1]) { - return 1; - } - } - */ - - foreach ($a as $depth => $aVal) { - // iterate over each piece of A - if (isset($b[$depth])) { - // if B matches A to this depth, compare the values - if ($aVal > $b[$depth]) { - return 1; // A > B - } - else if ($aVal < $b[$depth]) { - return -1; // B > A - } - // an equal result is inconclusive at this point - } else { - // if B does not match A to this depth, then A comes after B in sort order - return 1; // so A > B - } - } - // at this point, we know that to the depth that A and B extend to, they are equivalent. - // either the loop ended because A is shorter than B, or both are equal. - return (count($a) < count($b)) ? -1 : 0; -} diff --git a/lib/functions/froxlor/function.version_compare2.php b/lib/functions/froxlor/function.version_compare2.php new file mode 100644 index 00000000..8d71b8c2 --- /dev/null +++ b/lib/functions/froxlor/function.version_compare2.php @@ -0,0 +1,90 @@ + + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Functions + * + */ + +/** + * compare of froxlor versions + * + * @param string $a + * @param string $b + * + * @return integer 0 if equal, 1 if a>b and -1 if b>a + */ +function version_compare2($a, $b) { + + // split version into pieces and remove trailing .0 + $a = explode(".", rtrim($a, ".0")); + $b = explode(".", rtrim($b, ".0")); + + _parseVersionArray($a); + _parseVersionArray($b); + + while (count($a) != count($b)) { + if (count($a) < count($b)) { + $a[] = '0'; + } + elseif (count($b) < count($a)) { + $b[] = '0'; + } + } + + foreach ($a as $depth => $aVal) { + // iterate over each piece of A + if (isset($b[$depth])) { + // if B matches A to this depth, compare the values + if ($aVal > $b[$depth]) { + return 1; // A > B + } + else if ($aVal < $b[$depth]) { + return -1; // B > A + } + // an equal result is inconclusive at this point + } else { + // if B does not match A to this depth, then A comes after B in sort order + return 1; // so A > B + } + } + // at this point, we know that to the depth that A and B extend to, they are equivalent. + // either the loop ended because A is shorter than B, or both are equal. + return (count($a) < count($b)) ? -1 : 0; +} + +function _parseVersionArray(&$arr = null) { + // -svn or -dev or -rc ? + if (stripos($arr[count($arr)-1], '-') !== false) { + $x = explode("-", $arr[count($arr)-1]); + $arr[count($arr)-1] = $x[0]; + if (stripos($x[1], 'rc') !== false) { + $arr[] = '-1'; + $arr[] = '2'; // rc > dev > svn + // number of rc + $arr[] = substr($x[1], 2); + } + else if (stripos($x[1], 'dev') !== false) { + $arr[] = '-1'; + $arr[] = '1'; // svn < dev < rc + // number of dev + $arr[] = substr($x[1], 3); + } + // -svn version are deprecated + else if (stripos($x[1], 'svn') !== false) { + $arr[] = '-1'; + $arr[] = '0'; // svn < dev < rc + // number of svn + $arr[] = substr($x[1], 3); + } + } +} diff --git a/scripts/jobs/cron_tasks.inc.dns.10.bind.php b/scripts/jobs/cron_tasks.inc.dns.10.bind.php index a4883b8c..7b9b2308 100644 --- a/scripts/jobs/cron_tasks.inc.dns.10.bind.php +++ b/scripts/jobs/cron_tasks.inc.dns.10.bind.php @@ -117,15 +117,11 @@ class bind $bindconf_file.= ' file "' . makeCorrectFile($this->settings['system']['bindconf_directory'] . '/' . $domain['zonefile']) . '";' . "\n"; $bindconf_file.= ' allow-query { any; };' . "\n"; - if(count($this->nameservers) > 0) - { + if (count($this->nameservers) > 0) { $bindconf_file.= ' allow-transfer {' . "\n"; - for ($i = 0;$i < count($this->nameservers);$i++) - { - $bindconf_file.= ' ' . $this->nameservers[$i]['ip'] . ';' . "\n"; + foreach ($this->nameservers as $ns) { + $bindconf_file.= ' ' . $ns['ip'] . ';' . "\n"; } - - $bindconf_file.= ' };' . "\n"; } // AXFR server #100