From ab85af19a149686825e66d3d66fc31f8f8e92ee3 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Fri, 5 Jul 2013 23:23:19 +0200
Subject: [PATCH 001/137] Re-add shares archive table for 24h hashrates
This should fix #312 and fix #256 where hashrates are reset on quick rounds.
Users are not able to properly view their past 24h hashrates.
Will be merged once confirmed working.
---
public/include/classes/statistics.class.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 2ca5bfd1..8f530003 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -374,6 +374,16 @@ class Statistics {
ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate,
HOUR(s.time) AS hour
FROM " . $this->share->getTableName() . " AS s, accounts AS a
+ WHERE time < NOW() - INTERVAL 1 HOUR
+ AND time > NOW() - INTERVAL 25 HOUR
+ AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
+ AND a.id = ?
+ GROUP BY HOUR(time)
+ UNION ALL
+ SELECT
+ ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000) AS hashrate,
+ HOUR(s.time) AS hour
+ FROM " . $this->share->getArchiveTableName() . " AS s, accounts AS a
WHERE time < NOW() - INTERVAL 1 HOUR
AND time > NOW() - INTERVAL 25 HOUR
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
From 2a47fbba4fecea72da0acf5bab3e87ee8d5a6770 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Fri, 5 Jul 2013 23:45:32 +0200
Subject: [PATCH 002/137] Fixing PHP Warning on admin->user panel
This fixes #383
---
public/include/pages/admin/user.inc.php | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/public/include/pages/admin/user.inc.php b/public/include/pages/admin/user.inc.php
index 9bb9ecee..ecb447b9 100644
--- a/public/include/pages/admin/user.inc.php
+++ b/public/include/pages/admin/user.inc.php
@@ -34,10 +34,17 @@ if (@$_POST['query']) {
$aBalance = $transaction->getBalance($aUser['id']);
$aUser['balance'] = $aBalance['confirmed'];
$aUser['hashrate'] = $statistics->getUserHashrate($aUser['id']);
- $aUser['payout']['est_block'] = round(( (int)$aUser['shares'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
- $aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
- $aUser['payout']['est_donation'] = round((( $aUser['donate_percent'] / 100) * ($aUser['payout']['est_block'] - $aUser['payout']['est_fee'])), 3);
- $aUser['payout']['est_payout'] = round($aUser['payout']['est_block'] - $aUser['payout']['est_donation'] - $aUser['payout']['est_fee'], 3);
+ if ($aUser['shares'] > 0) {
+ $aUser['payout']['est_block'] = round(( (int)$aUser['shares'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3);
+ $aUser['payout']['est_fee'] = round(($config['fees'] / 100) * $aUser['payout']['est_block'], 3);
+ $aUser['payout']['est_donation'] = round((( $aUser['donate_percent'] / 100) * ($aUser['payout']['est_block'] - $aUser['payout']['est_fee'])), 3);
+ $aUser['payout']['est_payout'] = round($aUser['payout']['est_block'] - $aUser['payout']['est_donation'] - $aUser['payout']['est_fee'], 3);
+ } else {
+ $aUser['payout']['est_block'] = 0;
+ $aUser['payout']['est_fee'] = 0;
+ $aUser['payout']['est_donation'] = 0;
+ $aUser['payout']['est_payout'] = 0;
+ }
$aUsers[$iKey] = $aUser;
}
// Assign our variables
From 380e802c75d4bc6abc71a39445c672ca0271b2e8 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 08:34:41 +0200
Subject: [PATCH 003/137] fixing stmt issue
---
public/include/classes/statistics.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 8f530003..42ef3019 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -389,7 +389,7 @@ class Statistics {
AND a.username = SUBSTRING_INDEX( s.username, '.', 1 )
AND a.id = ?
GROUP BY HOUR(time)");
- if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result()) {
+ if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $account_id) && $stmt->execute() && $result = $stmt->get_result()) {
$aData = array();
while ($row = $result->fetch_assoc()) {
$aData[$row['hour']] = $row['hashrate'];
From 89af793a28248a727ba2d1186376c450aed3249d Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 17:32:58 +0200
Subject: [PATCH 004/137] Fixing pool hashrate graph
Should fix #312 completely.
---
public/include/classes/statistics.class.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 42ef3019..41fd7d95 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -410,6 +410,14 @@ class Statistics {
$this->debug->append("STA " . __METHOD__, 4);
if ($this->getGetCache() && $data = $this->memcache->get(__FUNCTION__)) return $data;
$stmt = $this->mysqli->prepare("
+ SELECT
+ IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate,
+ HOUR(s.time) AS hour
+ FROM " . $this->share->getTableName() . " AS s
+ WHERE time < NOW() - INTERVAL 1 HOUR
+ AND time > NOW() - INTERVAL 25 HOUR
+ GROUP BY HOUR(time)
+ UNION ALL
SELECT
IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour
From 9412107b53ffbd576df7508fc937e55ac76177d8 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 17:38:23 +0200
Subject: [PATCH 005/137] Hard coded block limit for pool statistics
This should fix a potential DoS like attack when fetching a random
amount of blocks continously.
Fixes #387
---
public/include/pages/statistics/blocks.inc.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/include/pages/statistics/blocks.inc.php b/public/include/pages/statistics/blocks.inc.php
index c65ea861..6c3b00b8 100644
--- a/public/include/pages/statistics/blocks.inc.php
+++ b/public/include/pages/statistics/blocks.inc.php
@@ -5,7 +5,7 @@ if (!defined('SECURITY')) die('Hacking attempt');
if (!$user->isAuthenticated()) header("Location: index.php?page=home");
// Grab the last blocks found
-empty($_REQUEST['limit']) ? $iLimit = 20 : $iLimit = $_REQUEST['limit'];
+$iLimit = 20;
$aBlocksFoundData = $statistics->getBlocksFound($iLimit);
// Propagate content our template
From 307c7ee23f753064937bf186f6a49d750dd75625 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 17:47:50 +0200
Subject: [PATCH 006/137] Enforce unique account emails
* display an error if user tries to re-use an email address
* moved SQL files to indicate the order of SQL import
* added unique email index SQL file
This will address #389, still needs email validation.
---
public/include/classes/user.class.php | 9 ++++++++-
sql/{mmcfe_ng_structure.sql => 000_base_structure.sql} | 0
sql/001_unique_email.sql | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
rename sql/{mmcfe_ng_structure.sql => 000_base_structure.sql} (100%)
create mode 100644 sql/001_unique_email.sql
diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php
index 69ebf8de..68616e3e 100644
--- a/public/include/classes/user.class.php
+++ b/public/include/classes/user.class.php
@@ -50,6 +50,9 @@ class User {
public function getUserIp($id) {
return $this->getSingle($id, 'loggedIp', 'id');
}
+ public function getEmail($email) {
+ return $this->getSingle($email, 'email', 'email', 's');
+ }
public function getUserFailed($id) {
return $this->getSingle($id, 'failed_logins', 'id');
}
@@ -439,6 +442,10 @@ class User {
**/
public function register($username, $password1, $password2, $pin, $email1='', $email2='') {
$this->debug->append("STA " . __METHOD__, 4);
+ if ($this->getEmail($email1)) {
+ $this->setErrorMessage( 'This e-mail address is already taken' );
+ return false;
+ }
if (strlen($password1) < 8) {
$this->setErrorMessage( 'Password is too short, minimum of 8 characters required' );
return false;
@@ -479,7 +486,7 @@ class User {
if ($this->checkStmt($stmt) && $stmt->bind_param('sssss', $username, $password_hash, $email1, $pin_hash, $apikey_hash)) {
if (!$stmt->execute()) {
$this->setErrorMessage( 'Unable to register' );
- if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username already exists' );
+ if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username or email already registered' );
return false;
}
$stmt->close();
diff --git a/sql/mmcfe_ng_structure.sql b/sql/000_base_structure.sql
similarity index 100%
rename from sql/mmcfe_ng_structure.sql
rename to sql/000_base_structure.sql
diff --git a/sql/001_unique_email.sql b/sql/001_unique_email.sql
new file mode 100644
index 00000000..30d2882e
--- /dev/null
+++ b/sql/001_unique_email.sql
@@ -0,0 +1 @@
+ALTER TABLE `accounts` ADD UNIQUE (`email`);
From fdb562b078edac7dd451311d151a413c10a5aa0c Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 17:57:37 +0200
Subject: [PATCH 007/137] Fixing PHP warning message for empty price var
Fixes #375
---
public/templates/mmcFE/global/header.tpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/templates/mmcFE/global/header.tpl b/public/templates/mmcFE/global/header.tpl
index c195c18a..b3d150f6 100644
--- a/public/templates/mmcFE/global/header.tpl
+++ b/public/templates/mmcFE/global/header.tpl
@@ -4,7 +4,7 @@
- {if $GLOBAL.config.price.currency}{$GLOBAL.config.currency}/{$GLOBAL.config.price.currency}: {$GLOBAL.price|default:"n/a"|number_format:"4"} {/if}
+ {if $GLOBAL.config.price.currency}{$GLOBAL.config.currency}/{$GLOBAL.config.price.currency}: {$GLOBAL.price|default:"0"|number_format:"4"} {/if}
Network Hashrate: {($GLOBAL.nethashrate / 1000 / 1000 )|default:"0"|number_format:"3"} MH/s
Pool Hashrate: {($GLOBAL.hashrate / 1000)|number_format:"3"} MH/s
Pool Sharerate: {$GLOBAL.sharerate|number_format:"2"} Shares/s
From 32d764127ed855a615aec942de99d06ac2352f3e Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 18:56:35 +0200
Subject: [PATCH 008/137] More descriptive error message exceeding LTC
threshold
Fixes #388
---
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 e7bfd4b5..147b38e9 100644
--- a/public/include/smarty_globals.inc.php
+++ b/public/include/smarty_globals.inc.php
@@ -103,7 +103,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' => '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');
}
From 752b3e810fa9687e964122d602d2291123b3640a Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sat, 6 Jul 2013 23:11:28 +0200
Subject: [PATCH 009/137] Fixing issue with delayed inserts for shares
When shares are inserted with a delay for performance optimizations,
this will cause block timestamps to be completely off with share
timestamps. Hence the timestamp limited search is now removed, it would
cause too many issues for Stratum users/pools.
Addresses #392
---
cronjobs/findblock.php | 2 +-
public/include/classes/share.class.php | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php
index efcc9f11..78bacd3e 100755
--- a/cronjobs/findblock.php
+++ b/cronjobs/findblock.php
@@ -77,7 +77,7 @@ if (empty($aAllBlocks)) {
foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aBlock['share_id'])) {
// Fetch this blocks upstream ID
- if ($share->setUpstream($block->getLastUpstreamId(), $aBlock['time'])) {
+ if ($share->setUpstream($block->getLastUpstreamId())) {
$iCurrentUpstreamId = $share->getUpstreamId();
$iAccountId = $user->getUserId($share->getUpstreamFinder());
} else {
diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php
index 6653814a..85935a2d 100644
--- a/public/include/classes/share.class.php
+++ b/public/include/classes/share.class.php
@@ -177,16 +177,15 @@ class Share {
* @param last int Skips all shares up to last to find new share
* @return bool
**/
- public function setUpstream($last=0, $time=0) {
+ public function setUpstream($last=0) {
$stmt = $this->mysqli->prepare("
SELECT
SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id
FROM $this->table
WHERE upstream_result = 'Y'
AND id > ?
- AND UNIX_TIMESTAMP(time) >= ?
ORDER BY id ASC LIMIT 1");
- if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $time) && $stmt->execute() && $result = $stmt->get_result()) {
+ if ($this->checkStmt($stmt) && $stmt->bind_param('i', $last) && $stmt->execute() && $result = $stmt->get_result()) {
$this->oUpstream = $result->fetch_object();
if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id))
return true;
From 5d57593f5d68a9c52b2c8bc1067faeaecb9dddd3 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 00:19:56 +0200
Subject: [PATCH 010/137] Abort payout process if `share_id` is missing
If we have a block with NO `share_id` we abort the entire process. Less
of an issue with proportional since PPS is still being paid out, but a
block round will never actually end.
This will allow for manual intervention by the user. Otherwise blocks
found after the one having issues might trigger the payout process and
pay out shares of the old block in a more recently found one.
Please use #392 for further help on this, I have yet to replicate the
unknown block finder issue with the proper amount of upstream shares.
---
cronjobs/pps_payout.php | 1 +
cronjobs/proportional_payout.php | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php
index 22e5fcf7..9c108e78 100755
--- a/cronjobs/pps_payout.php
+++ b/cronjobs/pps_payout.php
@@ -113,6 +113,7 @@ if (empty($aAllBlocks)) {
foreach ($aAllBlocks as $iIndex => $aBlock) {
// If we are running through more than one block, check for previous share ID
$iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0;
+ if (!is_numeric($aBlock['share_id'])) die("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue\n");
// Per account statistics
$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id']);
foreach ($aAccountShares as $key => $aData) {
diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php
index 57b97c2c..fa346dfc 100755
--- a/cronjobs/proportional_payout.php
+++ b/cronjobs/proportional_payout.php
@@ -40,12 +40,13 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$aBlock['accounted']) {
$iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0;
$iCurrentUpstreamId = $aBlock['share_id'];
+ if (!is_numeric($iCurrentUpstreamId)) die("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue\n");
$aAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']);
$iRoundShares = $share->getRoundShares($iPreviousShareId, $aBlock['share_id']);
$config['reward_type'] == 'block' ? $dReward = $aBlock['amount'] : $dReward = $config['reward'];
if (empty($aAccountShares)) {
- verbose("\nNo shares found for this block\n\n");
+ verbose("\nNo shares found for this block: " . $aBlock['height'] . " \n\n");
sleep(2);
continue;
}
From 9d50c9a2229a7e5d58a9b3111a8b5b7f9af46a39 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 19:39:16 +0200
Subject: [PATCH 011/137] User proper archive table for union
Addresses #312
---
public/include/classes/statistics.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php
index 41fd7d95..3e375249 100644
--- a/public/include/classes/statistics.class.php
+++ b/public/include/classes/statistics.class.php
@@ -421,7 +421,7 @@ class Statistics {
SELECT
IFNULL(ROUND(COUNT(s.id) * POW(2, " . $this->config['difficulty'] . ") / 3600 / 1000), 0) AS hashrate,
HOUR(s.time) AS hour
- FROM " . $this->share->getTableName() . " AS s
+ FROM " . $this->share->getArchiveTableName() . " AS s
WHERE time < NOW() - INTERVAL 1 HOUR
AND time > NOW() - INTERVAL 25 HOUR
GROUP BY HOUR(time)");
From 2586aca34e241b5ad253db7ce2e6435987453274 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 19:52:24 +0200
Subject: [PATCH 012/137] Revert "Fixing issue with delayed inserts for shares"
This reverts commit 752b3e810fa9687e964122d602d2291123b3640a.
---
cronjobs/findblock.php | 2 +-
public/include/classes/share.class.php | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php
index 78bacd3e..efcc9f11 100755
--- a/cronjobs/findblock.php
+++ b/cronjobs/findblock.php
@@ -77,7 +77,7 @@ if (empty($aAllBlocks)) {
foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aBlock['share_id'])) {
// Fetch this blocks upstream ID
- if ($share->setUpstream($block->getLastUpstreamId())) {
+ if ($share->setUpstream($block->getLastUpstreamId(), $aBlock['time'])) {
$iCurrentUpstreamId = $share->getUpstreamId();
$iAccountId = $user->getUserId($share->getUpstreamFinder());
} else {
diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php
index 85935a2d..6653814a 100644
--- a/public/include/classes/share.class.php
+++ b/public/include/classes/share.class.php
@@ -177,15 +177,16 @@ class Share {
* @param last int Skips all shares up to last to find new share
* @return bool
**/
- public function setUpstream($last=0) {
+ public function setUpstream($last=0, $time=0) {
$stmt = $this->mysqli->prepare("
SELECT
SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id
FROM $this->table
WHERE upstream_result = 'Y'
AND id > ?
+ AND UNIX_TIMESTAMP(time) >= ?
ORDER BY id ASC LIMIT 1");
- if ($this->checkStmt($stmt) && $stmt->bind_param('i', $last) && $stmt->execute() && $result = $stmt->get_result()) {
+ if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $time) && $stmt->execute() && $result = $stmt->get_result()) {
$this->oUpstream = $result->fetch_object();
if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id))
return true;
From 6dc795fd7747ece2722949e6258b3087868871fc Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 22:04:43 +0200
Subject: [PATCH 013/137] Improved cron logging via logfiles
* Added 3rd party logger library KLogger
* Adjusted all cronjobs from verbose output to logging
* Added new logs folder for crons to write to
* Added new .gitignore for logs folder data
* Updated blocks class to only fetch blocks with no share_id
* Adjusted findblocks to use no blocks class method
---
.gitignore | 1 +
cronjobs/auto_payout.php | 28 ++---
cronjobs/blockupdate.php | 18 ++-
cronjobs/findblock.php | 51 ++++-----
cronjobs/logs/README.md | 1 +
cronjobs/notifications.php | 30 +++--
cronjobs/pps_payout.php | 33 +++---
cronjobs/proportional_payout.php | 40 ++++---
cronjobs/shared.inc.php | 17 +--
cronjobs/statistics.php | 32 ++----
cronjobs/tickerupdate.php | 8 +-
public/include/autoloader.inc.php | 1 +
public/include/classes/block.class.php | 18 ++-
public/include/lib/KLogger.php | 148 +++++++++++++++++++++++++
14 files changed, 269 insertions(+), 157 deletions(-)
create mode 100644 cronjobs/logs/README.md
create mode 100755 public/include/lib/KLogger.php
diff --git a/.gitignore b/.gitignore
index d67a566e..66b6c501 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/public/include/config/global.inc.php
/public/templates/compile/*.php
+/cronjobs/logs/*.txt
diff --git a/cronjobs/auto_payout.php b/cronjobs/auto_payout.php
index aaf715e0..943a6cd7 100755
--- a/cronjobs/auto_payout.php
+++ b/cronjobs/auto_payout.php
@@ -22,10 +22,8 @@ limitations under the License.
// Include all settings and classes
require_once('shared.inc.php');
-verbose("Running auto-payouts ...");
-
if ($bitcoin->can_connect() !== true) {
- verbose(" unable to connect to RPC server, exiting\n");
+ $log->logFatal(" unable to connect to RPC server, exiting\n");
exit(1);
}
@@ -36,16 +34,16 @@ $setting->setValue('auto_payout_active', 1);
$users = $user->getAllAutoPayout();
// Quick summary
-verbose(" found " . count($users) . " queued payout(s)\n");
+$log->logInfo(" found " . count($users) . " queued payout(s)\n");
// Go through users and run transactions
if (! empty($users)) {
- verbose("\tUserID\tUsername\tBalance\tThreshold\tAddress\t\t\t\t\tStatus\n\n");
+ $log->logInfo("\tUserID\tUsername\tBalance\tThreshold\tAddress");
foreach ($users as $aUserData) {
$aBalance = $transaction->getBalance($aUserData['id']);
$dBalance = $aBalance['confirmed'];
- verbose("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address'] . "\t");
+ $log->logInfo("\t" . $aUserData['id'] . "\t" . $aUserData['username'] . "\t" . $dBalance . "\t" . $aUserData['ap_threshold'] . "\t\t" . $aUserData['coin_address']);
// Only run if balance meets threshold and can pay the potential transaction fee
if ($dBalance > $aUserData['ap_threshold'] && $dBalance > $config['txfee']) {
@@ -53,7 +51,7 @@ if (! empty($users)) {
try {
$bitcoin->validateaddress($aUserData['coin_address']);
} catch (BitcoinClientException $e) {
- verbose("VERIFY FAILED\n");
+ $log->logError('Failed to verifu this users coin address, skipping payout');
continue;
}
@@ -61,7 +59,7 @@ if (! empty($users)) {
try {
$bitcoin->sendtoaddress($aUserData['coin_address'], $dBalance);
} catch (BitcoinClientException $e) {
- verbose("SEND FAILED\n");
+ $log->logError('Failed to send requested balance to coin address, please check payout process');
continue;
}
@@ -71,21 +69,15 @@ if (! empty($users)) {
$aMailData['email'] = $user->getUserEmail($user->getUserName($aUserData['id']));
$aMailData['subject'] = 'Auto Payout Completed';
$aMailData['amount'] = $dBalance;
- if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData)) {
- verbose("NOTIFY FAILED\n");
- } else {
- verbose("OK\n");
- }
+ if (!$notification->sendNotification($aUserData['id'], 'auto_payout', $aMailData))
+ $log->logError('Failed to send notification email to users address: ' . $aMailData['email']);
} else {
- verbose("FAILED\n");
+ $log->logError('Failed to add new Debit_AP transaction in database for user ' . $user->getUserName($aUserData['id']));
}
-
- } else {
- verbose("SKIPPED\n");
}
}
} else {
- verbose(" no user has configured their AP > 0\n");
+ $log->logDebug(" no user has configured their AP > 0\n");
}
// Mark this job as inactive
diff --git a/cronjobs/blockupdate.php b/cronjobs/blockupdate.php
index 65779a3a..89a27be1 100755
--- a/cronjobs/blockupdate.php
+++ b/cronjobs/blockupdate.php
@@ -23,33 +23,31 @@ limitations under the License.
require_once('shared.inc.php');
if ( $bitcoin->can_connect() !== true ) {
- verbose("Failed to connect to RPC server\n");
+ $log->logFatal("Failed to connect to RPC server\n");
exit(1);
}
// Fetch all unconfirmed blocks
$aAllBlocks = $block->getAllUnconfirmed($config['confirmations']);
-verbose("ID\tBlockhash\tConfirmations\t\n");
+$log->logInfo("ID\tBlockhash\tConfirmations");
foreach ($aAllBlocks as $iIndex => $aBlock) {
$aBlockInfo = $bitcoin->query('getblock', $aBlock['blockhash']);
// Fetch this blocks transaction details to find orphan blocks
$aTxDetails = $bitcoin->query('gettransaction', $aBlockInfo['tx'][0]);
- verbose($aBlock['id'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations'] . "\t");
+ $log->logInfo($aBlock['id'] . "\t" . $aBlock['blockhash'] . "\t" . $aBlock['confirmations'] . " -> " . $aBlockInfo['confirmations']);
if ($aTxDetails['details'][0]['category'] == 'orphan') {
// We have an orphaned block, we need to invalidate all transactions for this one
if ($transaction->setOrphan($aBlock['id']) && $block->setConfirmations($aBlock['id'], -1)) {
- verbose("ORPHAN\n");
+ $log->logInfo(" Block marked as orphan");
} else {
- verbose("ORPHAN_ERR");
+ $log->logError(" Block became orphaned but unable to update database entries");
}
continue;
}
if ($aBlock['confirmations'] == $aBlockInfo['confirmations']) {
- verbose("SKIPPED\n");
- } else if ($block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) {
- verbose("UPDATED\n");
- } else {
- verbose("ERROR\n");
+ $log->logDebug(' No update needed');
+ } else if (!$block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) {
+ $log->logError(' Failed to update block confirmations');
}
}
diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php
index efcc9f11..28dddb4b 100755
--- a/cronjobs/findblock.php
+++ b/cronjobs/findblock.php
@@ -25,24 +25,22 @@ require_once('shared.inc.php');
// Fetch our last block found from the DB as a starting point
$aLastBlock = @$block->getLast();
$strLastBlockHash = $aLastBlock['blockhash'];
-if (!$strLastBlockHash) {
- $strLastBlockHash = '';
-}
+if (!$strLastBlockHash) $strLastBlockHash = '';
// Fetch all transactions since our last block
if ( $bitcoin->can_connect() === true ){
$aTransactions = $bitcoin->query('listsinceblock', $strLastBlockHash);
} else {
- verbose("Aborted: " . $bitcoin->can_connect() . "\n");
+ $log->logFatal('Unable to conenct to RPC server backend');
exit(1);
}
// Nothing to do so bail out
if (empty($aTransactions['transactions'])) {
- verbose("No new RPC transactions since last block\n");
+ $log->logDebug('No new RPC transactions since last block');
} else {
// Table header
- verbose("Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime\t\t\tStatus\n");
+ $log->logInfo("Blockhash\t\tHeight\tAmount\tConfirmations\tDiff\t\tTime");
// Let us add those blocks as unaccounted
foreach ($aTransactions['transactions'] as $iIndex => $aData) {
@@ -51,29 +49,26 @@ if (empty($aTransactions['transactions'])) {
$config['reward_type'] == 'block' ? $aData['amount'] = $aData['amount'] : $aData['amount'] = $config['reward'];
$aData['height'] = $aBlockInfo['height'];
$aData['difficulty'] = $aBlockInfo['difficulty'];
- verbose(substr($aData['blockhash'], 0, 15) . "...\t" .
+ $log->logInfo(substr($aData['blockhash'], 0, 15) . "...\t" .
$aData['height'] . "\t" .
$aData['amount'] . "\t" .
$aData['confirmations'] . "\t\t" .
$aData['difficulty'] . "\t" .
- strftime("%Y-%m-%d %H:%M:%S", $aData['time']) . "\t");
- if ( $block->addBlock($aData) ) {
- verbose("Added\n");
- } else {
- verbose("Failed" . "\n");
+ strftime("%Y-%m-%d %H:%M:%S", $aData['time']));
+ if (!$block->addBlock($aData) ) {
+ $log->logFatal('Unable to add this block to database: ' . $aData['height']);
}
}
}
}
-verbose("\n");
// Now with our blocks added we can scan for their upstream shares
-$aAllBlocks = $block->getAllUnaccounted('ASC');
+$aAllBlocks = $block->getAllUnsetShareId('ASC');
if (empty($aAllBlocks)) {
- verbose("No new unaccounted blocks found\n");
+ $log->logDebug('No new blocks without share_id found in database');
} else {
// Loop through our unaccounted blocks
- verbose("\nBlock ID\tBlock Height\tAmount\tShare ID\tShares\tFinder\t\t\tStatus\n");
+ $log->logInfo("Block ID\t\tHeight\tAmount\tShare ID\tShares\tFinder");
foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aBlock['share_id'])) {
// Fetch this blocks upstream ID
@@ -81,40 +76,35 @@ if (empty($aAllBlocks)) {
$iCurrentUpstreamId = $share->getUpstreamId();
$iAccountId = $user->getUserId($share->getUpstreamFinder());
} else {
- verbose("\nUnable to fetch blocks upstream share. Aborting!\n");
- verbose($share->getError() . "\n");
+ $log->logFatal('Unable to fetch blocks upstream share, aborted:' . $share->getError());
exit;
}
// Fetch share information
if (!$iPreviousShareId = $block->getLastShareId()) {
$iPreviousShareId = 0;
- verbose("\nUnable to find highest share ID found so far\n");
- verbose("If this is your first block, this is normal\n\n");
+ $log->logInfo('Unable to find highest share ID found so far, if this is your first block, this is normal.');
}
$iRoundShares = $share->getRoundShares($iPreviousShareId, $iCurrentUpstreamId);
// Store new information
- $strStatus = "OK";
if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId))
- $strStatus = "Share ID Failed";
+ $log->logError('Failed to update share ID in database for block ' . $aBlock['height']);
if (!$block->setFinder($aBlock['id'], $iAccountId))
- $strStatus = "Finder Failed";
+ $log->logError('Failed to update finder account ID in database for block ' . $aBlock['height']);
if (!$block->setShares($aBlock['id'], $iRoundShares))
- $strStatus = "Shares Failed";
+ $log->logError('Failed to update share count in database for block ' . $aBlock['height']);
if ($config['block_bonus'] > 0 && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) {
- $strStatus = "Bonus Failed";
+ $log->logError('Failed to create Bonus transaction in database for user ' . $user->getUserName($iAccountId) . ' for block ' . $aBlock['height']);
}
- verbose(
+ $log->logInfo(
$aBlock['id'] . "\t\t"
. $aBlock['height'] . "\t\t"
. $aBlock['amount'] . "\t"
. $iCurrentUpstreamId . "\t\t"
. $iRoundShares . "\t"
- . "[$iAccountId] " . $user->getUserName($iAccountId) . "\t\t"
- . $strStatus
- . "\n"
+ . "[$iAccountId] " . $user->getUserName($iAccountId)
);
// Notify users
@@ -125,7 +115,8 @@ if (empty($aAllBlocks)) {
$aMailData['subject'] = 'New Block';
$aMailData['email'] = $user->getUserEmail($user->getUserName($aData['account_id']));
$aMailData['shares'] = $iRoundShares;
- $notification->sendNotification($aData['account_id'], 'new_block', $aMailData);
+ if (!$notification->sendNotification($aData['account_id'], 'new_block', $aMailData))
+ $log->logError('Failed to notify user of new found block: ' . $user->getUserName($aData['account_id']));
}
}
}
diff --git a/cronjobs/logs/README.md b/cronjobs/logs/README.md
new file mode 100644
index 00000000..864999fd
--- /dev/null
+++ b/cronjobs/logs/README.md
@@ -0,0 +1 @@
+Logging directory for cronjobs.
diff --git a/cronjobs/notifications.php b/cronjobs/notifications.php
index 61a608ab..a60e4657 100755
--- a/cronjobs/notifications.php
+++ b/cronjobs/notifications.php
@@ -22,51 +22,47 @@ limitations under the License.
// Include all settings and classes
require_once('shared.inc.php');
-verbose("Running system notifications\n");
-verbose(" IDLE Worker Notifications ...");
+$log->logDebug(" IDLE Worker Notifications ...");
// Find all IDLE workers
$aWorkers = $worker->getAllIdleWorkers();
if (empty($aWorkers)) {
- verbose(" no idle workers found\n");
+ $log->logDebug(" no idle workers found\n");
} else {
- verbose(" found " . count($aWorkers) . " IDLE workers\n");
+ $log->logInfo(" found " . count($aWorkers) . " IDLE workers\n");
foreach ($aWorkers as $aWorker) {
$aData = $aWorker;
$aData['username'] = $user->getUserName($aWorker['account_id']);
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
$aData['worker'] = $aWorker['username'];
$aData['email'] = $user->getUserEmail($aData['username']);
- verbose(" " . $aWorker['username'] . "...");
- if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData)) {
- verbose(" " . $notification->getError() . "\n");
- } else {
- verbose(" sent\n");
- }
+ $log->logInfo(" " . $aWorker['username'] . "...");
+ if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
+ $log->logError(" Failed sending notifications: " . $notification->getError() . "\n");
}
}
-verbose(" Reset IDLE Worker Notifications ...");
+$log->logDebug(" Reset IDLE Worker Notifications ...");
// We notified, lets check which recovered
$aNotifications = $notification->getAllActive('idle_worker');
if (!empty($aNotifications)) {
- verbose(" found " . count($aNotifications) . " active notification(s)\n");
+ $log->logInfo(" found " . count($aNotifications) . " active notification(s)\n");
foreach ($aNotifications as $aNotification) {
$aData = json_decode($aNotification['data'], true);
$aWorker = $worker->getWorker($aData['id']);
- verbose(" " . $aWorker['username'] . " ...");
+ $log->logInfo(" " . $aWorker['username'] . " ...");
if ($aWorker['active'] == 1) {
if ($notification->setInactive($aNotification['id'])) {
- verbose(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive\n");
+ $log->logInfo(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive\n");
} else {
- verbose(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username'] . "\n");
+ $log->logInfo(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username'] . "\n");
}
} else {
- verbose(" still inactive\n");
+ $log->logInfo(" still inactive\n");
}
}
} else {
- verbose(" no active IDLE worker notifications\n");
+ $log->logDebug(" no active IDLE worker notifications\n");
}
?>
diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php
index 9c108e78..388f49ac 100755
--- a/cronjobs/pps_payout.php
+++ b/cronjobs/pps_payout.php
@@ -25,7 +25,7 @@ require_once('shared.inc.php');
// Check if we are set as the payout system
if ($config['payout_system'] != 'pps') {
- verbose("Please activate this cron in configuration via payout_system = pps\n");
+ $log->logInfo("Please activate this cron in configuration via payout_system = pps\n");
exit(0);
}
@@ -35,7 +35,7 @@ if ( $bitcoin->can_connect() === true ){
if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty))
$dDifficulty = $dDifficulty['proof-of-work'];
} else {
- verbose("Aborted: " . $bitcoin->can_connect() . "\n");
+ $log->logFatal("Aborted: " . $bitcoin->can_connect() . "\n");
exit(1);
}
@@ -58,7 +58,7 @@ $iLastShareId = $share->getLastInsertedShareId();
// Check for all new shares, we start one higher as our last accounted share to avoid duplicates
$aAccountShares = $share->getSharesForAccounts($iPreviousShareId + 1, $iLastShareId);
-verbose("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee\t\tStatus\n");
+$log->logInfo("ID\tUsername\tInvalid\tValid\t\tPPS Value\t\tPayout\t\tDonation\tFee");
foreach ($aAccountShares as $aData) {
// Take our valid shares and multiply by per share value
@@ -74,60 +74,59 @@ foreach ($aAccountShares as $aData) {
// Calculate donation amount
$aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8);
- verbose($aData['id'] . "\t" .
+ $log->logInfo($aData['id'] . "\t" .
$aData['username'] . "\t" .
$aData['invalid'] . "\t" .
$aData['valid'] . "\t*\t" .
$pps_value . "\t=\t" .
$aData['payout'] . "\t" .
$aData['donation'] . "\t" .
- $aData['fee'] . "\t");
+ $aData['fee']);
- $strStatus = "OK";
// Add new credit transaction
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit_PPS'))
- $strStatus = "Transaction Failed";
+ $log->logError('Failed to add Credit_PPS transaction in database');
// Add new fee debit for this block
if ($aData['fee'] > 0 && $config['fees'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee_PPS'))
- $strStatus = "Fee Failed";
+ $log->logError('Failed to add Fee_PPS transaction in database');
// Add new donation debit
if ($aData['donation'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation_PPS'))
- $strStatus = "Donation Failed";
- verbose($strStatus . "\n");
+ $log->logError('Failed to add Donation_PPS transaction in database');
}
// Store our last inserted ID for the next run
$setting->setValue('pps_last_share_id', $iLastShareId);
-verbose("\n\n------------------------------------------------------------------------------------\n\n");
-
// Fetch all unaccounted blocks
$aAllBlocks = $block->getAllUnaccounted('ASC');
if (empty($aAllBlocks)) {
- verbose("No new unaccounted blocks found\n");
+ $log->logDebug("No new unaccounted blocks found");
}
// Go through blocks and archive/delete shares that have been accounted for
foreach ($aAllBlocks as $iIndex => $aBlock) {
// If we are running through more than one block, check for previous share ID
$iLastBlockShare = @$aAllBlocks[$iIndex - 1]['share_id'] ? @$aAllBlocks[$iIndex - 1]['share_id'] : 0;
- if (!is_numeric($aBlock['share_id'])) die("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue\n");
+ if (!is_numeric($aBlock['share_id'])) {
+ $log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue");
+ exit(1);
+ }
// Per account statistics
$aAccountShares = $share->getSharesForAccounts(@$iLastBlockShare, $aBlock['share_id']);
foreach ($aAccountShares as $key => $aData) {
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
- verbose("Failed to update stats for this block on : " . $aData['username'] . "\n");
+ $log->logError("Failed to update stats for this block on : " . $aData['username']);
}
// Move shares to archive
if ($config['archive_shares'] && $aBlock['share_id'] < $iLastShareId) {
if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare))
- verbose("Archving failed\n");
+ $log->logError("Archving failed");
}
// Delete shares
if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) {
- verbose("\nERROR : Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting!\n");
+ $log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting!");
exit(1);
}
// Mark this block as accounted for
diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php
index fa346dfc..c9c61539 100755
--- a/cronjobs/proportional_payout.php
+++ b/cronjobs/proportional_payout.php
@@ -24,36 +24,39 @@ require_once('shared.inc.php');
// Check if we are set as the payout system
if ($config['payout_system'] != 'prop') {
- verbose("Please activate this cron in configuration via payout_system = prop\n");
+ $log->logInfo("Please activate this cron in configuration via payout_system = prop");
exit(0);
}
// Fetch all unaccounted blocks
$aAllBlocks = $block->getAllUnaccounted('ASC');
if (empty($aAllBlocks)) {
- verbose("No new unaccounted blocks found\n");
+ $log->logDebug('No new unaccounted blocks found in database');
exit(0);
}
$count = 0;
+// Table header for account shares
+$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee");
foreach ($aAllBlocks as $iIndex => $aBlock) {
if (!$aBlock['accounted']) {
$iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0;
$iCurrentUpstreamId = $aBlock['share_id'];
- if (!is_numeric($iCurrentUpstreamId)) die("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue\n");
+ if (!is_numeric($iCurrentUpstreamId)) {
+ $log->logFatal("Block " . $aBlock['height'] . " has no share_id associated with it, not going to continue.");
+ $log->logFatal("Please assign a valid share ID to this block to continue the payout process.");
+ exit(1);
+ }
$aAccountShares = $share->getSharesForAccounts($iPreviousShareId, $aBlock['share_id']);
$iRoundShares = $share->getRoundShares($iPreviousShareId, $aBlock['share_id']);
$config['reward_type'] == 'block' ? $dReward = $aBlock['amount'] : $dReward = $config['reward'];
if (empty($aAccountShares)) {
- verbose("\nNo shares found for this block: " . $aBlock['height'] . " \n\n");
+ $log->logFatal('No shares found for this block, aborted: ' . $aBlock['height']);
sleep(2);
continue;
}
- // Table header for account shares
- verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee\t\tStatus\n");
-
// Loop through all accounts that have found shares for this round
foreach ($aAccountShares as $key => $aData) {
// Payout based on shares, PPS system
@@ -69,45 +72,40 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
$aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8);
// Verbose output of this users calculations
- verbose($aData['id'] . "\t" .
+ $log->logInfo($aData['id'] . "\t" .
$aData['username'] . "\t" .
$aData['valid'] . "\t" .
$aData['invalid'] . "\t" .
$aData['percentage'] . "\t" .
$aData['payout'] . "\t" .
$aData['donation'] . "\t" .
- $aData['fee'] . "\t");
+ $aData['fee']);
- $strStatus = "OK";
// Update user share statistics
if (!$statistics->updateShareStatistics($aData, $aBlock['id']))
- $strStatus = "Stats Failed";
+ $log->logFatal('Failed to update share statistics for ' . $aData['username']);
// Add new credit transaction
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
- $strStatus = "Transaction Failed";
+ $log->logFatal('Failed to insert new Credit transaction to database for ' . $aData['username']);
// Add new fee debit for this block
if ($aData['fee'] > 0 && $config['fees'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee', $aBlock['id']))
- $strStatus = "Fee Failed";
+ $log->logFatal('Failed to insert new Fee transaction to database for ' . $aData['username']);
// Add new donation debit
if ($aData['donation'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
- $strStatus = "Donation Failed";
- verbose("\t$strStatus\n");
+ $log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username']);
}
// Move counted shares to archive before this blockhash upstream share
if ($config['archive_shares']) $share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId);
// Delete all accounted shares
if (!$share->deleteAccountedShares($iCurrentUpstreamId, $iPreviousShareId)) {
- verbose("\nERROR : Failed to delete accounted shares from $iPreviousShareId to $iCurrentUpstreamId, aborting!\n");
+ $log->logFatal('Failed to delete accounted shares from ' . $iPreviousShareId . ' to ' . $iCurrentUpstreamId . ', aborted');
exit(1);
}
// Mark this block as accounted for
- if (!$block->setAccounted($aBlock['id'])) {
- verbose("\nERROR : Failed to mark block as accounted! Aborting!\n");
- }
-
- verbose("------------------------------------------------------------------------\n\n");
+ if (!$block->setAccounted($aBlock['id']))
+ $log->logFatal('Failed to mark block as accounted! Aborted.');
}
}
diff --git a/cronjobs/shared.inc.php b/cronjobs/shared.inc.php
index a0b1dc5d..9d3ae322 100644
--- a/cronjobs/shared.inc.php
+++ b/cronjobs/shared.inc.php
@@ -31,16 +31,7 @@ require_once(BASEPATH . 'include/config/global.inc.php');
// We include all needed files here, even though our templates could load them themself
require_once(INCLUDE_DIR . '/autoloader.inc.php');
-// Parse command line
-$options = getopt("v");
-if (array_key_exists('v', $options)) {
- define("VERBOSE", true);
-} else {
- define("VERBOSE", false);
-}
-
-// Command line cron functions only
-function verbose($msg) {
- if (VERBOSE) echo $msg;
-}
-
+// Load 3rd party logging library for running crons
+$log = new KLogger ( 'logs/' . basename($_SERVER['PHP_SELF'], '.php') . '.txt' , KLogger::DEBUG );
+$log->LogDebug('Starting ' . basename($_SERVER['PHP_SELF'], '.php'));
+?>
diff --git a/cronjobs/statistics.php b/cronjobs/statistics.php
index 69c1db5f..9ce96bde 100755
--- a/cronjobs/statistics.php
+++ b/cronjobs/statistics.php
@@ -25,44 +25,34 @@ require_once('shared.inc.php');
// Fetch all cachable values but disable fetching from cache
$statistics->setGetCache(false);
-// Verbose output
-verbose("Running statistical cache updates\n");
-
// Since fetching from cache is disabled, overwrite our stats
-verbose(" getRoundShares ...");
$start = microtime(true);
if (!$statistics->getRoundShares())
- verbose(" update failed");
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds\n");
-verbose(" getTopContributors shares ...");
+ $log->logError("getRoundShares update failed");
+$log->logInfo("getRoundShares update " . number_format(microtime(true) - $start, 2) . " seconds");
$start = microtime(true);
if (!$statistics->getTopContributors('shares'))
- verbose(" update failed");
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds\n");
-verbose(" getTopContributors hashes ...");
+ $log->logError("getTopContributors shares update failed");
+$log->logInfo("getTopContributors shares " . number_format(microtime(true) - $start, 2) . " seconds");
$start = microtime(true);
if (!$statistics->getTopContributors('hashes'))
- verbose(" update failed");
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds\n");
-verbose(" getCurrentHashrate ...");
+ $log->logError("getTopContributors hashes update failed");
+$log->logInfo("getTopContributors hashes " . number_format(microtime(true) - $start, 2) . " seconds");
$start = microtime(true);
if (!$statistics->getCurrentHashrate())
- verbose(" update failed");
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds\n");
+ $log->logError("getCurrentHashrate update failed");
+$log->logInfo("getCurrentHashrate " . number_format(microtime(true) - $start, 2) . " seconds");
// Admin specific statistics, we cache the global query due to slowness
-verbose(" getAllUserStats ...");
$start = microtime(true);
if (!$statistics->getAllUserStats('%'))
- verbose(" update failed");
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds\n");
+ $log->logError("getAllUserStats update failed");
+$log->logInfo("getAllUserStats " . number_format(microtime(true) - $start, 2) . " seconds");
// Per user share statistics based on all shares submitted
-verbose(" getAllUserShares ...");
$start = microtime(true);
$aUserShares = $statistics->getAllUserShares();
-verbose(" " . number_format(microtime(true) - $start, 2) . " seconds");
+$log->logInfo("getAllUserShares " . number_format(microtime(true) - $start, 2) . " seconds");
foreach ($aUserShares as $aShares) {
$memcache->setCache('getUserShares'. $aShares['id'], $aShares);
}
-verbose("\n");
?>
diff --git a/cronjobs/tickerupdate.php b/cronjobs/tickerupdate.php
index 26323738..4b36adb2 100755
--- a/cronjobs/tickerupdate.php
+++ b/cronjobs/tickerupdate.php
@@ -25,14 +25,12 @@ require_once('shared.inc.php');
// Include additional file not set in autoloader
require_once(CLASS_DIR . '/tools.class.php');
-verbose("Running scheduled updates\n");
-verbose(" Price API Call ... ");
if ($price = $tools->getPrice()) {
- verbose("found $price as price\n");
+ $log->logInfo("Price update: found $price as price");
if (!$setting->setValue('price', $price))
- verbose("unable to update value in settings table\n");
+ $log->logError("unable to update value in settings table");
} else {
- verbose("failed to fetch API data: " . $tools->getError() . "\n");
+ $log->logFatal("failed to fetch API data: " . $tools->getError());
}
?>
diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php
index e3a4534b..c74fa62b 100644
--- a/public/include/autoloader.inc.php
+++ b/public/include/autoloader.inc.php
@@ -17,6 +17,7 @@ require_once(CLASS_DIR . '/debug.class.php');
require_once(CLASS_DIR . '/bitcoin.class.php');
require_once(CLASS_DIR . '/statscache.class.php');
require_once(CLASS_DIR . '/bitcoinwrapper.class.php');
+require_once(INCLUDE_DIR . '/lib/KLogger.php');
require_once(INCLUDE_DIR . '/database.inc.php');
require_once(INCLUDE_DIR . '/smarty.inc.php');
// Load classes that need the above as dependencies
diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php
index 743ce67e..2fcbad09 100644
--- a/public/include/classes/block.class.php
+++ b/public/include/classes/block.class.php
@@ -55,6 +55,18 @@ class Block {
return false;
}
+ /**
+ * Fetch all blocks without a share ID
+ * @param order string Sort order, default ASC
+ * @return data array Array with database fields as keys
+ **/
+ public function getAllUnsetShareId($order='ASC') {
+ $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE ISNULL(share_id) ORDER BY height $order");
+ if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
+ return $result->fetch_all(MYSQLI_ASSOC);
+ return false;
+ }
+
/**
* Fetch all unaccounted blocks
* @param order string Sort order, default ASC
@@ -62,12 +74,8 @@ class Block {
**/
public function getAllUnaccounted($order='ASC') {
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE accounted = 0 ORDER BY height $order");
- if ($this->checkStmt($stmt)) {
- $stmt->execute();
- $result = $stmt->get_result();
- $stmt->close();
+ if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
- }
return false;
}
diff --git a/public/include/lib/KLogger.php b/public/include/lib/KLogger.php
new file mode 100755
index 00000000..9f53788e
--- /dev/null
+++ b/public/include/lib/KLogger.php
@@ -0,0 +1,148 @@
+
+ * Date : July 26, 2008
+ * Comments : Originally written for use with wpSearch
+ * Website : http://codefury.net
+ * Version : 1.0
+ *
+ * Usage:
+ * $log = new KLogger ( "log.txt" , KLogger::INFO );
+ * $log->LogInfo("Returned a million search results"); //Prints to the log file
+ * $log->LogFATAL("Oh dear."); //Prints to the log file
+ * $log->LogDebug("x = 5"); //Prints nothing due to priority setting
+ */
+
+ class KLogger
+ {
+
+ const DEBUG = 1; // Most Verbose
+ const INFO = 2; // ...
+ const WARN = 3; // ...
+ const ERROR = 4; // ...
+ const FATAL = 5; // Least Verbose
+ const OFF = 6; // Nothing at all.
+
+ const LOG_OPEN = 1;
+ const OPEN_FAILED = 2;
+ const LOG_CLOSED = 3;
+
+ /* Public members: Not so much of an example of encapsulation, but that's okay. */
+ public $Log_Status = KLogger::LOG_CLOSED;
+ public $DateFormat = "Y-m-d G:i:s";
+ public $MessageQueue;
+
+ private $log_file;
+ private $priority = KLogger::INFO;
+
+ private $file_handle;
+
+ public function __construct( $filepath , $priority )
+ {
+ if ( $priority == KLogger::OFF ) return;
+
+ $this->log_file = $filepath;
+ $this->MessageQueue = array();
+ $this->priority = $priority;
+
+ if ( file_exists( $this->log_file ) )
+ {
+ if ( !is_writable($this->log_file) )
+ {
+ $this->Log_Status = KLogger::OPEN_FAILED;
+ $this->MessageQueue[] = "The file exists, but could not be opened for writing. Check that appropriate permissions have been set.";
+ return;
+ }
+ }
+
+ if ( $this->file_handle = fopen( $this->log_file , "a" ) )
+ {
+ $this->Log_Status = KLogger::LOG_OPEN;
+ $this->MessageQueue[] = "The log file was opened successfully.";
+ }
+ else
+ {
+ $this->Log_Status = KLogger::OPEN_FAILED;
+ $this->MessageQueue[] = "The file could not be opened. Check permissions.";
+ }
+
+ return;
+ }
+
+ public function __destruct()
+ {
+ if ( $this->file_handle )
+ fclose( $this->file_handle );
+ }
+
+ public function LogInfo($line)
+ {
+ $this->Log( $line , KLogger::INFO );
+ }
+
+ public function LogDebug($line)
+ {
+ $this->Log( $line , KLogger::DEBUG );
+ }
+
+ public function LogWarn($line)
+ {
+ $this->Log( $line , KLogger::WARN );
+ }
+
+ public function LogError($line)
+ {
+ $this->Log( $line , KLogger::ERROR );
+ }
+
+ public function LogFatal($line)
+ {
+ $this->Log( $line , KLogger::FATAL );
+ }
+
+ public function Log($line, $priority)
+ {
+ if ( $this->priority <= $priority )
+ {
+ $status = $this->getTimeLine( $priority );
+ $this->WriteFreeFormLine ( "$status $line \n" );
+ }
+ }
+
+ public function WriteFreeFormLine( $line )
+ {
+ if ( $this->Log_Status == KLogger::LOG_OPEN && $this->priority != KLogger::OFF )
+ {
+ if (fwrite( $this->file_handle , $line ) === false) {
+ $this->MessageQueue[] = "The file could not be written to. Check that appropriate permissions have been set.";
+ }
+ }
+ }
+
+ private function getTimeLine( $level )
+ {
+ $time = date( $this->DateFormat );
+
+ switch( $level )
+ {
+ case KLogger::INFO:
+ return "$time - INFO -->";
+ case KLogger::WARN:
+ return "$time - WARN -->";
+ case KLogger::DEBUG:
+ return "$time - DEBUG -->";
+ case KLogger::ERROR:
+ return "$time - ERROR -->";
+ case KLogger::FATAL:
+ return "$time - FATAL -->";
+ default:
+ return "$time - LOG -->";
+ }
+ }
+
+ }
+
+
+?>
\ No newline at end of file
From 952c8732b164d49b328ebcdbc767b67f22eadb77 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 22:15:40 +0200
Subject: [PATCH 014/137] Properly display piechart, first attempt
Should further address #312
---
public/templates/mmcFE/statistics/graphs/both.tpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/public/templates/mmcFE/statistics/graphs/both.tpl b/public/templates/mmcFE/statistics/graphs/both.tpl
index ff760be1..61f796dd 100644
--- a/public/templates/mmcFE/statistics/graphs/both.tpl
+++ b/public/templates/mmcFE/statistics/graphs/both.tpl
@@ -30,7 +30,7 @@
{$POOLHASHRATES.$i|default:"0"}
{/for}
{for $i=0 to date('G', time() - 60 * 60)}
- {$POOLHASHRATES.$i|default:"0"}
+ {$POOLHASHRATES.$i - $YOURHASHRATES.$i|default:"0"}
{/for}
From 6193604598f084e66d53f96980bb475aa70a5c2d Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Sun, 7 Jul 2013 22:24:52 +0200
Subject: [PATCH 015/137] Fallback call if upstream share not found properly
Implemented a fallback method in case no upstream share can be found for
a block. This will result in same strange behaviour especially if a
later block has properly added a valid share and this will be used for a
previous block. At least now even the last block will be properly found
and marked as discovered by a user, even though no actual upstream share
was involved in this.
This is a dirty workaround for pools having payout issues. After all
blocks are processed and assuming upstream shares continue to work as
expected, this will *skip* broken blocks/shares.
Workaround fix for #392
---
public/include/classes/share.class.php | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php
index 6653814a..5e4db85e 100644
--- a/public/include/classes/share.class.php
+++ b/public/include/classes/share.class.php
@@ -191,6 +191,20 @@ class Share {
if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id))
return true;
}
+ // First attempt failed, we do a fallback with any share available for now
+ $stmt = $this->mysqli->prepare("
+ SELECT
+ SUBSTRING_INDEX( `username` , '.', 1 ) AS account, id
+ FROM $this->table
+ WHERE our_result = 'Y'
+ AND id > ?
+ AND UNIX_TIMESTAMP(time) >= ?
+ ORDER BY id ASC LIMIT 1");
+ if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $time) && $stmt->execute() && $result = $stmt->get_result()) {
+ $this->oUpstream = $result->fetch_object();
+ if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id))
+ return true;
+ }
// Catchall
return false;
}
From 5e98496cecc0550d1a1a1cb16f426a9ae81e1b24 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Mon, 8 Jul 2013 07:22:05 +0200
Subject: [PATCH 016/137] Update proportional_payout.php
Abort if no shares could be found for a block to allow user intervention to fix it.
---
cronjobs/proportional_payout.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php
index c9c61539..d7ab7e95 100755
--- a/cronjobs/proportional_payout.php
+++ b/cronjobs/proportional_payout.php
@@ -54,7 +54,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aAccountShares)) {
$log->logFatal('No shares found for this block, aborted: ' . $aBlock['height']);
sleep(2);
- continue;
+ exit(1);
}
// Loop through all accounts that have found shares for this round
From 83f8438a9c5bf0bbc6bfa28a5aac2a9846fb8e91 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Mon, 8 Jul 2013 08:49:55 +0200
Subject: [PATCH 017/137] last cleanup before merge
---
cronjobs/pps_payout.php | 2 +-
cronjobs/proportional_payout.php | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php
index 388f49ac..ee35e2ad 100755
--- a/cronjobs/pps_payout.php
+++ b/cronjobs/pps_payout.php
@@ -131,7 +131,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
}
// Mark this block as accounted for
if (!$block->setAccounted($aBlock['id'])) {
- verbose("\nERROR : Failed to mark block as accounted! Aborting!\n");
+ $log->logFatal("Failed to mark block as accounted! Aborting!");
exit(1);
}
}
diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php
index d7ab7e95..8a7dd2cd 100755
--- a/cronjobs/proportional_payout.php
+++ b/cronjobs/proportional_payout.php
@@ -53,7 +53,6 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if (empty($aAccountShares)) {
$log->logFatal('No shares found for this block, aborted: ' . $aBlock['height']);
- sleep(2);
exit(1);
}
From 1c2891cc78b94e137226b8e678a3a796992d8512 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Mon, 8 Jul 2013 08:54:17 +0200
Subject: [PATCH 018/137] Removed piechart, removed no shares notification
* Removed broken piechart for now
* Do not display message if no shares are found for calculations to
avoid cross-tabe error messages
Fixes #312
---
public/templates/mmcFE/statistics/graphs/both.tpl | 6 +-----
public/templates/mmcFE/statistics/graphs/mine.tpl | 2 --
public/templates/mmcFE/statistics/graphs/pool.tpl | 2 --
3 files changed, 1 insertion(+), 9 deletions(-)
diff --git a/public/templates/mmcFE/statistics/graphs/both.tpl b/public/templates/mmcFE/statistics/graphs/both.tpl
index 61f796dd..03832b5f 100644
--- a/public/templates/mmcFE/statistics/graphs/both.tpl
+++ b/public/templates/mmcFE/statistics/graphs/both.tpl
@@ -1,7 +1,6 @@
{if is_array($YOURHASHRATES) && is_array($POOLHASHRATES)}
-{foreach from=array('area','pie') item=chartType}
-
+
Your vs Pool Hashrate
@@ -36,8 +35,5 @@
-{/foreach}
-{else}
-
No shares available to start calculations
{/if}
diff --git a/public/templates/mmcFE/statistics/graphs/mine.tpl b/public/templates/mmcFE/statistics/graphs/mine.tpl
index fe217f2f..4d4259f2 100644
--- a/public/templates/mmcFE/statistics/graphs/mine.tpl
+++ b/public/templates/mmcFE/statistics/graphs/mine.tpl
@@ -26,6 +26,4 @@
-{else}
-
No shares available to start calculations
{/if}
diff --git a/public/templates/mmcFE/statistics/graphs/pool.tpl b/public/templates/mmcFE/statistics/graphs/pool.tpl
index ba2ed4e5..f8d118c7 100644
--- a/public/templates/mmcFE/statistics/graphs/pool.tpl
+++ b/public/templates/mmcFE/statistics/graphs/pool.tpl
@@ -26,6 +26,4 @@
-{else}
-
No shares available to start calculations
{/if}
From 420ae332b5985f9f3f6651309e195d78ac253f23 Mon Sep 17 00:00:00 2001
From: Sebastian Grewe
Date: Tue, 2 Jul 2013 14:08:33 +0200
Subject: [PATCH 019/137] 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 020/137] 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 021/137] 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 022/137] 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 023/137] 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 @@
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 @@
Delete
{/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 @@
Yes
- No
+ {/nocache}No
@@ -26,7 +26,7 @@
Yes
- No
+ No
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 024/137] 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}