PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.10.0
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.10.0
3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 All 88 releases
vigilante / admin / class-admin.php

class-admin.php in Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… 2.10.0, at admin/class-admin.php

7,955 lines 510.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class
4 *
5 * Handles admin interface and settings page
6 *
7 * @package Vigilante
8 */
9
10 // Prevent direct access
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 // Load AJAX trait
16 require_once VIGILANTE_ADMIN_DIR . 'class-admin-ajax.php';
17
18 // Load promotional banner class
19 require_once VIGILANTE_INCLUDES_DIR . 'class-ayudawp-promo-banner.php';
20
21 /**
22 * Class Vigilante_Admin
23 *
24 * Manages the admin settings interface
25 */
26 class Vigilante_Admin {
27
28 use Vigilante_Admin_Ajax;
29 use Vigilante_Admin_Analyzer_Ajax;
30 use Vigilante_Admin_Audit_Alerts_Ajax;
31 use Vigilante_Admin_Recovery_Ajax;
32
33 /**
34 * Settings instance
35 *
36 * @var Vigilante_Settings
37 */
38 private $settings;
39
40 /**
41 * Database instance
42 *
43 * @var Vigilante_Database
44 */
45 private $database;
46
47 /**
48 * Activity log instance
49 *
50 * @var Vigilante_Activity_Log
51 */
52 private $activity_log;
53
54 /**
55 * Current tab
56 *
57 * @var string
58 */
59 private $current_tab = 'dashboard';
60
61 /**
62 * Available tabs
63 *
64 * @var array
65 */
66 private $tabs = array();
67
68 /**
69 * Constructor
70 *
71 * @param Vigilante_Settings $settings Settings instance.
72 * @param Vigilante_Database $database Database instance.
73 * @param Vigilante_Activity_Log $activity_log Activity log instance.
74 */
75 public function __construct( $settings, $database, $activity_log ) {
76 $this->settings = $settings;
77 $this->database = $database;
78 $this->activity_log = $activity_log;
79
80 $this->setup_tabs();
81 $this->init_hooks();
82 }
83
84 /**
85 * Setup available tabs
86 */
87 private function setup_tabs() {
88 $this->tabs = array(
89 'dashboard' => __( 'Dashboard', 'vigilante' ),
90 'firewall' => __( 'Firewall', 'vigilante' ),
91 'headers' => __( 'Security Headers', 'vigilante' ),
92 'login' => __( 'Login Security', 'vigilante' ),
93 'rest-api' => __( 'REST API', 'vigilante' ),
94 'users' => __( 'User Security', 'vigilante' ),
95 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
96 'file-integrity' => __( 'File Integrity', 'vigilante' ),
97 'activity-log' => __( 'Security Audit', 'vigilante' ),
98 'tools' => __( 'Settings & Tools', 'vigilante' ),
99 );
100 }
101
102 /**
103 * Initialize hooks
104 */
105 private function init_hooks() {
106 add_action( 'admin_menu', array( $this, 'add_menu' ) );
107 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
108 add_action( 'admin_init', array( $this, 'register_settings' ) );
109 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
110 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
111
112 // Highlight correct submenu based on active tab
113 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
114
115 // Set browser tab title to show plugin name and active tab
116 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
117
118 // AJAX handlers
119 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
120 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
121 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
122 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
123 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
124 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
125 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
126 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
127 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
128 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
129 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
130 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
131 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
132 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
133 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
134 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
135 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
136 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
137 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
138 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
139 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
140
141 // 2FA AJAX handlers
142 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
143 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
144 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
145 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
146 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
147 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
148
149 // Password Reset AJAX handlers
150 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
151 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
152 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
153 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
154
155 // User approval AJAX handlers
156 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
157 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
158
159 // Session management AJAX handlers
160 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
161 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
162 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
163
164 // Under Attack mode AJAX handlers
165 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
166 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
167 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
168
169 // Database backup AJAX handlers
170 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
171 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
172
173 // Database prefix AJAX handlers
174 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
175 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
176
177 // Firewall list management from activity log popup
178 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
179 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
180
181 // Security Analyzer AJAX handlers (v2.1.0)
182 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
183 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
184 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
185 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
186
187 // Security Headers settings recovery (2.10.0)
188 add_action( 'wp_ajax_vigilante_headers_recovery_restore', array( $this, 'ajax_headers_recovery_restore' ) );
189 add_action( 'wp_ajax_vigilante_headers_recovery_undo', array( $this, 'ajax_headers_recovery_undo' ) );
190 add_action( 'wp_ajax_vigilante_headers_recovery_dismiss', array( $this, 'ajax_headers_recovery_dismiss' ) );
191
192 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
193 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
194
195 // Run migrations on admin load
196 add_action( 'admin_init', array( $this, 'run_migrations' ) );
197 }
198
199 /**
200 * Run database migrations based on stored version
201 */
202 public function run_migrations() {
203 $db_version = get_option( 'vigilante_db_version', '0' );
204
205 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
206 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
207 $this->migrate_fix_ip_lists();
208 update_option( 'vigilante_db_version', '1.2.3' );
209 }
210
211 // 1.3.0: Add request_method column to activity log table
212 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
213 $this->database->run_migrations();
214 }
215
216 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
217 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
218 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
219 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
220 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
221 $wpconfig->apply_security_constants();
222 }
223 update_option( 'vigilante_db_version', '1.9.0' );
224 }
225
226 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
227 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
228 $this->migrate_cleanup_email_fields();
229 update_option( 'vigilante_db_version', '1.10.0' );
230 }
231
232 // 1.11.0: Remove stale 'enabled' key from activity_log settings
233 // + Convert additional_recipients from string to array
234 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
235 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
236 $changed = false;
237
238 if ( isset( $options['activity_log']['enabled'] ) ) {
239 unset( $options['activity_log']['enabled'] );
240 $changed = true;
241 }
242
243 // Convert corrupted string to array for additional_recipients
244 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
245 $raw = trim( $options['email']['additional_recipients'] );
246 if ( ! empty( $raw ) ) {
247 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
248 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
249 } else {
250 $options['email']['additional_recipients'] = array();
251 }
252 $changed = true;
253 }
254
255 if ( $changed ) {
256 update_option( Vigilante_Settings::OPTION_NAME, $options );
257 }
258 update_option( 'vigilante_db_version', '1.11.0' );
259 }
260
261 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
262 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
263 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
264 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
265 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
266 $htaccess->apply_rules();
267 }
268 update_option( 'vigilante_db_version', '1.12.1' );
269 }
270
271 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
272 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
273 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
274 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
275 }
276 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
277 $fi->regenerate_all_baselines();
278 update_option( 'vigilante_db_version', '1.14.0' );
279 }
280
281 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
282 // from firewall section to security_headers section
283 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
284 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
285 $changed = false;
286
287 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
288 if ( isset( $options['firewall'][ $key ] ) ) {
289 if ( ! isset( $options['security_headers'][ $key ] ) ) {
290 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
291 }
292 unset( $options['firewall'][ $key ] );
293 $changed = true;
294 }
295 }
296
297 if ( $changed ) {
298 update_option( Vigilante_Settings::OPTION_NAME, $options );
299 }
300 update_option( 'vigilante_db_version', '2.0.0' );
301 }
302
303 // 2.6.1: Two things happen here.
304 //
305 // 1. Re-apply wp-config constants so the block is rewritten with
306 // "if ( ! defined() )" guards around every define(). Without guards,
307 // non-standard setups that pre-define WordPress constants outside
308 // wp-config.php (custom bootstraps that load constants from .env or
309 // similar) hit a fatal "Constant already defined" when wp-config.php
310 // is parsed and reaches our block.
311 //
312 // 2. Drop the cached Security Check report. The cached "max" per
313 // category was frozen at scan time; with the internal category
314 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
315 // the cached report would keep displaying 22/22 until the next
316 // full scan. Clearing it forces a fresh scan with the new caps.
317 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
318 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
319 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
320 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
321 $wpconfig->apply_security_constants();
322 }
323 delete_option( 'vigilante_analyzer_last_scan' );
324
325 // Schedule an immediate background scan so the dashboard widget
326 // doesn't display "Last scan: never" right after the upgrade.
327 // Reuses the same hook the post-Under-Attack flow uses.
328 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
329 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
330 }
331
332 update_option( 'vigilante_db_version', '2.6.1' );
333 }
334
335 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
336 // User-Agent list dropped substring-prone tokens that 403'd
337 // legitimate clients (e.g. "rma" matched inside "Performance" and
338 // blocked WP Rocket's page fetch), and the blocking rules now honour
339 // the firewall IP / User-Agent whitelists as negated exceptions.
340 // Existing sites only rewrite the block when Server Protection is
341 // saved, so the upgrade has to refresh it once itself (same pattern
342 // as the 1.12.1 WooCommerce IPN migration).
343 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
344 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
345 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
346
347 if ( $htaccess->are_rules_active() ) {
348 $htaccess->apply_rules();
349 }
350
351 update_option( 'vigilante_db_version', '2.9.3' );
352 }
353
354 /*
355 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
356 * Requests" becomes a setting of its own, and Fix Mixed Content ships
357 * off, where before it shipped on and carried the directive with it.
358 * Both have to be written down for sites that are updating, so their
359 * pages keep loading exactly what they loaded yesterday.
360 *
361 * Read the RAW stored options, not get_section(): that one merges the
362 * defaults, so a site that never stored the key would be read with the
363 * new default and silently lose the behaviour it had. Absent means the
364 * site was running on the old default, which was on.
365 */
366 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
367 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
368 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
369 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
370
371 /*
372 * Merge, never replace. update_section() overwrites the whole
373 * section, so passing just these two keys wiped every other header
374 * setting the site had stored (HSTS, CSP, cross-origin policies,
375 * the HTTPS switches, Server Identity) and left the screen showing
376 * factory defaults while the .htaccess kept serving the old values.
377 */
378 $this->settings->update_section(
379 'security_headers',
380 array_merge(
381 $stored,
382 array(
383 'fix_mixed_content' => $had_fix,
384 'upgrade_insecure_requests' => $had_fix,
385 )
386 )
387 );
388
389 update_option( 'vigilante_db_version', '2.9.8' );
390 }
391
392 /*
393 * 2.9.9: drop the settings that no code has read for versions.
394 *
395 * They were carried in the defaults and therefore written into every
396 * saved configuration, they show up in an exported configuration, and
397 * anyone reading them assumes a feature exists behind them. Removing
398 * them from the defaults is not enough: the stored copies survive, so
399 * they are swept here too. Nothing reads them, so nothing changes.
400 */
401 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
402 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
403 $dead = array(
404 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
405 'file_integrity' => array( 'suspicious_patterns' ),
406 'backup' => array( 'auto_backup', 'backup_before_update' ),
407 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
408 );
409
410 $changed = false;
411 foreach ( $dead as $section => $keys ) {
412 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
413 continue;
414 }
415 foreach ( $keys as $key ) {
416 if ( array_key_exists( $key, $raw[ $section ] ) ) {
417 unset( $raw[ $section ][ $key ] );
418 $changed = true;
419 }
420 }
421 }
422
423 if ( $changed ) {
424 update_option( Vigilante_Settings::OPTION_NAME, $raw );
425 }
426
427 update_option( 'vigilante_db_version', '2.9.9' );
428 }
429 }
430
431 /**
432 * Migration: Remove orphaned email fields from saved options
433 *
434 * v1.10.0 centralized notification recipients into email section.
435 * Old per-module notify_email fields and dead email section fields
436 * are removed to avoid confusion.
437 */
438 private function migrate_cleanup_email_fields() {
439 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
440 $modified = false;
441
442 // Remove orphaned fields from email section
443 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
444 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
445 foreach ( $dead_email_keys as $key ) {
446 if ( array_key_exists( $key, $options['email'] ) ) {
447 unset( $options['email'][ $key ] );
448 $modified = true;
449 }
450 }
451 // Ensure new fields exist with defaults
452 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
453 $options['email']['send_to_admin_email'] = true;
454 $modified = true;
455 }
456 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
457 $options['email']['additional_recipients'] = '';
458 $modified = true;
459 }
460 }
461
462 // Remove notify_email from login_security
463 if ( isset( $options['login_security']['notify_email'] ) ) {
464 unset( $options['login_security']['notify_email'] );
465 $modified = true;
466 }
467
468 // Remove notify_email from file_integrity
469 if ( isset( $options['file_integrity']['notify_email'] ) ) {
470 unset( $options['file_integrity']['notify_email'] );
471 $modified = true;
472 }
473
474 if ( $modified ) {
475 update_option( Vigilante_Settings::OPTION_NAME, $options );
476 // Clear settings cache so the plugin uses clean data immediately
477 $this->settings->clear_cache();
478 }
479 }
480
481 /**
482 * Migration: Fix IP whitelist/blacklist entries merged into single line
483 *
484 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
485 * causing multiple IPs to be stored as a single space-separated string.
486 */
487 private function migrate_fix_ip_lists() {
488 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
489 $fixed = false;
490
491 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
492 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
493 $new_list = array();
494 foreach ( $options['firewall'][ $key ] as $entry ) {
495 // Split entries that were joined by spaces
496 $parts = preg_split( '/\s+/', trim( $entry ) );
497 foreach ( $parts as $part ) {
498 $part = trim( $part );
499 if ( '' !== $part ) {
500 $new_list[] = $part;
501 }
502 }
503 }
504 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
505 $options['firewall'][ $key ] = array_unique( $new_list );
506 $fixed = true;
507 }
508 }
509 }
510
511 if ( $fixed ) {
512 update_option( Vigilante_Settings::OPTION_NAME, $options );
513 // Clear settings cache so changes take effect immediately
514 $this->settings->clear_cache();
515 }
516 }
517
518 /**
519 * Add admin menu page in last position
520 */
521 public function add_menu() {
522 $menu_title = __( 'Vigilant', 'vigilante' );
523
524 // Count pending approvals (separate concern, always red if present)
525 $pending_count = $this->get_pending_approvals_count();
526
527 // Get security issues with severity
528 $security_status = $this->get_security_status_for_badge();
529
530 // Total count for badge
531 $total_badge = $pending_count + $security_status['count'];
532
533 if ( $total_badge > 0 ) {
534 // Determine badge color:
535 // - Red (awaiting-mod): pending approvals OR critical modules disabled
536 // - Orange (update-plugins): only non-critical modules disabled
537 if ( $pending_count > 0 || $security_status['has_critical'] ) {
538 $badge_class = 'awaiting-mod';
539 } else {
540 $badge_class = 'update-plugins vigilante-badge-warning';
541 }
542
543 $menu_title .= sprintf(
544 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
545 esc_attr( $badge_class ),
546 $total_badge,
547 $total_badge
548 );
549 }
550
551 add_menu_page(
552 __( 'Vigilant', 'vigilante' ),
553 $menu_title,
554 'manage_options',
555 'vigilante',
556 array( $this, 'render_settings_page' ),
557 'dashicons-shield',
558 999
559 );
560
561 // Rename auto-generated first submenu to "Dashboard"
562 add_submenu_page(
563 'vigilante',
564 __( 'Dashboard', 'vigilante' ),
565 __( 'Dashboard', 'vigilante' ),
566 'manage_options',
567 'vigilante',
568 array( $this, 'render_settings_page' )
569 );
570
571 // Security Audit shortcut
572 add_submenu_page(
573 'vigilante',
574 __( 'Security Audit', 'vigilante' ),
575 __( 'Security Audit', 'vigilante' ),
576 'manage_options',
577 'vigilante-activity-log',
578 array( $this, 'redirect_to_tab' )
579 );
580
581 // File Integrity shortcut
582 add_submenu_page(
583 'vigilante',
584 __( 'File Integrity', 'vigilante' ),
585 __( 'File Integrity', 'vigilante' ),
586 'manage_options',
587 'vigilante-file-integrity',
588 array( $this, 'redirect_to_tab' )
589 );
590 }
591
592 /**
593 * Redirect submenu shortcuts early, before headers are sent
594 */
595 public function redirect_submenu_shortcuts() {
596 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
597 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
598
599 $tab_map = array(
600 'vigilante-activity-log' => 'activity-log',
601 'vigilante-file-integrity' => 'file-integrity',
602 );
603
604 if ( isset( $tab_map[ $page ] ) ) {
605 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
606 exit;
607 }
608 }
609
610 /**
611 * Fallback redirect for submenu shortcuts (JS-based)
612 */
613 public function redirect_to_tab() {
614 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
615 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
616
617 $tab_map = array(
618 'vigilante-activity-log' => 'activity-log',
619 'vigilante-file-integrity' => 'file-integrity',
620 );
621
622 if ( isset( $tab_map[ $page ] ) ) {
623 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
624 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
625 }
626 }
627
628 /**
629 * Highlight the correct submenu item based on active tab
630 *
631 * @param string $submenu_file Current submenu file.
632 * @return string
633 */
634 public function highlight_submenu_tab( $submenu_file ) {
635 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
636 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
637 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
638 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
639
640 if ( 'vigilante' !== $page || empty( $tab ) ) {
641 return $submenu_file;
642 }
643
644 $tab_to_submenu = array(
645 'activity-log' => 'vigilante-activity-log',
646 'file-integrity' => 'vigilante-file-integrity',
647 );
648
649 if ( isset( $tab_to_submenu[ $tab ] ) ) {
650 return $tab_to_submenu[ $tab ];
651 }
652
653 return $submenu_file;
654 }
655
656 /**
657 * Set browser tab title to show plugin name and active tab
658 *
659 * Changes "Dashboard ‹ Site Name — WordPress" to
660 * "Vigilant > Dashboard ‹ Site Name — WordPress"
661 *
662 * @param string $admin_title Full admin title.
663 * @param string $title Page title from add_menu_page/add_submenu_page.
664 * @return string Modified title.
665 */
666 public function set_admin_page_title( $admin_title, $title ) {
667 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
668 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
669
670 // Only modify on Vigilante pages
671 if ( 0 !== strpos( $page, 'vigilante' ) ) {
672 return $admin_title;
673 }
674
675 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
676 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
677
678 if ( isset( $this->tabs[ $tab ] ) ) {
679 $tab_label = $this->tabs[ $tab ];
680 } else {
681 $tab_label = __( 'Dashboard', 'vigilante' );
682 }
683
684 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
685
686 // Replace the original page title portion
687 return str_replace( $title, $plugin_title, $admin_title );
688 }
689
690 /**
691 * Get count of users pending approval
692 *
693 * @return int Count of pending users.
694 */
695 private function get_pending_approvals_count() {
696 // Prevent early execution before WordPress is ready
697 if ( ! did_action( 'plugins_loaded' ) ) {
698 return 0;
699 }
700
701 $registration_approval = $this->settings->get_section( 'user_security' );
702 $approval_settings = $registration_approval['registration_approval'] ?? array();
703
704 if ( empty( $approval_settings['enabled'] ) ) {
705 return 0;
706 }
707
708 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
709 $pending_users = get_users( array(
710 'meta_key' => 'vigilante_pending_approval',
711 'meta_value' => '1',
712 'fields' => 'ID',
713 ) );
714 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
715
716 return count( $pending_users );
717 }
718
719 /**
720 * Calculate comprehensive security score (0-100)
721 *
722 * @param array $options Plugin options.
723 * @return int Security score.
724 */
725 private function calculate_security_score( $options ) {
726 $score = 0;
727 $max_score = 0;
728
729 // Module scores (60 points total)
730 $module_weights = array(
731 'firewall' => 10,
732 'security_headers' => 8,
733 'login_security' => 10,
734 'rest_api_security' => 6,
735 'user_security' => 8,
736 'wp_hardening' => 8,
737 'file_integrity' => 5,
738 'activity_log' => 5,
739 );
740
741 foreach ( $module_weights as $module => $weight ) {
742 $max_score += $weight;
743 if ( ! empty( $options['modules'][ $module ] ) ) {
744 $score += $weight;
745 }
746 }
747
748 // Firewall details (10 points)
749 if ( ! empty( $options['modules']['firewall'] ) ) {
750 $firewall = $options['firewall'] ?? array();
751 $max_score += 10;
752
753 $firewall_checks = array(
754 'block_sql_injection',
755 'block_xss_attacks',
756 'block_bad_query_strings',
757 'block_file_inclusion',
758 'block_directory_traversal',
759 );
760
761 $firewall_enabled = 0;
762 foreach ( $firewall_checks as $check ) {
763 if ( ! empty( $firewall[ $check ] ) ) {
764 $firewall_enabled++;
765 }
766 }
767 $score += min( 10, $firewall_enabled * 2 );
768 }
769
770 // Login security details (10 points)
771 if ( ! empty( $options['modules']['login_security'] ) ) {
772 $login = $options['login_security'] ?? array();
773 $max_score += 10;
774
775 // Max attempts configured
776 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
777 $score += 3;
778 }
779 // XML-RPC disabled
780 if ( ! empty( $login['disable_xmlrpc'] ) ) {
781 $score += 3;
782 }
783 // 2FA enabled
784 if ( ! empty( $login['two_factor']['enabled'] ) ) {
785 $score += 4;
786 }
787 }
788
789 // Security headers details (10 points)
790 if ( ! empty( $options['modules']['security_headers'] ) ) {
791 $headers = $options['security_headers'] ?? array();
792 $max_score += 10;
793
794 if ( ! empty( $headers['x_frame_options'] ) ) {
795 $score += 2;
796 }
797 if ( ! empty( $headers['x_content_type_options'] ) ) {
798 $score += 2;
799 }
800 if ( ! empty( $headers['hsts']['enabled'] ) ) {
801 $score += 3;
802 }
803 if ( ! empty( $headers['csp']['enabled'] ) ) {
804 $score += 3;
805 }
806 }
807
808 // User security details (10 points)
809 if ( ! empty( $options['modules']['user_security'] ) ) {
810 $user = $options['user_security'] ?? array();
811 $max_score += 10;
812
813 if ( ! empty( $user['block_insecure_usernames'] ) ) {
814 $score += 3;
815 }
816 if ( ! empty( $user['force_strong_passwords'] ) ) {
817 $score += 3;
818 }
819 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
820 $score += 2;
821 }
822 if ( ! empty( $user['email_verification']['enabled'] ) ) {
823 $score += 2;
824 }
825 }
826
827 // Audit alerts details (6 points) - only when Security Audit is on,
828 // because the alerting layer rides on top of the activity log. Leaving
829 // both alert legs off keeps these points unearned.
830 if ( ! empty( $options['modules']['activity_log'] ) ) {
831 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
832 $max_score += 6;
833 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
834 $score += 3;
835 }
836 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
837 $score += 3;
838 }
839 }
840
841 // Environment checks (8 points) - penalize insecure server configuration
842 $max_score += 8;
843 $env_score = 8;
844
845 // WP_DEBUG active in production is a security risk (exposes paths, errors)
846 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
847 $env_score -= 5;
848 }
849
850 // Accounts with insecure usernames (targeted by brute force attacks)
851 $insecure_admins = $this->get_insecure_admin_usernames();
852 if ( ! empty( $insecure_admins ) ) {
853 $env_score -= 3;
854 }
855
856 $score += max( 0, $env_score );
857
858 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
859 }
860
861 /**
862 * Get security recommendations based on current settings
863 *
864 * @param array $options Plugin options.
865 * @return array Array of recommendations.
866 */
867 private function get_security_recommendations( $options ) {
868 $recommendations = array();
869
870 // Critical: Firewall disabled
871 if ( empty( $options['modules']['firewall'] ) ) {
872 $recommendations[] = array(
873 'icon' => 'warning',
874 'priority' => 'critical',
875 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
876 );
877 }
878
879 // Critical: Login security disabled
880 if ( empty( $options['modules']['login_security'] ) ) {
881 $recommendations[] = array(
882 'icon' => 'warning',
883 'priority' => 'critical',
884 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
885 );
886 }
887
888 // High: Security headers disabled
889 if ( empty( $options['modules']['security_headers'] ) ) {
890 $recommendations[] = array(
891 'icon' => 'admin-generic',
892 'priority' => 'high',
893 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
894 );
895 }
896
897 // High: User security disabled
898 if ( empty( $options['modules']['user_security'] ) ) {
899 $recommendations[] = array(
900 'icon' => 'admin-users',
901 'priority' => 'high',
902 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
903 );
904 }
905
906 // High: 2FA not enabled (only if login security is active)
907 $login = $options['login_security'] ?? array();
908 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
909 $recommendations[] = array(
910 'icon' => 'shield',
911 'priority' => 'high',
912 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
913 'tab' => 'login',
914 );
915 }
916
917 // Medium: REST API security disabled
918 if ( empty( $options['modules']['rest_api_security'] ) ) {
919 $recommendations[] = array(
920 'icon' => 'rest-api',
921 'priority' => 'medium',
922 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
923 );
924 }
925
926 // Medium: WP Hardening disabled
927 if ( empty( $options['modules']['wp_hardening'] ) ) {
928 $recommendations[] = array(
929 'icon' => 'lock',
930 'priority' => 'medium',
931 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
932 );
933 }
934
935 // Medium: File integrity disabled
936 if ( empty( $options['modules']['file_integrity'] ) ) {
937 $recommendations[] = array(
938 'icon' => 'media-text',
939 'priority' => 'medium',
940 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
941 );
942 }
943
944 // Medium: Security Audit disabled
945 if ( empty( $options['modules']['activity_log'] ) ) {
946 $recommendations[] = array(
947 'icon' => 'list-view',
948 'priority' => 'medium',
949 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
950 );
951 }
952
953 // Low: XML-RPC enabled (only if login security is active)
954 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
955 $recommendations[] = array(
956 'icon' => 'info',
957 'priority' => 'low',
958 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
959 'tab' => 'login',
960 );
961 }
962
963 // Low: Strong passwords not enforced (only if user security is active)
964 $user = $options['user_security'] ?? array();
965 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
966 $recommendations[] = array(
967 'icon' => 'admin-users',
968 'priority' => 'low',
969 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
970 'tab' => 'users',
971 );
972 }
973
974 // High: WP_DEBUG active in production (regardless of Vigilante settings)
975 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
976 $recommendations[] = array(
977 'icon' => 'warning',
978 'priority' => 'high',
979 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
980 'tab' => 'wp-hardening',
981 );
982 }
983
984 // Low: Users with display name matching login username (only if user security active)
985 if ( ! empty( $options['modules']['user_security'] ) ) {
986 $exposed_users = $this->get_users_with_exposed_login();
987 if ( ! empty( $exposed_users ) ) {
988 $recommendations[] = array(
989 'icon' => 'admin-users',
990 'priority' => 'low',
991 'message' => sprintf(
992 /* translators: %s: Comma-separated list of usernames */
993 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
994 implode( ', ', $exposed_users )
995 ),
996 'tab' => 'users',
997 );
998 }
999 }
1000
1001 // High: Accounts with insecure usernames (regardless of module status)
1002 $insecure_admins = $this->get_insecure_admin_usernames();
1003 if ( ! empty( $insecure_admins ) ) {
1004 $recommendations[] = array(
1005 'icon' => 'warning',
1006 'priority' => 'high',
1007 'message' => sprintf(
1008 /* translators: %s: Comma-separated list of usernames */
1009 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
1010 implode( ', ', $insecure_admins )
1011 ),
1012 );
1013 }
1014
1015 // Critical: Closed or removed plugins detected by the daily check.
1016 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1017 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1018 // recommendation respects the user's per-slug Ignore decisions.
1019 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1020 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1021 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1022 }
1023 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1024 $closed_active = $closed_checker->get_closed_plugins();
1025 if ( ! empty( $closed_active ) ) {
1026 $names = array();
1027 foreach ( $closed_active as $slug => $entry ) {
1028 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1029 }
1030 $recommendations[] = array(
1031 'icon' => 'warning',
1032 'priority' => 'critical',
1033 'message' => sprintf(
1034 /* translators: 1: count, 2: comma-separated plugin names */
1035 _n(
1036 '%1$d closed plugin detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1037 '%1$d closed plugins detected on this site: %2$s. Closures in WordPress.org usually indicate malware, security issues or supply chain compromises. Uninstall and replace as soon as possible.',
1038 count( $closed_active ),
1039 'vigilante'
1040 ),
1041 count( $closed_active ),
1042 implode( ', ', $names )
1043 ),
1044 'tab' => 'file-integrity',
1045 );
1046 }
1047 }
1048
1049 // Medium: Security Audit is on but no audit alert is configured. The
1050 // alerting layer only makes sense while the activity log is running.
1051 if ( ! empty( $options['modules']['activity_log'] ) ) {
1052 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1053 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1054 $recommendations[] = array(
1055 'icon' => 'email-alt',
1056 'priority' => 'medium',
1057 'message' => __( 'Set up Audit Alerts to get an email when something important happens (a new admin, a closed plugin, or an attack in progress).', 'vigilante' ),
1058 'tab' => 'activity-log',
1059 );
1060 }
1061 }
1062
1063 // Sort by priority
1064 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1065 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1066 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1067 } );
1068
1069 return $recommendations;
1070 }
1071
1072 /**
1073 * Get users whose display name matches their login username
1074 *
1075 * Limited to administrators and editors for performance and relevance.
1076 * Cached with transient to avoid repeated queries on every dashboard load.
1077 *
1078 * @return array Array of usernames with exposed login.
1079 */
1080 private function get_users_with_exposed_login() {
1081 $cache_key = 'vigilante_exposed_display_names';
1082 $cached = get_transient( $cache_key );
1083
1084 if ( false !== $cached ) {
1085 return $cached;
1086 }
1087
1088 $exposed = array();
1089 $users = get_users( array(
1090 'role__in' => array( 'administrator', 'editor' ),
1091 'fields' => array( 'ID', 'user_login', 'display_name' ),
1092 ) );
1093
1094 foreach ( $users as $user ) {
1095 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1096 $exposed[] = $user->user_login;
1097 }
1098 }
1099
1100 // Cache for 12 hours
1101 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1102
1103 return $exposed;
1104 }
1105
1106 /**
1107 * Get accounts with insecure usernames
1108 *
1109 * Checks for common default usernames that are targeted by brute force attacks.
1110 * Detects any user regardless of role (consistent with username creation blocking).
1111 * Uses WordPress object cache via get_user_by() so no transient needed.
1112 *
1113 * @return array Array of insecure usernames found.
1114 */
1115 private function get_insecure_admin_usernames() {
1116 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1117 $found = array();
1118
1119 foreach ( $priority_usernames as $username ) {
1120 $user = get_user_by( 'login', $username );
1121 if ( $user ) {
1122 $found[] = $username;
1123 }
1124 }
1125
1126 return $found;
1127 }
1128
1129 /**
1130 * Get security status for menu badge
1131 *
1132 * Returns count of disabled modules and whether there are critical issues.
1133 * Critical = Firewall or Login Security disabled.
1134 *
1135 * @return array Array with 'count' and 'has_critical'.
1136 */
1137 public function get_security_status_for_badge() {
1138 $options = $this->settings->get_all_options();
1139 $modules = $options['modules'] ?? array();
1140
1141 // Count disabled modules
1142 $disabled_count = 0;
1143 $has_critical = false;
1144
1145 // Critical modules - if disabled, badge is red
1146 $critical_modules = array( 'firewall', 'login_security' );
1147
1148 foreach ( $modules as $module => $enabled ) {
1149 // Handle both boolean and string values ('1', '0', true, false)
1150 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1151
1152 if ( ! $is_enabled ) {
1153 $disabled_count++;
1154
1155 // Check if this is a critical module
1156 if ( in_array( $module, $critical_modules, true ) ) {
1157 $has_critical = true;
1158 }
1159 }
1160 }
1161
1162 return array(
1163 'count' => $disabled_count,
1164 'has_critical' => $has_critical,
1165 );
1166 }
1167
1168 /**
1169 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1170 *
1171 * @return int Count of critical/high issues.
1172 */
1173 public function get_security_issues_count() {
1174 $status = $this->get_security_status_for_badge();
1175 return $status['count'];
1176 }
1177
1178 /**
1179 * Register settings
1180 */
1181 public function register_settings() {
1182 register_setting(
1183 'vigilante_options',
1184 Vigilante_Settings::OPTION_NAME,
1185 array( $this->settings, 'validate_options' )
1186 );
1187 }
1188
1189 /**
1190 * Index behind the settings search box.
1191 *
1192 * Each entry points at one settings row. The search matches on the label,
1193 * on its English original and on 'keywords', which are extra terms someone
1194 * might type instead of the label itself.
1195 *
1196 * Those keywords are wrapped in _x() with the context "settings search
1197 * keywords" so every locale can supply its own: the source strings are in
1198 * English, and a Spanish user typing "contrasena" or a German one typing
1199 * "Kennwort" only reaches the password settings if that locale translated
1200 * them. Translators can add, drop or replace terms freely, one per space;
1201 * they are never displayed, only matched against what the user types.
1202 *
1203 * The list is maintained by hand, so a new settings row needs an entry here
1204 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1205 *
1206 * @return array
1207 */
1208 private function get_search_index() {
1209 return array(
1210 // Firewall - Main
1211 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block bad bots', 'vigilante' ), 'label_en' => 'Block bad bots', 'keywords' => _x( 'block bad bots blocking blocked deny malicious harmful bot crawler crawlers spider scraper robots', 'settings search keywords', 'vigilante' ) ),
1212 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block malicious requests', 'vigilante' ), 'label_en' => 'Block malicious requests', 'keywords' => _x( 'block malicious requests blocking blocked deny attack attacks exploit injection sqli xss rfi lfi request traffic', 'settings search keywords', 'vigilante' ) ),
1213 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Rate limiting', 'vigilante' ), 'label_en' => 'Rate limiting', 'keywords' => _x( 'rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1214 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Brute force protection', 'vigilante' ), 'label_en' => 'Brute force protection', 'keywords' => _x( 'brute force protection bruteforce login', 'settings search keywords', 'vigilante' ) ),
1215 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Whitelist', 'vigilante' ), 'label_en' => 'IP Whitelist', 'keywords' => _x( 'ip whitelist ips address addresses cidr ipv4 ipv6 allowlist allowed trusted', 'settings search keywords', 'vigilante' ) ),
1216 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'IP Blacklist', 'vigilante' ), 'label_en' => 'IP Blacklist', 'keywords' => _x( 'ip blacklist ips address addresses cidr ipv4 ipv6 blocklist denylist banned', 'settings search keywords', 'vigilante' ) ),
1217 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Whitelist', 'vigilante' ), 'label_en' => 'User-Agent Whitelist', 'keywords' => _x( 'user-agent whitelist ua useragent browser allowlist allowed trusted user', 'settings search keywords', 'vigilante' ) ),
1218 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'User-Agent Blacklist', 'vigilante' ), 'label_en' => 'User-Agent Blacklist', 'keywords' => _x( 'user-agent blacklist ua useragent browser blocklist denylist banned user', 'settings search keywords', 'vigilante' ) ),
1219 // Firewall - Server Protection
1220 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Directory Browsing', 'vigilante' ), 'label_en' => 'Directory Browsing', 'keywords' => _x( 'directory browsing folder folders listing indexing index', 'settings search keywords', 'vigilante' ) ),
1221 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-config.php', 'vigilante' ), 'label_en' => 'Protect wp-config.php', 'keywords' => _x( 'protect wp-config php protection secure lock', 'settings search keywords', 'vigilante' ) ),
1222 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'field-protect-wp-cron', 'label' => __( 'Protect wp-cron.php', 'vigilante' ), 'label_en' => 'Protect wp-cron.php', 'keywords' => _x( 'protect wp-cron php protection secure lock cron scheduled tasks block spam', 'settings search keywords', 'vigilante' ) ),
1223 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Protect wp-includes', 'vigilante' ), 'label_en' => 'Protect wp-includes', 'keywords' => _x( 'protect wp-includes protection secure lock', 'settings search keywords', 'vigilante' ) ),
1224 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'PHP in Uploads', 'vigilante' ), 'label_en' => 'PHP in Uploads', 'keywords' => _x( 'php in uploads media upload', 'settings search keywords', 'vigilante' ) ),
1225 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Sensitive Files', 'vigilante' ), 'label_en' => 'Sensitive Files', 'keywords' => _x( 'sensitive files private secret file log', 'settings search keywords', 'vigilante' ) ),
1226 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Server Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-server', 'label' => __( 'Limit HTTP Methods', 'vigilante' ), 'label_en' => 'Limit HTTP Methods', 'keywords' => _x( 'limit http methods', 'settings search keywords', 'vigilante' ) ),
1227 // Security Headers
1228 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Frame-Options', 'vigilante' ), 'label_en' => 'X-Frame-Options', 'keywords' => _x( 'x-frame-options headers', 'settings search keywords', 'vigilante' ) ),
1229 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'X-Content-Type-Options', 'vigilante' ), 'label_en' => 'X-Content-Type-Options', 'keywords' => _x( 'x-content-type-options content headers', 'settings search keywords', 'vigilante' ) ),
1230 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Referrer-Policy', 'vigilante' ), 'label_en' => 'Referrer-Policy', 'keywords' => _x( 'referrer-policy headers', 'settings search keywords', 'vigilante' ) ),
1231 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'HSTS', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'HSTS', 'vigilante' ), 'label_en' => 'HSTS', 'keywords' => _x( 'hsts strict transport security ssl tls https headers', 'settings search keywords', 'vigilante' ) ),
1232 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Content Security Policy', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Content Security Policy', 'vigilante' ), 'label_en' => 'Content Security Policy', 'keywords' => _x( 'content security policy csp xss headers', 'settings search keywords', 'vigilante' ) ),
1233 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Server Signature', 'vigilante' ), 'label_en' => 'Server Signature', 'keywords' => _x( 'server signature fingerprint banner', 'settings search keywords', 'vigilante' ) ),
1234 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Server Identity', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Remove Fingerprinting Headers', 'vigilante' ), 'label_en' => 'Remove Fingerprinting Headers', 'keywords' => _x( 'remove fingerprinting headers fingerprint banner header http', 'settings search keywords', 'vigilante' ) ),
1235 // Security Headers - Cross-Origin Policies
1236 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Opener-Policy (COOP)', 'keywords' => _x( 'coop cross-origin opener policy popup popups window opener tag assistant google isolation browsing context headers', 'settings search keywords', 'vigilante' ) ),
1237 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Embedder-Policy (COEP)', 'keywords' => _x( 'coep cross-origin embedder policy require-corp credentialless embed embeds iframe fonts headers', 'settings search keywords', 'vigilante' ) ),
1238 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Cross-Origin Policies', 'vigilante' ), 'anchor' => 'vigilante-section-headers-cross-origin', 'label' => __( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ), 'label_en' => 'Cross-Origin-Resource-Policy (CORP)', 'keywords' => _x( 'corp cross-origin resource policy hotlink hotlinking cdn images assets headers', 'settings search keywords', 'vigilante' ) ),
1239 // Login Security
1240 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Custom login URL', 'vigilante' ), 'label_en' => 'Custom login URL', 'keywords' => _x( 'custom login url signin log-in access slug', 'settings search keywords', 'vigilante' ) ),
1241 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Two-Factor Authentication', 'vigilante' ), 'label_en' => 'Two-Factor Authentication', 'keywords' => _x( 'two-factor authentication 2fa mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1242 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( '2FA', 'vigilante' ), 'label_en' => '2FA', 'keywords' => _x( '2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1243 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Failed login attempts', 'vigilante' ), 'label_en' => 'Failed login attempts', 'keywords' => _x( 'failed login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1244 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout', 'vigilante' ), 'label_en' => 'Lockout', 'keywords' => _x( 'lockout lock ban block login', 'settings search keywords', 'vigilante' ) ),
1245 // REST API
1246 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Access Mode', 'vigilante' ), 'label_en' => 'Access Mode', 'keywords' => _x( 'access mode rest api', 'settings search keywords', 'vigilante' ) ),
1247 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Block User Enumeration', 'vigilante' ), 'label_en' => 'Block User Enumeration', 'keywords' => _x( 'block user enumeration blocking blocked deny users account author slug', 'settings search keywords', 'vigilante' ) ),
1248 array( 'tab' => 'rest-api', 'tab_label' => __( 'REST API', 'vigilante' ), 'section' => __( 'REST API Security', 'vigilante' ), 'anchor' => 'vigilante-section-rest-api-main', 'label' => __( 'Disable JSONP', 'vigilante' ), 'label_en' => 'Disable JSONP', 'keywords' => _x( 'disable jsonp', 'settings search keywords', 'vigilante' ) ),
1249 // User Security
1250 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Username protection', 'vigilante' ), 'label_en' => 'Username protection', 'keywords' => _x( 'username protection admin', 'settings search keywords', 'vigilante' ) ),
1251 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password strength', 'vigilante' ), 'label_en' => 'Password strength', 'keywords' => _x( 'password strength passwords credentials', 'settings search keywords', 'vigilante' ) ),
1252 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin monitoring', 'vigilante' ), 'label_en' => 'Admin monitoring', 'keywords' => _x( 'admin monitoring administrator administrators', 'settings search keywords', 'vigilante' ) ),
1253 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Registration approval', 'vigilante' ), 'label_en' => 'Registration approval', 'keywords' => _x( 'registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1254 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Session limits', 'vigilante' ), 'label_en' => 'Session limits', 'keywords' => _x( 'session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1255 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password expiration', 'vigilante' ), 'label_en' => 'Password expiration', 'keywords' => _x( 'password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1256 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Email verification', 'vigilante' ), 'label_en' => 'Email verification', 'keywords' => _x( 'email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1257 // WP Hardening
1258 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database Hardening', 'vigilante' ), 'label_en' => 'Database Hardening', 'keywords' => _x( 'database hardening db mysql tables', 'settings search keywords', 'vigilante' ) ),
1259 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Database prefix', 'vigilante' ), 'label_en' => 'Database prefix', 'keywords' => _x( 'database prefix db mysql tables table', 'settings search keywords', 'vigilante' ) ),
1260 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable file editing', 'vigilante' ), 'label_en' => 'Disable file editing', 'keywords' => _x( 'disable file editing files editor edit', 'settings search keywords', 'vigilante' ) ),
1261 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable plugin/theme installation', 'vigilante' ), 'label_en' => 'Disable plugin/theme installation', 'keywords' => _x( 'disable plugin theme installation install', 'settings search keywords', 'vigilante' ) ),
1262 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Force SSL admin', 'vigilante' ), 'label_en' => 'Force SSL admin', 'keywords' => _x( 'force ssl admin bruteforce administrator administrators tls https', 'settings search keywords', 'vigilante' ) ),
1263 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'field-disable-wp-cron', 'label' => __( 'Disable WP Cron', 'vigilante' ), 'label_en' => 'Disable WP Cron', 'keywords' => _x( 'disable wp cron scheduled tasks wp-cron', 'settings search keywords', 'vigilante' ) ),
1264 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Comment Security', 'vigilante' ), 'label_en' => 'Comment Security', 'keywords' => _x( 'comment security comments spam honeypot url', 'settings search keywords', 'vigilante' ) ),
1265 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Header Cleanup', 'vigilante' ), 'label_en' => 'Header Cleanup', 'keywords' => _x( 'header cleanup headers http meta generator rsd wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1266 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WordPress version', 'vigilante' ), 'label_en' => 'Remove WordPress version', 'keywords' => _x( 'remove wordpress version generator meta', 'settings search keywords', 'vigilante' ) ),
1267 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'field-remove-wp-version-assets', 'label' => __( 'Remove version from assets', 'vigilante' ), 'label_en' => 'Remove version from assets', 'keywords' => _x( 'remove version from assets', 'settings search keywords', 'vigilante' ) ),
1268 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'Disable XML-RPC', 'vigilante' ), 'label_en' => 'Disable XML-RPC', 'keywords' => _x( 'disable xml-rpc xmlrpc rpc remote jetpack app pingback trackback', 'settings search keywords', 'vigilante' ) ),
1269 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'RSS Feed Settings', 'vigilante' ), 'label_en' => 'RSS Feed Settings', 'keywords' => _x( 'rss feed settings feeds atom', 'settings search keywords', 'vigilante' ) ),
1270 // File Integrity
1271 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'File Integrity Monitoring', 'vigilante' ), 'label_en' => 'File Integrity Monitoring', 'keywords' => _x( 'file integrity monitoring files checksum checksums tamper', 'settings search keywords', 'vigilante' ) ),
1272 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan schedule', 'vigilante' ), 'label_en' => 'Scan schedule', 'keywords' => _x( 'scan schedule scans scanning check cron', 'settings search keywords', 'vigilante' ) ),
1273 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Instant alert', 'vigilante' ), 'label_en' => 'Instant alert', 'keywords' => _x( 'instant alert alerts notification warning email', 'settings search keywords', 'vigilante' ) ),
1274 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'Ignored Files', 'vigilante' ), 'anchor' => 'vigilante-section-fi-ignored', 'label' => __( 'Ignored Files', 'vigilante' ), 'label_en' => 'Ignored Files', 'keywords' => _x( 'ignored files file exclude', 'settings search keywords', 'vigilante' ) ),
1275 // Security Audit
1276 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Retention', 'vigilante' ), 'label_en' => 'Retention', 'keywords' => _x( 'retention keep days storage log', 'settings search keywords', 'vigilante' ) ),
1277 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Events to Log', 'vigilante' ), 'label_en' => 'Events to Log', 'keywords' => _x( 'events to log', 'settings search keywords', 'vigilante' ) ),
1278 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Option Tracking', 'vigilante' ), 'label_en' => 'Option Tracking', 'keywords' => _x( 'option tracking', 'settings search keywords', 'vigilante' ) ),
1279 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Security Audit Settings', 'vigilante' ), 'anchor' => 'vigilante-section-audit-settings', 'label' => __( 'Exclusions', 'vigilante' ), 'label_en' => 'Exclusions', 'keywords' => _x( 'exclusions roles ip', 'settings search keywords', 'vigilante' ) ),
1280 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Audit Alerts', 'vigilante' ), 'label_en' => 'Audit Alerts', 'keywords' => _x( 'audit alerts email mail warning critical', 'settings search keywords', 'vigilante' ) ),
1281 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-immediate', 'label' => __( 'Immediate alerts', 'vigilante' ), 'label_en' => 'Immediate alerts', 'keywords' => _x( 'immediate alerts email mail critical warning', 'settings search keywords', 'vigilante' ) ),
1282 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'field-audit-alerts-threshold', 'label' => __( 'Threshold alerts', 'vigilante' ), 'label_en' => 'Threshold alerts', 'keywords' => _x( 'threshold alerts email mail login', 'settings search keywords', 'vigilante' ) ),
1283 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Recent Activity', 'vigilante' ), 'anchor' => 'vigilante-section-audit-recent', 'label' => __( 'Recent Activity', 'vigilante' ), 'label_en' => 'Recent Activity', 'keywords' => _x( 'recent activity log', 'settings search keywords', 'vigilante' ) ),
1284 // Settings & Tools
1285 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Notification settings', 'vigilante' ), 'label_en' => 'Notification settings', 'keywords' => _x( 'notification settings email', 'settings search keywords', 'vigilante' ) ),
1286 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Additional Recipients', 'vigilante' ), 'label_en' => 'Additional Recipients', 'keywords' => _x( 'additional recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1287 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Export Settings', 'vigilante' ), 'label_en' => 'Export Settings', 'keywords' => _x( 'export settings json', 'settings search keywords', 'vigilante' ) ),
1288 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Import Settings', 'vigilante' ), 'label_en' => 'Import Settings', 'keywords' => _x( 'import settings json', 'settings search keywords', 'vigilante' ) ),
1289 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Reset to Defaults', 'vigilante' ), 'label_en' => 'Reset to Defaults', 'keywords' => _x( 'reset to defaults', 'settings search keywords', 'vigilante' ) ),
1290 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Create Backup', 'vigilante' ), 'label_en' => 'Create Backup', 'keywords' => _x( 'create backup', 'settings search keywords', 'vigilante' ) ),
1291 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Tools', 'vigilante' ), 'anchor' => 'vigilante-section-tools-main', 'label' => __( 'Database Backup', 'vigilante' ), 'label_en' => 'Database Backup', 'keywords' => _x( 'database backup db mysql tables', 'settings search keywords', 'vigilante' ) ),
1292 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1293 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1294 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1295 // que anadirla tambien aqui.
1296 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'WordPress Admin Email', 'vigilante' ), 'label_en' => 'WordPress Admin Email', 'keywords' => _x( 'wordpress admin email administrator administrators mail notification notify', 'settings search keywords', 'vigilante' ) ),
1297 array( 'tab' => 'tools', 'tab_label' => __( 'Settings & Tools', 'vigilante' ), 'section' => __( 'Notification settings', 'vigilante' ), 'anchor' => 'vigilante-section-tools-notifications', 'label' => __( 'Plugin Deactivation', 'vigilante' ), 'label_en' => 'Plugin Deactivation', 'keywords' => _x( 'plugin deactivation', 'settings search keywords', 'vigilante' ) ),
1298 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Bad Query Strings', 'vigilante' ), 'label_en' => 'Block Bad Query Strings', 'keywords' => _x( 'block bad query strings blocking blocked deny malicious harmful', 'settings search keywords', 'vigilante' ) ),
1299 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'SQL Injection Protection', 'vigilante' ), 'label_en' => 'SQL Injection Protection', 'keywords' => _x( 'sql injection protection', 'settings search keywords', 'vigilante' ) ),
1300 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'XSS Protection', 'vigilante' ), 'label_en' => 'XSS Protection', 'keywords' => _x( 'xss protection', 'settings search keywords', 'vigilante' ) ),
1301 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'File Inclusion Protection', 'vigilante' ), 'label_en' => 'File Inclusion Protection', 'keywords' => _x( 'file inclusion protection files', 'settings search keywords', 'vigilante' ) ),
1302 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Directory Traversal Protection', 'vigilante' ), 'label_en' => 'Directory Traversal Protection', 'keywords' => _x( 'directory traversal protection folder folders', 'settings search keywords', 'vigilante' ) ),
1303 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Enable Rate Limiting', 'vigilante' ), 'label_en' => 'Enable Rate Limiting', 'keywords' => _x( 'enable rate limiting throttle flood burst limit limits', 'settings search keywords', 'vigilante' ) ),
1304 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Requests per Minute', 'vigilante' ), 'label_en' => 'Requests per Minute', 'keywords' => _x( 'requests per minute request traffic', 'settings search keywords', 'vigilante' ) ),
1305 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Block Duration (seconds)', 'vigilante' ), 'label_en' => 'Block Duration (seconds)', 'keywords' => _x( 'block duration seconds blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1306 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Progressive Blocking', 'vigilante' ), 'label_en' => 'Progressive Blocking', 'keywords' => _x( 'progressive blocking', 'settings search keywords', 'vigilante' ) ),
1307 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Maximum Block Duration', 'vigilante' ), 'label_en' => 'Maximum Block Duration', 'keywords' => _x( 'maximum block duration blocking blocked deny', 'settings search keywords', 'vigilante' ) ),
1308 array( 'tab' => 'firewall', 'tab_label' => __( 'Firewall', 'vigilante' ), 'section' => __( 'Firewall Protection', 'vigilante' ), 'anchor' => 'vigilante-section-firewall-main', 'label' => __( 'Visitor IP detection', 'vigilante' ), 'label_en' => 'Visitor IP detection', 'keywords' => _x( 'visitor ip detection ips address addresses cidr ipv4 ipv6', 'settings search keywords', 'vigilante' ) ),
1309 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Max Login Attempts', 'vigilante' ), 'label_en' => 'Max Login Attempts', 'keywords' => _x( 'max login attempts signin log-in access tries retries', 'settings search keywords', 'vigilante' ) ),
1310 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Lockout Duration', 'vigilante' ), 'label_en' => 'Lockout Duration', 'keywords' => _x( 'lockout duration lock ban block', 'settings search keywords', 'vigilante' ) ),
1311 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Progressive Lockout', 'vigilante' ), 'label_en' => 'Progressive Lockout', 'keywords' => _x( 'progressive lockout lock ban block', 'settings search keywords', 'vigilante' ) ),
1312 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Hide Login Errors', 'vigilante' ), 'label_en' => 'Hide Login Errors', 'keywords' => _x( 'hide login errors signin log-in access error debug log', 'settings search keywords', 'vigilante' ) ),
1313 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Disable Application Passwords', 'vigilante' ), 'label_en' => 'Disable Application Passwords', 'keywords' => _x( 'disable application passwords password credentials', 'settings search keywords', 'vigilante' ) ),
1314 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Login URL Slug', 'vigilante' ), 'label_en' => 'Login URL Slug', 'keywords' => _x( 'login url slug signin log-in access path', 'settings search keywords', 'vigilante' ) ),
1315 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify users', 'vigilante' ), 'label_en' => 'Notify users', 'keywords' => _x( 'notify users notification alert email user accounts', 'settings search keywords', 'vigilante' ) ),
1316 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Lockout', 'vigilante' ), 'label_en' => 'Notify on Lockout', 'keywords' => _x( 'notify on lockout notification alert email lock ban block', 'settings search keywords', 'vigilante' ) ),
1317 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on Admin Login', 'vigilante' ), 'label_en' => 'Notify on Admin Login', 'keywords' => _x( 'notify on admin login notification alert email administrator administrators signin log-in access', 'settings search keywords', 'vigilante' ) ),
1318 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Current settings', 'vigilante' ), 'label_en' => 'Current settings', 'keywords' => _x( 'current settings', 'settings search keywords', 'vigilante' ) ),
1319 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Blocked IPs', 'vigilante' ), 'label_en' => 'Blocked IPs', 'keywords' => _x( 'blocked ips', 'settings search keywords', 'vigilante' ) ),
1320 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enable 2FA', 'vigilante' ), 'label_en' => 'Enable 2FA', 'keywords' => _x( 'enable 2fa two-factor mfa otp totp authenticator', 'settings search keywords', 'vigilante' ) ),
1321 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Verification method', 'vigilante' ), 'label_en' => 'Verification method', 'keywords' => _x( 'verification method verify confirm', 'settings search keywords', 'vigilante' ) ),
1322 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Enforce for roles', 'vigilante' ), 'label_en' => 'Enforce for roles', 'keywords' => _x( 'enforce for roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1323 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1324 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Remember device', 'vigilante' ), 'label_en' => 'Remember device', 'keywords' => _x( 'remember device', 'settings search keywords', 'vigilante' ) ),
1325 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Grace period', 'vigilante' ), 'label_en' => 'Grace period', 'keywords' => _x( 'grace period', 'settings search keywords', 'vigilante' ) ),
1326 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Email sender name', 'vigilante' ), 'label_en' => 'Email sender name', 'keywords' => _x( 'email sender name mail notification notify names', 'settings search keywords', 'vigilante' ) ),
1327 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Reset user TOTP', 'vigilante' ), 'label_en' => 'Reset user TOTP', 'keywords' => _x( 'reset user totp users account 2fa authenticator app', 'settings search keywords', 'vigilante' ) ),
1328 array( 'tab' => 'login', 'tab_label' => __( 'Login Security', 'vigilante' ), 'section' => __( 'Login Protection Status', 'vigilante' ), 'anchor' => 'vigilante-section-login-main', 'label' => __( 'Notify on enable', 'vigilante' ), 'label_en' => 'Notify on enable', 'keywords' => _x( 'notify on enable notification alert email', 'settings search keywords', 'vigilante' ) ),
1329 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable CSP', 'vigilante' ), 'label_en' => 'Enable CSP', 'keywords' => _x( 'enable csp content security policy', 'settings search keywords', 'vigilante' ) ),
1330 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Report Only Mode', 'vigilante' ), 'label_en' => 'Report Only Mode', 'keywords' => _x( 'report only mode', 'settings search keywords', 'vigilante' ) ),
1331 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Redirect HTTP to HTTPS', 'vigilante' ), 'label_en' => 'Redirect HTTP to HTTPS', 'keywords' => _x( 'redirect http to https redirection forward ssl tls secure', 'settings search keywords', 'vigilante' ) ),
1332 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Fix Mixed Content', 'vigilante' ), 'label_en' => 'Fix Mixed Content', 'keywords' => _x( 'fix mixed content insecure http', 'settings search keywords', 'vigilante' ) ),
1333 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'field-upgrade-insecure-requests', 'label' => __( 'Upgrade Insecure Requests', 'vigilante' ), 'label_en' => 'Upgrade Insecure Requests', 'keywords' => _x( 'upgrade insecure requests mixed content csp https external resources', 'settings search keywords', 'vigilante' ) ),
1334 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Rewrite Site Address on Activation', 'vigilante' ), 'label_en' => 'Rewrite Site Address on Activation', 'keywords' => _x( 'rewrite site address on activation', 'settings search keywords', 'vigilante' ) ),
1335 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Enable HSTS', 'vigilante' ), 'label_en' => 'Enable HSTS', 'keywords' => _x( 'enable hsts strict transport security', 'settings search keywords', 'vigilante' ) ),
1336 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Max Age', 'vigilante' ), 'label_en' => 'Max Age', 'keywords' => _x( 'max age', 'settings search keywords', 'vigilante' ) ),
1337 array( 'tab' => 'headers', 'tab_label' => __( 'Security Headers', 'vigilante' ), 'section' => __( 'Security Headers', 'vigilante' ), 'anchor' => 'vigilante-section-headers-main', 'label' => __( 'Include Subdomains', 'vigilante' ), 'label_en' => 'Include Subdomains', 'keywords' => _x( 'include subdomains', 'settings search keywords', 'vigilante' ) ),
1338 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Insecure Usernames', 'vigilante' ), 'label_en' => 'Block Insecure Usernames', 'keywords' => _x( 'block insecure usernames blocking blocked deny weak unsafe', 'settings search keywords', 'vigilante' ) ),
1339 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Enforce Strong Passwords', 'vigilante' ), 'label_en' => 'Enforce Strong Passwords', 'keywords' => _x( 'enforce strong passwords complexity password credentials', 'settings search keywords', 'vigilante' ) ),
1340 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Minimum Password Length', 'vigilante' ), 'label_en' => 'Minimum Password Length', 'keywords' => _x( 'minimum password length passwords credentials characters', 'settings search keywords', 'vigilante' ) ),
1341 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Password Requirements', 'vigilante' ), 'label_en' => 'Password Requirements', 'keywords' => _x( 'password requirements passwords credentials', 'settings search keywords', 'vigilante' ) ),
1342 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Apply Password Rules To', 'vigilante' ), 'label_en' => 'Apply Password Rules To', 'keywords' => _x( 'apply password rules to passwords credentials', 'settings search keywords', 'vigilante' ) ),
1343 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Block Author Scanning', 'vigilante' ), 'label_en' => 'Block Author Scanning', 'keywords' => _x( 'block author scanning blocking blocked deny authors enumeration probing', 'settings search keywords', 'vigilante' ) ),
1344 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Username & password protection', 'vigilante' ), 'anchor' => 'vigilante-section-users-password', 'label' => __( 'Display Name Protection', 'vigilante' ), 'label_en' => 'Display Name Protection', 'keywords' => _x( 'display name protection public visible names', 'settings search keywords', 'vigilante' ) ),
1345 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'New Administrator Alert', 'vigilante' ), 'label_en' => 'New Administrator Alert', 'keywords' => _x( 'new administrator alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1346 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Email Change Alert', 'vigilante' ), 'label_en' => 'Admin Email Change Alert', 'keywords' => _x( 'admin email change alert administrator administrators mail notification notify alerts warning', 'settings search keywords', 'vigilante' ) ),
1347 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Permission Elevation Alert', 'vigilante' ), 'label_en' => 'Permission Elevation Alert', 'keywords' => _x( 'permission elevation alert alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1348 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Admin monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-users-admin-monitoring', 'label' => __( 'Admin Password Change Alert', 'vigilante' ), 'label_en' => 'Admin Password Change Alert', 'keywords' => _x( 'admin password change alert administrator administrators passwords credentials alerts notification warning', 'settings search keywords', 'vigilante' ) ),
1349 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Enable Registration Approval', 'vigilante' ), 'label_en' => 'Enable Registration Approval', 'keywords' => _x( 'enable registration approval signup register approve moderate', 'settings search keywords', 'vigilante' ) ),
1350 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Notify Admin', 'vigilante' ), 'label_en' => 'Notify Admin', 'keywords' => _x( 'notify admin notification alert email administrator administrators', 'settings search keywords', 'vigilante' ) ),
1351 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Registration approval', 'vigilante' ), 'anchor' => 'vigilante-section-users-registration', 'label' => __( 'Auto-reject After', 'vigilante' ), 'label_en' => 'Auto-reject After', 'keywords' => _x( 'auto-reject after', 'settings search keywords', 'vigilante' ) ),
1352 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Enable Session Limits', 'vigilante' ), 'label_en' => 'Enable Session Limits', 'keywords' => _x( 'enable session limits sessions concurrent', 'settings search keywords', 'vigilante' ) ),
1353 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Maximum Sessions', 'vigilante' ), 'label_en' => 'Maximum Sessions', 'keywords' => _x( 'maximum sessions session concurrent', 'settings search keywords', 'vigilante' ) ),
1354 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'When Limit Exceeded', 'vigilante' ), 'label_en' => 'When Limit Exceeded', 'keywords' => _x( 'when limit exceeded', 'settings search keywords', 'vigilante' ) ),
1355 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Session limits', 'vigilante' ), 'anchor' => 'vigilante-section-users-sessions', 'label' => __( 'Exclude Administrators', 'vigilante' ), 'label_en' => 'Exclude Administrators', 'keywords' => _x( 'exclude administrators', 'settings search keywords', 'vigilante' ) ),
1356 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Enable Password Expiration', 'vigilante' ), 'label_en' => 'Enable Password Expiration', 'keywords' => _x( 'enable password expiration passwords credentials expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1357 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Expire After', 'vigilante' ), 'label_en' => 'Expire After', 'keywords' => _x( 'expire after', 'settings search keywords', 'vigilante' ) ),
1358 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Warning Period', 'vigilante' ), 'label_en' => 'Warning Period', 'keywords' => _x( 'warning period', 'settings search keywords', 'vigilante' ) ),
1359 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Password History', 'vigilante' ), 'label_en' => 'Password History', 'keywords' => _x( 'password history passwords credentials reuse previous', 'settings search keywords', 'vigilante' ) ),
1360 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Email Reminder', 'vigilante' ), 'label_en' => 'Email Reminder', 'keywords' => _x( 'email reminder mail notification notify', 'settings search keywords', 'vigilante' ) ),
1361 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Affected Roles', 'vigilante' ), 'label_en' => 'Affected Roles', 'keywords' => _x( 'affected roles role capabilities', 'settings search keywords', 'vigilante' ) ),
1362 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Password expiration', 'vigilante' ), 'anchor' => 'vigilante-section-users-password-exp', 'label' => __( 'Exclude specific users', 'vigilante' ), 'label_en' => 'Exclude specific users', 'keywords' => _x( 'exclude specific users user accounts', 'settings search keywords', 'vigilante' ) ),
1363 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Enable Email Verification', 'vigilante' ), 'label_en' => 'Enable Email Verification', 'keywords' => _x( 'enable email verification mail notification notify verify confirm', 'settings search keywords', 'vigilante' ) ),
1364 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Link Expiration', 'vigilante' ), 'label_en' => 'Link Expiration', 'keywords' => _x( 'link expiration expiry expire caducity', 'settings search keywords', 'vigilante' ) ),
1365 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Allow Resend', 'vigilante' ), 'label_en' => 'Allow Resend', 'keywords' => _x( 'allow resend', 'settings search keywords', 'vigilante' ) ),
1366 array( 'tab' => 'users', 'tab_label' => __( 'User Security', 'vigilante' ), 'section' => __( 'Email verification', 'vigilante' ), 'anchor' => 'vigilante-section-users-email-verify', 'label' => __( 'Auto-delete Unverified', 'vigilante' ), 'label_en' => 'Auto-delete Unverified', 'keywords' => _x( 'auto-delete unverified', 'settings search keywords', 'vigilante' ) ),
1367 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'Current prefix', 'vigilante' ), 'label_en' => 'Current prefix', 'keywords' => _x( 'current prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1368 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Database Hardening', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-database', 'label' => __( 'New prefix', 'vigilante' ), 'label_en' => 'New prefix', 'keywords' => _x( 'new prefix database db table tables mysql', 'settings search keywords', 'vigilante' ) ),
1369 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Editor', 'vigilante' ), 'label_en' => 'Disable File Editor', 'keywords' => _x( 'disable file editor files edit editing', 'settings search keywords', 'vigilante' ) ),
1370 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Disable File Modifications', 'vigilante' ), 'label_en' => 'Disable File Modifications', 'keywords' => _x( 'disable file modifications files modify install update', 'settings search keywords', 'vigilante' ) ),
1371 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'wp-config.php Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-wpconfig', 'label' => __( 'Hide PHP errors from visitors', 'vigilante' ), 'label_en' => 'Hide PHP errors from visitors', 'keywords' => _x( 'hide php errors from visitors error debug log', 'settings search keywords', 'vigilante' ) ),
1372 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'XML-RPC', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-xmlrpc', 'label' => __( 'XML-RPC access', 'vigilante' ), 'label_en' => 'XML-RPC access', 'keywords' => _x( 'xml-rpc access xmlrpc rpc remote jetpack app', 'settings search keywords', 'vigilante' ) ),
1373 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Pingbacks', 'vigilante' ), 'label_en' => 'Disable Pingbacks', 'keywords' => _x( 'disable pingbacks pingback ping', 'settings search keywords', 'vigilante' ) ),
1374 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Disable Trackbacks', 'vigilante' ), 'label_en' => 'Disable Trackbacks', 'keywords' => _x( 'disable trackbacks trackback ping', 'settings search keywords', 'vigilante' ) ),
1375 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Require Moderation', 'vigilante' ), 'label_en' => 'Require Moderation', 'keywords' => _x( 'require moderation moderate approve', 'settings search keywords', 'vigilante' ) ),
1376 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Close Old Comments', 'vigilante' ), 'label_en' => 'Close Old Comments', 'keywords' => _x( 'close old comments comment discussion', 'settings search keywords', 'vigilante' ) ),
1377 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Comment Security', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-comments', 'label' => __( 'Honeypot Protection', 'vigilante' ), 'label_en' => 'Honeypot Protection', 'keywords' => _x( 'honeypot protection spam bots trap', 'settings search keywords', 'vigilante' ) ),
1378 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Generator', 'vigilante' ), 'label_en' => 'Remove Generator', 'keywords' => _x( 'remove generator version meta', 'settings search keywords', 'vigilante' ) ),
1379 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove RSD Link', 'vigilante' ), 'label_en' => 'Remove RSD Link', 'keywords' => _x( 'remove rsd link discovery', 'settings search keywords', 'vigilante' ) ),
1380 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove WLW Manifest', 'vigilante' ), 'label_en' => 'Remove WLW Manifest', 'keywords' => _x( 'remove wlw manifest wlwmanifest', 'settings search keywords', 'vigilante' ) ),
1381 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove Shortlink', 'vigilante' ), 'label_en' => 'Remove Shortlink', 'keywords' => _x( 'remove shortlink link', 'settings search keywords', 'vigilante' ) ),
1382 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'Header Cleanup', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-headers', 'label' => __( 'Remove REST API Link', 'vigilante' ), 'label_en' => 'Remove REST API Link', 'keywords' => _x( 'remove rest api link json endpoint', 'settings search keywords', 'vigilante' ) ),
1383 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable Feeds', 'vigilante' ), 'label_en' => 'Disable Feeds', 'keywords' => _x( 'disable feeds feed rss atom syndication', 'settings search keywords', 'vigilante' ) ),
1384 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Disable If No Content', 'vigilante' ), 'label_en' => 'Disable If No Content', 'keywords' => _x( 'disable if no content', 'settings search keywords', 'vigilante' ) ),
1385 array( 'tab' => 'wp-hardening', 'tab_label' => __( 'WP Hardening', 'vigilante' ), 'section' => __( 'RSS Feed Settings', 'vigilante' ), 'anchor' => 'vigilante-section-hardening-rss', 'label' => __( 'Remove Feed Version', 'vigilante' ), 'label_en' => 'Remove Feed Version', 'keywords' => _x( 'remove feed version feeds rss atom', 'settings search keywords', 'vigilante' ) ),
1386 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Alert on severity', 'vigilante' ), 'label_en' => 'Alert on severity', 'keywords' => _x( 'alert on severity alerts notification warning level critical', 'settings search keywords', 'vigilante' ) ),
1387 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Time window', 'vigilante' ), 'label_en' => 'Time window', 'keywords' => _x( 'time window', 'settings search keywords', 'vigilante' ) ),
1388 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Thresholds per category', 'vigilante' ), 'label_en' => 'Thresholds per category', 'keywords' => _x( 'thresholds per category threshold limit', 'settings search keywords', 'vigilante' ) ),
1389 array( 'tab' => 'activity-log', 'tab_label' => __( 'Security Audit', 'vigilante' ), 'section' => __( 'Audit Alerts', 'vigilante' ), 'anchor' => 'vigilante-section-audit-alerts', 'label' => __( 'Recipients', 'vigilante' ), 'label_en' => 'Recipients', 'keywords' => _x( 'recipients email recipient', 'settings search keywords', 'vigilante' ) ),
1390 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Automatic Scans', 'vigilante' ), 'label_en' => 'Automatic Scans', 'keywords' => _x( 'automatic scans scan scanning', 'settings search keywords', 'vigilante' ) ),
1391 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Frequency', 'vigilante' ), 'label_en' => 'Scan Frequency', 'keywords' => _x( 'scan frequency scans scanning check', 'settings search keywords', 'vigilante' ) ),
1392 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Email Notifications', 'vigilante' ), 'label_en' => 'Email Notifications', 'keywords' => _x( 'email notifications mail notification notify', 'settings search keywords', 'vigilante' ) ),
1393 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Test email', 'vigilante' ), 'label_en' => 'Test email', 'keywords' => _x( 'test email mail notification notify', 'settings search keywords', 'vigilante' ) ),
1394 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Scan Scope', 'vigilante' ), 'label_en' => 'Scan Scope', 'keywords' => _x( 'scan scope scans scanning check', 'settings search keywords', 'vigilante' ) ),
1395 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Paths', 'vigilante' ), 'label_en' => 'Excluded Paths', 'keywords' => _x( 'excluded paths exclude exclusions ignore ignored path folder folders', 'settings search keywords', 'vigilante' ) ),
1396 array( 'tab' => 'file-integrity', 'tab_label' => __( 'File Integrity', 'vigilante' ), 'section' => __( 'File Integrity Monitoring', 'vigilante' ), 'anchor' => 'vigilante-section-fi-monitoring', 'label' => __( 'Excluded Extensions', 'vigilante' ), 'label_en' => 'Excluded Extensions', 'keywords' => _x( 'excluded extensions exclude exclusions ignore ignored extension filetype', 'settings search keywords', 'vigilante' ) ),
1397 );
1398 }
1399
1400 /**
1401 * Enqueue admin assets
1402 *
1403 * @param string $hook Current admin page.
1404 */
1405 public function enqueue_assets( $hook ) {
1406 // toplevel_page_vigilante for top-level menu page
1407 if ( 'toplevel_page_vigilante' !== $hook ) {
1408 return;
1409 }
1410
1411 wp_enqueue_style(
1412 'vigilante-admin',
1413 VIGILANTE_ASSETS_URL . 'css/admin.css',
1414 array(),
1415 VIGILANTE_VERSION
1416 );
1417
1418 wp_enqueue_script(
1419 'vigilante-admin',
1420 VIGILANTE_ASSETS_URL . 'js/admin.js',
1421 array( 'jquery' ),
1422 VIGILANTE_VERSION,
1423 true
1424 );
1425
1426 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1427 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1428 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1429 'currentUserId' => get_current_user_id(),
1430 'logoutUrl' => wp_logout_url( wp_login_url() ),
1431 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1432 'searchIndex' => $this->get_search_index(),
1433 'underAttack' => array(
1434 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1435 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1436 ),
1437 'strings' => array(
1438 'saving' => __( 'Saving...', 'vigilante' ),
1439 'sendingTest' => __( 'Sending...', 'vigilante' ),
1440 'saved' => __( 'Settings saved', 'vigilante' ),
1441 'error' => __( 'Error saving settings', 'vigilante' ),
1442 'confirm' => __( 'Are you sure?', 'vigilante' ),
1443 'scanning' => __( 'Scanning...', 'vigilante' ),
1444 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1445 'loading' => __( 'Loading...', 'vigilante' ),
1446 'searching' => __( 'Searching...', 'vigilante' ),
1447 'noUsersFound' => __( 'No users found', 'vigilante' ),
1448 'searchError' => __( 'Error searching users', 'vigilante' ),
1449 'sending' => __( 'Sending...', 'vigilante' ),
1450 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1451 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1452 'skipped' => __( 'skipped', 'vigilante' ),
1453 'failed' => __( 'failed', 'vigilante' ),
1454 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1455 // Header tester strings
1456 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1457 'testing' => __( 'Testing...', 'vigilante' ),
1458 'score' => __( 'Score', 'vigilante' ),
1459 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1460 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1461 'warnings' => __( 'Warnings', 'vigilante' ),
1462 // File integrity scan results strings
1463 'scanResults' => __( 'Scan Results', 'vigilante' ),
1464 'ok' => __( 'OK', 'vigilante' ),
1465 'modified' => __( 'Modified', 'vigilante' ),
1466 'suspicious' => __( 'Suspicious', 'vigilante' ),
1467 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1468 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1469 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1470 'file' => __( 'File', 'vigilante' ),
1471 'reason' => __( 'Reason', 'vigilante' ),
1472 'type' => __( 'Type', 'vigilante' ),
1473 'unknown' => __( 'Unknown', 'vigilante' ),
1474 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1475 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1476 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1477 'extra' => __( 'Extra', 'vigilante' ),
1478 'ignored' => __( 'Ignored', 'vigilante' ),
1479 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1480 'actions' => __( 'Actions', 'vigilante' ),
1481 'ignore' => __( 'Ignore', 'vigilante' ),
1482 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1483 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1484 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1485 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1486 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1487 'selectAll' => __( 'Select all', 'vigilante' ),
1488 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1489 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1490 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1491 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1492 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1493 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1494 /* translators: %d: number of files selected for bulk action. */
1495 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1496 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1497 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1498 'criticalConfigDesc' => __( 'These files are common targets for code injection. Review the changes and approve if they are legitimate. Vigilant\'s own blocks are excluded from this check.', 'vigilante' ),
1499 'approve' => __( 'Approve', 'vigilante' ),
1500 'approving' => __( 'Approving...', 'vigilante' ),
1501 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1502 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1503 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1504 'changes' => __( 'Changes', 'vigilante' ),
1505 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1506 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1507 'diffLines' => __( 'lines', 'vigilante' ),
1508 // Under Attack mode strings
1509 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1510 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1511 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1512 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1513 // Database backup strings
1514 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1515 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1516 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1517 // Firewall unblock
1518 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1519 // Database prefix strings
1520 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1521 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1522 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1523 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1524 /* translators: 1: Hours, 2: Minutes */
1525 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1526 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1527 'standardLabel' => __( 'Standard', 'vigilante' ),
1528 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1529 'deactivate' => __( 'Deactivate', 'vigilante' ),
1530 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1531 // Settings strings
1532 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1533 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1534 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1535 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1536 /* translators: 1: tests passed, 2: total tests in this category */
1537 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1538 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1539 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1540 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1541 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1542 /* translators: %s: preset name */
1543 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1544 // Scan strings
1545 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1546 /* translators: %s: error message */
1547 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1548 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1549 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1550 'clearing' => __( 'Clearing...', 'vigilante' ),
1551 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1552 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1553 /* translators: %s: error message */
1554 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1555 // Activity log popup strings
1556 'logRequest' => __( 'Request', 'vigilante' ),
1557 'logDate' => __( 'Date', 'vigilante' ),
1558 'logMethod' => __( 'Method', 'vigilante' ),
1559 'logType' => __( 'Type', 'vigilante' ),
1560 'logAction' => __( 'Action', 'vigilante' ),
1561 'logSeverity' => __( 'Severity', 'vigilante' ),
1562 'logMessage' => __( 'Message', 'vigilante' ),
1563 'logClient' => __( 'Client', 'vigilante' ),
1564 'logUser' => __( 'User', 'vigilante' ),
1565 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1566 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1567 'logIpLabel' => __( 'IP:', 'vigilante' ),
1568 'logUaLabel' => __( 'UA:', 'vigilante' ),
1569 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1570 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1571 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1572 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1573 'logAdded' => __( 'Added!', 'vigilante' ),
1574 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1575 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1576 // Activity log table strings
1577 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1578 'view' => __( 'View', 'vigilante' ),
1579 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1580 // Export logs strings
1581 'exporting' => __( 'Exporting...', 'vigilante' ),
1582 /* translators: %d: number of entries */
1583 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1584 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1585 'exportFailed' => __( 'Export failed', 'vigilante' ),
1586 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1587 // Backup strings
1588 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1589 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1590 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1591 /* translators: %d: number of tables */
1592 'tablesCount' => __( '%d tables', 'vigilante' ),
1593 /* translators: 1: table count, 2: human-readable size */
1594 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1595 /* translators: 1: selected count, 2: human-readable size */
1596 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1597 // Settings search strings
1598 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1599 /* translators: %d: number of results that did not fit in the list. */
1600 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1601 'searchInTab' => __( 'in', 'vigilante' ),
1602 // Modules string
1603 /* translators: 1: enabled count, 2: total count */
1604 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1605 // Activity log label maps for JS rendering
1606 'eventTypeLabels' => array(
1607 'login' => __( 'Login', 'vigilante' ),
1608 'user' => __( 'User', 'vigilante' ),
1609 'content' => __( 'Content', 'vigilante' ),
1610 'plugin' => __( 'Plugin', 'vigilante' ),
1611 'theme' => __( 'Theme', 'vigilante' ),
1612 'settings' => __( 'Settings', 'vigilante' ),
1613 'comment' => __( 'Comment', 'vigilante' ),
1614 'media' => __( 'Media', 'vigilante' ),
1615 'firewall' => __( 'Firewall', 'vigilante' ),
1616 'file' => __( 'File', 'vigilante' ),
1617 'security' => __( 'Security', 'vigilante' ),
1618 'system' => __( 'System', 'vigilante' ),
1619 ),
1620 'severityLabels' => array(
1621 'info' => __( 'Info', 'vigilante' ),
1622 'warning' => __( 'Warning', 'vigilante' ),
1623 'critical' => __( 'Critical', 'vigilante' ),
1624 ),
1625 // Password reset strings
1626 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1627 /* translators: %d: number of users */
1628 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1629 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1630 'processing' => __( 'Processing...', 'vigilante' ),
1631 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1632 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1633 'confirmForceResetAll' => __( 'This will force ALL users to reset their password. All users will receive a password reset email. Are you sure you want to continue?', 'vigilante' ),
1634 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1635 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1636 // Role-based password reset strings
1637 /* translators: %d: number of users */
1638 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1639 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1640 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1641 // User approval strings
1642 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1643 'approve' => __( 'Approve', 'vigilante' ),
1644 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1645 'reject' => __( 'Reject', 'vigilante' ),
1646 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1647 // Session management strings
1648 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1649 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1650 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1651 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1652 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1653 'noSessions' => __( 'No active sessions', 'vigilante' ),
1654 'revoke' => __( 'Revoke', 'vigilante' ),
1655 'noUsers' => __( 'No users found', 'vigilante' ),
1656 // Time ago strings
1657 'timeYear' => __( 'year', 'vigilante' ),
1658 'timeYears' => __( 'years', 'vigilante' ),
1659 'timeMonth' => __( 'month', 'vigilante' ),
1660 'timeMonths' => __( 'months', 'vigilante' ),
1661 'timeDay' => __( 'day', 'vigilante' ),
1662 'timeDays' => __( 'days', 'vigilante' ),
1663 'timeHour' => __( 'hour', 'vigilante' ),
1664 'timeHours' => __( 'hours', 'vigilante' ),
1665 'timeMinute' => __( 'minute', 'vigilante' ),
1666 'timeMinutes' => __( 'minutes', 'vigilante' ),
1667 /* translators: %1$d: count, %2$s: time unit */
1668 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1669 'justNow' => __( 'Just now', 'vigilante' ),
1670 // Pagination strings
1671 /* translators: 1: first item number, 2: last item number, 3: total items */
1672 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1673 'paginationEmpty' => __( '0 items', 'vigilante' ),
1674 // Security Analyzer strings
1675 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1676 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1677 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1678 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1679 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1680 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1681 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1682 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1683 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1684 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1685 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1686 'analyzerAgo' => __( 'ago', 'vigilante' ),
1687 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1688 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1689 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1690 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1691 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1692 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1693 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1694 'analyzerPts' => __( 'pts', 'vigilante' ),
1695 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1696 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1697 /* translators: %d: number of findings in an info-only category */
1698 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1699 ),
1700 ) );
1701
1702 // 2FA Admin assets
1703 wp_enqueue_style(
1704 'vigilante-2fa-admin',
1705 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1706 array( 'vigilante-admin' ),
1707 VIGILANTE_VERSION
1708 );
1709
1710 wp_enqueue_script(
1711 'vigilante-2fa-admin',
1712 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1713 array( 'jquery', 'vigilante-admin' ),
1714 VIGILANTE_VERSION,
1715 true
1716 );
1717 }
1718
1719 /**
1720 * Show admin notices
1721 */
1722 public function show_admin_notices() {
1723 // Activation notice
1724 if ( get_transient( 'vigilante_activated' ) ) {
1725 ?>
1726 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1727 <p>
1728 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1729 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1730 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1731 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1732 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1733 </a>
1734 </p>
1735 </div>
1736 <?php
1737 delete_transient( 'vigilante_activated' );
1738 }
1739
1740 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1741 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1742 if ( ! empty( $ua_status['active'] ) ) {
1743 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1744 if ( $ua_remaining > 0 ) {
1745 $ua_hours = floor( $ua_remaining / 3600 );
1746 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1747 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1748 ?>
1749 <div class="notice notice-warning vigilante-ua-notice">
1750 <p>
1751 <span class="dashicons dashicons-shield"></span>
1752 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1753 &mdash;
1754 <?php
1755 printf(
1756 /* translators: 1: Hours, 2: Minutes */
1757 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1758 absint( $ua_hours ),
1759 absint( $ua_mins )
1760 );
1761 ?>
1762 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1763 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1764 </a>
1765 </p>
1766 <p>
1767 <em><?php esc_html_e( 'Vigilant has applied the Maximum preset plus extra hardening on top of your previous configuration. Any changes you make to Vigilant settings while this mode is active will be reverted when it ends.', 'vigilante' ); ?></em>
1768 </p>
1769 </div>
1770 <?php
1771 }
1772 }
1773
1774 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1775 // arrive with a forwarded-for header carrying a different valid IP, the
1776 // site is very likely behind a proxy/CDN that has not been declared, so
1777 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1778 //
1779 // Two deliberate silencers (2.9.2):
1780 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1781 // the machine itself: that only happens in local development stacks
1782 // (Local's nginx router, Docker...), never behind a production
1783 // proxy/CDN, so the notice would be pure noise there.
1784 // - The notice is dismissible and the dismissal persists site-wide via
1785 // the vigilante_dismissed_notices option (the admin evaluated it and
1786 // decided; nagging forever helps nobody).
1787 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1788 if (
1789 current_user_can( 'manage_options' )
1790 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1791 && ! isset( $dismissed_notices['proxy_detection'] )
1792 ) {
1793 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1794 $detected = '';
1795 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1796 if ( empty( $_SERVER[ $server_key ] ) ) {
1797 continue;
1798 }
1799 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1800 if ( false !== strpos( $candidate, ',' ) ) {
1801 $parts = explode( ',', $candidate );
1802 $candidate = trim( $parts[0] );
1803 }
1804 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1805 continue;
1806 }
1807 // Loopback forwarded IP = local development, not a real proxy.
1808 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1809 continue;
1810 }
1811 $detected = $proxy_label;
1812 break;
1813 }
1814
1815 if ( '' !== $detected ) {
1816 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1817 $detail_message = sprintf(
1818 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1819 esc_html__( 'Requests are arriving with a %s header, but visitor IP detection is set to direct connection. The firewall is reading the proxy address instead of the real visitor IP, which affects the IP lists and rate limiting.', 'vigilante' ),
1820 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1821 );
1822 ?>
1823 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1824 <p>
1825 <span class="dashicons dashicons-shield"></span>
1826 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1827 </p>
1828 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1829 <p>
1830 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1831 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1832 </a>
1833 </p>
1834 </div>
1835 <script>
1836 jQuery( function ( $ ) {
1837 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1838 $.post( ajaxurl, {
1839 action: 'vigilante_dismiss_notice',
1840 notice_id: 'proxy_detection',
1841 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1842 } );
1843 } );
1844 } );
1845 </script>
1846 <?php
1847 }
1848 }
1849 }
1850
1851 /**
1852 * Render settings page
1853 */
1854 public function render_settings_page() {
1855 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1856 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1857
1858 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1859 $this->current_tab = 'dashboard';
1860 }
1861 ?>
1862 <div class="wrap vigilante-admin-wrap">
1863 <div class="vigilante-header-row">
1864 <h1 class="vigilante-page-title">
1865 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1866 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1867 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1868 </h1>
1869 <div class="vigilante-search-wrapper">
1870 <div class="vigilante-search-input-wrap">
1871 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1872 <input type="search" id="vigilante-settings-search" class="vigilante-settings-search" aria-label="<?php esc_attr_e( 'Search settings', 'vigilante' ); ?>" placeholder="<?php esc_attr_e( 'Search settings…', 'vigilante' ); ?>" autocomplete="off">
1873 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1874 </div>
1875 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1876 </div>
1877 </div>
1878
1879 <?php $this->render_tabs(); ?>
1880
1881 <div class="vigilante-content">
1882 <div class="vigilante-main">
1883 <?php $this->render_tab_content(); ?>
1884 </div>
1885 <div class="vigilante-sidebar">
1886 <?php $this->render_sidebar(); ?>
1887 </div>
1888 </div>
1889 </div>
1890 <?php
1891 }
1892
1893 /**
1894 * Render tabs navigation
1895 */
1896 private function render_tabs() {
1897 $options = $this->settings->get_all_options();
1898
1899 // Map tabs to modules
1900 $tab_to_module = array(
1901 'firewall' => 'firewall',
1902 'headers' => 'security_headers',
1903 'login' => 'login_security',
1904 'rest-api' => 'rest_api_security',
1905 'users' => 'user_security',
1906 'wp-hardening' => 'wp_hardening',
1907 'file-integrity' => 'file_integrity',
1908 'activity-log' => 'activity_log',
1909 );
1910 ?>
1911 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1912 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1913 $is_disabled = false;
1914 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1915 if ( $module && empty( $options['modules'][ $module ] ) ) {
1916 $is_disabled = true;
1917 }
1918 ?>
1919 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1920 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1921 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1922 <?php echo esc_html( $tab_name ); ?>
1923 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1924 </a>
1925 <?php endforeach; ?>
1926 </nav>
1927 <?php
1928 }
1929
1930 /**
1931 * Render current tab content
1932 */
1933 private function render_tab_content() {
1934 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1935
1936 if ( method_exists( $this, $method ) ) {
1937 $this->$method();
1938 } else {
1939 $this->render_tab_coming_soon();
1940 }
1941 }
1942
1943 /**
1944 * Render coming soon placeholder
1945 */
1946 private function render_tab_coming_soon() {
1947 ?>
1948 <div class="vigilante-settings-section">
1949 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
1950 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
1951 </div>
1952 <?php
1953 }
1954
1955 /**
1956 * Values to display for a section that this site does not control
1957 *
1958 * On a subsite the stored options are its own copy, which nothing acts on:
1959 * wp-config.php and .htaccess are written from the main site. Painting the
1960 * local copy describes a configuration that is not running, so a subsite
1961 * admin sees a box ticked here and the constant absent from the file, or the
1962 * other way round. Read the main site's values instead, which are the ones in
1963 * force, and fall back to the local ones if they cannot be read.
1964 *
1965 * @since 2.9.8
1966 *
1967 * @param string $section Settings section.
1968 * @return array
1969 */
1970 private function get_section_for_display( $section ) {
1971 $local = $this->settings->get_section( $section );
1972
1973 if ( ! $this->shared_files_locked() ) {
1974 return $local;
1975 }
1976
1977 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
1978 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
1979
1980 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
1981 return $local;
1982 }
1983
1984 return wp_parse_args( $main[ $section ], $local );
1985 }
1986
1987 /**
1988 * Whether the sections that write wp-config.php and .htaccess are read-only here
1989 *
1990 * True on a network when this is not the main site, or the user is not a
1991 * network administrator. See Vigilante_Settings::can_write_shared_files().
1992 *
1993 * @since 2.9.8
1994 *
1995 * @return bool
1996 */
1997 private function shared_files_locked() {
1998 return ! Vigilante_Settings::can_write_shared_files();
1999 }
2000
2001 /**
2002 * Print the shared-files notice for a section that cannot be edited here
2003 *
2004 * @since 2.9.8
2005 */
2006 private function render_shared_files_notice() {
2007 if ( ! $this->shared_files_locked() ) {
2008 return;
2009 }
2010 ?>
2011 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2012 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2013 </div>
2014 <?php
2015 }
2016
2017 /**
2018 * Check if module is disabled and render warning
2019 *
2020 * @param string $module_key Module key.
2021 * @return bool True if disabled.
2022 */
2023 private function render_module_disabled_notice( $module_key ) {
2024 if ( $this->settings->is_module_enabled( $module_key ) ) {
2025 return false;
2026 }
2027
2028 $module_labels = $this->settings->get_module_labels();
2029 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2030 ?>
2031 <div class="notice notice-warning vigilante-module-disabled-notice">
2032 <p>
2033 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2034 <?php
2035 printf(
2036 /* translators: %s: Module name */
2037 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2038 esc_html( $module_name )
2039 );
2040 ?>
2041 </p>
2042 <p>
2043 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2044 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2045 </a>
2046 </p>
2047 </div>
2048 <?php
2049 return true;
2050 }
2051
2052 /**
2053 * Render the Security Analyzer (Security Check) widget + expandable full report.
2054 *
2055 * Lives in the Dashboard tab between the Configuration Score status card and
2056 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2057 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2058 *
2059 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2060 * @param array $history Score history (oldest first).
2061 * @param array $categories_def Category metadata (slug => label/max).
2062 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2063 */
2064 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2065 $has_data = ! empty( $last_scan['ran_at'] );
2066 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2067 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2068 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2069 $ran_at_human = $has_data
2070 ? sprintf(
2071 /* translators: %s: relative time like "2 hours" */
2072 __( 'Last scan %s ago', 'vigilante' ),
2073 human_time_diff( (int) $last_scan['ran_at'], time() )
2074 )
2075 : __( 'Never scanned', 'vigilante' );
2076 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2077 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2078 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2079
2080 $quality = self::analyzer_quality_tag( $score );
2081 ?>
2082 <div class="vigilante-analyzer" id="vigilante-analyzer"
2083 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2084 <div class="vigilante-analyzer-header">
2085 <div class="vigilante-analyzer-title">
2086 <h2>
2087 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2088 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2089 </h2>
2090 <p class="description">
2091 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2092 </p>
2093 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2094 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2095 <?php echo esc_html( $ran_at_human ); ?>
2096 </p>
2097 </div>
2098 <div class="vigilante-analyzer-actions">
2099 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2100 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2101 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2102 </button>
2103 </div>
2104 </div>
2105
2106 <div class="vigilante-analyzer-summary">
2107 <div class="vigilante-analyzer-score-card">
2108 <?php if ( $has_data && $grade ) : ?>
2109 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2110 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2111 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2112 </div>
2113 <?php else : ?>
2114 <div class="vigilante-score-circle vigilante-grade-empty">
2115 <span class="vigilante-grade">—</span>
2116 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2117 </div>
2118 <?php endif; ?>
2119 <div class="vigilante-analyzer-score-meta">
2120 <p class="vigilante-analyzer-score-label">
2121 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2122 </p>
2123 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2124 data-role="quality-tag">
2125 <?php echo esc_html( $quality['label'] ); ?>
2126 </span>
2127 </div>
2128 </div>
2129
2130 <div class="vigilante-analyzer-counts">
2131 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2132 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2133 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2134 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2135 </span>
2136 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2137 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2138 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2139 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2140 </span>
2141 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2142 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2143 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2144 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2145 </span>
2146 </div>
2147
2148 <?php
2149 // Sparkline of recent scores. Require at least 3 data points so the trend
2150 // is meaningful (2 points is just a line between dots, no real trend).
2151 $hist_points = array();
2152 foreach ( $history as $h ) {
2153 $hist_points[] = (int) $h['score'];
2154 }
2155 $hist_count = count( $hist_points );
2156 if ( $hist_count >= 3 ) :
2157 $current_score = (int) end( $hist_points );
2158 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2159 $delta = $current_score - $previous_score;
2160 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2161 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2162 if ( 0 === $delta ) {
2163 $delta_text = __( 'No change', 'vigilante' );
2164 } else {
2165 $delta_text = sprintf(
2166 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2167 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2168 ( $delta > 0 ? '+' : '' ) . (int) $delta
2169 );
2170 }
2171 ?>
2172 <div class="vigilante-analyzer-sparkline-wrap">
2173 <div class="vigilante-analyzer-sparkline-head">
2174 <span class="vigilante-analyzer-sparkline-label">
2175 <?php
2176 echo esc_html( sprintf(
2177 /* translators: %d: number of scans */
2178 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2179 $hist_count
2180 ) );
2181 ?>
2182 </span>
2183 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2184 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2185 <?php echo esc_html( $delta_text ); ?>
2186 </span>
2187 </div>
2188 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2189 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2190 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2191 </div>
2192 </div>
2193 <?php elseif ( $has_data ) : ?>
2194 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2195 <span class="vigilante-analyzer-sparkline-label">
2196 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2197 </span>
2198 <p class="vigilante-analyzer-sparkline-hint">
2199 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2200 <?php
2201 $needed = 3 - $hist_count;
2202 echo esc_html( sprintf(
2203 /* translators: %d: number of additional scans needed */
2204 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2205 $needed
2206 ) );
2207 ?>
2208 </p>
2209 </div>
2210 <?php endif; ?>
2211 </div>
2212
2213 <div class="vigilante-analyzer-toggle-row">
2214 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2215 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2216 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2217 </button>
2218 </div>
2219
2220 <div class="vigilante-analyzer-details" hidden>
2221 <div class="vigilante-analyzer-categories" data-role="categories">
2222 <?php foreach ( $categories_def as $slug => $meta ) :
2223 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2224 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2225 // Always use the declared meta as the source of truth for the maximum.
2226 // The cached scan may carry an old max if a check was added/removed
2227 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2228 // but cached scans still reported max=22 until reset).
2229 $cat_max = (int) $meta['max'];
2230 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2231 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2232 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2233 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2234 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2235 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2236 ?>
2237 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2238 data-category="<?php echo esc_attr( $slug ); ?>"
2239 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2240 <summary class="vigilante-analyzer-category-summary">
2241 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2242 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2243 <?php if ( $info_only ) : ?>
2244 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2245 data-role="category-quality"
2246 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2247 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2248 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2249 </span>
2250 <?php else :
2251 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2252 $scored_total = $passed_count
2253 + (int) ( $cat_counts['warn'] ?? 0 )
2254 + (int) ( $cat_counts['fail'] ?? 0 );
2255 ?>
2256 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2257 data-role="category-quality">
2258 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2259 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2260 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2261 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2262 data-total="<?php echo esc_attr( $scored_total ); ?>">
2263 <?php
2264 echo esc_html( sprintf(
2265 /* translators: 1: tests passed, 2: total tests in this category */
2266 __( '%1$d/%2$d tests', 'vigilante' ),
2267 $passed_count,
2268 $scored_total
2269 ) );
2270 ?>
2271 </span>
2272 </span>
2273 <?php endif; ?>
2274 <?php if ( $info_only ) : ?>
2275 <span class="vigilante-analyzer-category-states" data-role="category-states">
2276 <?php if ( $info_count > 0 ) : ?>
2277 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2278 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2279 </span>
2280 <?php endif; ?>
2281 </span>
2282 <?php endif; ?>
2283 <?php if ( ! $info_only ) : ?>
2284 <span class="vigilante-analyzer-category-score">
2285 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2286 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2287 </span>
2288 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2289 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2290 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2291 data-role="category-bar"></span>
2292 </span>
2293 <?php else :
2294 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2295 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2296 $info_issues = $info_warn + $info_fail;
2297 if ( $info_issues > 0 ) : ?>
2298 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2299 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2300 <?php
2301 echo esc_html( sprintf(
2302 /* translators: %d: number of findings */
2303 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2304 $info_issues
2305 ) );
2306 ?>
2307 </span>
2308 <?php else : ?>
2309 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2310 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2311 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2312 </span>
2313 <?php endif; ?>
2314 <?php endif; ?>
2315 </summary>
2316 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2317 <?php if ( empty( $checks ) ) : ?>
2318 <li class="vigilante-analyzer-check-empty">
2319 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2320 </li>
2321 <?php else : ?>
2322 <?php foreach ( $checks as $c ) : ?>
2323 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2324 <?php endforeach; ?>
2325 <?php endif; ?>
2326 </ul>
2327 </details>
2328 <?php endforeach; ?>
2329 </div>
2330
2331 <div class="vigilante-analyzer-weekly">
2332 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2333 <p class="description">
2334 <?php esc_html_e( 'Vigilante runs this check once a week in the background. Enable email alerts to be notified if the score drops by 10 points or more, or if a new critical check starts failing.', 'vigilante' ); ?>
2335 </p>
2336 <label class="vigilante-analyzer-toggle-option">
2337 <input type="checkbox"
2338 name="security_analyzer[weekly_scan_enabled]"
2339 value="1"
2340 <?php checked( $weekly_enabled ); ?>>
2341 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2342 </label>
2343 <label class="vigilante-analyzer-toggle-option">
2344 <input type="checkbox"
2345 name="security_analyzer[email_on_regression]"
2346 value="1"
2347 <?php checked( $email_enabled ); ?>>
2348 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2349 </label>
2350 </div>
2351 </div>
2352 </div>
2353 <?php
2354 }
2355
2356 /**
2357 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2358 * Dashboard grade palette (a/b/c/d/e).
2359 *
2360 * @param int $pct 0..100.
2361 * @return array{label:string,slug:string}
2362 */
2363 public static function analyzer_quality_tag( $pct ) {
2364 $pct = max( 0, min( 100, (int) $pct ) );
2365 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2366 if ( 100 === $pct ) {
2367 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2368 }
2369 if ( $pct >= 70 ) {
2370 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2371 }
2372 if ( $pct >= 50 ) {
2373 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2374 }
2375 if ( $pct >= 30 ) {
2376 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2377 }
2378 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2379 }
2380
2381 /**
2382 * Render a single analyzer check row (used both server-side and via JS template).
2383 *
2384 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2385 * @return string HTML (escaped).
2386 */
2387 private static function render_analyzer_check_row( $check ) {
2388 $id = isset( $check['id'] ) ? $check['id'] : '';
2389 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2390 $label = isset( $check['label'] ) ? $check['label'] : '';
2391 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2392 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2393 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2394 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2395
2396 $icons = array(
2397 'pass' => 'yes-alt',
2398 'warn' => 'warning',
2399 'fail' => 'dismiss',
2400 'info' => 'info',
2401 'skip' => 'minus',
2402 );
2403 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2404
2405 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2406 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2407 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2408 $html .= '<div class="vigilante-analyzer-check-body">';
2409 $html .= '<div class="vigilante-analyzer-check-label">';
2410 $html .= '<span>' . esc_html( $label ) . '</span>';
2411 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2412 $html .= '<span class="vigilante-analyzer-check-score">'
2413 . esc_html( $score . '/' . $max )
2414 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2415 . '</span>';
2416 }
2417 $html .= '</div>';
2418 if ( $detail ) {
2419 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2420 }
2421 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2422 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2423 . esc_html__( 'Go to setting', 'vigilante' )
2424 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2425 } elseif ( $fix_link && 'info' === $state ) {
2426 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2427 $is_external = 0 === strpos( $fix_link, 'http' );
2428 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2429 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2430 . esc_html__( 'Learn more', 'vigilante' )
2431 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2432 }
2433 $html .= '</div>';
2434 $html .= '</li>';
2435 return $html;
2436 }
2437
2438 /**
2439 * Build a minimal SVG sparkline for the score history.
2440 *
2441 * @param int[] $points Score values (0..100), oldest to newest.
2442 * @return string SVG markup.
2443 */
2444 private static function sparkline_svg( $points ) {
2445 $points = array_map( 'intval', (array) $points );
2446 $count = count( $points );
2447 if ( $count < 2 ) {
2448 return '';
2449 }
2450 $width = 280;
2451 $height = 60;
2452 $padding = 4;
2453
2454 $usable_w = $width - ( $padding * 2 );
2455 $usable_h = $height - ( $padding * 2 );
2456
2457 $step = $usable_w / max( 1, $count - 1 );
2458 $max = 100; // Fixed scale — scores are 0..100.
2459
2460 $coords = array();
2461 foreach ( $points as $i => $v ) {
2462 $x = $padding + ( $i * $step );
2463 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2464 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2465 }
2466 $path = 'M ' . implode( ' L ', $coords );
2467 $last = end( $points );
2468 $last_x = $padding + ( ( $count - 1 ) * $step );
2469 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2470
2471 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2472 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2473 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2474 $svg .= '</svg>';
2475 return $svg;
2476 }
2477
2478 /**
2479 * Render dashboard tab
2480 */
2481 private function render_tab_dashboard() {
2482 $options = $this->settings->get_all_options();
2483 $module_labels = $this->settings->get_module_labels();
2484 $module_descriptions = $this->settings->get_module_descriptions();
2485 $presets = $this->settings->get_presets();
2486 $active_preset = get_option( 'vigilante_active_preset', '' );
2487
2488 // Calculate security score with more factors
2489 $security_score = $this->calculate_security_score( $options );
2490
2491 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2492 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2493 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2494 }
2495 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2496 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2497 $analyzer_history = $analyzer_instance->get_score_history();
2498 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2499 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2500 ?>
2501 <div class="vigilante-dashboard">
2502 <div class="vigilante-status-card">
2503 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2504 <p class="vigilante-score-kind description">
2505 <?php esc_html_e( 'How well Vigilante is configured right now. Pair it with the Security Check below to see the real-world result.', 'vigilante' ); ?>
2506 </p>
2507 <div class="vigilante-security-score">
2508 <?php
2509 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2510 if ( $security_score >= 90 ) {
2511 $grade = 'A';
2512 } elseif ( $security_score >= 70 ) {
2513 $grade = 'B';
2514 } elseif ( $security_score >= 50 ) {
2515 $grade = 'C';
2516 } elseif ( $security_score >= 30 ) {
2517 $grade = 'D';
2518 } else {
2519 $grade = 'E';
2520 }
2521 ?>
2522 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2523 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2524 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2525 </div>
2526 <div class="vigilante-config-status">
2527 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2528 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2529 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2530 </span>
2531 <?php else : ?>
2532 <span class="vigilante-preset-badge vigilante-preset-custom">
2533 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2534 </span>
2535 <?php endif; ?>
2536 </div>
2537 </div>
2538
2539 <?php
2540 $recommendations = $this->get_security_recommendations( $options );
2541 if ( ! empty( $recommendations ) ) :
2542 ?>
2543 <div class="vigilante-recommendations">
2544 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2545 <ul class="vigilante-recommendations-grid">
2546 <?php foreach ( $recommendations as $rec ) : ?>
2547 <li>
2548 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2549 <?php echo esc_html( $rec['message'] ); ?>
2550 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2551 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $rec['tab'] ) ); ?>" class="vigilante-rec-link" title="<?php esc_attr_e( 'Go to settings', 'vigilante' ); ?>"><span class="dashicons dashicons-arrow-right-alt2"></span></a>
2552 <?php endif; ?>
2553 </li>
2554 <?php endforeach; ?>
2555 </ul>
2556 </div>
2557 <?php endif; ?>
2558 </div>
2559
2560 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2561
2562 <div class="vigilante-modules-grid">
2563 <h2><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2564 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2565 <div class="vigilante-modules-list">
2566 <?php foreach ( $options['modules'] as $module => $enabled ) :
2567 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2568 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2569 ?>
2570 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2571 <div class="vigilante-module-header">
2572 <span class="vigilante-module-status"></span>
2573 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2574 <label class="vigilante-toggle">
2575 <?php
2576 /* translators: %s: Security module name, for example Firewall. */
2577 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2578 ?>
2579 <input type="checkbox"
2580 name="modules[<?php echo esc_attr( $module ); ?>]"
2581 value="1"
2582 <?php checked( $enabled ); ?>
2583 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2584 data-module="<?php echo esc_attr( $module ); ?>">
2585 <span class="vigilante-toggle-slider"></span>
2586 </label>
2587 </div>
2588 <?php if ( $description ) : ?>
2589 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2590 <?php endif; ?>
2591 </div>
2592 <?php endforeach; ?>
2593 </div>
2594 </div>
2595
2596 <div class="vigilante-presets-card">
2597 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2598 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2599 <div class="vigilante-presets-grid">
2600 <?php foreach ( $presets as $preset_id => $preset ) :
2601 $is_active = ( $active_preset === $preset_id );
2602 ?>
2603 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2604 <?php if ( $is_active ) : ?>
2605 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2606 <?php endif; ?>
2607 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2608 <p><?php echo esc_html( $preset['description'] ); ?></p>
2609 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2610 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2611 </button>
2612 </div>
2613 <?php endforeach; ?>
2614
2615 <?php
2616 // Under Attack mode card
2617 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2618 $ua_active = $under_attack->is_active();
2619 $ua_remaining = $under_attack->get_remaining_time();
2620 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2621 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2622 ?>
2623 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2624 <h3>
2625 <span class="dashicons dashicons-shield"></span>
2626 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2627 </h3>
2628 <p><?php esc_html_e( 'Emergency mode. JavaScript challenge for all visitors, aggressive rate limiting, and restricted access. Auto-deactivates after 4 hours.', 'vigilante' ); ?></p>
2629 <?php if ( $ua_active ) : ?>
2630 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2631 <span class="dashicons dashicons-clock"></span>
2632 <span class="vigilante-ua-time">
2633 <?php
2634 printf(
2635 /* translators: 1: Hours, 2: Minutes */
2636 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2637 absint( $ua_remaining_hours ),
2638 absint( $ua_remaining_mins )
2639 );
2640 ?>
2641 </span>
2642 </div>
2643 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2644 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2645 </button>
2646 <?php else : ?>
2647 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2648 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2649 </button>
2650 <?php endif; ?>
2651 </div>
2652 </div>
2653 </div>
2654 </div>
2655 <?php
2656 }
2657
2658 /**
2659 * Render tools tab
2660 */
2661 private function render_tab_tools() {
2662 // Get current settings for notification summary
2663 $email_options = $this->settings->get_section( 'email' );
2664 $login_options = $this->settings->get_section( 'login_security' );
2665 $user_options = $this->settings->get_section( 'user_security' );
2666 $fi_options = $this->settings->get_section( 'file_integrity' );
2667 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2668 $monitoring = $user_options['admin_monitoring'] ?? array();
2669 $registration = $user_options['registration_approval'] ?? array();
2670 $current_admin = get_option( 'admin_email' );
2671 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2672 $additional_raw = $email_options['additional_recipients'] ?? array();
2673 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2674 ?>
2675
2676 <!-- Notification Settings -->
2677 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2678 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2679 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2680
2681 <div class="vigilante-notification-layout">
2682
2683 <!-- Left column: Recipients settings -->
2684 <div class="vigilante-notification-settings">
2685 <form class="vigilante-settings-form" data-section="email">
2686
2687 <table class="form-table vigilante-compact-form">
2688 <tr>
2689 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2690 <td>
2691 <label>
2692 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2693 <?php
2694 printf(
2695 /* translators: %s: Admin email address */
2696 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2697 '<code>' . esc_html( $current_admin ) . '</code>'
2698 );
2699 ?>
2700 </label>
2701 </td>
2702 </tr>
2703 <tr>
2704 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2705 <td>
2706 <textarea id="vigilante-f-email-additional-recipients" name="email[additional_recipients]" rows="3" class="large-text code" placeholder="maintenance@example.com&#10;security@example.com"><?php echo esc_textarea( $additional ); ?></textarea>
2707 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2708 </td>
2709 </tr>
2710 <tr>
2711 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2712 <td>
2713 <label>
2714 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2715 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2716 </label>
2717 </td>
2718 </tr>
2719 </table>
2720
2721 <p class="submit vigilante-notification-submit">
2722 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2723 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2724 </button>
2725 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2726 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2727 </button>
2728 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2729 </p>
2730 <p class="description"><?php esc_html_e( 'The test goes to the recipients above and confirms that email delivery works for every Vigilant notification.', 'vigilante' ); ?></p>
2731
2732 </form>
2733 </div>
2734
2735 <!-- Right column: Active notifications summary -->
2736 <div class="vigilante-notification-summary">
2737 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2738
2739 <table class="widefat striped">
2740 <thead>
2741 <tr>
2742 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2743 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2744 <th style="width: 50px; text-align: center;"></th>
2745 </tr>
2746 </thead>
2747 <tbody>
2748 <?php
2749 $notifications = array(
2750 array(
2751 'label' => __( 'Login lockout', 'vigilante' ),
2752 'active' => ! empty( $login_options['notify_on_lockout'] ),
2753 'tab' => 'login',
2754 ),
2755 array(
2756 'label' => __( 'Administrator login', 'vigilante' ),
2757 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2758 'tab' => 'login',
2759 ),
2760 array(
2761 'label' => __( 'New administrator created', 'vigilante' ),
2762 'active' => ! empty( $monitoring['alert_new_admin'] ),
2763 'tab' => 'users',
2764 ),
2765 array(
2766 'label' => __( 'Administrator email changed', 'vigilante' ),
2767 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2768 'tab' => 'users',
2769 ),
2770 array(
2771 'label' => __( 'Permission elevation', 'vigilante' ),
2772 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2773 'tab' => 'users',
2774 ),
2775 array(
2776 'label' => __( 'Admin password changed', 'vigilante' ),
2777 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2778 'tab' => 'users',
2779 ),
2780 array(
2781 'label' => __( 'Registration pending approval', 'vigilante' ),
2782 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2783 'tab' => 'users',
2784 ),
2785 array(
2786 'label' => __( 'File integrity scan report', 'vigilante' ),
2787 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2788 'tab' => 'file-integrity',
2789 ),
2790 array(
2791 'label' => __( 'File integrity instant alert', 'vigilante' ),
2792 'active' => ! empty( $fi_options['instant_alert'] ),
2793 'tab' => 'file-integrity',
2794 ),
2795 array(
2796 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2797 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2798 'tab' => 'activity-log',
2799 'anchor' => 'vigilante-section-audit-alerts',
2800 ),
2801 array(
2802 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2803 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2804 'tab' => 'activity-log',
2805 'anchor' => 'vigilante-section-audit-alerts',
2806 ),
2807 array(
2808 'label' => __( 'Under Attack mode', 'vigilante' ),
2809 'active' => true,
2810 'tab' => '',
2811 'note' => __( 'Always active', 'vigilante' ),
2812 ),
2813 array(
2814 'label' => __( 'Plugin deactivation', 'vigilante' ),
2815 'active' => ! empty( $email_options['send_deactivation_email'] ),
2816 'tab' => 'tools',
2817 ),
2818 );
2819
2820 foreach ( $notifications as $notif ) :
2821 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2822 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2823 if ( ! empty( $notif['note'] ) ) {
2824 $status_label = $notif['note'];
2825 }
2826 ?>
2827 <tr>
2828 <td><?php echo esc_html( $notif['label'] ); ?></td>
2829 <td style="text-align: center; white-space: nowrap;">
2830 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2831 </td>
2832 <td style="text-align: center;">
2833 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2834 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2835 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2836 </a>
2837 <?php else : ?>
2838 &mdash;
2839 <?php endif; ?>
2840 </td>
2841 </tr>
2842 <?php endforeach; ?>
2843 </tbody>
2844 </table>
2845 </div>
2846
2847 </div>
2848 </div>
2849
2850 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2851
2852 <?php
2853 // Warn that during Under Attack mode the export/import operate against
2854 // the temporary hardened config and any imported changes will be
2855 // reverted when the mode ends.
2856 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2857 if ( ! empty( $ua_status['active'] ) ) :
2858 ?>
2859 <div class="vigilante-ua-tools-notice-wrap">
2860 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2861 <p>
2862 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2863 <?php esc_html_e( 'Exports will reflect the temporary hardened configuration, not your saved one. Imports will apply on top of the hardened config and will be reverted when the mode ends. Consider waiting until you deactivate Under Attack before exporting or importing settings.', 'vigilante' ); ?>
2864 </p>
2865 </div>
2866 </div>
2867 <?php
2868 endif;
2869 ?>
2870
2871 <div class="vigilante-tools-grid">
2872 <div class="vigilante-tool-card">
2873 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2874 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2875 <button type="button" class="button vigilante-export-settings">
2876 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2877 </button>
2878 </div>
2879
2880 <div class="vigilante-tool-card">
2881 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
2882 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
2883 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
2884 <button type="button" class="button vigilante-import-settings">
2885 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
2886 </button>
2887 </div>
2888
2889 <div class="vigilante-tool-card">
2890 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
2891 <p><?php esc_html_e( 'Reset all the Vigilant security settings to default values. Your IP lists, custom login address, two-factor setup, scan exclusions and extra alert recipients are kept.', 'vigilante' ); ?></p>
2892 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
2893 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
2894 </button>
2895 </div>
2896
2897 <div class="vigilante-tool-card">
2898 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
2899 <p><?php esc_html_e( 'Download a ZIP backup of your wp-config.php and .htaccess (plus robots.txt if present) before making security changes. The archive is built on the fly and sent to your browser, so nothing is left on the server.', 'vigilante' ); ?></p>
2900 <?php if ( $this->shared_files_locked() ) : ?>
2901 <p class="description"><?php esc_html_e( 'Both files belong to the whole network, and wp-config.php carries the database credentials and the authentication salts of every site. The copy is taken from the main site.', 'vigilante' ); ?></p>
2902 <?php else : ?>
2903 <button type="button" class="button vigilante-create-backup">
2904 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
2905 </button>
2906 <?php endif; ?>
2907 </div>
2908
2909 <?php if ( ! $this->shared_files_locked() ) : ?>
2910
2911 <div class="vigilante-tool-card vigilante-tool-card-wide">
2912 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2913 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2914 <button type="button" class="button vigilante-db-backup-toggle">
2915 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
2916 </button>
2917
2918 <div class="vigilante-db-backup-panel" style="display: none;">
2919 <div class="vigilante-db-tables-loading">
2920 <span class="spinner is-active"></span>
2921 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
2922 </div>
2923
2924 <div class="vigilante-db-tables-content" style="display: none;">
2925 <div class="vigilante-db-tables-controls">
2926 <label>
2927 <input type="checkbox" id="vigilante-db-select-all" checked>
2928 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
2929 </label>
2930 <span class="vigilante-db-tables-info"></span>
2931 </div>
2932
2933 <div class="vigilante-db-tables-group">
2934 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
2935 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
2936 </div>
2937
2938 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
2939 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
2940 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
2941 </div>
2942
2943 <div class="vigilante-db-backup-actions">
2944 <button type="button" class="button button-primary vigilante-db-backup-download">
2945 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
2946 </button>
2947 </div>
2948 </div>
2949 </div>
2950 </div>
2951 <?php else : ?>
2952 <div class="vigilante-tool-card vigilante-tool-card-wide">
2953 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2954 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2955 <p class="description"><?php esc_html_e( 'The database is shared by the whole network, so a backup taken here would carry every other site and all of the network users. The copy is taken from the main site.', 'vigilante' ); ?></p>
2956 </div>
2957 <?php endif; ?>
2958 </div>
2959 <?php
2960 }
2961
2962 /**
2963 * Render firewall tab
2964 */
2965 private function render_tab_firewall() {
2966 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
2967 $options = $this->settings->get_section( 'firewall' );
2968 ?>
2969 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
2970 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
2971 <h2>
2972 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
2973 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
2974 </h2>
2975 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
2976 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2977 <p style="margin:0;">
2978 <?php esc_html_e( 'Full page caching systems that serve cached pages before PHP executes (Varnish, LiteSpeed Cache, NGINX FastCGI Cache, Cloudflare APO) may bypass PHP-level firewall rules for cached requests. The .htaccess rules will still apply on Apache/LiteSpeed servers.', 'vigilante' ); ?>
2979 </p>
2980 </div>
2981
2982 <table class="form-table">
2983 <tr>
2984 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
2985 <td>
2986 <label>
2987 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
2988 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
2989 </label>
2990 </td>
2991 </tr>
2992 <tr>
2993 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
2994 <td>
2995 <label>
2996 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
2997 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
2998 </label>
2999 </td>
3000 </tr>
3001 <tr>
3002 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3003 <td>
3004 <label>
3005 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3006 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3007 </label>
3008 </td>
3009 </tr>
3010 <tr>
3011 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3012 <td>
3013 <label>
3014 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3015 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3016 </label>
3017 </td>
3018 </tr>
3019 <tr>
3020 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3021 <td>
3022 <label>
3023 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3024 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3025 </label>
3026 </td>
3027 </tr>
3028 <tr>
3029 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3030 <td>
3031 <label>
3032 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3033 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3034 </label>
3035 </td>
3036 </tr>
3037 </table>
3038
3039 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3040 <table class="form-table">
3041 <tr>
3042 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3043 <td>
3044 <label>
3045 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3046 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3047 </label>
3048 </td>
3049 </tr>
3050 <tr>
3051 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3052 <td>
3053 <input id="vigilante-f-firewall-rate-limiting-requests-per-minute" type="number" name="firewall[rate_limiting][requests_per_minute]" value="<?php echo esc_attr( $options['rate_limiting']['requests_per_minute'] ?? 120 ); ?>" min="10" max="500" class="small-text">
3054 <p class="description">
3055 <?php esc_html_e( 'Counts only PHP requests to WordPress (pages, admin-ajax, REST, login) from a single IP, not static assets like images, CSS or JS. 120/min suits most sites; sustained traffic above that from one IP is usually a bot. To allow a legitimate service, whitelist its IP instead of raising the limit.', 'vigilante' ); ?>
3056 </p>
3057 </td>
3058 </tr>
3059 <tr>
3060 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3061 <td>
3062 <input id="vigilante-f-firewall-rate-limiting-block-duration" type="number" name="firewall[rate_limiting][block_duration]" value="<?php echo esc_attr( $options['rate_limiting']['block_duration'] ?? 300 ); ?>" min="60" max="3600" class="small-text">
3063 </td>
3064 </tr>
3065 <tr>
3066 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3067 <td>
3068 <label>
3069 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3070 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3071 </label>
3072 <p class="description">
3073 <?php
3074 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3075 printf(
3076 /* translators: 1: First block duration, 2: Second, 3: Third */
3077 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3078 esc_html( human_time_diff( 0, $base ) ),
3079 esc_html( human_time_diff( 0, $base * 2 ) ),
3080 esc_html( human_time_diff( 0, $base * 4 ) )
3081 );
3082 ?>
3083 </p>
3084 </td>
3085 </tr>
3086 <tr>
3087 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3088 <td>
3089 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3090 <?php
3091 $max_options = array(
3092 3600 => __( '1 hour', 'vigilante' ),
3093 21600 => __( '6 hours', 'vigilante' ),
3094 43200 => __( '12 hours', 'vigilante' ),
3095 86400 => __( '24 hours', 'vigilante' ),
3096 604800 => __( '7 days', 'vigilante' ),
3097 );
3098 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3099 foreach ( $max_options as $val => $label ) :
3100 ?>
3101 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3102 <?php echo esc_html( $label ); ?>
3103 </option>
3104 <?php endforeach; ?>
3105 </select>
3106 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3107 </td>
3108 </tr>
3109 </table>
3110
3111 <?php
3112 // Currently blocked IPs from rate limiting
3113 $active_blocks = Vigilante_Firewall::get_active_blocks();
3114 if ( ! empty( $active_blocks ) ) :
3115 ?>
3116 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3117 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3118 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3119 <thead>
3120 <tr>
3121 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3122 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3123 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3124 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3125 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3126 </tr>
3127 </thead>
3128 <tbody>
3129 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3130 <tr>
3131 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3132 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3133 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3134 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3135 <td>
3136 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3137 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3138 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3139 </button>
3140 </td>
3141 </tr>
3142 <?php endforeach; ?>
3143 </tbody>
3144 </table>
3145 </div>
3146 <?php endif; ?>
3147
3148 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3149 <p class="description">
3150 <?php
3151 printf(
3152 /* translators: %s: Current visitor IP address */
3153 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3154 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3155 );
3156 ?>
3157 </p>
3158 <table class="form-table">
3159 <tr>
3160 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3161 <td>
3162 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3163 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]">
3164 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3165 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3166 <option value="x-forwarded-for" <?php selected( $proxy_header, 'x-forwarded-for' ); ?>><?php esc_html_e( 'Behind a reverse proxy or load balancer (X-Forwarded-For)', 'vigilante' ); ?></option>
3167 <option value="x-real-ip" <?php selected( $proxy_header, 'x-real-ip' ); ?>><?php esc_html_e( 'Behind an nginx proxy (X-Real-IP)', 'vigilante' ); ?></option>
3168 </select>
3169 <p class="description">
3170 <?php esc_html_e( 'Where to read the visitor IP from. Leave on "Direct connection" unless your site really sits behind that proxy or CDN. Trusting a forwarded header on a site that is not behind it lets visitors spoof their IP and bypass the IP lists and rate limiting.', 'vigilante' ); ?>
3171 </p>
3172 </td>
3173 </tr>
3174 <tr>
3175 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3176 <td>
3177 <textarea id="vigilante-f-firewall-ip-whitelist" name="firewall[ip_whitelist]" rows="4" class="large-text code" placeholder="192.168.1.50&#10;192.168.1.0/24&#10;192.168.1.*"><?php echo esc_textarea( implode( "\n", $options['ip_whitelist'] ?? array() ) ); ?></textarea>
3178 <p class="description">
3179 <?php esc_html_e( 'One IP per line. These IPs bypass the firewall checks, and they also reach wp-admin when the login URL is hidden, so remote managers such as MainWP or ManageWP are not turned away with a 404. The hidden login form itself stays hidden for every IP, this one included.', 'vigilante' ); ?>
3180 <br>
3181 <?php
3182 printf(
3183 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3184 esc_html__( 'Accepts exact IPs (%1$s192.168.1.50%2$s), CIDR ranges (%1$s192.168.1.0/24%2$s, IPv4 and IPv6), and wildcards with %1$s*%2$s (e.g. %1$s192.168.1.*%2$s).', 'vigilante' ),
3185 '<code>',
3186 '</code>'
3187 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3188 ?>
3189 </p>
3190 </td>
3191 </tr>
3192 <tr>
3193 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3194 <td>
3195 <textarea id="vigilante-f-firewall-ip-blacklist" name="firewall[ip_blacklist]" rows="4" class="large-text code" placeholder="203.0.113.42&#10;203.0.113.0/24&#10;203.0.113.*"><?php echo esc_textarea( implode( "\n", $options['ip_blacklist'] ?? array() ) ); ?></textarea>
3196 <p class="description">
3197 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3198 <br>
3199 <?php
3200 printf(
3201 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3202 esc_html__( 'Accepts exact IPs (%1$s203.0.113.42%2$s), CIDR ranges (%1$s203.0.113.0/24%2$s, IPv4 and IPv6), and wildcards with %1$s*%2$s (e.g. %1$s203.0.113.*%2$s).', 'vigilante' ),
3203 '<code>',
3204 '</code>'
3205 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3206 ?>
3207 </p>
3208 </td>
3209 </tr>
3210 </table>
3211
3212 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3213 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3214 <table class="form-table">
3215 <tr>
3216 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3217 <td>
3218 <textarea id="vigilante-f-firewall-ua-whitelist" name="firewall[ua_whitelist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_whitelist'] ?? array() ) ); ?></textarea>
3219 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3220 </td>
3221 </tr>
3222 <tr>
3223 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3224 <td>
3225 <textarea id="vigilante-f-firewall-ua-blacklist" name="firewall[ua_blacklist]" rows="4" class="large-text code"><?php echo esc_textarea( implode( "\n", $options['ua_blacklist'] ?? array() ) ); ?></textarea>
3226 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3227 </td>
3228 </tr>
3229 </table>
3230 </div>
3231
3232 <?php
3233 $vg_shared_locked = $this->shared_files_locked();
3234 // Paint what is actually in force, not this site's unused copy.
3235 $vg_local_options = $options;
3236 $options = $this->get_section_for_display( 'firewall' );
3237 ?>
3238 <?php $this->render_shared_files_notice(); ?>
3239 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3240 <h2>
3241 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3242 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3243 </h2>
3244 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3245
3246 <table class="form-table">
3247 <tr id="field-disable-directory-browsing">
3248 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3249 <td>
3250 <label>
3251 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3252 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3253 </label>
3254 </td>
3255 </tr>
3256 <tr>
3257 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3258 <td>
3259 <label>
3260 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3261 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3262 </label>
3263 </td>
3264 </tr>
3265 <tr id="field-protect-wp-cron">
3266 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3267 <td>
3268 <label>
3269 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3270 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3271 </label>
3272 <p class="description"><?php
3273 printf(
3274 /* translators: 1: opening <strong>, 2: closing </strong> */
3275 esc_html__( '%1$sWarning:%2$s Only enable if your host runs a real server-side cron job calling wp-cron.php (most managed WordPress hosts do; check with your provider). Otherwise scheduled tasks — publishing, updates, emails, backups — stop running. Pair with %3$sDISABLE_WP_CRON%4$s in WP Hardening for full coverage.', 'vigilante' ),
3276 '<strong>',
3277 '</strong>',
3278 '<code>',
3279 '</code>'
3280 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3281 ?></p>
3282 </td>
3283 </tr>
3284 <tr>
3285 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3286 <td>
3287 <label>
3288 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3289 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3290 </label>
3291 </td>
3292 </tr>
3293 <tr>
3294 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3295 <td>
3296 <label>
3297 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3298 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3299 </label>
3300 </td>
3301 </tr>
3302 <tr>
3303 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3304 <td>
3305 <label>
3306 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3307 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3308 </label>
3309 </td>
3310 </tr>
3311 <tr>
3312 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3313 <td>
3314 <label>
3315 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3316 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3317 </label>
3318 </td>
3319 </tr>
3320 </table>
3321 </div>
3322 <?php $options = $vg_local_options; ?>
3323
3324 <p class="submit vigilante-submit-buttons">
3325 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3326 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3327 </button>
3328 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3329 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3330 </button>
3331 </p>
3332 </form>
3333 <?php
3334 }
3335
3336 /**
3337 * Render login security tab
3338 */
3339 private function render_tab_login() {
3340 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3341 $options = $this->settings->get_section( 'login_security' );
3342 $lockouts = $this->database->get_active_lockouts();
3343 ?>
3344 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3345 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3346 <h2>
3347 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3348 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3349 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3350 </h2>
3351 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3352
3353 <table class="form-table">
3354 <tr id="field-max-attempts">
3355 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3356 <td>
3357 <input id="vigilante-f-login-security-max-attempts" type="number" name="login_security[max_attempts]" value="<?php echo esc_attr( $options['max_attempts'] ?? 5 ); ?>" min="1" max="20" class="small-text">
3358 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3359 </td>
3360 </tr>
3361 <tr>
3362 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3363 <td>
3364 <input id="vigilante-f-login-security-lockout-duration" type="number" name="login_security[lockout_duration]" value="<?php echo esc_attr( ( $options['lockout_duration'] ?? 1800 ) / 60 ); ?>" min="1" max="1440" class="small-text">
3365 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3366 </td>
3367 </tr>
3368 <tr>
3369 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3370 <td>
3371 <label>
3372 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3373 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3374 </label>
3375 </td>
3376 </tr>
3377 <tr>
3378 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3379 <td>
3380 <label>
3381 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3382 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3383 </label>
3384 </td>
3385 </tr>
3386 <tr>
3387 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3388 <td>
3389 <label>
3390 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3391 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3392 </label>
3393 </td>
3394 </tr>
3395 </table>
3396
3397 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3398 <table class="form-table">
3399 <tr id="field-custom-login-url">
3400 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3401 <td>
3402 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3403 <input type="text" name="login_security[custom_login_url]" id="vigilante_custom_login_url" value="<?php echo esc_attr( $options['custom_login_url'] ?? '' ); ?>" class="regular-text" placeholder="<?php esc_attr_e( 'my-secret-login', 'vigilante' ); ?>">
3404 <p class="description">
3405 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3406 </p>
3407 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3408 <p class="description">
3409 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3410 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3411 </p>
3412 <p class="description">
3413 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3414 </p>
3415 <p class="description">
3416 <?php esc_html_e( 'An IP in the firewall whitelist is still allowed into wp-admin, so remote managers keep working, but it does not get the login form: the hidden URL is the only way in for everyone.', 'vigilante' ); ?>
3417 </p>
3418 </div>
3419 </td>
3420 </tr>
3421 </table>
3422
3423 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3424 <table class="form-table">
3425 <tr>
3426 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3427 <td>
3428 <label>
3429 <input type="checkbox" name="login_security[notify_on_login_url_change]" id="vigilante_notify_login_url_change" value="1" <?php checked( $options['notify_on_login_url_change'] ?? true ); ?>>
3430 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3431 </label>
3432 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3433 <button type="button" id="vigilante_notify_login_url" class="button">
3434 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3435 </button>
3436 <span class="vigilante-login-url-notify-status"></span>
3437 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3438 </div>
3439 </td>
3440 </tr>
3441 </table>
3442 </div>
3443
3444 <?php $this->render_2fa_settings( $options ); ?>
3445
3446 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3447 <table class="form-table">
3448 <tr>
3449 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3450 <td>
3451 <label>
3452 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3453 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3454 </label>
3455 </td>
3456 </tr>
3457 <tr>
3458 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3459 <td>
3460 <label>
3461 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3462 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3463 </label>
3464 </td>
3465 </tr>
3466 </table>
3467
3468 <p class="description">
3469 <?php
3470 printf(
3471 /* translators: %s: Link to notification settings */
3472 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3473 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3474 );
3475 ?>
3476 </p>
3477 </div>
3478
3479 <p class="submit vigilante-submit-buttons">
3480 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3481 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3482 </button>
3483 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3484 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3485 </button>
3486 </p>
3487 </form>
3488
3489 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3490 <?php
3491 }
3492
3493 /**
3494 * Render lockout information and blocked IPs section
3495 *
3496 * @param array $options Login security options.
3497 * @param array $lockouts Currently locked out IPs.
3498 */
3499 private function render_lockout_info_section( $options, $lockouts ) {
3500 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3501 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3502 $lockout_increment = ! empty( $options['lockout_increment'] );
3503 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3504 $two_factor = $options['two_factor'] ?? array();
3505 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3506 ?>
3507 <div class="vigilante-settings-section vigilante-lockout-section">
3508 <h2><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3509
3510 <table class="form-table">
3511 <tr>
3512 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3513 <td>
3514 <?php
3515 printf(
3516 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3517 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3518 absint( $max_attempts ),
3519 absint( ceil( $lockout_duration / 60 ) )
3520 );
3521
3522 if ( $lockout_increment ) {
3523 echo '<br>';
3524 printf(
3525 /* translators: %d: Maximum lockout duration in hours */
3526 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3527 absint( ceil( $max_lockout / 3600 ) )
3528 );
3529 }
3530
3531 if ( $two_factor_enabled ) {
3532 echo '<br>';
3533 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3534 }
3535 ?>
3536 </td>
3537 </tr>
3538 <tr>
3539 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3540 <td>
3541 <?php if ( ! empty( $lockouts ) ) : ?>
3542 <div class="vigilante-paginated-section">
3543 <div class="vigilante-fi-pagination-wrap"></div>
3544 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3545 <thead>
3546 <tr>
3547 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3548 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3549 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3550 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3551 </tr>
3552 </thead>
3553 <tbody>
3554 <?php foreach ( $lockouts as $lockout ) :
3555 $lockout_time = strtotime( $lockout->locked_until );
3556 $remaining_seconds = $lockout_time - time();
3557 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3558 ?>
3559 <tr>
3560 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3561 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3562 <td>
3563 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3564 <br>
3565 <small class="description">
3566 <?php
3567 printf(
3568 /* translators: %s: Remaining time */
3569 esc_html__( '%s remaining', 'vigilante' ),
3570 esc_html( $remaining_text )
3571 );
3572 ?>
3573 </small>
3574 </td>
3575 <td>
3576 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3577 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3578 </button>
3579 </td>
3580 </tr>
3581 <?php endforeach; ?>
3582 </tbody>
3583 </table>
3584 </div>
3585 <p class="description" style="margin-top: 10px;">
3586 <button type="button" class="button vigilante-clear-all-lockouts">
3587 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3588 </button>
3589 <span style="margin-left: 10px;">
3590 <?php
3591 printf(
3592 /* translators: %d: Number of blocked IPs */
3593 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3594 count( $lockouts )
3595 );
3596 ?>
3597 </span>
3598 </p>
3599 <?php else : ?>
3600 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3601 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3602 <?php endif; ?>
3603 </td>
3604 </tr>
3605 </table>
3606 </div>
3607 <?php
3608 }
3609
3610 /**
3611 * Format remaining lockout time in human readable format
3612 *
3613 * @param int $seconds Remaining seconds.
3614 * @return string Formatted time string.
3615 */
3616 private function format_remaining_time( $seconds ) {
3617 if ( $seconds <= 0 ) {
3618 return __( 'expired', 'vigilante' );
3619 }
3620
3621 if ( $seconds < 60 ) {
3622 return sprintf(
3623 /* translators: %d: Number of seconds */
3624 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3625 $seconds
3626 );
3627 }
3628
3629 if ( $seconds < 3600 ) {
3630 $minutes = ceil( $seconds / 60 );
3631 return sprintf(
3632 /* translators: %d: Number of minutes */
3633 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3634 $minutes
3635 );
3636 }
3637
3638 $hours = floor( $seconds / 3600 );
3639 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3640
3641 if ( $remaining_minutes > 0 ) {
3642 return sprintf(
3643 /* translators: 1: Number of hours, 2: Number of minutes */
3644 __( '%1$d hours %2$d minutes', 'vigilante' ),
3645 $hours,
3646 $remaining_minutes
3647 );
3648 }
3649
3650 return sprintf(
3651 /* translators: %d: Number of hours */
3652 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3653 $hours
3654 );
3655 }
3656
3657 /**
3658 * Render 2FA settings section
3659 *
3660 * @param array $options Login security options.
3661 */
3662 private function render_2fa_settings( $options ) {
3663 $two_factor = $options['two_factor'] ?? array();
3664 $all_roles = wp_roles()->roles;
3665 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3666 $excluded = $two_factor['excluded_users'] ?? array();
3667 $method = $two_factor['method'] ?? 'email';
3668 $grace_days = $two_factor['grace_period_days'] ?? 3;
3669 ?>
3670 <h3>
3671 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3672 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3673 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3674 </h3>
3675 <p class="description"><?php esc_html_e( 'Require a second verification step after password. Choose between email codes or an authenticator app (TOTP).', 'vigilante' ); ?></p>
3676
3677 <table class="form-table">
3678 <tr>
3679 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3680 <td>
3681 <label>
3682 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3683 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3684 </label>
3685 </td>
3686 </tr>
3687 </table>
3688
3689 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3690 <table class="form-table">
3691 <tr>
3692 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3693 <td>
3694 <fieldset class="vigilante-2fa-method-selector">
3695 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3696 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3697 <span class="dashicons dashicons-email"></span>
3698 <span class="method-info">
3699 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3700 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3701 </span>
3702 </label>
3703 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3704 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3705 <span class="dashicons dashicons-smartphone"></span>
3706 <span class="method-info">
3707 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3708 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3709 </span>
3710 </label>
3711 </fieldset>
3712 </td>
3713 </tr>
3714 <tr>
3715 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3716 <td>
3717 <div class="vigilante-2fa-roles">
3718 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3719 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3720 ?>
3721 <label>
3722 <input type="checkbox"
3723 name="login_security[two_factor][enforced_roles][]"
3724 value="<?php echo esc_attr( $role_slug ); ?>"
3725 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3726 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3727 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3728 </label>
3729 <?php endforeach; ?>
3730 </div>
3731 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3732 </td>
3733 </tr>
3734 <tr>
3735 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3736 <td>
3737 <div class="vigilante-2fa-user-search-container">
3738 <div class="vigilante-2fa-user-search">
3739 <span class="search-icon"></span>
3740 <input type="text"
3741 id="vigilante_2fa_user_search"
3742 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3743 autocomplete="off">
3744 <div class="vigilante-2fa-search-results"></div>
3745 </div>
3746 <div class="vigilante-2fa-excluded-users">
3747 <?php
3748 foreach ( $excluded as $user_id ) :
3749 $user = get_user_by( 'ID', $user_id );
3750 if ( ! $user ) continue;
3751 ?>
3752 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3753 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3754 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3755 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3756 </div>
3757 <?php endforeach; ?>
3758 </div>
3759 </div>
3760 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3761 </td>
3762 </tr>
3763
3764 <!-- Remember device option -->
3765 <tr>
3766 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3767 <td>
3768 <label>
3769 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3770 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3771 </label>
3772 <p class="description">
3773 <?php
3774 printf(
3775 /* translators: %d: Number of days */
3776 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3777 absint( $two_factor['remember_device_days'] ?? 30 )
3778 );
3779 ?>
3780 </p>
3781 </td>
3782 </tr>
3783
3784 <!-- TOTP-specific: Grace period -->
3785 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3786 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3787 <td>
3788 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3789 name="login_security[two_factor][grace_period_days]"
3790 value="<?php echo esc_attr( $grace_days ); ?>"
3791 min="0" max="30" class="small-text">
3792 <?php esc_html_e( 'days', 'vigilante' ); ?>
3793 <p class="description"><?php esc_html_e( 'Days users have to set up their authenticator app. During this period they can log in without TOTP. Set to 0 for immediate enforcement.', 'vigilante' ); ?></p>
3794 </td>
3795 </tr>
3796
3797 <!-- Email-specific: Sender name -->
3798 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3799 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3800 <td>
3801 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3802 name="login_security[two_factor][email_from_name]"
3803 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3804 class="regular-text vigilante-2fa-email-from"
3805 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3806 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3807 </td>
3808 </tr>
3809
3810 <!-- TOTP-specific: Reset users -->
3811 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3812 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3813 <td>
3814 <div class="vigilante-totp-reset-container">
3815 <div class="vigilante-2fa-user-search">
3816 <span class="search-icon"></span>
3817 <input type="text"
3818 id="vigilante_totp_reset_search"
3819 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3820 autocomplete="off">
3821 <div class="vigilante-totp-reset-results"></div>
3822 </div>
3823 <div class="vigilante-totp-reset-selected"></div>
3824 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3825 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3826 </button>
3827 <span class="vigilante-totp-reset-status"></span>
3828 </div>
3829 <p class="description"><?php esc_html_e( 'Reset TOTP for users who lost access to their authenticator app. They will need to set up again.', 'vigilante' ); ?></p>
3830 </td>
3831 </tr>
3832 </table>
3833
3834 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3835 <table class="form-table">
3836 <tr>
3837 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3838 <td>
3839 <label>
3840 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3841 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3842 </label>
3843
3844 <div class="vigilante-2fa-notification-options">
3845 <label>
3846 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3847 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3848 </label>
3849 <label>
3850 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3851 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3852 </label>
3853 </div>
3854
3855 <div class="vigilante-2fa-send-notification">
3856 <button type="button" id="vigilante_2fa_send_notification" class="button">
3857 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3858 </button>
3859 <span class="vigilante-2fa-notification-status"></span>
3860 </div>
3861 </td>
3862 </tr>
3863 </table>
3864 </div>
3865 <?php
3866 }
3867
3868 /**
3869 * Render security headers tab
3870 */
3871 /**
3872 * Offer back the header settings the 2.9.8 migration wiped.
3873 *
3874 * Rendered outside the settings form on purpose, so its buttons can never
3875 * submit it, and only when there is something to actually change. Shows the
3876 * difference before anything is written: nothing is applied that the owner
3877 * has not seen first.
3878 *
3879 * @since 2.10.0
3880 */
3881 private function render_headers_recovery_offer() {
3882 /*
3883 * On a network the .htaccess belongs to every site and only the main one
3884 * writes it, so this is not a decision a subsite gets to make. Its own
3885 * security_headers options are inert anyway: what the network serves
3886 * comes from the file the main site owns. Without this gate a subsite
3887 * administrator was shown a Restore button that could only ever answer
3888 * with a permission error, which is worse than showing nothing.
3889 */
3890 if ( ! Vigilante_Settings::can_write_shared_files() ) {
3891 return;
3892 }
3893
3894 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
3895 /*
3896 * Already restored. Offer to take it back for as long as the previous
3897 * section is still stored: a restore that cannot be undone is a second
3898 * irreversible change on top of the one being repaired.
3899 */
3900 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
3901 ?>
3902 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
3903 <p>
3904 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
3905 <button type="button" class="button button-small" id="vigilante-recovery-undo">
3906 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
3907 </button>
3908 </p>
3909 </div>
3910 <?php
3911 }
3912
3913 return;
3914 }
3915
3916 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
3917
3918 if ( empty( $rows ) ) {
3919 return;
3920 }
3921
3922 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
3923 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
3924 $block = Vigilante_Htaccess_Recovery::get_raw_block();
3925 ?>
3926 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
3927 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
3928 <p>
3929 <?php esc_html_e( 'Updating to 2.9.8 reset this tab to factory values: the migration replaced the whole section instead of merging into it. Your server kept sending the right headers, because the .htaccess had not been rewritten yet, so Vigilant saved a copy of that file before touching it. These are the settings it found in that copy.', 'vigilante' ); ?>
3930 </p>
3931 <?php if ( $taken ) : ?>
3932 <p class="description">
3933 <?php
3934 printf(
3935 /* translators: %s: date and time the .htaccess copy was taken. */
3936 esc_html__( 'Copy taken on %s.', 'vigilante' ),
3937 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
3938 );
3939 ?>
3940 </p>
3941 <?php endif; ?>
3942
3943 <table class="widefat striped">
3944 <thead>
3945 <tr>
3946 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
3947 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
3948 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
3949 </tr>
3950 </thead>
3951 <tbody>
3952 <?php foreach ( $rows as $row ) : ?>
3953 <tr>
3954 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
3955 <td><?php echo esc_html( $row['current'] ); ?></td>
3956 <td>
3957 <?php echo esc_html( $row['recovered'] ); ?>
3958 <?php if ( ! empty( $row['detail'] ) ) : ?>
3959 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
3960 <?php endif; ?>
3961 </td>
3962 </tr>
3963 <?php endforeach; ?>
3964 </tbody>
3965 </table>
3966
3967 <p class="description">
3968 <?php esc_html_e( 'Only these settings are written. The .htaccess is then rebuilt from them, the same way saving this tab rebuilds it. The stored copy of the file is never written back, so nothing your host, your cache plugin or your CDN added to it is touched.', 'vigilante' ); ?>
3969 </p>
3970
3971 <?php if ( '' !== $block ) : ?>
3972 <details>
3973 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
3974 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
3975 </details>
3976 <?php endif; ?>
3977
3978 <p class="submit vigilante-submit-buttons">
3979 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
3980 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
3981 </button>
3982 <button type="button" class="button" id="vigilante-recovery-dismiss">
3983 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
3984 </button>
3985 </p>
3986 <div id="vigilante-recovery-result"></div>
3987 </div>
3988 <?php
3989 }
3990
3991 private function render_tab_headers() {
3992 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
3993 // Every setting on this tab ends up in .htaccess, so on a subsite the
3994 // whole tab is somebody else's, values included.
3995 $vg_shared_locked = $this->shared_files_locked();
3996 $options = $this->get_section_for_display( 'security_headers' );
3997 ?>
3998 <?php $this->render_headers_recovery_offer(); ?>
3999
4000 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4001 <?php $this->render_shared_files_notice(); ?>
4002 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4003 <h2>
4004 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4005 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4006 </h2>
4007 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4008
4009 <table class="form-table">
4010 <tr>
4011 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4012 <td>
4013 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4014 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4015 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4016 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4017 </select>
4018 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4019 </td>
4020 </tr>
4021 <tr>
4022 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4023 <td>
4024 <label>
4025 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4026 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4027 </label>
4028 </td>
4029 </tr>
4030 <tr>
4031 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4032 <td>
4033 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4034 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4035 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4036 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4037 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4038 </select>
4039 </td>
4040 </tr>
4041 </table>
4042
4043 <h3><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4044 <table class="form-table">
4045 <tr>
4046 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4047 <td>
4048 <label>
4049 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4050 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4051 </label>
4052 </td>
4053 </tr>
4054 <tr>
4055 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4056 <td>
4057 <label>
4058 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4059 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4060 </label>
4061 </td>
4062 </tr>
4063 </table>
4064
4065 <h3><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4066 <p class="description"><?php esc_html_e( 'HTTPS is strongly recommended, but Vigilant will not impose it. Enable only what your site already supports.', 'vigilante' ); ?></p>
4067 <table class="form-table">
4068 <tr>
4069 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4070 <td>
4071 <label>
4072 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4073 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4074 </label>
4075 <p class="description"><?php esc_html_e( 'Only applies when the site address is already an https:// one. On a site still published over HTTP it does nothing, so it cannot leave the site unreachable.', 'vigilante' ); ?></p>
4076 </td>
4077 </tr>
4078 <tr>
4079 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4080 <td>
4081 <label>
4082 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4083 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4084 </label>
4085 <p class="description"><?php esc_html_e( 'Off by default. Only touches addresses of this same site, and only when the site is already served over HTTPS, so it cannot break an external resource. Useful right after moving a site to HTTPS, when old content still points at http:// addresses.', 'vigilante' ); ?></p>
4086 </td>
4087 </tr>
4088 <tr id="field-upgrade-insecure-requests">
4089 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4090 <td>
4091 <label>
4092 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4093 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4094 </label>
4095 <p class="description"><?php esc_html_e( '&#9888; Off by default. This one also covers resources hosted elsewhere: anything served from a domain with no HTTPS stops loading instead of loading insecurely. Turn it on once you know every external resource the site uses is available over HTTPS.', 'vigilante' ); ?></p>
4096 </td>
4097 </tr>
4098 <tr>
4099 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4100 <td>
4101 <label>
4102 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4103 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4104 </label>
4105 <p class="description"><?php esc_html_e( '&#9888; Off by default. This writes to the WordPress Address and Site Address settings, and turning the plugin off later does not undo it. It only runs on activation, and only when the site answers over HTTPS.', 'vigilante' ); ?></p>
4106 </td>
4107 </tr>
4108 </table>
4109
4110 <h3><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4111 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4112 <p class="description"><?php esc_html_e( 'Tells browsers to reach this site over HTTPS and never over HTTP, for as long as the max age below.', 'vigilante' ); ?></p>
4113 <?php if ( ! $vig_home_https ) : ?>
4114 <p class="description" style="color:#b32d2e"><strong><?php esc_html_e( 'Unavailable: the site address still starts with http://. Enabling HSTS on a site not published over HTTPS would make it unreachable in any browser that honours it.', 'vigilante' ); ?></strong></p>
4115 <?php endif; ?>
4116 <table class="form-table">
4117 <tr>
4118 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4119 <td>
4120 <?php if ( ! $vig_home_https ) : ?>
4121 <?php /* A disabled checkbox is not submitted, and a boolean missing from the post is treated as unticked, so saving the tab would silently switch HSTS off. Carry the stored value instead. */ ?>
4122 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4123 <?php endif; ?>
4124 <label>
4125 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4126 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4127 </label>
4128 <p class="description"><?php esc_html_e( '&#9888; Hard to undo: browsers remember it for the whole max age even if you turn it off later, so a site that loses its certificate stays unreachable until it expires. Start with a short max age.', 'vigilante' ); ?></p>
4129 </td>
4130 </tr>
4131 <tr>
4132 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4133 <td>
4134 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4135 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4136 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4137 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4138 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4139 </select>
4140 </td>
4141 </tr>
4142 <tr>
4143 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4144 <td>
4145 <label>
4146 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4147 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4148 </label>
4149 </td>
4150 </tr>
4151 </table>
4152
4153 <h3><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4154 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4155 <table class="form-table">
4156 <tr>
4157 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4158 <td>
4159 <label>
4160 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4161 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4162 </label>
4163 </td>
4164 </tr>
4165 <tr>
4166 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4167 <td>
4168 <label>
4169 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4170 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4171 </label>
4172 </td>
4173 </tr>
4174 </table>
4175 </div>
4176
4177 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4178 <div id="vigilante-section-headers-cross-origin" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4179 <h2>
4180 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4181 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4182 </h2>
4183 <p><?php esc_html_e( 'Control how other origins may open, embed or fetch your site. Vigilant already sends these headers with the values below.', 'vigilante' ); ?></p>
4184
4185 <table class="form-table">
4186 <tr>
4187 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4188 <td>
4189 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4190 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4191 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4192 <option value="same-origin-allow-popups" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin-allow-popups' ); ?>><?php esc_html_e( 'same-origin-allow-popups (recommended)', 'vigilante' ); ?></option>
4193 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4194 </select>
4195 <p class="description"><?php esc_html_e( '&#9432; Cuts the link between your site and a window from another origin that opened it. Side effect: external tools that open your site in a new tab and talk to it through window.opener, such as Google Tag Assistant, will report that they cannot connect. Pick unsafe-none or Disabled if you need those tools.', 'vigilante' ); ?></p>
4196 </td>
4197 </tr>
4198 <tr>
4199 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4200 <td>
4201 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4202 <option value="unsafe-none" <?php selected( ( $vg_cop['embedder_policy'] ?? 'unsafe-none' ), 'unsafe-none' ); ?>><?php esc_html_e( 'unsafe-none (header not sent)', 'vigilante' ); ?></option>
4203 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4204 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4205 </select>
4206 <p class="description"><?php esc_html_e( '&#9432; Requires every cross-origin resource to opt in. require-corp can block third-party images, fonts, videos and embeds that do not send their own CORP or CORS headers.', 'vigilante' ); ?></p>
4207 </td>
4208 </tr>
4209 <tr>
4210 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4211 <td>
4212 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4213 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4214 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4215 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4216 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4217 </select>
4218 <p class="description"><?php esc_html_e( '&#9432; Declares who may load resources from this site. same-origin stops hotlinking, but it also breaks CDNs, feed readers and any external service that fetches your images or files.', 'vigilante' ); ?></p>
4219 </td>
4220 </tr>
4221 </table>
4222 </div>
4223
4224 <p class="submit vigilante-submit-buttons">
4225 <?php if ( ! $vg_shared_locked ) : ?>
4226 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4227 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4228 </button>
4229 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4230 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4231 </button>
4232 <?php endif; ?>
4233 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4234 <button type="button" class="button vigilante-test-headers">
4235 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4236 </button>
4237 </p>
4238 </form>
4239
4240 <div id="vigilante-headers-result"></div>
4241 <?php
4242 }
4243
4244 /**
4245 * Render REST API tab
4246 */
4247 private function render_tab_rest_api() {
4248 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4249 $options = $this->settings->get_section( 'rest_api_security' );
4250 ?>
4251 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4252 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4253 <h2>
4254 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4255 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4256 </h2>
4257 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4258
4259 <table class="form-table">
4260 <tr>
4261 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4262 <td>
4263 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4264 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4265 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4266 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4267 </select>
4268 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4269 </td>
4270 </tr>
4271 <tr id="field-block-user-enumeration">
4272 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4273 <td>
4274 <label>
4275 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4276 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4277 </label>
4278 </td>
4279 </tr>
4280 <tr>
4281 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4282 <td>
4283 <label>
4284 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4285 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4286 </label>
4287 </td>
4288 </tr>
4289 </table>
4290 </div>
4291
4292 <p class="submit vigilante-submit-buttons">
4293 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4294 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4295 </button>
4296 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4297 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4298 </button>
4299 </p>
4300 </form>
4301 <?php
4302 }
4303
4304 /**
4305 * Render User Security tab
4306 */
4307 private function render_tab_users() {
4308 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4309 $options = $this->settings->get_section( 'user_security' );
4310 $monitoring = $options['admin_monitoring'] ?? array();
4311 $registration = $options['registration_approval'] ?? array();
4312 $session_limits = $options['session_limits'] ?? array();
4313 $password_exp = $options['password_expiration'] ?? array();
4314 $email_verify = $options['email_verification'] ?? array();
4315 ?>
4316
4317 <!-- ============================================================
4318 SETTINGS SECTION - Single form for all configuration
4319 ============================================================ -->
4320 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4321
4322 <!-- Username & Password Protection -->
4323 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4324 <h2>
4325 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4326 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4327 </h2>
4328 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4329
4330 <table class="form-table">
4331 <tr>
4332 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4333 <td>
4334 <label>
4335 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4336 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4337 </label>
4338 </td>
4339 </tr>
4340 <?php
4341 $pw_policy = wp_parse_args(
4342 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4343 array(
4344 'require_uppercase' => false,
4345 'require_lowercase' => false,
4346 'require_number' => false,
4347 'require_special' => false,
4348 'block_common' => true,
4349 'block_username' => true,
4350 'affected_roles' => array(),
4351 )
4352 );
4353 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4354 ?>
4355 <tr>
4356 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4357 <td>
4358 <label>
4359 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4360 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4361 </label>
4362 </td>
4363 </tr>
4364 <tr>
4365 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4366 <td>
4367 <input id="vigilante-f-user-security-min-password-length" type="number" name="user_security[min_password_length]" value="<?php echo esc_attr( $options['min_password_length'] ?? 12 ); ?>" min="6" max="32" class="small-text">
4368 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4369 </td>
4370 </tr>
4371 <tr>
4372 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4373 <td>
4374 <label style="display:block;margin-bottom:5px;">
4375 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4376 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4377 </label>
4378 <label style="display:block;margin-bottom:5px;">
4379 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4380 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4381 </label>
4382 <label style="display:block;margin-bottom:5px;">
4383 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4384 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4385 </label>
4386 <label style="display:block;margin-bottom:5px;">
4387 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4388 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4389 </label>
4390 <label style="display:block;margin-bottom:5px;">
4391 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4392 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4393 </label>
4394 <label style="display:block;margin-bottom:5px;">
4395 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4396 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4397 </label>
4398 <p class="description"><?php esc_html_e( 'These rules apply only while "Enforce Strong Passwords" is on. Turn off individual rules to allow, for example, long passphrases without numbers or symbols.', 'vigilante' ); ?></p>
4399 </td>
4400 </tr>
4401 <tr>
4402 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4403 <td>
4404 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4405 <label style="display:block;margin-bottom:5px;">
4406 <input type="checkbox" name="user_security[password_policy][affected_roles][]" value="<?php echo esc_attr( $role_slug ); ?>" <?php checked( empty( $pw_policy_roles ) || in_array( $role_slug, $pw_policy_roles, true ) ); ?>>
4407 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4408 </label>
4409 <?php endforeach; ?>
4410 <p class="description"><?php esc_html_e( 'All roles are covered by default. Uncheck a role to exclude it from the password policy.', 'vigilante' ); ?></p>
4411 </td>
4412 </tr>
4413 <tr id="field-block-author-scanning">
4414 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4415 <td>
4416 <label>
4417 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4418 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4419 </label>
4420 </td>
4421 </tr>
4422 <tr>
4423 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4424 <td>
4425 <label>
4426 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4427 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4428 </label>
4429 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4430 </td>
4431 </tr>
4432 </table>
4433 </div>
4434
4435 <!-- Admin Monitoring -->
4436 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4437 <h2>
4438 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4439 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4440 </h2>
4441 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4442
4443 <table class="form-table">
4444 <tr>
4445 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4446 <td>
4447 <label>
4448 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4449 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4450 </label>
4451 </td>
4452 </tr>
4453 <tr>
4454 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4455 <td>
4456 <label>
4457 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4458 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4459 </label>
4460 </td>
4461 </tr>
4462 <tr>
4463 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4464 <td>
4465 <label>
4466 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4467 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4468 </label>
4469 </td>
4470 </tr>
4471 <tr>
4472 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4473 <td>
4474 <label>
4475 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4476 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4477 </label>
4478 </td>
4479 </tr>
4480 </table>
4481
4482 <p class="description">
4483 <?php
4484 printf(
4485 /* translators: %s: Link to notification settings */
4486 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4487 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4488 );
4489 ?>
4490 </p>
4491 </div>
4492
4493 <!-- Registration Approval -->
4494 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4495 <h2>
4496 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4497 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4498 </h2>
4499 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4500
4501 <table class="form-table">
4502 <tr>
4503 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4504 <td>
4505 <label>
4506 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4507 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4508 </label>
4509 </td>
4510 </tr>
4511 <tr>
4512 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4513 <td>
4514 <label>
4515 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4516 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4517 </label>
4518 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4519 </td>
4520 </tr>
4521 <tr>
4522 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4523 <td>
4524 <input id="vigilante-f-user-security-registration-approval-auto-reject-days" type="number" name="user_security[registration_approval][auto_reject_days]" value="<?php echo esc_attr( $registration['auto_reject_days'] ?? 0 ); ?>" min="0" max="365" class="small-text">
4525 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4526 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4527 </td>
4528 </tr>
4529 </table>
4530 </div>
4531
4532 <!-- Session Limits -->
4533 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4534 <h2>
4535 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4536 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4537 </h2>
4538 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4539
4540 <table class="form-table">
4541 <tr>
4542 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4543 <td>
4544 <label>
4545 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4546 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4547 </label>
4548 </td>
4549 </tr>
4550 <tr>
4551 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4552 <td>
4553 <input id="vigilante-f-user-security-session-limits-max-sessions" type="number" name="user_security[session_limits][max_sessions]" value="<?php echo esc_attr( $session_limits['max_sessions'] ?? 3 ); ?>" min="1" max="10" class="small-text">
4554 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4555 </td>
4556 </tr>
4557 <tr>
4558 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4559 <td>
4560 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4561 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4562 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4563 </select>
4564 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4565 </td>
4566 </tr>
4567 <tr>
4568 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4569 <td>
4570 <label>
4571 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4572 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4573 </label>
4574 </td>
4575 </tr>
4576 </table>
4577 </div>
4578
4579 <!-- Password Expiration -->
4580 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4581 <h2>
4582 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4583 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4584 </h2>
4585 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4586
4587 <table class="form-table">
4588 <tr>
4589 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4590 <td>
4591 <label>
4592 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4593 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4594 </label>
4595 </td>
4596 </tr>
4597 <tr>
4598 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4599 <td>
4600 <input id="vigilante-f-user-security-password-expiration-expire-days" type="number" name="user_security[password_expiration][expire_days]" value="<?php echo esc_attr( $password_exp['expire_days'] ?? 90 ); ?>" min="7" max="365" class="small-text">
4601 <?php esc_html_e( 'days', 'vigilante' ); ?>
4602 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4603 </td>
4604 </tr>
4605 <tr>
4606 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4607 <td>
4608 <input id="vigilante-f-user-security-password-expiration-warning-days" type="number" name="user_security[password_expiration][warning_days]" value="<?php echo esc_attr( $password_exp['warning_days'] ?? 14 ); ?>" min="1" max="30" class="small-text">
4609 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4610 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4611 </td>
4612 </tr>
4613 <tr>
4614 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4615 <td>
4616 <input id="vigilante-f-user-security-password-expiration-password-history" type="number" name="user_security[password_expiration][password_history]" value="<?php echo esc_attr( $password_exp['password_history'] ?? 3 ); ?>" min="0" max="24" class="small-text">
4617 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4618 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4619 </td>
4620 </tr>
4621 <tr>
4622 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4623 <td>
4624 <label>
4625 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4626 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4627 </label>
4628 <p class="description"><?php esc_html_e( 'The reminder is sent once when the warning period starts, using the same number of days configured above.', 'vigilante' ); ?></p>
4629 </td>
4630 </tr>
4631 <tr>
4632 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4633 <td>
4634 <?php
4635 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4636 $all_roles = wp_roles()->get_names();
4637 foreach ( $all_roles as $role_slug => $role_name ) :
4638 ?>
4639 <label style="display: block; margin-bottom: 5px;">
4640 <input type="checkbox" name="user_security[password_expiration][affected_roles][]" value="<?php echo esc_attr( $role_slug ); ?>" <?php checked( in_array( $role_slug, $affected_roles, true ) ); ?>>
4641 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4642 </label>
4643 <?php endforeach; ?>
4644 </td>
4645 </tr>
4646 <tr>
4647 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4648 <td>
4649 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4650 <div class="vigilante-2fa-user-search-container">
4651 <div class="vigilante-2fa-user-search">
4652 <span class="search-icon"></span>
4653 <input type="text"
4654 id="vigilante_pwexp_user_search"
4655 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4656 autocomplete="off">
4657 <div class="vigilante-pwexp-search-results"></div>
4658 </div>
4659 <div class="vigilante-pwexp-excluded-users">
4660 <?php
4661 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4662 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4663 if ( ! $excluded_user ) {
4664 continue;
4665 }
4666 ?>
4667 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4668 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4669 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4670 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4671 </div>
4672 <?php endforeach; ?>
4673 </div>
4674 </div>
4675 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4676 </td>
4677 </tr>
4678 </table>
4679 </div>
4680
4681 <!-- Email Verification -->
4682 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4683 <h2>
4684 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4685 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4686 </h2>
4687 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4688
4689 <table class="form-table">
4690 <tr>
4691 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4692 <td>
4693 <label>
4694 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4695 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4696 </label>
4697 </td>
4698 </tr>
4699 <tr>
4700 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4701 <td>
4702 <input id="vigilante-f-user-security-email-verification-token-expiry-hours" type="number" name="user_security[email_verification][token_expiry_hours]" value="<?php echo esc_attr( $email_verify['token_expiry_hours'] ?? 24 ); ?>" min="1" max="168" class="small-text">
4703 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4704 </td>
4705 </tr>
4706 <tr>
4707 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4708 <td>
4709 <label>
4710 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4711 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4712 </label>
4713 </td>
4714 </tr>
4715 <tr>
4716 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4717 <td>
4718 <input id="vigilante-f-user-security-email-verification-auto-delete-days" type="number" name="user_security[email_verification][auto_delete_days]" value="<?php echo esc_attr( $email_verify['auto_delete_days'] ?? 7 ); ?>" min="0" max="365" class="small-text">
4719 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4720 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4721 </td>
4722 </tr>
4723 </table>
4724 </div>
4725
4726 <p class="submit vigilante-submit-buttons">
4727 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4728 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4729 </button>
4730 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4731 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4732 </button>
4733 </p>
4734 </form>
4735
4736 <!-- ============================================================
4737 TOOLS SECTION - Actions and utilities (no save button)
4738 ============================================================ -->
4739 <div class="vigilante-tools-section">
4740 <h2 class="vigilante-tools-header">
4741 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4742 </h2>
4743
4744 <!-- Force Password Reset -->
4745 <div class="vigilante-tool-box">
4746 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4747 <p class="description"><?php esc_html_e( 'Force users to reset their password. Useful after a security incident. Users will receive an email with a reset link.', 'vigilante' ); ?></p>
4748
4749 <!-- Reset Specific Users -->
4750 <div class="vigilante-password-reset-box">
4751 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4752
4753 <div class="vigilante-user-search-wrapper">
4754 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4755 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4756 </div>
4757
4758 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4759 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4760 <ul class="vigilante-selected-users-list"></ul>
4761 </div>
4762
4763 <p class="description" style="margin-top: 15px;">
4764 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4765 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4766 </p>
4767
4768 <p class="submit">
4769 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4770 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4771 </button>
4772 </p>
4773 </div>
4774
4775 <!-- Reset by Role -->
4776 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4777 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4778 <p class="description"><?php esc_html_e( 'Select one or more roles to force a password reset for all users with those roles. Ideal for security incidents where you need to reset access quickly.', 'vigilante' ); ?></p>
4779
4780 <?php
4781 $wp_roles = wp_roles();
4782 $user_counts = count_users();
4783 $avail_roles = $user_counts['avail_roles'] ?? array();
4784 $current_user = wp_get_current_user();
4785 $current_roles = $current_user->roles;
4786 ?>
4787
4788 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4789 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4790 $count = $avail_roles[ $role_slug ] ?? 0;
4791 if ( 0 === $count ) {
4792 continue;
4793 }
4794 $role_name = translate_user_role( $role_data['name'] );
4795 ?>
4796 <label style="display: block; margin-bottom: 6px;">
4797 <input type="checkbox"
4798 class="vigilante-reset-role-checkbox"
4799 value="<?php echo esc_attr( $role_slug ); ?>"
4800 data-count="<?php echo absint( $count ); ?>">
4801 <?php
4802 printf(
4803 /* translators: 1: Role name, 2: Number of users */
4804 '%1$s <span class="description">(%2$d)</span>',
4805 esc_html( $role_name ),
4806 absint( $count )
4807 );
4808 ?>
4809 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4810 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4811 <?php endif; ?>
4812 </label>
4813 <?php endforeach; ?>
4814 </fieldset>
4815
4816 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4817 <p>
4818 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4819 <strong id="vigilante-reset-role-count">0</strong>
4820 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4821 </p>
4822 </div>
4823
4824 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4825 <label>
4826 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4827 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4828 </label>
4829 </div>
4830
4831 <p class="submit">
4832 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4833 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4834 </button>
4835 </p>
4836 </div>
4837
4838 <!-- Reset All Users -->
4839 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4840 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4841
4842 <?php
4843 $total_users = count_users();
4844 $total_count = $total_users['total_users'];
4845 ?>
4846 <p>
4847 <?php
4848 printf(
4849 /* translators: %d: Number of users */
4850 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4851 absint( $total_count )
4852 );
4853 ?>
4854 </p>
4855
4856 <p class="description" style="color: #d63638;">
4857 <span class="dashicons dashicons-warning"></span>
4858 <?php esc_html_e( 'Warning: All users will receive a password reset email. On sites with many users, this could overwhelm your mail server.', 'vigilante' ); ?>
4859 </p>
4860
4861 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4862 <label>
4863 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4864 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4865 </label>
4866 </div>
4867
4868 <p class="submit">
4869 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4870 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4871 </button>
4872 </p>
4873 </div>
4874 </div>
4875
4876 <!-- Pending Registrations -->
4877 <?php
4878 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
4879 $pending_users = $user_security->get_pending_users();
4880 ?>
4881 <div class="vigilante-tool-box vigilante-pending-users-section">
4882 <h3>
4883 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
4884 <?php if ( count( $pending_users ) > 0 ) : ?>
4885 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
4886 <?php endif; ?>
4887 </h3>
4888
4889 <?php if ( empty( $registration['enabled'] ) ) : ?>
4890 <p class="description">
4891 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
4892 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
4893 </p>
4894 <?php elseif ( empty( $pending_users ) ) : ?>
4895 <div class="vigilante-no-lockouts">
4896 <span class="dashicons dashicons-yes-alt"></span>
4897 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
4898 </div>
4899 <?php else : ?>
4900 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
4901 <thead>
4902 <tr>
4903 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
4904 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
4905 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
4906 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4907 </tr>
4908 </thead>
4909 <tbody>
4910 <?php foreach ( $pending_users as $pending_user ) :
4911 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
4912 ?>
4913 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4914 <td>
4915 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
4916 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
4917 </td>
4918 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
4919 <td>
4920 <?php
4921 if ( $pending_since ) {
4922 /* translators: %s: Time ago */
4923 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
4924 } else {
4925 echo esc_html( $pending_user->user_registered );
4926 }
4927 ?>
4928 </td>
4929 <td>
4930 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4931 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
4932 </button>
4933 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
4934 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
4935 </button>
4936 </td>
4937 </tr>
4938 <?php endforeach; ?>
4939 </tbody>
4940 </table>
4941 <?php endif; ?>
4942 </div>
4943
4944 <!-- Active Sessions Management -->
4945 <div class="vigilante-tool-box vigilante-session-management-section">
4946 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
4947 <p class="description"><?php esc_html_e( 'View and manage active login sessions. You can revoke sessions to force users to log in again.', 'vigilante' ); ?></p>
4948
4949 <!-- Current user sessions -->
4950 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
4951 <?php
4952 $current_user_id = get_current_user_id();
4953 $my_sessions = $user_security->get_user_sessions( $current_user_id );
4954 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
4955 $raw_count = $user_security->get_raw_session_count( $current_user_id );
4956 ?>
4957
4958 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
4959 <div class="notice notice-warning inline" style="margin: 10px 0;">
4960 <p>
4961 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
4962 <?php esc_html_e( 'Some session data is corrupted and cannot be displayed. Use "Revoke All Other Sessions" to clean up, then log out and log in again to fix this.', 'vigilante' ); ?>
4963 </p>
4964 </div>
4965 <?php endif; ?>
4966
4967 <?php if ( empty( $my_sessions ) ) : ?>
4968 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
4969 <?php if ( $has_corrupted ) : ?>
4970 <p style="margin-top: 10px;">
4971 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
4972 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
4973 </button>
4974 </p>
4975 <?php endif; ?>
4976 <?php else : ?>
4977 <div class="vigilante-paginated-section">
4978 <div class="vigilante-fi-pagination-wrap"></div>
4979 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
4980 <thead>
4981 <tr>
4982 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
4983 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4984 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
4985 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4986 </tr>
4987 </thead>
4988 <tbody>
4989 <?php foreach ( $my_sessions as $session ) : ?>
4990 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
4991 <td><?php echo esc_html( $session['browser'] ); ?></td>
4992 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
4993 <td>
4994 <?php
4995 if ( $session['login'] ) {
4996 /* translators: %s: Time ago */
4997 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
4998 } else {
4999 esc_html_e( 'Unknown', 'vigilante' );
5000 }
5001 ?>
5002 </td>
5003 <td>
5004 <?php if ( ! $session['is_current'] ) : ?>
5005 <button type="button" class="button button-small vigilante-revoke-session" data-user-id="<?php echo esc_attr( $current_user_id ); ?>" data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5006 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5007 </button>
5008 <?php else : ?>
5009 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5010 <?php endif; ?>
5011 </td>
5012 </tr>
5013 <?php endforeach; ?>
5014 </tbody>
5015 </table>
5016 </div>
5017
5018 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5019 <p style="margin-top: 10px;">
5020 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5021 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5022 </button>
5023 </p>
5024 <?php endif; ?>
5025 <?php endif; ?>
5026
5027 <!-- Search user sessions (admin only) -->
5028 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5029 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5030
5031 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5032 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5033 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5034 </div>
5035
5036 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5037 <h4 id="vigilante-sessions-user-name"></h4>
5038 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5039 <thead>
5040 <tr>
5041 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5042 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5043 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5044 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5045 </tr>
5046 </thead>
5047 <tbody id="vigilante-user-sessions-list">
5048 </tbody>
5049 </table>
5050 <p style="margin-top: 10px;">
5051 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5052 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5053 </button>
5054 </p>
5055 </div>
5056 </div>
5057 </div>
5058 <?php
5059 }
5060
5061 /**
5062 * Render WordPress Hardening tab
5063 */
5064 private function render_tab_wp_hardening() {
5065 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5066 $options = $this->settings->get_section( 'wp_hardening' );
5067 ?>
5068 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5069 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5070 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5071 <?php $this->render_shared_files_notice(); ?>
5072 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5073 <h2>
5074 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5075 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5076 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5077 </h2>
5078 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5079
5080 <?php
5081 $db_prefix = new Vigilante_Database_Prefix();
5082 $current_prefix = $db_prefix->get_current_prefix();
5083 $is_default = $db_prefix->is_default_prefix();
5084 ?>
5085
5086 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5087 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5088 <p style="margin:0;"><?php esc_html_e( 'Network-wide operation: it renames the tables of every site in the network and rewrites the wp-config.php they all share. Back up the whole database first, not just the main site.', 'vigilante' ); ?></p>
5089 </div>
5090 <?php endif; ?>
5091
5092 <table class="form-table">
5093 <tr>
5094 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5095 <td>
5096 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5097 <?php if ( $is_default ) : ?>
5098 <span class="vigilante-inline-warning">
5099 <span class="dashicons dashicons-warning"></span>
5100 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5101 </span>
5102 <?php else : ?>
5103 <span class="vigilante-inline-ok">
5104 <span class="dashicons dashicons-yes-alt"></span>
5105 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5106 </span>
5107 <?php endif; ?>
5108 </td>
5109 </tr>
5110 <tr>
5111 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5112 <td>
5113 <div class="vigilante-db-prefix-row">
5114 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5115 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5116 <span class="dashicons dashicons-update"></span>
5117 </button>
5118 </div>
5119 </td>
5120 </tr>
5121 <tr>
5122 <th scope="row"></th>
5123 <td>
5124 <div class="vigilante-db-prefix-confirm">
5125 <label>
5126 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5127 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5128 </label>
5129 <p class="description">
5130 <?php
5131 printf(
5132 /* translators: %s: Link to tools tab */
5133 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5134 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5135 );
5136 ?>
5137 </p>
5138 </div>
5139 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5140 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5141 </button>
5142 </td>
5143 </tr>
5144 </table>
5145 </div>
5146
5147 <!-- wp-config Security -->
5148 <?php
5149 $vg_shared_locked = $this->shared_files_locked();
5150 // Paint what is actually in force, not this site's unused copy.
5151 $vg_local_options = $options;
5152 $options = $this->get_section_for_display( 'wp_hardening' );
5153 ?>
5154 <?php $this->render_shared_files_notice(); ?>
5155 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5156 <h2>
5157 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5158 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5159 </h2>
5160 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5161
5162 <table class="form-table">
5163 <tr>
5164 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5165 <td>
5166 <label>
5167 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5168 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5169 </label>
5170 </td>
5171 </tr>
5172 <tr>
5173 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5174 <td>
5175 <label>
5176 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5177 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5178 </label>
5179 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5180 </td>
5181 </tr>
5182 <tr id="field-force-ssl-admin">
5183 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5184 <td>
5185 <label>
5186 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5187 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5188 </label>
5189 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5190 </td>
5191 </tr>
5192 <tr id="field-wp-debug">
5193 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5194 <td>
5195 <label>
5196 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5197 <?php esc_html_e( 'Prevents PHP errors and warnings from being displayed publicly. Also avoids exposing a debug.log file in wp-content/ that could leak paths and code. Uncheck only on development or staging sites.', 'vigilante' ); ?>
5198 </label>
5199 </td>
5200 </tr>
5201 <tr id="field-disable-wp-cron">
5202 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5203 <td>
5204 <label>
5205 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5206 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5207 </label>
5208 <p class="description"><?php
5209 printf(
5210 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5211 esc_html__( '%1$sWarning:%2$s Only enable if your host runs a real server-side cron job calling wp-cron.php. Otherwise scheduled tasks stop running. This constant only stops the page-view auto-spawn — to also block external HTTP abuse, enable %3$sProtect wp-cron.php%4$s in Firewall &rarr; File Protection.', 'vigilante' ),
5212 '<strong>',
5213 '</strong>',
5214 '<code>',
5215 '</code>'
5216 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5217 ?></p>
5218 </td>
5219 </tr>
5220 </table>
5221 </div>
5222 <?php $options = $vg_local_options; ?>
5223
5224 <!-- Comment Security -->
5225 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5226 <h2>
5227 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5228 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5229 </h2>
5230 <p><?php esc_html_e( 'The legacy remote interface. It is what the WordPress mobile app, Jetpack and remote managers talk to, and also the way pingback amplification and password guessing reach a site.', 'vigilante' ); ?></p>
5231
5232 <table class="form-table">
5233 <tr id="field-disable-xmlrpc">
5234 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5235 <td>
5236 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5237 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5238 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5239 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5240 </option>
5241 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5242 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5243 </option>
5244 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5245 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5246 </option>
5247 </select>
5248 <p class="description"><?php esc_html_e( 'Disable it completely unless something still needs it, such as the WordPress mobile app, Jetpack or a remote manager; in that case block only the pingback methods, which closes the amplification vector and leaves the rest working. Pingbacks are also covered by the Comment Security setting just below, which additionally closes them for comments.', 'vigilante' ); ?></p>
5249 </td>
5250 </tr>
5251 </table>
5252 </div>
5253
5254 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5255 <h2>
5256 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5257 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5258 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5259 </h2>
5260 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5261
5262 <table class="form-table">
5263 <tr>
5264 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5265 <td>
5266 <label>
5267 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5268 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5269 </label>
5270 </td>
5271 </tr>
5272 <tr>
5273 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5274 <td>
5275 <label>
5276 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5277 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5278 </label>
5279 </td>
5280 </tr>
5281 <tr>
5282 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5283 <td>
5284 <label>
5285 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5286 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5287 </label>
5288 </td>
5289 </tr>
5290 <tr>
5291 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5292 <td>
5293 <label>
5294 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5295 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5296 </label>
5297 <input type="number" id="vigilante-f-wp-hardening-close-comments-after-days" name="wp_hardening[close_comments_after_days]" value="<?php echo esc_attr( $options['close_comments_after_days'] ?? 30 ); ?>" min="1" max="365" class="small-text">
5298 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5299 </td>
5300 </tr>
5301 <tr>
5302 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5303 <td>
5304 <label>
5305 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5306 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5307 </label>
5308 </td>
5309 </tr>
5310 </table>
5311 </div>
5312
5313 <!-- Head Cleaner -->
5314 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5315 <h2>
5316 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5317 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5318 </h2>
5319 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5320
5321 <table class="form-table">
5322 <tr>
5323 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5324 <td>
5325 <label>
5326 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5327 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5328 </label>
5329 </td>
5330 </tr>
5331 <tr id="field-remove-wp-version-assets">
5332 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5333 <td>
5334 <label>
5335 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5336 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5337 </label>
5338 <p class="description"><?php esc_html_e( 'Hides the exact WordPress version that would otherwise leak in every enqueued asset URL. Versions added by plugins or themes are kept untouched.', 'vigilante' ); ?></p>
5339 </td>
5340 </tr>
5341 <tr>
5342 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5343 <td>
5344 <label>
5345 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5346 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5347 </label>
5348 </td>
5349 </tr>
5350 <tr>
5351 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5352 <td>
5353 <label>
5354 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5355 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5356 </label>
5357 </td>
5358 </tr>
5359 <tr>
5360 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5361 <td>
5362 <label>
5363 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5364 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5365 </label>
5366 </td>
5367 </tr>
5368 <tr>
5369 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5370 <td>
5371 <label>
5372 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5373 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5374 </label>
5375 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5376 </td>
5377 </tr>
5378 </table>
5379 </div>
5380
5381 <!-- Feed Manager -->
5382 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5383 <h2>
5384 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5385 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5386 </h2>
5387 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5388
5389 <table class="form-table">
5390 <tr>
5391 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5392 <td>
5393 <label>
5394 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5395 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5396 </label>
5397 </td>
5398 </tr>
5399 <tr>
5400 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5401 <td>
5402 <label>
5403 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5404 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5405 </label>
5406 </td>
5407 </tr>
5408 <tr>
5409 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5410 <td>
5411 <label>
5412 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5413 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5414 </label>
5415 </td>
5416 </tr>
5417 </table>
5418 </div>
5419
5420 <p class="submit vigilante-submit-buttons">
5421 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5422 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5423 </button>
5424 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5425 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5426 </button>
5427 </p>
5428 </form>
5429 <?php
5430 }
5431
5432 /**
5433 * Render activity log tab
5434 */
5435 private function render_tab_activity_log() {
5436 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5437 $options = $this->settings->get_section( 'activity_log' );
5438 ?>
5439 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5440 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5441 <h2>
5442 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5443 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5444 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5445 </h2>
5446 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5447
5448 <table class="form-table">
5449 <tr>
5450 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5451 <td>
5452 <input type="number" id="vigilante-f-activity-log-retention-days" name="activity_log[retention_days]" value="<?php echo esc_attr( $options['retention_days'] ?? 30 ); ?>" min="7" max="365" class="small-text">
5453 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5454 &nbsp;&nbsp;
5455 <input type="number" id="vigilante-f-activity-log-max-entries" name="activity_log[max_entries]" value="<?php echo esc_attr( $options['max_entries'] ?? 10000 ); ?>" min="100" max="100000" step="100" class="small-text">
5456 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5457 <p class="description"><?php esc_html_e( 'Whichever limit is reached first takes effect. Changes apply immediately on save; daily maintenance also enforces these limits automatically.', 'vigilante' ); ?></p>
5458 </td>
5459 </tr>
5460 <tr>
5461 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5462 <td>
5463 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5464 <label><input type="checkbox" name="activity_log[log_logins]" value="1" <?php checked( ! empty( $options['log_logins'] ) ); ?>> <?php esc_html_e( 'Successful logins', 'vigilante' ); ?></label>
5465 <label><input type="checkbox" name="activity_log[log_failed_logins]" value="1" <?php checked( ! empty( $options['log_failed_logins'] ) ); ?>> <?php esc_html_e( 'Failed login attempts', 'vigilante' ); ?></label>
5466 <label><input type="checkbox" name="activity_log[log_user_changes]" value="1" <?php checked( ! empty( $options['log_user_changes'] ) ); ?>> <?php esc_html_e( 'User changes', 'vigilante' ); ?></label>
5467 <label><input type="checkbox" name="activity_log[log_post_changes]" value="1" <?php checked( ! empty( $options['log_post_changes'] ) ); ?>> <?php esc_html_e( 'Content changes', 'vigilante' ); ?></label>
5468 <label><input type="checkbox" name="activity_log[log_plugin_changes]" value="1" <?php checked( ! empty( $options['log_plugin_changes'] ) ); ?>> <?php esc_html_e( 'Plugin changes', 'vigilante' ); ?></label>
5469 <label><input type="checkbox" name="activity_log[log_theme_changes]" value="1" <?php checked( ! empty( $options['log_theme_changes'] ) ); ?>> <?php esc_html_e( 'Theme changes', 'vigilante' ); ?></label>
5470 <label><input type="checkbox" name="activity_log[log_comments]" value="1" <?php checked( ! empty( $options['log_comments'] ) ); ?>> <?php esc_html_e( 'Comment changes', 'vigilante' ); ?></label>
5471 <label><input type="checkbox" name="activity_log[log_media]" value="1" <?php checked( ! empty( $options['log_media'] ) ); ?>> <?php esc_html_e( 'Media uploads/deletions', 'vigilante' ); ?></label>
5472 <label><input type="checkbox" name="activity_log[log_file_changes]" value="1" <?php checked( ! empty( $options['log_file_changes'] ) ); ?>> <?php esc_html_e( 'File integrity events', 'vigilante' ); ?></label>
5473 <label><input type="checkbox" name="activity_log[log_option_changes]" value="1" <?php checked( ! empty( $options['log_option_changes'] ) ); ?>> <?php esc_html_e( 'WordPress option changes', 'vigilante' ); ?></label>
5474 </fieldset>
5475 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5476 <p style="margin:0;">
5477 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5478 </p>
5479 </div>
5480 </td>
5481 </tr>
5482 <tr>
5483 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5484 <td>
5485 <p class="description" style="margin-top:0;"><?php esc_html_e( 'When "WordPress option changes" is enabled, Vigilant tracks ~30 core WordPress settings (site URL, admin email, registration, active plugins, theme, comments, privacy, etc.). Use the field below to track additional options from other plugins.', 'vigilante' ); ?></p>
5486 <br>
5487 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5488 <textarea id="vigilante-f-activity-log-tracked-options" name="activity_log[tracked_options]" rows="3" cols="50" class="regular-text code" placeholder="woocommerce_&#10;seopress_&#10;wpforms_"><?php echo esc_textarea( implode( "\n", $options['tracked_options'] ?? array() ) ); ?></textarea>
5489 <p class="description"><?php esc_html_e( 'One option name per line. Use a trailing underscore to match all options with that prefix (e.g. "woocommerce_" tracks all WooCommerce settings).', 'vigilante' ); ?></p>
5490 </td>
5491 </tr>
5492 <tr>
5493 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5494 <td>
5495 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5496 <div>
5497 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5498 <textarea id="vigilante-f-activity-log-excluded-users" name="activity_log[excluded_users]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_users'] ?? array() ) ); ?></textarea>
5499 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5500 </div>
5501 <div>
5502 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5503 <textarea id="vigilante-f-activity-log-excluded-ips" name="activity_log[excluded_ips]" rows="3" cols="25"><?php echo esc_textarea( implode( "\n", $options['excluded_ips'] ?? array() ) ); ?></textarea>
5504 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5505 </div>
5506 </div>
5507 </td>
5508 </tr>
5509 </table>
5510 </div>
5511
5512 <p class="submit vigilante-submit-buttons">
5513 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5514 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5515 </button>
5516 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5517 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5518 </button>
5519 </p>
5520 </form>
5521
5522 <?php
5523 // Audit Alerts — alerting layer on top of Security Audit. Its own
5524 // settings section and form, rendered right after the logging settings
5525 // so the tab reads as "log this, exclude that, and alert me about this".
5526 $alerts = $this->settings->get_section( 'audit_alerts' );
5527 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5528 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5529 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5530 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5531 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5532 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5533 ?>
5534 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5535 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5536 <h2>
5537 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5538 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5539 </h2>
5540 <p><?php esc_html_e( 'Get an email when the events above point to something worth your attention. Both alert types are off by default.', 'vigilante' ); ?></p>
5541
5542 <table class="form-table">
5543 <tr id="field-audit-alerts-immediate">
5544 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5545 <td>
5546 <label>
5547 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5548 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5549 </label>
5550 <p class="description"><?php esc_html_e( 'Sends one email per event type, then waits for the cooldown below before repeating, so a burst of the same event is a single notice.', 'vigilante' ); ?></p>
5551 </td>
5552 </tr>
5553 <tr>
5554 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5555 <td>
5556 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5557 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5558 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5559 </select>
5560 <p class="description"><?php esc_html_e( 'A new administrator, a closed plugin or a privilege escalation are all logged as Critical, so "Critical only" already covers them.', 'vigilante' ); ?></p>
5561 </td>
5562 </tr>
5563 <tr id="field-audit-alerts-threshold">
5564 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5565 <td>
5566 <label>
5567 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5568 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5569 </label>
5570 <p class="description"><?php esc_html_e( 'Catches an attack in progress, e.g. hundreds of firewall blocks or login failures in an hour.', 'vigilante' ); ?></p>
5571 </td>
5572 </tr>
5573 <tr>
5574 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5575 <td>
5576 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5577 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5578 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5579 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5580 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5581 </select>
5582 <p class="description"><?php esc_html_e( 'How far back Vigilant looks when counting events. For example, "1 hour" means "more than the number below within the last hour".', 'vigilante' ); ?></p>
5583 </td>
5584 </tr>
5585 <tr>
5586 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5587 <td>
5588 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5589 <?php
5590 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5591 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5592 ?>
5593 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5594 <span><?php echo esc_html( $cat_label ); ?></span>
5595 <input type="number" name="audit_alerts[threshold][categories][<?php echo esc_attr( $cat_slug ); ?>]" value="<?php echo esc_attr( $cat_value ); ?>" min="0" max="100000" step="1" class="small-text">
5596 </label>
5597 <?php endforeach; ?>
5598 </fieldset>
5599 <p class="description"><?php esc_html_e( 'Number of warning/critical events in the window that triggers an alert. 0 disables that category. Routine info-level activity (normal logins, edits) is not counted.', 'vigilante' ); ?></p>
5600 </td>
5601 </tr>
5602 <tr>
5603 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5604 <td>
5605 <input type="number" id="vigilante-f-audit-alerts-cooldown-minutes" name="audit_alerts[cooldown_minutes]" value="<?php echo esc_attr( isset( $alerts['cooldown_minutes'] ) ? (int) $alerts['cooldown_minutes'] : 60 ); ?>" min="0" max="1440" class="small-text">
5606 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5607 <p class="description"><?php esc_html_e( 'After an alert, Vigilant waits this long before sending another about the same thing: the same event type for immediate alerts, or the same category for threshold alerts. This prevents a flood during a sustained attack. Applies to both alert types above.', 'vigilante' ); ?></p>
5608 </td>
5609 </tr>
5610
5611 <tr>
5612 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5613 <td>
5614 <p class="description" style="margin-top:0;">
5615 <?php
5616 printf(
5617 /* translators: %s: Link to notification settings */
5618 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5619 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5620 );
5621 ?>
5622 </p>
5623 <p style="margin:8px 0 0;">
5624 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5625 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5626 </button>
5627 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5628 </p>
5629 <p class="description"><?php esc_html_e( 'Heads up: some events (a new admin, a closed plugin) already send their own email from other modules. Enabling alerts for them here too may produce two notices until notifications are unified.', 'vigilante' ); ?></p>
5630 </td>
5631 </tr>
5632 </table>
5633 </div>
5634
5635 <p class="submit vigilante-submit-buttons">
5636 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5637 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5638 </button>
5639 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5640 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5641 </button>
5642 </p>
5643 </form>
5644
5645 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5646 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5647
5648 <?php
5649 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5650 $total_logs = $this->activity_log->get_logs_count();
5651
5652 // Label maps for translated display
5653 $type_labels = array(
5654 'login' => __( 'Login', 'vigilante' ),
5655 'user' => __( 'User', 'vigilante' ),
5656 'content' => __( 'Content', 'vigilante' ),
5657 'plugin' => __( 'Plugin', 'vigilante' ),
5658 'theme' => __( 'Theme', 'vigilante' ),
5659 'settings' => __( 'Settings', 'vigilante' ),
5660 'comment' => __( 'Comment', 'vigilante' ),
5661 'media' => __( 'Media', 'vigilante' ),
5662 'firewall' => __( 'Firewall', 'vigilante' ),
5663 'file' => __( 'File', 'vigilante' ),
5664 'security' => __( 'Security', 'vigilante' ),
5665 'system' => __( 'System', 'vigilante' ),
5666 );
5667 $severity_labels = array(
5668 'info' => __( 'Info', 'vigilante' ),
5669 'warning' => __( 'Warning', 'vigilante' ),
5670 'critical' => __( 'Critical', 'vigilante' ),
5671 );
5672
5673 $firewall_options = $this->settings->get_section( 'firewall' );
5674 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5675 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5676 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5677 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5678 ?>
5679
5680 <div class="vigilante-log-filters">
5681 <input type="text" id="vigilante-log-search" aria-label="<?php esc_attr_e( 'Search the activity log', 'vigilante' ); ?>" size="1" placeholder="<?php esc_attr_e( 'Search logs (min. 3 characters)...', 'vigilante' ); ?>" class="vigilante-log-search-input">
5682 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5683 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5684 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5685 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5686 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5687 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5688 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5689 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5690 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5691 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5692 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5693 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5694 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5695 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5696 </select>
5697 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5698 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5699 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5700 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5701 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5702 </select>
5703 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5704 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5705 <option value="GET">GET</option>
5706 <option value="POST">POST</option>
5707 <option value="PUT">PUT</option>
5708 <option value="DELETE">DELETE</option>
5709 <option value="PATCH">PATCH</option>
5710 <option value="OPTIONS">OPTIONS</option>
5711 <option value="HEAD">HEAD</option>
5712 </select>
5713 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5714 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5715 <?php if ( $total_logs > 20 ) : ?>
5716 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5717 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5718 <?php endif; ?>
5719 <span class="vigilante-page-info">
5720 <?php
5721 $showing = min( 20, $total_logs );
5722 printf(
5723 /* translators: 1: first item, 2: last item, 3: total items */
5724 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5725 $total_logs > 0 ? 1 : 0,
5726 absint( $showing ),
5727 absint( $total_logs )
5728 );
5729 ?>
5730 </span>
5731 <?php if ( $total_logs > 20 ) : ?>
5732 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5733 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5734 <?php endif; ?>
5735 </span>
5736 </div>
5737
5738 <div class="vigilante-log-table-wrap">
5739 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5740 <thead>
5741 <tr>
5742 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5743 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5744 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5745 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5746 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5747 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5748 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5749 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5750 </tr>
5751 </thead>
5752 <tbody>
5753 <?php
5754 if ( empty( $logs ) ) :
5755 ?>
5756 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5757 <?php else : ?>
5758 <?php foreach ( $logs as $log ) :
5759 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5760 // Prepare details as a simple object
5761 $ip_val = (string) ( $log->ip_address ?? '' );
5762 $ua_val = (string) ( $log->user_agent ?? '' );
5763 $details = array(
5764 'id' => (int) $log->id,
5765 'type' => (string) ( $log->event_type ?? '' ),
5766 'action' => (string) ( $log->event_action ?? '' ),
5767 'message' => (string) ( $log->event_message ?? '' ),
5768 'user' => (string) ( $log->user_login ?? '' ),
5769 'ip' => $ip_val,
5770 'user_agent' => $ua_val,
5771 'request_method' => (string) $request_method,
5772 'date' => (string) ( $log->created_at ?? '' ),
5773 'severity' => (string) ( $log->severity ?? 'info' ),
5774 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5775 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5776 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5777 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5778 );
5779 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5780 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5781 ?>
5782 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5783 <td><?php echo esc_html( $log->created_at ); ?></td>
5784 <td><?php echo esc_html( $display_type ); ?></td>
5785 <td><?php if ( ! empty( $request_method ) ) : ?><span class="vigilante-method-label vigilante-method-<?php echo esc_attr( strtolower( $request_method ) ); ?>"><?php echo esc_html( $request_method ); ?></span><?php else : ?>-<?php endif; ?></td>
5786 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5787 <td><?php echo esc_html( $log->event_message ); ?></td>
5788 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5789 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5790 <td>
5791 <button type="button" class="button button-small vigilante-view-log-details"
5792 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5793 <?php esc_html_e( 'View', 'vigilante' ); ?>
5794 </button>
5795 </td>
5796 </tr>
5797 <?php endforeach; ?>
5798 <?php endif; ?>
5799 </tbody>
5800 </table>
5801 </div>
5802
5803 <!-- Log Details Modal -->
5804 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5805 <div class="vigilante-modal-content">
5806 <span class="vigilante-modal-close">&times;</span>
5807 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5808 <div id="vigilante-log-details-content"></div>
5809 </div>
5810 </div>
5811
5812 <p>
5813 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5814 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5815 </p>
5816 </div>
5817 <?php
5818 }
5819
5820 /**
5821 * Render File Integrity tab
5822 */
5823 private function render_tab_file_integrity() {
5824 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5825 $options = $this->settings->get_section( 'file_integrity' );
5826 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5827 $last_results = get_option( 'vigilante_last_integrity_results' );
5828 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5829
5830 // Backward compat: convert old notify_on_changes to notify_level
5831 $notify_level = $options['notify_level'] ?? '';
5832 if ( empty( $notify_level ) ) {
5833 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5834 }
5835
5836 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5837 // user sees file findings and plugin closures together (same tier of risk,
5838 // same UI), and as the trigger to keep Last Scan Results open even when no
5839 // file scan has run yet (the daily cron may have populated this section).
5840 //
5841 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5842 // resets this block: the option vigilante_plugin_status_last_check is
5843 // deleted on Clear, but the state map and the ignored list survive so the
5844 // next scan reconstructs without degrading a 'removed' slug. While
5845 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5846 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5847 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5848 }
5849 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5850 $closed_last_check = $closed_checker->get_last_check_time();
5851 if ( $closed_last_check > 0 ) {
5852 $closed_plugins = $closed_checker->get_closed_plugins();
5853 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5854 } else {
5855 $closed_plugins = array();
5856 $ignored_closed_plugins = array();
5857 }
5858 $has_closed = ! empty( $closed_plugins );
5859 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5860 ?>
5861 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5862 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5863 <h2>
5864 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5865 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5866 </h2>
5867 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5868
5869 <table class="form-table">
5870 <tr>
5871 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5872 <td>
5873 <label>
5874 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5875 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
5876 </label>
5877 </td>
5878 </tr>
5879 <tr>
5880 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
5881 <td>
5882 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
5883 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
5884 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
5885 </select>
5886 </td>
5887 </tr>
5888 <tr>
5889 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
5890 <td>
5891 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
5892 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
5893 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
5894 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
5895 </select>
5896 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
5897 </td>
5898 </tr>
5899 <tr>
5900 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
5901 <td>
5902 <label>
5903 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
5904 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
5905 </label>
5906 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
5907 <p class="description">
5908 <?php
5909 printf(
5910 /* translators: %s: Link to notification settings */
5911 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5912 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5913 );
5914 ?>
5915 </p>
5916 </td>
5917 </tr>
5918 <tr>
5919 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
5920 <td>
5921 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5922 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5923 </button>
5924 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5925 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
5926 </td>
5927 </tr>
5928 <tr>
5929 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
5930 <td>
5931 <fieldset>
5932 <label>
5933 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
5934 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
5935 </label>
5936 <br>
5937 <label>
5938 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
5939 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
5940 </label>
5941 <br>
5942 <label>
5943 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
5944 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
5945 </label>
5946 <br>
5947 <label>
5948 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
5949 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
5950 </label>
5951 <br>
5952 <label>
5953 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
5954 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
5955 </label>
5956 <br>
5957 <label>
5958 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
5959 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
5960 </label>
5961 </fieldset>
5962 </td>
5963 </tr>
5964 <tr>
5965 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
5966 <td>
5967 <textarea id="vigilante-f-file-integrity-excluded-paths" name="file_integrity[excluded_paths]" rows="4" class="large-text code" placeholder="wp-content/cache&#10;wp-content/languages"><?php echo esc_textarea( implode( "\n", $options['excluded_paths'] ?? array() ) ); ?></textarea>
5968 <p class="description"><?php esc_html_e( 'One path per line, relative to the WordPress root. A path such as wp-content/cache excludes exactly that folder and everything under it. A name on its own, such as cache, excludes any folder called exactly that, wherever it is.', 'vigilante' ); ?></p>
5969 </td>
5970 </tr>
5971 <tr>
5972 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
5973 <td>
5974 <textarea id="vigilante-f-file-integrity-excluded-extensions" name="file_integrity[excluded_extensions]" rows="3" class="large-text code" placeholder=".log&#10;.po&#10;.mo&#10;.pot"><?php echo esc_textarea( implode( "\n", $options['excluded_extensions'] ?? array() ) ); ?></textarea>
5975 <p class="description">
5976 <?php esc_html_e( 'One extension per line (e.g. .log, .po, .mo). Files with these extensions will be skipped. Useful to avoid false positives from translation or log files.', 'vigilante' ); ?>
5977 <br>
5978 <?php
5979 printf(
5980 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
5981 esc_html__( 'An extension on its own applies to the whole site. To limit it to one folder, write it as %1$swp-content/languages/*.json%2$s, which leaves the same extension watched everywhere else.', 'vigilante' ),
5982 '<code>',
5983 '</code>'
5984 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5985 ?>
5986 </p>
5987 </td>
5988 </tr>
5989 </table>
5990 </div>
5991
5992 <p class="submit vigilante-submit-buttons">
5993 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5994 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5995 </button>
5996 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5997 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5998 </button>
5999 <span class="vigilante-buttons-separator"></span>
6000 <button type="button" class="button button-primary vigilante-run-scan">
6001 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6002 </button>
6003 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6004 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6005 </button>
6006 </p>
6007 </form>
6008
6009 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6010
6011 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6012 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6013 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6014 <?php if ( $last_scan ) : ?>
6015 <p>
6016 <?php
6017 // Build the "X files scanned" hint inline with the date so it doesn't
6018 // need its own stat box (keeps the row compact when closed plugins are
6019 // present).
6020 $scanned_total = 0;
6021 if ( $last_results ) {
6022 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6023 + count( $last_results['modified'] ?? array() )
6024 + count( $last_results['suspicious'] ?? array() )
6025 + count( $last_results['extra'] ?? array() )
6026 + count( $ignored_files );
6027 }
6028 if ( $scanned_total > 0 ) {
6029 printf(
6030 /* translators: 1: date and time of last scan, 2: formatted file count */
6031 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6032 esc_html( wp_date( $datetime_format, $last_scan ) ),
6033 esc_html( number_format_i18n( $scanned_total ) )
6034 );
6035 } else {
6036 printf(
6037 /* translators: %s: date and time of last scan */
6038 esc_html__( 'Last scan: %s', 'vigilante' ),
6039 esc_html( wp_date( $datetime_format, $last_scan ) )
6040 );
6041 }
6042 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6043 echo ' &middot; ';
6044 printf(
6045 /* translators: %s: date and time of last closed plugins check */
6046 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6047 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6048 );
6049 }
6050 ?>
6051 </p>
6052 <?php elseif ( $closed_last_check > 0 ) : ?>
6053 <p>
6054 <?php
6055 printf(
6056 /* translators: %s: date and time of last closed plugins check */
6057 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6058 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6059 );
6060 ?>
6061 </p>
6062 <?php endif; ?>
6063 <div id="vigilante-last-scan-results">
6064 <?php if ( $last_results || $has_closed ) : ?>
6065 <div class="vigilante-scan-summary">
6066 <?php if ( $last_results ) : ?>
6067 <div class="vigilante-scan-stat vigilante-stat-ok">
6068 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6069 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6070 </div>
6071 <div class="vigilante-scan-stat vigilante-stat-modified">
6072 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6073 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6074 </div>
6075 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6076 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6077 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6078 </div>
6079 <div class="vigilante-scan-stat vigilante-stat-extra">
6080 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6081 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6082 </div>
6083 <?php endif; ?>
6084 <?php if ( $has_closed ) : ?>
6085 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6086 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6087 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6088 </div>
6089 <?php endif; ?>
6090 <?php if ( ! empty( $ignored_files ) ) : ?>
6091 <div class="vigilante-scan-stat vigilante-stat-ignored">
6092 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6093 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6094 </div>
6095 <?php endif; ?>
6096 </div>
6097
6098 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6099 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6100 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6101 <p class="description" style="color: #d63638;"><?php esc_html_e( '&#9888; Warning: These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ); ?></p>
6102 <div class="vigilante-fi-bulk-bar">
6103 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6104 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6105 </div>
6106 <div class="vigilante-fi-pagination-wrap"></div>
6107 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6108 <thead>
6109 <tr>
6110 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
6111 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6112 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6113 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6114 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6115 </tr>
6116 </thead>
6117 <tbody>
6118 <?php
6119 foreach ( $last_results['suspicious'] as $item ) {
6120 $file_path = '';
6121 $file_reason = __( 'Unknown', 'vigilante' );
6122 $file_type = 'unknown';
6123
6124 if ( is_array( $item ) ) {
6125 if ( isset( $item['file'] ) ) {
6126 $file_path = $item['file'];
6127 }
6128 if ( isset( $item['reason'] ) ) {
6129 $file_reason = $item['reason'];
6130 }
6131 if ( isset( $item['type'] ) ) {
6132 $file_type = $item['type'];
6133 }
6134 } else {
6135 $file_path = (string) $item;
6136 }
6137 ?>
6138 <tr>
6139 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6140 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6141 <td><?php echo esc_html( $file_reason ); ?></td>
6142 <td><?php echo esc_html( $file_type ); ?></td>
6143 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
6144 </tr>
6145 <?php
6146 }
6147 ?>
6148 </tbody>
6149 </table>
6150 </div>
6151 <?php endif; ?>
6152
6153 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6154 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6155 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6156 <p class="description"><?php esc_html_e( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org. May be legitimate customizations or injected backdoors.', 'vigilante' ); ?></p>
6157 <div class="vigilante-fi-bulk-bar">
6158 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6159 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6160 </div>
6161 <div class="vigilante-fi-pagination-wrap"></div>
6162 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6163 <thead>
6164 <tr>
6165 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
6166 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6167 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6168 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6169 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6170 </tr>
6171 </thead>
6172 <tbody>
6173 <?php
6174 foreach ( $last_results['extra'] as $item ) {
6175 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6176 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6177 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6178 ?>
6179 <tr>
6180 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6181 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6182 <td><?php echo esc_html( $file_reason ); ?></td>
6183 <td><?php echo esc_html( $file_type ); ?></td>
6184 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
6185 </tr>
6186 <?php
6187 }
6188 ?>
6189 </tbody>
6190 </table>
6191 </div>
6192 <?php endif; ?>
6193
6194 <?php
6195 // Split critical config files from regular modified files.
6196 // Computed unconditionally so the three sub-sections that consume
6197 // these arrays (Critical Config, Closed + Removed, Modified Files)
6198 // can render independently and in the order the team picked.
6199 $critical_modified = array();
6200 $regular_modified = array();
6201 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6202 foreach ( $last_results['modified'] as $item ) {
6203 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6204 $critical_modified[] = $item;
6205 } else {
6206 $regular_modified[] = $item;
6207 }
6208 }
6209 }
6210 ?>
6211
6212 <?php if ( ! empty( $critical_modified ) ) : ?>
6213 <div class="vigilante-file-list vigilante-critical-config-files">
6214 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6215 <p class="description">
6216 <?php esc_html_e( 'These files are common targets for code injection. Review the changes and approve if they are legitimate. Vigilant\'s own blocks are excluded from this check.', 'vigilante' ); ?>
6217 </p>
6218 <table class="wp-list-table widefat fixed striped">
6219 <thead>
6220 <tr>
6221 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6222 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6223 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6224 </tr>
6225 </thead>
6226 <tbody>
6227 <?php foreach ( $critical_modified as $crit_item ) :
6228 $crit_file = $crit_item['file'] ?? '';
6229 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6230 $crit_current_size = $crit_item['current_size'] ?? 0;
6231 $crit_diff = $crit_item['diff'] ?? array();
6232 $crit_id = sanitize_html_class( $crit_file );
6233 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6234 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6235 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6236 ?>
6237 <tr>
6238 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6239 <td>
6240 <?php if ( ! $diff_unavailable ) : ?>
6241 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6242 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6243 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6244 <?php endif; ?>
6245 <small style="color: #50575e;">
6246 <?php
6247 printf(
6248 /* translators: 1: baseline size, 2: current size */
6249 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6250 esc_html( number_format_i18n( $crit_baseline_size ) ),
6251 esc_html( number_format_i18n( $crit_current_size ) )
6252 );
6253 ?>
6254 </small>
6255 </td>
6256 <td>
6257 <button type="button" class="button button-small vigilante-toggle-critical-content" data-target="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" data-label-show="<?php esc_attr_e( 'Review changes', 'vigilante' ); ?>" data-label-hide="<?php esc_attr_e( 'Hide changes', 'vigilante' ); ?>">
6258 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6259 </button>
6260 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6261 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6262 </button>
6263 </td>
6264 </tr>
6265 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6266 <td colspan="3" style="padding: 0;">
6267 <div class="vigilante-critical-content" style="max-height: 400px; overflow: auto; background: #fff; padding: 10px; font-size: 12px; line-height: 1.5; font-family: Consolas, Monaco, monospace; border-top: 1px solid #c3c4c7;">
6268 <?php if ( $diff_unavailable ) : ?>
6269 <p style="color: #50575e; font-style: italic; margin: 0;">
6270 <?php esc_html_e( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ); ?>
6271 </p>
6272 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6273 <p style="color: #50575e; font-style: italic; margin: 0;">
6274 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6275 </p>
6276 <?php else : ?>
6277 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6278 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6279 <div style="background: #fbeaea; color: #b32d2e; padding: 1px 4px; white-space: pre-wrap; word-wrap: break-word;"><span style="display: inline-block; width: 50px; color: #999; user-select: none;"><?php echo (int) $rline['line']; ?></span>- <?php echo esc_html( $rline['content'] ); ?></div>
6280 <?php endforeach; ?>
6281 <?php endif; ?>
6282 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6283 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6284 <div style="background: #e6f4e9; color: #007017; padding: 1px 4px; white-space: pre-wrap; word-wrap: break-word;"><span style="display: inline-block; width: 50px; color: #999; user-select: none;"><?php echo (int) $aline['line']; ?></span>+ <?php echo esc_html( $aline['content'] ); ?></div>
6285 <?php endforeach; ?>
6286 <?php endif; ?>
6287 <?php endif; ?>
6288 </div>
6289 </td>
6290 </tr>
6291 <?php endforeach; ?>
6292 </tbody>
6293 </table>
6294 </div>
6295 <?php endif; ?>
6296
6297 <?php if ( $has_closed ) : ?>
6298 <div class="vigilante-file-list vigilante-closed-plugins">
6299 <h3 style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6300 <p class="description" style="color: #d63638;">
6301 <?php esc_html_e( '&#9888; Warning: These plugins have been closed in the WordPress.org repository. Closures usually indicate malware, security issues, guideline violations, or supply chain attacks. Uninstall and replace as soon as possible.', 'vigilante' ); ?>
6302 </p>
6303 <table class="wp-list-table widefat striped">
6304 <thead>
6305 <tr>
6306 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6307 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6308 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6309 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6310 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6311 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6312 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6313 </tr>
6314 </thead>
6315 <tbody>
6316 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6317 $cp_state = $cp_entry['state'] ?? '';
6318 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6319 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6320 $cp_reason = '';
6321 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6322 $cp_reason = $cp_entry['closed_reason_text'];
6323 } elseif ( 'removed' === $cp_state ) {
6324 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6325 }
6326 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6327 ?>
6328 <tr>
6329 <td>
6330 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6331 <a href="<?php echo esc_url( 'https://wordpress.org/plugins/' . $cp_slug . '/' ); ?>" target="_blank" rel="noopener noreferrer"><code style="color: #50575e;"><?php echo esc_html( $cp_slug ); ?></code></a>
6332 </td>
6333 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6334 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6335 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6336 <td><?php echo esc_html( $cp_reason ); ?></td>
6337 <td>
6338 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6339 </td>
6340 <td>
6341 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6342 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6343 </button>
6344 </td>
6345 </tr>
6346 <?php endforeach; ?>
6347 </tbody>
6348 </table>
6349 </div>
6350 <?php endif; ?>
6351
6352 <?php if ( ! empty( $regular_modified ) ) : ?>
6353 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6354 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6355 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6356 <div class="vigilante-fi-bulk-bar">
6357 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6358 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6359 </div>
6360 <div class="vigilante-fi-pagination-wrap"></div>
6361 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6362 <thead>
6363 <tr>
6364 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
6365 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6366 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6367 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6368 </tr>
6369 </thead>
6370 <tbody>
6371 <?php
6372 foreach ( $regular_modified as $item ) {
6373 $file_path = '';
6374 $file_type = 'unknown';
6375
6376 if ( is_array( $item ) ) {
6377 if ( isset( $item['file'] ) ) {
6378 $file_path = $item['file'];
6379 }
6380 if ( isset( $item['type'] ) ) {
6381 $file_type = $item['type'];
6382 }
6383 } else {
6384 $file_path = (string) $item;
6385 }
6386 ?>
6387 <tr>
6388 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6389 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6390 <td><?php echo esc_html( $file_type ); ?></td>
6391 <td><button type="button" class="button button-small vigilante-ignore-file" data-file="<?php echo esc_attr( $file_path ); ?>"><?php esc_html_e( 'Ignore', 'vigilante' ); ?></button></td>
6392 </tr>
6393 <?php
6394 }
6395 ?>
6396 </tbody>
6397 </table>
6398 </div>
6399 <?php endif; ?>
6400
6401 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6402 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6403 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6404 </p>
6405 <?php endif; ?>
6406 <?php endif; ?>
6407 </div>
6408 </div>
6409 <?php endif; ?>
6410
6411 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6412 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6413 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6414 <p class="description"><?php esc_html_e( 'These plugins remain closed/removed in WordPress.org but you have chosen to hide them from the main list and from email alerts. They are still installed on the site and still running their code &mdash; the silencing is purely cosmetic.', 'vigilante' ); ?></p>
6415 <table class="wp-list-table widefat fixed striped">
6416 <thead>
6417 <tr>
6418 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6419 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6420 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6421 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6422 </tr>
6423 </thead>
6424 <tbody>
6425 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6426 $icp_state = $icp_entry['state'] ?? '';
6427 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6428 ?>
6429 <tr>
6430 <td>
6431 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6432 <a href="<?php echo esc_url( 'https://wordpress.org/plugins/' . $icp_slug . '/' ); ?>" target="_blank" rel="noopener noreferrer"><code style="color: #50575e;"><?php echo esc_html( $icp_slug ); ?></code></a>
6433 </td>
6434 <td><?php echo esc_html( $icp_state_label ); ?></td>
6435 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6436 <td>
6437 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6438 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6439 </button>
6440 </td>
6441 </tr>
6442 <?php endforeach; ?>
6443 </tbody>
6444 </table>
6445 <p style="margin-top: 10px;">
6446 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6447 </p>
6448 </div>
6449 <?php endif; ?>
6450
6451 <?php if ( ! empty( $ignored_files ) ) : ?>
6452 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6453 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6454 <p class="description"><?php esc_html_e( 'These files are excluded from scan results and email notifications. They will still be scanned but any findings will be hidden.', 'vigilante' ); ?></p>
6455 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6456 <div class="vigilante-fi-bulk-bar">
6457 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6458 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6459 </div>
6460 <div class="vigilante-fi-pagination-wrap"></div>
6461 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6462 <thead>
6463 <tr>
6464 <td class="manage-column column-cb check-column"><input type="checkbox" class="vigilante-fi-cb-all" aria-label="<?php esc_attr_e( 'Select all', 'vigilante' ); ?>"></td>
6465 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6466 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6467 </tr>
6468 </thead>
6469 <tbody>
6470 <?php foreach ( $ignored_files as $file ) : ?>
6471 <tr>
6472 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6473 <td><code><?php echo esc_html( $file ); ?></code></td>
6474 <td><button type="button" class="button button-small vigilante-unignore-file" data-file="<?php echo esc_attr( $file ); ?>"><?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?></button></td>
6475 </tr>
6476 <?php endforeach; ?>
6477 </tbody>
6478 </table>
6479 </div>
6480 <p style="margin-top: 10px;">
6481 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6482 </p>
6483 </div>
6484 <?php endif; ?>
6485 <?php
6486 }
6487
6488 /**
6489 * Render sidebar with promotional widgets
6490 */
6491 private function render_sidebar() {
6492 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6493 $promo_banner->render();
6494 }
6495
6496 /**
6497 * AJAX: Download a ZIP backup of the critical config files.
6498 *
6499 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6500 * downloadable archive. Config backups are no longer left as files under the
6501 * web root, so this hands the admin the archive directly.
6502 */
6503 public function ajax_download_files_backup() {
6504 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6505
6506 if ( ! current_user_can( 'manage_options' ) ) {
6507 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6508 }
6509
6510 $backup_manager = new Vigilante_Backup_Manager();
6511 $result = $backup_manager->stream_files_zip();
6512
6513 // stream_files_zip() exits on success; only a WP_Error returns here.
6514 if ( is_wp_error( $result ) ) {
6515 wp_die( esc_html( $result->get_error_message() ), 500 );
6516 }
6517 }
6518
6519 /**
6520 * AJAX: Save settings
6521 */
6522 public function ajax_save_settings() {
6523 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6524
6525 if ( ! current_user_can( 'manage_options' ) ) {
6526 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6527 }
6528
6529 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6530
6531 // Handle $_POST['data'] based on type
6532 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6533 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6534 } elseif ( isset( $_POST['data'] ) ) {
6535 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6536 $raw_data = wp_unslash( $_POST['data'] );
6537 parse_str( $raw_data, $data );
6538 $data = map_deep( $data, 'sanitize_textarea_field' );
6539 } else {
6540 $data = array();
6541 }
6542
6543 if ( empty( $section ) ) {
6544 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6545 }
6546
6547 // Check if 2FA is being enabled or method changed (for notification sending)
6548 $send_2fa_notification = false;
6549 $send_login_url_notification = false;
6550
6551 if ( 'login_security' === $section ) {
6552 // Read old state from DB
6553 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6554 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6555 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6556
6557 // Check new state from submitted data
6558 $new_2fa_enabled = false;
6559 $notify_on_enable = false;
6560 $new_method = isset( $data['login_security']['two_factor']['method'] )
6561 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6562 : 'email';
6563
6564 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6565 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6566 }
6567 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6568 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6569 }
6570
6571 // Send notification if:
6572 // 1. 2FA is being enabled (was off, now on) OR
6573 // 2. Method changed while 2FA is enabled
6574 if ( $notify_on_enable && $new_2fa_enabled ) {
6575 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6576 $send_2fa_notification = true;
6577 }
6578 }
6579
6580 // Check if login URL changed and notification is enabled
6581 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6582 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6583 ? sanitize_title( $data['login_security']['custom_login_url'] )
6584 : '';
6585 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6586 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6587 : false;
6588
6589 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6590 $send_login_url_notification = true;
6591 }
6592 }
6593
6594 // Get defaults
6595 $defaults = $this->settings->get_default_options();
6596
6597 // Read ONLY saved options from database (not merged with defaults)
6598 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6599
6600 $rejected_ips = array();
6601
6602 // Handle modules
6603 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6604 if ( ! isset( $saved_options['modules'] ) ) {
6605 $saved_options['modules'] = array();
6606 }
6607 foreach ( $data['modules'] as $module => $enabled ) {
6608 $module = sanitize_key( $module );
6609 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6610 }
6611 // Clear active preset when modules change
6612 update_option( 'vigilante_active_preset', '' );
6613 } else {
6614 // Process primary section
6615 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6616 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6617 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6618
6619 // Process the submitted data
6620 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6621
6622 // The IP boxes are free text and, until 2.9.9, whatever was typed
6623 // went straight into the option. An entry the matcher can never
6624 // match still sits in a security list looking like protection,
6625 // so the ones that cannot match are dropped and reported back
6626 // instead of being stored in silence.
6627 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6628
6629 // Save the processed section
6630 $saved_options[ $section ] = $processed;
6631
6632 // Clear active preset when any section settings change
6633 update_option( 'vigilante_active_preset', '' );
6634 }
6635 }
6636
6637 // Clear cache before saving
6638 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6639
6640 // Save to database
6641 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6642
6643 // Clear the settings cache
6644 $this->settings->clear_cache();
6645
6646 // Apply changes based on section
6647 $this->apply_section_changes( $section, $saved_options );
6648
6649 // Send 2FA notifications after settings are saved
6650 $notification_result = null;
6651 if ( $send_2fa_notification ) {
6652 $notification_result = $this->send_2fa_enable_notifications();
6653 }
6654
6655 // Send login URL notifications after settings are saved
6656 $login_url_result = null;
6657 if ( $send_login_url_notification ) {
6658 $login_url_result = $this->send_login_url_notifications();
6659 }
6660
6661 // Build success message
6662 $message = __( 'Settings saved successfully.', 'vigilante' );
6663
6664 if ( $notification_result && $notification_result['sent'] > 0 ) {
6665 $message .= ' ' . sprintf(
6666 /* translators: %d: Number of emails sent */
6667 _n(
6668 '2FA notification sent to %d user.',
6669 '2FA notifications sent to %d users.',
6670 $notification_result['sent'],
6671 'vigilante'
6672 ),
6673 $notification_result['sent']
6674 );
6675 }
6676
6677 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6678 $message .= ' ' . sprintf(
6679 /* translators: %d: Number of emails sent */
6680 _n(
6681 'Login URL notification sent to %d user.',
6682 'Login URL notifications sent to %d users.',
6683 $login_url_result['sent'],
6684 'vigilante'
6685 ),
6686 $login_url_result['sent']
6687 );
6688 }
6689
6690 if ( ! empty( $rejected_ips ) ) {
6691 $message .= ' ' . sprintf(
6692 /* translators: %s: comma separated list of the entries that were not saved. */
6693 _n(
6694 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6695 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6696 count( $rejected_ips ),
6697 'vigilante'
6698 ),
6699 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6700 );
6701 }
6702
6703 wp_send_json_success( $message );
6704 }
6705
6706 /**
6707 * Keep only the IP patterns the matcher can actually match
6708 *
6709 * @since 2.9.9
6710 *
6711 * @param string $section Section being saved.
6712 * @param array $processed Section data, edited in place.
6713 * @return array Entries that were dropped, for the message back to the user.
6714 */
6715 private function filter_ip_lists( $section, &$processed ) {
6716 $lists = array(
6717 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6718 'login_security' => array( 'ip_whitelist' ),
6719 );
6720
6721 if ( ! isset( $lists[ $section ] ) ) {
6722 return array();
6723 }
6724
6725 $rejected = array();
6726
6727 foreach ( $lists[ $section ] as $key ) {
6728 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6729 continue;
6730 }
6731
6732 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6733 $processed[ $key ] = $split['valid'];
6734 $rejected = array_merge( $rejected, $split['rejected'] );
6735 }
6736
6737 return array_values( array_unique( $rejected ) );
6738 }
6739
6740 /**
6741 * Send 2FA enable notifications to users
6742 *
6743 * @return array Result with 'sent' and 'failed' counts.
6744 */
6745 private function send_2fa_enable_notifications() {
6746 $result = array(
6747 'sent' => 0,
6748 'failed' => 0,
6749 );
6750
6751 // Get settings for roles and method
6752 $login_security = $this->settings->get_section( 'login_security' );
6753 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6754 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6755 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6756
6757 if ( empty( $roles ) ) {
6758 $roles = array( 'administrator' );
6759 }
6760
6761 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6762
6763 // Get users with these roles
6764 $args = array(
6765 'role__in' => $roles,
6766 );
6767 if ( ! empty( $excluded ) ) {
6768 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6769 $args['exclude'] = $excluded;
6770 }
6771 $users = get_users( $args );
6772
6773 if ( empty( $users ) ) {
6774 return $result;
6775 }
6776
6777 $site_name = get_bloginfo( 'name' );
6778 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6779
6780 if ( 'totp' === $method ) {
6781 // Use TOTP class for styled HTML emails
6782 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6783 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6784 }
6785 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6786
6787 foreach ( $users as $user ) {
6788 // Skip users who already have TOTP configured
6789 $totp_data = $this->database->get_totp_data( $user->ID );
6790 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6791 continue;
6792 }
6793
6794 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6795
6796 if ( $sent ) {
6797 $this->database->mark_2fa_notified( $user->ID );
6798 $result['sent']++;
6799 } else {
6800 $result['failed']++;
6801 }
6802 }
6803 } else {
6804 // Email method - use existing email 2FA class
6805 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6806 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6807 }
6808 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6809 return $email_2fa->send_activation_notifications( false );
6810 }
6811
6812 return $result;
6813 }
6814
6815 /**
6816 * Send login URL change notifications to users with admin access
6817 *
6818 * @return array Result with 'sent' and 'failed' counts.
6819 */
6820 private function send_login_url_notifications() {
6821 $login_options = $this->settings->get_section( 'login_security' );
6822 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6823
6824 if ( empty( $custom_url ) ) {
6825 return array( 'sent' => 0, 'failed' => 0 );
6826 }
6827
6828 $login_url = home_url( $custom_url . '/' );
6829 $site_name = get_bloginfo( 'name' );
6830
6831 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6832 $users = get_users( array( 'role__in' => $admin_roles ) );
6833
6834 if ( empty( $users ) ) {
6835 return array( 'sent' => 0, 'failed' => 0 );
6836 }
6837
6838 $subject = sprintf(
6839 /* translators: %s: Site name */
6840 __( '[%s] Your login URL has changed', 'vigilante' ),
6841 $site_name
6842 );
6843
6844 $body = Vigilante_Email_Template::p( __( 'The login URL for the admin area has been changed. Please save the new URL below and use it from now on.', 'vigilante' ) );
6845 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6846 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6847 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6848
6849 $sent = 0;
6850 $failed = 0;
6851
6852 foreach ( $users as $user ) {
6853 $result = Vigilante_Email_Template::send(
6854 $user->user_email,
6855 $subject,
6856 __( 'Login URL changed', 'vigilante' ),
6857 $body
6858 );
6859 if ( $result ) {
6860 $sent++;
6861 } else {
6862 $failed++;
6863 }
6864 }
6865
6866 if ( $this->activity_log ) {
6867 $this->activity_log->log(
6868 'login',
6869 'login_url_notified',
6870 sprintf(
6871 /* translators: 1: Sent count, 2: Failed count */
6872 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
6873 $sent,
6874 $failed
6875 )
6876 );
6877 }
6878
6879 return array( 'sent' => $sent, 'failed' => $failed );
6880 }
6881
6882 /**
6883 * Process section data maintaining proper types from defaults
6884 *
6885 * @param array $submitted_data Data submitted from form.
6886 * @param array $defaults Default values for this section.
6887 * @param array $current Current saved values.
6888 * @param string $section_name Section name for special handling.
6889 * @return array Processed data.
6890 */
6891 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
6892 // Start with defaults, then merge current saved values
6893 $result = array_replace_recursive( $defaults, $current );
6894
6895 // Process each submitted value
6896 foreach ( $submitted_data as $key => $value ) {
6897 $key = sanitize_key( $key );
6898
6899 if ( is_array( $value ) ) {
6900 // Nested array (like rate_limiting)
6901 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
6902 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
6903 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
6904 } else {
6905 // Determine type from default value
6906 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
6907
6908 if ( null === $default_value ) {
6909 // No default, check current value type or use as string
6910 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
6911 if ( is_bool( $current_value ) ) {
6912 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6913 } elseif ( is_int( $current_value ) ) {
6914 $result[ $key ] = intval( $value );
6915 } elseif ( is_array( $current_value ) ) {
6916 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
6917 } else {
6918 $result[ $key ] = sanitize_text_field( $value );
6919 }
6920 } elseif ( is_bool( $default_value ) ) {
6921 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
6922 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6923 } elseif ( is_int( $default_value ) ) {
6924 // Integer - with special handling for time fields shown in minutes
6925 $int_value = intval( $value );
6926
6927 // Convert minutes to seconds for login_security duration fields
6928 // These are displayed as minutes in the form but stored as seconds
6929 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
6930 $int_value = $int_value * 60;
6931 }
6932
6933 $result[ $key ] = $int_value;
6934 } elseif ( is_array( $default_value ) ) {
6935 // Array from textarea (e.g., IP lists)
6936 if ( is_string( $value ) ) {
6937 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
6938 } else {
6939 $result[ $key ] = (array) $value;
6940 }
6941 } else {
6942 // String - preserve newlines for textarea fields
6943 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
6944 $result[ $key ] = sanitize_textarea_field( $value );
6945 } else {
6946 $result[ $key ] = sanitize_text_field( $value );
6947 }
6948 }
6949 }
6950 }
6951
6952 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
6953 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
6954 //
6955 // EXCEPTION: the top-level 'enabled' flag of every section is the
6956 // module's master switch and is controlled by the Dashboard module
6957 // toggle, NOT by a checkbox inside the section's form. Treating it
6958 // like a regular checkbox here would silently switch the module off
6959 // every time the user saves the tab — see the REST API enabled=false
6960 // regression. We only skip it at the top level (when section_name is
6961 // empty); nested 'enabled' fields like security_headers.csp.enabled
6962 // are real checkboxes and must keep the auto-unset behaviour.
6963 $preserve_top_level = array( 'enabled' );
6964
6965 foreach ( $defaults as $key => $default_value ) {
6966 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
6967 continue;
6968 }
6969 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
6970 $result[ $key ] = false;
6971 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
6972 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
6973 // vs a nested settings group (like rate_limiting, two_factor)
6974 // Flat lists: default is empty array OR all values are scalar
6975 $is_value_list = empty( $default_value );
6976 if ( ! $is_value_list ) {
6977 $is_value_list = true;
6978 foreach ( $default_value as $dv ) {
6979 if ( ! is_scalar( $dv ) ) {
6980 $is_value_list = false;
6981 break;
6982 }
6983 }
6984 }
6985
6986 if ( $is_value_list ) {
6987 // All items removed - reset to empty array
6988 $result[ $key ] = array();
6989 } else {
6990 // Nested settings group - handle boolean children
6991 foreach ( $default_value as $nested_key => $nested_default ) {
6992 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
6993 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
6994 ? $submitted_data[ $key ]
6995 : array();
6996 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
6997 $result[ $key ][ $nested_key ] = false;
6998 }
6999 }
7000 }
7001 }
7002 }
7003 }
7004
7005 return $result;
7006 }
7007
7008 /**
7009 * AJAX: Export settings
7010 */
7011 public function ajax_export_settings() {
7012 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7013
7014 if ( ! current_user_can( 'manage_options' ) ) {
7015 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7016 }
7017
7018 $options = $this->settings->get_all_options();
7019 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7020
7021 wp_send_json_success( array(
7022 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7023 'filename' => $filename,
7024 ) );
7025 }
7026
7027 /**
7028 * AJAX: Import settings
7029 */
7030 public function ajax_import_settings() {
7031 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7032
7033 if ( ! current_user_can( 'manage_options' ) ) {
7034 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7035 }
7036
7037 // Accept both 'settings' (from JS) and 'content' (legacy).
7038 // Do NOT run sanitize_text_field() on the raw payload: it calls
7039 // wp_strip_all_tags() internally, which removes any "<...>" substring
7040 // and turns a valid export JSON into garbage if any stored value
7041 // contains < or > (htaccess snippets, email templates, etc.). The
7042 // real sanitization happens after json_decode(), via map_deep() on
7043 // the parsed array.
7044 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7045 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7046 if ( empty( $content ) ) {
7047 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7048 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7049 }
7050
7051 if ( empty( $content ) || ! is_string( $content ) ) {
7052 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7053 }
7054
7055 $imported = json_decode( $content, true );
7056
7057 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7058 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7059 }
7060
7061 // Sanitize imported data recursively
7062 $imported = map_deep( $imported, 'sanitize_text_field' );
7063
7064 // Validate structure
7065 $defaults = $this->settings->get_default_options();
7066 $merged = array_replace_recursive( $defaults, $imported );
7067
7068 // Save
7069 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7070 $this->settings->clear_cache();
7071
7072 // Re-evaluate the active preset marker. The imported config may match
7073 // a known preset exactly, partially, or not at all — without this step
7074 // the dashboard would keep showing whatever preset was active before
7075 // the import even if the new config no longer matches it.
7076 $matched_preset = $this->detect_matching_preset( $merged );
7077 if ( null === $matched_preset ) {
7078 delete_option( 'vigilante_active_preset' );
7079 } else {
7080 update_option( 'vigilante_active_preset', $matched_preset );
7081 }
7082
7083 // Apply file changes after import
7084 $this->apply_all_file_changes( $merged );
7085
7086 // Refresh the Security Analyzer score so the dashboard widget reflects
7087 // the imported config rather than the pre-import scan. Reuse the
7088 // post-Under-Attack scan hook (same job: full scan, async).
7089 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7090 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7091 }
7092
7093 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
7094 }
7095
7096 /**
7097 * Detect whether a vigilante_options array matches a known preset.
7098 *
7099 * A preset matches when every field the preset explicitly declares is
7100 * present in the config with the same (normalised) value. Fields outside
7101 * the preset are ignored — they may have been modified by the user before
7102 * applying the preset and do not invalidate the match. This mirrors how
7103 * apply_preset() now layers presets on top of the user's existing config.
7104 *
7105 * @param array $options The current/imported vigilante_options.
7106 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7107 */
7108 private function detect_matching_preset( $options ) {
7109 if ( ! is_array( $options ) ) {
7110 return null;
7111 }
7112
7113 $presets = $this->settings->get_presets();
7114
7115 foreach ( $presets as $preset_id => $preset_data ) {
7116 unset( $preset_data['name'], $preset_data['description'] );
7117 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7118 return $preset_id;
7119 }
7120 }
7121
7122 return null;
7123 }
7124
7125 /**
7126 * Check whether every leaf value inside $preset_subset exists with the
7127 * same (normalised) value at the same path inside $config.
7128 *
7129 * @param mixed $preset_subset Branch of the preset definition.
7130 * @param mixed $config Same branch in the live/imported config.
7131 * @return bool
7132 */
7133 private function preset_subset_matches( $preset_subset, $config ) {
7134 if ( is_array( $preset_subset ) ) {
7135 if ( ! is_array( $config ) ) {
7136 return false;
7137 }
7138 foreach ( $preset_subset as $key => $value ) {
7139 if ( ! array_key_exists( $key, $config ) ) {
7140 return false;
7141 }
7142 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7143 return false;
7144 }
7145 }
7146 return true;
7147 }
7148
7149 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7150 }
7151
7152 /**
7153 * Normalise a scalar value so that the variants WordPress and the form
7154 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7155 * null → "") compare equal. Other values become strings unchanged.
7156 *
7157 * @param mixed $value
7158 * @return string
7159 */
7160 private function normalise_scalar_for_compare( $value ) {
7161 if ( is_bool( $value ) ) {
7162 return $value ? '1' : '';
7163 }
7164 if ( null === $value ) {
7165 return '';
7166 }
7167 if ( is_int( $value ) || is_float( $value ) ) {
7168 return (string) $value;
7169 }
7170 if ( is_string( $value ) ) {
7171 if ( 'true' === $value ) {
7172 return '1';
7173 }
7174 if ( 'false' === $value ) {
7175 return '';
7176 }
7177 return $value;
7178 }
7179 // Arrays and objects shouldn't reach here (handled by recursion above),
7180 // but if they do, fall back to a stable comparable representation.
7181 return wp_json_encode( $value );
7182 }
7183
7184 /**
7185 * AJAX: Apply preset
7186 */
7187 public function ajax_apply_preset() {
7188 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7189
7190 if ( ! current_user_can( 'manage_options' ) ) {
7191 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7192 }
7193
7194 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7195
7196 // Handle reset to defaults
7197 if ( 'reset' === $preset ) {
7198 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7199 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7200 $this->settings->clear_cache();
7201
7202 // Clear active preset
7203 update_option( 'vigilante_active_preset', '' );
7204
7205 // Apply file changes after reset
7206 $this->apply_all_file_changes( $defaults );
7207
7208 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
7209 return;
7210 }
7211
7212 $presets = $this->settings->get_presets();
7213
7214 if ( ! isset( $presets[ $preset ] ) ) {
7215 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7216 }
7217
7218 $preset_options = $presets[ $preset ];
7219 unset( $preset_options['name'], $preset_options['description'] );
7220
7221 // Layer the preset on top of the user's CURRENT configuration, not on
7222 // top of defaults. This way applying a preset only changes the fields
7223 // the preset explicitly mentions; everything else stays as the user
7224 // had it. For example, applying Maximum will not flip HSTS off if the
7225 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7226 // Use "Reset to Defaults" if a clean slate is needed.
7227 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7228 if ( ! is_array( $current ) ) {
7229 $current = array();
7230 }
7231 // Make sure all known keys exist before merging — the merge does not
7232 // invent keys that are missing on both sides.
7233 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7234
7235 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7236
7237 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7238 $this->settings->clear_cache();
7239
7240 // Save active preset
7241 update_option( 'vigilante_active_preset', $preset );
7242
7243 // Apply file changes after preset
7244 $this->apply_all_file_changes( $merged );
7245
7246 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
7247 }
7248
7249 /**
7250 * AJAX: Reset a specific section to defaults
7251 */
7252 public function ajax_reset_section() {
7253 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7254
7255 if ( ! current_user_can( 'manage_options' ) ) {
7256 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7257 }
7258
7259 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7260
7261 if ( empty( $section ) ) {
7262 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7263 }
7264
7265 // Get current options and defaults. get_defaults_preserving_user_data()
7266 // applies the tweaks a fresh installation gets, so the button and a new
7267 // install agree, and keeps whatever the owner typed in.
7268 $current_options = $this->settings->get_all_options();
7269 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7270
7271 // Check if section exists in defaults
7272 if ( ! isset( $defaults[ $section ] ) ) {
7273 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7274 }
7275
7276 $new_values = $defaults[ $section ];
7277
7278 /*
7279 * On a subsite, the settings written to wp-config.php and .htaccess are
7280 * the main site's business. Resetting the local copy of those would only
7281 * make this screen disagree with the file, so they are carried over
7282 * untouched, and a section that is nothing but shared settings is not
7283 * reset at all.
7284 */
7285 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7286 $shared = Vigilante_Settings::get_shared_file_settings();
7287
7288 if ( isset( $shared[ $section ] ) ) {
7289 if ( true === $shared[ $section ] ) {
7290 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7291 }
7292
7293 foreach ( $shared[ $section ] as $shared_key ) {
7294 if ( array_key_exists( $shared_key, (array) $current_options[ $section ] ) ) {
7295 $new_values[ $shared_key ] = $current_options[ $section ][ $shared_key ];
7296 }
7297 }
7298 }
7299 }
7300
7301 $current_options[ $section ] = $new_values;
7302
7303 // Save
7304 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7305 $this->settings->clear_cache();
7306
7307 // Apply file changes if needed
7308 $this->apply_section_changes( $section, $current_options );
7309
7310 wp_send_json_success( array(
7311 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7312 'section' => $section,
7313 'reload' => true,
7314 ) );
7315 }
7316
7317 /**
7318 * AJAX: Clear lockouts
7319 */
7320 public function ajax_clear_lockouts() {
7321 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7322
7323 if ( ! current_user_can( 'manage_options' ) ) {
7324 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7325 }
7326
7327 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7328
7329 if ( ! empty( $ip ) ) {
7330 $this->database->clear_lockout( $ip );
7331 } else {
7332 $this->database->clear_all_lockouts();
7333 }
7334
7335 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7336 }
7337
7338 /**
7339 * AJAX: Clear logs
7340 */
7341 public function ajax_clear_logs() {
7342 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7343
7344 if ( ! current_user_can( 'manage_options' ) ) {
7345 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7346 }
7347
7348 if ( $this->activity_log ) {
7349 $result = $this->activity_log->clear_all_logs();
7350 if ( $result ) {
7351 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7352 } else {
7353 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7354 }
7355 } else {
7356 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7357 }
7358 }
7359
7360 /**
7361 * AJAX: Run file integrity scan.
7362 *
7363 * Triggers the file integrity scan, which now also runs the closed plugins
7364 * check at the end when the `check_closed_plugins` toggle is on. Activity
7365 * log is passed through so Security Audit entries (both file-level and
7366 * plugin-status) are recorded from this entry point.
7367 */
7368 public function ajax_run_scan() {
7369 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7370
7371 if ( ! current_user_can( 'manage_options' ) ) {
7372 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7373 }
7374
7375 // Clear previous results before running new scan
7376 delete_option( 'vigilante_last_integrity_results' );
7377 delete_option( 'vigilante_last_integrity_scan' );
7378
7379 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7380 $results = $file_integrity->run_scan();
7381
7382 // Save new results
7383 update_option( 'vigilante_last_integrity_scan', time() );
7384 update_option( 'vigilante_last_integrity_results', $results );
7385
7386 wp_send_json_success( array(
7387 'message' => __( 'Scan completed.', 'vigilante' ),
7388 'results' => $results,
7389 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7390 ) );
7391 }
7392
7393 /**
7394 * AJAX: Clear scan results.
7395 *
7396 * Wipes visually everything inside "Last Scan Results": file scan findings
7397 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7398 * Closed + Removed Plugins block.
7399 *
7400 * Implementation detail to keep persistence intact:
7401 * - We delete the file scan options + hashes outright.
7402 * - For plugin status we ONLY delete the last_check timestamp — the state
7403 * map and the ignore list are preserved in DB. The render gates the
7404 * plugin_status subsections on last_check > 0, so they hide after
7405 * Clear (visual reset) and reappear on the next Run Scan Now with the
7406 * state intact. This avoids degrading a 'removed' slug (404 without
7407 * metadata) back to 'not_in_repo' on the next scan, which would
7408 * silently lose the alert.
7409 *
7410 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7411 * are preserved on purpose; each has its own explicit "Clear All …"
7412 * button.
7413 */
7414 public function ajax_clear_scan() {
7415 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7416
7417 if ( ! current_user_can( 'manage_options' ) ) {
7418 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7419 }
7420
7421 delete_option( 'vigilante_last_integrity_results' );
7422 delete_option( 'vigilante_last_integrity_scan' );
7423
7424 if ( $this->database ) {
7425 $this->database->clear_file_hashes();
7426 }
7427
7428 // Visual reset of plugin_status block without touching the state map
7429 // or the ignored list. See PHPDoc above for the rationale.
7430 delete_option( 'vigilante_plugin_status_last_check' );
7431
7432 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7433 }
7434
7435 /**
7436 * AJAX: Ignore a file from scan results
7437 */
7438 public function ajax_ignore_file() {
7439 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7440
7441 if ( ! current_user_can( 'manage_options' ) ) {
7442 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7443 }
7444
7445 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7446
7447 if ( empty( $file ) ) {
7448 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7449 }
7450
7451 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7452 $file_integrity->ignore_file( $file );
7453
7454 // Also remove the file from stored scan results so UI updates
7455 $results = get_option( 'vigilante_last_integrity_results' );
7456 if ( $results ) {
7457 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7458 if ( ! empty( $results[ $category ] ) ) {
7459 $results[ $category ] = array_values(
7460 array_filter(
7461 $results[ $category ],
7462 function ( $item ) use ( $file ) {
7463 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7464 }
7465 )
7466 );
7467 }
7468 }
7469 update_option( 'vigilante_last_integrity_results', $results );
7470 }
7471
7472 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7473 }
7474
7475 /**
7476 * AJAX: Stop ignoring a file
7477 */
7478 public function ajax_unignore_file() {
7479 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7480
7481 if ( ! current_user_can( 'manage_options' ) ) {
7482 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7483 }
7484
7485 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7486
7487 if ( empty( $file ) ) {
7488 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7489 }
7490
7491 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7492 $file_integrity->unignore_file( $file );
7493
7494 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7495 }
7496
7497 /**
7498 * AJAX: Bulk ignore multiple files at once
7499 *
7500 * Processes a single batch into ignored list and prunes them from the
7501 * stored scan results so the UI updates without a re-scan.
7502 */
7503 public function ajax_bulk_ignore_files() {
7504 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7505
7506 if ( ! current_user_can( 'manage_options' ) ) {
7507 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7508 }
7509
7510 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7511 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7512 if ( ! is_array( $raw_files ) ) {
7513 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7514 }
7515
7516 $files = array();
7517 foreach ( $raw_files as $f ) {
7518 $clean = sanitize_text_field( $f );
7519 if ( '' !== $clean ) {
7520 $files[] = $clean;
7521 }
7522 }
7523
7524 if ( empty( $files ) ) {
7525 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7526 }
7527
7528 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7529 $count = 0;
7530 foreach ( $files as $file ) {
7531 $file_integrity->ignore_file( $file );
7532 $count++;
7533 }
7534
7535 // Also prune the stored scan results so the UI matches the new ignore list.
7536 $results = get_option( 'vigilante_last_integrity_results' );
7537 if ( $results ) {
7538 $files_set = array_flip( $files );
7539 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7540 if ( ! empty( $results[ $category ] ) ) {
7541 $results[ $category ] = array_values(
7542 array_filter(
7543 $results[ $category ],
7544 function ( $item ) use ( $files_set ) {
7545 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7546 return ! isset( $files_set[ $path ] );
7547 }
7548 )
7549 );
7550 }
7551 }
7552 update_option( 'vigilante_last_integrity_results', $results );
7553 }
7554
7555 wp_send_json_success(
7556 array(
7557 'count' => $count,
7558 'message' => sprintf(
7559 /* translators: %d: number of files added to the ignored list */
7560 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7561 $count
7562 ),
7563 )
7564 );
7565 }
7566
7567 /**
7568 * AJAX: Bulk un-ignore multiple files at once
7569 */
7570 public function ajax_bulk_unignore_files() {
7571 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7572
7573 if ( ! current_user_can( 'manage_options' ) ) {
7574 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7575 }
7576
7577 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7578 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7579 if ( ! is_array( $raw_files ) ) {
7580 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7581 }
7582
7583 $files = array();
7584 foreach ( $raw_files as $f ) {
7585 $clean = sanitize_text_field( $f );
7586 if ( '' !== $clean ) {
7587 $files[] = $clean;
7588 }
7589 }
7590
7591 if ( empty( $files ) ) {
7592 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7593 }
7594
7595 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7596 $count = 0;
7597 foreach ( $files as $file ) {
7598 $file_integrity->unignore_file( $file );
7599 $count++;
7600 }
7601
7602 wp_send_json_success(
7603 array(
7604 'count' => $count,
7605 'message' => sprintf(
7606 /* translators: %d: number of files removed from the ignored list */
7607 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7608 $count
7609 ),
7610 )
7611 );
7612 }
7613
7614 /**
7615 * AJAX: Clear all ignored files
7616 */
7617 public function ajax_clear_ignored() {
7618 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7619
7620 if ( ! current_user_can( 'manage_options' ) ) {
7621 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7622 }
7623
7624 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7625 $file_integrity->clear_ignored_files();
7626
7627 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7628 }
7629
7630 /**
7631 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7632 * main list and email digests. The plugin keeps running on the site;
7633 * silencing is purely cosmetic and reversible.
7634 */
7635 public function ajax_ignore_closed_plugin() {
7636 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7637
7638 if ( ! current_user_can( 'manage_options' ) ) {
7639 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7640 }
7641
7642 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7643 if ( '' === $slug ) {
7644 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7645 }
7646
7647 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7648 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7649 }
7650 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7651 $checker->ignore_slug( $slug );
7652
7653 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7654 }
7655
7656 /**
7657 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7658 */
7659 public function ajax_unignore_closed_plugin() {
7660 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7661
7662 if ( ! current_user_can( 'manage_options' ) ) {
7663 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7664 }
7665
7666 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7667 if ( '' === $slug ) {
7668 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7669 }
7670
7671 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7672 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7673 }
7674 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7675 $checker->unignore_slug( $slug );
7676
7677 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7678 }
7679
7680 /**
7681 * AJAX: Clear the entire ignored-closed-plugins list.
7682 */
7683 public function ajax_clear_ignored_closed_plugins() {
7684 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7685
7686 if ( ! current_user_can( 'manage_options' ) ) {
7687 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7688 }
7689
7690 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7691 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7692 }
7693 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7694 $checker->clear_ignored();
7695
7696 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7697 }
7698
7699 /**
7700 * AJAX: Test security headers
7701 */
7702 public function ajax_test_headers() {
7703 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7704
7705 if ( ! current_user_can( 'manage_options' ) ) {
7706 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7707 }
7708
7709 // Get security grade from settings (not from actual HTTP request)
7710 $security_headers = new Vigilante_Security_Headers( $this->settings );
7711 $results = $security_headers->get_security_grade();
7712
7713 wp_send_json_success( $results );
7714 }
7715
7716 /**
7717 * Sanitize section data (kept for compatibility)
7718 *
7719 * @param string $section Section name.
7720 * @param array $data Section data.
7721 * @return array
7722 */
7723 private function sanitize_section_data( $section, $data ) {
7724 $sanitized = array();
7725
7726 foreach ( $data as $key => $value ) {
7727 $key = sanitize_key( $key );
7728
7729 if ( is_array( $value ) ) {
7730 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7731 } elseif ( is_numeric( $value ) ) {
7732 $sanitized[ $key ] = intval( $value );
7733 } else {
7734 $sanitized[ $key ] = sanitize_text_field( $value );
7735 }
7736 }
7737
7738 return $sanitized;
7739 }
7740
7741 /**
7742 * Apply changes after saving settings
7743 *
7744 * @param string $section Section that was updated.
7745 * @param array $all_options All options.
7746 */
7747 private function apply_section_changes( $section, $all_options ) {
7748 // Create fresh settings instance to ensure we have the latest data
7749 $fresh_settings = new Vigilante_Settings();
7750
7751 // The shared Vigilant .htaccess block carries BOTH the firewall's
7752 // file-protection rules and the server-signature / fingerprinting rules
7753 // that are configured under Security Headers. So it must be regenerated
7754 // whenever either section (or the module toggles) changes, not only on
7755 // the firewall save — otherwise toggling "Hide server signature" or
7756 // "Remove fingerprinting headers" never reaches the .htaccess.
7757 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7758 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7759 $sh = $fresh_settings->get_section( 'security_headers' );
7760 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7761 || ! empty( $sh['hide_server_signature'] )
7762 || ! empty( $sh['remove_fingerprinting_headers'] );
7763
7764 if ( $needs_htaccess_block ) {
7765 $htaccess->apply_rules();
7766 } else {
7767 $htaccess->remove_rules();
7768 }
7769 }
7770
7771 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7772 if ( 'security_headers' === $section || 'modules' === $section ) {
7773 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7774 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7775
7776 if ( $headers_enabled ) {
7777 $security_headers->apply_rules();
7778 } else {
7779 $security_headers->remove_rules();
7780 }
7781 }
7782
7783 // Regenerate wp-config for wp_hardening section
7784 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7785 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7786 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7787
7788 if ( $hardening_enabled ) {
7789 $wpconfig->apply_security_constants();
7790 } else {
7791 $wpconfig->remove_constants();
7792 }
7793
7794 // Apply WordPress options for comments/pingbacks
7795 $hardening_options = $all_options['wp_hardening'] ?? array();
7796
7797 if ( $hardening_enabled ) {
7798 // Pingbacks
7799 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7800 update_option( 'default_pingback_flag', 0 );
7801 } else {
7802 // Restore default: pingbacks enabled
7803 update_option( 'default_pingback_flag', 1 );
7804 }
7805
7806 // Trackbacks and ping status
7807 // Only close if either pingbacks OR trackbacks are disabled
7808 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7809 update_option( 'default_ping_status', 'closed' );
7810 } else {
7811 // Restore default: pings open
7812 update_option( 'default_ping_status', 'open' );
7813 }
7814
7815 // Comment moderation
7816 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7817 update_option( 'comment_moderation', 1 );
7818 } else {
7819 // Restore default: no moderation required
7820 update_option( 'comment_moderation', 0 );
7821 }
7822 }
7823 }
7824
7825 // Trim activity log entries immediately when limits change
7826 if ( 'activity_log' === $section && $this->activity_log ) {
7827 $this->activity_log->cleanup_old_logs();
7828 }
7829
7830 // Flush rewrite rules if login URL changed
7831 if ( 'login_security' === $section ) {
7832 $login_options = $all_options['login_security'] ?? array();
7833 if ( ! empty( $login_options['custom_login_url'] ) ) {
7834 delete_option( 'vigilante_login_rules_version' );
7835 }
7836 }
7837
7838 // Log the settings change with readable section name
7839 if ( $this->activity_log ) {
7840 $section_names = array(
7841 'firewall' => __( 'Firewall', 'vigilante' ),
7842 'login_security' => __( 'Login Security', 'vigilante' ),
7843 'security_headers' => __( 'Security Headers', 'vigilante' ),
7844 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7845 'user_security' => __( 'User Security', 'vigilante' ),
7846 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7847 'activity_log' => __( 'Security Audit', 'vigilante' ),
7848 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7849 'email' => __( 'Notification Settings', 'vigilante' ),
7850 'backup' => __( 'Backup', 'vigilante' ),
7851 'advanced' => __( 'Advanced', 'vigilante' ),
7852 'modules' => __( 'Modules', 'vigilante' ),
7853 );
7854 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
7855
7856 $this->activity_log->log(
7857 'settings',
7858 'settings_updated',
7859 sprintf(
7860 /* translators: %s: Section name */
7861 __( 'Settings updated: %s', 'vigilante' ),
7862 $display_name
7863 ),
7864 array( 'section' => $section ),
7865 'info'
7866 );
7867 }
7868 }
7869
7870 /**
7871 * Apply all file changes (htaccess, wp-config) based on current options
7872 *
7873 * Used after preset, import, or reset operations
7874 *
7875 * @param array $all_options All plugin options.
7876 */
7877 private function apply_all_file_changes( $all_options ) {
7878 // Refresh settings cache first
7879 $this->settings->clear_cache();
7880
7881 // Create fresh settings instance
7882 $fresh_settings = new Vigilante_Settings();
7883
7884 // Apply firewall htaccess changes
7885 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7886 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
7887
7888 if ( $firewall_enabled ) {
7889 $htaccess->apply_rules();
7890 } else {
7891 $htaccess->remove_rules();
7892 }
7893
7894 // Apply security headers htaccess changes
7895 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7896 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7897
7898 if ( $headers_enabled ) {
7899 $security_headers->apply_rules();
7900 } else {
7901 $security_headers->remove_rules();
7902 }
7903
7904 // Apply wp-config changes
7905 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7906 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7907
7908 if ( $hardening_enabled ) {
7909 $wpconfig->apply_security_constants();
7910 } else {
7911 $wpconfig->remove_constants();
7912 }
7913
7914 // Apply WordPress options for comments/pingbacks
7915 $hardening_options = $all_options['wp_hardening'] ?? array();
7916
7917 if ( $hardening_enabled ) {
7918 // Pingbacks
7919 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7920 update_option( 'default_pingback_flag', 0 );
7921 } else {
7922 // Restore default: pingbacks enabled
7923 update_option( 'default_pingback_flag', 1 );
7924 }
7925
7926 // Trackbacks and ping status
7927 // Only close if either pingbacks OR trackbacks are disabled
7928 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7929 update_option( 'default_ping_status', 'closed' );
7930 } else {
7931 // Restore default: pings open
7932 update_option( 'default_ping_status', 'open' );
7933 }
7934
7935 // Comment moderation
7936 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7937 update_option( 'comment_moderation', 1 );
7938 } else {
7939 // Restore default: no moderation required
7940 update_option( 'comment_moderation', 0 );
7941 }
7942 }
7943
7944 // Log the change
7945 if ( $this->activity_log ) {
7946 $this->activity_log->log(
7947 'settings',
7948 'bulk_settings_applied',
7949 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
7950 array(),
7951 'info'
7952 );
7953 }
7954 }
7955 }