Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Worker
File: Configuration.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Worker_Configuration
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
private $context;
[13] Fix | Delete
[14] Fix | Delete
public function __construct(MWP_WordPress_Context $context)
[15] Fix | Delete
{
[16] Fix | Delete
$this->context = $context;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
public function getPublicKey()
[20] Fix | Delete
{
[21] Fix | Delete
return base64_decode($this->context->optionGet('_worker_public_key'));
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
public function setPublicKey($publicKey)
[25] Fix | Delete
{
[26] Fix | Delete
$this->context->optionSet('_worker_public_key', base64_encode($publicKey), true);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
public function deletePublicKey()
[30] Fix | Delete
{
[31] Fix | Delete
$this->context->optionDelete('_worker_public_key');
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* @return string
[36] Fix | Delete
*
[37] Fix | Delete
* @deprecated Use public key instead.
[38] Fix | Delete
*/
[39] Fix | Delete
public function getSecureKey()
[40] Fix | Delete
{
[41] Fix | Delete
return base64_decode($this->context->optionGet('_worker_nossl_key'));
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* @param $secureKey
[46] Fix | Delete
*
[47] Fix | Delete
* @deprecated Use public key instead.
[48] Fix | Delete
*/
[49] Fix | Delete
public function setSecureKey($secureKey)
[50] Fix | Delete
{
[51] Fix | Delete
$this->context->optionSet('_worker_nossl_key', base64_encode($secureKey));
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function deleteSecureKey()
[55] Fix | Delete
{
[56] Fix | Delete
$this->context->optionSet('_worker_nossl_key', '');
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
public function getLivePublicKey($keyName, $prefix = false)
[60] Fix | Delete
{
[61] Fix | Delete
$keyData = $this->findKeyData($keyName, $prefix);
[62] Fix | Delete
return $keyData !== null ? $keyData['publicKey'] : null;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
public function isCommunicationKey($keyName)
[66] Fix | Delete
{
[67] Fix | Delete
$keyData = $this->findKeyData($keyName);
[68] Fix | Delete
return ($keyData === null || empty($keyData['useServiceKey']));
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
public function getCommunicationStringByKeyName($keyName)
[72] Fix | Delete
{
[73] Fix | Delete
return $this->isCommunicationKey($keyName) ? mwp_get_communication_key() : mwp_get_service_key();
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
public function acceptCommunicationKeyIfEmpty($keyName, $communicationKey)
[77] Fix | Delete
{
[78] Fix | Delete
if (!$this->isCommunicationKey($keyName)) {
[79] Fix | Delete
return;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
mwp_add_as_site_communication_key($communicationKey);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
protected function findKeyData($keyName, $prefix = false)
[86] Fix | Delete
{
[87] Fix | Delete
$key = $this->findKey($keyName, $prefix);
[88] Fix | Delete
[89] Fix | Delete
if (!empty($key)) {
[90] Fix | Delete
return $key;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$time = time();
[94] Fix | Delete
$keys = $this->context->optionGet('mwp_public_keys', null);
[95] Fix | Delete
$refresh_time = $this->context->optionGet('mwp_public_keys_refresh_time', $time - 100000);
[96] Fix | Delete
[97] Fix | Delete
// if the keys were refreshed recently, give up
[98] Fix | Delete
if (!empty($keys) && $time - $refresh_time < 86400) {
[99] Fix | Delete
return null;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
mwp_refresh_live_public_keys(array());
[103] Fix | Delete
[104] Fix | Delete
return $this->findKey($keyName, $prefix);
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
private function findKey($keyName, $prefix = false)
[108] Fix | Delete
{
[109] Fix | Delete
$keys = $this->context->optionGet('mwp_public_keys', null);
[110] Fix | Delete
[111] Fix | Delete
if (empty($keys) || !is_array($keys)) {
[112] Fix | Delete
return null;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
foreach ($keys as $key) {
[116] Fix | Delete
if (empty($key['id']) || ($key['id'] !== $keyName && !$prefix) || ($key['service'] !== $keyName && $prefix)) {
[117] Fix | Delete
continue;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if (empty($key['validFrom']) || empty($key['validTo']) || empty($key['publicKey']) || empty($key['service'])) {
[121] Fix | Delete
continue;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
$timeNow = new DateTime();
[125] Fix | Delete
[126] Fix | Delete
if ($timeNow < new DateTime($key['validFrom']) || $timeNow > new DateTime($key['validTo'])) {
[127] Fix | Delete
continue;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return $key;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
return null;
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function