[REFACTOR] Refactored classes for error handling
* [ADDED] More error codes * [MODIFIED] Class updates to use Base Class all the time * [MODIFIED] Cronjobs have been slightly adjusted * [ADDED] More base class features
This commit is contained in:
parent
04e2bf5932
commit
f67e63b6fc
@ -51,7 +51,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
if ($aBlock['confirmations'] == $aBlockInfo['confirmations']) {
|
||||
$log->logDebug(' No update needed');
|
||||
} else if (!$block->setConfirmations($aBlock['id'], $aBlockInfo['confirmations'])) {
|
||||
$log->logError(' Failed to update block confirmations');
|
||||
$log->logError(' Failed to update block confirmations: ' . $block->getCronMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ if (empty($aAllBlocks)) {
|
||||
$iAccountId = $user->getUserId($share->getUpstreamFinder());
|
||||
}
|
||||
} else {
|
||||
$log->logFatal('E0005: Unable to fetch blocks upstream share, aborted:' . $share->getError());
|
||||
$log->logFatal('E0005: Unable to fetch blocks upstream share, aborted:' . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0005', 1, true);
|
||||
}
|
||||
|
||||
@ -130,13 +130,13 @@ if (empty($aAllBlocks)) {
|
||||
|
||||
// Store new information
|
||||
if (!$block->setShareId($aBlock['id'], $iCurrentUpstreamId))
|
||||
$log->logError('Failed to update share ID in database for block ' . $aBlock['height']);
|
||||
$log->logError('Failed to update share ID in database for block ' . $aBlock['height'] . ': ' . $block->getCronError());
|
||||
if (!$block->setFinder($aBlock['id'], $iAccountId))
|
||||
$log->logError('Failed to update finder account ID in database for block ' . $aBlock['height']);
|
||||
$log->logError('Failed to update finder account ID in database for block ' . $aBlock['height'] . ': ' . $block->getCronError());
|
||||
if (!$block->setShares($aBlock['id'], $iRoundShares))
|
||||
$log->logError('Failed to update share count in database for block ' . $aBlock['height']);
|
||||
$log->logError('Failed to update share count in database for block ' . $aBlock['height'] . ': ' . $block->getCronError());
|
||||
if ($config['block_bonus'] > 0 && !$transaction->addTransaction($iAccountId, $config['block_bonus'], 'Bonus', $aBlock['id'])) {
|
||||
$log->logError('Failed to create Bonus transaction in database for user ' . $user->getUserName($iAccountId) . ' for block ' . $aBlock['height']);
|
||||
$log->logError('Failed to create Bonus transaction in database for user ' . $user->getUserName($iAccountId) . ' for block ' . $aBlock['height'] . ': ' . $transaction->getCronError());
|
||||
}
|
||||
|
||||
if ($setting->getValue('disable_notifications') != 1) {
|
||||
|
||||
@ -44,7 +44,7 @@ if (empty($aWorkers)) {
|
||||
$aData['email'] = $user->getUserEmail($aData['username']);
|
||||
$log->logDebug(" " . $aWorker['username'] . "...");
|
||||
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
|
||||
$log->logError(" Failed sending notifications: " . $notification->getError() . "\n");
|
||||
$log->logError(" Failed sending notifications: " . $notification->getCronError() . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -209,15 +209,15 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
|
||||
// Move counted shares to archive before this blockhash upstream share
|
||||
if (!$share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId))
|
||||
$log->logError('Failed to copy shares to archive table: ' . $share->getError());
|
||||
$log->logError('Failed to copy shares to archive table: ' . $share->getCronError());
|
||||
// Delete all accounted shares
|
||||
if (!$share->deleteAccountedShares($iCurrentUpstreamId, $iPreviousShareId)) {
|
||||
$log->logFatal("Failed to delete accounted shares from $iPreviousShareId to $iCurrentUpstreamId, aborting! Error: " . $share->getError());
|
||||
$log->logFatal("Failed to delete accounted shares from $iPreviousShareId to $iCurrentUpstreamId, aborting! Error: " . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
// Mark this block as accounted for
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getError());
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
} else {
|
||||
@ -231,7 +231,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
'Block Share ID' => $aBlock['share_id']
|
||||
);
|
||||
if (!$mail->sendMail('notifications/error', $aMailData))
|
||||
$log->logError(" Failed sending notifications: " . $notification->getError() . "\n");
|
||||
$log->logError(" Failed sending notifications: " . $notification->getCronError() . "\n");
|
||||
$monitoring->endCronjob($cron_name, 'E0015', 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,16 +146,16 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// Move shares to archive
|
||||
if ($aBlock['share_id'] < $iLastShareId) {
|
||||
if (!$share->moveArchive($aBlock['share_id'], $aBlock['id'], @$iLastBlockShare))
|
||||
$log->logError("Failed to copy shares to archive: " . $share->getError());
|
||||
$log->logError("Failed to copy shares to archive: " . $share->getCronError());
|
||||
}
|
||||
// Delete shares
|
||||
if ($aBlock['share_id'] < $iLastShareId && !$share->deleteAccountedShares($aBlock['share_id'], $iLastBlockShare)) {
|
||||
$log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getError());
|
||||
$log->logFatal("Failed to delete accounted shares from " . $aBlock['share_id'] . " to " . $iLastBlockShare . ", aborting! Error: " . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
// Mark this block as accounted for
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getError());
|
||||
$log->logFatal("Failed to mark block as accounted! Aborting! Error: " . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,15 +105,15 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
|
||||
// Move counted shares to archive before this blockhash upstream share
|
||||
if (!$share->moveArchive($iCurrentUpstreamId, $aBlock['id'], $iPreviousShareId))
|
||||
$log->logError('Failed to copy shares to archive: ' . $share->getError());
|
||||
$log->logError('Failed to copy shares to archive: ' . $share->getCronError());
|
||||
// Delete all accounted shares
|
||||
if (!$share->deleteAccountedShares($iCurrentUpstreamId, $iPreviousShareId)) {
|
||||
$log->logFatal('Failed to delete accounted shares from ' . $iPreviousShareId . ' to ' . $iCurrentUpstreamId . ', aborted! Error: ' . $share->getError());
|
||||
$log->logFatal('Failed to delete accounted shares from ' . $iPreviousShareId . ' to ' . $iCurrentUpstreamId . ', aborted! Error: ' . $share->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0016', 1, true);
|
||||
}
|
||||
// Mark this block as accounted for
|
||||
if (!$block->setAccounted($aBlock['id'])) {
|
||||
$log->logFatal('Failed to mark block as accounted! Aborted! Error: ' . $block->getError());
|
||||
$log->logFatal('Failed to mark block as accounted! Aborted! Error: ' . $block->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0014', 1, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -33,13 +33,13 @@ if ($price = $tools->getPrice()) {
|
||||
if (!$setting->setValue('price', $price))
|
||||
$log->logError("unable to update value in settings table");
|
||||
} else {
|
||||
$log->logError("failed to fetch API data: " . $tools->getError());
|
||||
$log->logError("failed to fetch API data: " . $tools->getCronError());
|
||||
}
|
||||
|
||||
if ($setting->getValue('monitoring_uptimerobot_private_key')) {
|
||||
$monitoring->setTools($tools);
|
||||
if (!$monitoring->storeUptimeRobotStatus()) {
|
||||
$log->logError('Failed to update Uptime Robot Status: ' . $monitoring->getError());
|
||||
$log->logError($monitoring->getCronError());
|
||||
$monitoring->endCronjob($cron_name, 'E0017', 1, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -51,8 +51,8 @@ require_once(CLASS_DIR . '/invitation.class.php');
|
||||
require_once(CLASS_DIR . '/share.class.php');
|
||||
require_once(CLASS_DIR . '/worker.class.php');
|
||||
require_once(CLASS_DIR . '/statistics.class.php');
|
||||
require_once(CLASS_DIR . '/roundstats.class.php');
|
||||
require_once(CLASS_DIR . '/transaction.class.php');
|
||||
require_once(CLASS_DIR . '/roundstats.class.php');
|
||||
require_once(CLASS_DIR . '/notification.class.php');
|
||||
require_once(CLASS_DIR . '/news.class.php');
|
||||
require_once(CLASS_DIR . '/api.class.php');
|
||||
|
||||
@ -4,10 +4,15 @@
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Our base class that defines
|
||||
// some cross-class functions.
|
||||
/**
|
||||
* Our base class that we extend our other classes from
|
||||
*
|
||||
* It supplies some basic features as cross-linking with other classes
|
||||
* after loading a newly created class.
|
||||
**/
|
||||
class Base {
|
||||
private $sError = '';
|
||||
private $sCronError = '';
|
||||
protected $table = '';
|
||||
private $values = array(), $types = '';
|
||||
|
||||
@ -23,6 +28,9 @@ class Base {
|
||||
public function setMail($mail) {
|
||||
$this->mail = $mail;
|
||||
}
|
||||
public function setSalt($salt) {
|
||||
$this->salt = $salt;
|
||||
}
|
||||
public function setSmarty($smarty) {
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
@ -32,8 +40,8 @@ class Base {
|
||||
public function setConfig($config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
public function setErrorCodes($aErrorCodes) {
|
||||
$this->aErrorCodes = $aErrorCodes;
|
||||
public function setErrorCodes(&$aErrorCodes) {
|
||||
$this->aErrorCodes =& $aErrorCodes;
|
||||
}
|
||||
public function setToken($token) {
|
||||
$this->token = $token;
|
||||
@ -41,6 +49,15 @@ class Base {
|
||||
public function setBlock($block) {
|
||||
$this->block = $block;
|
||||
}
|
||||
public function setTransaction($transaction) {
|
||||
$this->transaction = $transaction;
|
||||
}
|
||||
public function setMemcache($memcache) {
|
||||
$this->memcache = $memcache;
|
||||
}
|
||||
public function setStatistics($statistics) {
|
||||
$this->statistics = $statistics;
|
||||
}
|
||||
public function setSetting($setting) {
|
||||
$this->setting = $setting;
|
||||
}
|
||||
@ -58,23 +75,49 @@ class Base {
|
||||
}
|
||||
public function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
// Default to same error for crons
|
||||
$this->sCronError = $msg;
|
||||
}
|
||||
public function setCronMessage($msg) {
|
||||
// Used to overwrite any errors with a custom cron one
|
||||
$this->sCronError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
public function getErrorMsg($errCode) {
|
||||
/**
|
||||
* Additional information in error string for cronjobs logging
|
||||
**/
|
||||
public function getCronError() {
|
||||
return $this->sCronError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error message from error code array
|
||||
* @param errCode string Error code string
|
||||
* @param optional string Optional addtitional error strings to append
|
||||
* @retrun string Error Message
|
||||
**/
|
||||
public function getErrorMsg($errCode='') {
|
||||
if (!is_array($this->aErrorCodes)) return 'Error codes not loaded';
|
||||
if (!array_key_exists($errCode, $this->aErrorCodes)) return 'Unknown Error: ' . $errCode;
|
||||
if (!array_key_exists($errCode, $this->aErrorCodes)) return 'Unknown Error Code: ' . $errCode;
|
||||
if (func_num_args() > 1) {
|
||||
$sOutput = "";
|
||||
for ($i = 1; $i < func_num_args(); $i++) {
|
||||
$sOutput .= sprintf(" %s", func_get_arg($i));
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
$param_count = substr_count($this->aErrorCodes[$errCode], '%s');
|
||||
if ($param_count == count($args)) {
|
||||
return vsprintf($this->aErrorCodes[$errCode], $args);
|
||||
} else {
|
||||
return $this->aErrorCodes[$errCode] . ' (missing information to complete string)';
|
||||
}
|
||||
return sprintf($this->aErrorCodes[$errCode], $sOutput);
|
||||
} else {
|
||||
return $this->aErrorCodes[$errCode];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element as an associated array
|
||||
**/
|
||||
protected function getAllAssoc($value, $field='id', $type='i') {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE $field = ? LIMIT 1");
|
||||
@ -88,11 +131,15 @@ class Base {
|
||||
* @param search Return column to search for
|
||||
* @param field string Search column
|
||||
* @param type string Type of value
|
||||
* @param lower bool try with LOWER comparision
|
||||
* @return array Return result
|
||||
**/
|
||||
protected function getSingle($value, $search='id', $field='id', $type="i") {
|
||||
protected function getSingle($value, $search='id', $field='id', $type="i", $lower=false) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("SELECT $search FROM $this->table WHERE $field = ? LIMIT 1");
|
||||
$sql = "SELECT $search FROM $this->table WHERE";
|
||||
$lower ? $sql .= " LOWER($field) = LOWER(?)" : $sql .= " $field = ?";
|
||||
$sql .= " LIMIT 1";
|
||||
$stmt = $this->mysqli->prepare($sql);
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param($type, $value);
|
||||
$stmt->execute();
|
||||
@ -104,28 +151,38 @@ class Base {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the prepared statement is valid
|
||||
* @param $bState Statement return value
|
||||
* @return bool true or false
|
||||
**/
|
||||
function checkStmt($bState) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
return false;
|
||||
}
|
||||
if ($bState ===! true)
|
||||
return $this->sqlError();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Catch SQL errors with this method
|
||||
* @param error_code string Error code to read
|
||||
**/
|
||||
protected function sqlError() {
|
||||
protected function sqlError($error_code='E0020') {
|
||||
// More human-readable error for UI
|
||||
if (func_num_args() == 0) {
|
||||
$this->setErrorMessage($this->getErrorMsg($error_code));
|
||||
} else {
|
||||
$this->setErrorMessage(call_user_func_array(array($this, 'getErrorMsg'), func_get_args()));
|
||||
}
|
||||
// Default to SQL error for debug and cron errors
|
||||
$this->debug->append($this->getErrorMsg('E0019', $this->mysqli->error));
|
||||
$this->setErrorMessage($this->getErrorMsg('E0019', $this->mysqli->error));
|
||||
$this->setCronMessage($this->getErrorMsg('E0019', $this->mysqli->error));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a single row in a table
|
||||
* @param userID int Account ID
|
||||
* Update a single row in a table
|
||||
* @param field string Field to update
|
||||
* @return bool
|
||||
**/
|
||||
|
||||
@ -194,7 +194,8 @@ class Block extends Base {
|
||||
* @return bool
|
||||
**/
|
||||
public function setFinder($block_id, $account_id=NULL) {
|
||||
return $this->updateSingle($block_id, 'account_id', $account_id);
|
||||
$field = array( 'name' => 'account_id', 'value' => $account_id, 'type' => 'i' );
|
||||
return $this->updateSingle($block_id, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,7 +205,8 @@ class Block extends Base {
|
||||
* @return bool
|
||||
**/
|
||||
public function setShareId($block_id, $share_id) {
|
||||
return $this->updateSingle($block_id, 'share_id', $share_id);
|
||||
$field = array( 'name' => 'share_id', 'value' => $share_id, 'type' => 'i');
|
||||
return $this->updateSingle($block_id, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +216,8 @@ class Block extends Base {
|
||||
* @return bool
|
||||
**/
|
||||
public function setShares($block_id, $shares=NULL) {
|
||||
return $this->updateSingle($block_id, 'shares', $shares);
|
||||
$field = array( 'name' => 'shares', 'value' => $shares, 'type' => 'i');
|
||||
return $this->updateSingle($block_id, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,7 +227,8 @@ class Block extends Base {
|
||||
**/
|
||||
public function setAccounted($block_id=NULL) {
|
||||
if (empty($block_id)) return false;
|
||||
return $this->updateSingle($block_id, 'accounted', 1);
|
||||
$field = array( 'name' => 'accounted', 'value' => 1, 'type' => 'i');
|
||||
return $this->updateSingle($block_id, $field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,7 @@ class Invitation extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ?");
|
||||
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->setErrorMessage('Unable to fetch invitiations send from your account');
|
||||
$this->debug->append('Failed to fetch invitations from database: ' . $this->mysqli->errro);
|
||||
return false;
|
||||
$this->sqlError('E0021');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,9 +29,7 @@ class Invitation extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT count(id) AS total FROM $this->table WHERE account_id = ?");
|
||||
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $stmt->bind_result($total) && $stmt->fetch())
|
||||
return $total;
|
||||
$this->setErrorMessage('Unable to fetch invitiations send from your account');
|
||||
$this->debug->append('Failed to fetch invitations from database: ' . $this->mysqli->errro);
|
||||
return false;
|
||||
$this->sqlError('E0021');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +61,7 @@ class Invitation extends Base {
|
||||
**/
|
||||
public function setActivated($token_id) {
|
||||
if (!$iInvitationId = $this->getByTokenId($token_id)) {
|
||||
$this->setErrorMessage('Unable to convert token ID to invitation ID');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0030'));
|
||||
return false;
|
||||
}
|
||||
$field = array('name' => 'is_activated', 'type' => 'i', 'value' => 1);
|
||||
@ -84,8 +80,9 @@ class Invitation extends Base {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table ( account_id, email, token_id ) VALUES ( ?, ?, ?)");
|
||||
if ($stmt && $stmt->bind_param('isi', $account_id, $email, $token_id) && $stmt->execute())
|
||||
return true;
|
||||
return false;
|
||||
$this->sqlError('E0022');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an invitation out to a user
|
||||
* Uses the mail class to send mails
|
||||
@ -97,39 +94,37 @@ class Invitation extends Base {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
// Check data input
|
||||
if (empty($aData['email']) || !filter_var($aData['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
$this->setErrorMessage( 'Invalid e-mail address' );
|
||||
$this->setErrorMessage($this->getErrorMsg('E0023'));
|
||||
return false;
|
||||
}
|
||||
if (preg_match('/[^a-z_\.\!\?\-0-9 ]/i', $aData['message'])) {
|
||||
$this->setErrorMessage('Message may only contain alphanumeric characters');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0024'));
|
||||
return false;
|
||||
}
|
||||
// Ensure this invitation does not exist yet nor do we have an account with that email
|
||||
if ($this->user->getEmail($aData['email'])) {
|
||||
$this->setErrorMessage('This email is already registered as an account');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0025'));
|
||||
return false;
|
||||
}
|
||||
if ($this->getByEmail($aData['email'])) {
|
||||
$this->setErrorMessage('A pending invitation for this address already exists');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0026'));
|
||||
return false;
|
||||
}
|
||||
if (!$aData['token'] = $this->token->createToken('invitation', $account_id)) {
|
||||
$this->setErrorMessage('Unable to generate invitation token: ' . $this->token->getError());
|
||||
$this->setErrorMessage($this->getErrorMsg('E0027', $this->token->getError()));
|
||||
return false;
|
||||
}
|
||||
$aData['username'] = $this->user->getUserName($account_id);
|
||||
$aData['subject'] = 'Pending Invitation';
|
||||
if ($this->mail->sendMail('invitations/body', $aData)) {
|
||||
$aToken = $this->token->getToken($aData['token']);
|
||||
if (!$this->createInvitation($account_id, $aData['email'], $aToken['id'])) {
|
||||
$this->setErrorMessage('Unable to create invitation record');
|
||||
if (!$this->createInvitation($account_id, $aData['email'], $aToken['id']))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
$this->setErrorMessage('Unable to send email to recipient');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0028'));
|
||||
}
|
||||
$this->setErrorMessage('Unable to send invitation');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0029'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -142,5 +137,5 @@ $invitation->setMail($mail);
|
||||
$invitation->setUser($user);
|
||||
$invitation->setToken($oToken);
|
||||
$invitation->setConfig($config);
|
||||
|
||||
$invitation->setErrorCodes($aErrorCodes);
|
||||
?>
|
||||
|
||||
@ -5,16 +5,6 @@ if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Mail extends Base {
|
||||
function checkStmt($bState) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mail form contact site admin
|
||||
* @param senderName string senderName
|
||||
@ -28,19 +18,19 @@ class Mail extends Base {
|
||||
public function contactform($senderName, $senderEmail, $senderSubject, $senderMessage) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if (preg_match('/[^a-z_\.\!\?\-0-9\\s ]/i', $senderName)) {
|
||||
$this->setErrorMessage('Username may only contain alphanumeric characters');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0024'));
|
||||
return false;
|
||||
}
|
||||
if (empty($senderEmail) || !filter_var($senderEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->setErrorMessage( 'Invalid e-mail address' );
|
||||
$this->setErrorMessage($this->getErrorMsg('E0023'));
|
||||
return false;
|
||||
}
|
||||
if (preg_match('/[^a-z_\.\!\?\-0-9\\s ]/i', $senderSubject)) {
|
||||
$this->setErrorMessage('Subject may only contain alphanumeric characters');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0034'));
|
||||
return false;
|
||||
}
|
||||
if (strlen(strip_tags($senderMessage)) < strlen($senderMessage)) {
|
||||
$this->setErrorMessage('Your message may only contain alphanumeric characters');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0024'));
|
||||
return false;
|
||||
}
|
||||
$aData['senderName'] = $senderName;
|
||||
@ -58,6 +48,13 @@ class Mail extends Base {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a mail with templating via Smarty
|
||||
* @param template string Template name within the mail folder, no extension
|
||||
* @param aData array Data array with some required fields
|
||||
* SUBJECT : Mail Subject
|
||||
* email : Destination address
|
||||
**/
|
||||
public function sendMail($template, $aData) {
|
||||
$this->smarty->assign('WEBSITENAME', $this->setting->getValue('website_name'));
|
||||
$this->smarty->assign('SUBJECT', $aData['subject']);
|
||||
@ -67,7 +64,7 @@ class Mail extends Base {
|
||||
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
|
||||
if (mail($aData['email'], $this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'), $this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), $headers))
|
||||
return true;
|
||||
$this->setErrorMessage('Unable to send mail');
|
||||
$this->setErrorMessage($this->sqlError('E0031'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -79,4 +76,5 @@ $mail->setMysql($mysqli);
|
||||
$mail->setSmarty($smarty);
|
||||
$mail->setConfig($config);
|
||||
$mail->setSetting($setting);
|
||||
$mail->setErrorCodes($aErrorCodes);
|
||||
?>
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
if (!defined('SECURITY')) die('Hacking attempt');
|
||||
|
||||
class Monitoring extends Base {
|
||||
public function __construct() {
|
||||
$this->table = 'monitoring';
|
||||
}
|
||||
protected $table = 'monitoring';
|
||||
|
||||
/**
|
||||
* Store Uptime Robot status information as JSON in settings table
|
||||
@ -27,9 +24,9 @@ class Monitoring extends Base {
|
||||
$aMonitorStatus = $this->tools->getApi($url, $target);
|
||||
if (!$aMonitorStatus || @$aMonitorStatus['stat'] == 'fail') {
|
||||
if (is_array($aMonitorStatus) && array_key_exists('message', @$aMonitorStatus)) {
|
||||
$this->setErrorMessage('Failed to run API call: ' . $aMonitorStatus['message']);
|
||||
$this->setErrorMessage($this->getErrorMsg('E0032', $aMonitorStatus['message']));
|
||||
} else {
|
||||
$this->setErrorMessage('Failed to run API call: ' . $this->tools->getError());
|
||||
$this->setErrorMessage($this->getErrorMsg('E0032', $this->tools->getError()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -37,7 +34,7 @@ class Monitoring extends Base {
|
||||
$aAllMonitorsStatus[] = $aMonitorStatus['monitors']['monitor'][0];
|
||||
}
|
||||
if (!$this->setting->setValue('monitoring_uptimerobot_status', json_encode($aAllMonitorsStatus)) || !$this->setting->setValue('monitoring_uptimerobot_lastcheck', time())) {
|
||||
$this->setErrorMessage('Failed to store uptime status: ' . $setting->getError());
|
||||
$this->setErrorMessage($this->getErrorMsg('E0033'), $setting->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -75,8 +72,7 @@ class Monitoring extends Base {
|
||||
if ($query && $query->bind_param('s', $name) && $query->execute() && $result = $query->get_result()) {
|
||||
return $result->fetch_assoc();
|
||||
} else {
|
||||
$this->debug->append("Failed to fetch variable $name from $this->table");
|
||||
return false;
|
||||
$this->sqlError();
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -5,13 +5,23 @@ if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class News extends Base {
|
||||
var $table = 'news';
|
||||
protected $table = 'news';
|
||||
|
||||
/**
|
||||
* Get activation status of post
|
||||
* @param id int News ID
|
||||
* @return bool true or false
|
||||
**/
|
||||
public function getActive($id) {
|
||||
$this->debug->append("STA " . __METHOD__, 5);
|
||||
return $this->getSingle($id, 'active', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch activation status
|
||||
* @param id int News ID
|
||||
* @return bool true or false
|
||||
**/
|
||||
public function toggleActive($id) {
|
||||
$this->debug->append("STA " . __METHOD__, 5);
|
||||
$field = array('name' => 'active', 'type' => 'i', 'value' => !$this->getActive($id));
|
||||
@ -26,8 +36,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT n.*, a.username AS author FROM $this->table AS n LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = n.account_id WHERE active = 1 ORDER BY time DESC");
|
||||
if ($stmt && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError('E0040');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,8 +47,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT n.*, a.username AS author FROM $this->table AS n LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = n.account_id ORDER BY time DESC");
|
||||
if ($stmt && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError('E0039');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,8 +58,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE id = ?");
|
||||
if ($stmt && $stmt->bind_param('i', $id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError('E0038');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,8 +69,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET content = ?, header = ?, active = ? WHERE id = ?");
|
||||
if ($stmt && $stmt->bind_param('ssii', $content, $header, $active, $id) && $stmt->execute() && $stmt->affected_rows == 1)
|
||||
return true;
|
||||
$this->setErrorMessage("Failed to update news entry $id");
|
||||
return false;
|
||||
return $this->sqlError('E0037');
|
||||
}
|
||||
|
||||
public function deleteNews($id) {
|
||||
@ -72,8 +78,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $id) && $stmt->execute() && $stmt->affected_rows == 1)
|
||||
return true;
|
||||
$this->setErrorMessage("Failed to delete news entry $id");
|
||||
return false;
|
||||
return $this->sqlError('E0036');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,9 +94,7 @@ class News extends Base {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, header, content, active) VALUES (?,?,?,?)");
|
||||
if ($stmt && $stmt->bind_param('issi', $account_id, $aData['header'], $aData['content'], $active) && $stmt->execute())
|
||||
return true;
|
||||
$this->debug->append("Failed to add news: " . $this->mysqli->error);
|
||||
$this->setErrorMessage("Unable to add new news: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0035');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,9 +27,7 @@ class Notification extends Mail {
|
||||
$stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE data = ? AND active = 1 LIMIT 1");
|
||||
if ($stmt && $stmt->bind_param('s', $data) && $stmt->execute() && $stmt->store_result() && $stmt->num_rows == 1)
|
||||
return true;
|
||||
// Catchall
|
||||
// Does not seem to have a notification set
|
||||
return false;
|
||||
return $this->sqlError('E0041');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,11 +35,10 @@ class Notification extends Mail {
|
||||
**/
|
||||
public function getAllActive($strType) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt =$this->mysqli->prepare("SELECT id, data FROM $this->table WHERE active = 1 AND type = ?");
|
||||
$stmt =$this->mysqli->prepare("SELECT id2, data FROM $this->table WHERE active = 1 AND type = ?");
|
||||
if ($stmt && $stmt->bind_param('s', $strType) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError('E0042');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,9 +53,7 @@ class Notification extends Mail {
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, type, data, active) VALUES (?, ?,?,1)");
|
||||
if ($stmt && $stmt->bind_param('iss', $account_id, $type, $data) && $stmt->execute())
|
||||
return true;
|
||||
$this->debug->append("Failed to add notification for $type with $data: " . $this->mysqli->error);
|
||||
$this->setErrorMessage("Unable to add new notification " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0043');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,8 +66,7 @@ class Notification extends Mail {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ? ORDER BY time DESC");
|
||||
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->getError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,10 +85,7 @@ class Notification extends Mail {
|
||||
return $aData;
|
||||
}
|
||||
}
|
||||
// Catchall
|
||||
$this->setErrorMessage('Unable to fetch notification settings');
|
||||
$this->debug->append('Failed fetching notification settings for ' . $account_id . ': ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0045');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,8 +99,7 @@ class Notification extends Mail {
|
||||
if ($stmt && $stmt->bind_param('s', $strType) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError('E0046');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +132,7 @@ class Notification extends Mail {
|
||||
}
|
||||
}
|
||||
if ($failed > 0) {
|
||||
$this->setErrorMessage('Failed to update ' . $failed . ' settings');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0047', $failed));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -183,4 +173,5 @@ $notification->setMysql($mysqli);
|
||||
$notification->setSmarty($smarty);
|
||||
$notification->setConfig($config);
|
||||
$notification->setSetting($setting);
|
||||
$notification->setErrorCodes($aErrorCodes);
|
||||
?>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
if (!defined('SECURITY')) die('Hacking attempt');
|
||||
|
||||
class Payout Extends Base {
|
||||
var $table = 'payouts';
|
||||
protected $table = 'payouts';
|
||||
|
||||
/**
|
||||
* Check if the user has an active payout request already
|
||||
@ -15,7 +15,7 @@ class Payout Extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT id FROM $this->table WHERE completed = 0 AND account_id = ? LIMIT 1");
|
||||
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute( )&& $stmt->store_result() && $stmt->num_rows > 0)
|
||||
return true;
|
||||
return false;
|
||||
return $this->sqlError('E0048');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ class Payout Extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE completed = 0");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
return $this->sqlError('E0050');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,9 +40,7 @@ class Payout Extends Base {
|
||||
if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute()) {
|
||||
return $stmt->insert_id;
|
||||
}
|
||||
$this->setErrorMessage('Unable to create new payout request');
|
||||
$this->debug->append('Failed to create new payout request in database: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0049');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,10 +52,13 @@ class Payout Extends Base {
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET completed = 1 WHERE id = ?");
|
||||
if ($stmt && $stmt->bind_param('i', $id) && $stmt->execute())
|
||||
return true;
|
||||
return false;
|
||||
return $this->sqlError('E0051');
|
||||
}
|
||||
}
|
||||
|
||||
$oPayout = new Payout();
|
||||
$oPayout->setDebug($debug);
|
||||
$oPayout->setMysql($mysqli);
|
||||
$oPayout->setErrorCodes($aErrorCodes);
|
||||
|
||||
?>
|
||||
|
||||
@ -4,41 +4,25 @@
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class RoundStats {
|
||||
private $sError = '';
|
||||
class RoundStats extends Base {
|
||||
private $tableTrans = 'transactions';
|
||||
private $tableStats = 'statistics_shares';
|
||||
private $tableBlocks = 'blocks';
|
||||
private $tableUsers = 'accounts';
|
||||
|
||||
public function __construct($debug, $mysqli, $config) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->config = $config;
|
||||
$this->debug->append("Instantiated RoundStats class", 2);
|
||||
}
|
||||
|
||||
// get and set methods
|
||||
private function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next block for round stats
|
||||
**/
|
||||
public function getNextBlock($iHeight=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT height
|
||||
FROM $this->tableBlocks
|
||||
FROM " . $this->block->getTableName() . "
|
||||
WHERE height > ?
|
||||
ORDER BY height ASC
|
||||
LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,13 +31,13 @@ class RoundStats {
|
||||
public function getPreviousBlock($iHeight=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT height
|
||||
FROM $this->tableBlocks
|
||||
FROM " . $this->block->getTableName() . "
|
||||
WHERE height < ?
|
||||
ORDER BY height DESC
|
||||
LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,13 +46,13 @@ class RoundStats {
|
||||
public function searchForBlockHeight($iHeight=0) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT height
|
||||
FROM $this->tableBlocks
|
||||
FROM " . $this->block->getTableName() . "
|
||||
WHERE height >= ?
|
||||
ORDER BY height ASC
|
||||
LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,13 +60,15 @@ class RoundStats {
|
||||
**/
|
||||
public function getNextBlockForStats($iHeight=0, $limit=10) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT MAX(x.height) AS height
|
||||
FROM (SELECT height FROM $this->tableBlocks
|
||||
WHERE height >= ?
|
||||
ORDER BY height ASC LIMIT ?) AS x");
|
||||
SELECT MAX(x.height) AS height
|
||||
FROM (
|
||||
SELECT height FROM " . $this->block->getTableName() . "
|
||||
WHERE height >= ?
|
||||
ORDER BY height ASC LIMIT ?
|
||||
) AS x");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $iHeight, $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->height;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,14 +81,14 @@ class RoundStats {
|
||||
SELECT
|
||||
b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares,
|
||||
IF(a.is_anonymous, 'anonymous', a.username) AS finder,
|
||||
ROUND((difficulty * 65535) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares,
|
||||
ROUND((difficulty * 65535) / POW(2, (" . $this->config['difficulty'] . " -16)), 0) AS estshares,
|
||||
(time - (SELECT time FROM $this->tableBlocks WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time
|
||||
FROM $this->tableBlocks as b
|
||||
LEFT JOIN $this->tableUsers AS a ON b.account_id = a.id
|
||||
WHERE b.height = ? LIMIT 1");
|
||||
FROM " . $this->block->getTableName() . " as b
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id
|
||||
WHERE b.height = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iHeight, $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,9 +104,9 @@ class RoundStats {
|
||||
a.is_anonymous,
|
||||
s.valid,
|
||||
s.invalid
|
||||
FROM $this->tableStats AS s
|
||||
LEFT JOIN $this->tableBlocks AS b ON s.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON a.id = s.account_id
|
||||
FROM " . $this->statistics->getTableName() . " AS s
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||
WHERE b.height = ?
|
||||
GROUP BY username ASC
|
||||
ORDER BY valid DESC
|
||||
@ -131,7 +117,7 @@ class RoundStats {
|
||||
}
|
||||
return $aData;
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,16 +132,16 @@ class RoundStats {
|
||||
a.is_anonymous,
|
||||
s.pplns_valid,
|
||||
s.pplns_invalid
|
||||
FROM $this->tableStats AS s
|
||||
LEFT JOIN $this->tableBlocks AS b ON s.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON a.id = s.account_id
|
||||
FROM " . $this->statistics->getTableName() . " AS s
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||
WHERE b.height = ?
|
||||
GROUP BY username ASC
|
||||
ORDER BY pplns_valid DESC
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,13 +151,13 @@ class RoundStats {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
SUM(s.pplns_valid) AS pplns_valid
|
||||
FROM $this->tableStats AS s
|
||||
LEFT JOIN $this->tableBlocks AS b ON s.block_id = b.id
|
||||
FROM " . $this->statistics->getTableName() . " AS s
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||
WHERE b.height = ?
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->pplns_valid;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,15 +175,15 @@ class RoundStats {
|
||||
a.is_anonymous,
|
||||
t.type AS type,
|
||||
t.amount AS amount
|
||||
FROM $this->tableTrans AS t
|
||||
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON t.account_id = a.id
|
||||
FROM " . $this->transaction->getTableName() . " AS t
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id
|
||||
WHERE b.height = ? AND t.type = 'Credit'
|
||||
ORDER BY amount DESC");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->debug->append('Unable to fetch transactions');
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,15 +200,15 @@ class RoundStats {
|
||||
a.username AS username,
|
||||
t.type AS type,
|
||||
t.amount AS amount
|
||||
FROM $this->tableTrans AS t
|
||||
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON t.account_id = a.id
|
||||
FROM " . $this->transaction->getTableName() . " AS t
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id
|
||||
WHERE b.height = ? AND a.id = ?
|
||||
ORDER BY id ASC");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iHeight, $id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->debug->append('Unable to fetch transactions');
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,12 +218,12 @@ class RoundStats {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
height, shares
|
||||
FROM $this->tableBlocks
|
||||
FROM " . $this->block->getTableName() . "
|
||||
WHERE height <= ?
|
||||
ORDER BY height DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $iHeight, $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,14 +233,14 @@ class RoundStats {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
b.height, b.shares
|
||||
FROM $this->tableBlocks AS b
|
||||
LEFT JOIN $this->tableStats AS s ON s.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON a.id = s.account_id
|
||||
FROM " . $this->block->getTableName() . " AS b
|
||||
LEFT JOIN " . $this->statistics->getTableName() . " AS s ON s.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||
WHERE b.height <= ? AND a.id = ?
|
||||
ORDER BY height DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $iHeight, $iUser, $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,13 +253,13 @@ class RoundStats {
|
||||
s.invalid,
|
||||
s.pplns_valid,
|
||||
s.pplns_invalid
|
||||
FROM $this->tableStats AS s
|
||||
LEFT JOIN $this->tableBlocks AS b ON s.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON a.id = s.account_id
|
||||
FROM " . $this->statistics->getTableName() . " AS s
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||
WHERE b.height = ? AND a.id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iHeight, $iUser) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -284,47 +270,23 @@ class RoundStats {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
IFNULL(t.amount, 0) AS amount
|
||||
FROM $this->tableTrans AS t
|
||||
LEFT JOIN $this->tableBlocks AS b ON t.block_id = b.id
|
||||
LEFT JOIN $this->tableUsers AS a ON t.account_id = a.id
|
||||
FROM " . $this->transaction->getTableName() . " AS t
|
||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id
|
||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON t.account_id = a.id
|
||||
WHERE b.height = ? AND t.type = 'Credit' AND t.account_id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iHeight, $iUser) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->amount;
|
||||
$this->debug->append('Unable to fetch transactions');
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users for admin panel
|
||||
**/
|
||||
public function getAllUsers($filter='%') {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
a.id AS id,
|
||||
a.username AS username
|
||||
FROM $this->tableUsers AS a
|
||||
WHERE a.username LIKE ?
|
||||
GROUP BY username
|
||||
ORDER BY username");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$aData[$row['id']] = $row['username'];
|
||||
}
|
||||
return $aData;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$roundstats = new RoundStats($debug, $mysqli, $config);
|
||||
$roundstats = new RoundStats();
|
||||
$roundstats->setDebug($debug);
|
||||
$roundstats->setMysql($mysqli);
|
||||
$roundstats->setConfig($config);
|
||||
$roundstats->setErrorCodes($aErrorCodes);
|
||||
$roundstats->setUser($user);
|
||||
$roundstats->setStatistics($statistics);
|
||||
$roundstats->setBlock($block);
|
||||
$roundstats->setTransaction($transaction);
|
||||
|
||||
@ -12,18 +12,10 @@ class Setting extends Base {
|
||||
* @return value string Value
|
||||
**/
|
||||
public function getValue($name) {
|
||||
$query = $this->mysqli->prepare("SELECT value FROM $this->table WHERE name=? LIMIT 1");
|
||||
if ($query) {
|
||||
$query->bind_param('s', $name);
|
||||
$query->execute();
|
||||
$query->bind_result($value);
|
||||
$query->fetch();
|
||||
$query->close();
|
||||
} else {
|
||||
$this->debug->append("Failed to fetch variable $name from $this->table");
|
||||
return false;
|
||||
}
|
||||
return $value;
|
||||
$stmt = $this->mysqli->prepare("SELECT value FROM $this->table WHERE name = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $name) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->value;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,15 +28,14 @@ class Setting extends Base {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
INSERT INTO $this->table (name, value)
|
||||
VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE value = ?
|
||||
");
|
||||
ON DUPLICATE KEY UPDATE value = ?");
|
||||
if ($stmt && $stmt->bind_param('sss', $name, $value, $value) && $stmt->execute())
|
||||
return true;
|
||||
$this->debug->append("Failed to set $name to $value");
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
}
|
||||
|
||||
$setting = new Setting($debug, $mysqli);
|
||||
$setting->setDebug($debug);
|
||||
$setting->setMysql($mysqli);
|
||||
$setting->setErrorCodes($aErrorCodes);
|
||||
|
||||
@ -6,21 +6,12 @@ if (!defined('SECURITY'))
|
||||
|
||||
class Share Extends Base {
|
||||
protected $table = 'shares';
|
||||
private $tableArchive = 'shares_archive';
|
||||
protected $tableArchive = 'shares_archive';
|
||||
private $oUpstream;
|
||||
private $iLastUpstreamId;
|
||||
// This defines each share
|
||||
public $rem_host, $username, $our_result, $upstream_result, $reason, $solution, $time, $difficulty;
|
||||
|
||||
public function __construct($debug, $mysqli, $user, $block, $config) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->user = $user;
|
||||
$this->config = $config;
|
||||
$this->block = $block;
|
||||
$this->debug->append("Instantiated Share class", 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch archive tables name for this class
|
||||
* @param none
|
||||
@ -65,7 +56,7 @@ class Share Extends Base {
|
||||
$stmt = $this->mysqli->prepare($sql);
|
||||
if ($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute())
|
||||
return true;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,14 +64,10 @@ class Share Extends Base {
|
||||
* Used for PPS calculations without moving to archive
|
||||
**/
|
||||
public function getLastInsertedShareId() {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT MAX(id) AS id FROM $this->table
|
||||
");
|
||||
$stmt = $this->mysqli->prepare("SELECT MAX(id) AS id FROM $this->table");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->id;
|
||||
// Catchall
|
||||
$this->setErrorMessage('Failed to fetch last inserted share ID');
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,14 +83,9 @@ class Share Extends Base {
|
||||
WHERE our_result = 'Y'
|
||||
AND id > ? AND id <= ?
|
||||
");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $previous_upstream, $current_upstream);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$stmt->close();
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $previous_upstream, $current_upstream) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->total;
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,7 +111,7 @@ class Share Extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $previous_upstream, $current_upstream) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,19 +121,17 @@ class Share Extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT MAX(id) AS id FROM $this->table");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->id;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the highest available share ID from archive
|
||||
**/
|
||||
function getMaxArchiveShareId() {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT MAX(share_id) AS share_id FROM $this->tableArchive
|
||||
");
|
||||
$stmt = $this->mysqli->prepare("SELECT MAX(share_id) AS share_id FROM $this->tableArchive");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->share_id;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,7 +162,7 @@ class Share Extends Base {
|
||||
}
|
||||
if (is_array($aData)) return $aData;
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,8 +186,7 @@ class Share Extends Base {
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $this->config['archive']['maxage']) && $stmt->execute())
|
||||
return true;
|
||||
}
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,22 +202,22 @@ class Share Extends Base {
|
||||
SELECT id, username, our_result, upstream_result, ?, time, IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
|
||||
FROM $this->table
|
||||
WHERE id > ? AND id <= ?");
|
||||
if ($this->checkStmt($archive_stmt) && $archive_stmt->bind_param('iii', $block_id, $previous_upstream, $current_upstream) && $archive_stmt->execute()) {
|
||||
$archive_stmt->close();
|
||||
if ($this->checkStmt($archive_stmt) && $archive_stmt->bind_param('iii', $block_id, $previous_upstream, $current_upstream) && $archive_stmt->execute())
|
||||
return true;
|
||||
}
|
||||
// Catchall
|
||||
$this->setErrorMessage('Archiving shares failed: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete accounted shares from shares table
|
||||
* @param current_upstream int Current highest upstream ID
|
||||
* @param previous_upstream int Previous upstream ID
|
||||
* @return bool true or false
|
||||
**/
|
||||
public function deleteAccountedShares($current_upstream, $previous_upstream=0) {
|
||||
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE id > ? AND id <= ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $previous_upstream, $current_upstream) && $stmt->execute())
|
||||
return true;
|
||||
// Catchall
|
||||
$this->setErrorMessage('Deleting shares failed: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
/**
|
||||
* Set/get last found share accepted by upstream: id and accounts
|
||||
@ -336,8 +315,7 @@ class Share Extends Base {
|
||||
if (!empty($this->oUpstream->account) && is_int($this->oUpstream->id))
|
||||
return true;
|
||||
}
|
||||
// Catchall
|
||||
return false;
|
||||
return $this->getErrorMsg('E0052', $aBlock['height']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,11 +333,10 @@ class Share Extends Base {
|
||||
AND id <= ? AND @total < ?
|
||||
ORDER BY id DESC
|
||||
) AS b
|
||||
WHERE total <= ?
|
||||
");
|
||||
WHERE total <= ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $current_upstream, $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->id;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,13 +358,14 @@ class Share Extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $iCount, $iCount) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->share_id;
|
||||
$this->setErrorMessage("Failed fetching additional shares from archive: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
}
|
||||
|
||||
$share = new Share($debug, $mysqli, $user, $block, $config);
|
||||
$share = new Share();
|
||||
$share->setDebug($debug);
|
||||
$share->setMysql($mysqli);
|
||||
$share->setConfig($config);
|
||||
$share->setUser($user);
|
||||
$share->setBlock($block);
|
||||
$share->setErrorCodes($aErrorCodes);
|
||||
|
||||
@ -10,31 +10,10 @@ if (!defined('SECURITY'))
|
||||
* Statistics should be non-intrusive and not change any
|
||||
* rows in our database to ensure data integrity for the backend
|
||||
**/
|
||||
class Statistics {
|
||||
private $sError = '';
|
||||
private $table = 'statistics_shares';
|
||||
class Statistics extends Base {
|
||||
protected $table = 'statistics_shares';
|
||||
private $getcache = true;
|
||||
|
||||
public function __construct($debug, $mysqli, $config, $share, $user, $block, $memcache) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->share = $share;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
$this->block = $block;
|
||||
$this->memcache = $memcache;
|
||||
$this->debug->append("Instantiated Share class", 2);
|
||||
}
|
||||
|
||||
/* Some basic get and set methods
|
||||
**/
|
||||
private function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
|
||||
// Disable fetching values from cache
|
||||
public function setGetCache($set=false) {
|
||||
$this->getcache = $set;
|
||||
@ -43,15 +22,6 @@ class Statistics {
|
||||
return $this->getcache;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Failed to prepare statement');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch last found blocks by time
|
||||
**/
|
||||
@ -64,17 +34,12 @@ class Statistics {
|
||||
if ($aTimeFrame == 0) $aTimeDiff = 0;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT COUNT(id) AS count FROM " . $this->block->getTableName() . "
|
||||
WHERE confirmations > 0
|
||||
AND time >= ?
|
||||
");
|
||||
|
||||
WHERE confirmations > 0
|
||||
AND time >= ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $aTimeDiff) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $aTimeFrame, $result->fetch_object()->count);
|
||||
$this->debug->append("Failed to get valid Blocks by time: ". $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getLastOrphanBlocksbyTime($aTimeFrame) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
@ -85,16 +50,12 @@ class Statistics {
|
||||
if ($aTimeFrame == 0) $aTimeDiff = 0;
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT COUNT(id) AS count FROM " . $this->block->getTableName() . "
|
||||
WHERE confirmations = -1
|
||||
AND time >= ?
|
||||
");
|
||||
|
||||
WHERE confirmations = -1
|
||||
AND time >= ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $aTimeDiff) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $aTimeFrame, $result->fetch_object()->count);
|
||||
$this->debug->append("Failed to get orphan Blocks by time: ". $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get our last $limit blocks found
|
||||
@ -116,9 +77,7 @@ class Statistics {
|
||||
ORDER BY height DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $limit, $result->fetch_all(MYSQLI_ASSOC), 5);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to find blocks:" . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,9 +101,7 @@ class Statistics {
|
||||
ORDER BY height DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $iHeight, $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $iHeight . $limit, $result->fetch_all(MYSQLI_ASSOC), 5);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to find blocks:" . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,9 +115,7 @@ class Statistics {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
|
||||
// Catchall
|
||||
$this->debug->append("Failed to update share stats: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,9 +126,7 @@ class Statistics {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
UPDATE $this->table SET pplns_valid = ?, pplns_invalid = ? WHERE account_id = ? AND block_id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['valid'], $aStats['invalid'], $aStats['id'], $iBlockId) && $stmt->execute()) return true;
|
||||
// Catchall
|
||||
$this->debug->append("Failed to update pplns share stats: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,9 +136,7 @@ class Statistics {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, 0, 0, ?, ?, ?)");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
|
||||
// Catchall
|
||||
$this->debug->append("Failed to insert pplns share stats: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +149,7 @@ class Statistics {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $aStats['id'], $iBlockId) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->id;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,10 +177,8 @@ class Statistics {
|
||||
)
|
||||
) AS hashrate
|
||||
FROM DUAL");
|
||||
// Catchall
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->hashrate);
|
||||
$this->debug->append("Failed to get hashrate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,9 +206,7 @@ class Statistics {
|
||||
) AS sharerate
|
||||
FROM DUAL");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $interval, $interval, $interval, $interval) && $stmt->execute() && $result = $stmt->get_result() ) return $this->memcache->setCache(__FUNCTION__, $result->fetch_object()->sharerate);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch share rate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,9 +238,7 @@ class Statistics {
|
||||
WHERE UNIX_TIMESTAMP(time) > IFNULL((SELECT MAX(time) FROM " . $this->block->getTableName() . "), 0)");
|
||||
if ( $this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(STATISTICS_ROUND_SHARES, $result->fetch_assoc());
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch round shares: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,9 +286,7 @@ class Statistics {
|
||||
$data['share_id'] = $this->share->getMaxShareId();
|
||||
return $this->memcache->setCache(STATISTICS_ALL_USER_SHARES, $data);
|
||||
}
|
||||
// Catchall
|
||||
$this->debug->append("Unable to fetch all users round shares: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,9 +316,7 @@ class Statistics {
|
||||
AND u.id = ?");
|
||||
if ($stmt && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc());
|
||||
// Catchall
|
||||
$this->debug->append("Unable to fetch user round shares: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -402,9 +343,9 @@ class Statistics {
|
||||
a.username LIKE ?
|
||||
GROUP BY username
|
||||
ORDER BY username");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $filter, $result->fetch_all(MYSQLI_ASSOC));
|
||||
}
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -437,9 +378,7 @@ class Statistics {
|
||||
FROM DUAL");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiiii", $interval, $interval, $account_id, $interval, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->hashrate);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch hashrate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
public function getUserUnpaidPPSShares($account_id, $last_paid_pps_id) {
|
||||
@ -456,8 +395,7 @@ class Statistics {
|
||||
WHERE our_result = 'Y'");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $account_id, $last_paid_pps_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->total);
|
||||
$this->debug->append("Failed fetching average share dificulty: " . $this->mysqli->error, 3);
|
||||
return 0;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,8 +418,7 @@ class Statistics {
|
||||
AND a.id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("ii", $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->avgsharediff);
|
||||
$this->debug->append("Failed fetching average share dificulty: " . $this->mysqli->error, 3);
|
||||
return 0;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,9 +453,7 @@ class Statistics {
|
||||
FROM DUAL");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiiii", $interval, $interval, $account_id, $interval, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_object()->sharerate);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch sharerate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -539,9 +474,7 @@ class Statistics {
|
||||
AND u.id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result() )
|
||||
return $this->memcache->setCache(__FUNCTION__ . $worker_id, $result->fetch_object()->hashrate);
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch hashrate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -591,8 +524,7 @@ class Statistics {
|
||||
LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $type . $limit, $result->fetch_all(MYSQLI_ASSOC));
|
||||
$this->debug->append("Fetching shares failed: ");
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
break;
|
||||
|
||||
case 'hashes':
|
||||
@ -614,8 +546,7 @@ class Statistics {
|
||||
ORDER BY hashrate DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $type . $limit, $result->fetch_all(MYSQLI_ASSOC));
|
||||
$this->debug->append("Fetching shares failed: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -658,9 +589,7 @@ class Statistics {
|
||||
while ($row = $result->fetch_assoc()) $aData[$row['hour']] = $row['hashrate'];
|
||||
return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData);
|
||||
}
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -697,9 +626,7 @@ class Statistics {
|
||||
while ($row = $result->fetch_assoc()) $aData[$row['hour']] = (int) $row['hashrate'];
|
||||
return $this->memcache->setCache(__FUNCTION__, $aData);
|
||||
}
|
||||
// Catchall
|
||||
$this->debug->append("Failed to fetch hourly hashrate: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -767,9 +694,7 @@ class Statistics {
|
||||
AND confirmations >= 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $hour) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $this->memcache->setCache(__FUNCTION__ . $hour, $result->fetch_assoc());
|
||||
// Catchall
|
||||
$this->debug->append("Failed to get pool statistics:" . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -782,5 +707,14 @@ class Statistics {
|
||||
}
|
||||
}
|
||||
|
||||
$statistics = new Statistics();
|
||||
$statistics->setDebug($debug);
|
||||
$statistics->setMysql($mysqli);
|
||||
$statistics->setShare($share);
|
||||
$statistics->setUser($user);
|
||||
$statistics->setBlock($block);
|
||||
$statistics->setMemcache($memcache);
|
||||
$statistics->setConfig($config);
|
||||
$statistics->setErrorCodes($aErrorCodes);
|
||||
|
||||
$statistics = new Statistics($debug, $mysqli, $config, $share, $user, $block, $memcache);
|
||||
?>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
if (!defined('SECURITY')) die('Hacking attempt');
|
||||
|
||||
class Token Extends Base {
|
||||
var $table = 'tokens';
|
||||
protected $table = 'tokens';
|
||||
|
||||
/**
|
||||
* Fetch a token from our table
|
||||
@ -15,7 +15,7 @@ class Token Extends Base {
|
||||
$stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE token = ? LIMIT 1");
|
||||
if ($stmt && $stmt->bind_param('s', $strToken) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,9 +36,7 @@ class Token Extends Base {
|
||||
");
|
||||
if ($stmt && $stmt->bind_param('sii', $strToken, $iToken_id, $account_id) && $stmt->execute())
|
||||
return $strToken;
|
||||
$this->setErrorMessage('Unable to create new token');
|
||||
$this->debug->append('Failed to create new token in database: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +48,7 @@ class Token Extends Base {
|
||||
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE token = ? LIMIT 1");
|
||||
if ($stmt && $stmt->bind_param('s', $token) && $stmt->execute())
|
||||
return true;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,3 +56,4 @@ $oToken = new Token();
|
||||
$oToken->setDebug($debug);
|
||||
$oToken->setMysql($mysqli);
|
||||
$oToken->setTokenType($tokentype);
|
||||
$oToken->setErrorCodes($aErrorCodes);
|
||||
|
||||
@ -5,7 +5,8 @@ if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Token_Type Extends Base {
|
||||
var $table = 'token_types';
|
||||
protected $table = 'token_types';
|
||||
|
||||
/**
|
||||
* Return ID for specific token
|
||||
* @param strName string Token Name
|
||||
@ -19,3 +20,4 @@ class Token_Type Extends Base {
|
||||
$tokentype = new Token_Type();
|
||||
$tokentype->setDebug($debug);
|
||||
$tokentype->setMysql($mysqli);
|
||||
$tokentype->setErrorCodes($aErrorCodes);
|
||||
|
||||
@ -5,7 +5,6 @@ if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Transaction extends Base {
|
||||
private $sError = '';
|
||||
protected $table = 'transactions';
|
||||
public $num_rows = 0, $insert_id = 0;
|
||||
|
||||
@ -25,8 +24,7 @@ class Transaction extends Base {
|
||||
$this->insert_id = $stmt->insert_id;
|
||||
return true;
|
||||
}
|
||||
$this->setErrorMessage("Failed to store transaction");
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -45,7 +43,7 @@ class Transaction extends Base {
|
||||
OR ( t.account_id = ? AND t.id <= ? AND t.type IN ( 'Credit_PPS', 'Donation_PPS', 'Fee_PPS', 'TXFee', 'Debit_MP', 'Debit_AP' ) )");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiii', $account_id, $txid, $this->config['confirmations'], $account_id, $txid) && $stmt->execute())
|
||||
return true;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,8 +58,7 @@ class Transaction extends Base {
|
||||
FROM transactions AS t
|
||||
LEFT OUTER JOIN blocks AS b
|
||||
ON b.id = t.block_id
|
||||
WHERE ( b.confirmations > 0 OR b.id IS NULL )
|
||||
";
|
||||
WHERE ( b.confirmations > 0 OR b.id IS NULL )";
|
||||
if (!empty($account_id)) {
|
||||
$sql .= " AND t.account_id = ? ";
|
||||
$this->addParam('i', $account_id);
|
||||
@ -84,7 +81,7 @@ class Transaction extends Base {
|
||||
}
|
||||
return $aData;
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +149,7 @@ class Transaction extends Base {
|
||||
}
|
||||
}
|
||||
if (!empty($aFilter)) {
|
||||
empty($account_id) ? $sql .= " WHERE " : $sql .= " AND ";
|
||||
empty($account_id) ? $sql .= " WHERE " : $sql .= " AND ";
|
||||
$sql .= implode(' AND ', $aFilter);
|
||||
}
|
||||
}
|
||||
@ -171,8 +168,7 @@ class Transaction extends Base {
|
||||
$this->num_rows = $row_count;
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
$this->debug->append('Failed to fetch transactions: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,8 +184,7 @@ class Transaction extends Base {
|
||||
}
|
||||
return $aData;
|
||||
}
|
||||
$this->debug->append('Failed to fetch transaction types: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,8 +215,7 @@ class Transaction extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
$this->debug->append("Failed to fetch website donors: " . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,10 +239,7 @@ class Transaction extends Base {
|
||||
WHERE archived = 0");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $this->config['confirmations'], $this->config['confirmations']) && $stmt->execute() && $stmt->bind_result($dBalance) && $stmt->fetch())
|
||||
return $dBalance;
|
||||
// Catchall
|
||||
$this->setErrorMessage('Unable to find locked credits for all users');
|
||||
$this->debug->append('MySQL query failed : ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -281,8 +272,7 @@ class Transaction extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("iiiii", $this->config['confirmations'], $this->config['confirmations'], $this->config['confirmations'], $this->config['confirmations'], $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
$this->debug->append('Failed to fetch users balance: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,3 +282,6 @@ $transaction->setMysql($mysqli);
|
||||
$transaction->setConfig($config);
|
||||
$transaction->setBlock($block);
|
||||
$transaction->setUser($user);
|
||||
$transaction->setErrorCodes($aErrorCodes);
|
||||
|
||||
?>
|
||||
|
||||
@ -4,39 +4,12 @@
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class User {
|
||||
private $sError = '';
|
||||
class User extends Base {
|
||||
protected $table = 'accounts';
|
||||
private $userID = false;
|
||||
private $table = 'accounts';
|
||||
private $user = array();
|
||||
|
||||
public function __construct($debug, $mysqli, $salt, $config) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
$this->salt = $salt;
|
||||
$this->config = $config;
|
||||
$this->debug->append("Instantiated User class", 2);
|
||||
}
|
||||
|
||||
// get and set methods
|
||||
public function setMail($mail) {
|
||||
$this->mail = $mail;
|
||||
}
|
||||
public function setToken($token) {
|
||||
$this->token = $token;
|
||||
}
|
||||
public function setBitcoin($bitcoin) {
|
||||
$this->bitcoin = $bitcoin;
|
||||
}
|
||||
public function setSetting($setting) {
|
||||
$this->setting = $setting;
|
||||
}
|
||||
private function setErrorMessage($msg) {
|
||||
$this->sError = $msg;
|
||||
}
|
||||
public function getError() {
|
||||
return $this->sError;
|
||||
}
|
||||
private function getHash($string) {
|
||||
return hash('sha256', $string.$this->salt);
|
||||
}
|
||||
@ -174,31 +147,6 @@ class User {
|
||||
return $pin_hash === $row_pin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single row from the table
|
||||
* @param value string Value to search for
|
||||
* @param search Return column to search for
|
||||
* @param field string Search column
|
||||
* @param type string Type of value
|
||||
* @return array Return result
|
||||
**/
|
||||
private function getSingle($value, $search='id', $field='id', $type="i", $lower=false) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$sql = "SELECT $search FROM $this->table WHERE";
|
||||
$lower ? $sql .= " LOWER($field) = LOWER(?)" : $sql .= " $field = ?";
|
||||
$sql .= " LIMIT 1";
|
||||
$stmt = $this->mysqli->prepare($sql);
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param($type, $value);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($retval);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
return $retval;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users that have auto payout setup
|
||||
* @param none
|
||||
@ -243,31 +191,6 @@ class User {
|
||||
return $dPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a single row in a table
|
||||
* @param userID int Account ID
|
||||
* @param field string Field to update
|
||||
* @return bool
|
||||
**/
|
||||
private function updateSingle($id, $field) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET `" . $field['name'] . "` = ? WHERE id = ? LIMIT 1");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param($field['type'].'i', $field['value'], $id) && $stmt->execute())
|
||||
return true;
|
||||
$this->debug->append("Unable to update " . $field['name'] . " with " . $field['value'] . " for ID $id");
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkStmt($bState) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ($bState ===! true) {
|
||||
$this->debug->append("Failed to prepare statement: " . $this->mysqli->error);
|
||||
$this->setErrorMessage('Internal application Error');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the accounts password
|
||||
* @param userID int User ID
|
||||
@ -445,6 +368,27 @@ class User {
|
||||
exit('<meta http-equiv="refresh" content="0; url=' . $location . '"/>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users for admin panel
|
||||
**/
|
||||
public function getAllUsers($filter='%') {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT
|
||||
a.id AS id,
|
||||
a.username AS username
|
||||
FROM " . $this->getTableName() . " AS a
|
||||
WHERE a.username LIKE ?
|
||||
GROUP BY username");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $filter) && $stmt->execute() && $result = $stmt->get_result()) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$aData[$row['id']] = $row['username'];
|
||||
}
|
||||
return $aData;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch this classes table name
|
||||
* @return table string This classes table name
|
||||
@ -688,7 +632,11 @@ class User {
|
||||
}
|
||||
|
||||
// Make our class available automatically
|
||||
$user = new User($debug, $mysqli, SALT, $config);
|
||||
$user = new User();
|
||||
$user->setDebug($debug);
|
||||
$user->setMysql($mysqli);
|
||||
$user->setSalt(SALT);
|
||||
$user->setConfig($config);
|
||||
$user->setMail($mail);
|
||||
$user->setToken($oToken);
|
||||
$user->setBitcoin($bitcoin);
|
||||
|
||||
@ -26,16 +26,14 @@ class Worker extends Base {
|
||||
} else {
|
||||
// Prefix the WebUser to Worker name
|
||||
$value['username'] = "$username." . $value['username'];
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ?");
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET password2 = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ?");
|
||||
if ( ! ( $this->checkStmt($stmt) && $stmt->bind_param('ssiii', $value['password'], $value['username'], $value['monitor'], $account_id, $key) && $stmt->execute()) )
|
||||
$iFailed++;
|
||||
}
|
||||
}
|
||||
if ($iFailed == 0)
|
||||
return true;
|
||||
// Catchall
|
||||
$this->setErrorMessage('Failed to update ' . $iFailed . ' worker.');
|
||||
return false;
|
||||
return $this->sqlError('E0053', $iFailed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +55,7 @@ class Worker extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $interval) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
$this->setErrorMessage("Unable to fetch IDLE, monitored workers");
|
||||
return false;
|
||||
return $this->sqlError('E0054');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,9 +98,7 @@ class Worker extends Base {
|
||||
");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_assoc();
|
||||
// Catchall
|
||||
$this->serErrorMessage('Failed fetching worker details: '. $this->mysqli->error());
|
||||
return false;
|
||||
return $this->sqlError('E0055');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,10 +140,7 @@ class Worker extends Base {
|
||||
WHERE account_id = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $account_id) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
$this->setErrorMessage('Failed to fetch workers for your account');
|
||||
$this->debug->append('Fetching workers failed: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0056');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,10 +189,7 @@ class Worker extends Base {
|
||||
ORDER BY hashrate DESC LIMIT ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiiiiii', $interval, $interval, $interval, $interval, $interval, $interval, $interval, $interval, $iLimit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
// Catchall
|
||||
$this->setErrorMessage('Failed to fetch workers');
|
||||
$this->debug->append('Fetching workers failed: ' . $this->mysqli->error);
|
||||
return false;
|
||||
return $this->sqlError('E0057');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,11 +203,10 @@ class Worker extends Base {
|
||||
SELECT COUNT(DISTINCT(username)) AS total
|
||||
FROM " . $this->share->getTableName() . "
|
||||
WHERE our_result = 'Y'
|
||||
AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)
|
||||
");
|
||||
AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)");
|
||||
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return $result->fetch_object()->total;
|
||||
return false;
|
||||
return $this->sqlError();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,22 +221,20 @@ class Worker extends Base {
|
||||
public function addWorker($account_id, $workerName, $workerPassword) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
if ('' === $workerName || '' === $workerPassword) {
|
||||
$this->setErrorMessage('Worker name and/or password may not be empty');
|
||||
$this->setErrorMessage($this->getErrorMsg('E0058'));
|
||||
return false;
|
||||
}
|
||||
$username = $this->user->getUserName($account_id);
|
||||
$workerName = "$username.$workerName";
|
||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, username, password) VALUES(?, ?, ?)");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('iss', $account_id, $workerName, $workerPassword);
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iss', $account_id, $workerName, $workerPassword)) {
|
||||
if (!$stmt->execute()) {
|
||||
$this->setErrorMessage( 'Failed to add worker' );
|
||||
if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Worker already exists' );
|
||||
return false;
|
||||
if ($stmt->sqlstate == '23000') return $this->sqlError('E0059');
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError('E0060');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,15 +246,9 @@ class Worker extends Base {
|
||||
public function deleteWorker($account_id, $id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("DELETE FROM $this->table WHERE account_id = ? AND id = ?");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
$stmt->bind_param('ii', $account_id, $id);
|
||||
if ($stmt->execute() && $stmt->affected_rows == 1) {
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $account_id, $id) && $stmt->execute() && $stmt->affected_rows == 1)
|
||||
return true;
|
||||
} else {
|
||||
$this->setErrorMessage( 'Unable to delete worker' );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return $this->sqlError('E0061');
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,3 +258,6 @@ $worker->setMysql($mysqli);
|
||||
$worker->setShare($share);
|
||||
$worker->setConfig($config);
|
||||
$worker->setUser($user);
|
||||
$worker->setErrorCodes($aErrorCodes);
|
||||
|
||||
?>
|
||||
|
||||
@ -23,6 +23,47 @@ $aErrorCodes['E0016'] = 'Failed to delete accounted shares';
|
||||
$aErrorCodes['E0017'] = 'Failed to update Uptime Robot status';
|
||||
$aErrorCodes['E0018'] = 'Cron disbaled due to errors';
|
||||
$aErrorCodes['E0019'] = "SQL Query failed: %s";
|
||||
$aErrorCodes[''] = '';
|
||||
$aErrorCodes['E0020'] = 'Internal error while executing SQL';
|
||||
$aErrorCodes['E0021'] = 'Unable to fetch invitiations send from your account';
|
||||
$aErrorCodes['E0022'] = 'Unable to create invitation record';
|
||||
$aErrorCodes['E0023'] = 'Invalid E-Mail Address';
|
||||
$aErrorCodes['E0024'] = 'Message may only contain alphanumeric characters';
|
||||
$aErrorCodes['E0025'] = 'This email is already registered as an account';
|
||||
$aErrorCodes['E0026'] = 'A pending invitation for this address already exists';
|
||||
$aErrorCodes['E0027'] = 'Unable to generate invitation token: %s';
|
||||
$aErrorCodes['E0028'] = 'Unable to send email to recipient';
|
||||
$aErrorCodes['E0029'] = 'Unable to send invitation';
|
||||
$aErrorCodes['E0030'] = 'Unable to fetch a valid token for this invitation';
|
||||
$aErrorCodes['E0031'] = 'Failed to send e-mail via mail() function';
|
||||
$aErrorCodes['E0032'] = 'Failed to run API call: %s';
|
||||
$aErrorCodes['E0033'] = 'Failed to store uptime status: %s';
|
||||
$aErrorCodes['E0034'] = 'Subjcet may only contain alphanumeric characters';
|
||||
$aErrorCodes['E0035'] = 'Failed to add news record';
|
||||
$aErrorCodes['E0036'] = 'Failed to delete news record';
|
||||
$aErrorCodes['E0037'] = 'Failed to update news record';
|
||||
$aErrorCodes['E0038'] = 'Failed to fetch news record entry';
|
||||
$aErrorCodes['E0039'] = 'Failed to fetch news records';
|
||||
$aErrorCodes['E0040'] = 'Failed to fetch active news records';
|
||||
$aErrorCodes['E0041'] = 'Failed to fetch existing notification records';
|
||||
$aErrorCodes['E0042'] = 'Failed to fetch active notification records';
|
||||
$aErrorCodes['E0043'] = 'Unable to add new notification';
|
||||
$aErrorCodes['E0044'] = 'Failed to fetch notifications for user account';
|
||||
$aErrorCodes['E0045'] = 'Failed fetching notification settings for user account';
|
||||
$aErrorCodes['E0046'] = 'Failed to fetch notification setting for user account';
|
||||
$aErrorCodes['E0047'] = "Failed to update %s settings";
|
||||
$aErrorCodes['E0048'] = 'Failed to check for existing active payouts';
|
||||
$aErrorCodes['E0049'] = 'Unable to create new payout request';
|
||||
$aErrorCodes['E0050'] = 'Failed to fetch unprocessed payouts';
|
||||
$aErrorCodes['E0051'] = 'Failed to mark payout as processed';
|
||||
$aErrorCodes['E0052'] = 'Unable to find valid upstream share for block: %s';
|
||||
$aErrorCodes['E0053'] = 'Failed to update %s workers';
|
||||
$aErrorCodes['E0054'] = 'Unable to fetch IDLE, monitored workers';
|
||||
$aErrorCodes['E0055'] = 'Failed fetching worker details';
|
||||
$aErrorCodes['E0056'] = 'Failed to fetch workers for your account';
|
||||
$aErrorCodes['E0057'] = 'Failed to fetch workers for admin panel';
|
||||
$aErrorCodes['E0058'] = 'Worker name and/or password must not be empty';
|
||||
$aErrorCodes['E0059'] = 'Worker already exists';
|
||||
$aErrorCodes['E0060'] = 'Failed to add new worker';
|
||||
$aErrorCodes['E0061'] = 'Failed to delete worker';
|
||||
$aErrorCodes[''] = '';
|
||||
?>
|
||||
|
||||
@ -11,7 +11,7 @@ if ($user->isAuthenticated()) {
|
||||
if ($notification->updateSettings($_SESSION['USERDATA']['id'], $_REQUEST['data'])) {
|
||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Updated notification settings');
|
||||
} else {
|
||||
$_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update settings', 'TYPE' => 'errormsg');
|
||||
$_SESSION['POPUP'][] = array('CONTENT' => $notification->getError(), 'TYPE' => 'errormsg');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ if (!$user->isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) {
|
||||
if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
|
||||
$debug->append('No cached version available, fetching from backend', 3);
|
||||
|
||||
$aUserList = $roundstats->getAllUsers('%');
|
||||
$aUserList = $user->getAllUsers('%');
|
||||
|
||||
$iHeight = 0;
|
||||
$iUserId = 0;
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<tr>
|
||||
<th scope="row">Actual</th>
|
||||
{section block $BLOCKSFOUND step=-1}
|
||||
<td>{$BLOCKSFOUND[block].shares}</td>
|
||||
<td>{$BLOCKSFOUND[block].shares|default:"0"}</td>
|
||||
{/section}
|
||||
</tr>
|
||||
{if $GLOBAL.config.payout_system == 'pplns'}<tr>
|
||||
@ -136,7 +136,7 @@
|
||||
{if $GLOBAL.config.payout_system == 'pplns'}<td align="right">{$BLOCKSFOUND[block].pplns_shares|number_format}</td>{/if}
|
||||
<td align="right">{$BLOCKSFOUND[block].shares|number_format}</td>
|
||||
<td align="right" style="padding-right: 25px;">
|
||||
{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares estshares=$BLOCKSFOUND[block].estshares}
|
||||
{math assign="percentage" equation="shares / estshares * 100" shares=$BLOCKSFOUND[block].shares|default:"0" estshares=$BLOCKSFOUND[block].estshares}
|
||||
<font color="{if ($percentage <= 100)}green{else}red{/if}">{$percentage|number_format:"2"}</font>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user