summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjim-p <jim@pingle.org>2010-04-16 12:14:05 -0400
committerjim-p <jim@pingle.org>2010-04-16 12:14:05 -0400
commita76c1c453a207195d70de9da4a3ac3b4b0840162 (patch)
tree96499f04f967d35ddfb914f9844bf2fc6bf39adc
parent93b8266e2a93982b2b9a065821e59dc1a85f36e9 (diff)
downloadpfsense-a76c1c453a207195d70de9da4a3ac3b4b0840162.zip
pfsense-a76c1c453a207195d70de9da4a3ac3b4b0840162.tar.gz
Beef up the version comparison code. This should let us compare several combinations of local and remote versions and properly determine if the current version is older or the same as the remote version.
-rw-r--r--etc/inc/pfsense-utils.inc85
-rwxr-xr-xusr/local/www/system_firmware_check.php41
2 files changed, 106 insertions, 20 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index dd7c4de..007a27e 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1793,4 +1793,89 @@ function process_alias_tgz($temp_filename) {
fclose($fd);
}
+function version_compare_dates($a, $b) {
+ $a_time = strtotime($a);
+ $b_time = strtotime($b);
+
+ if ((!$a_time) || (!$b_time)) {
+ return FALSE;
+ } else {
+ if ($a < $b)
+ return -1;
+ elseif ($a == $b)
+ return 0;
+ else
+ return 1;
+ }
+}
+function version_get_string_value($a) {
+ $strs = array(
+ 0 => "ALPHA-ALPHA",
+ 2 => "ALPHA",
+ 3 => "BETA",
+ 4 => "B",
+ 5 => "RC",
+ 6 => "RELEASE"
+ );
+ $major = 0;
+ $minor = 0;
+ foreach ($strs as $num => $str) {
+ if (substr($a, 0, strlen($str)) == $str) {
+ $major = $num;
+ $n = substr($a, strlen($str));
+ if (is_numeric($n))
+ $minor = $n;
+ break;
+ }
+ }
+ return "{$major}.{$minor}";
+}
+function version_compare_string($a, $b) {
+ return version_compare_numeric(version_get_string_value($a), version_get_string_value($b));
+}
+function version_compare_numeric($a, $b) {
+ $a_arr = explode('.', rtrim($a, '.0'));
+ $b_arr = explode('.', rtrim($b, '.0'));
+
+ foreach ($a_arr as $n => $val) {
+ if (array_key_exists($n, $b_arr)) {
+ // So far so good, both have values at this minor version level. Compare.
+ if ($val > $b_arr[$n])
+ return 1;
+ elseif ($val < $b_arr[$n])
+ return -1;
+ } else {
+ // a is greater, since b doesn't have any minor version here.
+ return 1;
+ }
+ }
+ if (count($b_arr) > count($a_arr)) {
+ // b is longer than a, so it must be greater.
+ return -1;
+ } else {
+ // Both a and b are of equal length and value.
+ return 0;
+ }
+}
+function pfs_version_compare($cur_time, $cur_text, $remote) {
+ // First try date compare
+ $v = version_compare_dates($cur_time, $b);
+ if ($v === FALSE) {
+ // If that fails, try to compare by string
+ // Before anything else, simply test if the strings are equal
+ if ($cur_text == $remote)
+ return 0;
+ list($cur_num, $cur_str) = explode('-', $cur_text);
+ list($rem_num, $rem_str) = explode('-', $remote);
+
+ // First try to compare the numeric parts of the version string.
+ $v = version_compare_numeric($cur_num, $rem_num);
+
+ // If the numeric parts are the same, compare the string parts.
+ if ($v == 0)
+ return version_compare_string($cur_str, $rem_str);
+ }
+ return $v;
+}
+
?>
diff --git a/usr/local/www/system_firmware_check.php b/usr/local/www/system_firmware_check.php
index 77c528c..8d342ae 100755
--- a/usr/local/www/system_firmware_check.php
+++ b/usr/local/www/system_firmware_check.php
@@ -119,33 +119,33 @@ if(isset($curcfg['alturl']['enable']))
else
$updater_url = $g['update_url'];
$needs_system_upgrade = false;
+$static_text .= "Downloading new version information...";
download_file_with_progress_bar("{$updater_url}/version", "/tmp/{$g['product_name']}_version");
-$latest_version = str_replace("\n", "", @file_get_contents("/tmp/{$g['product_name']}_version"));
-$static_text .= "done.\n";
-if(!$latest_version) {
- $static_text .= "Unable to check for updates.\n";
+$remote_version = trim(@file_get_contents("/tmp/{$g['product_name']}_version"));
+$static_text .= "done.\\n";
+if (!$remote_version) {
+ $static_text .= "Unable to check for updates.\\n";
if(isset($curcfg['alturl']['enable']))
- $static_text .= "Could not contact custom update server.\n";
+ $static_text .= "Could not contact custom update server.\\n";
else
- $static_text .= "Could not contact {$g['product_name']} update server {$updater_url}.\n";
+ $static_text .= "Could not contact {$g['product_name']} update server {$updater_url}.\\n";
} else {
- $static_text .= "Downloading current version information...";
+ $static_text .= "Obtaining current version information...";
update_output_window($static_text);
- $current_installed_pfsense_version = str_replace("\n", "", file_get_contents("/etc/version.buildtime"));
- $current_installed_pfsense = strtotime($current_installed_pfsense_version);
- $latest_build_version = strtotime($latest_version);
- $static_text .= "done\n";
+
+ $current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
+ $current_installed_version = trim(file_get_contents("/etc/version"));
+
+ $static_text .= "done\\n";
update_output_window($static_text);
- if(!$latest_build_version) {
+
+ if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) {
$needs_system_upgrade = true;
} else {
- if($current_installed_pfsense < $latest_build_version) {
- $needs_system_upgrade = true;
- } else {
- $static_text .= "You are on the latest version.\n";
- }
+ $static_text .= "\\nYou are on the latest version.\\n";
}
}
+
update_output_window($static_text);
if ($needs_system_upgrade == false) {
require("fend.inc");
@@ -154,9 +154,10 @@ if ($needs_system_upgrade == false) {
echo "\n<script>$('invokeupgrade').style.visibility = 'visible';</script>";
$txt = "A new version is now available \\n\\n";
-$txt .= "Current version: {$current_installed_pfsense_version}\\n";
-$txt .= "New version: {$latest_version}\\n\\n";
-$txt .= "Update source: {$updater_url}\\n";
+$txt .= "Current version: {$current_installed_version}\\n";
+$txt .= " Built On: {$current_installed_buildtime}\\n";
+$txt .= " New version: {$remote_version}\\n\\n";
+$txt .= " Update source: {$updater_url}\\n";
update_output_window($txt);
?>
</form>
OpenPOWER on IntegriCloud