PluginProbe
Patchstack – WordPress & Plugins Security / 2.3.2
Patchstack – WordPress & Plugins Security v2.3.2
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/activation.php +55 -35 trunk2.3.2 View file →
@@ -42,21 +42,10 @@
42 42 if ( defined( 'WP_CLI' ) && WP_CLI ) {
43 43 return;
44 44 }
45 45
46 - // Only if it's the current plugin.
47 46 if ( $plugin == $this->plugin->basename && ! isset( $_REQUEST['_ajax_nonce'] ) ) {
48 47
49 - // If plugin bulk activate through wp-admin, we ignore the redirect if it's more than 1 plugin.
50 - if ( isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) && count( $_POST['checked'] ) > 1 ) {
51 - return;
52 - }
53 -
54 - // If the plugin is already connected or API activated, no need to redirect again.
55 - if ( $this->license_is_active() || $this->is_connected() ) {
56 - return;
57 - }
58 -
59 48 // Determine if secret token was set, if so, sync with API.
60 49 $attemptAuto = false;
61 50 $secretToken = get_option( 'patchstack_activation_secret', '' );
62 51 if ( ! empty( $secretToken ) ) {
@@ -243,8 +232,51 @@
243 232 }
244 233 }
245 234
246 235 /**
236 + * Used to activate an individual license on multisite/network.
237 + *
238 + * @param object $site
239 + * @param array $license
240 + * @return void
241 + */
242 + public function activate_multisite_license( $site, $license ) {
243 + // Build the Patchstack tables on the site.
244 + $this->migrate( null, $site->id );
245 +
246 + // Add the options to given site.
247 + foreach ( $this->plugin->admin_options->options as $name => $value ) {
248 + add_blog_option( $site->id, $name, $value['default'] );
249 + }
250 +
251 + // Set the client id and secret key.
252 + update_blog_option( $site->id, 'patchstack_clientid', $license['id'] );
253 + $enc = $this->get_secret_key( $license['secret'] );
254 + update_blog_option( $site->id, 'patchstack_secretkey', $enc['cipher'] );
255 + update_blog_option( $site->id, 'patchstack_secretkey_nonce', $enc['nonce'] );
256 +
257 + $this->plugin->api->blog_id = $site->id;
258 +
259 + // Activate the license and update firewall status after activating the plugin.
260 + $token = $this->plugin->api->get_access_token( $license['id'], $license['secret'], true );
261 + if ( ! empty( $token ) ) {
262 + $this->plugin->api->update_firewall_status( [ 'status' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ] );
263 + $this->plugin->api->update_url( [ 'plugin_url' => get_blog_option( $site->id, 'siteurl' ) ] );
264 +
265 + // If we have an access token, tell our API that the firewall is activated
266 + // and the current URL of the site.
267 + update_blog_option( $site->id, 'patchstack_license_activated', '1' );
268 + $this->plugin->api->update_license_status();
269 +
270 + // This will trigger the software synchronization action.
271 + wp_remote_get( get_site_url( $site->id ), [ 'sslverify' => false ] );
272 + }
273 +
274 + // Make sure to switch back to the current blog id.
275 + $this->plugin->api->blog_id = get_current_blog_id();
276 + }
277 +
278 + /**
247 279 * Build the required Patchstack tables.
248 280 *
249 281 * @param null|string $ver The version to upgrade to.
250 282 * @param null|integer $site_id The blog id to perform the upgrades on.
@@ -305,9 +337,9 @@
305 337 //
306 338 }
307 339
308 340 // Clear all Patchstack scheduled tasks.
309 - $tasks = [ 'patchstack_zip_backup', 'patchstack_send_software_data', 'patchstack_send_hacker_logs', 'patchstack_send_visitor_logs', 'patchstack_send_event_logs', 'patchstack_reset_blocked_attacks', 'patchstack_post_firewall_rules', 'patchstack_post_firewall_htaccess_rules', 'patchstack_post_dynamic_firewall_rules', 'patchstack_update_license_status', 'patchstack_update_plugins', 'patchstack_send_ping', 'patchstack_check_env', 'puc_cron_check_updates-webarx' ];
341 + $tasks = [ 'patchstack_zip_backup', 'patchstack_send_software_data', 'patchstack_send_hacker_logs', 'patchstack_send_visitor_logs', 'patchstack_send_event_logs', 'patchstack_reset_blocked_attacks', 'patchstack_post_firewall_rules', 'patchstack_post_firewall_htaccess_rules', 'patchstack_post_dynamic_firewall_rules', 'patchstack_update_license_status', 'patchstack_update_plugins', 'patchstack_send_ping', 'puc_cron_check_updates-webarx' ];
310 342 foreach ( $tasks as $task ) {
311 343 wp_clear_scheduled_hook( $task );
312 344 }
313 345
@@ -358,21 +390,14 @@
358 390 'message' => 'Cannot activate license!',
359 391 ];
360 392 }
361 393
362 - // Successfully activated.
394 + // If we have an access token, tell our API that the firewall is activated
395 + // and the current URL of the site.
363 396 update_option( 'patchstack_license_activated', '1', true );
364 -
365 - // Update license status and fetch policy settings.
366 - $fetchPolicy = (int) get_option( 'patchstack_last_license_check', 0 ) == 0;
367 - $this->plugin->api->update_license_status( $fetchPolicy );
368 -
369 - // Perform post-activation actions, incl. access token retrieval.
397 + $this->plugin->api->update_license_status();
370 398 $token = $this->plugin->api->get_access_token();
371 399 if ( ! empty( $token ) ) {
372 -
373 - // Immediately send software data to our server to set firewall as enabled.
374 - // Also immediately download the whitelist file and the firewall rules.
375 400 do_action( 'patchstack_send_software_data' );
376 401 if ( get_option( 'patchstack_license_free', 0 ) != 1 ) {
377 402 update_option( 'patchstack_basic_firewall', 1, true );
378 403 do_action( 'patchstack_post_firewall_rules' );
@@ -379,11 +404,11 @@
379 404 do_action( 'patchstack_post_dynamic_firewall_rules' );
380 405 $this->header();
381 406 }
382 407
383 - // Update firewall status, URL and ping API.
384 408 $this->plugin->api->update_firewall_status( [ 'status' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ] );
385 409 $this->plugin->api->update_url( [ 'plugin_url' => get_option( 'siteurl' ) ] );
410 + $this->plugin->api->ping();
386 411 $this->auto_prepend_injection();
387 412 }
388 413
389 414 return [
@@ -394,13 +419,9 @@
394 419
395 420 // Deactivate the license.
396 421 if ( $action == 'deactivate' ) {
397 422 update_option( 'patchstack_api_token', '' );
398 - update_option( 'patchstack_license_activated', '0' );
399 - update_option( 'patchstack_clientid', '' );
400 - update_option( 'patchstack_secretkey', '' );
401 - update_option( 'patchstack_secretkey_nonce', '' );
402 -
423 + update_option( 'patchstack_license_activated', '0', true );
403 424 $this->auto_prepend_removal();
404 425
405 426 return [
406 427 'result' => 'success',
@@ -749,9 +770,9 @@
749 770
750 771 // Ensure that the SERVER_SOFTWARE value is set.
751 772 $software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
752 773 if ( ! $software ) {
753 - update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $software );
774 + update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $_SERVER['SERVER_SOFTWARE'] );
754 775 return false;
755 776 }
756 777
757 778 // At this time, reject non-Apache environments.
@@ -765,11 +786,11 @@
765 786 $is_litespeed = stripos( $_SERVER['SERVER_SOFTWARE'], 'litespeed' ) !== false || $sapi == 'litespeed';
766 787
767 788 // Attempt to find the Apache version, < 2.4 does not support <If>.
768 789 // This depends on ServerTokens value, so only stop execution if we can't find the specific unsupported versions.
769 - $version = function_exists( 'apache_get_version' ) ? apache_get_version() : $software;
770 - if ( ! $is_litespeed && stripos( $version, 'Apache/2.4' ) === false ) {
771 - update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $software );
790 + $version = function_exists( 'apache_get_version' ) ? apache_get_version() : $_SERVER['SERVER_SOFTWARE'];
791 + if ( stripos( $version, 'Apache/2.4' ) === false ) {
792 + update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $_SERVER['SERVER_SOFTWARE'] );
772 793 return false;
773 794 }
774 795
775 796 // Add c-style slashes.
@@ -841,11 +862,10 @@
841 862 * @param mixed $value
842 863 * @return void
843 864 */
844 865 public function updated_option( $option_name, $old_value, $value ) {
845 - // Only allow to run for our options. The IP header is embedded in the AP config
846 - // file too, so a change there must also regenerate it.
847 - if ( !in_array( $option_name, [ 'patchstack_basic_firewall', 'patchstack_license_free', 'patchstack_firewall_rules_v3_ap', 'patchstack_firewall_ip_header' ] ) ) {
866 + // Only allow to run for our options.
867 + if ( !in_array( $option_name, [ 'patchstack_basic_firewall', 'patchstack_license_free', 'patchstack_firewall_rules_v3_ap' ] ) ) {
848 868 return;
849 869 }
850 870
851 871 // Not strict type matching.