diff options
-rw-r--r-- | src/etc/inc/globals.inc | 4 | ||||
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 22 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/etc/inc/globals.inc b/src/etc/inc/globals.inc index b803953..f2fe7bf 100644 --- a/src/etc/inc/globals.inc +++ b/src/etc/inc/globals.inc @@ -172,6 +172,10 @@ if (file_exists("/etc/inc/globals_override.inc")) { /* Read all XML files in following dir and load menu entries */ $g["ext_menu_path"] = "/usr/local/share/{$g['product_name']}/menu"; +/* Cache file used to store pfSense version */ +$g["version_cache_file"] = "{$g['varrun_path']}/{$g['product_name']}_version"; +$g['version_cache_refresh'] = 24 * 60 * 60; /* 24h */ + function platform_booting($on_console = false) { global $g; diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index cb805eb..9130ed6 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -1170,14 +1170,28 @@ function get_base_pkg_name() { } /* Verify if system needs upgrade (meta package or base) */ -function get_system_pkg_version($baseonly = false) { +function get_system_pkg_version($baseonly = false, $use_cache = true) { global $g; - $output = exec("/usr/local/sbin/{$g['product_name']}-upgrade -c", $_gc, - $rc); + $cache_file = $g['version_cache_file']; + $rc_file = $cache_file . '.rc'; + + $rc = ""; + if ($use_cache && file_exists($rc_file) && + (time()-filemtime($rc_file) < $g['version_cache_refresh'])) { + $rc = chop(@file_get_contents($rc_file)); + } + + if ($rc == "2") { + $output = @file_get_contents($cache_file); + } else if ($rc != "0") { + $output = exec( + "/usr/local/sbin/{$g['product_name']}-upgrade -c", $_gc, + $rc); + } /* pfSense-upgrade returns 2 when there is a new version */ - if ($rc == 2) { + if ($rc == "2") { $new_version = explode(' ', $output)[0]; } |