PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.1
Patchstack – WordPress & Plugins Security v2.2.1
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/api.php +37 -33 2.1.242.2.1 View file →
@@ -23,10 +23,10 @@
23 23 */
24 24 public function __construct( $core ) {
25 25 parent::__construct( $core );
26 26 $this->blog_id = get_current_blog_id();
27 - add_action( 'patchstack_update_license_status', array( $this, 'update_license_status' ) );
28 - add_action( 'patchstack_send_ping', array( $this, 'ping' ) );
27 + add_action( 'patchstack_update_license_status', [ $this, 'update_license_status' ] );
28 + add_action( 'patchstack_send_ping', [ $this, 'ping' ] );
29 29 }
30 30
31 31 /**
32 32 * Get the API token.
@@ -50,12 +50,12 @@
50 50 if ( $response && $response->result == 'success' ) {
51 51 $this->update_blog_option(
52 52 $this->blog_id,
53 53 'patchstack_api_token',
54 - array(
54 + [
55 55 'token' => $response->message,
56 56 'expiresin' => $response->expiresin,
57 - )
57 + ]
58 58 );
59 59 return $response->message;
60 60 }
61 61
@@ -68,17 +68,17 @@
68 68 * Fetch the API Token from API Server.
69 69 *
70 70 * @param string $clientid The API client ID.
71 71 * @param string $secretkey The API secret key.
72 - * @return string|array|object
72 + * @return string|array
73 73 */
74 74 public function fetch_access_token( $clientid = '', $secretkey = '' ) {
75 75 // Skeleton for the response data.
76 - $response_data = (object) array(
76 + $response_data = (object) [
77 77 'result' => '',
78 78 'message' => '',
79 79 'expiresin' => '',
80 - );
80 + ];
81 81
82 82 // Determine if the license id/key is set.
83 83 $client_id = $this->get_blog_option( $this->blog_id, 'patchstack_clientid', $clientid );
84 84
@@ -98,22 +98,22 @@
98 98
99 99 // Send a request to our server to obtain the access token.
100 100 $response = wp_remote_post(
101 101 $this->plugin->auth_url . '/oauth/token',
102 - array(
102 + [
103 103 'method' => 'POST',
104 104 'timeout' => 60,
105 105 'redirection' => 5,
106 106 'httpversion' => '1.0',
107 107 'blocking' => true,
108 - 'headers' => array(),
109 - 'body' => array(
108 + 'headers' => [],
109 + 'body' => [
110 110 'client_id' => $client_id,
111 111 'client_secret' => $client_secret,
112 112 'grant_type' => 'client_credentials',
113 - ),
114 - 'cookies' => array(),
115 - )
113 + ],
114 + 'cookies' => [],
115 + ]
116 116 );
117 117
118 118 // Stop if we received an error from the API.
119 119 if ( is_wp_error( $response ) ) {
@@ -189,8 +189,17 @@
189 189 $this->update_blog_option( $this->blog_id, 'patchstack_subscription_class', $response['class'] );
190 190 $this->update_blog_option( $this->blog_id, 'patchstack_last_license_check', time() );
191 191 }
192 192
193 + if ( isset( $response['managed'], $response['managed_string'] ) ) {
194 + $this->update_blog_option( $this->blog_id, 'patchstack_managed', $response['managed'] );
195 + $this->update_blog_option( $this->blog_id, 'patchstack_managed_text', $response['managed_string'] );
196 + }
197 +
198 + if ( isset( $response['site_id'] ) ) {
199 + $this->update_blog_option( $this->blog_id, 'patchstack_site_id', $response['site_id'] );
200 + }
201 +
193 202 return $response;
194 203 }
195 204
196 205 /**
@@ -200,9 +209,9 @@
200 209 * @param string $request
201 210 * @param array $data
202 211 * @return void|array If successful array, otherwise void.
203 212 */
204 - public function send_request( $url, $request, $data = array() ) {
213 + public function send_request( $url, $request, $data = [] ) {
205 214 // Attempt to get the access token.
206 215 $token = $this->get_access_token();
207 216 if ( empty( $token ) ) {
208 217 return;
@@ -210,22 +219,22 @@
210 219
211 220 // Send the remote request using the WordPress built-in method.
212 221 $response = wp_remote_request(
213 222 $this->plugin->api_url . $url,
214 - array(
223 + [
215 224 'method' => $request,
216 225 'timeout' => 60,
217 226 'redirection' => 5,
218 227 'httpversion' => '1.0',
219 228 'blocking' => true,
220 - 'headers' => array(
229 + 'headers' => [
221 230 'Authorization' => 'Bearer ' . $token,
222 231 'LicenseID' => $this->get_blog_option( $this->blog_id, 'patchstack_clientid', 0 ),
223 232 'Source-Host' => get_site_url(),
224 - ),
233 + ],
225 234 'body' => $data,
226 - 'cookies' => array(),
227 - )
235 + 'cookies' => [],
236 + ]
228 237 );
229 238
230 239 // Check error or status code.
231 240 if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
@@ -251,23 +260,23 @@
251 260
252 261 // Tell our API.
253 262 wp_remote_request(
254 263 $this->plugin->api_url . '/api/header',
255 - array(
264 + [
256 265 'method' => 'POST',
257 266 'timeout' => 60,
258 267 'redirection' => 5,
259 268 'httpversion' => '1.0',
260 269 'blocking' => true,
261 - 'headers' => array(
270 + 'headers' => [
262 271 'Source-Host' => get_site_url(),
263 - ),
264 - 'body' => array(
272 + ],
273 + 'body' => [
265 274 'token' => $ott,
266 275 'url' => get_site_url()
267 - ),
268 - 'cookies' => array(),
269 - )
276 + ],
277 + 'cookies' => [],
278 + ]
270 279 );
271 280 }
272 281 }
273 282
@@ -276,14 +285,9 @@
276 285 *
277 286 * @return array The firewall rules.
278 287 */
279 288 public function post_firewall_rule_json() {
280 - // If the request is coming from the API, fetch fresh rules.
281 - if ( isset( $_POST['webarx_refresh_rules'] ) ) {
282 - return $this->send_request( '/api/get-rules/2?bypass=cache', 'POST' );
283 - }
284 -
285 - return $this->send_request( '/api/get-rules/2', 'POST' );
289 + return $this->send_request( '/api/get-rules/3', 'POST' );
286 290 }
287 291
288 292 /**
289 293 * Get the .htaccess rules.
@@ -373,7 +377,7 @@
373 377 *
374 378 * @return void
375 379 */
376 380 public function ping() {
377 - $this->send_request( '/api/ping', 'POST', array( 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ) );
381 + $this->send_request( '/api/ping', 'POST', [ 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ] );
378 382 }
379 383 }