PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Action / ConnectWebsite.php

ConnectWebsite.php in ManageWP Worker 4.9.25, at src/MWP/Action/ConnectWebsite.php

63 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_Action_ConnectWebsite extends MWP_Action_Abstract
12 {
13
14 public function execute(array $params = array(), MWP_Worker_Request $request)
15 {
16 if (empty($params['public_key'])) {
17 throw new MWP_Worker_Exception(MWP_Worker_Exception::CONNECTION_PUBLIC_KEY_NOT_PROVIDED);
18 }
19
20 $siteId = $request->getSiteId();
21 $communicationKey = mwp_get_communication_key();
22 $publicKey = base64_decode($params['public_key']);
23 $configuration = $this->container->getConfiguration();
24 $existingPublicKey = $configuration->getPublicKey();
25
26 if (empty($siteId) && ((!empty($existingPublicKey) && $publicKey !== $existingPublicKey) || !empty($communicationKey))) {
27 throw new MWP_Worker_Exception(MWP_Worker_Exception::CONNECTION_PUBLIC_KEY_EXISTS, "Sorry, the site appears to be already added to a ManageWP account. Please deactivate, then activate ManageWP Worker plugin on your website and try again or contact our support.");
28 }
29
30 if (!empty($params['skipVerificationTest'])) {
31 // Legacy support for worker key.
32 $signer = $this->container->getSigner();
33 $messageId = $request->getAction().$request->getNonce();
34 $verify = $signer->verify($messageId, $request->getSignature(), $publicKey);
35
36 if (!$verify) {
37 throw new MWP_Worker_Exception(MWP_Worker_Exception::CONNECTION_VERIFICATION_TEST_FAILED, "Unable to verify security signature. Contact your hosting support to check the OpenSSL configuration.");
38 }
39 }
40
41 if (empty($existingPublicKey)) {
42 $configuration->setPublicKey($publicKey);
43 }
44
45 mwp_accept_potential_key($request->getCommunicationKey());
46
47 $this->setBrand($params);
48
49 return array();
50 }
51
52 private function setBrand(array $params)
53 {
54 if (!empty($params['brand']) && is_array($params['brand'])) {
55 $this->container->getBrand()->update($params['brand']);
56
57 return;
58 }
59
60 $this->container->getBrand()->delete();
61 }
62 }
63