PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.1.0
Defender Security – Malware Scanner, Login Security & Firewall v3.1.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
defender-security / src / model / notification / firewall-report.php

firewall-report.php in Defender Security – Malware Scanner, Login Security & Firewall 3.1.0, at src/model/notification/firewall-report.php

158 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_Defender\Model\Notification;
4
5 use WP_Defender\Controller\Firewall;
6 use WP_Defender\Model\Lockout_Log;
7
8 /**
9 * Class Firewall_Report.
10 * @package WP_Defender\Model\Notification
11 */
12 class Firewall_Report extends \WP_Defender\Model\Notification {
13 protected $table = 'wd_lockout_report';
14
15 public function before_load() {
16 $default = array(
17 'slug' => 'firewall-report',
18 'title' => __( 'Firewall - Reporting', 'wpdef' ),
19 'status' => self::STATUS_DISABLED,
20 'description' => __( 'Configure Defender to automatically email you a lockout report for this website.', 'wpdef' ),
21 // @since 3.0.0 Fix 'Guest'-line.
22 'in_house_recipients' => is_user_logged_in() ? array( $this->get_default_user() ) : array(),
23 'out_house_recipients' => array(),
24 'type' => 'report',
25 'dry_run' => false,
26 'frequency' => 'weekly',
27 'day' => 'sunday',
28 'day_n' => '1',
29 'time' => '4:00',
30 'configs' => array(),
31 );
32 $this->import( $default );
33 }
34
35 public function send() {
36 foreach ( $this->in_house_recipients as $recipient ) {
37 if ( self::USER_SUBSCRIBED !== $recipient['status'] ) {
38 continue;
39 }
40 $this->send_to_user( $recipient['name'], $recipient['email'] );
41 }
42 foreach ( $this->out_house_recipients as $recipient ) {
43 if ( self::USER_SUBSCRIBED !== $recipient['status'] ) {
44 continue;
45 }
46 $this->send_to_user( $recipient['name'], $recipient['email'] );
47 }
48 $this->last_sent = $this->est_timestamp;
49 $this->est_timestamp = $this->get_next_run()->getTimestamp();
50 $this->save();
51 }
52
53 private function send_to_user( $name, $email ) {
54 $site_url = network_site_url();
55 /* translators: */
56 $subject = sprintf( __( 'Defender Lockouts Report for %s', 'wpdef' ), $site_url );
57 if ( 'daily' === $this->frequency ) {
58 $time_unit = __( 'in the past 24 hours', 'wpdef' );
59 $interval = '-24 hours';
60 } elseif ( 'weekly' === $this->frequency ) {
61 $time_unit = __( 'in the past week', 'wpdef' );
62 $interval = '-7 days';
63 } else {
64 $time_unit = __( 'in the month', 'wpdef' );
65 $interval = '-30 days';
66 }
67 // Number of lockouts.
68 $count_lockouts = array(
69 '404' => Lockout_Log::count(
70 strtotime( $interval ),
71 time(),
72 array(
73 Lockout_Log::LOCKOUT_404,
74 )
75 ),
76 'login' => Lockout_Log::count(
77 strtotime( $interval ),
78 time(),
79 array(
80 Lockout_Log::AUTH_LOCK,
81 )
82 ),
83 // Todo: add UA-lockouts when UA-checkbox appears in the Firewall email configure.
84 // Todo: change COUNT-logic for all lockouts when UA-checkbox will be ready, e.g. Lockout_Log::count_lockout_in_24_hours().
85 );
86
87 $firewall = wd_di()->get( Firewall::class );
88 $logs_url = network_admin_url( 'admin.php?page=wdf-ip-lockout&view=logs' );
89 // Need for activated Mask Login feature.
90 $logs_url = apply_filters( 'report_email_logs_link', $logs_url, $email );
91 $content_body = $firewall->render_partial(
92 'email/firewall-report',
93 array(
94 'name' => $name,
95 'count_total' => (int) $count_lockouts['404'] + (int) $count_lockouts['login'],
96 'time_unit' => $time_unit,
97 'logs_url' => $logs_url,
98 'site_url' => $site_url,
99 'count_lockouts' => $count_lockouts,
100 ),
101 false
102 );
103 $content = $firewall->render_partial(
104 'email/index',
105 array(
106 'title' => __( 'Firewall', 'wpdef' ),
107 'content_body' => $content_body,
108 ),
109 false
110 );
111
112 $headers = defender_noreply_html_header(
113 defender_noreply_email( 'wd_lockout_noreply_email' )
114 );
115
116 $ret = wp_mail( $email, $subject, $content, $headers );
117 if ( $ret ) {
118 $this->save_log( $email );
119 }
120 }
121
122 /**
123 * Define labels for settings key.
124 *
125 * @param string|null $key
126 *
127 * @return string|array|null
128 */
129 public function labels( $key = null ) {
130 $labels = array(
131 'report' => __( 'Firewall - Reporting', 'wpdef' ),
132 'day' => __( 'Day of', 'wpdef' ),
133 'day_n' => __( 'Day of', 'wpdef' ),
134 'report_time' => __( 'Time of day', 'wpdef' ),
135 'report_frequency' => __( 'Frequency', 'wpdef' ),
136 'report_subscribers' => __( 'Recipients', 'wpdef' ),
137 );
138
139 if ( ! is_null( $key ) ) {
140 return $labels[ $key ] ?? null;
141 }
142
143 return $labels;
144 }
145
146 /**
147 * Additional converting rules.
148 *
149 * @param array $configs
150 *
151 * @return array
152 * @since 3.1.0
153 */
154 public function type_casting( $configs ) {
155 return $configs;
156 }
157 }
158