PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.9
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.9
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / lib / settings_event_notifications.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-api.php 4 weeks ago class-centralised-logging.php 4 weeks ago class-coupon.php 7 months ago class-email-sodium.php 4 weeks ago class-firewall-log.php 4 weeks ago class-helpers.php 9 months ago class-import-export.php 5 months ago class-ip.php 5 months ago class-nfw-database.php 7 months ago class-plugin-upgrade.php 4 weeks ago class-security-updates.php 4 weeks ago class-session.php 4 weeks ago class_mail.php 4 weeks ago firewall.php 4 weeks ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 4 weeks ago helpers.php 4 weeks ago i18n-extra.php 4 weeks ago i18n.php 1 year ago index.html 13 years ago init_update.php 2 years ago install.php 1 year ago install_default.php 4 weeks ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 4 weeks ago scheduled_tasks.php 3 years ago settings_dashboard.php 4 weeks ago settings_dashboard_about.php 4 weeks ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 4 weeks ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 4 weeks ago settings_login_protection.php 2 months ago settings_logs.php 4 weeks ago settings_logs_firewall_log.php 4 weeks ago settings_logs_live_log.php 2 months ago settings_monitoring.php 4 weeks ago settings_monitoring_file_check.php 2 months ago settings_monitoring_file_guard.php 2 months ago settings_network.php 2 months ago settings_security_rules.php 2 months ago settings_security_rules_editor.php 4 weeks ago settings_security_rules_update.php 4 weeks ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
settings_event_notifications.php
501 lines
1 <?php
2 /*
3 +=====================================================================+
4 | _ _ _ _ _____ _ _ _ |
5 | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | |
6 | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | |
7 | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | |
8 | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| |
9 | |__/ |
10 | (c) NinTechNet Limited ~ https://nintechnet.com/ |
11 +=====================================================================+
12 */
13
14 if (! defined( 'NFW_ENGINE_VERSION' ) ) {
15 die( 'Forbidden' );
16 }
17
18 // Daily report cronjob?
19 if ( defined('NFREPORTDO') ) {
20 nf_daily_report();
21 return;
22 }
23
24 // Block immediately if user is not allowed :
25 nf_not_allowed( 'block', __LINE__ );
26
27 $nfw_options = nfw_get_option( 'nfw_options' );
28
29 echo '<div class="wrap">
30 <h1><img style="vertical-align:top;width:33px;height:33px;" src="'. plugins_url( '/ninjafirewall/images/ninjafirewall_32.png' ) .'">&nbsp;' . __('Event Notifications', 'ninjafirewall') . '</h1>';
31
32 // Saved ?
33 if ( isset( $_POST['nfw_options']) ) {
34 if ( empty($_POST['nfwnonce']) || ! wp_verify_nonce($_POST['nfwnonce'], 'events_save') ) {
35 wp_nonce_ays('events_save');
36 }
37 nf_sub_event_save();
38 echo '<div class="updated notice is-dismissible"><p>' . esc_html__('Your changes have been saved.', 'ninjafirewall') . '</p></div>';
39 $nfw_options = nfw_get_option( 'nfw_options' );
40 }
41
42 if (! isset( $nfw_options['a_0'] ) ) {
43 $nfw_options['a_0'] = 1;
44 }
45
46 nfw_contextual_help();
47 ?>
48 <form method="post" name="nfwalerts">
49 <?php wp_nonce_field('events_save', 'nfwnonce', 0); ?>
50 <h3><?php _e('WordPress admin dashboard', 'ninjafirewall') ?></h3>
51 <table class="form-table nfw-table">
52 <tr>
53 <th scope="row" class="row-med"><?php _e('Send me an alert whenever', 'ninjafirewall') ?></th>
54 <td>
55 <p><label><input type="radio" name="nfw_options[a_0]" value="1"<?php checked( $nfw_options['a_0'], 1) ?>>&nbsp;<?php _e('An administrator logs in (default)', 'ninjafirewall') ?></label></p>
56 <p><label><input type="radio" name="nfw_options[a_0]" value="2"<?php checked( $nfw_options['a_0'], 2) ?>>&nbsp;<?php _e('Someone - user, admin, editor, etc - logs in', 'ninjafirewall') ?></label></p>
57 <p><label><input type="radio" name="nfw_options[a_0]" value="0"<?php checked( $nfw_options['a_0'], 0) ?>>&nbsp;<?php _e('No, thanks (not recommended)', 'ninjafirewall') ?></label></p>
58 </td>
59 </tr>
60 </table>
61
62 <br />
63
64 <h3><?php _e('Plugins', 'ninjafirewall') ?></h3>
65 <table class="form-table nfw-table">
66 <tr>
67 <th scope="row" class="row-med"><?php _e('Send me an alert whenever someone', 'ninjafirewall') ?></th>
68 <td>
69 <p><label><input type="checkbox" name="nfw_options[a_11]" value="1"<?php checked( $nfw_options['a_11'], 1) ?>>&nbsp;<?php _e('Uploads a plugin (default)', 'ninjafirewall') ?></label></p>
70 <p><label><input type="checkbox" name="nfw_options[a_12]" value="1"<?php checked( $nfw_options['a_12'], 1) ?>>&nbsp;<?php _e('Installs a plugin (default)', 'ninjafirewall') ?></label></p>
71 <p><label><input type="checkbox" name="nfw_options[a_13]" value="1"<?php checked( $nfw_options['a_13'], 1) ?>>&nbsp;<?php _e('Activates a plugin', 'ninjafirewall') ?></label></p>
72 <p><label><input type="checkbox" name="nfw_options[a_14]" value="1"<?php checked( $nfw_options['a_14'], 1) ?>>&nbsp;<?php _e('Updates a plugin', 'ninjafirewall') ?></label></p>
73 <p><label><input type="checkbox" name="nfw_options[a_15]" value="1"<?php checked( $nfw_options['a_15'], 1) ?>>&nbsp;<?php _e('Deactivates a plugin (default)', 'ninjafirewall') ?></label></p>
74 <p><label><input type="checkbox" name="nfw_options[a_16]" value="1"<?php checked( $nfw_options['a_16'], 1) ?>>&nbsp;<?php _e('Deletes a plugin', 'ninjafirewall') ?></label></p>
75 </td>
76 </tr>
77 </table>
78
79 <br />
80
81 <h3><?php _e('Themes', 'ninjafirewall') ?></h3>
82 <table class="form-table nfw-table">
83 <tr>
84 <th scope="row" class="row-med"><?php _e('Send me an alert whenever someone', 'ninjafirewall') ?></th>
85 <td>
86 <p><label><input type="checkbox" name="nfw_options[a_21]" value="1"<?php checked( $nfw_options['a_21'], 1) ?>>&nbsp;<?php _e('Uploads a theme (default)', 'ninjafirewall') ?></label></p>
87 <p><label><input type="checkbox" name="nfw_options[a_22]" value="1"<?php checked( $nfw_options['a_22'], 1) ?>>&nbsp;<?php _e('Installs a theme (default)', 'ninjafirewall') ?></label></p>
88 <p><label><input type="checkbox" name="nfw_options[a_23]" value="1"<?php checked( $nfw_options['a_23'], 1) ?>>&nbsp;<?php _e('Activates a theme', 'ninjafirewall') ?></label></p>
89 <p><label><input type="checkbox" name="nfw_options[a_24]" value="1"<?php checked( $nfw_options['a_24'], 1) ?>>&nbsp;<?php _e('Deletes a theme', 'ninjafirewall') ?></label></p>
90 <p><label><input type="checkbox" name="nfw_options[a_25]" value="1"<?php checked( $nfw_options['a_25'], 1) ?>>&nbsp;<?php _e('Updates a theme', 'ninjafirewall') ?></label></p>
91 </td>
92 </tr>
93 </table>
94
95 <br />
96
97 <h3><?php _e('Core', 'ninjafirewall') ?></h3>
98 <table class="form-table nfw-table">
99 <tr>
100 <th scope="row" class="row-med"><?php _e('Send me an alert whenever someone', 'ninjafirewall') ?></th>
101 <td>
102 <p><label><input type="checkbox" name="nfw_options[a_31]" value="1"<?php checked( $nfw_options['a_31'], 1) ?>>&nbsp;<?php _e('Updates WordPress (default)', 'ninjafirewall') ?></label></p>
103 </td>
104 </tr>
105 </table>
106
107 <br />
108
109 <?php
110 if (! isset( $nfw_options['secupdates'] ) ) {
111 $nfw_options['secupdates'] = 1;
112 }
113 ?>
114 <h3><?php _e('Security updates', 'ninjafirewall') ?></h3>
115 <table class="form-table nfw-table">
116 <tr>
117 <th scope="row" class="row-med"><?php _e('Send me an alert whenever', 'ninjafirewall') ?> <span class="ninjafirewall-tip" data-tip="<?php esc_attr_e('In the Premium version of NinjaFirewall, security updates are checked every hour, as opposed to three times a day in this free version.', 'ninjafirewall' ) ?>"></span></th>
118 <td>
119 <p><label><input type="checkbox" name="nfw_options[secupdates]" value="1"<?php checked( $nfw_options['secupdates'], 1) ?>>&nbsp;<?php _e('An important security update is available for a plugin, theme or WordPress (default)', 'ninjafirewall') ?></label></p>
120 <p><span class="description"><a href="https://blog.nintechnet.com/how-to-get-informed-about-the-latest-security-updates-in-your-wordpress-plugins-and-themes/" target="_blank"><?php esc_html_e('Consult our blog for more info.', 'ninjafirewall') ?></a>
121 </td>
122 </tr>
123 </table>
124
125 <br />
126
127 <?php
128 if (! isset( $nfw_options['a_51']) ) {
129 $nfw_options['a_51'] = 1;
130 }
131 if (! isset( $nfw_options['a_52']) ) {
132 $nfw_options['a_52'] = 1;
133 }
134 ?>
135 <h3><?php _e('Administrator account', 'ninjafirewall') ?></h3>
136 <table class="form-table nfw-table">
137 <tr>
138 <th scope="row" class="row-med"><?php _e('Send me an alert whenever', 'ninjafirewall') ?></th>
139 <td>
140 <p><label><input type="checkbox" name="nfw_options[a_51]" value="1"<?php checked( $nfw_options['a_51'], 1) ?>>&nbsp;<?php _e('An administrator account is created, modified or deleted in the database (default)', 'ninjafirewall') ?></label></p>
141 </td>
142 </tr>
143 </table>
144
145 <br />
146
147 <h3><?php _e('Daily report', 'ninjafirewall') ?></h3>
148 <table class="form-table nfw-table">
149 <tr>
150 <th scope="row" class="row-med"><?php _e('Send me a daily activity report', 'ninjafirewall') ?></th>
151 <td>
152 <?php nfw_toggle_switch( 'info', 'nfw_options[a_52]', __('Yes', 'ninjafirewall'), __('No', 'ninjafirewall'), 'small', $nfw_options['a_52'] ) ?>
153 </td>
154 </tr>
155 </table>
156
157 <br />
158
159 <h3><?php _e('Log', 'ninjafirewall') ?></h3>
160 <table class="form-table nfw-table">
161 <tr>
162 <th scope="row" class="row-med"><?php _e('Write all events to the firewall log', 'ninjafirewall') ?></th>
163 <td>
164 <?php nfw_toggle_switch( 'info', 'nfw_options[a_41]', __('Yes', 'ninjafirewall'), __('No', 'ninjafirewall'), 'small', $nfw_options['a_41'] ) ?>
165 </td>
166 </tr>
167 </table>
168
169 <br />
170
171 <?php
172 if (! isset( $nfw_options['a_61']) ) {
173 $nfw_options['a_61'] = 1;
174 }
175 ?>
176 <h3><?php _e('PHP backtrace', 'ninjafirewall') ?></h3>
177 <table class="form-table nfw-table">
178 <tr>
179 <th scope="row" class="row-med"><?php _e('Attach a PHP backtrace to important notifications', 'ninjafirewall') ?></th>
180 <td>
181 <select name="nfw_options[a_61]">
182 <option value="off"<?php selected( $nfw_options['a_61'], -1) ?>><?php _e('Disable backtrace', 'ninjafirewall') ?></option>
183 <option value="0"<?php selected( $nfw_options['a_61'], 0) ?>><?php _e('Low verbosity', 'ninjafirewall') ?></option>
184 <option value="1"<?php selected( $nfw_options['a_61'], 1) ?>><?php _e('Medium verbosity (default)', 'ninjafirewall') ?></option>
185 <option value="2"<?php selected( $nfw_options['a_61'], 2) ?>><?php _e('High verbosity', 'ninjafirewall') ?></option>
186 </select>
187 <p><span class="description"><a href="https://blog.nintechnet.com/ninjafirewall-wp-edition-adds-php-backtrace-to-email-notifications/" target="_blank"><?php esc_html_e('Consult our blog for more info.', 'ninjafirewall') ?></a>
188 </td>
189 </tr>
190 </table>
191
192 <br />
193
194 <?php
195 if (! is_multisite() ) {
196 ?>
197 <h3><?php _e('Contact email', 'ninjafirewall') ?></h3>
198 <table class="form-table nfw-table">
199 <tr>
200 <th scope="row" class="row-med"><?php _e('Alerts should be sent to', 'ninjafirewall') ?></th>
201 <td>
202 <input class="regular-text" type="text" name="nfw_options[alert_email]" size="45" maxlength="250" value="<?php
203 if ( empty( $nfw_options['alert_email'])) {
204 echo htmlspecialchars( get_option('admin_email') );
205 } else {
206 echo htmlspecialchars( $nfw_options['alert_email'] );
207 }
208 ?>">
209 <br /><span class="description"><?php _e('Multiple recipients must be comma-separated (e.g., <code>joe@example.org,alice@example.org</code>).', 'ninjafirewall') ?></span>
210 <input type="hidden" name="nfw_options[alert_sa_only]" value="2">
211 </td>
212 </tr>
213 </table>
214
215 <?php
216 } else {
217 // Select which admin(s) will recevied alerts in multi-site mode :
218 if (! isset( $nfw_options['alert_sa_only'] ) ) {
219 $nfw_options['alert_sa_only'] = 1;
220 }
221 if ($nfw_options['alert_sa_only'] == 3) {
222 $tmp_email = $nfw_options['alert_email'];
223 } else {
224 $tmp_email = '';
225 }
226 ?>
227 <h3><?php _e('Contact email', 'ninjafirewall') ?></h3>
228 <table class="form-table nfw-table">
229 <tr>
230 <th scope="row" class="row-med"><?php _e('Alerts should be sent to', 'ninjafirewall') ?></th>
231 <td>
232 <p><label><input type="radio" name="nfw_options[alert_sa_only]" value="1"<?php checked( $nfw_options['alert_sa_only'], 1 ) ?> onclick="ac_radio_toogle(0,'alert_multirec');" />&nbsp;<?php _e('Only to me, the Super Admin', 'ninjafirewall') ?>, <?php echo '<code>'. htmlspecialchars(get_option('admin_email')) . '</code>'; ?> (<?php _e('default', 'ninjafirewall') ?>)</label></p>
233 <p><label><input type="radio" name="nfw_options[alert_sa_only]" value="2"<?php checked( $nfw_options['alert_sa_only'], 2) ?> onclick="ac_radio_toogle(0,'alert_multirec');" />&nbsp;<?php _e('To the administrator of the site where originated the alert', 'ninjafirewall') ?></label></p>
234 <p><label><input type="radio" name="nfw_options[alert_sa_only]" value="3"<?php checked( $nfw_options['alert_sa_only'], 3) ?> onclick="ac_radio_toogle(1,'alert_multirec');" />&nbsp;<?php _e('Other(s):', 'ninjafirewall') ?> </label><input class="regular-text" type="text" name="nfw_options[alert_multirec]" size="45" maxlength="250" value="<?php echo esc_attr( $tmp_email ); ?>" <?php disabled($tmp_email, '') ?>></p>
235 <span class="description"><?php _e('Multiple recipients must be comma-separated (e.g., <code>joe@example.org,alice@example.org</code>).', 'ninjafirewall') ?></span>
236 <input type="hidden" name="nfw_options[alert_email]" value="<?php echo htmlspecialchars(get_option('admin_email')); ?>">
237 </td>
238 </tr>
239 </table>
240 <?php
241 }
242 ?>
243
244 <br />
245 <br />
246 <input class="button-primary" type="submit" name="Save" value="<?php _e('Save Event Notifications', 'ninjafirewall') ?>" />
247
248 </form>
249
250 </div>
251 <?php
252
253 // ---------------------------------------------------------------------
254
255 function nf_sub_event_save() {
256
257 // Save Event Notifications :
258
259 // Block immediately if user is not allowed :
260 nf_not_allowed( 'block', __LINE__ );
261
262 $nfw_options = nfw_get_option( 'nfw_options' );
263
264 if (! preg_match('/^[012]$/', $_POST['nfw_options']['a_0']) ) {
265 $nfw_options['a_0'] = 1;
266 } else {
267 $nfw_options['a_0'] = $_POST['nfw_options']['a_0'];
268 }
269
270 if (! preg_match('/^[123]$/', $_POST['nfw_options']['alert_sa_only']) ) {
271 $nfw_options['alert_sa_only'] = 1;
272 } else {
273 $nfw_options['alert_sa_only'] = $_POST['nfw_options']['alert_sa_only'];
274 }
275
276 if ( empty( $_POST['nfw_options']['a_11']) ) {
277 $nfw_options['a_11'] = 0;
278 } else {
279 $nfw_options['a_11'] = 1;
280 }
281 if ( empty( $_POST['nfw_options']['a_12']) ) {
282 $nfw_options['a_12'] = 0;
283 } else {
284 $nfw_options['a_12'] = 1;
285 }
286 if ( empty( $_POST['nfw_options']['a_13']) ) {
287 $nfw_options['a_13'] = 0;
288 } else {
289 $nfw_options['a_13'] = 1;
290 }
291 if ( empty( $_POST['nfw_options']['a_14']) ) {
292 $nfw_options['a_14'] = 0;
293 } else {
294 $nfw_options['a_14'] = 1;
295 }
296 if ( empty( $_POST['nfw_options']['a_15']) ) {
297 $nfw_options['a_15'] = 0;
298 } else {
299 $nfw_options['a_15'] = 1;
300 }
301 if ( empty( $_POST['nfw_options']['a_16']) ) {
302 $nfw_options['a_16'] = 0;
303 } else {
304 $nfw_options['a_16'] = 1;
305 }
306
307 if ( empty( $_POST['nfw_options']['a_21']) ) {
308 $nfw_options['a_21'] = 0;
309 } else {
310 $nfw_options['a_21'] = 1;
311 }
312 if ( empty( $_POST['nfw_options']['a_22']) ) {
313 $nfw_options['a_22'] = 0;
314 } else {
315 $nfw_options['a_22'] = 1;
316 }
317 if ( empty( $_POST['nfw_options']['a_23']) ) {
318 $nfw_options['a_23'] = 0;
319 } else {
320 $nfw_options['a_23'] = 1;
321 }
322 if ( empty( $_POST['nfw_options']['a_24']) ) {
323 $nfw_options['a_24'] = 0;
324 } else {
325 $nfw_options['a_24'] = 1;
326 }
327 if ( empty( $_POST['nfw_options']['a_25']) ) {
328 $nfw_options['a_25'] = 0;
329 } else {
330 $nfw_options['a_25'] = 1;
331 }
332
333 if ( empty( $_POST['nfw_options']['a_31']) ) {
334 $nfw_options['a_31'] = 0;
335 } else {
336 $nfw_options['a_31'] = 1;
337 }
338
339 if ( empty( $_POST['nfw_options']['a_41']) ) {
340 $nfw_options['a_41'] = 0;
341 } else {
342 $nfw_options['a_41'] = 1;
343 }
344
345 if ( empty( $_POST['nfw_options']['secupdates']) ) {
346 $nfw_options['secupdates'] = 0;
347 } else {
348 $nfw_options['secupdates'] = 1;
349 }
350
351 if ( empty( $_POST['nfw_options']['a_51']) ) {
352 $nfw_options['a_51'] = 0;
353 } else {
354 $nfw_options['a_51'] = 1;
355 }
356 if ( empty( $_POST['nfw_options']['a_52']) ) {
357 $nfw_options['a_52'] = 0;
358 } else {
359 $nfw_options['a_52'] = 1;
360 }
361
362 if ( empty( $_POST['nfw_options']['a_61']) ) {
363 $nfw_options['a_61'] = 0;
364
365 } elseif ( $_POST['nfw_options']['a_61'] == 1 ) {
366 $nfw_options['a_61'] = 1;
367
368 } elseif ( $_POST['nfw_options']['a_61'] == 2 ) {
369 $nfw_options['a_61'] = 2;
370
371 } else {
372 $nfw_options['a_61'] = -1;
373 }
374
375 // Multiple recipients (WPMU only) ?
376 if (! empty( $_POST['nfw_options']['alert_multirec']) ) {
377 $_POST['nfw_options']['alert_email'] = $_POST['nfw_options']['alert_multirec'];
378 }
379
380 if (! empty( $_POST['nfw_options']['alert_email']) ) {
381 $nfw_options['alert_email'] = '';
382 $tmp_email = explode(',', $_POST['nfw_options']['alert_email'] );
383 foreach ($tmp_email as $notif_email) {
384 $nfw_options['alert_email'] .= sanitize_email($notif_email) . ', ';
385 }
386 $nfw_options['alert_email'] = trim($nfw_options['alert_email'], ', ' );
387 }
388 if ( empty( $nfw_options['alert_email'] ) ) {
389 $nfw_options['alert_email'] = get_option('admin_email');
390 }
391
392 // Update options
393 nfw_update_option( 'nfw_options', $nfw_options );
394
395 // Recreate cronjobs if needed
396 nfw_create_scheduled_tasks('nfdailyreport');
397
398 }
399
400 // ---------------------------------------------------------------------
401
402 function nf_daily_report() {
403
404 // Send a daily report to the admin(s)
405 $nfw_options = nfw_get_option('nfw_options');
406
407 // We check if it is enabled here just in case something went
408 // wrong with the task scheduler
409 if ( empty( $nfw_options['a_52']) ) {
410 return;
411 }
412
413 // Make sure we didn't send it already (if WP-Cron is ran twice by mistake)
414 if ( is_multisite() ) {
415 $nf_transient = get_site_transient('nfw_dailyreport');
416 } else {
417 $nf_transient = get_transient('nfw_dailyreport');
418 }
419
420 if ( $nf_transient == false || $nf_transient < time() ) {
421 if ( is_multisite() ) {
422 set_site_transient('nfw_dailyreport', time() + 3600, 3600 );
423 } else {
424 set_transient('nfw_dailyreport', time() + 3600, 3600 );
425 }
426
427 $logstats = [];
428 $logstats = nf_daily_report_log();
429
430 nf_daily_report_email( $logstats );
431 }
432
433 }
434 // ---------------------------------------------------------------------
435 function nf_daily_report_log() {
436
437 if ( date('j') == 1 ) {
438 $cur_month_log = date('Y-m', strtotime( date('Y-m') .' -1 month') );
439 } else {
440 $cur_month_log = date('Y-m');
441 }
442 $previous_day = strtotime( date('Y-m-d 00:00:01', strtotime('-1 day') ) );
443 $logstats = [ 0 => 0, 1 => 0, 2 => 0, 3 => 0, 5 => 0 ];
444
445 $files = NinjaFirewall_helpers::nfw_glob(
446 NFW_LOG_DIR .'/nfwlog', 'firewall_'. $cur_month_log, true, true
447 );
448
449 // Parse each log
450 foreach( $files as $file ) {
451
452 // Stat the file: if it's older than 24 hours, we skip it
453 $log_stat = stat( $file );
454 if ( $log_stat['mtime'] < $previous_day ) {
455 continue;
456 }
457
458 $log_lines = file( $file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
459 foreach ( $log_lines as $line ) {
460 if ( preg_match(
461 '/^\[(\d{10})\]\s+\[.+?\]\s+\[.+?\]\s+\[#\d{7}\]\s+\[\d+\]\s+\[([1235])\]\s+\[/',
462 $line, $match )
463 ) {
464 // Fetch last 24 hours only
465 if ( $match[1] > $previous_day && $match[1] < $previous_day + 86400 ) {
466 ++$logstats[ $match[2] ];
467 if ( strpos( $line, 'Brute-force attack detected') !== FALSE ) {
468 ++$logstats[0];
469 }
470 }
471 }
472 }
473 }
474 return $logstats;
475 }
476
477 // ---------------------------------------------------------------------
478
479 function nf_daily_report_email( $logstats ) {
480
481 /**
482 * Home URL.
483 */
484 if ( is_multisite() ) {
485 $url = network_home_url('/');
486 } else {
487 $url = home_url('/');
488 }
489 $host = parse_url( $url, PHP_URL_HOST );
490
491 $subject = [ $host ];
492 $content = [ $url, ucfirst( date('F j, Y',strtotime('-1 days') ) ),
493 $logstats[1] + $logstats[2] + $logstats[3],
494 $logstats[3], $logstats[2], $logstats[1], $logstats[0] ];
495
496 NinjaFirewall_mail::send('daily_report', $subject, $content, '', [], 1 );
497 }
498
499 // ---------------------------------------------------------------------
500 // EOF
501