Skip to content

Commit 02067ac

Browse files
committed
See issue #2427
1 parent 433c8f7 commit 02067ac

File tree

11 files changed

+288
-157
lines changed

11 files changed

+288
-157
lines changed

include/admin_checks.php

Lines changed: 0 additions & 155 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
// check if daemon can connect -> error
5+
try {
6+
if ($bitcoin->can_connect() !== true) {
7+
$newerror = array();
8+
$newerror['name'] = "Coin daemon";
9+
$newerror['description'] = "Unable to connect to coin daemon using provided credentials.";
10+
$newerror['configvalue'] = "wallet.*";
11+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-local-wallet-rpc";
12+
$error[] = $newerror;
13+
$newerror = null;
14+
}
15+
else {
16+
// validate that the wallet service is not in test mode
17+
if ($bitcoin->is_testnet() == true) {
18+
$newerror = array();
19+
$newerror['name'] = "Coin daemon";
20+
$newerror['description'] = "The coin daemon service is running as a testnet. Check the TESTNET setting in your coin daemon config and make sure the correct port is set in the MPOS config.";
21+
$newerror['configvalue'] = "wallet.host";
22+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-local-wallet-rpc";
23+
$error[] = $newerror;
24+
$newerror = null;
25+
}
26+
// check if there is more than one account set on wallet
27+
$accounts = $bitcoin->listaccounts();
28+
if (count($accounts) > 1 && $accounts[''] <= 0) {
29+
$newerror = array();
30+
$newerror['name'] = "Coin daemon";
31+
$newerror['description'] = "There are " . count($accounts) . " Accounts set in local Wallet and Default Account has no liquid funds to pay your miners!";
32+
$newerror['configvalue'] = "wallet.host";
33+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-local-wallet-rpc";
34+
$error[] = $newerror;
35+
$newerror = null;
36+
}
37+
}
38+
} catch (Exception $e) {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
// check if fees are 0 and ap/mp tx fees are also set to 0 -> issue #2424
5+
if ($config['fees'] == 0 && ($config['txfee_auto'] == 0 || $config['txfee_manual'] == 0)) {
6+
$newerror = array();
7+
$newerror['name'] = "Fees and TX Fees 0";
8+
$newerror['description'] = "Having your pool fees set to 0 and tx fees also set to 0 can cause a problem where the wallet cannot payout, consider setting the txfee to a very low amount, ie. 0.0001 to avoid this.";
9+
$newerror['configvalue'] = "fees";
10+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/issues/2424";
11+
$error[] = $newerror;
12+
$newerror = null;
13+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
// check if memcache isn't available but enabled in config -> error
5+
if (!class_exists('Memcached') && $config['memcache']['enabled']) {
6+
$newerror = array();
7+
$newerror['name'] = "Memcache Config";
8+
$newerror['description'] = "You have memcached enabled in your config and it's not available as a PHP module. Install the package on your system.";
9+
$newerror['configvalue'] = "memcache.enabled";
10+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache";
11+
$error[] = $newerror;
12+
$newerror = null;
13+
}
14+
15+
// if it's not enabled, test it if it exists, if it works -> error tell them to enable, -> otherwise notice it's disabled
16+
if (!$config['memcache']['enabled']) {
17+
if (PHP_OS == 'WINNT') {
18+
require_once(CLASS_DIR . 'memcached.class.php');
19+
}
20+
if (class_exists('Memcached')) {
21+
$memcache_test = @new Memcached();
22+
if ($config['memcache']['sasl'] === true) {
23+
$memcache_test->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
24+
$memcache_test->setSaslAuthData($config['memcache']['sasl']['username'], $config['memcache']['sasl']['password']);
25+
}
26+
$memcache_test_add = @$memcache_test->addServer($config['memcache']['host'], $config['memcache']['port']);
27+
$randmctv = rand(5,10);
28+
$memcache_test_set = @$memcache_test->set('test_mpos_setval', $randmctv);
29+
$memcache_test_get = @$memcache_test->get('test_mpos_setval');
30+
}
31+
if (class_exists('Memcached') && $memcache_test_get == $randmctv) {
32+
$newerror = array();
33+
$newerror['name'] = "Memcache Config";
34+
$newerror['description'] = "You have memcache disabled in the config but it's available and works! Enable it for best performance.";
35+
$newerror['configvalue'] = "memcache.enabled";
36+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache";
37+
$error[] = $newerror;
38+
$newerror = null;
39+
} else {
40+
$newerror = array();
41+
$newerror['name'] = "Memcache Config";
42+
$newerror['description'] = "Memcache is disabled; Almost every linux distro has packages for it, you should be using it if you can.";
43+
$newerror['configvalue'] = "memcache.enabled";
44+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-memcache";
45+
$error[] = $newerror;
46+
$newerror = null;
47+
}
48+
}
49+
50+
// check anti DOS protection, we need memcache for that
51+
if ($config['mc_antidos'] && !$config['memcache']['enabled']) {
52+
$newerror = array();
53+
$newerror['name'] = "Memcache Config";
54+
$newerror['description'] = "mc_antidos is enabled and memcache is not, <u>memcache is required</u> to use this.";
55+
$newerror['configvalue'] = "memcache.enabled";
56+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#memcache-rate-limiting";
57+
$error[] = $newerror;
58+
$newerror = null;
59+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
if ($config['logging']['enabled']) {
5+
// checks to see that the logging path is writable
6+
if (!is_writable($config['logging']['path'])) {
7+
$newerror = array();
8+
$newerror['name'] = "Log path permissions";
9+
$newerror['description'] = "Logging is enabled but we can't write in the logfile path.";
10+
$newerror['configvalue'] = "logging.path";
11+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#configuration-1";
12+
$error[] = $newerror;
13+
$newerror = null;
14+
}
15+
}
16+
17+
// check if we can write templates/cache and templates/compile -> error
18+
if (!is_writable(TEMPLATE_DIR . '/cache')) {
19+
$newerror = array();
20+
$newerror['name'] = "templates/cache permissions";
21+
$newerror['description'] = "templates/cache folder is not writable for uid {$apache_user['name']}";
22+
$newerror['configvalue'] = "templates/cache folder";
23+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#configuration-1";
24+
$error[] = $newerror;
25+
$newerror = null;
26+
}
27+
if (!is_writable(TEMPLATE_DIR . '/compile')) {
28+
$newerror = array();
29+
$newerror['name'] = "templates/compile permissions";
30+
$newerror['description'] = "templates/compile folder is not writable for uid {$apache_user['name']}";
31+
$newerror['configvalue'] = "templates/compile folder";
32+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#configuration-1";
33+
$error[] = $newerror;
34+
$newerror = null;
35+
}
36+
37+
// check if we can write the config files, we should NOT be able to -> error
38+
if (is_writable(INCLUDE_DIR.'/config/global.inc.php') || is_writable(INCLUDE_DIR.'/config/global.inc.dist.php') ||
39+
is_writable(INCLUDE_DIR.'/config/security.inc.php') || is_writable(INCLUDE_DIR.'/config/security.inc.dist.php')) {
40+
$newerror = array();
41+
$newerror['name'] = "Config permissions";
42+
$newerror['description'] = "Your config files <b>SHOULD NOT be writable to this user</b>!";
43+
$newerror['configvalue'] = "global.inc.php and security.inc.php";
44+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide#configuration-1";
45+
$error[] = $newerror;
46+
$newerror = null;
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
// check if password salts are sane
5+
if (strlen($config['SALT']) < 24 || strlen($config['SALTY']) < 24 || $config['SALT'] == 'PLEASEMAKEMESOMETHINGRANDOM' || $config['SALTY'] == 'THISSHOULDALSOBERRAANNDDOOM') {
6+
$newerror = array();
7+
$newerror['name'] = "Password Salts";
8+
if ($config['SALT'] == 'PLEASEMAKEMESOMETHINGRANDOM' || $config['SALTY'] == 'THISSHOULDALSOBERRAANNDDOOM') {
9+
$newerror['description'] = "You absolutely <u>SHOULD NOT leave your SALT or SALTY default</u> changing them will require registering again.";
10+
} else {
11+
$newerror['description'] = "SALT or SALTY is too short, they should be more than 24 characters and changing them will require registering again.</p>";
12+
}
13+
$newerror['configvalue'] = "SALT";
14+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-defines--salts";
15+
$error[] = $newerror;
16+
$newerror = null;
17+
}
18+
19+
// check if htaccess exists
20+
if (!file_exists(BASEPATH.".htaccess")) {
21+
$newerror = array();
22+
$newerror['name'] = ".htaccess";
23+
$htaccess_link = "<a href='https://github.com/MPOS/php-mpos/blob/next/public/.htaccess'>.htaccess</a>";
24+
$newerror['description'] = "You don't seem to have a .htaccess in your public folder, if you're using Apache set it up: $htaccess_link";
25+
$newerror['configvalue'] = ".htaccess";
26+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki";
27+
$error[] = $newerror;
28+
$newerror = null;
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
// poke stratum using gettingstarted details -> enotice
5+
if (function_exists('socket_create')) {
6+
$host = @gethostbyname($config['gettingstarted']['stratumurl']);
7+
$port = $config['gettingstarted']['stratumport'];
8+
if (isset($host) and
9+
isset($port) and
10+
($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and
11+
(socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 3, 'usec' => 0))) and
12+
(@socket_connect($socket, $host, $port)))
13+
{
14+
socket_close($socket);
15+
} else {
16+
$newerror = array();
17+
$newerror['name'] = "Stratum information";
18+
$newerror['description'] = "We tried to poke your Stratum server using your \$config['gettingstarted'] settings but it didn't respond - " . socket_strerror(socket_last_error()) . ".";
19+
$newerror['configvalue'] = "gettingstarted";
20+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-getting-started";
21+
$error[] = $newerror;
22+
$newerror = null;
23+
}
24+
} else {
25+
// Connect via fsockopen as fallback
26+
if (! $fp = @fsockopen($config['gettingstarted']['stratumurl'], $config['gettingstarted']['stratumport'], $errCode, $errStr, 1)) {
27+
$newerror = array();
28+
$newerror['name'] = "Stratum information";
29+
$newerror['description'] = "We tried to poke your Stratum server using your \$config['gettingstarted'] settings but it didn't respond.";
30+
$newerror['configvalue'] = "gettingstarted";
31+
$newerror['helplink'] = "https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-getting-started";
32+
$error[] = $newerror;
33+
$newerror = null;
34+
}
35+
@fclose($fp);
36+
}

0 commit comments

Comments
 (0)