From 5779ade6707ba530517da239d9ec3fc751d17d83 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Fri, 31 Jul 2015 10:03:34 -0300 Subject: Introduce a new item to $g global, 'product_version' and stop reading /etc/version all around --- etc/inc/globals.inc | 4 ++-- etc/inc/pfsense-utils.inc | 12 ++++++------ etc/inc/services.inc | 3 +-- etc/rc.banner | 3 +-- usr/local/pkg/miniupnpd.inc | 4 ++-- usr/local/www/crash_reporter.php | 2 +- usr/local/www/pkg_mgr_installed.php | 3 +-- usr/local/www/pkg_mgr_settings.php | 3 +-- usr/local/www/system_firmware_auto.php | 7 +++---- usr/local/www/system_firmware_check.php | 5 ++--- usr/local/www/widgets/widgets/system_information.widget.php | 5 ++--- 11 files changed, 22 insertions(+), 29 deletions(-) diff --git a/etc/inc/globals.inc b/etc/inc/globals.inc index 504f67c..b40a862 100644 --- a/etc/inc/globals.inc +++ b/etc/inc/globals.inc @@ -58,6 +58,7 @@ $g = array( "xml_rootobj" => "pfsense", "admin_group" => "admins", "product_name" => "pfSense", + "product_version" => trim(file_get_contents("{$g['etc_path']}/version"), " \n"), "product_copyright" => "Electric Sheep Fencing LLC", "product_copyright_url" => "http://www.electricsheepfencing.com", "product_copyright_years" => "2004 - ".date("Y"), @@ -98,9 +99,8 @@ $tcpflags = array("syn", "ack", "fin", "rst", "psh", "urg", "ece", "cwr"); if (file_exists("/etc/platform")) { $arch = php_uname("m"); - $current_version = trim(file_get_contents("{$g['etc_path']}/version")); - if (strstr($current_version, "-RELEASE")) { + if (strstr($g['product_version'], "-RELEASE")) { /* This is only necessary for RELEASE */ $arch = ($arch == "i386") ? "" : '/' . $arch; /* Full installs and NanoBSD use the same update directory and manifest in 2.x */ diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 22b0be0..93719ad 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -802,7 +802,7 @@ function check_firmware_version($tocheck = "all", $return_php = true) { } $version = php_uname('r'); $version = explode('-', $version); - $rawparams = array("firmware" => array("version" => trim(file_get_contents('/etc/version'))), + $rawparams = array("firmware" => array("version" => $g['product_version']), "kernel" => array("version" => $version[0]), "base" => array("version" => $version[0]), "platform" => trim(file_get_contents('/etc/platform')), @@ -841,7 +841,7 @@ function host_firmware_version($tocheck = "") { $os_version = trim(substr(php_uname("r"), 0, strpos(php_uname("r"), '-'))); return array( - "firmware" => array("version" => trim(file_get_contents('/etc/version', " \n"))), + "firmware" => array("version" => $g['product_version']), "kernel" => array("version" => $os_version), "base" => array("version" => $os_version), "platform" => trim(file_get_contents('/etc/platform', " \n")), @@ -1773,9 +1773,9 @@ function download_file($url, $destination, $verify_ssl = true, $connect_timeout curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if (!isset($config['system']['host_uuid'])) { - curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version") . ' : ' . get_single_sysctl('kern.hostuuid'))); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version'] . ' : ' . get_single_sysctl('kern.hostuuid')); } else { - curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version"))); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version']); } if (!empty($config['system']['proxyurl'])) { @@ -1819,9 +1819,9 @@ function download_file_with_progress_bar($url_file, $destination_file, $readbody curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); if (!isset($config['system']['host_uuid'])) { - curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version") . ' : ' . get_single_sysctl('kern.hostuuid'))); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version'] . ' : ' . get_single_sysctl('kern.hostuuid')); } else { - curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version"))); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version']); } if (!empty($config['system']['proxyurl'])) { diff --git a/etc/inc/services.inc b/etc/inc/services.inc index e3bf092..1412f7e 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -2084,13 +2084,12 @@ trap := "{$config['snmpd']['trapstring']}" EOD; } - $version = trim(file_get_contents('/etc/version')); $platform = trim(file_get_contents('/etc/platform')); if (($platform == "pfSense") && ($g['product_name'] != "pfSense")) { $platform = $g['product_name']; } $sysDescr = "{$g['product_name']} " . php_uname("n") . - " {$version} {$platform} " . php_uname("s") . + " {$g['product_version']} {$platform} " . php_uname("s") . " " . php_uname("r") . " " . php_uname("m"); $snmpdconf .= << $friendly) { diff --git a/usr/local/pkg/miniupnpd.inc b/usr/local/pkg/miniupnpd.inc index a545744..4ea768c 100644 --- a/usr/local/pkg/miniupnpd.inc +++ b/usr/local/pkg/miniupnpd.inc @@ -145,7 +145,7 @@ } function sync_package_miniupnpd() { - global $config; + global $g, $config; global $input_errors; $upnp_config = $config['installedpackages']['miniupnpd']['config'][0]; @@ -238,7 +238,7 @@ $config_text .= "serial=".strtoupper(substr(upnp_uuid(), 0, 8))."\n"; /* set model number */ - $config_text .= "model_number=".file_get_contents("/etc/version")."\n"; + $config_text .= "model_number=" . $g['product_version'] . "\n"; /* upnp access restrictions */ foreach ($upnp_config['row'] as $row) { diff --git a/usr/local/www/crash_reporter.php b/usr/local/www/crash_reporter.php index 24cb36f..3b00e47 100644 --- a/usr/local/www/crash_reporter.php +++ b/usr/local/www/crash_reporter.php @@ -57,7 +57,7 @@ function upload_crash_report($files) { curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version"))); + curl_setopt($ch, CURLOPT_USERAGENT, $g['product_name'] . '/' . $g['product_version']); curl_setopt($ch, CURLOPT_URL, $g['crashreporterurl']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); diff --git a/usr/local/www/pkg_mgr_installed.php b/usr/local/www/pkg_mgr_installed.php index e190fec..3801271 100644 --- a/usr/local/www/pkg_mgr_installed.php +++ b/usr/local/www/pkg_mgr_installed.php @@ -109,10 +109,9 @@ include("head.inc"); $upgrade_latest_tgz_sha256) { */ function read_body_firmware($ch, $string) { - global $fout, $file_size, $downloaded, $counter, $version, $latest_version, $current_installed_version; + global $g, $fout, $file_size, $downloaded, $counter, $version, $latest_version; $length = strlen($string); $downloaded += intval($length); $downloadProgress = round(100 * (1 - $downloaded / $file_size), 0); @@ -275,7 +274,7 @@ function read_body_firmware($ch, $string) { $c = $downloadProgress; $text = " " . gettext("Auto Update Download Status") . "\\n"; $text .= "----------------------------------------------------\\n"; - $text .= " " . gettext("Current Version") . " : {$current_installed_version}\\n"; + $text .= " " . gettext("Current Version") . " : {$g['product_version']}\\n"; $text .= " " . gettext("Latest Version") . " : {$latest_version}\\n"; $text .= " " . gettext("File size") . " : {$a}\\n"; $text .= " " . gettext("Downloaded") . " : {$b}\\n"; diff --git a/usr/local/www/system_firmware_check.php b/usr/local/www/system_firmware_check.php index d240a63..2e56943 100644 --- a/usr/local/www/system_firmware_check.php +++ b/usr/local/www/system_firmware_check.php @@ -157,12 +157,11 @@ if (!$remote_version) { update_output_window($static_text); $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 (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) { + if (pfs_version_compare($current_installed_buildtime, $g['product_version'], $remote_version) == -1) { $needs_system_upgrade = true; } else { $static_text .= "\\n" . gettext("You are on the latest version.") . "\\n"; @@ -191,7 +190,7 @@ echo "//]]>\n"; echo "\n"; $txt = gettext("A new version is now available") . "\\n\\n"; -$txt .= gettext("Current version") . ": " . $current_installed_version . "\\n"; +$txt .= gettext("Current version") . ": " . $g['product_version'] . "\\n"; if ($g['platform'] == "nanobsd") { $txt .= " " . gettext("NanoBSD Size") . " : " . trim(file_get_contents("/etc/nanosize.txt")) . "\\n"; } diff --git a/usr/local/www/widgets/widgets/system_information.widget.php b/usr/local/www/widgets/widgets/system_information.widget.php index 6143ac1..231f2ee 100644 --- a/usr/local/www/widgets/widgets/system_information.widget.php +++ b/usr/local/www/widgets/widgets/system_information.widget.php @@ -66,13 +66,12 @@ if ($_REQUEST['getupdatestatus']) { echo "

Unable to check for updates."; } else { $current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime")); - $current_installed_version = trim(file_get_contents("/etc/version")); if (!$remote_version) { echo "

Unable to check for updates."; } else { $needs_system_upgrade = false; - if (pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1) { + if (pfs_version_compare($current_installed_buildtime, $g['product_version'], $remote_version) == -1) { echo "
Update available. Click Here to view update."; echo "\n