| @@ -17,11 +17,11 @@ | ||
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | 19 | public function __construct( $core ) { |
| 20 | 20 | parent::__construct( $core ); |
| 21 | - add_action( 'patchstack_post_firewall_rules', array( $this, 'post_firewall_rules' ) ); | |
| 22 | - add_action( 'patchstack_post_firewall_htaccess_rules', array( $this, 'post_firewall_htaccess_rules' ) ); | |
| 23 | - add_action( 'patchstack_post_dynamic_firewall_rules', array( $this, 'dynamic_firewall_rules' ) ); | |
| 21 | + add_action( 'patchstack_post_firewall_rules', [ $this, 'post_firewall_rules' ] ); | |
| 22 | + add_action( 'patchstack_post_firewall_htaccess_rules', [ $this, 'post_firewall_htaccess_rules' ] ); | |
| 23 | + add_action( 'patchstack_post_dynamic_firewall_rules', [ $this, 'dynamic_firewall_rules' ] ); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Pull the hardening .htaccess rules from the API. |
| @@ -35,9 +35,9 @@ | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $rules = $this->plugin->htaccess->get_firewall_rule_settings(); |
| 38 | 38 | $settings = json_encode( $rules ); |
| 39 | - $results = $this->plugin->api->post_firewall_rule( array( 'settings' => $settings ) ); | |
| 39 | + $results = $this->plugin->api->post_firewall_rule( [ 'settings' => $settings ] ); | |
| 40 | 40 | |
| 41 | 41 | // If no rules returned, we assume all settings are turned off. |
| 42 | 42 | if ( empty( $results ) ) { |
| 43 | 43 | $results['rules'] = ''; |
| @@ -89,16 +89,44 @@ | ||
| 89 | 89 | if ( ! isset( $results['firewall'] ) ) { |
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + // Separate the new firewall engine rules from the old ones. | |
| 94 | + $rules = $results['firewall']; | |
| 95 | + $newRules = []; | |
| 96 | + $oldRules = []; | |
| 97 | + foreach ( $rules as $rule ) { | |
| 98 | + if ( isset( $rule['rule_v2'] ) ) { | |
| 99 | + $rule['rules'] = $rule['rule_v2']; | |
| 100 | + unset($rule['rule_v2']); | |
| 101 | + $newRules[] = $rule; | |
| 102 | + } else { | |
| 103 | + $oldRules[] = $rule; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + | |
| 93 | 107 | // Update firewall rules. |
| 94 | - update_option( 'patchstack_firewall_rules', json_encode( $results['firewall'] ) ); | |
| 108 | + update_option( 'patchstack_firewall_rules', json_encode( $oldRules ) ); | |
| 109 | + update_option( 'patchstack_firewall_rules_v3', json_encode( $newRules ) ); | |
| 95 | 110 | |
| 111 | + // Separate the new firewall engine rules from the old ones. | |
| 112 | + $rules = $results['whitelists']; | |
| 113 | + $newRules = []; | |
| 114 | + $oldRules = []; | |
| 115 | + foreach ( $rules as $rule ) { | |
| 116 | + if ( isset( $rule['rule_v2'] ) ) { | |
| 117 | + $rule['rules'] = $rule['rule_v2']; | |
| 118 | + unset($rule['rule_v2']); | |
| 119 | + $newRules[] = $rule; | |
| 120 | + } else { | |
| 121 | + $oldRules[] = $rule; | |
| 122 | + } | |
| 123 | + } | |
| 124 | + | |
| 96 | 125 | // Update whitelist rules. |
| 97 | - update_option( 'patchstack_whitelist_rules', json_encode( $results['whitelists'] ) ); | |
| 126 | + update_option( 'patchstack_whitelist_rules', json_encode( $oldRules ) ); | |
| 127 | + update_option( 'patchstack_whitelist_rules_v3', json_encode( $newRules ) ); | |
| 98 | 128 | |
| 99 | - // Update secondary whitelist rules. | |
| 100 | - if ( isset( $results['whitelist_keys'] ) ) { | |
| 101 | - update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ) ); | |
| 102 | - } | |
| 129 | + // Update the whitelisted keys. | |
| 130 | + update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ) ); | |
| 103 | 131 | } |
| 104 | 132 | } |