Skip to content

Commit a7fc714

Browse files
committed
[ADDED] SSO across MPOS pools with single database host
1 parent 4adc113 commit a7fc714

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
1.0.2 (XXX XXth 2015)
22
---------------------
33

4+
* Allow SSO accross MPOS pools
5+
* Added a new config option `$config['db']['shared']['name']`, defaults to `$config['db']['name']`
6+
* Will access `accounts` and `pool_workers` on shared table
7+
* Does not allow splitting `accounts` and `pool_woker` across database hosts
8+
* Required `$config['cookie']['domain']` to be set
9+
* You need to use the top domain shared between hosts as the setting
10+
* e.g. `ltc.thepool.com` and `btc.thepool.com` it has to be `.thepool.com` (NOTE the leading .)
411
* Increased information on `Admin -> Wallet Info`
512
* Added block count to Wallet Status
613
* Added number of accounts to Wallet Status

include/classes/coin_address.class.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
class CoinAddress extends Base {
55
protected $table = 'coin_addresses';
6-
private $cache = array();
6+
7+
/**
8+
* We allow changing the database for shared accounts across pools
9+
* Load the config on construct so we can assign the DB name
10+
* @param config array MPOS configuration
11+
* @return none
12+
**/
13+
public function __construct($config) {
14+
$this->setConfig($config);
15+
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
16+
}
717

818
/**
919
* Fetch users coin address for a currency
@@ -124,8 +134,7 @@ public function update($userID, $address, $ap_threshold, $currency=NULL) {
124134
}
125135
}
126136

127-
$coin_address = new CoinAddress();
137+
$coin_address = new CoinAddress($config);
128138
$coin_address->setDebug($debug);
129-
$coin_address->setConfig($config);
130139
$coin_address->setMysql($mysqli);
131140
$coin_address->setErrorCodes($aErrorCodes);

include/classes/roundstats.class.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

44
class RoundStats extends Base {
5-
private $tableTrans = 'transactions';
6-
private $tableStats = 'statistics_shares';
7-
private $tableBlocks = 'blocks';
8-
private $tableUsers = 'accounts';
9-
105
/**
116
* Get next block for round stats
127
**/
@@ -79,7 +74,7 @@ public function getDetailsForBlockHeight($iHeight=0) {
7974
b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares,
8075
IF(a.is_anonymous, 'anonymous', a.username) AS finder,
8176
ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares,
82-
(time - (SELECT time FROM $this->tableBlocks WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time
77+
(time - (SELECT time FROM " . $this->block->getTableName() . " WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time
8378
FROM " . $this->block->getTableName() . " as b
8479
LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id
8580
WHERE b.height = ? LIMIT 1");

include/classes/user.class.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ class User extends Base {
66
private $userID = false;
77
private $user = array();
88

9+
/**
10+
* We allow changing the database for shared accounts across pools
11+
* Load the config on construct so we can assign the DB name
12+
* @param config array MPOS configuration
13+
* @return none
14+
**/
15+
public function __construct($config) {
16+
$this->setConfig($config);
17+
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
18+
}
19+
920
// get and set methods
1021
private function getHash($string, $version=0, $pepper='') {
1122
switch($version) {
@@ -984,13 +995,12 @@ public function getCurrentIP($trustremote=false, $checkcloudflare=true, $checkcl
984995
}
985996

986997
// Make our class available automatically
987-
$user = new User();
998+
$user = new User($config);
988999
$user->setDebug($debug);
9891000
$user->setLog($log);
9901001
$user->setMysql($mysqli);
9911002
$user->setSalt($config['SALT']);
9921003
$user->setSmarty($smarty);
993-
$user->setConfig($config);
9941004
$user->setMail($mail);
9951005
$user->setToken($oToken);
9961006
$user->setBitcoin($bitcoin);

include/classes/worker.class.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
class Worker extends Base {
55
protected $table = 'pool_worker';
66

7+
/**
8+
* We allow changing the database for shared accounts across pools
9+
* Load the config on construct so we can assign the DB name
10+
* @param config array MPOS configuration
11+
* @return none
12+
**/
13+
public function __construct($config) {
14+
$this->setConfig($config);
15+
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
16+
}
17+
718
/**
819
* Update worker list for a user
920
* @param account_id int User ID
@@ -294,12 +305,11 @@ public function deleteWorker($account_id, $id) {
294305
}
295306
}
296307

297-
$worker = new Worker();
308+
$worker = new Worker($config);
298309
$worker->setDebug($debug);
299310
$worker->setMysql($mysqli);
300311
$worker->setMemcache($memcache);
301312
$worker->setShare($share);
302-
$worker->setConfig($config);
303313
$worker->setUser($user);
304314
$worker->setErrorCodes($aErrorCodes);
305315
$worker->setCoin($coin);

include/config/global.inc.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
$config['db']['pass'] = 'somepass';
5555
$config['db']['port'] = 3306;
5656
$config['db']['name'] = 'mpos';
57+
$config['db']['shared']['name'] = $config['db']['name'];
5758

5859
/**
5960
* Local wallet RPC

0 commit comments

Comments
 (0)