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 / ninjafirewall.php
ninjafirewall Last commit date
images 4 weeks ago languages 11 months ago lib 4 weeks ago static 4 weeks ago .htaccess 7 years ago .htninja.sample 2 years ago LICENSE.TXT 13 years ago index.html 12 years ago ninjafirewall.php 4 weeks ago readme.txt 2 weeks ago uninstall.php 1 year ago
ninjafirewall.php
1239 lines
1 <?php
2 /*
3 Plugin Name: NinjaFirewall (WP Edition)
4 Plugin URI: https://nintechnet.com/
5 Description: A true Web Application Firewall to protect and secure WordPress.
6 Version: 4.9
7 Author: The Ninja Technologies Network
8 Author URI: https://nintechnet.com/
9 License: GPLv3 or later
10 Network: true
11 Text Domain: ninjafirewall
12 Domain Path: /languages
13 */
14 define('NFW_ENGINE_VERSION', '4.9');
15 /*
16 +=====================================================================+
17 | _ _ _ _ _____ _ _ _ |
18 | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | |
19 | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | |
20 | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | |
21 | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| |
22 | |__/ |
23 | (c) NinTechNet Limited ~ https://nintechnet.com/ |
24 +=====================================================================+
25 */
26
27 if (! defined('ABSPATH') ) {
28 die('Forbidden');
29 }
30
31 /* ------------------------------------------------------------------ */
32 define('NFW_NULL_BYTE', 2);
33 define('NFW_SCAN_BOTS', 531);
34 define('NFW_ASCII_CTRL', 500);
35 define('NFW_DOC_ROOT', 510);
36 define('NFW_WRAPPERS', 520);
37 define('NFW_OBJECTS', 525);
38 define('NFW_LOOPBACK', 540);
39 define('NFW_DEFAULT_MSG', '<br /><br /><br /><br /><center>' .
40 sprintf('Sorry %s, your request cannot be processed.', '<b>%%REM_ADDRESS%%</b>') .
41 '<br />' . 'For security reasons, it was blocked and logged.' .
42 '<br /><br />%%NINJA_LOGO%%<br /><br />' .
43 'If you believe this was an error please contact the<br />webmaster and enclose the '.
44 'following incident ID:' .' <br /><br />[ <b>#%%NUM_INCIDENT%%</b> ]</center>'
45 );
46
47 /**
48 * Since WP 6.7, translation loading must not be triggered too early.
49 */
50 require_once __DIR__ . '/lib/i18n.php';
51
52 if (! defined('NFW_LOG_DIR') ) {
53 define('NFW_LOG_DIR', WP_CONTENT_DIR );
54 }
55 if (! empty( $_SERVER['DOCUMENT_ROOT'] ) && $_SERVER['DOCUMENT_ROOT'] != '/') {
56 $_SERVER['DOCUMENT_ROOT'] = rtrim( $_SERVER['DOCUMENT_ROOT'] , '/');
57 }
58
59 /* ------------------------------------------------------------------ */
60
61 /**
62 * Start a session.
63 */
64 if (! defined('NFWSESSION_DIR') ) {
65 /**
66 * NFWSESSION_DIR can be defined in the .htninja.
67 */
68 define('NFWSESSION_DIR', NFW_LOG_DIR .'/nfwlog/session');
69 }
70 require_once __DIR__ .'/lib/class-session.php';
71
72
73 if (! defined( 'NFW_REMOTE_ADDR') ) {
74 /**
75 * Error: the firewall isn't loaded.
76 */
77 require_once __DIR__ .'/lib/class-ip.php';
78 NinjaFirewall_IP::check_ip( ['ac_ip' => 1 ] );
79 }
80
81 /**
82 * Those classes and constants could be already loaded/defined by the firewall (if enabled).
83 */
84 if ( ! defined('NFWLOG_DEBUG') ) {
85 define('NFWLOG_MEDIUM', 1);
86 define('NFWLOG_HIGH', 2);
87 define('NFWLOG_CRITICAL', 3);
88 define('NFWLOG_POSTDETECT', 4);
89 define('NFWLOG_UPLOAD', 5);
90 define('NFWLOG_INFO', 6);
91 define('NFWLOG_DEBUG', 7);
92 }
93 require_once __DIR__ .'/lib/class-firewall-log.php';
94 require_once __DIR__ . '/lib/class-helpers.php';
95 require_once __DIR__ .'/lib/class_mail.php';
96
97 require __DIR__ . '/lib/scheduled_tasks.php';
98 require __DIR__ . '/lib/helpers.php';
99 require __DIR__ . '/lib/settings_events.php';
100
101 add_action( 'nfwgccron', 'nfw_garbage_collector' );
102
103 /* ------------------------------------------------------------------ */
104
105 function nfw_activate() {
106
107 // Install/activate NinjaFirewall
108
109 if ( defined('WP_CLI') && WP_CLI && PHP_SAPI === 'cli' ) {
110 $php_cli = true;
111 }
112
113 if (! isset( $php_cli ) ) {
114 /**
115 * Warn if the user does not have the 'unfiltered_html' capability.
116 */
117 if (! current_user_can('unfiltered_html') ) {
118 wp_die(
119 esc_html__('You do not have "unfiltered_html" capability. Please enable it in order to run NinjaFirewall (or make sure you do not have "DISALLOW_UNFILTERED_HTML" in your wp-config.php script).', 'ninjafirewall'),
120 esc_html__('Plugin Activation Error', 'ninjafirewall'),
121 ['back_link' => true ]
122 );
123 }
124 }
125
126 /**
127 * WordPress minimum version.
128 */
129 global $wp_version;
130 if ( version_compare( $wp_version, '4.7.0', '<') ) {
131 wp_die( sprintf(
132 esc_html__('NinjaFirewall requires WordPress %s or greater but your current version is %s.', 'ninjafirewall'), '4.7.0', $wp_version
133 ),
134 esc_html__('Plugin Activation Error', 'ninjafirewall'),
135 ['back_link' => true ]
136 );
137 }
138
139 /**
140 * PHP minimum version.
141 */
142 if ( version_compare( PHP_VERSION, '7.1.0', '<') ) {
143 wp_die( sprintf(
144 esc_html__('NinjaFirewall requires PHP 7.1 or greater but your current version is %s.', 'ninjafirewall'), PHP_VERSION
145 ),
146 esc_html__('Plugin Activation Error', 'ninjafirewall'),
147 ['back_link' => true ]
148 );
149 }
150
151 /**
152 * We need the mysqli extension loaded.
153 */
154 if (! function_exists('mysqli_connect') ) {
155 wp_die( sprintf(
156 esc_html__('NinjaFirewall requires the PHP %s extension.', 'ninjafirewall'), '<code>mysqli</code>'
157 ),
158 esc_html__('Plugin Activation Error', 'ninjafirewall'),
159 ['back_link' => true ]
160 );
161 }
162
163 /**
164 * We don't do Windows.
165 */
166 if ( PATH_SEPARATOR == ';') {
167 wp_die(
168 esc_html__('NinjaFirewall is not compatible with Microsoft Windows.', 'ninjafirewall'),
169 esc_html__('Plugin Activation Error', 'ninjafirewall'),
170 ['back_link' => true ]
171 );
172 }
173
174 if (! $nfw_options = nfw_get_option( 'nfw_options' ) ) {
175 // First time we're running: download the security rules
176 // and populate the options:
177 require_once __DIR__ .'/lib/install_default.php';
178 nfw_load_default_conf();
179 // Reload them
180 $nfw_options = nfw_get_option( 'nfw_options' );
181 } else {
182 // (Re)create the loader
183 require_once __DIR__ .'/lib/install_default.php';
184 nfw_create_loader();
185 }
186
187 $nfw_options['enabled'] = 1;
188 nfw_update_option( 'nfw_options', $nfw_options);
189
190 $res = nfw_enable_wpwaf();
191 if (! empty( $res ) ){
192 /**
193 * Display WAF activation errors.
194 */
195 wp_die( $res );
196 }
197
198 // Create scheduled tasks.
199 nfw_create_scheduled_tasks();
200
201 // Re-enable brute-force protection
202 if ( file_exists( NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php' ) ) {
203 rename(NFW_LOG_DIR . '/nfwlog/cache/bf_conf_off.php', NFW_LOG_DIR . '/nfwlog/cache/bf_conf.php');
204 }
205 }
206
207 register_activation_hook( __FILE__, 'nfw_activate' );
208
209 /* ------------------------------------------------------------------ */
210
211 function nfw_deactivate() {
212
213 if ( defined('WP_CLI') && WP_CLI && PHP_SAPI === 'cli') {
214 $php_cli = true;
215 }
216
217 if (! isset( $php_cli ) ) {
218 /**
219 * Warn if the user does not have the 'unfiltered_html' capability unless it's CLI.
220 */
221 if (! current_user_can('unfiltered_html') ) {
222 exit( esc_html__('You do not have "unfiltered_html" capability. Please enable it in order to run NinjaFirewall (or make sure you do not have "DISALLOW_UNFILTERED_HTML" in your wp-config.php script).', 'ninjafirewall') );
223 }
224 nf_not_allowed('block', __LINE__ );
225
226 global $current_user;
227 $current_user = wp_get_current_user();
228 $user_login = $current_user->user_login;
229 $user_roles = $current_user->roles[0];
230 } else {
231 $user_login = 'WP CLI';
232 $user_roles = '-';
233 }
234
235 $nfw_options = nfw_get_option('nfw_options');
236
237 /**
238 * Re-used code from Firewall Options.
239 */
240 if ( empty( $_REQUEST['action'] ) || strpos( $_REQUEST['action'], 'deactivate') === false ) {
241
242 if ( is_multisite() ) {
243 $url = network_home_url('/');
244 } else {
245 $url = home_url('/');
246 }
247
248 $subject = [ ];
249 $content = [ "$user_login ($user_roles)", NFW_REMOTE_ADDR,
250 ucfirst( date_i18n('F j, Y @ H:i:s O') ), $url ];
251
252 NinjaFirewall_mail::send('disabled', $subject, $content, '', [], 1 );
253 }
254
255 $nfw_options['enabled'] = 0;
256 nfw_disable_wpwaf();
257
258 /**
259 * Disable brute-force protection.
260 */
261 if ( file_exists( NFW_LOG_DIR .'/nfwlog/cache/bf_conf.php') ) {
262 rename(NFW_LOG_DIR .'/nfwlog/cache/bf_conf.php', NFW_LOG_DIR .'/nfwlog/cache/bf_conf_off.php');
263 }
264
265 nfw_update_option('nfw_options', $nfw_options);
266
267 /**
268 * Remove any existing cron.
269 */
270 nfw_delete_scheduled_tasks();
271
272 }
273
274 register_deactivation_hook( __FILE__, 'nfw_deactivate');
275
276 /* ------------------------------------------------------------------ */
277 // Load script/style files
278
279 function nfw_load_ext( $hook ) {
280
281 // Load the external JS script and CSS:
282 // -Single site: to the admin only.
283 // -Multi-site: to the superadmin and from the main network admin screen only.
284 // -All: only if this is a NinjaFirewall menu page, or the Plugins page
285 if (! current_user_can('activate_plugins') || ! is_main_site() ) {
286 return;
287 }
288
289 if ( stripos( $hook, 'ninjafirewall' ) === false && $hook != 'plugins.php') {
290 return;
291 }
292
293 if ( strpos ( $hook, 'nfsubwplus' ) !== false ) {
294 // Load thickbox JS and CSS (WP only for "WP+" menu page's screenshots)
295 $extra_js = ['jquery', 'thickbox'];
296 $extra_css = ['thickbox'];
297 } else {
298 $extra_js = ['jquery'];
299 $extra_css = null;
300 }
301
302 // TipTip (WP Edition only)
303 wp_enqueue_script(
304 'jquery-tiptip',
305 plugin_dir_url( __FILE__ ) .'static/jquery.tipTip.js',
306 ['jquery'],
307 NFW_ENGINE_VERSION
308 );
309
310
311 wp_enqueue_script(
312 'nfw_javascript',
313 plugin_dir_url( __FILE__ ) .'static/ninjafirewall.js',
314 $extra_js,
315 NFW_ENGINE_VERSION
316 );
317
318 // Load Chart.js if we are viewing the statistics page:
319 if ( strpos( $hook, 'NinjaFirewall' ) !== false ) {
320 wp_enqueue_script(
321 'nfw_charts',
322 plugin_dir_url( __FILE__ ) . 'static/chart.min.js',
323 ['jquery'],
324 NFW_ENGINE_VERSION,
325 // We load it in the footer, because some plugins loads it too
326 // on every pages and that could mess with our pages
327 true
328 );
329 }
330
331 wp_enqueue_style(
332 'nfw_style',
333 plugin_dir_url( __FILE__ ) .'static/ninjafirewall.css',
334 $extra_css,
335 NFW_ENGINE_VERSION,
336 false
337 );
338
339 // Javascript i18n:
340 $nfw_js_array = [
341
342 // Generic
343 'restore_default' =>
344 __('All fields will be restored to their default values and any changes you made will be lost. Continue?', 'ninjafirewall'),
345
346 // Full WAF/WordPress WAF
347 'missing_nonce' =>
348 __('Missing security nonce, try to reload the page.', 'ninjafirewall'),
349 'missing_httpserver' =>
350 __('Please select the HTTP server in the list.', 'ninjafirewall'),
351 // Dashboard
352 'del_errorlog' =>
353 __('Delete the firewall\'s error log ?', 'ninjafirewall'),
354
355 // Firewall Options
356 'restore_warning' =>
357 __('This action will restore the selected configuration file and will override all your current firewall options, policies and rules. Continue?', 'ninjafirewall'),
358
359 // Firewall Policies
360 'warn_sanitise' =>
361 __('Any character that is not a letter [a-zA-Z], a digit [0-9], a dot [.], a hyphen [-] or an underscore [_] will be removed from the filename and replaced with the substitution character. Continue?', 'ninjafirewall'),
362 'ssl_warning' =>
363 __('Ensure that you can access your admin dashboard over HTTPS before enabling this option, otherwise you will lock yourself out of your site. Continue?', 'ninjafirewall'),
364 'woo_warning' =>
365 __("WooCommerce is running: if you block accounts creation, your customers won't be able to sign up. Continue?", 'ninjafirewall'),
366 'reguser_warning' =>
367 __("Your blog has user registration enabled: if you block accounts creation, your customers won't be able to sign up. Continue?", 'ninjafirewall'),
368 'regsite_warning' =>
369 __("Your multisite installation allows users to register new sites: if you enable this option, they will likely get blocked when creating their blog. Continue?", 'ninjafirewall'),
370
371 // File Check
372 'del_snapshot' =>
373 __('Delete the current snapshot ?', 'ninjafirewall'),
374
375 // Login Protection
376 'invalid_char' =>
377 __('Invalid character.', 'ninjafirewall'),
378 'no_admin' =>
379 __('"admin" is not acceptable, please choose another user name.', 'ninjafirewall'),
380 'max_char' =>
381 __('Please enter max 1024 character only.', 'ninjafirewall'),
382 'select_when' =>
383 __('Select when to enable the login protection.', 'ninjafirewall'),
384 'missing_auth' =>
385 __('Enter a name and a password for the HTTP authentication.', 'ninjafirewall'),
386
387 // Firewall Log
388 'invalid_key' =>
389 __('Your public key is not valid.', 'ninjafirewall'),
390
391 // Events notification
392 'missing_parameters' =>
393 __('Missing parameters.', 'ninjafirewall'),
394 'unknown_error' =>
395 __('Unknown error.', 'ninjafirewall'),
396
397 // Live Log
398 'live_log_desc' =>
399 __('Live Log lets you watch your blog traffic in real time. To enable it, click on the button below.', 'ninjafirewall'),
400 'no_traffic' =>
401 __('No traffic yet, please wait', 'ninjafirewall'),
402 'seconds' =>
403 ' ' . __('seconds...', 'ninjafirewall'),
404 'err_unexpected' =>
405 __('Error: Live Log did not receive the expected response from your server:', 'ninjafirewall'),
406 'error_404' =>
407 __('Error: URL does not seem to exist (404 Not Found):', 'ninjafirewall'),
408 'log_not_found' =>
409 __('Error: Cannot find your log file. Try to reload this page.', 'ninjafirewall'),
410 'http_error' =>
411 __('Error: The HTTP server returned the following error code:', 'ninjafirewall')
412 ];
413
414 wp_localize_script( 'nfw_javascript', 'nfwi18n', $nfw_js_array );
415 }
416
417 add_action( 'admin_enqueue_scripts', 'nfw_load_ext' );
418
419 /* ------------------------------------------------------------------ */
420
421 function nfw_admin_init() {
422
423 // We must make sure that the current PHP session is always
424 // updated even for whitelisted non-admin users (must be logged-in
425 // to prevent unauthenticated AJAX calls to trigger it):
426 if ( is_user_logged_in() ) {
427 NinjaFirewall_session::start();
428 // Save user's capabilities
429 $nf_user = wp_get_current_user();
430 if ( $nf_user instanceof WP_User ) {
431 NinjaFirewall_session::write( ['allcaps' => $nf_user->allcaps ] );
432 }
433 }
434
435 $nfw_options = nfw_get_option( 'nfw_options' );
436 $nfw_rules = nfw_get_option( 'nfw_rules' );
437
438 // Post-update adjustment:
439 require plugin_dir_path(__FILE__) . 'lib/init_update.php';
440
441 // Make sure cronjobs are running as expected
442 nfw_verify_scheduled_tasks();
443
444 // --------------------------------------------
445 // Anything below requires admin authentication
446 // --------------------------------------------
447
448 if ( nf_not_allowed( 0, __LINE__ ) ) {
449 return;
450 }
451
452 // Create our unique PID
453 $nfw_pid = NFW_LOG_DIR .'/nfwlog/cache/.pid';
454 if (! file_exists( $nfw_pid ) ) {
455 file_put_contents( $nfw_pid, uniqid('', true) );
456 }
457
458 // Update fallback loader if needed
459 if ( wp_doing_ajax() == false ) {
460 nfw_enable_wpwaf();
461 }
462
463 /**
464 * WordPress, plugins and themes security updates.
465 */
466 global $pagenow;
467 if ( $pagenow == 'plugins.php' && current_user_can('update_plugins') ) {
468 require_once __DIR__ .'/lib/class-security-updates.php';
469 NinjaFirewall_security_updates::display();
470 }
471
472 /**
473 * Export NinjaFirewall's configuration.
474 */
475 if ( isset( $_POST['ninjafirewall_export'] ) ) {
476
477 require_once __DIR__ .'/lib/class-import-export.php';
478 NinjaFirewall_ImpExp::export();
479 }
480
481 // Download File Check modified files list:
482 if ( isset($_POST['dlmods']) ) {
483 if ( empty($_POST['nfwnonce']) || ! wp_verify_nonce($_POST['nfwnonce'], 'filecheck_save') ) {
484 wp_nonce_ays('filecheck_save');
485 }
486 if (file_exists(NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_diff.php') ) {
487 $download_file = NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_diff.php';
488 } elseif (file_exists(NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_diff.php.php') ) {
489 $download_file = NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_diff.php.php';
490 } else {
491 wp_nonce_ays('filecheck_save');
492 }
493 $stat = stat($download_file);
494 $data = '== NinjaFirewall File Check (diff)'. "\n";
495 $data.= '== ' . site_url() . "\n";
496 $data.= '== ' . date_i18n('M d, Y @ H:i:s O', $stat['ctime']) . "\n\n";
497 $data.= '[+] = ' . __('New file', 'ninjafirewall') .
498 ' [!] = ' . __('Modified file', 'ninjafirewall') .
499 ' [-] = ' . __('Deleted file', 'ninjafirewall') .
500 "\n\n";
501 $fh = fopen($download_file, 'r');
502 while (! feof($fh) ) {
503 $res = explode('::', fgets($fh) );
504 if ( empty($res[1]) ) { continue; }
505 if ($res[1] == 'N') {
506 $data .= '[+] ' . $res[0] . "\n";
507 } elseif ($res[1] == 'D') {
508 $data .= '[-] ' . $res[0] . "\n";
509 } elseif ($res[1] == 'M') {
510 $data .= '[!] ' . $res[0] . "\n";
511 }
512 }
513 fclose($fh);
514 $data .= "\n== EOF\n";
515 /**
516 * Use the home_url instead of SERVER_NAME, as they could be different.
517 */
518 $dl_name = sanitize_file_name( wp_parse_url( home_url(), PHP_URL_HOST ) );
519 if ( empty( $dl_name ) ) {
520 $dl_name = sanitize_file_name( $_SERVER['SERVER_NAME'] );
521 }
522 header('Content-Type: text/plain');
523 header('Content-Length: '. strlen( $data ) );
524 header('Content-Disposition: attachment; filename="'. $dl_name .'_diff.txt"');
525 echo $data;
526 exit;
527 }
528
529 // Download File Check snapshot:
530 if ( isset($_POST['dlsnap']) ) {
531 if ( empty($_POST['nfwnonce']) || ! wp_verify_nonce($_POST['nfwnonce'], 'filecheck_save') ) {
532 wp_nonce_ays('filecheck_save');
533 }
534 if (file_exists(NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_snapshot.php') ) {
535 $stat = stat(NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_snapshot.php');
536 $data = '== NinjaFirewall File Check (snapshot)'. "\n";
537 $data.= '== ' . site_url() . "\n";
538 $data.= '== ' . date_i18n('M d, Y @ H:i:s O', $stat['ctime']) . "\n\n";
539 $fh = fopen(NFW_LOG_DIR . '/nfwlog/cache/nfilecheck_snapshot.php', 'r');
540 while (! feof($fh) ) {
541 $res = explode('::', fgets($fh) );
542 if (! empty($res[0][0]) && $res[0][0] == '/') {
543 $data .= $res[0] . "\n";
544 }
545 }
546 fclose($fh);
547 $data .= "\n== EOF\n";
548 /**
549 * Use the home_url instead of SERVER_NAME, as they could be different.
550 */
551 $dl_name = sanitize_file_name( wp_parse_url( home_url(), PHP_URL_HOST ) );
552 if ( empty( $dl_name ) ) {
553 $dl_name = sanitize_file_name( $_SERVER['SERVER_NAME'] );
554 }
555 header('Content-Type: text/plain');
556 header('Content-Length: '. strlen( $data ) );
557 header('Content-Disposition: attachment; filename="'. $dl_name .'_snapshot.txt"');
558 echo $data;
559 exit;
560 } else {
561 wp_nonce_ays('filecheck_save');
562 }
563 }
564
565 // Applies to admin only (unlike the WP+ Edition):
566 if (! empty( $nfw_options['wl_admin'] ) ) {
567 if (! empty( $nfw_options['bf_enable'] ) && ! empty( $nfw_options['bf_rand'] ) ) {
568 NinjaFirewall_session::write( ['nfw_goodguy' => true, 'nfw_bfd' => $nfw_options['bf_rand'] ] );
569 } else {
570 NinjaFirewall_session::write( ['nfw_goodguy' => true ] );
571 }
572 return;
573 }
574 NinjaFirewall_session::delete('nfw_goodguy');
575 }
576
577 add_action('admin_init', 'nfw_admin_init' );
578
579 // ---------------------------------------------------------------------
580 // Check if the user wants to remove her email from the notification list.
581
582 function nfw_init_emailremoval() {
583
584 if (! empty( $_GET['nfw_stop_notification'] ) ) {
585 require_once 'lib/class-email-sodium.php';
586 NinjaFirewall_emailsodium::sodium_decrypt( $_GET['nfw_stop_notification'] );
587 }
588
589 }
590 add_action('init', 'nfw_init_emailremoval' );
591
592 // ---------------------------------------------------------------------
593 // Check if the user is an admin and if we must whitelist them.
594
595 function nfw_login_hook( $user_login, $user ) {
596
597 NinjaFirewall_session::start();
598
599 $nfw_options = nfw_get_option( 'nfw_options' );
600
601 // Don't do anything if NinjaFirewall is disabled:
602 if ( empty( $nfw_options['enabled'] ) ) { return; }
603
604 // Fetch user roles:
605 $whoami = '';
606 foreach( $user->roles as $k => $v ) {
607 if ( $v == 'administrator' ) {
608 $admin_flag = 1;
609 }
610 $whoami .= "$v ";
611 }
612 $whoami = trim( $whoami );
613
614 // Still nothing: Maybe an additional superadmin
615 if ( empty( $whoami ) && is_multisite() ) {
616 // $user->ID is required here
617 if ( is_super_admin( $user->ID ) ) {
618 $admin_flag = 1;
619 $whoami = 'administrator';
620 }
621 }
622
623 // Are we supposed to send an alert?
624 if (! empty( $nfw_options['a_0'] ) ) {
625 if ( ( $nfw_options['a_0'] == 1 && isset( $admin_flag ) ) || $nfw_options['a_0'] == 2 ) {
626
627 nfw_send_loginemail( $user_login, $whoami );
628 /**
629 * Write event to log.
630 */
631 if (! empty( $nfw_options['a_41'] ) ) {
632 NinjaFirewall_log::write(
633 'Logged in user',
634 "{$user_login} ({$whoami})",
635 NFWLOG_INFO, 0, $nfw_options, NFW_LOG_DIR .'/nfwlog'
636 );
637 }
638 }
639 }
640
641 //Whitelist:
642 if (! empty( $nfw_options['wl_admin']) ) {
643 if ( ( $nfw_options['wl_admin'] == 1 && isset( $admin_flag ) ) || $nfw_options['wl_admin'] == 2 ) {
644 // Set the goodguy flag
645 NinjaFirewall_session::write( ['nfw_goodguy' => true ] );
646 return;
647 }
648 }
649 NinjaFirewall_session::delete('nfw_goodguy');
650 }
651
652 // Hook priority can be defined in the wp-config.php or .htninja
653 if ( defined('NFW_LOGINHOOK') ) {
654 $NFW_LOGINHOOK = (int) NFW_LOGINHOOK;
655 } else {
656 $NFW_LOGINHOOK = -999999999;
657 }
658 add_action( 'wp_login', 'nfw_login_hook', $NFW_LOGINHOOK, 2 );
659
660 /* ------------------------------------------------------------------ */
661 function nfw_logout_hook() {
662
663 NinjaFirewall_session::start();
664
665 // Whoever it was, we clear the goodguy flag
666 NinjaFirewall_session::delete('nfw_goodguy');
667 // And the Live Log flag as well
668 NinjaFirewall_session::delete('nfw_livelog');
669 NinjaFirewall_session::delete('allcaps');
670 }
671
672 add_action( 'wp_logout', 'nfw_logout_hook' );
673
674 // =====================================================================
675 // Plugin ugrade AJAX function.
676
677 require __DIR__ .'/lib/class-plugin-upgrade.php';
678 add_action('wp_ajax_nfw_pluginupgrade', ['NinjaFirewall_plugin', 'upgrade'] );
679
680 /* ------------------------------------------------------------------ */
681 // FullWAF upgrade AJAX function.
682
683 add_action( 'wp_ajax_nfw_fullwafsetup', 'nfw_fullwafsetup' );
684
685 function nfw_fullwafsetup() {
686
687 nf_not_allowed( 'block', __LINE__ );
688
689 if (! check_ajax_referer( 'events_save', 'nonce', false ) ) {
690 esc_html_e('Error: Security nonces do not match. Reload the page and try again.', 'ninjafirewall');
691 wp_die();
692 }
693
694 $nfw_options = nfw_get_option( 'nfw_options' );
695 if ( empty( $nfw_options['enabled'] ) ) {
696 esc_html_e('Error: NinjaFirewall is disabled', 'ninjafirewall');
697 wp_die();
698 }
699
700 if ( empty( $_POST['httpserver'] ) ) {
701 printf( esc_html__('Error: missing parameter (%s).', 'ninjafirewall'), 'httpserver' );
702 wp_die();
703 }
704 if ( preg_match('/^[^1-8]$/', $_POST['httpserver'] ) ) {
705 printf( esc_html__('Error: wrong parameter value (%s).', 'ninjafirewall'), 'httpserver' );
706 wp_die();
707 }
708 if ( empty( $_POST['diy'] ) || ! preg_match( '/^(nfw|usr)$/', $_POST['diy'] ) ) {
709 printf( esc_html__('Error: wrong parameter value (%s).', 'ninjafirewall'), 'diy' );
710 wp_die();
711 }
712
713 // Retrieve the list of excluded folders, if any, and save it
714 nfw_save_waf_exclusionlist( $_POST['exclude_waf_list'] );
715
716 // Disable the sandbox?
717 if ( empty( $_POST['sandbox'] ) ) {
718 define('NFW_BYPASS_SANDBOX', true);
719 }
720
721 $time = time() + 300;
722
723 // 1: Apache mod_php
724 // 2: Apache + CGI/FastCGI or PHP-FPM
725 // 3: Apache + suPHP
726 // 4: Nginx + CGI/FastCGI or PHP-FPM
727 // 5: Litespeed
728 // 6: Openlitespeed
729 // 7: Other webserver + CGI/FastCGI or PHP-FPM
730 // 8: Apache + LSAPI
731 $httpserver = (int) $_POST['httpserver'];
732
733 // [6] Openlitespeed: nothing to do.
734 if ( $httpserver == 6 ) {
735 set_transient( 'nfw_fullwaf', "{$httpserver}:{$time}", 60 * 5 );
736 echo '200';
737 wp_die();
738 }
739
740 require_once __DIR__ .'/lib/install.php';
741
742 // .htaccess mods only
743 if ( $httpserver == 1 || $httpserver == 5 || $httpserver == 8 ) {
744 // User wants to make the modification
745 if ( $_POST['diy'] == 'usr' ) {
746 // Nothing to do
747 set_transient( 'nfw_fullwaf', "{$httpserver}:{$time}", 60 * 5 );
748 echo '200';
749 wp_die();
750 }
751 // Make changes
752 $ret = nfw_fullwaf_htaccess( $httpserver );
753 if ( $ret !== true ) {
754 echo esc_html( $ret );
755 } else {
756 set_transient( 'nfw_fullwaf', "{$httpserver}:{$time}", 60 * 5 );
757 echo '200';
758 }
759 wp_die();
760 }
761
762 if ( $_POST['diy'] == 'usr' ) {
763 // Nothing to do, but add 5-minute notice to the overview page
764 // because an INI file is being used
765 set_transient( 'nfw_fullwaf', "{$httpserver}:{$time}", 60 * 5 );
766 echo '200';
767 wp_die();
768 }
769
770 // [1] .user.ini
771 // [2] php.ini
772 if ( empty ( $_POST['initype'] ) || ! preg_match( '/^[12]$/', $_POST['initype'] ) ) {
773 $initype = 1;
774 } else {
775 $initype = (int) $_POST['initype'];
776 }
777
778 if ( $httpserver == 3 ) { // Apache + suPHP
779 // Set up the htaccess file
780 $ret = nfw_fullwaf_htaccess( $httpserver );
781 if ( $ret !== true ) {
782 echo esc_html( $ret );
783 wp_die();
784 }
785 }
786 // ini file
787 $ret = nfw_fullwaf_ini( $httpserver, $initype );
788 if ( $ret !== true ) {
789 echo esc_html( $ret );
790 wp_die();
791 } else {
792 // Add 5-minute notice to the overview page
793 // because an INI file is being used
794 set_transient( 'nfw_fullwaf', "{$httpserver}:{$time}", 60 * 5 );
795 echo 200;
796 }
797 wp_die();
798 }
799
800 /* ------------------------------------------------------------------ */
801 // Configure Full WAF mode or fallback to WP WAF mode. AJAX action.
802
803 add_action( 'wp_ajax_nfw_fullwafconfig', 'nfw_fullwafconfig' );
804
805 function nfw_fullwafconfig() {
806
807 nf_not_allowed( 'block', __LINE__ );
808
809 if (! check_ajax_referer( 'events_save', 'nonce', false ) ) {
810 esc_html_e('Error: Security nonces do not match. Reload the page and try again.', 'ninjafirewall');
811 wp_die();
812 }
813
814 if ( empty( $_POST['what'] ) || ! preg_match( '/^[12]$/', $_POST['what'] ) ) {
815 printf( esc_html__('Error: missing parameter (%s).', 'ninjafirewall'), 'what' );
816 wp_die();
817 }
818
819 // Downgrade to WP WAF
820 if ( $_POST['what'] == 2 ) {
821
822 require __DIR__ .'/lib/install.php';
823 nfw_get_constants();
824 nfw_remove_directives();
825
826 // Full WAF directories exclusion
827 } else {
828 // Retrieve the list of excluded folders, if any, and save it
829 nfw_save_waf_exclusionlist( $_POST['list'] );
830 }
831
832 wp_die(200);
833 }
834
835 /* ------------------------------------------------------------------ */
836 // Save new exclusion list.
837
838 function nfw_save_waf_exclusionlist( $input ) {
839
840 $nfw_options = nfw_get_option('nfw_options');
841
842 // Retrieve the list of excluded folders, if any, and save it
843 $tmp_exclude_waf_list = json_decode( stripslashes( $input ) );
844 if ( $tmp_exclude_waf_list === false || $tmp_exclude_waf_list === null ) {
845 printf( esc_html__('Error: missing parameter (%s).', 'ninjafirewall'), 'list');
846 wp_die();
847 }
848 $exclude_waf_list = [];
849 if (! empty( $tmp_exclude_waf_list ) ) {
850 foreach( $tmp_exclude_waf_list as $folder ) {
851 if ( is_dir( realpath( ABSPATH . $folder ) ) ) {
852 $exclude_waf_list[] = $folder;
853 }
854 }
855 }
856 // Update/clear the list
857 if (! empty( $exclude_waf_list ) ) {
858 $nfw_options['exclude_waf_list'] = json_encode( $exclude_waf_list );
859 } else {
860 unset( $nfw_options['exclude_waf_list'] );
861 }
862 nfw_update_option('nfw_options', $nfw_options);
863 // (Re)create the loader
864 require_once __DIR__ .'/lib/install_default.php';
865 nfw_create_loader();
866
867 }
868
869 /* ------------------------------------------------------------------ */
870
871 function is_nfw_enabled() {
872
873 $nfw_options = nfw_get_option( 'nfw_options' );
874
875 if (! defined('NFW_STATUS') ) {
876 define('NF_DISABLED', 10);
877 return;
878 }
879
880 if ( isset($nfw_options['enabled']) && $nfw_options['enabled'] == '0' ) {
881 define('NF_DISABLED', 9);
882 return;
883 }
884
885 if (NFW_STATUS == 21 || NFW_STATUS == 22 || NFW_STATUS == 23) {
886 define('NF_DISABLED', 10);
887 return;
888 }
889
890 // OK
891 if (NFW_STATUS == 20) {
892 define('NF_DISABLED', 0);
893 return;
894 }
895
896 define('NF_DISABLED', NFW_STATUS);
897 return;
898
899 }
900
901 /* ------------------------------------------------------------------ */
902
903 function ninjafirewall_admin_menu() {
904
905 if ( nf_not_allowed( 0, __LINE__ ) ) { return; }
906
907 if (! empty($_REQUEST['nfw_act']) && $_REQUEST['nfw_act'] == 99) {
908 if ( empty($_GET['nfwnonce']) || ! wp_verify_nonce($_GET['nfwnonce'], 'show_phpinfo') ) {
909 wp_nonce_ays('show_phpinfo');
910 }
911 phpinfo(33);
912 exit;
913 }
914
915 add_menu_page( 'NinjaFirewall', 'NinjaFirewall', 'manage_options',
916 'NinjaFirewall', 'nf_sub_main', plugins_url( '/images/nf_icon.png', __FILE__ )
917 );
918
919 global $menu_hook;
920
921 require_once plugin_dir_path(__FILE__) . 'lib/help.php';
922
923 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Dashboard', 'ninjafirewall'), __('Dashboard', 'ninjafirewall'), 'manage_options',
924 'NinjaFirewall', 'nf_sub_main' );
925 add_action( 'load-' . $menu_hook, 'help_nfsubmain' );
926
927 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Firewall Options', 'ninjafirewall'), __('Firewall Options', 'ninjafirewall'), 'manage_options',
928 'nfsubopt', 'nf_sub_options' );
929 add_action( 'load-' . $menu_hook, 'help_nfsubopt' );
930
931 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Firewall Policies', 'ninjafirewall'), __('Firewall Policies', 'ninjafirewall'), 'manage_options',
932 'nfsubpolicies', 'nf_sub_policies' );
933 add_action( 'load-' . $menu_hook, 'help_nfsubpolicies' );
934
935 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Monitoring', 'ninjafirewall'), __( 'Monitoring', 'ninjafirewall'), 'manage_options',
936 'nfsubfileguard', 'nf_sub_monitoring' );
937 add_action( 'load-' . $menu_hook, 'help_nfsubfileguard' );
938
939 $nscan_options = get_option( 'nscan_options' );
940 if ( defined('NSCAN_NAME') && defined('NSCAN_SLUG') && ! empty( $nscan_options['scan_nfwpintegration'] ) ) {
941 $menu_hook = add_submenu_page( 'NinjaFirewall', NSCAN_NAME, NSCAN_NAME, 'manage_options', NSCAN_NAME, 'nscan_main_menu' );
942 require_once dirname( __DIR__ ).'/'. NSCAN_SLUG .'/lib/help.php';
943 add_action( 'load-' . $menu_hook, 'nscan_help' );
944 } else {
945 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Anti-Malware', 'ninjafirewall'), __('Anti-Malware', 'ninjafirewall'), 'manage_options',
946 'nfsubmalwarescan', 'nf_sub_malwarescan' );
947 }
948
949 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Network', 'ninjafirewall'), __('Network', 'ninjafirewall'), 'manage_network',
950 'nfsubnetwork', 'nf_sub_network' );
951 add_action( 'load-' . $menu_hook, 'help_nfsubnetwork' );
952
953 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Event Notifications', 'ninjafirewall'), __('Event Notifications', 'ninjafirewall'), 'manage_options',
954 'nfsubevent', 'nf_sub_event' );
955 add_action( 'load-' . $menu_hook, 'help_nfsubevent' );
956
957 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Log-in Protection', 'ninjafirewall'), __('Login Protection', 'ninjafirewall'), 'manage_options',
958 'nfsubloginprot', 'nf_sub_loginprot' );
959 add_action( 'load-' . $menu_hook, 'help_nfsublogin' );
960
961 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Logs', 'ninjafirewall'), __('Logs', 'ninjafirewall'), 'manage_options',
962 'nfsublog', 'nf_sub_log' );
963 add_action( 'load-' . $menu_hook, 'help_nfsublog' );
964
965 $menu_hook = add_submenu_page( 'NinjaFirewall', __('NinjaFirewall: Security Rules', 'ninjafirewall'), __('Security Rules', 'ninjafirewall'), 'manage_options',
966 'nfsubupdates', 'nf_sub_updates' );
967 add_action( 'load-' . $menu_hook, 'help_nfsubupdates' );
968
969 $menu_hook = add_submenu_page( 'NinjaFirewall', 'NinjaFirewall: WP+ Edition', '<b style="color:#fcdc25">WP+ Edition</b>', 'manage_options',
970 'nfsubwplus', 'nf_sub_wplus' );
971
972 }
973 // Must load before NinjaScanner (11):
974 if (! is_multisite() ) {
975 add_action( 'admin_menu', 'ninjafirewall_admin_menu', 10 );
976 } else {
977 add_action( 'network_admin_menu', 'ninjafirewall_admin_menu', 10 );
978 }
979
980 /* ------------------------------------------------------------------ */
981
982 function nf_admin_bar_status() {
983
984 if (! current_user_can( 'manage_options' ) ) {
985 return;
986 }
987
988 $nfw_options = nfw_get_option( 'nfw_options' );
989 if ( @$nfw_options['nt_show_status'] != 1 && ! current_user_can('manage_network') ) {
990 return;
991 }
992
993 if (! defined('NF_DISABLED') ) {
994 is_nfw_enabled();
995 }
996 if (NF_DISABLED) { return; }
997
998 global $wp_admin_bar;
999 $wp_admin_bar->add_menu( [
1000 'id' => 'nfw_ntw1',
1001 'title' => '<img src="' . plugins_url() . '/ninjafirewall/images/ninjafirewall_20.png" ' .
1002 'style="vertical-align:middle;margin-right:5px" />'
1003 ] );
1004
1005 if ( current_user_can( 'manage_network' ) ) {
1006 $wp_admin_bar->add_menu( [
1007 'parent' => 'nfw_ntw1',
1008 'id' => 'nfw_ntw2',
1009 'title' => __( 'NinjaFirewall Settings', 'ninjafirewall'),
1010 'href' => network_admin_url() . 'admin.php?page=NinjaFirewall'
1011 ] );
1012 } else {
1013 if ( defined('NFW_STATUS') ) {
1014 $wp_admin_bar->add_menu( [
1015 'parent' => 'nfw_ntw1',
1016 'id' => 'nfw_ntw2',
1017 'title' => __( 'NinjaFirewall is enabled', 'ninjafirewall')
1018 ] );
1019 }
1020 }
1021 }
1022
1023 if ( is_multisite() ) {
1024 add_action('admin_bar_menu', 'nf_admin_bar_status', 95);
1025 }
1026
1027 /* ------------------------------------------------------------------ */
1028
1029 function nf_sub_main() {
1030
1031 // Main menu (Overview)
1032 require plugin_dir_path(__FILE__) . 'lib/settings_dashboard.php';
1033
1034 }
1035
1036 /* ------------------------------------------------------------------ */
1037
1038 function nf_sub_options() { // i18n
1039
1040 require plugin_dir_path(__FILE__) . 'lib/settings_firewall_options.php';
1041
1042 }
1043
1044 /* ------------------------------------------------------------------ */
1045
1046 function nf_sub_policies() {
1047
1048 // Firewall Policies menu
1049 require plugin_dir_path(__FILE__) . 'lib/settings_firewall_policies.php';
1050
1051 }
1052
1053 /* ------------------------------------------------------------------ */
1054
1055 function nf_sub_monitoring() {
1056
1057 require plugin_dir_path(__FILE__) . 'lib/settings_monitoring.php';
1058
1059 }
1060 add_action('nfscanevent', 'nfscando');
1061
1062 function nfscando() {
1063
1064 define('NFSCANDO', 1);
1065 nf_sub_monitoring();
1066 }
1067
1068 /* ------------------------------------------------------------------ */
1069
1070 function nf_sub_network() {
1071
1072 // Network menu (multi-site only)
1073 require plugin_dir_path(__FILE__) . 'lib/settings_network.php';
1074
1075 }
1076
1077 /* ------------------------------------------------------------------ */
1078
1079 function nf_sub_malwarescan() {
1080
1081 require plugin_dir_path(__FILE__) . 'lib/anti_malware.php';
1082
1083 }
1084
1085 /* ------------------------------------------------------------------ */
1086
1087 function nf_sub_event() {
1088
1089 require plugin_dir_path(__FILE__) . 'lib/settings_event_notifications.php';
1090
1091 }
1092
1093 add_action('shutdown', 'nf_check_dbdata', 1);
1094
1095 add_action('nfdailyreport', 'nfdailyreportdo');
1096
1097 function nfdailyreportdo() {
1098 define('NFREPORTDO', 1);
1099 nf_sub_event();
1100 }
1101
1102 /* ------------------------------------------------------------------ */
1103
1104 function nf_sub_log() {
1105
1106 require plugin_dir_path(__FILE__) . 'lib/settings_logs.php';
1107
1108 }
1109
1110 /* ------------------------------------------------------------------ */
1111
1112 function nf_sub_loginprot() {
1113
1114 require plugin_dir_path(__FILE__) . 'lib/settings_login_protection.php';
1115
1116 }
1117
1118 /* ------------------------------------------------------------------ */
1119
1120 function nf_sub_updates() {
1121
1122 require plugin_dir_path(__FILE__) . 'lib/settings_security_rules.php';
1123
1124 }
1125
1126 add_action('nfsecupdates', 'nfupdatesdo');
1127
1128 function nfupdatesdo() {
1129 define('NFUPDATESDO', 1);
1130 nf_sub_updates();
1131 }
1132
1133 /* ------------------------------------------------------------------ */
1134
1135 function nf_sub_wplus() {
1136
1137 require plugin_dir_path(__FILE__) . 'lib/wpplus.php';
1138 }
1139
1140 /* ------------------------------------------------------------------ */
1141
1142 function ninjafirewall_settings_link( $links ) {
1143
1144 // Check if access is restricted to one or more specific admins
1145 // See: https://blog.nintechnet.com/restricting-access-to-ninjafirewall-wp-edition-settings/
1146 if ( nf_not_allowed( 0, __LINE__ ) ) {
1147 unset( $links );
1148 $links[] = __('Access Restricted', 'ninjafirewall');
1149 return $links;
1150 }
1151
1152 if ( is_multisite() ) { $net = 'network/'; } else { $net = ''; }
1153
1154 $links[] = '<a href="'. get_admin_url(null, $net .'admin.php?page=NinjaFirewall') .'">'. __('Settings', 'ninjafirewall') .'</a>';
1155 $links[] = '<a href="https://nintechnet.com/ninjafirewall/wp-edition/?pricing" target="_blank">'. __('Upgrade to Premium', 'ninjafirewall'). '</a>';
1156 $links[] = '<a href="https://wordpress.org/support/view/plugin-reviews/ninjafirewall?rate=5#postform" target="_blank">'. __('Rate it!', 'ninjafirewall'). '</a>';
1157 unset( $links['edit'] );
1158 return $links;
1159
1160 }
1161
1162 if ( is_multisite() ) {
1163 add_filter( 'network_admin_plugin_action_links_' . plugin_basename(__FILE__), 'ninjafirewall_settings_link' );
1164 } else {
1165 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'ninjafirewall_settings_link' );
1166 }
1167
1168 /* ------------------------------------------------------------------ */
1169
1170 function nfw_dashboard_widgets() {
1171
1172 require plugin_dir_path(__FILE__) . 'lib/widget.php';
1173
1174 }
1175
1176 if ( is_multisite() ) {
1177 add_action( 'wp_network_dashboard_setup', 'nfw_dashboard_widgets' );
1178 } else {
1179 add_action( 'wp_dashboard_setup', 'nfw_dashboard_widgets' );
1180 }
1181
1182 /* ------------------------------------------------------------------ */
1183
1184 function nf_not_allowed( $block, $line = 0, $ajax = 0 ) {
1185
1186 if ( is_multisite() ) {
1187 if ( current_user_can('manage_network') && is_main_site() ) {
1188 return false;
1189 }
1190 } else {
1191 if ( current_user_can('manage_options') &&
1192 current_user_can('unfiltered_html') ) {
1193 // Check if that admin is allowed to use NinjaFirewall
1194 // (see NFW_ALLOWED_ADMIN at http://nin.link/nfwaa ):
1195 if ( defined('NFW_ALLOWED_ADMIN') ) {
1196 $current_user = wp_get_current_user();
1197 $admins = explode(',', NFW_ALLOWED_ADMIN );
1198 foreach ( $admins as $admin ) {
1199 if ( trim( $admin ) == $current_user->user_login ) {
1200 return false;
1201 }
1202 }
1203 } else {
1204 return false;
1205 }
1206 }
1207 }
1208
1209 if ( $block ) {
1210 if ( defined('WP_CLI') && WP_CLI ) {
1211 // Format text for WP-CLI:
1212 WP_CLI::error(
1213 sprintf(
1214 __('You are not allowed to perform this task (%s).', 'ninjafirewall'),
1215 "NinjaFirewall: $line"
1216 )
1217 );
1218 } elseif ( $ajax ) {
1219 $message = sprintf(
1220 esc_html__('You are not allowed to perform this task (%s).', 'ninjafirewall'),
1221 "NinjaFirewall: $line"
1222 );
1223 wp_send_json( ['error' => $message ] );
1224
1225 } else {
1226 die( '<br /><br /><br /><div class="error notice is-dismissible"><p>' .
1227 sprintf(
1228 esc_html__('You are not allowed to perform this task (%s).', 'ninjafirewall'),
1229 "NinjaFirewall: $line"
1230 ) .'</p></div>'
1231 );
1232 }
1233 }
1234 return true;
1235 }
1236
1237 /* ------------------------------------------------------------------ */
1238 // EOF //
1239