PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/controller/class-blacklist.php +78 -27 5.9.0 → 6.3.0 View file →
@@ -18,9 +18,9 @@
18 18 use WP_Defender\Behavior\WPMUDEV;
19 19 use WP_Defender\Model\Lockout_Ip;
20 20 use WP_Defender\Traits\Continent;
21 21 use WP_Defender\Component\Blacklist_Lockout;
22 -use MaxMind\Db\Reader\InvalidDatabaseException;
22 +use WP_DEFENDER_VENDOR\MaxMind\Db\Reader\InvalidDatabaseException;
23 23 use WP_Defender\Component\Network_Cron_Manager;
24 24 use WP_Defender\Integrations\MaxMind_Geolocation;
25 25 use WP_Defender\Component\Config\Config_Hub_Helper;
26 26 use WP_Defender\Model\Setting\Blacklist_Lockout as Model_Blacklist_Lockout;
@@ -110,9 +110,8 @@
110 110 public function enqueue_assets() {
111 111 if ( ! $this->is_page_active() ) {
112 112 return;
113 113 }
114 - wp_localize_script( 'def-iplockout', 'blacklist', $this->data_frontend() );
115 114 }
116 115
117 116 /**
118 117 * Provides data for the frontend.
@@ -147,9 +146,9 @@
147 146 $current_country[] = $this->get_current_country( $ip );
148 147 }
149 148
150 149 $misc = array(
151 - 'user_ip' => implode( ',', $user_ip ),
150 + 'user_ip' => implode( ', ', $user_ip ),
152 151 'is_geodb_downloaded' => $exist_geodb,
153 152 'blacklist_countries' => $blacklist_countries,
154 153 'whitelist_countries' => $whitelist_countries,
155 154 'current_country' => $current_country,
@@ -229,8 +228,10 @@
229 228 'sanitize' => 'sanitize_textarea_field',
230 229 ),
231 230 )
232 231 );
232 + $data = $this->remove_country_list_conflicts( $data );
233 +
233 234 $this->model->import( $data );
234 235 if ( $this->model->validate() ) {
235 236 $this->model->save();
236 237 Config_Hub_Helper::set_clear_active_flag();
@@ -256,10 +257,8 @@
256 257 $this->model->save();
257 258 Config_Hub_Helper::set_clear_active_flag();
258 259 }
259 260
260 - $this->model->import( $data );
261 -
262 261 return new Response(
263 262 false,
264 263 array_merge(
265 264 array( 'message' => $this->model->get_formatted_errors() ),
@@ -268,8 +267,44 @@
268 267 );
269 268 }
270 269
271 270 /**
271 + * Prevent the same country from being saved in both blocked and allowed lists.
272 + *
273 + * @param array $data Settings data.
274 + *
275 + * @return array
276 + */
277 + private function remove_country_list_conflicts( array $data ): array {
278 + if ( ! isset( $data['country_blacklist'], $data['country_whitelist'] ) ) {
279 + return $data;
280 + }
281 +
282 + $country_blacklist = array_values( array_unique( $data['country_blacklist'] ) );
283 + $country_whitelist = array_values( array_unique( $data['country_whitelist'] ) );
284 + $added_blacklist = array_diff( $country_blacklist, $this->model->country_blacklist );
285 + $added_whitelist = array_diff( $country_whitelist, $this->model->country_whitelist );
286 +
287 + if ( array() !== $added_blacklist ) {
288 + $country_whitelist = array_values( array_diff( $country_whitelist, $added_blacklist ) );
289 + }
290 +
291 + if ( array() !== $added_whitelist ) {
292 + $country_blacklist = array_values( array_diff( $country_blacklist, $added_whitelist ) );
293 + }
294 +
295 + $remaining_conflicts = array_intersect( $country_blacklist, $country_whitelist );
296 + if ( array() !== $remaining_conflicts ) {
297 + $country_whitelist = array_values( array_diff( $country_whitelist, $remaining_conflicts ) );
298 + }
299 +
300 + $data['country_blacklist'] = $country_blacklist;
301 + $data['country_whitelist'] = $country_whitelist;
302 +
303 + return $data;
304 + }
305 +
306 + /**
272 307 * Download the GEODB IP from Maxmind.
273 308 *
274 309 * @param Request $request The request object containing the license key.
275 310 *
@@ -325,19 +360,23 @@
325 360 )
326 361 );
327 362 } else {
328 363 $this->log( 'Error from MaxMind: ' . $tmp->get_error_message(), Firewall::FIREWALL_LOG );
329 - $string = sprintf(
330 - /* translators: 1. License key with link. */
331 - esc_html__(
332 - 'You have entered an invalid %1$s. If you just created the key, please wait 5 minutes before trying to activate it.',
333 - 'defender-security'
334 - ),
335 - '<a target="_blank" href="https://www.maxmind.com/en/accounts/current/license-key">' . esc_html__( 'license key', 'defender-security' ) . '</a>'
364 + $string = esc_html__(
365 + 'The license key you entered isn\'t valid. If you recently created it, allow up to 5 minutes for activation before trying again.',
366 + 'defender-security'
336 367 );
337 368
338 369 if ( ( new WPMUDEV() )->show_support_links() ) {
339 - $string .= defender_support_ticket_text();
370 + $string = sprintf(
371 + /* translators: 1. Opening support link, 2. Closing support link. */
372 + esc_html__(
373 + 'The license key you entered isn\'t valid. If you recently created it, allow up to 5 minutes for activation before trying again. Need help? %1$sContact support%2$s.',
374 + 'defender-security'
375 + ),
376 + '<a target="_blank" href="' . WP_DEFENDER_SUPPORT_LINK . '">',
377 + '</a>'
378 + );
340 379 }
341 380
342 381 return new Response( false, array( 'invalid_text' => $string ) );
343 382 }
@@ -573,9 +612,9 @@
573 612 'ip_blacklist' => $data['ip_blacklist'],
574 613 'ip_whitelist' => $data['ip_whitelist'],
575 614 'ip_lockout_message' => $data['ip_lockout_message'],
576 615 );
577 - if ( isset( $data['geoIP_db'] ) && file_exists( $data['geoIP_db'] ) ) {
616 + if ( isset( $data['geoIP_db'] ) && is_string( $data['geoIP_db'] ) && file_exists( $data['geoIP_db'] ) ) {
578 617 $adapted_data['geodb_path'] = $data['geoIP_db'];
579 618 if ( isset( $data['country_blacklist'] ) ) {
580 619 $adapted_data['country_blacklist'] = $data['country_blacklist'];
581 620 }
@@ -642,20 +681,29 @@
642 681 'type' => 'int',
643 682 ),
644 683 )
645 684 );
646 - $attached_id = $data['id'];
647 - if ( ! is_object( get_post( $attached_id ) ) ) {
648 - return new Response(
649 - false,
650 - array(
651 - 'message' => esc_html__( 'Your file is invalid!', 'defender-security' ),
652 - )
653 - );
685 + $file = '';
686 + $attached_id = $data['id'] ?? 0;
687 + if ( 0 < $attached_id ) {
688 + if ( ! is_object( get_post( $attached_id ) ) ) {
689 + return new Response(
690 + false,
691 + array(
692 + 'message' => esc_html__( 'Your file is invalid!', 'defender-security' ),
693 + )
694 + );
695 + }
696 +
697 + $file = get_attached_file( $attached_id );
698 + } else {
699 + $file_data = defender_get_data_from_request( 'file', 'f' );
700 + if ( is_array( $file_data ) && isset( $file_data['tmp_name'] ) && is_uploaded_file( $file_data['tmp_name'] ) ) {
701 + $file = $file_data['tmp_name'];
702 + }
654 703 }
655 704
656 - $file = get_attached_file( $attached_id );
657 - if ( ! is_file( $file ) ) {
705 + if ( ! is_string( $file ) || '' === $file || ! is_file( $file ) ) {
658 706 return new Response(
659 707 false,
660 708 array(
661 709 'message' => esc_html__( 'Your file is invalid!', 'defender-security' ),
@@ -679,11 +727,14 @@
679 727 }
680 728
681 729 return new Response(
682 730 true,
683 - array(
684 - 'message' => esc_html__( 'Your allowlist/blocklist has been successfully imported.', 'defender-security' ),
685 - 'interval' => 1,
731 + array_merge(
732 + array(
733 + 'message' => esc_html__( 'Your allowlist/blocklist has been successfully imported.', 'defender-security' ),
734 + 'auto_close' => true,
735 + ),
736 + $this->data_frontend()
686 737 )
687 738 );
688 739 }
689 740