diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1cdd1a..085f4e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ 1.0.2 (XXX XXth 2015) --------------------- +* Allow SSO accross MPOS pools + * Added a new config option `$config['db']['shared']['name']`, defaults to `$config['db']['name']` + * Will access `accounts` and `pool_workers` on shared table + * Does not allow splitting `accounts` and `pool_woker` across database hosts + * Required `$config['cookie']['domain']` to be set + * You need to use the top domain shared between hosts as the setting + * e.g. `ltc.thepool.com` and `btc.thepool.com` it has to be `.thepool.com` (NOTE the leading .) * Increased information on `Admin -> Wallet Info` * Added block count to Wallet Status * Added number of accounts to Wallet Status diff --git a/include/classes/coin_address.class.php b/include/classes/coin_address.class.php index 3396a54a..8b5620e6 100644 --- a/include/classes/coin_address.class.php +++ b/include/classes/coin_address.class.php @@ -3,7 +3,17 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; class CoinAddress extends Base { protected $table = 'coin_addresses'; - private $cache = array(); + + /** + * We allow changing the database for shared accounts across pools + * Load the config on construct so we can assign the DB name + * @param config array MPOS configuration + * @return none + **/ + public function __construct($config) { + $this->setConfig($config); + $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + } /** * Fetch users coin address for a currency @@ -124,8 +134,7 @@ class CoinAddress extends Base { } } -$coin_address = new CoinAddress(); +$coin_address = new CoinAddress($config); $coin_address->setDebug($debug); -$coin_address->setConfig($config); $coin_address->setMysql($mysqli); $coin_address->setErrorCodes($aErrorCodes); diff --git a/include/classes/roundstats.class.php b/include/classes/roundstats.class.php index 8c3f0315..6198f299 100644 --- a/include/classes/roundstats.class.php +++ b/include/classes/roundstats.class.php @@ -2,11 +2,6 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; class RoundStats extends Base { - private $tableTrans = 'transactions'; - private $tableStats = 'statistics_shares'; - private $tableBlocks = 'blocks'; - private $tableUsers = 'accounts'; - /** * Get next block for round stats **/ @@ -79,7 +74,7 @@ class RoundStats extends Base { b.id, height, blockhash, amount, confirmations, difficulty, FROM_UNIXTIME(time) as time, shares, IF(a.is_anonymous, 'anonymous', a.username) AS finder, ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares, - (time - (SELECT time FROM $this->tableBlocks WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time + (time - (SELECT time FROM " . $this->block->getTableName() . " WHERE height < ? ORDER BY height DESC LIMIT 1)) AS round_time FROM " . $this->block->getTableName() . " as b LEFT JOIN " . $this->user->getTableName() . " AS a ON b.account_id = a.id WHERE b.height = ? LIMIT 1"); diff --git a/include/classes/user.class.php b/include/classes/user.class.php index 69dc0794..c5ab0c34 100644 --- a/include/classes/user.class.php +++ b/include/classes/user.class.php @@ -6,6 +6,17 @@ class User extends Base { private $userID = false; private $user = array(); + /** + * We allow changing the database for shared accounts across pools + * Load the config on construct so we can assign the DB name + * @param config array MPOS configuration + * @return none + **/ + public function __construct($config) { + $this->setConfig($config); + $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + } + // get and set methods private function getHash($string, $version=0, $pepper='') { switch($version) { @@ -984,13 +995,12 @@ public function isAuthenticated($logout=true) { } // Make our class available automatically -$user = new User(); +$user = new User($config); $user->setDebug($debug); $user->setLog($log); $user->setMysql($mysqli); $user->setSalt($config['SALT']); $user->setSmarty($smarty); -$user->setConfig($config); $user->setMail($mail); $user->setToken($oToken); $user->setBitcoin($bitcoin); diff --git a/include/classes/worker.class.php b/include/classes/worker.class.php index 1f273d3e..3f9569f9 100644 --- a/include/classes/worker.class.php +++ b/include/classes/worker.class.php @@ -4,6 +4,17 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; class Worker extends Base { protected $table = 'pool_worker'; + /** + * We allow changing the database for shared accounts across pools + * Load the config on construct so we can assign the DB name + * @param config array MPOS configuration + * @return none + **/ + public function __construct($config) { + $this->setConfig($config); + $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + } + /** * Update worker list for a user * @param account_id int User ID @@ -294,12 +305,11 @@ class Worker extends Base { } } -$worker = new Worker(); +$worker = new Worker($config); $worker->setDebug($debug); $worker->setMysql($mysqli); $worker->setMemcache($memcache); $worker->setShare($share); -$worker->setConfig($config); $worker->setUser($user); $worker->setErrorCodes($aErrorCodes); $worker->setCoin($coin); diff --git a/include/config/global.inc.dist.php b/include/config/global.inc.dist.php index bc8ce5bf..b234794d 100644 --- a/include/config/global.inc.dist.php +++ b/include/config/global.inc.dist.php @@ -54,6 +54,7 @@ $config['db']['user'] = 'someuser'; $config['db']['pass'] = 'somepass'; $config['db']['port'] = 3306; $config['db']['name'] = 'mpos'; +$config['db']['shared']['name'] = $config['db']['name']; /** * Local wallet RPC