| 1 |
<?php |
| 2 |
/* |
| 3 |
* This file is part of the ManageWP Worker plugin. |
| 4 |
* |
| 5 |
* (c) ManageWP LLC <contact@managewp.com> |
| 6 |
* |
| 7 |
* For the full copyright and license information, please view the LICENSE |
| 8 |
* file that was distributed with this source code. |
| 9 |
*/ |
| 10 |
|
| 11 |
class MWP_System_Environment |
| 12 |
{ |
| 13 |
|
| 14 |
/** |
| 15 |
* @var MWP_ServiceContainer_Interface |
| 16 |
*/ |
| 17 |
private $container; |
| 18 |
|
| 19 |
public function __construct(MWP_ServiceContainer_Interface $container) |
| 20 |
{ |
| 21 |
$this->container = $container; |
| 22 |
} |
| 23 |
|
| 24 |
public function isPdoEnabled() |
| 25 |
{ |
| 26 |
if ($this->container->getParameter('disable_pdo')) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
|
| 30 |
return extension_loaded('pdo_mysql'); |
| 31 |
} |
| 32 |
|
| 33 |
public function isMysqliEnabled() |
| 34 |
{ |
| 35 |
if ($this->container->getParameter('disable_mysqli')) { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
return extension_loaded('mysqli'); |
| 40 |
} |
| 41 |
|
| 42 |
public function isMysqlEnabled() |
| 43 |
{ |
| 44 |
if ($this->container->getParameter('disable_mysql')) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return extension_loaded('mysql'); |
| 49 |
} |
| 50 |
|
| 51 |
public function isCurlEnabled() |
| 52 |
{ |
| 53 |
// Some hosting providers disable only curl_exec(). |
| 54 |
return (function_exists('curl_init') && function_exists('curl_exec')); |
| 55 |
} |
| 56 |
|
| 57 |
public function isOpenSslLibraryEnabled() |
| 58 |
{ |
| 59 |
if ($this->container->getParameter('prefer_phpseclib')) { |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
if (!extension_loaded('openssl')) { |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
$context = $this->container->getWordPressContext(); |
| 68 |
|
| 69 |
$openSslParameters = $context->optionGet('mwp_openssl_parameters'); |
| 70 |
|
| 71 |
if (isset($openSslParameters['time']) && time() - $openSslParameters['time'] < 86400) { |
| 72 |
return !empty($openSslParameters['working']); |
| 73 |
} |
| 74 |
|
| 75 |
$context->optionSet('mwp_openssl_parameters', array( |
| 76 |
'time' => time(), |
| 77 |
'working' => false, |
| 78 |
)); |
| 79 |
|
| 80 |
$workingOpenSsl = $this->verifyIsOpenSslWorking(); |
| 81 |
|
| 82 |
$context->optionSet('mwp_openssl_parameters', array( |
| 83 |
'time' => time(), |
| 84 |
'working' => $workingOpenSsl, |
| 85 |
)); |
| 86 |
|
| 87 |
return $workingOpenSsl; |
| 88 |
} |
| 89 |
|
| 90 |
private function verifyIsOpenSslWorking() |
| 91 |
{ |
| 92 |
$publicKey = <<<EOF |
| 93 |
-----BEGIN PUBLIC KEY----- |
| 94 |
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwQzibtUfAtHeyFwgc0ev |
| 95 |
HnvwSxnM8DBLEBgI/uMWV/GlhbRLqyHMiIe9p7UsMfeOgY4MJmug4j7ITGeYUVeX |
| 96 |
Hit+GLlq5arntlYUyYm09YNPkBzfV6oxPcWScRVmmRXK2L40ZfRHdo24Wz8//Vwo |
| 97 |
ZGWNX0ozq0I6yg5PAyyJt9+DV8dBCUVkDVaQ3qudn4kWSRVb/cD2foeddEcQ1Hni |
| 98 |
dSgvfyrvTF7vPvyIpbHENEBFigUyoHzWXRWmAR2BkdPUN1gLHCaieQPeAOQS704H |
| 99 |
HCDgCgja7zNOP/yT96H4pSyeD/VMj4dmudBjdiFCjfF0VEl5iv5siEBW6KHGP5Ye |
| 100 |
0wIDAQAB |
| 101 |
-----END PUBLIC KEY----- |
| 102 |
EOF; |
| 103 |
|
| 104 |
$data = 'my data'; |
| 105 |
$signature = @base64_decode('Wu8wSnlTaxf3hSGj+6kAY0kP1B9VO3cZ6dTVGda0Ti8cHK/ea1hFqo9nUefppPmrVZrSMrFmkBWeOonHhesJxGUNd3AAd+MF9U8hl5a5H2LiA/IYCBZmWCdnJJrGnD8X0hEV0IEEPSvqK3BA6xzKYfCpi1weCH+BByp9asHdnPNKq3uegoXUxubQ6BOslCMZ6fMt9bNOY/2S5O9iV2N0OrPKa9Wseb2Z8qmo8T1l0Oczz66Gtff8/YHZPvZil45ggfeF8fDOHAdOT8LLDEb9k59X3DrKFI3h4OAqernP2ZrN5EpneCJeq5tSwdbDwbqIh+ghqD7ttb6oY2El6w17yw=='); |
| 106 |
|
| 107 |
/** @handled function */ |
| 108 |
$verifyResult = @openssl_verify($data, $signature, $publicKey, OPENSSL_ALGO_SHA1); |
| 109 |
|
| 110 |
return $verifyResult === 1; |
| 111 |
} |
| 112 |
} |
| 113 |
|