PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Configuration/License.php +30 -0 10.10.2 → 11.1.0 View file →
@@ -7,8 +7,10 @@
7 7 trait License
8 8 {
9 9 public function unlinkLicense(): void
10 10 {
11 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
12 +
11 13 $config = acym_getVar('array', 'config', []);
12 14 $licenseKey = empty($config['license_key']) ? $this->config->get('license_key') : $config['license_key'];
13 15
14 16 $resultUnlinkLicenseOnUpdateMe = $this->unlinkLicenseOnUpdateMe($licenseKey);
@@ -21,14 +23,17 @@
21 23 if (!empty($resultUnlinkLicenseOnUpdateMe['message'])) {
22 24 $this->displayMessage($resultUnlinkLicenseOnUpdateMe['message']);
23 25 }
24 26
27 + //Display the configuration
25 28 $this->listing();
26 29 }
27 30
28 31 public function attachLicense(): void
29 32 {
33 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
30 34
35 +
31 36 $config = acym_getVar('array', 'config', []);
32 37 if (empty($config['license_key'])) {
33 38 $this->displayMessage(acym_translation('ACYM_PLEASE_SET_A_LICENSE_KEY'));
34 39 $this->listing();
@@ -35,10 +40,12 @@
35 40
36 41 return;
37 42 }
38 43
44 + //We save the license key
39 45 $this->config->saveConfig(['license_key' => $config['license_key']]);
40 46
47 + //We call updateme to attach the website to the license
41 48 $resultAttachLicenseOnUpdateMe = $this->attachLicenseOnUpdateMe();
42 49
43 50 if ($resultAttachLicenseOnUpdateMe['success'] === false) {
44 51 $this->config->saveConfig(['license_key' => '']);
@@ -55,8 +62,9 @@
55 62
56 63 public function attachLicenseOnUpdateMe(?string $licenseKey = null): array
57 64 {
58 65
66 + //We get the license key saved
59 67 if (is_null($licenseKey)) {
60 68 $licenseKey = $this->config->get('license_key', '');
61 69 }
62 70
@@ -78,8 +86,10 @@
78 86 ];
79 87
80 88 $resultAttach = UpdatemeHelper::call('api/websites/attach', 'POST', $data);
81 89
90 + // If it's not the result well formatted => don't save the license key and out
91 + // If there is an error when the website has been attached => don't save the license key in the configuration
82 92 if (empty($resultAttach) || !$resultAttach['success']) {
83 93 return $return;
84 94 }
85 95
@@ -89,8 +99,9 @@
89 99 }
90 100
91 101 private function unlinkLicenseOnUpdateMe(?string $licenseKey = null): array
92 102 {
103 + //We get the license key saved
93 104 if (is_null($licenseKey)) {
94 105 $licenseKey = $this->config->get('license_key');
95 106 }
96 107
@@ -104,8 +115,9 @@
104 115
105 116 return $return;
106 117 }
107 118
119 + //First let's deactivate the cron
108 120 $this->deactivateCron(false, $licenseKey);
109 121
110 122 $data = [
111 123 'domain' => ACYM_LIVE,
@@ -110,10 +122,12 @@
110 122 $data = [
111 123 'domain' => ACYM_LIVE,
112 124 ];
113 125
126 + //Call updateme to unlink the license from this website
114 127 $resultUnlink = UpdatemeHelper::call('api/websites/unlink', 'POST', $data);
115 128
129 + //If it's not the result well formated => out
116 130 if (empty($resultUnlink) || !$resultUnlink['success']) {
117 131 return $return;
118 132 }
119 133
@@ -123,10 +137,13 @@
123 137 }
124 138
125 139 public function activateCron(): void
126 140 {
141 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
127 142
143 +
128 144 $result = $this->modifyCron('activateCron');
145 + //If everything went ok we save config with an active_cron to true
129 146 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
130 147 $this->config->saveConfig(['active_cron' => 1]);
131 148 }
132 149
@@ -132,12 +149,19 @@
132 149
133 150 $this->listing();
134 151 }
135 152
153 + //The listing parameter allows us to know if we need to display the listing or not
136 154 public function deactivateCron(bool $listing = true, ?string $licenseKey = null): void
137 155 {
156 + // Called as a task (no argument) → require a CSRF token. Internal calls (e.g. unlinkLicense) are already token-checked.
157 + if (func_num_args() === 0) {
158 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
159 + }
138 160
161 +
139 162 $result = $this->modifyCron('deactivateCron', $licenseKey);
163 + //If everything went ok we save config with an active_cron to false
140 164 if (!empty($result) && !empty($this->displayMessage($result['message']))) {
141 165 $this->config->saveConfig(['active_cron' => 0]);
142 166 }
143 167
@@ -145,8 +169,9 @@
145 169 $this->listing();
146 170 }
147 171 }
148 172
173 + //The listing parameter allows us to know if we need to display the listing or not
149 174 public function modifyCron(string $functionToCall, ?string $licenseKey = null): array
150 175 {
151 176 if (is_null($licenseKey)) {
152 177 $config = acym_getVar('array', 'config', []);
@@ -152,8 +177,9 @@
152 177 $config = acym_getVar('array', 'config', []);
153 178 $licenseKey = empty($config['license_key']) ? '' : $config['license_key'];
154 179 }
155 180
181 + //If the license is not set => out
156 182 if (empty($licenseKey)) {
157 183 $this->displayMessage('LICENSE_NOT_FOUND');
158 184
159 185 return [];
@@ -167,10 +193,12 @@
167 193 'activate' => $functionToCall === 'activateCron',
168 194 'security_key' => $this->config->get('cron_key'),
169 195 ];
170 196
197 + //We call updateme to activate/deactivate the cron
171 198 $result = UpdatemeHelper::call('api/crons/modify', 'POST', $data);
172 199
200 + //If it's not the result well formated => out
173 201 if (empty($result['success'])) {
174 202 $this->displayMessage(empty($result['message']) ? 'CRON_NOT_SAVED' : $result['message']);
175 203
176 204 return [];
@@ -180,8 +208,10 @@
180 208 }
181 209
182 210 public function attachLicenseAcymailer(): void
183 211 {
212 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
213 +
184 214 $acyMailerLicenseKey = $this->config->get('acymailer_apikey');
185 215 $acyMailingKey = $this->config->get('license_key');
186 216 if (empty($acyMailerLicenseKey) && !empty($acyMailingKey)) {
187 217 acym_trigger('onAcymAttachLicense', [&$acyMailingKey]);