From ca427b414b4604c9d8812c5d31f0001e1cddf452 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 4 Dec 2013 09:54:11 +0100 Subject: [PATCH 1/2] [FEATURE] Disable Dashboard and Dashboard API Allows pools to disable the dashboard and dashboard API completely. Useful if you are not running a master/load(/load/load) setup to deal with frequent live queries. Fixes #876 once merged. --- public/include/config/admin_settings.inc.php | 14 +++++ .../pages/api/getdashboarddata.inc.php | 13 +++- public/include/pages/dashboard.inc.php | 38 +++++------- .../templates/mpos/dashboard/account_data.tpl | 8 ++- public/templates/mpos/dashboard/default.tpl | 6 +- .../mpos/dashboard/{js.tpl => js_api.tpl} | 0 public/templates/mpos/dashboard/js_static.tpl | 62 +++++++++++++++++++ .../templates/mpos/dashboard/network_info.tpl | 4 +- public/templates/mpos/dashboard/overview.tpl | 2 + .../mpos/dashboard/payout_estimates.tpl | 8 +-- .../templates/mpos/dashboard/round_shares.tpl | 10 +-- .../templates/mpos/dashboard/system_stats.tpl | 2 +- 12 files changed, 127 insertions(+), 40 deletions(-) rename public/templates/mpos/dashboard/{js.tpl => js_api.tpl} (100%) create mode 100644 public/templates/mpos/dashboard/js_static.tpl diff --git a/public/include/config/admin_settings.inc.php b/public/include/config/admin_settings.inc.php index 37769bd5..116a43bd 100644 --- a/public/include/config/admin_settings.inc.php +++ b/public/include/config/admin_settings.inc.php @@ -278,6 +278,20 @@ $aSettings['system'][] = array( 'name' => 'disable_about', 'value' => $setting->getValue('disable_about'), 'tooltip' => 'Showing About page in Navigation.' ); +$aSettings['system'][] = array( + 'display' => 'Disable Live Dashboard', 'type' => 'select', + 'options' => array( 0 => 'No', 1 => 'Yes'), + 'default' => 0, + 'name' => 'disable_dashboard', 'value' => $setting->getValue('disable_dashboard'), + 'tooltip' => 'Disable live updates on the dashboard to reduce server load.' +); +$aSettings['system'][] = array( + 'display' => 'Disable Dashboard API', 'type' => 'select', + 'options' => array( 0 => 'No', 1 => 'Yes'), + 'default' => 0, + 'name' => 'disable_dashboard_api', 'value' => $setting->getValue('disable_dashboard_api'), + 'tooltip' => 'Disable dashboard API entirely to reduce server load.' +); $aSettings['recaptcha'][] = array( 'display' => 'Enable re-Captcha', 'type' => 'select', 'options' => array( 0 => 'No', 1 => 'Yes' ), diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index c2e766f6..f1ed90c3 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -3,6 +3,15 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); +// Supress master template +$supress_master = 1; + +// Check if the system is enabled +if ($setting->getValue('disable_dashboard_api')) { + echo $api->get_json(array('error' => 'disabled')); + die(); +} + // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']); @@ -107,8 +116,6 @@ $data = array( ), 'network' => array( 'hashrate' => $dNetworkHashrateAdjusted, 'difficulty' => $dDifficulty, 'block' => $iBlock ), ); -echo $api->get_json($data); -// Supress master template -$supress_master = 1; +echo $api->get_json($data); ?> diff --git a/public/include/pages/dashboard.inc.php b/public/include/pages/dashboard.inc.php index 22a4edec..0b8796ac 100644 --- a/public/include/pages/dashboard.inc.php +++ b/public/include/pages/dashboard.inc.php @@ -9,32 +9,24 @@ if ($user->isAuthenticated()) { $dDifficulty = 1; $aRoundShares = 1; - // Only run these if the user is logged in $aRoundShares = $statistics->getRoundShares(); + $dDifficulty = 1; + $dNetworkHashrate = 1; + $iBlock = 0; 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 - $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']; - try { $dNetworkHashrate = $bitcoin->query('getnetworkhashps') / 1000; } catch (Exception $e) { - // Maybe we are SHA - try { $dNetworkHashrate = $bitcoin->query('gethashespersec') / 1000; } catch (Exception $e) { - $dNetworkHashrate = 0; - } - $dNetworkHashrate = 0; - } - } else { - $dNetworkHashrate = 0; + $dDifficulty = $bitcoin->getdifficulty(); + $dNetworkHashrate = $bitcoin->getnetworkhashps(); + $iBlock = $bitcoin->getblockcount(); } // Fetch some data + // Round progress + $iEstShares = $statistics->getEstimatedShares($dDifficulty); + if ($iEstShares > 0 && $aRoundShares['valid'] > 0) { + $dEstPercent = round(100 / $iEstShares * $aRoundShares['valid'], 2); + } else { + $dEstPercent = 0; + } if (!$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers()) $iCurrentActiveWorkers = 0; $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); @@ -43,6 +35,10 @@ if ($user->isAuthenticated()) { if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; // Make it available in Smarty + $smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard')); + $smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api')); + $smarty->assign('ESTIMATES', array('shares' => $iEstShares, 'percent' => $dEstPercent)); + $smarty->assign('NETWORK', array('difficulty' => $dDifficulty, 'block' => $iBlock)); $smarty->assign('INTERVAL', $interval / 60); $smarty->assign('CONTENT', 'default.tpl'); } diff --git a/public/templates/mpos/dashboard/account_data.tpl b/public/templates/mpos/dashboard/account_data.tpl index ce1bf20b..c03165c7 100644 --- a/public/templates/mpos/dashboard/account_data.tpl +++ b/public/templates/mpos/dashboard/account_data.tpl @@ -24,13 +24,14 @@ Confirmed - + {$GLOBAL.userdata.balance.confirmed} Unconfirmed - + {$GLOBAL.userdata.balance.unconfirmed} + {if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API} @@ -40,8 +41,9 @@ - +
Loading worker informationNo worker information available
+ {/if} diff --git a/public/templates/mpos/dashboard/default.tpl b/public/templates/mpos/dashboard/default.tpl index d12b4e1d..43e85d42 100644 --- a/public/templates/mpos/dashboard/default.tpl +++ b/public/templates/mpos/dashboard/default.tpl @@ -3,5 +3,9 @@ {include file="dashboard/system_stats.tpl"} {include file="dashboard/round_data.tpl"} {include file="dashboard/account_data.tpl"} - {include file="dashboard/js.tpl"} + {if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API} + {include file="dashboard/js_api.tpl"} + {else} + {include file="dashboard/js_static.tpl"} + {/if} {/if} diff --git a/public/templates/mpos/dashboard/js.tpl b/public/templates/mpos/dashboard/js_api.tpl similarity index 100% rename from public/templates/mpos/dashboard/js.tpl rename to public/templates/mpos/dashboard/js_api.tpl diff --git a/public/templates/mpos/dashboard/js_static.tpl b/public/templates/mpos/dashboard/js_static.tpl new file mode 100644 index 00000000..b2468644 --- /dev/null +++ b/public/templates/mpos/dashboard/js_static.tpl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + diff --git a/public/templates/mpos/dashboard/network_info.tpl b/public/templates/mpos/dashboard/network_info.tpl index 22bf9e79..1c8691c5 100644 --- a/public/templates/mpos/dashboard/network_info.tpl +++ b/public/templates/mpos/dashboard/network_info.tpl @@ -3,9 +3,9 @@ Difficulty - + {$NETWORK.difficulty} Current Block - + {$NETWORK.block} diff --git a/public/templates/mpos/dashboard/overview.tpl b/public/templates/mpos/dashboard/overview.tpl index 61b76021..41d325eb 100644 --- a/public/templates/mpos/dashboard/overview.tpl +++ b/public/templates/mpos/dashboard/overview.tpl @@ -14,9 +14,11 @@
+ {if !$DISABLED_DASHBOARD and !$DISABLED_DASHBOARD_API}
+ {/if}