| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Handles the scheduling and sending of firewall-related reports. | |
| 3 | + * Firewall report notification stub for free version. | |
| 4 | 4 | * |
| 5 | 5 | * @package WP_Defender\Model\Notification |
| 6 | 6 | */ |
| 7 | 7 | |
| @@ -6,17 +6,12 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace WP_Defender\Model\Notification; |
| 9 | 9 | |
| 10 | -use WP_Defender\Component\Mail; | |
| 11 | -use WP_Defender\Model\Lockout_Log; | |
| 12 | -use WP_Defender\Controller\Firewall; | |
| 13 | -use WP_Defender\Component\Notification; | |
| 14 | - | |
| 15 | 10 | /** |
| 16 | - * Handles the scheduling and sending of firewall-related reports. | |
| 11 | + * Firewall – Reporting. | |
| 17 | 12 | */ |
| 18 | -class Firewall_Report extends \WP_Defender\Model\Notification { | |
| 13 | +class Firewall_Report extends Free_Report { | |
| 19 | 14 | |
| 20 | 15 | /** |
| 21 | 16 | * Table name. |
| 22 | 17 | * |
| @@ -23,154 +18,32 @@ | ||
| 23 | 18 | * @var string |
| 24 | 19 | */ |
| 25 | 20 | protected $table = 'wd_lockout_report'; |
| 26 | 21 | |
| 27 | - public const SLUG = 'firewall-report'; | |
| 28 | - | |
| 29 | 22 | /** |
| 30 | - * Constructor method. | |
| 31 | - * Sets default values for the firewall report. | |
| 32 | - */ | |
| 33 | - protected function before_load(): void { | |
| 34 | - $default = array( | |
| 35 | - 'slug' => self::SLUG, | |
| 36 | - 'title' => esc_html__( 'Firewall - Reporting', 'defender-security' ), | |
| 37 | - 'status' => self::STATUS_DISABLED, | |
| 38 | - 'description' => esc_html__( | |
| 39 | - 'Configure Defender to automatically email you a lockout report for this website.', | |
| 40 | - 'defender-security' | |
| 41 | - ), | |
| 42 | - // @since 3.0.0 Fix 'Guest'-line. | |
| 43 | - 'in_house_recipients' => is_user_logged_in() ? array( $this->get_default_user() ) : array(), | |
| 44 | - 'out_house_recipients' => array(), | |
| 45 | - 'type' => 'report', | |
| 46 | - 'dry_run' => false, | |
| 47 | - 'frequency' => 'weekly', | |
| 48 | - 'day' => 'sunday', | |
| 49 | - 'day_n' => '1', | |
| 50 | - 'time' => '4:00', | |
| 51 | - 'configs' => array(), | |
| 52 | - ); | |
| 53 | - $this->import( $default ); | |
| 54 | - } | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * Sends the firewall report email. | |
| 58 | - * Constructs and sends the firewall report email to the recipients. | |
| 23 | + * Slug identifier for the firewall report. | |
| 59 | 24 | * |
| 60 | - * @return void | |
| 25 | + * @var string | |
| 61 | 26 | */ |
| 62 | - public function send() { | |
| 63 | - $service = wd_di()->get( Notification::class ); | |
| 64 | - foreach ( $this->in_house_recipients as $recipient ) { | |
| 65 | - if ( self::USER_SUBSCRIBED !== $recipient['status'] ) { | |
| 66 | - continue; | |
| 67 | - } | |
| 68 | - $this->send_to_user( $recipient['name'], $recipient['email'], $service ); | |
| 69 | - } | |
| 70 | - foreach ( $this->out_house_recipients as $recipient ) { | |
| 71 | - if ( self::USER_SUBSCRIBED !== $recipient['status'] ) { | |
| 72 | - continue; | |
| 73 | - } | |
| 74 | - $this->send_to_user( $recipient['name'], $recipient['email'], $service ); | |
| 75 | - } | |
| 76 | - $this->last_sent = $this->est_timestamp; | |
| 77 | - $this->est_timestamp = $this->get_next_run()->getTimestamp(); | |
| 78 | - $this->save(); | |
| 79 | - } | |
| 27 | + public const SLUG = 'firewall-report'; | |
| 80 | 28 | |
| 81 | 29 | /** |
| 82 | - * Sends the firewall report email to a specific user. | |
| 83 | - * Constructs and sends the firewall report email to the specified recipient. | |
| 84 | - * | |
| 85 | - * @param string $name The recipient's name. | |
| 86 | - * @param string $email The recipient's email address. | |
| 87 | - * @param object $service The notification service object. | |
| 88 | - * | |
| 89 | - * @return void | |
| 30 | + * Sets default values. | |
| 90 | 31 | */ |
| 91 | - private function send_to_user( $name, $email, $service ) { | |
| 92 | - $site_url = network_site_url(); | |
| 93 | - $mail_object = wd_di()->get( Mail::class ); | |
| 94 | - $plugin_label = $mail_object->get_sender_name( self::SLUG ); | |
| 95 | - $subject = sprintf( | |
| 96 | - /* translators: 1. Plugin label. 2. Site URL. */ | |
| 97 | - esc_html__( '%1$s Lockouts Report for %2$s', 'defender-security' ), | |
| 98 | - $plugin_label, | |
| 99 | - $site_url | |
| 100 | - ); | |
| 101 | - // Frequency. | |
| 102 | - if ( 'daily' === $this->frequency ) { | |
| 103 | - $time_unit = esc_html__( 'in the past 24 hours', 'defender-security' ); | |
| 104 | - $interval = '-24 hours'; | |
| 105 | - } elseif ( 'weekly' === $this->frequency ) { | |
| 106 | - $time_unit = esc_html__( 'in the past week', 'defender-security' ); | |
| 107 | - $interval = '-7 days'; | |
| 108 | - } else { | |
| 109 | - $time_unit = esc_html__( 'in the month', 'defender-security' ); | |
| 110 | - $interval = '-30 days'; | |
| 111 | - } | |
| 112 | - // Number of lockouts. | |
| 113 | - $count_lockouts = array( | |
| 114 | - '404' => Lockout_Log::count( | |
| 115 | - strtotime( $interval ), | |
| 116 | - time(), | |
| 32 | + protected function before_load(): void { | |
| 33 | + $this->import( | |
| 34 | + array_merge( | |
| 35 | + $this->base_defaults(), | |
| 117 | 36 | array( |
| 118 | - Lockout_Log::LOCKOUT_404, | |
| 37 | + 'slug' => self::SLUG, | |
| 38 | + 'title' => esc_html__( 'Firewall - Reporting', 'defender-security' ), | |
| 39 | + 'description' => esc_html__( | |
| 40 | + 'Configure Defender to automatically email you a lockout report for this website.', | |
| 41 | + 'defender-security' | |
| 42 | + ), | |
| 119 | 43 | ) |
| 120 | - ), | |
| 121 | - 'login' => Lockout_Log::count( | |
| 122 | - strtotime( $interval ), | |
| 123 | - time(), | |
| 124 | - array( | |
| 125 | - Lockout_Log::AUTH_LOCK, | |
| 126 | - ) | |
| 127 | - ), | |
| 128 | - 'ua' => Lockout_Log::count( | |
| 129 | - strtotime( $interval ), | |
| 130 | - time(), | |
| 131 | - array( | |
| 132 | - Lockout_Log::LOCKOUT_UA, | |
| 133 | - ) | |
| 134 | - ), | |
| 44 | + ) | |
| 135 | 45 | ); |
| 136 | - | |
| 137 | - $firewall = wd_di()->get( Firewall::class ); | |
| 138 | - $logs_url = network_admin_url( 'admin.php?page=wdf-ip-lockout&view=logs' ); | |
| 139 | - // Need for activated Mask Login feature. | |
| 140 | - $logs_url = apply_filters( 'report_email_logs_link', $logs_url, $email ); | |
| 141 | - $content_body = $firewall->render_partial( | |
| 142 | - 'email/firewall-report', | |
| 143 | - array( | |
| 144 | - 'name' => $name, | |
| 145 | - 'count_total' => (int) $count_lockouts['404'] + (int) $count_lockouts['login'] + (int) $count_lockouts['ua'], | |
| 146 | - 'time_unit' => $time_unit, | |
| 147 | - 'logs_url' => $logs_url, | |
| 148 | - 'site_url' => $site_url, | |
| 149 | - 'count_lockouts' => $count_lockouts, | |
| 150 | - ), | |
| 151 | - false | |
| 152 | - ); | |
| 153 | - $unsubscribe_link = $service->create_unsubscribe_url( $this->slug, $email ); | |
| 154 | - $content = $firewall->render_partial( | |
| 155 | - 'email/index', | |
| 156 | - array( | |
| 157 | - 'title' => esc_html__( 'Firewall', 'defender-security' ), | |
| 158 | - 'content_body' => $content_body, | |
| 159 | - 'unsubscribe_link' => $unsubscribe_link, | |
| 160 | - ), | |
| 161 | - false | |
| 162 | - ); | |
| 163 | - | |
| 164 | - $headers = $mail_object->get_headers( | |
| 165 | - defender_noreply_email( 'wd_lockout_noreply_email' ), | |
| 166 | - self::SLUG | |
| 167 | - ); | |
| 168 | - | |
| 169 | - $ret = wp_mail( $email, $subject, $content, $headers ); | |
| 170 | - if ( $ret ) { | |
| 171 | - $this->save_log( $email ); | |
| 172 | - } | |
| 173 | 46 | } |
| 174 | 47 | |
| 175 | 48 | /** |
| 176 | 49 | * Define settings labels. |
| @@ -187,16 +60,5 @@ | ||
| 187 | 60 | 'report_subscribers' => esc_html__( 'Recipients', 'defender-security' ), |
| 188 | 61 | ); |
| 189 | 62 | } |
| 190 | 63 | |
| 191 | - /** | |
| 192 | - * Additional converting rules. | |
| 193 | - * | |
| 194 | - * @param array $configs The configuration data. | |
| 195 | - * | |
| 196 | - * @return array The type-casted configuration data. | |
| 197 | - * @since 3.1.0 | |
| 198 | - */ | |
| 199 | - public function type_casting( $configs ): array { | |
| 200 | - return is_array( $configs ) ? $configs : array(); | |
| 201 | - } | |
| 202 | 64 | } |