| @@ -305,9 +305,9 @@ | ||
| 305 | 305 | // |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | // 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' ]; | |
| 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', 'puc_cron_check_updates-webarx' ]; | |
| 310 | 310 | foreach ( $tasks as $task ) { |
| 311 | 311 | wp_clear_scheduled_hook( $task ); |
| 312 | 312 | } |
| 313 | 313 | |
| @@ -358,21 +358,14 @@ | ||
| 358 | 358 | 'message' => 'Cannot activate license!', |
| 359 | 359 | ]; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - // Successfully activated. | |
| 362 | + // If we have an access token, tell our API that the firewall is activated | |
| 363 | + // and the current URL of the site. | |
| 363 | 364 | 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. | |
| 365 | + $this->plugin->api->update_license_status(); | |
| 370 | 366 | $token = $this->plugin->api->get_access_token(); |
| 371 | 367 | 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 | 368 | do_action( 'patchstack_send_software_data' ); |
| 376 | 369 | if ( get_option( 'patchstack_license_free', 0 ) != 1 ) { |
| 377 | 370 | update_option( 'patchstack_basic_firewall', 1, true ); |
| 378 | 371 | do_action( 'patchstack_post_firewall_rules' ); |
| @@ -379,11 +372,11 @@ | ||
| 379 | 372 | do_action( 'patchstack_post_dynamic_firewall_rules' ); |
| 380 | 373 | $this->header(); |
| 381 | 374 | } |
| 382 | 375 | |
| 383 | - // Update firewall status, URL and ping API. | |
| 384 | 376 | $this->plugin->api->update_firewall_status( [ 'status' => $this->get_option( 'patchstack_basic_firewall' ) == 1 ] ); |
| 385 | 377 | $this->plugin->api->update_url( [ 'plugin_url' => get_option( 'siteurl' ) ] ); |
| 378 | + $this->plugin->api->ping(); | |
| 386 | 379 | $this->auto_prepend_injection(); |
| 387 | 380 | } |
| 388 | 381 | |
| 389 | 382 | return [ |
| @@ -394,13 +387,9 @@ | ||
| 394 | 387 | |
| 395 | 388 | // Deactivate the license. |
| 396 | 389 | if ( $action == 'deactivate' ) { |
| 397 | 390 | 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 | - | |
| 391 | + update_option( 'patchstack_license_activated', '0', true ); | |
| 403 | 392 | $this->auto_prepend_removal(); |
| 404 | 393 | |
| 405 | 394 | return [ |
| 406 | 395 | 'result' => 'success', |
| @@ -749,9 +738,9 @@ | ||
| 749 | 738 | |
| 750 | 739 | // Ensure that the SERVER_SOFTWARE value is set. |
| 751 | 740 | $software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : ''; |
| 752 | 741 | if ( ! $software ) { |
| 753 | - update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $software ); | |
| 742 | + update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $_SERVER['SERVER_SOFTWARE'] ); | |
| 754 | 743 | return false; |
| 755 | 744 | } |
| 756 | 745 | |
| 757 | 746 | // At this time, reject non-Apache environments. |
| @@ -765,11 +754,11 @@ | ||
| 765 | 754 | $is_litespeed = stripos( $_SERVER['SERVER_SOFTWARE'], 'litespeed' ) !== false || $sapi == 'litespeed'; |
| 766 | 755 | |
| 767 | 756 | // Attempt to find the Apache version, < 2.4 does not support <If>. |
| 768 | 757 | // 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 ); | |
| 758 | + $version = function_exists( 'apache_get_version' ) ? apache_get_version() : $_SERVER['SERVER_SOFTWARE']; | |
| 759 | + if ( stripos( $version, 'Apache/2.4' ) === false ) { | |
| 760 | + update_option( 'patchstack_firewall_ap_error', 'Unsupported SERVER_SOFTWARE, found: ' . $_SERVER['SERVER_SOFTWARE'] ); | |
| 772 | 761 | return false; |
| 773 | 762 | } |
| 774 | 763 | |
| 775 | 764 | // Add c-style slashes. |
| @@ -841,11 +830,10 @@ | ||
| 841 | 830 | * @param mixed $value |
| 842 | 831 | * @return void |
| 843 | 832 | */ |
| 844 | 833 | 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' ] ) ) { | |
| 834 | + // Only allow to run for our options. | |
| 835 | + if ( !in_array( $option_name, [ 'patchstack_basic_firewall', 'patchstack_license_free', 'patchstack_firewall_rules_v3_ap' ] ) ) { | |
| 848 | 836 | return; |
| 849 | 837 | } |
| 850 | 838 | |
| 851 | 839 | // Not strict type matching. |