| @@ -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 ) ) { |
| @@ -175,15 +175,16 @@ | ||
| 175 | 175 | $this->update_blog_option( $this->blog_id, 'patchstack_license_free', $response['free'] == false ? 0 : 1 ); |
| 176 | 176 | |
| 177 | 177 | if ( $response['free'] == true ) { |
| 178 | 178 | $this->update_blog_option( $this->blog_id, 'patchstack_show_settings', 0 ); |
| 179 | + $this->update_blog_option( $this->blog_id, 'patchstack_firewall_rules_v3', '[]' ); | |
| 179 | 180 | } else { |
| 180 | 181 | $this->send_header_request(); |
| 181 | 182 | } |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | - if ( isset( $response['active'] ) && $response['active'] == true ) { | |
| 185 | - $this->update_blog_option( $this->blog_id, 'patchstack_license_activated', true ); | |
| 185 | + if ( isset( $response['active'] ) ) { | |
| 186 | + $this->update_blog_option( $this->blog_id, 'patchstack_license_activated', $response['active'] == true ); | |
| 186 | 187 | } |
| 187 | 188 | |
| 188 | 189 | if ( isset( $response['class'] ) ) { |
| 189 | 190 | $this->update_blog_option( $this->blog_id, 'patchstack_subscription_class', $response['class'] ); |
| @@ -189,8 +190,17 @@ | ||
| 189 | 190 | $this->update_blog_option( $this->blog_id, 'patchstack_subscription_class', $response['class'] ); |
| 190 | 191 | $this->update_blog_option( $this->blog_id, 'patchstack_last_license_check', time() ); |
| 191 | 192 | } |
| 192 | 193 | |
| 194 | + if ( isset( $response['managed'], $response['managed_string'] ) ) { | |
| 195 | + $this->update_blog_option( $this->blog_id, 'patchstack_managed', $response['managed'] ); | |
| 196 | + $this->update_blog_option( $this->blog_id, 'patchstack_managed_text', $response['managed_string'] ); | |
| 197 | + } | |
| 198 | + | |
| 199 | + if ( isset( $response['site_id'] ) ) { | |
| 200 | + $this->update_blog_option( $this->blog_id, 'patchstack_site_id', $response['site_id'] ); | |
| 201 | + } | |
| 202 | + | |
| 193 | 203 | return $response; |
| 194 | 204 | } |
| 195 | 205 | |
| 196 | 206 | /** |
| @@ -200,9 +210,9 @@ | ||
| 200 | 210 | * @param string $request |
| 201 | 211 | * @param array $data |
| 202 | 212 | * @return void|array If successful array, otherwise void. |
| 203 | 213 | */ |
| 204 | - public function send_request( $url, $request, $data = array() ) { | |
| 214 | + public function send_request( $url, $request, $data = [] ) { | |
| 205 | 215 | // Attempt to get the access token. |
| 206 | 216 | $token = $this->get_access_token(); |
| 207 | 217 | if ( empty( $token ) ) { |
| 208 | 218 | return; |
| @@ -210,22 +220,22 @@ | ||
| 210 | 220 | |
| 211 | 221 | // Send the remote request using the WordPress built-in method. |
| 212 | 222 | $response = wp_remote_request( |
| 213 | 223 | $this->plugin->api_url . $url, |
| 214 | - array( | |
| 224 | + [ | |
| 215 | 225 | 'method' => $request, |
| 216 | 226 | 'timeout' => 60, |
| 217 | 227 | 'redirection' => 5, |
| 218 | 228 | 'httpversion' => '1.0', |
| 219 | 229 | 'blocking' => true, |
| 220 | - 'headers' => array( | |
| 230 | + 'headers' => [ | |
| 221 | 231 | 'Authorization' => 'Bearer ' . $token, |
| 222 | 232 | 'LicenseID' => $this->get_blog_option( $this->blog_id, 'patchstack_clientid', 0 ), |
| 223 | 233 | 'Source-Host' => get_site_url(), |
| 224 | - ), | |
| 234 | + ], | |
| 225 | 235 | 'body' => $data, |
| 226 | - 'cookies' => array(), | |
| 227 | - ) | |
| 236 | + 'cookies' => [], | |
| 237 | + ] | |
| 228 | 238 | ); |
| 229 | 239 | |
| 230 | 240 | // Check error or status code. |
| 231 | 241 | if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) { |
| @@ -251,23 +261,23 @@ | ||
| 251 | 261 | |
| 252 | 262 | // Tell our API. |
| 253 | 263 | wp_remote_request( |
| 254 | 264 | $this->plugin->api_url . '/api/header', |
| 255 | - array( | |
| 265 | + [ | |
| 256 | 266 | 'method' => 'POST', |
| 257 | 267 | 'timeout' => 60, |
| 258 | 268 | 'redirection' => 5, |
| 259 | 269 | 'httpversion' => '1.0', |
| 260 | 270 | 'blocking' => true, |
| 261 | - 'headers' => array( | |
| 271 | + 'headers' => [ | |
| 262 | 272 | 'Source-Host' => get_site_url(), |
| 263 | - ), | |
| 264 | - 'body' => array( | |
| 273 | + ], | |
| 274 | + 'body' => [ | |
| 265 | 275 | 'token' => $ott, |
| 266 | 276 | 'url' => get_site_url() |
| 267 | - ), | |
| 268 | - 'cookies' => array(), | |
| 269 | - ) | |
| 277 | + ], | |
| 278 | + 'cookies' => [], | |
| 279 | + ] | |
| 270 | 280 | ); |
| 271 | 281 | } |
| 272 | 282 | } |
| 273 | 283 | |
| @@ -276,14 +286,9 @@ | ||
| 276 | 286 | * |
| 277 | 287 | * @return array The firewall rules. |
| 278 | 288 | */ |
| 279 | 289 | 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' ); | |
| 290 | + return $this->send_request( '/api/get-rules/3', 'POST' ); | |
| 286 | 291 | } |
| 287 | 292 | |
| 288 | 293 | /** |
| 289 | 294 | * Get the .htaccess rules. |
| @@ -373,7 +378,7 @@ | ||
| 373 | 378 | * |
| 374 | 379 | * @return void |
| 375 | 380 | */ |
| 376 | 381 | public function ping() { |
| 377 | - $this->send_request( '/api/ping', 'POST', array( 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ) ); | |
| 382 | + $this->send_request( '/api/ping', 'POST', [ 'firewall' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ? 1 : 0 ] ); | |
| 378 | 383 | } |
| 379 | 384 | } |