From 2568ced4d4af38ce09df7b19d9d3f957e5c87dea Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sun, 5 Jan 2014 11:19:09 +0100 Subject: [PATCH 1/2] [INITIAL] Working version checks * Check DB structure version, config file version and MPOS core version * Added new Admin Dashboard to show this core information * Cronjobs will be disabled if SQL files are not imported * SQL files must re-set the db_upgrade_required setting * Cronjobs will disabled if config files are not updated * Simple config file update and version string update will fix this * Added MPOS status overview * Cronjobs and Wallet information for now, others may be added later * Added new navigation link for Admin Panel Dashboard * Added new version file * Will require updates whenever DB or configs are updated * Update SQL file that adds the DB_VERSION setting This will address #1242 and already includes a huge chunk of changes required to make this work. --- cronjobs/shared.inc.php | 6 ++ public/include/autoloader.inc.php | 3 + public/include/config/error_codes.inc.php | 1 + public/include/config/global.inc.dist.php | 7 ++ public/include/pages/admin/dashboard.inc.php | 45 +++++++++++++ public/include/version.inc.php | 24 +++++++ .../mpos/admin/dashboard/default.tpl | 66 +++++++++++++++++++ public/templates/mpos/global/navigation.tpl | 1 + sql/000_base_structure.sql | 2 + sql/012_db_version.sql | 2 + 10 files changed, 157 insertions(+) create mode 100644 public/include/pages/admin/dashboard.inc.php create mode 100644 public/include/version.inc.php create mode 100644 public/templates/mpos/admin/dashboard/default.tpl create mode 100644 sql/012_db_version.sql diff --git a/cronjobs/shared.inc.php b/cronjobs/shared.inc.php index 4d41a54e3..5368ecac6 100644 --- a/cronjobs/shared.inc.php +++ b/cronjobs/shared.inc.php @@ -64,6 +64,12 @@ $monitoring->endCronjob($cron_name, 'E0018', 1, true, false); } +// 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')) { + $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); +} + // Mark cron as running for monitoring $log->logDebug('Marking cronjob as running for monitoring'); $monitoring->setStatus($cron_name . '_starttime', 'date', time()); diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php index a46632231..c2d605fe0 100644 --- a/public/include/autoloader.inc.php +++ b/public/include/autoloader.inc.php @@ -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'); + ?> diff --git a/public/include/config/error_codes.inc.php b/public/include/config/error_codes.inc.php index f0979fc19..a157f14b0 100644 --- a/public/include/config/error_codes.inc.php +++ b/public/include/config/error_codes.inc.php @@ -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'; ?> diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index e4c690272..704d01ebf 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -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'); diff --git a/public/include/pages/admin/dashboard.inc.php b/public/include/pages/admin/dashboard.inc.php new file mode 100644 index 000000000..af32639a1 --- /dev/null +++ b/public/include/pages/admin/dashboard.inc.php @@ -0,0 +1,45 @@ +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"); +?> diff --git a/public/include/version.inc.php b/public/include/version.inc.php new file mode 100644 index 000000000..026707ea1 --- /dev/null +++ b/public/include/version.inc.php @@ -0,0 +1,24 @@ +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); +} diff --git a/public/templates/mpos/admin/dashboard/default.tpl b/public/templates/mpos/admin/dashboard/default.tpl new file mode 100644 index 000000000..2ac4b0a47 --- /dev/null +++ b/public/templates/mpos/admin/dashboard/default.tpl @@ -0,0 +1,66 @@ +{nocache} +
+

MPOS Version Information

+ + + + + + + + + + + + + + + + + + + + + + + + + +
ComponentCurrentInstalled
MPOS{$VERSION['CURRENT']['CORE']} + {$VERSION['INSTALLED']['CORE']} +
Config{$VERSION['CURRENT']['CONFIG']} + {$VERSION['INSTALLED']['CONFIG']} +
Database{$VERSION['CURRENT']['DB']} + {$VERSION['INSTALLED']['DB']} +
+
+
+

MPOS Status

+ + + + + + + + + + + + + + + + + + + +
CronjobsWallet
ErrorsDisabledErrors
+ {if $CRON_ERROR == 0}None - OK{else}{$CRON_ERROR}{/if} + + {if $CRON_DISABLED == 0}None - OK{else}{$CRON_DISABLED}{/if} + + {$WALLET_ERROR|default:"None - OK"} +
+
+{/nocache} diff --git a/public/templates/mpos/global/navigation.tpl b/public/templates/mpos/global/navigation.tpl index 588014992..fd2da85ad 100644 --- a/public/templates/mpos/global/navigation.tpl +++ b/public/templates/mpos/global/navigation.tpl @@ -16,6 +16,7 @@ {if $smarty.session.AUTHENTICATED|default:"0" == 1 && $GLOBAL.userdata.is_admin == 1}

Admin Panel