From 420ae332b5985f9f3f6651309e195d78ac253f23 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:08:33 +0200 Subject: [PATCH 01/20] Add detailed smarty cache documentation to config Instead of just making it availble document the smarty cache feature. It might work for users, but it's advised to rely on the memcache instead. Fixes #309 --- public/include/config/global.inc.dist.php | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index c5a298c7..5778f2c5 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -258,8 +258,30 @@ $config['cookie']['path'] = '/'; $config['cookie']['name'] = 'POOLERCOOKIE'; $config['cookie']['domain'] = ''; -// Disable or enable smarty cache -// This is usually not required, default: 0 + +/** + * Enable or disable the Smarty cache + * + * Explanation: + * Smarty implements a file based cache for all HTML output generated + * from dynamic scripts. It can be enabled to cache the HTML data on disk, + * future request are served from those cache files. + * + * This may or may not work as expected, in general Memcache is used to cache + * all data so rendering the page should not take too long anyway. + * + * You can test this out and enable (1) this setting but it's not guaranteed to + * work with mmcfe-ng. + * + * Ensure that the folder `templates/cache` is writable by the webserver! + * + * Options: + * 0 = disabled + * 1 = enabled + * + * Default: + * 0 = disabled + **/ $config['cache'] = 0; ?> From 3449d5c29c6d05c893ac66dca2440b5aa5d2dcf0 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:30:07 +0200 Subject: [PATCH 02/20] Adding cache lifetime option to smarty config * Renamed configuration array to `smarty` => `cache` * Added `smarty` => `cache_lifetime` to expire cache files properly This should be safe to use, be aware that each page request is cached! That includes any POST/GET calls to the site. It does help in speeding up the site, up to 100% on some requests. For a high traffic site it probably makes sense to enable this option with a low cache lifetime to ensure most recent data. Addresses #309 --- .gitignore | 1 + public/include/config/global.inc.dist.php | 21 ++++++++++++++------- public/include/smarty.inc.php | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 66b6c501..a8f1b1ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /public/include/config/global.inc.php /public/templates/compile/*.php /cronjobs/logs/*.txt +/public/templates/cache/*.php diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 5778f2c5..8e502ed1 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -275,13 +275,20 @@ $config['cookie']['domain'] = ''; * * Ensure that the folder `templates/cache` is writable by the webserver! * - * Options: - * 0 = disabled - * 1 = enabled + * cache = Enable/Disable the cache + * cache_lifetime = Time to keep files in seconds before updating them * - * Default: - * 0 = disabled + * Options: + * cache: + * 0 = disabled + * 1 = enabled + * cache_lifetime: + * time in seconds + * + * Defaults: + * cache = 0, disabled + * cache_lifetime = 30 seconds **/ -$config['cache'] = 0; - +$config['smarty']['cache'] = 1; +$config['smarty']['cache_lifetime'] = 30; ?> diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index 8a320581..46a38750 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -20,6 +20,7 @@ $smarty->template_dir = BASEPATH . 'templates/' . THEME . '/'; $smarty->compile_dir = BASEPATH . 'templates/compile/'; // Optional smarty caching, check Smarty documentation for details -$smarty->caching = $config['cache']; +$smarty->caching = $config['smarty']['cache']; +$smarty->cache_lifetime = $config['smarty']['cache_lifetime']; $smarty->cache_dir = BASEPATH . "templates/cache"; ?> From da0ab75d5de348040e79ecf1d96dca957ff7f9a3 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 4 Jul 2013 08:48:19 +0200 Subject: [PATCH 03/20] adjust smarty configurations --- public/include/smarty.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index 46a38750..e42e56e3 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -20,7 +20,10 @@ $smarty->template_dir = BASEPATH . 'templates/' . THEME . '/'; $smarty->compile_dir = BASEPATH . 'templates/compile/'; // Optional smarty caching, check Smarty documentation for details -$smarty->caching = $config['smarty']['cache']; -$smarty->cache_lifetime = $config['smarty']['cache_lifetime']; -$smarty->cache_dir = BASEPATH . "templates/cache"; +if ($config['smarty']['cache']) { + $debug->append('Enable smarty cache'); + $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); + $smarty->cache_lifetime = $config['smarty']['cache_lifetime']; + $smarty->cache_dir = BASEPATH . "templates/cache"; +} ?> From 87ecfc55981bd783a54804179f85ac8d728a5de2 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:08:33 +0200 Subject: [PATCH 04/20] Add detailed smarty cache documentation to config Instead of just making it availble document the smarty cache feature. It might work for users, but it's advised to rely on the memcache instead. Fixes #309 --- public/include/config/global.inc.dist.php | 1 - 1 file changed, 1 deletion(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 8e502ed1..e335405c 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -258,7 +258,6 @@ $config['cookie']['path'] = '/'; $config['cookie']['name'] = 'POOLERCOOKIE'; $config['cookie']['domain'] = ''; - /** * Enable or disable the Smarty cache * From 9aeb0052014cd72871b454f63995eda80e8748df Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 6 Jul 2013 18:10:23 +0200 Subject: [PATCH 05/20] Adding `{nocache}` flags for dynamic content This will update content instantly once the user changes it and not load a cached version from the smarty cache. Addresses #309 --- public/templates/mmcFE/account/edit/default.tpl | 10 +++++----- .../templates/mmcFE/account/notifications/default.tpl | 8 ++++---- public/templates/mmcFE/account/workers/default.tpl | 2 ++ public/templates/mmcFE/admin/news/default.tpl | 2 ++ public/templates/mmcFE/admin/news_edit/default.tpl | 6 +++--- public/templates/mmcFE/admin/settings/default.tpl | 4 ++-- public/templates/mmcFE/admin/user/default.tpl | 2 ++ 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/public/templates/mmcFE/account/edit/default.tpl b/public/templates/mmcFE/account/edit/default.tpl index 482c3579..c15b56d4 100644 --- a/public/templates/mmcFE/account/edit/default.tpl +++ b/public/templates/mmcFE/account/edit/default.tpl @@ -7,9 +7,9 @@ Username: {$GLOBAL.userdata.username} User Id: {$GLOBAL.userdata.id} API Key: {$GLOBAL.userdata.api_key} - E-Mail: - Payment Address: - Donation %: [donation amount in percent (example: 0.5)] + E-Mail: + Payment Address: + Donation %: [donation amount in percent (example: 0.5)] Automatic Payout Threshold: [{$GLOBAL.config.ap_threshold.min}-{$GLOBAL.config.ap_threshold.max} {$GLOBAL.config.currency}. Set to '0' for no auto payout] 4 digit PIN: [The 4 digit PIN you chose when registering] @@ -23,8 +23,8 @@ - - + +
Account Balance:    {$GLOBAL.userdata.balance.confirmed|escape} {$GLOBAL.config.currency}
Payout to:
{$GLOBAL.userdata.coin_address|escape}
Account Balance:    {nocache}{$GLOBAL.userdata.balance.confirmed|escape}{/nocache} {$GLOBAL.config.currency}
Payout to:
{nocache}{$GLOBAL.userdata.coin_address|escape}{/nocache}
4 digit PIN:
diff --git a/public/templates/mmcFE/account/notifications/default.tpl b/public/templates/mmcFE/account/notifications/default.tpl index 1d54729b..52140466 100644 --- a/public/templates/mmcFE/account/notifications/default.tpl +++ b/public/templates/mmcFE/account/notifications/default.tpl @@ -12,7 +12,7 @@ IDLE Worker - + @@ -20,7 +20,7 @@ New Blocks - + @@ -28,7 +28,7 @@ Auto Payout - + @@ -36,7 +36,7 @@ Manual Payout - + diff --git a/public/templates/mmcFE/account/workers/default.tpl b/public/templates/mmcFE/account/workers/default.tpl index c69d1139..f26e3109 100644 --- a/public/templates/mmcFE/account/workers/default.tpl +++ b/public/templates/mmcFE/account/workers/default.tpl @@ -15,6 +15,7 @@     + {nocache} {section worker $WORKERS} {assign var="username" value="."|escape|explode:$WORKERS[worker].username:2} @@ -29,6 +30,7 @@ {/section} + {/nocache} diff --git a/public/templates/mmcFE/admin/news/default.tpl b/public/templates/mmcFE/admin/news/default.tpl index 7bd8c198..8c3ac5d1 100644 --- a/public/templates/mmcFE/admin/news/default.tpl +++ b/public/templates/mmcFE/admin/news/default.tpl @@ -17,6 +17,7 @@ {include file="global/block_footer.tpl"} +{nocache} {section name=news loop=$NEWS} {include file="global/block_header.tpl" @@ -35,4 +36,5 @@ {include file="global/block_footer.tpl"} {/section} +{/nocache} {include file="global/block_footer.tpl"} diff --git a/public/templates/mmcFE/admin/news_edit/default.tpl b/public/templates/mmcFE/admin/news_edit/default.tpl index 467d4a6c..22e945fb 100644 --- a/public/templates/mmcFE/admin/news_edit/default.tpl +++ b/public/templates/mmcFE/admin/news_edit/default.tpl @@ -10,7 +10,7 @@ Active - + @@ -18,13 +18,13 @@ Header - + Content - + diff --git a/public/templates/mmcFE/admin/settings/default.tpl b/public/templates/mmcFE/admin/settings/default.tpl index 3cd67f4e..a2ffbd5b 100644 --- a/public/templates/mmcFE/admin/settings/default.tpl +++ b/public/templates/mmcFE/admin/settings/default.tpl @@ -16,7 +16,7 @@ @@ -26,7 +26,7 @@ diff --git a/public/templates/mmcFE/admin/user/default.tpl b/public/templates/mmcFE/admin/user/default.tpl index 82955741..8c65c49f 100644 --- a/public/templates/mmcFE/admin/user/default.tpl +++ b/public/templates/mmcFE/admin/user/default.tpl @@ -44,6 +44,7 @@ +{nocache} {section name=user loop=$USERS|default} {$USERS[user].id} @@ -70,6 +71,7 @@ {/section} +{/nocache} From 4ea33a5e50a08bf0daa6b285bc06e37d9b87efa1 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 6 Jul 2013 18:36:11 +0200 Subject: [PATCH 06/20] Adding cache detection to many pages This will allow pages to skip loading data from backends like the database or the wallet RPC server. If a cached page is detected and valid, all dynamic content generation will be skipped completely. Other pages that have not been adjusted in this commit will still fetch backend data all the time. This will ensure clients always see the most recent data, like worker information or account changes. This should fix #309 completely but needs some testing. --- .../include/pages/admin/transactions.inc.php | 16 +- public/include/pages/admin/wallet.inc.php | 17 +- public/include/pages/home.inc.php | 17 +- public/include/pages/statistics.inc.php | 26 ++- .../include/pages/statistics/blocks.inc.php | 17 +- .../include/pages/statistics/graphs.inc.php | 19 +- public/include/pages/statistics/pool.inc.php | 97 ++++---- public/include/smarty_globals.inc.php | 209 +++++++++--------- public/templates/mmcFE/master.tpl | 2 +- 9 files changed, 234 insertions(+), 186 deletions(-) diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index 00345903..b25d6f15 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -2,10 +2,20 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); -if ($user->isAuthenticated()) { + +// 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 (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); - $smarty->assign('TRANSACTIONS', $aTransactions); - $smarty->assign('CONTENT', 'default.tpl'); +} else { + $debug->append('Using cached page', 3); } +$smarty->assign('TRANSACTIONS', $aTransactions); +$smarty->assign('CONTENT', 'default.tpl'); ?> diff --git a/public/include/pages/admin/wallet.inc.php b/public/include/pages/admin/wallet.inc.php index 479ff919..d0642b14 100644 --- a/public/include/pages/admin/wallet.inc.php +++ b/public/include/pages/admin/wallet.inc.php @@ -9,15 +9,22 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { die("404 Page not found"); } -if ($bitcoin->can_connect() === true){ - $dBalance = $bitcoin->query('getbalance'); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($bitcoin->can_connect() === true){ + $dBalance = $bitcoin->query('getbalance'); + } else { + $dBalance = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + // Fetch locked balance from transactions + $dLockedBalance = $transaction->getLockedBalance(); } else { - $dBalance = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } $smarty->assign("BALANCE", $dBalance); -$smarty->assign("LOCKED", $transaction->getLockedBalance()); +$smarty->assign("LOCKED", $dLockedBalance); // Tempalte specifics $smarty->assign("CONTENT", "default.tpl"); diff --git a/public/include/pages/home.inc.php b/public/include/pages/home.inc.php index ea4bd8fb..ac7b458e 100644 --- a/public/include/pages/home.inc.php +++ b/public/include/pages/home.inc.php @@ -6,13 +6,18 @@ if (!defined('SECURITY')) die('Hacking attempt'); // Include markdown library use \Michelf\Markdown; -// Fetch active news to display -$aNews = $news->getAllActive(); -if (is_array($aNews)) { - foreach ($aNews as $key => $aData) { - // Transform Markdown content to HTML - $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Fetch active news to display + $aNews = $news->getAllActive(); + if (is_array($aNews)) { + foreach ($aNews as $key => $aData) { + // Transform Markdown content to HTML + $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); + } } +} else { + $debug->append('Using cached page', 3); } // Load news entries for Desktop site and unauthenticated users diff --git a/public/include/pages/statistics.inc.php b/public/include/pages/statistics.inc.php index dc27fde6..c5035f0c 100644 --- a/public/include/pages/statistics.inc.php +++ b/public/include/pages/statistics.inc.php @@ -4,17 +4,23 @@ if (!defined('SECURITY')) die('Hacking attempt'); -if ($bitcoin->can_connect() === true){ - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - $iBlock = $bitcoin->query('getblockcount'); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($bitcoin->can_connect() === true){ + $dDifficulty = $bitcoin->query('getdifficulty'); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + $iBlock = $bitcoin->query('getblockcount'); + } else { + $dDifficulty = 1; + $iBlock = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + $smarty->assign("CURRENTBLOCK", $iBlock); + $smarty->assign("DIFFICULTY", $dDifficulty); } else { - $dDifficulty = 1; - $iBlock = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } -$smarty->assign("CURRENTBLOCK", $iBlock); -$smarty->assign("DIFFICULTY", $dDifficulty); $smarty->assign("CONTENT", "default.tpl"); +?> diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php index 6c3b00b8..115dfb5b 100644 --- a/public/include/pages/statistics/blocks.inc.php +++ b/public/include/pages/statistics/blocks.inc.php @@ -5,12 +5,19 @@ if (!defined('SECURITY')) die('Hacking attempt'); if (!$user->isAuthenticated()) header("Location: index.php?page=home"); // Grab the last blocks found -$iLimit = 20; -$aBlocksFoundData = $statistics->getBlocksFound($iLimit); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Grab the last blocks found + $iLimit = 20; + $aBlocksFoundData = $statistics->getBlocksFound($iLimit); -// Propagate content our template -$smarty->assign("BLOCKSFOUND", $aBlocksFoundData); -$smarty->assign("BLOCKLIMIT", $iLimit); + // Propagate content our template + $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); + $smarty->assign("BLOCKLIMIT", $iLimit); + +} else { + $debug->append('Using cached page', 3); +} $smarty->assign("CONTENT", "default.tpl"); ?> diff --git a/public/include/pages/statistics/graphs.inc.php b/public/include/pages/statistics/graphs.inc.php index f7016835..4d31aadb 100644 --- a/public/include/pages/statistics/graphs.inc.php +++ b/public/include/pages/statistics/graphs.inc.php @@ -1,16 +1,19 @@ isAuthenticated()) { - $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); - $aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool(); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($user->isAuthenticated()) { + $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); + $aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool(); + } + $smarty->assign("YOURHASHRATES", @$aHourlyHashRates); + $smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates); +} else { + $debug->append('Using cached page', 3); } -// Propagate content our template -$smarty->assign("YOURHASHRATES", @$aHourlyHashRates); -$smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates); $smarty->assign("CONTENT", "default.tpl"); ?> diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 1cab1009..1e79658c 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -4,55 +4,60 @@ if (!defined('SECURITY')) die('Hacking attempt'); -// Fetch data from wallet -if ($bitcoin->can_connect() === true){ - $dDifficulty = $bitcoin->getdifficulty(); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - $iBlock = $bitcoin->getblockcount(); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Fetch data from wallet + if ($bitcoin->can_connect() === true){ + $dDifficulty = $bitcoin->getdifficulty(); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + $iBlock = $bitcoin->getblockcount(); + } else { + $dDifficulty = 1; + $iBlock = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + + // Top share contributors + $aContributorsShares = $statistics->getTopContributors('shares', 15); + + // Top hash contributors + $aContributorsHashes = $statistics->getTopContributors('hashes', 15); + + // Grab the last 10 blocks found + $iLimit = 5; + $aBlocksFoundData = $statistics->getBlocksFound($iLimit); + count($aBlocksFoundData) > 0 ? $aBlockData = $aBlocksFoundData[0] : $aBlockData = array(); + + // Estimated time to find the next block + $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); + + // Time in seconds, not hours, using modifier in smarty to translate + $iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0; + + // Time since last block + $now = new DateTime( "now" ); + if (!empty($aBlockData)) { + $dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']); + } else { + $dTimeSinceLast = 0; + } + + // Propagate content our template + $smarty->assign("ESTTIME", $iEstTime); + $smarty->assign("TIMESINCELAST", $dTimeSinceLast); + $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); + $smarty->assign("BLOCKLIMIT", $iLimit); + $smarty->assign("CONTRIBSHARES", $aContributorsShares); + $smarty->assign("CONTRIBHASHES", $aContributorsHashes); + $smarty->assign("CURRENTBLOCK", $iBlock); + count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0); + $smarty->assign("DIFFICULTY", $dDifficulty); + $smarty->assign("REWARD", $config['reward']); } else { - $dDifficulty = 1; - $iBlock = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } -// Top share contributors -$aContributorsShares = $statistics->getTopContributors('shares', 15); - -// Top hash contributors -$aContributorsHashes = $statistics->getTopContributors('hashes', 15); - -// Grab the last 10 blocks found -$iLimit = 5; -$aBlocksFoundData = $statistics->getBlocksFound($iLimit); -count($aBlocksFoundData) > 0 ? $aBlockData = $aBlocksFoundData[0] : $aBlockData = array(); - -// Estimated time to find the next block -$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); - -// Time in seconds, not hours, using modifier in smarty to translate -$iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0; - -// Time since last block -$now = new DateTime( "now" ); -if (!empty($aBlockData)) { - $dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']); -} else { - $dTimeSinceLast = 0; -} - -// Propagate content our template -$smarty->assign("ESTTIME", $iEstTime); -$smarty->assign("TIMESINCELAST", $dTimeSinceLast); -$smarty->assign("BLOCKSFOUND", $aBlocksFoundData); -$smarty->assign("BLOCKLIMIT", $iLimit); -$smarty->assign("CONTRIBSHARES", $aContributorsShares); -$smarty->assign("CONTRIBHASHES", $aContributorsHashes); -$smarty->assign("CURRENTBLOCK", $iBlock); -count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0); -$smarty->assign("DIFFICULTY", $dDifficulty); -$smarty->assign("REWARD", $config['reward']); - if ($user->isAuthenticated()) { $smarty->assign("CONTENT", "authenticated.tpl"); } else { diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 147b38e9..0f1e2896 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -7,111 +7,116 @@ if (!defined('SECURITY')) // Globally available variables $debug->append('Global smarty variables', 3); -// Defaults to get rid of PHP Notice warnings -$dDifficulty = 1; -$aRoundShares = 1; +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached page detected, loading smarty globals', 3); + // Defaults to get rid of PHP Notice warnings + $dDifficulty = 1; + $aRoundShares = 1; -// Only run these if the user is logged in -if (@$_SESSION['AUTHENTICATED']) { - $aRoundShares = $statistics->getRoundShares(); - if ($bitcoin->can_connect() === true) { - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - } -} -// Always fetch this since we need for ministats header -$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; - -// Fetch some data -$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); -$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); -$iCurrentPoolShareRate = $statistics->getCurrentShareRate(); - -// Avoid confusion, ensure our nethash isn't higher than poolhash -if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; - -// Global data for Smarty -$aGlobal = array( - 'slogan' => $config['website']['slogan'], - 'websitename' => $config['website']['name'], - 'hashrate' => $iCurrentPoolHashrate, - 'nethashrate' => $dNetworkHashrate, - 'sharerate' => $iCurrentPoolShareRate, - 'workers' => $iCurrentActiveWorkers, - 'roundshares' => $aRoundShares, - 'fees' => $config['fees'], - 'confirmations' => $config['confirmations'], - 'reward' => $config['reward'], - 'price' => $setting->getValue('price'), - 'blockexplorer' => $config['blockexplorer'], - 'chaininfo' => $config['chaininfo'], - 'config' => array( - 'website' => array( 'title' => $config['website']['title'] ), - 'price' => array( 'currency' => $config['price']['currency'] ), - 'targetdiff' => $config['difficulty'], - 'currency' => $config['currency'], - 'txfee' => $config['txfee'], - 'payout_system' => $config['payout_system'], - 'ap_threshold' => array( - 'min' => $config['ap_threshold']['min'], - 'max' => $config['ap_threshold']['max'] - ) - ) -); - -// Special calculations for PPS Values based on reward_type setting and/or available blocks -if ($config['reward_type'] != 'block') { - $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); -} else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } else { - $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } -} - -// We don't want these session infos cached -if (@$_SESSION['USERDATA']['id']) { - $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); - $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); - - // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); - - switch ($config['payout_system']) { - case 'pps': - break; - default: - // Some estimations - if (@$aRoundShares['valid'] > 0) { - $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); - $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); - $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); - $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); - } else { - $aGlobal['userdata']['est_block'] = 0; - $aGlobal['userdata']['est_fee'] = 0; - $aGlobal['userdata']['est_donation'] = 0; - $aGlobal['userdata']['est_payout'] = 0; + // Only run these if the user is logged in + if (@$_SESSION['AUTHENTICATED']) { + $aRoundShares = $statistics->getRoundShares(); + if ($bitcoin->can_connect() === true) { + $dDifficulty = $bitcoin->query('getdifficulty'); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + } + } + // Always fetch this since we need for ministats header + $bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; + + // Fetch some data + $iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); + $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); + $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); + + // Avoid confusion, ensure our nethash isn't higher than poolhash + if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; + + // Global data for Smarty + $aGlobal = array( + 'slogan' => $config['website']['slogan'], + 'websitename' => $config['website']['name'], + 'hashrate' => $iCurrentPoolHashrate, + 'nethashrate' => $dNetworkHashrate, + 'sharerate' => $iCurrentPoolShareRate, + 'workers' => $iCurrentActiveWorkers, + 'roundshares' => $aRoundShares, + 'fees' => $config['fees'], + 'confirmations' => $config['confirmations'], + 'reward' => $config['reward'], + 'price' => $setting->getValue('price'), + 'blockexplorer' => $config['blockexplorer'], + 'chaininfo' => $config['chaininfo'], + 'config' => array( + 'website' => array( 'title' => $config['website']['title'] ), + 'price' => array( 'currency' => $config['price']['currency'] ), + 'targetdiff' => $config['difficulty'], + 'currency' => $config['currency'], + 'txfee' => $config['txfee'], + 'payout_system' => $config['payout_system'], + 'ap_threshold' => array( + 'min' => $config['ap_threshold']['min'], + 'max' => $config['ap_threshold']['max'] + ) + ) + ); + + // Special calculations for PPS Values based on reward_type setting and/or available blocks + if ($config['reward_type'] != 'block') { + $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } else { + // Try to find the last block value and use that for future payouts, revert to fixed reward if none found + if ($aLastBlock = $block->getLast()) { + $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } else { + $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); } - break; } - // Site-wide notifications, based on user events - if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded the pools configured ' . $config['currency'] . ' warning threshold. Please initiate a transfer!', 'TYPE' => 'warning'); - if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); + // We don't want these session infos cached + if (@$_SESSION['USERDATA']['id']) { + $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); + $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); + + // Other userdata that we can cache savely + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); + + switch ($config['payout_system']) { + case 'pps': + break; + default: + // Some estimations + if (@$aRoundShares['valid'] > 0) { + $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); + $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); + $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); + $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); + } else { + $aGlobal['userdata']['est_block'] = 0; + $aGlobal['userdata']['est_fee'] = 0; + $aGlobal['userdata']['est_donation'] = 0; + $aGlobal['userdata']['est_payout'] = 0; + } + break; + } + + // Site-wide notifications, based on user events + if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); + if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); + } + + if ($setting->getValue('maintenance')) + $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); + + // Make it available in Smarty + $smarty->assign('PATH', 'site_assets/' . THEME); + $smarty->assign('GLOBAL', $aGlobal); +} else { + $debug->append('We found a cached page, not loaded smarty globals', 3); } - -if ($setting->getValue('maintenance')) - $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); - -// Make it available in Smarty -$smarty->assign('PATH', 'site_assets/' . THEME); -$smarty->assign('GLOBAL', $aGlobal); ?> diff --git a/public/templates/mmcFE/master.tpl b/public/templates/mmcFE/master.tpl index f476f747..68777d1a 100644 --- a/public/templates/mmcFE/master.tpl +++ b/public/templates/mmcFE/master.tpl @@ -69,7 +69,7 @@
- {include file="system/debugger.tpl"} + {nocache}{include file="system/debugger.tpl"}{/nocache}
From bb0e9dff3915c3db9f109b74304d6b5ccf234c62 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 8 Jul 2013 14:16:45 +0200 Subject: [PATCH 07/20] disable smarty cache by default in dist --- public/include/config/global.inc.dist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index e335405c..49692646 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -288,6 +288,6 @@ $config['cookie']['domain'] = ''; * cache = 0, disabled * cache_lifetime = 30 seconds **/ -$config['smarty']['cache'] = 1; +$config['smarty']['cache'] = 0; $config['smarty']['cache_lifetime'] = 30; ?> From d25387f0b597923ff4e8b7b71943c84279535c72 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 8 Jul 2013 14:16:52 +0200 Subject: [PATCH 08/20] Disable caching check on Smarty globals This will ensure data is available for those pages relying on global data. A better step might be to load template specific data always on the pages that require the data instead of relying on global data to be available. Fixes #309 --- public/include/smarty_globals.inc.php | 216 +++++++++++++------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 0f1e2896..8f543699 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -2,121 +2,117 @@ // Make sure we are called from index.php if (!defined('SECURITY')) - die('Hacking attempt'); + die('Hacking attempt'); // Globally available variables $debug->append('Global smarty variables', 3); -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { - $debug->append('No cached page detected, loading smarty globals', 3); - // Defaults to get rid of PHP Notice warnings - $dDifficulty = 1; - $aRoundShares = 1; +$debug->append('No cached page detected, loading smarty globals', 3); +// Defaults to get rid of PHP Notice warnings +$dDifficulty = 1; +$aRoundShares = 1; - // Only run these if the user is logged in - if (@$_SESSION['AUTHENTICATED']) { - $aRoundShares = $statistics->getRoundShares(); - if ($bitcoin->can_connect() === true) { - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - } +// Only run these if the user is logged in +if (@$_SESSION['AUTHENTICATED']) { + $aRoundShares = $statistics->getRoundShares(); + if ($bitcoin->can_connect() === true) { + $dDifficulty = $bitcoin->query('getdifficulty'); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; } - // Always fetch this since we need for ministats header - $bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; - - // Fetch some data - $iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); - $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); - $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); - - // Avoid confusion, ensure our nethash isn't higher than poolhash - if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; - - // Global data for Smarty - $aGlobal = array( - 'slogan' => $config['website']['slogan'], - 'websitename' => $config['website']['name'], - 'hashrate' => $iCurrentPoolHashrate, - 'nethashrate' => $dNetworkHashrate, - 'sharerate' => $iCurrentPoolShareRate, - 'workers' => $iCurrentActiveWorkers, - 'roundshares' => $aRoundShares, - 'fees' => $config['fees'], - 'confirmations' => $config['confirmations'], - 'reward' => $config['reward'], - 'price' => $setting->getValue('price'), - 'blockexplorer' => $config['blockexplorer'], - 'chaininfo' => $config['chaininfo'], - 'config' => array( - 'website' => array( 'title' => $config['website']['title'] ), - 'price' => array( 'currency' => $config['price']['currency'] ), - 'targetdiff' => $config['difficulty'], - 'currency' => $config['currency'], - 'txfee' => $config['txfee'], - 'payout_system' => $config['payout_system'], - 'ap_threshold' => array( - 'min' => $config['ap_threshold']['min'], - 'max' => $config['ap_threshold']['max'] - ) - ) - ); - - // Special calculations for PPS Values based on reward_type setting and/or available blocks - if ($config['reward_type'] != 'block') { - $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } else { - $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } - } - - // We don't want these session infos cached - if (@$_SESSION['USERDATA']['id']) { - $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); - $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); - - // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); - - switch ($config['payout_system']) { - case 'pps': - break; - default: - // Some estimations - if (@$aRoundShares['valid'] > 0) { - $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); - $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); - $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); - $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); - } else { - $aGlobal['userdata']['est_block'] = 0; - $aGlobal['userdata']['est_fee'] = 0; - $aGlobal['userdata']['est_donation'] = 0; - $aGlobal['userdata']['est_payout'] = 0; - } - break; - } - - // Site-wide notifications, based on user events - if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); - if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); - } - - if ($setting->getValue('maintenance')) - $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); - - // Make it available in Smarty - $smarty->assign('PATH', 'site_assets/' . THEME); - $smarty->assign('GLOBAL', $aGlobal); -} else { - $debug->append('We found a cached page, not loaded smarty globals', 3); } +// Always fetch this since we need for ministats header +$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; + +// Fetch some data +$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); +$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); +$iCurrentPoolShareRate = $statistics->getCurrentShareRate(); + +// Avoid confusion, ensure our nethash isn't higher than poolhash +if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; + +// Global data for Smarty +$aGlobal = array( + 'slogan' => $config['website']['slogan'], + 'websitename' => $config['website']['name'], + 'hashrate' => $iCurrentPoolHashrate, + 'nethashrate' => $dNetworkHashrate, + 'sharerate' => $iCurrentPoolShareRate, + 'workers' => $iCurrentActiveWorkers, + 'roundshares' => $aRoundShares, + 'fees' => $config['fees'], + 'confirmations' => $config['confirmations'], + 'reward' => $config['reward'], + 'price' => $setting->getValue('price'), + 'blockexplorer' => $config['blockexplorer'], + 'chaininfo' => $config['chaininfo'], + 'config' => array( + 'website' => array( 'title' => $config['website']['title'] ), + 'price' => array( 'currency' => $config['price']['currency'] ), + 'targetdiff' => $config['difficulty'], + 'currency' => $config['currency'], + 'txfee' => $config['txfee'], + 'payout_system' => $config['payout_system'], + 'ap_threshold' => array( + 'min' => $config['ap_threshold']['min'], + 'max' => $config['ap_threshold']['max'] + ) + ) +); + +// Special calculations for PPS Values based on reward_type setting and/or available blocks +if ($config['reward_type'] != 'block') { + $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); +} else { + // Try to find the last block value and use that for future payouts, revert to fixed reward if none found + if ($aLastBlock = $block->getLast()) { + $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } else { + $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } +} + +// We don't want these session infos cached +if (@$_SESSION['USERDATA']['id']) { + $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); + $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); + + // Other userdata that we can cache savely + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); + + switch ($config['payout_system']) { + case 'pps': + break; + default: + // Some estimations + if (@$aRoundShares['valid'] > 0) { + $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); + $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); + $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); + $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); + } else { + $aGlobal['userdata']['est_block'] = 0; + $aGlobal['userdata']['est_fee'] = 0; + $aGlobal['userdata']['est_donation'] = 0; + $aGlobal['userdata']['est_payout'] = 0; + } + break; + } + + // Site-wide notifications, based on user events + if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); + if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); +} + +if ($setting->getValue('maintenance')) + $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); + +// Make it available in Smarty +$smarty->assign('PATH', 'site_assets/' . THEME); +$smarty->assign('GLOBAL', $aGlobal); ?> From 4c531360c1e011e4f745feb1c8852d854c6c437e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 9 Jul 2013 08:54:20 +0200 Subject: [PATCH 09/20] fixing empty variable when using cache --- public/include/pages/home.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/pages/home.inc.php b/public/include/pages/home.inc.php index ac7b458e..9431e219 100644 --- a/public/include/pages/home.inc.php +++ b/public/include/pages/home.inc.php @@ -16,11 +16,11 @@ if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); } } + $smarty->assign("NEWS", $aNews); } else { $debug->append('Using cached page', 3); } // Load news entries for Desktop site and unauthenticated users -$smarty->assign("NEWS", $aNews); $smarty->assign("CONTENT", "default.tpl"); ?> From 6632920fa1ba4c0e37c2a50b98f5f1d9104ff2ed Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:08:33 +0200 Subject: [PATCH 10/20] Add detailed smarty cache documentation to config Instead of just making it availble document the smarty cache feature. It might work for users, but it's advised to rely on the memcache instead. Fixes #309 --- public/include/config/global.inc.dist.php | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index a57c1f22..8bff1114 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -341,8 +341,30 @@ $config['cookie']['path'] = '/'; $config['cookie']['name'] = 'POOLERCOOKIE'; $config['cookie']['domain'] = ''; -// Disable or enable smarty cache -// This is usually not required, default: 0 + +/** + * Enable or disable the Smarty cache + * + * Explanation: + * Smarty implements a file based cache for all HTML output generated + * from dynamic scripts. It can be enabled to cache the HTML data on disk, + * future request are served from those cache files. + * + * This may or may not work as expected, in general Memcache is used to cache + * all data so rendering the page should not take too long anyway. + * + * You can test this out and enable (1) this setting but it's not guaranteed to + * work with mmcfe-ng. + * + * Ensure that the folder `templates/cache` is writable by the webserver! + * + * Options: + * 0 = disabled + * 1 = enabled + * + * Default: + * 0 = disabled + **/ $config['cache'] = 0; ?> From e9311f08a53912ea8b2a491124345b5fa11ed1b1 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:30:07 +0200 Subject: [PATCH 11/20] Adding cache lifetime option to smarty config * Renamed configuration array to `smarty` => `cache` * Added `smarty` => `cache_lifetime` to expire cache files properly This should be safe to use, be aware that each page request is cached! That includes any POST/GET calls to the site. It does help in speeding up the site, up to 100% on some requests. For a high traffic site it probably makes sense to enable this option with a low cache lifetime to ensure most recent data. Addresses #309 --- .gitignore | 1 + public/include/config/global.inc.dist.php | 21 ++++++++++++++------- public/include/smarty.inc.php | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 66b6c501..a8f1b1ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /public/include/config/global.inc.php /public/templates/compile/*.php /cronjobs/logs/*.txt +/public/templates/cache/*.php diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 8bff1114..da41eb90 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -358,13 +358,20 @@ $config['cookie']['domain'] = ''; * * Ensure that the folder `templates/cache` is writable by the webserver! * - * Options: - * 0 = disabled - * 1 = enabled + * cache = Enable/Disable the cache + * cache_lifetime = Time to keep files in seconds before updating them * - * Default: - * 0 = disabled + * Options: + * cache: + * 0 = disabled + * 1 = enabled + * cache_lifetime: + * time in seconds + * + * Defaults: + * cache = 0, disabled + * cache_lifetime = 30 seconds **/ -$config['cache'] = 0; - +$config['smarty']['cache'] = 1; +$config['smarty']['cache_lifetime'] = 30; ?> diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index 8a320581..46a38750 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -20,6 +20,7 @@ $smarty->template_dir = BASEPATH . 'templates/' . THEME . '/'; $smarty->compile_dir = BASEPATH . 'templates/compile/'; // Optional smarty caching, check Smarty documentation for details -$smarty->caching = $config['cache']; +$smarty->caching = $config['smarty']['cache']; +$smarty->cache_lifetime = $config['smarty']['cache_lifetime']; $smarty->cache_dir = BASEPATH . "templates/cache"; ?> From 426268f71db7c5a10d685859592931c859cc5db6 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 4 Jul 2013 08:48:19 +0200 Subject: [PATCH 12/20] adjust smarty configurations --- public/include/smarty.inc.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/include/smarty.inc.php b/public/include/smarty.inc.php index 46a38750..e42e56e3 100644 --- a/public/include/smarty.inc.php +++ b/public/include/smarty.inc.php @@ -20,7 +20,10 @@ $smarty->template_dir = BASEPATH . 'templates/' . THEME . '/'; $smarty->compile_dir = BASEPATH . 'templates/compile/'; // Optional smarty caching, check Smarty documentation for details -$smarty->caching = $config['smarty']['cache']; -$smarty->cache_lifetime = $config['smarty']['cache_lifetime']; -$smarty->cache_dir = BASEPATH . "templates/cache"; +if ($config['smarty']['cache']) { + $debug->append('Enable smarty cache'); + $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); + $smarty->cache_lifetime = $config['smarty']['cache_lifetime']; + $smarty->cache_dir = BASEPATH . "templates/cache"; +} ?> From 0e6edc562c89361ed6348cf23f91b7e7aedb51a4 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 2 Jul 2013 14:08:33 +0200 Subject: [PATCH 13/20] Add detailed smarty cache documentation to config Instead of just making it availble document the smarty cache feature. It might work for users, but it's advised to rely on the memcache instead. Fixes #309 --- public/include/config/global.inc.dist.php | 1 - 1 file changed, 1 deletion(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index da41eb90..b0aa2f21 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -341,7 +341,6 @@ $config['cookie']['path'] = '/'; $config['cookie']['name'] = 'POOLERCOOKIE'; $config['cookie']['domain'] = ''; - /** * Enable or disable the Smarty cache * From 3c426e913b609b927c1d79cdf03941f24e19ca45 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 6 Jul 2013 18:10:23 +0200 Subject: [PATCH 14/20] Adding `{nocache}` flags for dynamic content This will update content instantly once the user changes it and not load a cached version from the smarty cache. Addresses #309 --- public/templates/mmcFE/account/edit/default.tpl | 10 +++++----- .../templates/mmcFE/account/notifications/default.tpl | 8 ++++---- public/templates/mmcFE/account/workers/default.tpl | 2 ++ public/templates/mmcFE/admin/news/default.tpl | 2 ++ public/templates/mmcFE/admin/news_edit/default.tpl | 6 +++--- public/templates/mmcFE/admin/settings/default.tpl | 4 ++-- public/templates/mmcFE/admin/user/default.tpl | 2 ++ 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/public/templates/mmcFE/account/edit/default.tpl b/public/templates/mmcFE/account/edit/default.tpl index 482c3579..c15b56d4 100644 --- a/public/templates/mmcFE/account/edit/default.tpl +++ b/public/templates/mmcFE/account/edit/default.tpl @@ -7,9 +7,9 @@ Username: {$GLOBAL.userdata.username} User Id: {$GLOBAL.userdata.id} API Key: {$GLOBAL.userdata.api_key} - E-Mail: - Payment Address: - Donation %: [donation amount in percent (example: 0.5)] + E-Mail: + Payment Address: + Donation %: [donation amount in percent (example: 0.5)] Automatic Payout Threshold: [{$GLOBAL.config.ap_threshold.min}-{$GLOBAL.config.ap_threshold.max} {$GLOBAL.config.currency}. Set to '0' for no auto payout] 4 digit PIN: [The 4 digit PIN you chose when registering] @@ -23,8 +23,8 @@ - - + +
Account Balance:    {$GLOBAL.userdata.balance.confirmed|escape} {$GLOBAL.config.currency}
Payout to:
{$GLOBAL.userdata.coin_address|escape}
Account Balance:    {nocache}{$GLOBAL.userdata.balance.confirmed|escape}{/nocache} {$GLOBAL.config.currency}
Payout to:
{nocache}{$GLOBAL.userdata.coin_address|escape}{/nocache}
4 digit PIN:
diff --git a/public/templates/mmcFE/account/notifications/default.tpl b/public/templates/mmcFE/account/notifications/default.tpl index 1d54729b..52140466 100644 --- a/public/templates/mmcFE/account/notifications/default.tpl +++ b/public/templates/mmcFE/account/notifications/default.tpl @@ -12,7 +12,7 @@ IDLE Worker - + @@ -20,7 +20,7 @@ New Blocks - + @@ -28,7 +28,7 @@ Auto Payout - + @@ -36,7 +36,7 @@ Manual Payout - + diff --git a/public/templates/mmcFE/account/workers/default.tpl b/public/templates/mmcFE/account/workers/default.tpl index c69d1139..f26e3109 100644 --- a/public/templates/mmcFE/account/workers/default.tpl +++ b/public/templates/mmcFE/account/workers/default.tpl @@ -15,6 +15,7 @@     + {nocache} {section worker $WORKERS} {assign var="username" value="."|escape|explode:$WORKERS[worker].username:2} @@ -29,6 +30,7 @@ {/section} + {/nocache} diff --git a/public/templates/mmcFE/admin/news/default.tpl b/public/templates/mmcFE/admin/news/default.tpl index 7bd8c198..8c3ac5d1 100644 --- a/public/templates/mmcFE/admin/news/default.tpl +++ b/public/templates/mmcFE/admin/news/default.tpl @@ -17,6 +17,7 @@ {include file="global/block_footer.tpl"} +{nocache} {section name=news loop=$NEWS} {include file="global/block_header.tpl" @@ -35,4 +36,5 @@ {include file="global/block_footer.tpl"} {/section} +{/nocache} {include file="global/block_footer.tpl"} diff --git a/public/templates/mmcFE/admin/news_edit/default.tpl b/public/templates/mmcFE/admin/news_edit/default.tpl index 467d4a6c..22e945fb 100644 --- a/public/templates/mmcFE/admin/news_edit/default.tpl +++ b/public/templates/mmcFE/admin/news_edit/default.tpl @@ -10,7 +10,7 @@ Active - + @@ -18,13 +18,13 @@ Header - + Content - + diff --git a/public/templates/mmcFE/admin/settings/default.tpl b/public/templates/mmcFE/admin/settings/default.tpl index 3cd67f4e..a2ffbd5b 100644 --- a/public/templates/mmcFE/admin/settings/default.tpl +++ b/public/templates/mmcFE/admin/settings/default.tpl @@ -16,7 +16,7 @@ @@ -26,7 +26,7 @@ diff --git a/public/templates/mmcFE/admin/user/default.tpl b/public/templates/mmcFE/admin/user/default.tpl index 82955741..8c65c49f 100644 --- a/public/templates/mmcFE/admin/user/default.tpl +++ b/public/templates/mmcFE/admin/user/default.tpl @@ -44,6 +44,7 @@ +{nocache} {section name=user loop=$USERS|default} {$USERS[user].id} @@ -70,6 +71,7 @@ {/section} +{/nocache} From bffeea07c93ced2830ed4cc1ed0e89b5de947352 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Sat, 6 Jul 2013 18:36:11 +0200 Subject: [PATCH 15/20] Adding cache detection to many pages This will allow pages to skip loading data from backends like the database or the wallet RPC server. If a cached page is detected and valid, all dynamic content generation will be skipped completely. Other pages that have not been adjusted in this commit will still fetch backend data all the time. This will ensure clients always see the most recent data, like worker information or account changes. This should fix #309 completely but needs some testing. --- .../include/pages/admin/transactions.inc.php | 16 ++- public/include/pages/admin/wallet.inc.php | 17 ++- public/include/pages/home.inc.php | 17 +-- public/include/pages/statistics.inc.php | 25 +++-- .../include/pages/statistics/blocks.inc.php | 17 ++- .../include/pages/statistics/graphs.inc.php | 19 ++-- public/include/pages/statistics/pool.inc.php | 101 +++++++++--------- public/include/smarty_globals.inc.php | 4 +- public/templates/mmcFE/master.tpl | 2 +- 9 files changed, 130 insertions(+), 88 deletions(-) diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index 00345903..b25d6f15 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -2,10 +2,20 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); -if ($user->isAuthenticated()) { + +// 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 (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); $aTransactions = $transaction->getAllTransactions(@$_REQUEST['start']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); - $smarty->assign('TRANSACTIONS', $aTransactions); - $smarty->assign('CONTENT', 'default.tpl'); +} else { + $debug->append('Using cached page', 3); } +$smarty->assign('TRANSACTIONS', $aTransactions); +$smarty->assign('CONTENT', 'default.tpl'); ?> diff --git a/public/include/pages/admin/wallet.inc.php b/public/include/pages/admin/wallet.inc.php index 479ff919..d0642b14 100644 --- a/public/include/pages/admin/wallet.inc.php +++ b/public/include/pages/admin/wallet.inc.php @@ -9,15 +9,22 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { die("404 Page not found"); } -if ($bitcoin->can_connect() === true){ - $dBalance = $bitcoin->query('getbalance'); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($bitcoin->can_connect() === true){ + $dBalance = $bitcoin->query('getbalance'); + } else { + $dBalance = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + // Fetch locked balance from transactions + $dLockedBalance = $transaction->getLockedBalance(); } else { - $dBalance = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } $smarty->assign("BALANCE", $dBalance); -$smarty->assign("LOCKED", $transaction->getLockedBalance()); +$smarty->assign("LOCKED", $dLockedBalance); // Tempalte specifics $smarty->assign("CONTENT", "default.tpl"); diff --git a/public/include/pages/home.inc.php b/public/include/pages/home.inc.php index ea4bd8fb..ac7b458e 100644 --- a/public/include/pages/home.inc.php +++ b/public/include/pages/home.inc.php @@ -6,13 +6,18 @@ if (!defined('SECURITY')) die('Hacking attempt'); // Include markdown library use \Michelf\Markdown; -// Fetch active news to display -$aNews = $news->getAllActive(); -if (is_array($aNews)) { - foreach ($aNews as $key => $aData) { - // Transform Markdown content to HTML - $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Fetch active news to display + $aNews = $news->getAllActive(); + if (is_array($aNews)) { + foreach ($aNews as $key => $aData) { + // Transform Markdown content to HTML + $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); + } } +} else { + $debug->append('Using cached page', 3); } // Load news entries for Desktop site and unauthenticated users diff --git a/public/include/pages/statistics.inc.php b/public/include/pages/statistics.inc.php index 3307dd21..c5035f0c 100644 --- a/public/include/pages/statistics.inc.php +++ b/public/include/pages/statistics.inc.php @@ -4,18 +4,23 @@ if (!defined('SECURITY')) die('Hacking attempt'); -if ($bitcoin->can_connect() === true){ - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - $iBlock = $bitcoin->query('getblockcount'); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($bitcoin->can_connect() === true){ + $dDifficulty = $bitcoin->query('getdifficulty'); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + $iBlock = $bitcoin->query('getblockcount'); + } else { + $dDifficulty = 1; + $iBlock = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + $smarty->assign("CURRENTBLOCK", $iBlock); + $smarty->assign("DIFFICULTY", $dDifficulty); } else { - $dDifficulty = 1; - $iBlock = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to litecoind RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } -$smarty->assign("CURRENTBLOCK", $iBlock); -$smarty->assign("DIFFICULTY", $dDifficulty); $smarty->assign("CONTENT", "default.tpl"); ?> diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php index 22eeadff..41e209cb 100644 --- a/public/include/pages/statistics/blocks.inc.php +++ b/public/include/pages/statistics/blocks.inc.php @@ -4,12 +4,19 @@ if (!defined('SECURITY')) die('Hacking attempt'); // Grab the last blocks found -$iLimit = 20; -$aBlocksFoundData = $statistics->getBlocksFound($iLimit); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Grab the last blocks found + $iLimit = 20; + $aBlocksFoundData = $statistics->getBlocksFound($iLimit); -// Propagate content our template -$smarty->assign("BLOCKSFOUND", $aBlocksFoundData); -$smarty->assign("BLOCKLIMIT", $iLimit); + // Propagate content our template + $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); + $smarty->assign("BLOCKLIMIT", $iLimit); + +} else { + $debug->append('Using cached page', 3); +} if ($config['website']['acl']['statistics']['blocks'] == 'public') { $smarty->assign("CONTENT", "default.tpl"); diff --git a/public/include/pages/statistics/graphs.inc.php b/public/include/pages/statistics/graphs.inc.php index f7016835..4d31aadb 100644 --- a/public/include/pages/statistics/graphs.inc.php +++ b/public/include/pages/statistics/graphs.inc.php @@ -1,16 +1,19 @@ isAuthenticated()) { - $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); - $aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool(); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + if ($user->isAuthenticated()) { + $aHourlyHashRates = $statistics->getHourlyHashrateByAccount($_SESSION['USERDATA']['id']); + $aPoolHourlyHashRates = $statistics->getHourlyHashrateByPool(); + } + $smarty->assign("YOURHASHRATES", @$aHourlyHashRates); + $smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates); +} else { + $debug->append('Using cached page', 3); } -// Propagate content our template -$smarty->assign("YOURHASHRATES", @$aHourlyHashRates); -$smarty->assign("POOLHASHRATES", @$aPoolHourlyHashRates); $smarty->assign("CONTENT", "default.tpl"); ?> diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 27395cc1..8386cb07 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -1,58 +1,63 @@ can_connect() === true){ - $dDifficulty = $bitcoin->getdifficulty(); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - $iBlock = $bitcoin->getblockcount(); +if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { + $debug->append('No cached version available, fetching from backend', 3); + // Fetch data from wallet + if ($bitcoin->can_connect() === true){ + $dDifficulty = $bitcoin->getdifficulty(); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + $iBlock = $bitcoin->getblockcount(); + } else { + $dDifficulty = 1; + $iBlock = 0; + $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + } + + // Top share contributors + $aContributorsShares = $statistics->getTopContributors('shares', 15); + + // Top hash contributors + $aContributorsHashes = $statistics->getTopContributors('hashes', 15); + + // Grab the last 10 blocks found + $iLimit = 5; + $aBlocksFoundData = $statistics->getBlocksFound($iLimit); + count($aBlocksFoundData) > 0 ? $aBlockData = $aBlocksFoundData[0] : $aBlockData = array(); + + // Estimated time to find the next block + $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); + + // Time in seconds, not hours, using modifier in smarty to translate + $iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0; + + // Time since last block + $now = new DateTime( "now" ); + if (!empty($aBlockData)) { + $dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']); + } else { + $dTimeSinceLast = 0; + } + + // Propagate content our template + $smarty->assign("ESTTIME", $iEstTime); + $smarty->assign("TIMESINCELAST", $dTimeSinceLast); + $smarty->assign("BLOCKSFOUND", $aBlocksFoundData); + $smarty->assign("BLOCKLIMIT", $iLimit); + $smarty->assign("CONTRIBSHARES", $aContributorsShares); + $smarty->assign("CONTRIBHASHES", $aContributorsHashes); + $smarty->assign("CURRENTBLOCK", $iBlock); + count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0); + $smarty->assign("DIFFICULTY", $dDifficulty); + $smarty->assign("REWARD", $config['reward']); } else { - $dDifficulty = 1; - $iBlock = 0; - $_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to wallet RPC service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg'); + $debug->append('Using cached page', 3); } -// Top share contributors -$aContributorsShares = $statistics->getTopContributors('shares', 15); - -// Top hash contributors -$aContributorsHashes = $statistics->getTopContributors('hashes', 15); - -// Grab the last 10 blocks found -$iLimit = 5; -$aBlocksFoundData = $statistics->getBlocksFound($iLimit); -count($aBlocksFoundData) > 0 ? $aBlockData = $aBlocksFoundData[0] : $aBlockData = array(); - -// Estimated time to find the next block -$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); - -// Time in seconds, not hours, using modifier in smarty to translate -$iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0; - -// Time since last block -$now = new DateTime( "now" ); -if (!empty($aBlockData)) { - $dTimeSinceLast = ($now->getTimestamp() - $aBlockData['time']); -} else { - $dTimeSinceLast = 0; -} - -// Propagate content our template -$smarty->assign("ESTTIME", $iEstTime); -$smarty->assign("TIMESINCELAST", $dTimeSinceLast); -$smarty->assign("BLOCKSFOUND", $aBlocksFoundData); -$smarty->assign("BLOCKLIMIT", $iLimit); -$smarty->assign("CONTRIBSHARES", $aContributorsShares); -$smarty->assign("CONTRIBHASHES", $aContributorsHashes); -$smarty->assign("CURRENTBLOCK", $iBlock); -count($aBlockData) > 0 ? $smarty->assign("LASTBLOCK", $aBlockData['height']) : $smarty->assign("LASTBLOCK", 0); -$smarty->assign("DIFFICULTY", $dDifficulty); -$smarty->assign("REWARD", $config['reward']); - +// Public / private page detection if ($config['website']['acl']['statistics']['pool'] == 'public') { $smarty->assign("CONTENT", "authenticated.tpl"); } else if ($user->isAuthenticated() && $config['website']['acl']['statistics']['pool'] == 'private') { diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index e83b1ca3..cbd369d3 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -2,7 +2,7 @@ // Make sure we are called from index.php if (!defined('SECURITY')) - die('Hacking attempt'); + die('Hacking attempt'); // Globally available variables $debug->append('Global smarty variables', 3); @@ -109,7 +109,7 @@ if (@$_SESSION['USERDATA']['id']) { // Site-wide notifications, based on user events if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded the pools configured ' . $config['currency'] . ' warning threshold. Please initiate a transfer!', 'TYPE' => 'warning'); + $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); } diff --git a/public/templates/mmcFE/master.tpl b/public/templates/mmcFE/master.tpl index f476f747..68777d1a 100644 --- a/public/templates/mmcFE/master.tpl +++ b/public/templates/mmcFE/master.tpl @@ -69,7 +69,7 @@
- {include file="system/debugger.tpl"} + {nocache}{include file="system/debugger.tpl"}{/nocache}
From e0275566ae3f8c2b83de98980ada6a5d5fb0442c Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 8 Jul 2013 14:16:45 +0200 Subject: [PATCH 16/20] disable smarty cache by default in dist --- public/include/config/global.inc.dist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index b0aa2f21..238654e7 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -371,6 +371,6 @@ $config['cookie']['domain'] = ''; * cache = 0, disabled * cache_lifetime = 30 seconds **/ -$config['smarty']['cache'] = 1; +$config['smarty']['cache'] = 0; $config['smarty']['cache_lifetime'] = 30; ?> From 65c6318b026a11845cc5b308dafd48f6fed83c41 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Tue, 9 Jul 2013 08:54:20 +0200 Subject: [PATCH 17/20] fixing empty variable when using cache --- public/include/pages/home.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/pages/home.inc.php b/public/include/pages/home.inc.php index ac7b458e..9431e219 100644 --- a/public/include/pages/home.inc.php +++ b/public/include/pages/home.inc.php @@ -16,11 +16,11 @@ if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { $aNews[$key]['content'] = Markdown::defaultTransform($aData['content']); } } + $smarty->assign("NEWS", $aNews); } else { $debug->append('Using cached page', 3); } // Load news entries for Desktop site and unauthenticated users -$smarty->assign("NEWS", $aNews); $smarty->assign("CONTENT", "default.tpl"); ?> From 17829cfd4ab146e34371b4a946092b201a6acfb9 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 11 Jul 2013 09:13:50 +0200 Subject: [PATCH 18/20] always assign default content --- public/include/pages/account/transactions.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/pages/account/transactions.inc.php b/public/include/pages/account/transactions.inc.php index db927ca7..7bcfb4f2 100644 --- a/public/include/pages/account/transactions.inc.php +++ b/public/include/pages/account/transactions.inc.php @@ -6,6 +6,6 @@ if ($user->isAuthenticated()) { $aTransactions = $transaction->getTransactions($_SESSION['USERDATA']['id']); if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg'); $smarty->assign('TRANSACTIONS', $aTransactions); - $smarty->assign('CONTENT', 'default.tpl'); } +$smarty->assign('CONTENT', 'default.tpl'); ?> From 39cfdc78e03c541bf3c3fab089708dacbbb3aaa7 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 11 Jul 2013 09:15:36 +0200 Subject: [PATCH 19/20] onliner security check --- public/include/smarty_globals.inc.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 82938ee2..a1e0eb19 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -1,8 +1,7 @@ append('Global smarty variables', 3); From 72d91ff6c3fb4ffc8c184ab83e9f6de2b99ace06 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 11 Jul 2013 09:16:31 +0200 Subject: [PATCH 20/20] adding proper account balance warning back in --- public/include/smarty_globals.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a1e0eb19..7219778c 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -109,7 +109,7 @@ if (@$_SESSION['USERDATA']['id']) { // Site-wide notifications, based on user events if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); + $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded the pools configured ' . $config['currency'] . ' warning threshold. Please initiate a transfer!', 'TYPE' => 'errormsg'); if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); }