From 79529c0d2a63c6ec35855824ccfb479bd8609a5c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 25 Apr 2014 15:40:07 +0200 Subject: [PATCH] [ADDED] Online version checks --- public/include/classes/tools.class.php | 23 +++++++++++++++++++ public/include/config/global.inc.dist.php | 2 ++ public/include/pages/admin/dashboard.inc.php | 7 +++++- .../bootstrap/admin/dashboard/mpos.tpl | 10 ++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/public/include/classes/tools.class.php b/public/include/classes/tools.class.php index 210e27e0..8e861e63 100644 --- a/public/include/classes/tools.class.php +++ b/public/include/classes/tools.class.php @@ -7,6 +7,28 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; * the scope of our web application **/ class Tools extends Base { + public function getOnlineVersions() { + // Fetch version online, cache for a bit + $key = $this->config['memcache']['keyprefix'] . 'ONLINE_VERSIONS'; + if (! $mpos_versions = $this->memcache->get($key)) { + $url = $this->config['version_url']; + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HEADER, false); + $data = curl_exec($curl); + preg_match('/define\(\'MPOS_VERSION\', \'(.*)\'\);/', $data, $match); + $mpos_versions['MPOS_VERSION'] = $match[1]; + preg_match('/define\(\'DB_VERSION\', \'(.*)\'\);/', $data, $match); + $mpos_versions['DB_VERSION'] = $match[1]; + preg_match('/define\(\'CONFIG_VERSION\', \'(.*)\'\);/', $data, $match); + $mpos_versions['CONFIG_VERSION'] = $match[1]; + curl_close($curl); + return $this->memcache->setCache($key, $mpos_versions, 30); + } else { + return $mpos_versions; + } + } /** * Fetch JSON data from an API * @param url string API URL @@ -108,3 +130,4 @@ class Tools extends Base { $tools = new Tools(); $tools->setDebug($debug); $tools->setConfig($config); +$tools->setMemcache($memcache); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index cb3e7988..ca1069dd 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -3,9 +3,11 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; /** * Do not edit this unless you have confirmed that your config has been updated! + * Also the URL to check for the most recent upstream versions available * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-config-version **/ $config['version'] = '0.0.8'; +$config['version_url'] = 'https://raw.githubusercontent.com/MPOS/php-mpos/master/public/include/version.inc.php'; /** * Unless you disable this, we'll do a quick check on your config first. diff --git a/public/include/pages/admin/dashboard.inc.php b/public/include/pages/admin/dashboard.inc.php index d5ab1bdc..63d2738f 100644 --- a/public/include/pages/admin/dashboard.inc.php +++ b/public/include/pages/admin/dashboard.inc.php @@ -14,9 +14,14 @@ if ($bitcoin->can_connect() === true){ $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'alert alert-danger'); } +// Grab versions from Online source +require_once(CLASS_DIR . '/tools.class.php'); +$online_versions = $tools->getOnlineVersions(); + // Fetch version information $version['CURRENT'] = array('DB' => DB_VERSION, 'CONFIG' => CONFIG_VERSION, 'CORE' => MPOS_VERSION); -$version['INSTALLED'] = array('DB' => $setting->getValue('DB_VERSION'), 'CONFIG' => $config['version'], 'CORE' => MPOS_VERSION); +$version['INSTALLED'] = array('DB' => $setting->getValue('DB_VERSION'), 'CONFIG' => $config['version'], 'CORE' => $online_versions['MPOS_VERSION']); +$version['ONLINE'] = array('DB' => $online_versions['DB_VERSION'], 'CONFIG' => $online_versions['CONFIG_VERSION'], 'CORE' => $online_versions['MPOS_VERSION']); // Fetch our cron list $aMonitorCrons require_once(INCLUDE_DIR . '/config/monitor_crons.inc.php'); diff --git a/public/templates/bootstrap/admin/dashboard/mpos.tpl b/public/templates/bootstrap/admin/dashboard/mpos.tpl index 5161a009..e0a83751 100644 --- a/public/templates/bootstrap/admin/dashboard/mpos.tpl +++ b/public/templates/bootstrap/admin/dashboard/mpos.tpl @@ -11,6 +11,7 @@ Component Current Installed + Online @@ -20,6 +21,9 @@ {$VERSION['INSTALLED']['CORE']} + + {$VERSION['ONLINE']['CORE']} + Config @@ -27,6 +31,9 @@ {$VERSION['INSTALLED']['CONFIG']} + + {$VERSION['ONLINE']['CONFIG']} + Database @@ -34,6 +41,9 @@ {$VERSION['INSTALLED']['DB']} + + {$VERSION['ONLINE']['DB']} +