This commit is contained in:
Sebastian Grewe 2014-01-07 09:40:02 +01:00
commit ef28547940
10 changed files with 158 additions and 0 deletions

View File

@ -67,4 +67,11 @@ if ($monitoring->isDisabled($cron_name)) {
// Mark cron as running for monitoring
$log->logDebug('Marking cronjob as running for monitoring');
$monitoring->setStatus($cron_name . '_starttime', 'date', time());
// Check if we need to halt our crons due to an outstanding upgrade
if ($setting->getValue('db_upgrade_required') == 1 || $setting->getValue('config_upgrade_required') == 1) {
$log->logFatal('Cronjob is currently disabled due to required upgrades. Import any outstanding SQL files and check your configuration file.');
$monitoring->endCronjob($cron_name, 'E0075', 0, true, false);
}
?>

View File

@ -61,4 +61,7 @@ require_once(CLASS_DIR . '/api.class.php');
require_once(INCLUDE_DIR . '/lib/Michelf/Markdown.php');
require_once(INCLUDE_DIR . '/lib/scrypt.php');
// Include our versions
require_once(INCLUDE_DIR . '/version.inc.php');
?>

View File

@ -72,4 +72,5 @@ $aErrorCodes['E0065'] = 'Remaining balance is greater than 0';
$aErrorCodes['E0072'] = 'Worker names must be alphanumeric';
$aErrorCodes['E0073'] = 'Worker name is too long; try entering a shorter name';
$aErrorCodes['E0074'] = 'Failed deleting expired tokens';
$aErrorCodes['E0075'] = 'Upgrade required';
?>

View File

@ -2,6 +2,13 @@
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
/**
* Do not edit this unless you have confirmed that your config has been updated!
* This is used in the version check to ensure you run the latest version of the configuration file.
* Once you upgraded your config, change the version here too.
**/
$config['version'] = '0.0.1';
// Our include directory for additional features
define('INCLUDE_DIR', BASEPATH . 'include');

View File

@ -0,0 +1,45 @@
<?php
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
// Check user to ensure they are admin
if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
header("HTTP/1.1 404 Page not found");
die("404 Page not found");
}
if ($bitcoin->can_connect() === true){
$aGetInfo = $bitcoin->query('getinfo');
} else {
$aGetInfo = array('errors' => 'Unable to connect');
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
}
// 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);
// Fetch cron information
$aCrons = array('statistics','payouts','token_cleanup','archive_cleanup','blockupdate','findblock','notifications','tickerupdate');
// Data array for template
$cron_errors = 0;
$cron_disabled = 0;
foreach ($aCrons as $strCron) {
$status = $monitoring->getStatus($strCron . '_status');
$disabled = $monitoring->isDisabled($strCron);
if ($status['value'] != 0)
$cron_errors++;
if ($disabled['value'] == 1)
$cron_disabled++;
}
$smarty->assign('CRON_ERROR', $cron_errors);
$smarty->assign('CRON_DISABLED', $cron_disabled);
// Wallet status
$smarty->assign('WALLET_ERROR', $aGetInfo['errors']);
// Tempalte specifics
$smarty->assign('VERSION', $version);
$smarty->assign("CONTENT", "default.tpl");
?>

View File

@ -0,0 +1,24 @@
<?php
define('DB_VERSION', '0.0.1');
define('CONFIG_VERSION', '0.0.1');
define('MPOS_VERSION', '0.0.1');
// Fetch installed database version
$db_version = $setting->getValue('DB_VERSION');
if ($db_version != DB_VERSION) {
$setting->setValue('db_upgrade_required', 1);
// Notify admins via error popup
if (isset($_SESSION['USERDATA']) && $user->isAdmin($_SESSION['USERDATA']['id']))
$_SESSION['POPUP'][] = array('CONTENT' => 'Database version mismatch (Installed: ' . $db_version . ', Current: ' . DB_VERSION . '). Database update required, please import any new SQL files. Cronjobs have been halted.', 'TYPE' => 'errormsg');
}
if (@$config['version'] != CONFIG_VERSION) {
$setting->setValue('config_upgrade_required', 1);
// Notify admins via error popup
if (isset($_SESSION['USERDATA']) && $user->isAdmin($_SESSION['USERDATA']['id']))
$_SESSION['POPUP'][] = array('CONTENT' => 'Configuration file version mismatch (Installed: ' . @$config['version'] . ', Current: ' . CONFIG_VERSION . '). Configuration update required, please check dist config for changes. Cronjobs have been halted.', 'TYPE' => 'errormsg');
} else {
// Reset option, maybe there is a better way?
$setting->setValue('config_upgrade_required', 0);
}

View File

@ -0,0 +1,66 @@
{nocache}
<article class="module width_quarter">
<header><h3>MPOS Version Information</h3></header>
<table width="25%" class="tablesorter" cellspacing="0">
<thead>
<tr>
<th>Component</th>
<th align="center">Current</th>
<th align="center">Installed</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>MPOS</strong></td>
<td align="center"><font color="green">{$VERSION['CURRENT']['CORE']}</font></td>
<td align="center">
<font color="{if $VERSION['INSTALLED']['CORE'] == $VERSION['CURRENT']['CORE']}green{else}red{/if}">{$VERSION['INSTALLED']['CORE']}</font>
</td>
</tr>
<tr>
<td><strong>Config</strong></td>
<td align="center"><font color="green">{$VERSION['CURRENT']['CONFIG']}</font></td>
<td align="center">
<font color="{if $VERSION['INSTALLED']['CONFIG'] == $VERSION['CURRENT']['CONFIG']}green{else}red{/if}">{$VERSION['INSTALLED']['CONFIG']}</font>
</td>
</tr>
<tr>
<td><strong>Database</strong></td>
<td align="center"><font color="green">{$VERSION['CURRENT']['DB']}</font></td>
<td align="center">
<font color="{if $VERSION['INSTALLED']['DB'] == $VERSION['CURRENT']['DB']}green{else}red{/if}">{$VERSION['INSTALLED']['DB']}</font>
</td>
</tr>
</tbody>
</table>
</article>
<article class="module width_quarter">
<header><h3>MPOS Status</h3></header>
<table class="tablesorter" cellspacing="0">
<thead>
<tr>
<th colspan="2" align="center">Cronjobs</th>
<th align="center">Wallet</th>
</tr>
<tr>
<th align="center"><strong>Errors</strong></th>
<th align="center"><strong>Disabled</strong></th>
<th align="center"><strong>Errors</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">
<a href="{$smarty.server.PHP_SELF}?page=admin&action=monitoring">{if $CRON_ERROR == 0}None - OK{else}{$CRON_ERROR}{/if}</a>
</td>
<td align="center">
<a href="{$smarty.server.PHP_SELF}?page=admin&action=monitoring">{if $CRON_DISABLED == 0}None - OK{else}{$CRON_DISABLED}{/if}</a>
</td>
<td align="center">
<a href="{$smarty.server.PHP_SELF}?page=admin&action=wallet">{$WALLET_ERROR|default:"None - OK"}</a>
</td>
</tr>
</tbody>
</table>
</article>
{/nocache}

View File

@ -16,6 +16,7 @@
{if $smarty.session.AUTHENTICATED|default:"0" == 1 && $GLOBAL.userdata.is_admin == 1}
<h3>Admin Panel</h3>
<ul class="toggle">
<li class="icon-gauge"><a href="{$smarty.server.PHP_SELF}?page=admin&action=dashboard">Dashboard</a></li>
<li class="icon-bell"><a href="{$smarty.server.PHP_SELF}?page=admin&action=monitoring">Monitoring</a></li>
<li class="icon-torso"><a href="{$smarty.server.PHP_SELF}?page=admin&action=user">User Info</a></li>
<li class="icon-money"><a href="{$smarty.server.PHP_SELF}?page=admin&action=wallet">Wallet Info</a></li>

View File

@ -128,6 +128,8 @@ CREATE TABLE IF NOT EXISTS `settings` (
UNIQUE KEY `setting` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.1');
CREATE TABLE IF NOT EXISTS `shares` (
`id` bigint(30) NOT NULL AUTO_INCREMENT,
`rem_host` varchar(255) NOT NULL,

2
sql/012_db_version.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.1') ON DUPLICATE KEY UPDATE `value` = '0.0.1';
INSERT INTO `settings` (`name`, `value`) VALUES ('db_upgrade_required', 0) ON DUPLICATE KEY UPDATE `value` = 0;