Merge pull request #3 from Atadilo/master

Use buildin function to get version
This commit is contained in:
Dallas 2019-10-17 08:39:51 -05:00 committed by GitHub
commit 1b094f3c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,78 +1,19 @@
#!/usr/local/bin/php -f #!/usr/local/bin/php -f
<? <?
# This check used to pull the version from the website and compare them, require_once("pkg-utils.inc");
# but some variables changed recently and I haven't circled back to this. $system_pkg_version = get_system_pkg_version();
# Thus, a majority of that code has been commented out.
#
require("globals.inc");
require("config.inc");
require("functions.inc");
$current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime")); $current_installed_buildtime = trim(file_get_contents("/etc/version.buildtime"));
$current_installed_version = trim(file_get_contents("/etc/version"));
# originally going to use same version file as web interface in tmp, but permission issues arose
$remote_version = trim(@file_get_contents("/home/nagios/{$g['product_name']}_version"));
$static_text = "";
if(isset($config['system']['firmware']['alturl']['enable'])) if ( $system_pkg_version['installed_version'] !== $system_pkg_version['version']) {
$updater_url = "{$config['system']['firmware']['alturl']['firmwareurl']}"; $additional_info = "WARNING - new version available\n" ; $exitcode = 1;
else
$updater_url = $g['update_url'];
$nanosize = "";
if ($g['platform'] == "nanobsd") {
if (file_exists("/etc/nano_use_vga.txt"))
$nanosize = "-nanobsd-vga-";
else
$nanosize = "-nanobsd-";
$nanosize .= strtolower(trim(file_get_contents("/etc/nanosize.txt")));
$update_filename = "latest{$nanosize}.img.gz";
} else { } else {
$update_filename = "latest.tgz"; $additional_info = "OK - already at latest version\n" ; $exitcode = 0;
} }
$additional_info .= "Current version: ".$system_pkg_version['installed_version']."\n";
$autoupdateurl = "{$updater_url}/{$update_filename}"; $additional_info .= "Built on: ".$current_installed_buildtime."\n";
$additional_info .= "Remote version: ".$system_pkg_version['version']."\n";
$tmp_filename = "/home/nagios/{$g['product_name']}_version";
// check if file exists and see if it is over 6 (60*60*6) hours old, if it is grab a new one
// do not drop your check under 6 hours as it will cause unnecessary calls to pfSense servers
if ( (!file_exists($tmp_filename)) || ((time()-filemtime($tmp_filename))> 60*60*6) || (count(file($tmp_filename))>2) ) {
//echo "need new remote file\n";
if(download_file_with_progress_bar("{$updater_url}/version{$nanosize}", "/home/nagios/{$g['product_name']}_version", 'read_body', 5, 5) === true)
{ sleep (5); $remote_version = trim(@file_get_contents("/home/nagios/{$g['product_name']}_version")); }
if ( (count(file($tmp_filename))>2) ) {
$static_text = gettext("UNKNOWN - unable to check for updates.") . "\n";
$exitcode = 3;
$remote_version = "Error";
if(isset($curcfg['alturl']['enable']))
$static_text .= gettext("Could not contact custom update server.") . "\n";
else
$static_text .= sprintf(gettext('Could not contact %1$s update server %2$s%3$s'), $g['product_name'], $updater_url, "\n");
}
}
if ($static_text !== "")
{ $additional_info = $static_text; }
/*
elseif ( pfs_version_compare($current_installed_buildtime, $current_installed_version, $remote_version) == -1)
{ $additional_info = "WARNING - new version available\n" ; $exitcode = 1; }
else
{ $additional_info = "OK - already at latest version\n" ; $exitcode = 0; }
*/
$additional_info .= "Current version: ".$current_installed_version." / ".$current_installed_buildtime;
#$additional_info .= "Current version: ".$current_installed_version."\n";
#$additional_info .= "Built on: ".$current_installed_buildtime;
#$additional_info .= "Remote version: ".$remote_version."\n";
echo $additional_info; echo $additional_info;
exit ($exitcode);
#exit ($exitcode);
?>