Skip to content

Commit 1d6a560

Browse files
committed
Merge pull request #2142 from MPOS/online-version-check
[ADDED] Online version checks
2 parents dab06b7 + 79529c0 commit 1d6a560

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

public/include/classes/tools.class.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
* the scope of our web application
88
**/
99
class Tools extends Base {
10+
public function getOnlineVersions() {
11+
// Fetch version online, cache for a bit
12+
$key = $this->config['memcache']['keyprefix'] . 'ONLINE_VERSIONS';
13+
if (! $mpos_versions = $this->memcache->get($key)) {
14+
$url = $this->config['version_url'];
15+
$curl = curl_init();
16+
curl_setopt($curl, CURLOPT_URL, $url);
17+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
18+
curl_setopt($curl, CURLOPT_HEADER, false);
19+
$data = curl_exec($curl);
20+
preg_match('/define\(\'MPOS_VERSION\', \'(.*)\'\);/', $data, $match);
21+
$mpos_versions['MPOS_VERSION'] = $match[1];
22+
preg_match('/define\(\'DB_VERSION\', \'(.*)\'\);/', $data, $match);
23+
$mpos_versions['DB_VERSION'] = $match[1];
24+
preg_match('/define\(\'CONFIG_VERSION\', \'(.*)\'\);/', $data, $match);
25+
$mpos_versions['CONFIG_VERSION'] = $match[1];
26+
curl_close($curl);
27+
return $this->memcache->setCache($key, $mpos_versions, 30);
28+
} else {
29+
return $mpos_versions;
30+
}
31+
}
1032
/**
1133
* Fetch JSON data from an API
1234
* @param url string API URL
@@ -108,3 +130,4 @@ public function getPrice() {
108130
$tools = new Tools();
109131
$tools->setDebug($debug);
110132
$tools->setConfig($config);
133+
$tools->setMemcache($memcache);

public/include/config/global.inc.dist.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
/**
55
* Do not edit this unless you have confirmed that your config has been updated!
6+
* Also the URL to check for the most recent upstream versions available
67
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-config-version
78
**/
89
$config['version'] = '0.0.8';
10+
$config['version_url'] = 'https://raw.githubusercontent.com/MPOS/php-mpos/master/public/include/version.inc.php';
911

1012
/**
1113
* Unless you disable this, we'll do a quick check on your config first.

public/include/pages/admin/dashboard.inc.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'alert alert-danger');
1515
}
1616

17+
// Grab versions from Online source
18+
require_once(CLASS_DIR . '/tools.class.php');
19+
$online_versions = $tools->getOnlineVersions();
20+
1721
// Fetch version information
1822
$version['CURRENT'] = array('DB' => DB_VERSION, 'CONFIG' => CONFIG_VERSION, 'CORE' => MPOS_VERSION);
19-
$version['INSTALLED'] = array('DB' => $setting->getValue('DB_VERSION'), 'CONFIG' => $config['version'], 'CORE' => MPOS_VERSION);
23+
$version['INSTALLED'] = array('DB' => $setting->getValue('DB_VERSION'), 'CONFIG' => $config['version'], 'CORE' => $online_versions['MPOS_VERSION']);
24+
$version['ONLINE'] = array('DB' => $online_versions['DB_VERSION'], 'CONFIG' => $online_versions['CONFIG_VERSION'], 'CORE' => $online_versions['MPOS_VERSION']);
2025

2126
// Fetch our cron list $aMonitorCrons
2227
require_once(INCLUDE_DIR . '/config/monitor_crons.inc.php');

public/templates/bootstrap/admin/dashboard/mpos.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<th>Component</th>
1212
<th>Current</th>
1313
<th>Installed</th>
14+
<th>Online</th>
1415
</tr>
1516
</thead>
1617
<tbody>
@@ -20,20 +21,29 @@
2021
<td>
2122
<font color="{if $VERSION['INSTALLED']['CORE'] == $VERSION['CURRENT']['CORE']}green{else}red{/if}">{$VERSION['INSTALLED']['CORE']}</font>
2223
</td>
24+
<td>
25+
<font color="{if $VERSION['INSTALLED']['CORE'] == $VERSION['ONLINE']['CORE']}green{else}red{/if}">{$VERSION['ONLINE']['CORE']}</font>
26+
</td>
2327
</tr>
2428
<tr>
2529
<td><strong>Config</strong></td>
2630
<td><font color="green">{$VERSION['CURRENT']['CONFIG']}</font></td>
2731
<td>
2832
<font color="{if $VERSION['INSTALLED']['CONFIG'] == $VERSION['CURRENT']['CONFIG']}green{else}red{/if}">{$VERSION['INSTALLED']['CONFIG']}</font>
2933
</td>
34+
<td>
35+
<font color="{if $VERSION['INSTALLED']['CONFIG'] == $VERSION['ONLINE']['CONFIG']}green{else}red{/if}">{$VERSION['ONLINE']['CONFIG']}</font>
36+
</td>
3037
</tr>
3138
<tr>
3239
<td><strong>Database</strong></td>
3340
<td><font color="green">{$VERSION['CURRENT']['DB']}</font></td>
3441
<td>
3542
<font color="{if $VERSION['INSTALLED']['DB'] == $VERSION['CURRENT']['DB']}green{else}red{/if}">{$VERSION['INSTALLED']['DB']}</font>
3643
</td>
44+
<td>
45+
<font color="{if $VERSION['INSTALLED']['DB'] == $VERSION['ONLINE']['DB']}green{else}red{/if}">{$VERSION['ONLINE']['DB']}</font>
46+
</td>
3747
</tr>
3848
</tbody>
3949
</table>

0 commit comments

Comments
 (0)