← All changes
|
jetpack_vendor/automattic/jetpack-waf/src/class-rest-controller.php
+31
-12
13.6.2
→
16.3-beta
View file →
| @@ -78,9 +78,9 @@ | ||
| 78 | 78 | |
| 79 | 79 | return rest_ensure_response( |
| 80 | 80 | array( |
| 81 | 81 | 'success' => true, |
| 82 | - 'message' => __( 'Rules updated succesfully', 'jetpack-waf' ), | |
| 82 | + 'message' => __( 'Rules updated successfully', 'jetpack-waf' ), | |
| 83 | 83 | ) |
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
| @@ -89,9 +89,17 @@ | ||
| 89 | 89 | * |
| 90 | 90 | * @return WP_REST_Response |
| 91 | 91 | */ |
| 92 | 92 | public static function waf() { |
| 93 | - return rest_ensure_response( Waf_Runner::get_config() ); | |
| 93 | + return rest_ensure_response( | |
| 94 | + array_merge( | |
| 95 | + Waf_Runner::get_config(), | |
| 96 | + array( | |
| 97 | + 'waf_supported' => Waf_Runner::is_supported_environment(), | |
| 98 | + 'automatic_rules_last_updated' => Waf_Stats::get_automatic_rules_last_updated(), | |
| 99 | + ) | |
| 100 | + ) | |
| 101 | + ); | |
| 94 | 102 | } |
| 95 | 103 | |
| 96 | 104 | /** |
| 97 | 105 | * Update WAF Endpoint |
| @@ -102,14 +110,19 @@ | ||
| 102 | 110 | */ |
| 103 | 111 | public static function update_waf( $request ) { |
| 104 | 112 | // Automatic Rules Enabled |
| 105 | 113 | if ( isset( $request[ Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ] ) ) { |
| 106 | - update_option( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME, (bool) $request->get_param( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ) ); | |
| 114 | + update_option( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME, $request->get_param( Waf_Rules_Manager::AUTOMATIC_RULES_ENABLED_OPTION_NAME ) ? '1' : '' ); | |
| 107 | 115 | } |
| 108 | 116 | |
| 109 | - // IP Lists Enabled | |
| 110 | - if ( isset( $request[ Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME ] ) ) { | |
| 111 | - update_option( Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME, (bool) $request->get_param( Waf_Rules_Manager::IP_LISTS_ENABLED_OPTION_NAME ) ); | |
| 117 | + /** | |
| 118 | + * IP Lists Enabled | |
| 119 | + * | |
| 120 | + * @deprecated 0.17.0 This is a legacy option maintained here for backwards compatibility. | |
| 121 | + */ | |
| 122 | + if ( isset( $request['jetpack_waf_ip_list'] ) ) { | |
| 123 | + update_option( Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME, $request['jetpack_waf_ip_list'] ? '1' : '' ); | |
| 124 | + update_option( Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME, $request['jetpack_waf_ip_list'] ? '1' : '' ); | |
| 112 | 125 | } |
| 113 | 126 | |
| 114 | 127 | // IP Block List |
| 115 | 128 | if ( isset( $request[ Waf_Rules_Manager::IP_BLOCK_LIST_OPTION_NAME ] ) ) { |
| @@ -114,32 +127,38 @@ | ||
| 114 | 127 | // IP Block List |
| 115 | 128 | if ( isset( $request[ Waf_Rules_Manager::IP_BLOCK_LIST_OPTION_NAME ] ) ) { |
| 116 | 129 | update_option( Waf_Rules_Manager::IP_BLOCK_LIST_OPTION_NAME, $request[ Waf_Rules_Manager::IP_BLOCK_LIST_OPTION_NAME ] ); |
| 117 | 130 | } |
| 131 | + if ( isset( $request[ Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME ] ) ) { | |
| 132 | + update_option( Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME, $request[ Waf_Rules_Manager::IP_BLOCK_LIST_ENABLED_OPTION_NAME ] ? '1' : '' ); | |
| 133 | + } | |
| 118 | 134 | |
| 119 | 135 | // IP Allow List |
| 120 | 136 | if ( isset( $request[ Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME ] ) ) { |
| 121 | 137 | update_option( Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME, $request[ Waf_Rules_Manager::IP_ALLOW_LIST_OPTION_NAME ] ); |
| 122 | 138 | } |
| 139 | + if ( isset( $request[ Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME ] ) ) { | |
| 140 | + update_option( Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME, $request[ Waf_Rules_Manager::IP_ALLOW_LIST_ENABLED_OPTION_NAME ] ? '1' : '' ); | |
| 141 | + } | |
| 123 | 142 | |
| 124 | 143 | // Share Data |
| 125 | 144 | if ( isset( $request[ Waf_Runner::SHARE_DATA_OPTION_NAME ] ) ) { |
| 126 | 145 | // If a user disabled the regular share we should disable the debug share data option. |
| 127 | - if ( false === $request[ Waf_Runner::SHARE_DATA_OPTION_NAME ] ) { | |
| 128 | - update_option( Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME, false ); | |
| 146 | + if ( ! $request[ Waf_Runner::SHARE_DATA_OPTION_NAME ] ) { | |
| 147 | + update_option( Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME, '' ); | |
| 129 | 148 | } |
| 130 | 149 | |
| 131 | - update_option( Waf_Runner::SHARE_DATA_OPTION_NAME, (bool) $request[ Waf_Runner::SHARE_DATA_OPTION_NAME ] ); | |
| 150 | + update_option( Waf_Runner::SHARE_DATA_OPTION_NAME, $request[ Waf_Runner::SHARE_DATA_OPTION_NAME ] ? '1' : '' ); | |
| 132 | 151 | } |
| 133 | 152 | |
| 134 | 153 | // Share Debug Data |
| 135 | 154 | if ( isset( $request[ Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME ] ) ) { |
| 136 | 155 | // If a user toggles the debug share we should enable the regular share data option. |
| 137 | - if ( true === $request[ Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME ] ) { | |
| 138 | - update_option( Waf_Runner::SHARE_DATA_OPTION_NAME, true ); | |
| 156 | + if ( $request[ Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME ] ) { | |
| 157 | + update_option( Waf_Runner::SHARE_DATA_OPTION_NAME, 1 ); | |
| 139 | 158 | } |
| 140 | 159 | |
| 141 | - update_option( Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME, (bool) $request[ Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME ] ); | |
| 160 | + update_option( Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME, $request[ Waf_Runner::SHARE_DEBUG_DATA_OPTION_NAME ] ? '1' : '' ); | |
| 142 | 161 | } |
| 143 | 162 | |
| 144 | 163 | // Brute Force Protection |
| 145 | 164 | if ( isset( $request['brute_force_protection'] ) ) { |