Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cronjobs/shared.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@
// 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);
}

?>
3 changes: 3 additions & 0 deletions public/include/autoloader.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@
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');

?>
1 change: 1 addition & 0 deletions public/include/config/error_codes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
$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';
?>
7 changes: 7 additions & 0 deletions public/include/config/global.inc.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
45 changes: 45 additions & 0 deletions public/include/pages/admin/dashboard.inc.php
Original file line number Diff line number Diff line change
@@ -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");
?>
24 changes: 24 additions & 0 deletions public/include/version.inc.php
Original file line number Diff line number Diff line change
@@ -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);
}
66 changes: 66 additions & 0 deletions public/templates/mpos/admin/dashboard/default.tpl
Original file line number Diff line number Diff line change
@@ -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}
1 change: 1 addition & 0 deletions public/templates/mpos/global/navigation.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions sql/000_base_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ CREATE TABLE IF NOT EXISTS `notification_settings` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.1');

CREATE TABLE IF NOT EXISTS `payouts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_id` int(11) NOT NULL,
Expand Down
2 changes: 2 additions & 0 deletions sql/012_db_version.sql
Original file line number Diff line number Diff line change
@@ -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;