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-ua-lockout.php +17 -21 6.0.1 → 6.3.0 View file →
@@ -7,8 +7,9 @@
7 7
8 8 namespace WP_Defender\Controller;
9 9
10 10 use Exception;
11 +use Generator;
11 12 use WP_Defender\Event;
12 13 use Calotes\Component\Request;
13 14 use Calotes\Component\Response;
14 15 use WP_Defender\Traits\Setting;
@@ -13,8 +14,9 @@
13 14 use Calotes\Component\Response;
14 15 use WP_Defender\Traits\Setting;
15 16 use WP_Defender\Model\Lockout_Log;
16 17 use WP_Defender\Model\Setting\User_Agent_Lockout;
18 +use WP_Defender\Component\Export\Csv;
17 19 use WP_Defender\Component\Config\Config_Hub_Helper;
18 20 use WP_Defender\Component\User_Agent as User_Agent_Service;
19 21
20 22 /**
@@ -271,13 +273,9 @@
271 273 'module_name' => User_Agent_Lockout::get_module_name(),
272 274 'blocklist_presets' => User_Agent_Service::get_blocklist_presets(),
273 275 'script_presets' => User_Agent_Service::get_script_presets(),
274 276 'has_empty_disallow_line' => $has_empty_disallow,
275 - 'lockouts_last_24_hours' => Lockout_Log::count(
276 - strtotime( '-24 hours' ),
277 - time(),
278 - Lockout_Log::LOCKOUT_UA
279 - ),
277 + 'lockouts_last_24_hours' => Lockout_Log::count_ua_lockouts_in_24_hours(),
280 278 );
281 279
282 280 return array_merge(
283 281 array(
@@ -349,12 +347,23 @@
349 347 * @defender_route
350 348 * @since 2.6.0
351 349 */
352 350 public function export_ua(): void {
353 - $data = array();
351 + try {
352 + Csv::to_browser( 'ua', $this->get_export_rows() );
353 + } catch ( \RuntimeException $e ) {
354 + $this->log( $e->getMessage(), 'ua-lockout' );
355 + }
356 + }
354 357
358 + /**
359 + * Generates User Agent export rows.
360 + *
361 + * @return Generator
362 + */
363 + private function get_export_rows(): Generator {
355 364 foreach ( $this->model->get_lockout_list( 'allowlist', false ) as $ua ) {
356 - $data[] = array(
365 + yield array(
357 366 'ua' => $ua,
358 367 'type' => 'allowlist',
359 368 );
360 369 }
@@ -359,26 +368,13 @@
359 368 );
360 369 }
361 370
362 371 foreach ( $this->model->get_all_selected_blocklist_ua( false ) as $ua ) {
363 - $data[] = array(
372 + yield array(
364 373 'ua' => $ua,
365 374 'type' => 'blocklist',
366 375 );
367 376 }
368 -
369 - // WP_Filesystem class doesn’t directly provide a function for opening a stream to php://memory with the 'w' mode.
370 - $fp = fopen( 'php://memory', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
371 - foreach ( $data as $fields ) {
372 - fputcsv( $fp, $fields, ',', '"', '\\' );
373 - }
374 - $filename = 'wdf-ua-export-' . wp_date( 'ymdHis' ) . '.csv';
375 - fseek( $fp, 0 );
376 - header( 'Content-Type: text/csv' );
377 - header( 'Content-Disposition: attachment; filename="' . $filename . '";' );
378 - // Make php send the generated csv lines to the browser.
379 - fpassthru( $fp );
380 - exit();
381 377 }
382 378
383 379 /**
384 380 * Importing UAs from exporter.