Skip to content

Commit 885e932

Browse files
committed
Merge pull request #1944 from MPOS/development
[MASTER] Update from Development
2 parents eb192c5 + 9b36c9a commit 885e932

File tree

16 files changed

+191
-75
lines changed

16 files changed

+191
-75
lines changed

cronjobs/notifications.php

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,49 @@
2929
$monitoring->endCronjob($cron_name, 'E0009', 0, true, false);
3030
}
3131

32-
$log->logDebug(" IDLE Worker Notifications ...");
33-
// Find all IDLE workers
34-
$aWorkers = $worker->getAllIdleWorkers();
35-
if (empty($aWorkers)) {
36-
$log->logDebug(" no idle workers found");
37-
} else {
38-
$log->logInfo(" found " . count($aWorkers) . " IDLE workers");
39-
foreach ($aWorkers as $aWorker) {
40-
$aData = $aWorker;
41-
$aData['username'] = $user->getUserName($aWorker['account_id']);
42-
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
43-
$aData['worker'] = $aWorker['username'];
44-
$aData['email'] = $user->getUserEmail($aData['username']);
45-
$log->logDebug(" " . $aWorker['username'] . "...");
46-
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
47-
$log->logDebug(" Failed sending notifications: " . $notification->getCronError());
32+
if ($setting->getValue('notifications_disable_idle_worker') != 1) {
33+
$log->logDebug(" IDLE Worker Notifications ...");
34+
// Find all IDLE workers
35+
$aWorkers = $worker->getAllIdleWorkers();
36+
if (empty($aWorkers)) {
37+
$log->logDebug(" no idle workers found");
38+
} else {
39+
$log->logInfo(" found " . count($aWorkers) . " IDLE workers");
40+
foreach ($aWorkers as $aWorker) {
41+
$aData = $aWorker;
42+
$aData['username'] = $user->getUserName($aWorker['account_id']);
43+
$aData['subject'] = 'IDLE Worker : ' . $aWorker['username'];
44+
$aData['worker'] = $aWorker['username'];
45+
$aData['email'] = $user->getUserEmail($aData['username']);
46+
$log->logDebug(" " . $aWorker['username'] . "...");
47+
if (!$notification->sendNotification($aWorker['account_id'], 'idle_worker', $aData))
48+
$log->logDebug(" Failed sending notifications: " . $notification->getCronError());
49+
}
4850
}
49-
}
5051

5152

52-
$log->logDebug(" Reset IDLE Worker Notifications ...");
53-
// We notified, lets check which recovered
54-
$aNotifications = $notification->getAllActive('idle_worker');
55-
if (!empty($aNotifications)) {
56-
$log->logInfo(" found " . count($aNotifications) . " active notification(s)");
57-
foreach ($aNotifications as $aNotification) {
58-
$aData = json_decode($aNotification['data'], true);
59-
$aWorker = $worker->getWorker($aData['id']);
60-
$log->logDebug(" " . $aWorker['username'] . " ...");
61-
if ($aWorker['hashrate'] > 0) {
62-
if ($notification->setInactive($aNotification['id'])) {
63-
$log->logDebug(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive");
53+
$log->logDebug(" Reset IDLE Worker Notifications ...");
54+
// We notified, lets check which recovered
55+
$aNotifications = $notification->getAllActive('idle_worker');
56+
if (!empty($aNotifications)) {
57+
$log->logInfo(" found " . count($aNotifications) . " active notification(s)");
58+
foreach ($aNotifications as $aNotification) {
59+
$aData = json_decode($aNotification['data'], true);
60+
$aWorker = $worker->getWorker($aData['id']);
61+
$log->logDebug(" " . $aWorker['username'] . " ...");
62+
if ($aWorker['hashrate'] > 0) {
63+
if ($notification->setInactive($aNotification['id'])) {
64+
$log->logDebug(" updated #" . $aNotification['id'] . " for " . $aWorker['username'] . " as inactive");
65+
} else {
66+
$log->logError(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username']);
67+
}
6468
} else {
65-
$log->logError(" failed to update #" . $aNotification['id'] . " for " . $aWorker['username']);
69+
$log->logDebug(" still inactive");
6670
}
67-
} else {
68-
$log->logDebug(" still inactive");
6971
}
72+
} else {
73+
$log->logDebug(" no active IDLE worker notifications");
7074
}
71-
} else {
72-
$log->logDebug(" no active IDLE worker notifications");
7375
}
7476

7577
require_once('cron_end.inc.php');

cronjobs/pplns_payout.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@
181181
}
182182

183183
// Table header for account shares
184-
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
185-
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
184+
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
185+
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
186186

187187
// Loop through all accounts that have found shares for this round
188188
foreach ($aTotalAccountShares as $key => $aData) {
@@ -201,16 +201,28 @@
201201
// Defaults
202202
$aData['fee' ] = 0;
203203
$aData['donation'] = 0;
204+
$aData['pool_bonus'] = 0;
204205

206+
// Calculate pool fees
205207
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
206208
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
209+
210+
// Calculate pool bonus if it applies, will be paid from liquid assets!
211+
if ($config['pool_bonus'] > 0) {
212+
if ($config['pool_bonus_type'] == 'block') {
213+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
214+
} else {
215+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
216+
}
217+
}
218+
207219
// Calculate donation amount, fees not included
208220
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
209221

210222
// Verbose output of this users calculations
211223
$log->logInfo(
212224
sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'],
213-
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)
225+
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8)
214226
)
215227
);
216228

@@ -225,6 +237,10 @@
225237
if ($aData['donation'] > 0)
226238
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
227239
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError() . 'on block ' . $aBlock['id']);
240+
// Add new bonus credit
241+
if ($aData['pool_bonus'] > 0)
242+
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
243+
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
228244
}
229245

230246
// Add full round share statistics

cronjobs/proportional_payout.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
$count = 0;
4242
// Table header for account shares
43-
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
44-
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
43+
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
44+
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
4545
foreach ($aAllBlocks as $iIndex => $aBlock) {
4646
// If we have unaccounted blocks without share_ids, they might not have been inserted yet
4747
if (!$aBlock['share_id']) {
@@ -86,18 +86,30 @@
8686
// Defaults
8787
$aData['fee' ] = 0;
8888
$aData['donation'] = 0;
89+
$aData['pool_bonus'] = 0;
8990
$aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8);
9091
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
9192

93+
// Calculate pool fees if they apply
9294
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
9395
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
96+
97+
// Calculate pool bonus if it applies, will be paid from liquid assets!
98+
if ($config['pool_bonus'] > 0) {
99+
if ($config['pool_bonus_type'] == 'block') {
100+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
101+
} else {
102+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
103+
}
104+
}
105+
94106
// Calculate donation amount, fees not included
95107
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
96108

97109
// Verbose output of this users calculations
98110
$log->logInfo(
99111
sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'],
100-
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8))
112+
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8))
101113
);
102114

103115
// Update user share statistics
@@ -114,6 +126,10 @@
114126
if ($aData['donation'] > 0)
115127
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
116128
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
129+
// Add new bonus credit
130+
if ($aData['pool_bonus'] > 0)
131+
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
132+
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
117133
}
118134

119135
// Add block as accounted for into settings table

public/include/admin_checks.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@
66
$notice = array();
77
$enotice = array();
88
$error = array();
9-
9+
1010
// setup some basic stuff for checking - getuid/getpwuid not available on mac/windows
1111
$apache_user = 'unknown';
1212
if (substr_count(strtolower(PHP_OS), 'nix') > 0 || substr_count(strtolower(PHP_OS), 'linux') > 0) {
1313
$apache_user = (function_exists('posix_getuid')) ? posix_getuid() : 'unknown';
1414
$apache_user = (function_exists('posix_getpwuid')) ? posix_getpwuid($apache_user) : $apache_user;
1515
}
16-
16+
1717
// setup checks
1818
// logging
1919
if ($config['logging']['enabled']) {
2020
if (!is_writable($config['logging']['path'])) {
21-
$error[] = "Logging is enabled but we can't write in the logging path";
21+
$error[] = "Logging is enabled but we can't write in the logfile path";
2222
}
2323
}
24+
2425
// check if memcache isn't available but enabled in config -> error
2526
if (!class_exists('Memcached') && $config['memcache']['enabled']) {
26-
$error[] = "You have memcache enabled in your config and it's not available. Install the package on your system.";
27+
$error[] = "You have memcached enabled in your config and it's not available as a PHP module. Install the package on your system.";
2728
}
29+
2830
// if it's not enabled, test it if it exists, if it works -> error tell them to enable, -> otherwise notice it's disabled
2931
if (!$config['memcache']['enabled']) {
3032
if (PHP_OS == 'WINNT') {
@@ -38,28 +40,32 @@
3840
$memcache_test_get = @$memcache_test->get('test_mpos_setval');
3941
}
4042
if (class_exists('Memcached') && $memcache_test_get == $randmctv) {
41-
$error[] = "You have memcache disabled in the config and it's available & works! Enable it.";
43+
$error[] = "You have memcache disabled in the config but it's available and works! Enable it for best performance.";
4244
} else {
4345
$notice[] = "Memcache is disabled; Almost every linux distro has packages for it, you should be using it if you can.";
4446
}
4547
}
48+
4649
// check if htaccess exists
4750
if (!file_exists(BASEPATH.".htaccess")) {
4851
$htaccess_link = "<a href='https://github.com/MPOS/php-mpos/blob/next/public/.htaccess'>.htaccess</a>";
49-
$notice[] = "You don't seem to have a .htaccess in your public folder, if you're using apache set it up $htaccess_link";
52+
$notice[] = "You don't seem to have a .htaccess in your public folder, if you're using Apache set it up: $htaccess_link";
5053
}
54+
5155
// check if we can write templates/cache and templates/compile -> error
5256
if (!is_writable(THEME_DIR.'/cache')) {
5357
$error[] = "templates/cache folder is not writable for uid {$apache_user['name']}";
5458
}
5559
if (!is_writable(THEME_DIR.'/compile')) {
5660
$error[] = "templates/compile folder is not writable for uid {$apache_user['name']}";
5761
}
62+
5863
// check if we can write the config files, we should NOT be able to -> error
5964
if (is_writable(INCLUDE_DIR.'/config/global.inc.php') || is_writable(INCLUDE_DIR.'/config/global.inc.dist.php') ||
6065
is_writable(INCLUDE_DIR.'/config/security.inc.php') || is_writable(INCLUDE_DIR.'/config/security.inc.dist.php')) {
6166
$error[] = "Your config files <b>SHOULD NOT be writable to this user</b>!";
6267
}
68+
6369
// check if daemon can connect -> error
6470
try {
6571
if ($bitcoin->can_connect() !== true) {
@@ -76,7 +82,7 @@
7682
if (!$bitcoin->validateaddress($config['coldwallet']['address']))
7783
$error[] = "Your cold wallet address is <u>SET and INVALID</u>";
7884
}
79-
85+
8086
// check if there is more than one account set on wallet
8187
$accounts = $bitcoin->listaccounts();
8288
if (count($accounts) > 1 && $accounts[''] <= 0) {
@@ -85,34 +91,30 @@
8591
}
8692
} catch (Exception $e) {
8793
}
88-
// if database connection fails -> error
89-
$db_connect = new mysqli($config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $config['db']['port']);
90-
if (mysqli_connect_errno() || !array_key_exists('client_info', $db_connect)) {
91-
$error[] = "Unable to connect to mysql using provided credentials";
92-
}
94+
// check anti DOS protection, we need memcache for that
9395
if ($config['mc_antidos'] && !$config['memcache']['enabled']) {
9496
$error[] = "mc_antidos is enabled and memcache is not, <u>memcache is required</u> to use this";
9597
}
98+
9699
// poke stratum using gettingstarted details -> enotice
97-
if (substr_count(strtolower(PHP_OS), 'nix') > 0) {
98-
// unix *poke*
99-
$socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
100+
if (function_exists('socket_create')) {
101+
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
100102
if ($socket !== false) {
101103
$address = @gethostbyname($config['gettingstarted']['stratumurl']);
102104
$result = @socket_connect($socket, $address, $config['gettingstarted']['stratumport']);
103105
if ($result !== true) {
104-
$enotice[] = "We tried to poke your Stratum server using config->gettingstarted details but it didn't respond";
106+
$enotice[] = 'We tried to poke your Stratum server using your $config[\'gettingstarted\'] settings but it didn\'t respond';
105107
}
106108
$close = @socket_close($socket);
107109
}
108110
} else {
109-
// mac/windows *poke*
110-
if (! $fp = @fsockopen($config['gettingstarted']['stratumurl'],$config['gettingstarted']['stratumport'],$errCode,$errStr,1)) {
111-
$enotice[] = "We tried to poke your Stratum server using config->gettingstarted details but it didn't respond";
111+
// Connect via fsockopen as fallback
112+
if (! $fp = @fsockopen($config['gettingstarted']['stratumurl'], $config['gettingstarted']['stratumport'], $errCode, $errStr, 1)) {
113+
$enotice[] = 'We tried to poke your Stratum server using your $config[\'gettingstarted\'] settings but it didn\'t respond';
112114
}
113115
@fclose($fp);
114116
}
115-
117+
116118
// security checks
117119
// salts too short -> notice, salts default -> error
118120
if ((strlen($config['SALT']) < 24) || (strlen($config['SALTY']) < 24) || $config['SALT'] == 'PLEASEMAKEMESOMETHINGRANDOM' || $config['SALTY'] == 'THISSHOULDALSOBERRAANNDDOOM') {
@@ -122,7 +124,7 @@
122124
$notice[] = "SALT or SALTY is too short, they should be more than 24 characters and changing them will require registering again";
123125
}
124126
}
125-
127+
126128
// display the errors
127129
foreach ($enotice as $en) {
128130
$_SESSION['POPUP'][] = array('CONTENT' => $en, 'TYPE' => 'info');

public/include/classes/setting.class.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,30 @@
33

44
class Setting extends Base {
55
protected $table = 'settings';
6+
private $cache = array();
7+
8+
/**
9+
* Fetch all values available and cache them in this class
10+
* That way we don't fetch them from DB for each call
11+
*/
12+
public function createCache() {
13+
if ($aSettings = $this->getAllAssoc()) {
14+
foreach ($aSettings as $key => $aData) {
15+
$this->cache[$aData['name']] = $aData['value'];
16+
}
17+
return true;
18+
}
19+
return false;
20+
}
621

722
/**
823
* Fetch a value from our table
924
* @param name string Setting name
1025
* @return value string Value
1126
**/
1227
public function getValue($name, $default="") {
28+
// Try our class cache first
29+
if (isset($this->cache[$name])) return $this->cache[$name];
1330
$stmt = $this->mysqli->prepare("SELECT value FROM $this->table WHERE name = ? LIMIT 1");
1431
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $name) && $stmt->execute() && $result = $stmt->get_result()) {
1532
if ($result->num_rows > 0) {
@@ -30,6 +47,8 @@ public function getValue($name, $default="") {
3047
* @return bool
3148
**/
3249
public function setValue($name, $value) {
50+
// Update local cache too
51+
$this->cache[$name] = $value;
3352
$stmt = $this->mysqli->prepare("
3453
INSERT INTO $this->table (name, value)
3554
VALUES (?, ?)
@@ -44,3 +63,5 @@ public function setValue($name, $value) {
4463
$setting->setDebug($debug);
4564
$setting->setMysql($mysqli);
4665
$setting->setErrorCodes($aErrorCodes);
66+
// Fill our class cache with data so we don't have to run SQL queries all the time
67+
$setting->createCache();

public/include/classes/statistics.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function getAllUserMiningStats($interval=180) {
469469
share_id,
470470
IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty,
471471
username
472-
FROM shares_archive
472+
FROM " . $this->share->getArchiveTableName() . "
473473
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y'
474474
) AS t1
475475
LEFT JOIN " . $this->user->getTableName() . " AS a

public/include/classes/tools.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private function getApiType($url) {
5555
return 'btce';
5656
} else if (preg_match('/cryptsy.com/', $url)) {
5757
return 'cryptsy';
58+
} else if (preg_match('/cryptorush.in/', $url)) {
59+
return 'cryptorush';
5860
}
5961
$this->setErrorMessage("API URL unknown");
6062
return false;
@@ -84,6 +86,9 @@ public function getPrice() {
8486
case 'cryptsy':
8587
return @$aData['return']['markets'][$strCurrency]['lasttradeprice'];
8688
break;
89+
case 'cryptorush':
90+
return @$aData["$strCurrency/" . $this->config['price']['target']]['last_trade'];
91+
break;
8792
}
8893
} else {
8994
$this->setErrorMessage("Got an invalid response from ticker API");

0 commit comments

Comments
 (0)