| @@ -41,13 +41,11 @@ | ||
| 41 | 41 | $rules = $this->plugin->htaccess->get_firewall_rule_settings(); |
| 42 | 42 | $settings = json_encode( $rules ); |
| 43 | 43 | $results = $this->plugin->api->post_firewall_rule( [ 'settings' => $settings ] ); |
| 44 | 44 | |
| 45 | - // If no rules returned (empty, or a status code/null from a failed request), | |
| 46 | - // we assume all settings are turned off. Guard against assigning to a string | |
| 47 | - // offset, which is a fatal error on PHP 7.1+. | |
| 48 | - if ( ! is_array( $results ) ) { | |
| 49 | - $results = [ 'rules' => '' ]; | |
| 45 | + // If no rules returned, we assume all settings are turned off. | |
| 46 | + if ( empty( $results ) ) { | |
| 47 | + $results['rules'] = ''; | |
| 50 | 48 | } |
| 51 | 49 | |
| 52 | 50 | // We have rules so apply it to the .htaccess file. |
| 53 | 51 | if ( isset( $results['rules'] ) ) { |
| @@ -114,31 +112,25 @@ | ||
| 114 | 112 | // Update the counters. |
| 115 | 113 | update_option( 'patchstack_vpatches_present', $vPatchCount ); |
| 116 | 114 | update_option( 'patchstack_non_vpatches_present', $ruleCount ); |
| 117 | 115 | |
| 118 | - // Separate the new firewall engine rules from the old ones. Only touch the | |
| 119 | - // stored whitelists when the API actually returned them, otherwise a partial | |
| 120 | - // response would wipe the existing whitelist rules. | |
| 121 | - if ( isset( $results['whitelists'] ) && is_array( $results['whitelists'] ) ) { | |
| 122 | - $newRules = []; | |
| 123 | - $oldRules = []; | |
| 124 | - foreach ( $results['whitelists'] as $rule ) { | |
| 125 | - if ( isset( $rule['rule_v2'] ) ) { | |
| 126 | - $rule['rules'] = $rule['rule_v2']; | |
| 127 | - unset( $rule['rule_v2'] ); | |
| 128 | - $newRules[] = $rule; | |
| 129 | - } else { | |
| 130 | - $oldRules[] = $rule; | |
| 131 | - } | |
| 116 | + // Separate the new firewall engine rules from the old ones. | |
| 117 | + $newRules = []; | |
| 118 | + $oldRules = []; | |
| 119 | + foreach ( $results['whitelists'] as $rule ) { | |
| 120 | + if ( isset( $rule['rule_v2'] ) ) { | |
| 121 | + $rule['rules'] = $rule['rule_v2']; | |
| 122 | + unset( $rule['rule_v2'] ); | |
| 123 | + $newRules[] = $rule; | |
| 124 | + } else { | |
| 125 | + $oldRules[] = $rule; | |
| 132 | 126 | } |
| 127 | + } | |
| 133 | 128 | |
| 134 | - // Update whitelist rules. | |
| 135 | - update_option( 'patchstack_whitelist_rules', json_encode( $oldRules ), true ); | |
| 136 | - update_option( 'patchstack_whitelist_rules_v3', json_encode( $newRules ), true ); | |
| 137 | - } | |
| 129 | + // Update whitelist rules. | |
| 130 | + update_option( 'patchstack_whitelist_rules', json_encode( $oldRules ), true ); | |
| 131 | + update_option( 'patchstack_whitelist_rules_v3', json_encode( $newRules ), true ); | |
| 138 | 132 | |
| 139 | 133 | // Update the whitelisted keys. |
| 140 | - if ( isset( $results['whitelist_keys'] ) ) { | |
| 141 | - update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ), true ); | |
| 142 | - } | |
| 134 | + update_option( 'patchstack_whitelist_keys_rules', json_encode( $results['whitelist_keys'] ), true ); | |
| 143 | 135 | } |
| 144 | 136 | } |