PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.10.4
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.10.4
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.4, at admin/class-admin.php

8,001 lines 512.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 'logRequestUri' => __( 'Address', 'vigilante' ),
1564 'logClient' => __( 'Client', 'vigilante' ),
1565 'logUser' => __( 'User', 'vigilante' ),
1566 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1567 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1568 'logIpLabel' => __( 'IP:', 'vigilante' ),
1569 'logUaLabel' => __( 'UA:', 'vigilante' ),
1570 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1571 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1572 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1573 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1574 'logAdded' => __( 'Added!', 'vigilante' ),
1575 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1576 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1577 // Activity log table strings
1578 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1579 'view' => __( 'View', 'vigilante' ),
1580 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1581 // Export logs strings
1582 'exporting' => __( 'Exporting...', 'vigilante' ),
1583 /* translators: %d: number of entries */
1584 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1585 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1586 'exportFailed' => __( 'Export failed', 'vigilante' ),
1587 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1588 // Backup strings
1589 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1590 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1591 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1592 /* translators: %d: number of tables */
1593 'tablesCount' => __( '%d tables', 'vigilante' ),
1594 /* translators: 1: table count, 2: human-readable size */
1595 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1596 /* translators: 1: selected count, 2: human-readable size */
1597 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1598 // Settings search strings
1599 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1600 /* translators: %d: number of results that did not fit in the list. */
1601 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1602 'searchInTab' => __( 'in', 'vigilante' ),
1603 // Modules string
1604 /* translators: 1: enabled count, 2: total count */
1605 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1606 // Activity log label maps for JS rendering
1607 'eventTypeLabels' => array(
1608 'login' => __( 'Login', 'vigilante' ),
1609 'user' => __( 'User', 'vigilante' ),
1610 'content' => __( 'Content', 'vigilante' ),
1611 'plugin' => __( 'Plugin', 'vigilante' ),
1612 'theme' => __( 'Theme', 'vigilante' ),
1613 'settings' => __( 'Settings', 'vigilante' ),
1614 'comment' => __( 'Comment', 'vigilante' ),
1615 'media' => __( 'Media', 'vigilante' ),
1616 'firewall' => __( 'Firewall', 'vigilante' ),
1617 'file' => __( 'File', 'vigilante' ),
1618 'security' => __( 'Security', 'vigilante' ),
1619 'system' => __( 'System', 'vigilante' ),
1620 ),
1621 'severityLabels' => array(
1622 'info' => __( 'Info', 'vigilante' ),
1623 'warning' => __( 'Warning', 'vigilante' ),
1624 'critical' => __( 'Critical', 'vigilante' ),
1625 ),
1626 // Password reset strings
1627 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1628 /* translators: %d: number of users */
1629 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1630 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1631 'processing' => __( 'Processing...', 'vigilante' ),
1632 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1633 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1634 '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' ),
1635 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1636 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1637 // Role-based password reset strings
1638 /* translators: %d: number of users */
1639 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1640 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1641 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1642 // User approval strings
1643 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1644 'approve' => __( 'Approve', 'vigilante' ),
1645 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1646 'reject' => __( 'Reject', 'vigilante' ),
1647 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1648 // Session management strings
1649 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1650 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1651 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1652 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1653 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1654 'noSessions' => __( 'No active sessions', 'vigilante' ),
1655 'revoke' => __( 'Revoke', 'vigilante' ),
1656 'noUsers' => __( 'No users found', 'vigilante' ),
1657 // Time ago strings
1658 'timeYear' => __( 'year', 'vigilante' ),
1659 'timeYears' => __( 'years', 'vigilante' ),
1660 'timeMonth' => __( 'month', 'vigilante' ),
1661 'timeMonths' => __( 'months', 'vigilante' ),
1662 'timeDay' => __( 'day', 'vigilante' ),
1663 'timeDays' => __( 'days', 'vigilante' ),
1664 'timeHour' => __( 'hour', 'vigilante' ),
1665 'timeHours' => __( 'hours', 'vigilante' ),
1666 'timeMinute' => __( 'minute', 'vigilante' ),
1667 'timeMinutes' => __( 'minutes', 'vigilante' ),
1668 /* translators: %1$d: count, %2$s: time unit */
1669 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1670 'justNow' => __( 'Just now', 'vigilante' ),
1671 // Pagination strings
1672 /* translators: 1: first item number, 2: last item number, 3: total items */
1673 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1674 'paginationEmpty' => __( '0 items', 'vigilante' ),
1675 // Security Analyzer strings
1676 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1677 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1678 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1679 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1680 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1681 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1682 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1683 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1684 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1685 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1686 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1687 'analyzerAgo' => __( 'ago', 'vigilante' ),
1688 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1689 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1690 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1691 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1692 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1693 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1694 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1695 'analyzerPts' => __( 'pts', 'vigilante' ),
1696 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1697 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1698 /* translators: %d: number of findings in an info-only category */
1699 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1700 ),
1701 ) );
1702
1703 // 2FA Admin assets
1704 wp_enqueue_style(
1705 'vigilante-2fa-admin',
1706 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1707 array( 'vigilante-admin' ),
1708 VIGILANTE_VERSION
1709 );
1710
1711 wp_enqueue_script(
1712 'vigilante-2fa-admin',
1713 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1714 array( 'jquery', 'vigilante-admin' ),
1715 VIGILANTE_VERSION,
1716 true
1717 );
1718 }
1719
1720 /**
1721 * Show admin notices
1722 */
1723 public function show_admin_notices() {
1724 // Activation notice
1725 if ( get_transient( 'vigilante_activated' ) ) {
1726 ?>
1727 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1728 <p>
1729 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1730 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1731 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1732 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1733 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1734 </a>
1735 </p>
1736 </div>
1737 <?php
1738 delete_transient( 'vigilante_activated' );
1739 }
1740
1741 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1742 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1743 if ( ! empty( $ua_status['active'] ) ) {
1744 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1745 if ( $ua_remaining > 0 ) {
1746 $ua_hours = floor( $ua_remaining / 3600 );
1747 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1748 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1749 ?>
1750 <div class="notice notice-warning vigilante-ua-notice">
1751 <p>
1752 <span class="dashicons dashicons-shield"></span>
1753 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1754 &mdash;
1755 <?php
1756 printf(
1757 /* translators: 1: Hours, 2: Minutes */
1758 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1759 absint( $ua_hours ),
1760 absint( $ua_mins )
1761 );
1762 ?>
1763 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1764 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1765 </a>
1766 </p>
1767 <p>
1768 <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>
1769 </p>
1770 </div>
1771 <?php
1772 }
1773 }
1774
1775 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1776 // arrive with a forwarded-for header carrying a different valid IP, the
1777 // site is very likely behind a proxy/CDN that has not been declared, so
1778 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1779 //
1780 // Two deliberate silencers (2.9.2):
1781 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1782 // the machine itself: that only happens in local development stacks
1783 // (Local's nginx router, Docker...), never behind a production
1784 // proxy/CDN, so the notice would be pure noise there.
1785 // - The notice is dismissible and the dismissal persists site-wide via
1786 // the vigilante_dismissed_notices option (the admin evaluated it and
1787 // decided; nagging forever helps nobody).
1788 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1789 if (
1790 current_user_can( 'manage_options' )
1791 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1792 && ! isset( $dismissed_notices['proxy_detection'] )
1793 ) {
1794 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1795 $detected = '';
1796 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1797 if ( empty( $_SERVER[ $server_key ] ) ) {
1798 continue;
1799 }
1800 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1801 if ( false !== strpos( $candidate, ',' ) ) {
1802 $parts = explode( ',', $candidate );
1803 $candidate = trim( $parts[0] );
1804 }
1805 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1806 continue;
1807 }
1808 // Loopback forwarded IP = local development, not a real proxy.
1809 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1810 continue;
1811 }
1812 $detected = $proxy_label;
1813 break;
1814 }
1815
1816 if ( '' !== $detected ) {
1817 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1818 $detail_message = sprintf(
1819 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1820 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' ),
1821 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1822 );
1823 ?>
1824 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1825 <p>
1826 <span class="dashicons dashicons-shield"></span>
1827 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1828 </p>
1829 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1830 <p>
1831 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1832 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1833 </a>
1834 </p>
1835 </div>
1836 <script>
1837 jQuery( function ( $ ) {
1838 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1839 $.post( ajaxurl, {
1840 action: 'vigilante_dismiss_notice',
1841 notice_id: 'proxy_detection',
1842 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1843 } );
1844 } );
1845 } );
1846 </script>
1847 <?php
1848 }
1849 }
1850 }
1851
1852 /**
1853 * Render settings page
1854 */
1855 public function render_settings_page() {
1856 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1857 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1858
1859 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1860 $this->current_tab = 'dashboard';
1861 }
1862 ?>
1863 <div class="wrap vigilante-admin-wrap">
1864 <div class="vigilante-header-row">
1865 <h1 class="vigilante-page-title">
1866 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1867 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1868 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1869 </h1>
1870 <div class="vigilante-search-wrapper">
1871 <div class="vigilante-search-input-wrap">
1872 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1873 <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">
1874 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1875 </div>
1876 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1877 </div>
1878 </div>
1879
1880 <?php $this->render_tabs(); ?>
1881
1882 <div class="vigilante-content">
1883 <div class="vigilante-main">
1884 <?php $this->render_tab_content(); ?>
1885 </div>
1886 <div class="vigilante-sidebar">
1887 <?php $this->render_sidebar(); ?>
1888 </div>
1889 </div>
1890 </div>
1891 <?php
1892 }
1893
1894 /**
1895 * Render tabs navigation
1896 */
1897 private function render_tabs() {
1898 $options = $this->settings->get_all_options();
1899
1900 // Map tabs to modules
1901 $tab_to_module = array(
1902 'firewall' => 'firewall',
1903 'headers' => 'security_headers',
1904 'login' => 'login_security',
1905 'rest-api' => 'rest_api_security',
1906 'users' => 'user_security',
1907 'wp-hardening' => 'wp_hardening',
1908 'file-integrity' => 'file_integrity',
1909 'activity-log' => 'activity_log',
1910 );
1911 ?>
1912 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1913 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1914 $is_disabled = false;
1915 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1916 if ( $module && empty( $options['modules'][ $module ] ) ) {
1917 $is_disabled = true;
1918 }
1919 ?>
1920 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1921 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1922 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1923 <?php echo esc_html( $tab_name ); ?>
1924 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1925 </a>
1926 <?php endforeach; ?>
1927 </nav>
1928 <?php
1929 }
1930
1931 /**
1932 * Render current tab content
1933 */
1934 private function render_tab_content() {
1935 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1936
1937 if ( method_exists( $this, $method ) ) {
1938 $this->$method();
1939 } else {
1940 $this->render_tab_coming_soon();
1941 }
1942 }
1943
1944 /**
1945 * Render coming soon placeholder
1946 */
1947 private function render_tab_coming_soon() {
1948 ?>
1949 <div class="vigilante-settings-section">
1950 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
1951 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
1952 </div>
1953 <?php
1954 }
1955
1956 /**
1957 * Values to display for a section that this site does not control
1958 *
1959 * On a subsite the stored options are its own copy, which nothing acts on:
1960 * wp-config.php and .htaccess are written from the main site. Painting the
1961 * local copy describes a configuration that is not running, so a subsite
1962 * admin sees a box ticked here and the constant absent from the file, or the
1963 * other way round. Read the main site's values instead, which are the ones in
1964 * force, and fall back to the local ones if they cannot be read.
1965 *
1966 * @since 2.9.8
1967 *
1968 * @param string $section Settings section.
1969 * @return array
1970 */
1971 private function get_section_for_display( $section ) {
1972 $local = $this->settings->get_section( $section );
1973
1974 if ( ! $this->shared_files_locked() ) {
1975 return $local;
1976 }
1977
1978 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
1979 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
1980
1981 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
1982 return $local;
1983 }
1984
1985 return wp_parse_args( $main[ $section ], $local );
1986 }
1987
1988 /**
1989 * Whether the sections that write wp-config.php and .htaccess are read-only here
1990 *
1991 * True on a network when this is not the main site, or the user is not a
1992 * network administrator. See Vigilante_Settings::can_write_shared_files().
1993 *
1994 * @since 2.9.8
1995 *
1996 * @return bool
1997 */
1998 private function shared_files_locked() {
1999 return ! Vigilante_Settings::can_write_shared_files();
2000 }
2001
2002 /**
2003 * Print the shared-files notice for a section that cannot be edited here
2004 *
2005 * @since 2.9.8
2006 */
2007 private function render_shared_files_notice() {
2008 if ( ! $this->shared_files_locked() ) {
2009 return;
2010 }
2011 ?>
2012 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2013 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
2014 </div>
2015 <?php
2016 }
2017
2018 /**
2019 * Acting on another user's account needs permission over that user
2020 *
2021 * Since 2.10.3 the handlers behind these tools ask for edit_user over the
2022 * target, which is the rule WordPress itself applies. On a network the core
2023 * grants edit_user only to network administrators, so for anybody else these
2024 * controls do nothing. Better to say so than to paint a button that silently
2025 * skips every user.
2026 *
2027 * @since 2.10.4
2028 * @return bool
2029 */
2030 private function user_actions_locked() {
2031 return is_multisite() && ! current_user_can( 'manage_network_users' );
2032 }
2033
2034 /**
2035 * Print the notice for user tools that cannot be used from this site
2036 *
2037 * @since 2.10.4
2038 */
2039 private function render_user_actions_notice() {
2040 if ( ! $this->user_actions_locked() ) {
2041 return;
2042 }
2043 ?>
2044 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2045 <p style="margin:0;"><?php esc_html_e( 'These tools act on user accounts, which on a network belong to the whole network rather than to one site. WordPress reserves that to network administrators, so they are managed from the network admin.', 'vigilante' ); ?></p>
2046 </div>
2047 <?php
2048 }
2049
2050 /**
2051 * Check if module is disabled and render warning
2052 *
2053 * @param string $module_key Module key.
2054 * @return bool True if disabled.
2055 */
2056 private function render_module_disabled_notice( $module_key ) {
2057 if ( $this->settings->is_module_enabled( $module_key ) ) {
2058 return false;
2059 }
2060
2061 $module_labels = $this->settings->get_module_labels();
2062 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2063 ?>
2064 <div class="notice notice-warning vigilante-module-disabled-notice">
2065 <p>
2066 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2067 <?php
2068 printf(
2069 /* translators: %s: Module name */
2070 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2071 esc_html( $module_name )
2072 );
2073 ?>
2074 </p>
2075 <p>
2076 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2077 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2078 </a>
2079 </p>
2080 </div>
2081 <?php
2082 return true;
2083 }
2084
2085 /**
2086 * Render the Security Analyzer (Security Check) widget + expandable full report.
2087 *
2088 * Lives in the Dashboard tab between the Configuration Score status card and
2089 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2090 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2091 *
2092 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2093 * @param array $history Score history (oldest first).
2094 * @param array $categories_def Category metadata (slug => label/max).
2095 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2096 */
2097 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2098 $has_data = ! empty( $last_scan['ran_at'] );
2099 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2100 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2101 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2102 $ran_at_human = $has_data
2103 ? sprintf(
2104 /* translators: %s: relative time like "2 hours" */
2105 __( 'Last scan %s ago', 'vigilante' ),
2106 human_time_diff( (int) $last_scan['ran_at'], time() )
2107 )
2108 : __( 'Never scanned', 'vigilante' );
2109 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2110 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2111 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2112
2113 $quality = self::analyzer_quality_tag( $score );
2114 ?>
2115 <div class="vigilante-analyzer" id="vigilante-analyzer"
2116 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2117 <div class="vigilante-analyzer-header">
2118 <div class="vigilante-analyzer-title">
2119 <h2>
2120 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2121 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2122 </h2>
2123 <p class="description">
2124 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2125 </p>
2126 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2127 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2128 <?php echo esc_html( $ran_at_human ); ?>
2129 </p>
2130 </div>
2131 <div class="vigilante-analyzer-actions">
2132 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2133 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2134 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2135 </button>
2136 </div>
2137 </div>
2138
2139 <div class="vigilante-analyzer-summary">
2140 <div class="vigilante-analyzer-score-card">
2141 <?php if ( $has_data && $grade ) : ?>
2142 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2143 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2144 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2145 </div>
2146 <?php else : ?>
2147 <div class="vigilante-score-circle vigilante-grade-empty">
2148 <span class="vigilante-grade">—</span>
2149 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2150 </div>
2151 <?php endif; ?>
2152 <div class="vigilante-analyzer-score-meta">
2153 <p class="vigilante-analyzer-score-label">
2154 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2155 </p>
2156 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2157 data-role="quality-tag">
2158 <?php echo esc_html( $quality['label'] ); ?>
2159 </span>
2160 </div>
2161 </div>
2162
2163 <div class="vigilante-analyzer-counts">
2164 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2165 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2166 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2167 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2168 </span>
2169 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2170 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2171 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2172 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2173 </span>
2174 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2175 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2176 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2177 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2178 </span>
2179 </div>
2180
2181 <?php
2182 // Sparkline of recent scores. Require at least 3 data points so the trend
2183 // is meaningful (2 points is just a line between dots, no real trend).
2184 $hist_points = array();
2185 foreach ( $history as $h ) {
2186 $hist_points[] = (int) $h['score'];
2187 }
2188 $hist_count = count( $hist_points );
2189 if ( $hist_count >= 3 ) :
2190 $current_score = (int) end( $hist_points );
2191 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2192 $delta = $current_score - $previous_score;
2193 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2194 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2195 if ( 0 === $delta ) {
2196 $delta_text = __( 'No change', 'vigilante' );
2197 } else {
2198 $delta_text = sprintf(
2199 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2200 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2201 ( $delta > 0 ? '+' : '' ) . (int) $delta
2202 );
2203 }
2204 ?>
2205 <div class="vigilante-analyzer-sparkline-wrap">
2206 <div class="vigilante-analyzer-sparkline-head">
2207 <span class="vigilante-analyzer-sparkline-label">
2208 <?php
2209 echo esc_html( sprintf(
2210 /* translators: %d: number of scans */
2211 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2212 $hist_count
2213 ) );
2214 ?>
2215 </span>
2216 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2217 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2218 <?php echo esc_html( $delta_text ); ?>
2219 </span>
2220 </div>
2221 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2222 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2223 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2224 </div>
2225 </div>
2226 <?php elseif ( $has_data ) : ?>
2227 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2228 <span class="vigilante-analyzer-sparkline-label">
2229 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2230 </span>
2231 <p class="vigilante-analyzer-sparkline-hint">
2232 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2233 <?php
2234 $needed = 3 - $hist_count;
2235 echo esc_html( sprintf(
2236 /* translators: %d: number of additional scans needed */
2237 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2238 $needed
2239 ) );
2240 ?>
2241 </p>
2242 </div>
2243 <?php endif; ?>
2244 </div>
2245
2246 <div class="vigilante-analyzer-toggle-row">
2247 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2248 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2249 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2250 </button>
2251 </div>
2252
2253 <div class="vigilante-analyzer-details" hidden>
2254 <div class="vigilante-analyzer-categories" data-role="categories">
2255 <?php foreach ( $categories_def as $slug => $meta ) :
2256 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2257 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2258 // Always use the declared meta as the source of truth for the maximum.
2259 // The cached scan may carry an old max if a check was added/removed
2260 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2261 // but cached scans still reported max=22 until reset).
2262 $cat_max = (int) $meta['max'];
2263 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2264 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2265 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2266 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2267 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2268 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2269 ?>
2270 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2271 data-category="<?php echo esc_attr( $slug ); ?>"
2272 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2273 <summary class="vigilante-analyzer-category-summary">
2274 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2275 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2276 <?php if ( $info_only ) : ?>
2277 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2278 data-role="category-quality"
2279 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2280 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2281 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2282 </span>
2283 <?php else :
2284 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2285 $scored_total = $passed_count
2286 + (int) ( $cat_counts['warn'] ?? 0 )
2287 + (int) ( $cat_counts['fail'] ?? 0 );
2288 ?>
2289 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2290 data-role="category-quality">
2291 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2292 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2293 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2294 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2295 data-total="<?php echo esc_attr( $scored_total ); ?>">
2296 <?php
2297 echo esc_html( sprintf(
2298 /* translators: 1: tests passed, 2: total tests in this category */
2299 __( '%1$d/%2$d tests', 'vigilante' ),
2300 $passed_count,
2301 $scored_total
2302 ) );
2303 ?>
2304 </span>
2305 </span>
2306 <?php endif; ?>
2307 <?php if ( $info_only ) : ?>
2308 <span class="vigilante-analyzer-category-states" data-role="category-states">
2309 <?php if ( $info_count > 0 ) : ?>
2310 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2311 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2312 </span>
2313 <?php endif; ?>
2314 </span>
2315 <?php endif; ?>
2316 <?php if ( ! $info_only ) : ?>
2317 <span class="vigilante-analyzer-category-score">
2318 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2319 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2320 </span>
2321 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2322 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2323 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2324 data-role="category-bar"></span>
2325 </span>
2326 <?php else :
2327 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2328 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2329 $info_issues = $info_warn + $info_fail;
2330 if ( $info_issues > 0 ) : ?>
2331 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2332 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2333 <?php
2334 echo esc_html( sprintf(
2335 /* translators: %d: number of findings */
2336 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2337 $info_issues
2338 ) );
2339 ?>
2340 </span>
2341 <?php else : ?>
2342 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2343 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2344 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2345 </span>
2346 <?php endif; ?>
2347 <?php endif; ?>
2348 </summary>
2349 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2350 <?php if ( empty( $checks ) ) : ?>
2351 <li class="vigilante-analyzer-check-empty">
2352 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2353 </li>
2354 <?php else : ?>
2355 <?php foreach ( $checks as $c ) : ?>
2356 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2357 <?php endforeach; ?>
2358 <?php endif; ?>
2359 </ul>
2360 </details>
2361 <?php endforeach; ?>
2362 </div>
2363
2364 <div class="vigilante-analyzer-weekly">
2365 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2366 <p class="description">
2367 <?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' ); ?>
2368 </p>
2369 <label class="vigilante-analyzer-toggle-option">
2370 <input type="checkbox"
2371 name="security_analyzer[weekly_scan_enabled]"
2372 value="1"
2373 <?php checked( $weekly_enabled ); ?>>
2374 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2375 </label>
2376 <label class="vigilante-analyzer-toggle-option">
2377 <input type="checkbox"
2378 name="security_analyzer[email_on_regression]"
2379 value="1"
2380 <?php checked( $email_enabled ); ?>>
2381 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2382 </label>
2383 </div>
2384 </div>
2385 </div>
2386 <?php
2387 }
2388
2389 /**
2390 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2391 * Dashboard grade palette (a/b/c/d/e).
2392 *
2393 * @param int $pct 0..100.
2394 * @return array{label:string,slug:string}
2395 */
2396 public static function analyzer_quality_tag( $pct ) {
2397 $pct = max( 0, min( 100, (int) $pct ) );
2398 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2399 if ( 100 === $pct ) {
2400 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2401 }
2402 if ( $pct >= 70 ) {
2403 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2404 }
2405 if ( $pct >= 50 ) {
2406 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2407 }
2408 if ( $pct >= 30 ) {
2409 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2410 }
2411 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2412 }
2413
2414 /**
2415 * Render a single analyzer check row (used both server-side and via JS template).
2416 *
2417 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2418 * @return string HTML (escaped).
2419 */
2420 private static function render_analyzer_check_row( $check ) {
2421 $id = isset( $check['id'] ) ? $check['id'] : '';
2422 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2423 $label = isset( $check['label'] ) ? $check['label'] : '';
2424 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2425 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2426 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2427 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2428
2429 $icons = array(
2430 'pass' => 'yes-alt',
2431 'warn' => 'warning',
2432 'fail' => 'dismiss',
2433 'info' => 'info',
2434 'skip' => 'minus',
2435 );
2436 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2437
2438 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2439 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2440 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2441 $html .= '<div class="vigilante-analyzer-check-body">';
2442 $html .= '<div class="vigilante-analyzer-check-label">';
2443 $html .= '<span>' . esc_html( $label ) . '</span>';
2444 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2445 $html .= '<span class="vigilante-analyzer-check-score">'
2446 . esc_html( $score . '/' . $max )
2447 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2448 . '</span>';
2449 }
2450 $html .= '</div>';
2451 if ( $detail ) {
2452 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2453 }
2454 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2455 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2456 . esc_html__( 'Go to setting', 'vigilante' )
2457 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2458 } elseif ( $fix_link && 'info' === $state ) {
2459 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2460 $is_external = 0 === strpos( $fix_link, 'http' );
2461 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2462 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2463 . esc_html__( 'Learn more', 'vigilante' )
2464 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2465 }
2466 $html .= '</div>';
2467 $html .= '</li>';
2468 return $html;
2469 }
2470
2471 /**
2472 * Build a minimal SVG sparkline for the score history.
2473 *
2474 * @param int[] $points Score values (0..100), oldest to newest.
2475 * @return string SVG markup.
2476 */
2477 private static function sparkline_svg( $points ) {
2478 $points = array_map( 'intval', (array) $points );
2479 $count = count( $points );
2480 if ( $count < 2 ) {
2481 return '';
2482 }
2483 $width = 280;
2484 $height = 60;
2485 $padding = 4;
2486
2487 $usable_w = $width - ( $padding * 2 );
2488 $usable_h = $height - ( $padding * 2 );
2489
2490 $step = $usable_w / max( 1, $count - 1 );
2491 $max = 100; // Fixed scale — scores are 0..100.
2492
2493 $coords = array();
2494 foreach ( $points as $i => $v ) {
2495 $x = $padding + ( $i * $step );
2496 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2497 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2498 }
2499 $path = 'M ' . implode( ' L ', $coords );
2500 $last = end( $points );
2501 $last_x = $padding + ( ( $count - 1 ) * $step );
2502 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2503
2504 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2505 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2506 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2507 $svg .= '</svg>';
2508 return $svg;
2509 }
2510
2511 /**
2512 * Render dashboard tab
2513 */
2514 private function render_tab_dashboard() {
2515 $options = $this->settings->get_all_options();
2516 $module_labels = $this->settings->get_module_labels();
2517 $module_descriptions = $this->settings->get_module_descriptions();
2518 $presets = $this->settings->get_presets();
2519 $active_preset = get_option( 'vigilante_active_preset', '' );
2520
2521 // Calculate security score with more factors
2522 $security_score = $this->calculate_security_score( $options );
2523
2524 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2525 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2526 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2527 }
2528 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2529 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2530 $analyzer_history = $analyzer_instance->get_score_history();
2531 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2532 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2533 ?>
2534 <div class="vigilante-dashboard">
2535 <div class="vigilante-status-card">
2536 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2537 <p class="vigilante-score-kind description">
2538 <?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' ); ?>
2539 </p>
2540 <div class="vigilante-security-score">
2541 <?php
2542 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2543 if ( $security_score >= 90 ) {
2544 $grade = 'A';
2545 } elseif ( $security_score >= 70 ) {
2546 $grade = 'B';
2547 } elseif ( $security_score >= 50 ) {
2548 $grade = 'C';
2549 } elseif ( $security_score >= 30 ) {
2550 $grade = 'D';
2551 } else {
2552 $grade = 'E';
2553 }
2554 ?>
2555 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2556 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2557 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2558 </div>
2559 <div class="vigilante-config-status">
2560 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2561 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2562 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2563 </span>
2564 <?php else : ?>
2565 <span class="vigilante-preset-badge vigilante-preset-custom">
2566 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2567 </span>
2568 <?php endif; ?>
2569 </div>
2570 </div>
2571
2572 <?php
2573 $recommendations = $this->get_security_recommendations( $options );
2574 if ( ! empty( $recommendations ) ) :
2575 ?>
2576 <div class="vigilante-recommendations">
2577 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2578 <ul class="vigilante-recommendations-grid">
2579 <?php foreach ( $recommendations as $rec ) : ?>
2580 <li>
2581 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2582 <?php echo esc_html( $rec['message'] ); ?>
2583 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2584 <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>
2585 <?php endif; ?>
2586 </li>
2587 <?php endforeach; ?>
2588 </ul>
2589 </div>
2590 <?php endif; ?>
2591 </div>
2592
2593 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2594
2595 <div class="vigilante-modules-grid">
2596 <h2><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2597 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2598 <div class="vigilante-modules-list">
2599 <?php foreach ( $options['modules'] as $module => $enabled ) :
2600 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2601 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2602 ?>
2603 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2604 <div class="vigilante-module-header">
2605 <span class="vigilante-module-status"></span>
2606 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2607 <label class="vigilante-toggle">
2608 <?php
2609 /* translators: %s: Security module name, for example Firewall. */
2610 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2611 ?>
2612 <input type="checkbox"
2613 name="modules[<?php echo esc_attr( $module ); ?>]"
2614 value="1"
2615 <?php checked( $enabled ); ?>
2616 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2617 data-module="<?php echo esc_attr( $module ); ?>">
2618 <span class="vigilante-toggle-slider"></span>
2619 </label>
2620 </div>
2621 <?php if ( $description ) : ?>
2622 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2623 <?php endif; ?>
2624 </div>
2625 <?php endforeach; ?>
2626 </div>
2627 </div>
2628
2629 <div class="vigilante-presets-card">
2630 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2631 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2632 <div class="vigilante-presets-grid">
2633 <?php foreach ( $presets as $preset_id => $preset ) :
2634 $is_active = ( $active_preset === $preset_id );
2635 ?>
2636 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2637 <?php if ( $is_active ) : ?>
2638 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2639 <?php endif; ?>
2640 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2641 <p><?php echo esc_html( $preset['description'] ); ?></p>
2642 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2643 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2644 </button>
2645 </div>
2646 <?php endforeach; ?>
2647
2648 <?php
2649 // Under Attack mode card
2650 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2651 $ua_active = $under_attack->is_active();
2652 $ua_remaining = $under_attack->get_remaining_time();
2653 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2654 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2655 ?>
2656 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2657 <h3>
2658 <span class="dashicons dashicons-shield"></span>
2659 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2660 </h3>
2661 <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>
2662 <?php if ( $ua_active ) : ?>
2663 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2664 <span class="dashicons dashicons-clock"></span>
2665 <span class="vigilante-ua-time">
2666 <?php
2667 printf(
2668 /* translators: 1: Hours, 2: Minutes */
2669 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2670 absint( $ua_remaining_hours ),
2671 absint( $ua_remaining_mins )
2672 );
2673 ?>
2674 </span>
2675 </div>
2676 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2677 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2678 </button>
2679 <?php else : ?>
2680 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2681 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2682 </button>
2683 <?php endif; ?>
2684 </div>
2685 </div>
2686 </div>
2687 </div>
2688 <?php
2689 }
2690
2691 /**
2692 * Render tools tab
2693 */
2694 private function render_tab_tools() {
2695 // Get current settings for notification summary
2696 $email_options = $this->settings->get_section( 'email' );
2697 $login_options = $this->settings->get_section( 'login_security' );
2698 $user_options = $this->settings->get_section( 'user_security' );
2699 $fi_options = $this->settings->get_section( 'file_integrity' );
2700 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2701 $monitoring = $user_options['admin_monitoring'] ?? array();
2702 $registration = $user_options['registration_approval'] ?? array();
2703 $current_admin = get_option( 'admin_email' );
2704 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2705 $additional_raw = $email_options['additional_recipients'] ?? array();
2706 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2707 ?>
2708
2709 <!-- Notification Settings -->
2710 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2711 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2712 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2713
2714 <div class="vigilante-notification-layout">
2715
2716 <!-- Left column: Recipients settings -->
2717 <div class="vigilante-notification-settings">
2718 <form class="vigilante-settings-form" data-section="email">
2719
2720 <table class="form-table vigilante-compact-form">
2721 <tr>
2722 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2723 <td>
2724 <label>
2725 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2726 <?php
2727 printf(
2728 /* translators: %s: Admin email address */
2729 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2730 '<code>' . esc_html( $current_admin ) . '</code>'
2731 );
2732 ?>
2733 </label>
2734 </td>
2735 </tr>
2736 <tr>
2737 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2738 <td>
2739 <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>
2740 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2741 </td>
2742 </tr>
2743 <tr>
2744 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2745 <td>
2746 <label>
2747 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2748 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2749 </label>
2750 </td>
2751 </tr>
2752 </table>
2753
2754 <p class="submit vigilante-notification-submit">
2755 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2756 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2757 </button>
2758 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2759 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2760 </button>
2761 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2762 </p>
2763 <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>
2764
2765 </form>
2766 </div>
2767
2768 <!-- Right column: Active notifications summary -->
2769 <div class="vigilante-notification-summary">
2770 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2771
2772 <table class="widefat striped">
2773 <thead>
2774 <tr>
2775 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2776 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2777 <th style="width: 50px; text-align: center;"></th>
2778 </tr>
2779 </thead>
2780 <tbody>
2781 <?php
2782 $notifications = array(
2783 array(
2784 'label' => __( 'Login lockout', 'vigilante' ),
2785 'active' => ! empty( $login_options['notify_on_lockout'] ),
2786 'tab' => 'login',
2787 ),
2788 array(
2789 'label' => __( 'Administrator login', 'vigilante' ),
2790 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2791 'tab' => 'login',
2792 ),
2793 array(
2794 'label' => __( 'New administrator created', 'vigilante' ),
2795 'active' => ! empty( $monitoring['alert_new_admin'] ),
2796 'tab' => 'users',
2797 ),
2798 array(
2799 'label' => __( 'Administrator email changed', 'vigilante' ),
2800 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2801 'tab' => 'users',
2802 ),
2803 array(
2804 'label' => __( 'Permission elevation', 'vigilante' ),
2805 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2806 'tab' => 'users',
2807 ),
2808 array(
2809 'label' => __( 'Admin password changed', 'vigilante' ),
2810 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2811 'tab' => 'users',
2812 ),
2813 array(
2814 'label' => __( 'Registration pending approval', 'vigilante' ),
2815 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2816 'tab' => 'users',
2817 ),
2818 array(
2819 'label' => __( 'File integrity scan report', 'vigilante' ),
2820 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2821 'tab' => 'file-integrity',
2822 ),
2823 array(
2824 'label' => __( 'File integrity instant alert', 'vigilante' ),
2825 'active' => ! empty( $fi_options['instant_alert'] ),
2826 'tab' => 'file-integrity',
2827 ),
2828 array(
2829 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2830 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2831 'tab' => 'activity-log',
2832 'anchor' => 'vigilante-section-audit-alerts',
2833 ),
2834 array(
2835 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2836 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2837 'tab' => 'activity-log',
2838 'anchor' => 'vigilante-section-audit-alerts',
2839 ),
2840 array(
2841 'label' => __( 'Under Attack mode', 'vigilante' ),
2842 'active' => true,
2843 'tab' => '',
2844 'note' => __( 'Always active', 'vigilante' ),
2845 ),
2846 array(
2847 'label' => __( 'Plugin deactivation', 'vigilante' ),
2848 'active' => ! empty( $email_options['send_deactivation_email'] ),
2849 'tab' => 'tools',
2850 ),
2851 );
2852
2853 foreach ( $notifications as $notif ) :
2854 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2855 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2856 if ( ! empty( $notif['note'] ) ) {
2857 $status_label = $notif['note'];
2858 }
2859 ?>
2860 <tr>
2861 <td><?php echo esc_html( $notif['label'] ); ?></td>
2862 <td style="text-align: center; white-space: nowrap;">
2863 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2864 </td>
2865 <td style="text-align: center;">
2866 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2867 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2868 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2869 </a>
2870 <?php else : ?>
2871 &mdash;
2872 <?php endif; ?>
2873 </td>
2874 </tr>
2875 <?php endforeach; ?>
2876 </tbody>
2877 </table>
2878 </div>
2879
2880 </div>
2881 </div>
2882
2883 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2884
2885 <?php
2886 // Warn that during Under Attack mode the export/import operate against
2887 // the temporary hardened config and any imported changes will be
2888 // reverted when the mode ends.
2889 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2890 if ( ! empty( $ua_status['active'] ) ) :
2891 ?>
2892 <div class="vigilante-ua-tools-notice-wrap">
2893 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2894 <p>
2895 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2896 <?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' ); ?>
2897 </p>
2898 </div>
2899 </div>
2900 <?php
2901 endif;
2902 ?>
2903
2904 <div class="vigilante-tools-grid">
2905 <div class="vigilante-tool-card">
2906 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2907 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2908 <button type="button" class="button vigilante-export-settings">
2909 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2910 </button>
2911 </div>
2912
2913 <div class="vigilante-tool-card">
2914 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
2915 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
2916 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
2917 <button type="button" class="button vigilante-import-settings">
2918 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
2919 </button>
2920 </div>
2921
2922 <div class="vigilante-tool-card">
2923 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
2924 <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>
2925 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
2926 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
2927 </button>
2928 </div>
2929
2930 <div class="vigilante-tool-card">
2931 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
2932 <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>
2933 <?php if ( $this->shared_files_locked() ) : ?>
2934 <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>
2935 <?php else : ?>
2936 <button type="button" class="button vigilante-create-backup">
2937 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
2938 </button>
2939 <?php endif; ?>
2940 </div>
2941
2942 <?php if ( ! $this->shared_files_locked() ) : ?>
2943
2944 <div class="vigilante-tool-card vigilante-tool-card-wide">
2945 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2946 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2947 <button type="button" class="button vigilante-db-backup-toggle">
2948 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
2949 </button>
2950
2951 <div class="vigilante-db-backup-panel" style="display: none;">
2952 <div class="vigilante-db-tables-loading">
2953 <span class="spinner is-active"></span>
2954 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
2955 </div>
2956
2957 <div class="vigilante-db-tables-content" style="display: none;">
2958 <div class="vigilante-db-tables-controls">
2959 <label>
2960 <input type="checkbox" id="vigilante-db-select-all" checked>
2961 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
2962 </label>
2963 <span class="vigilante-db-tables-info"></span>
2964 </div>
2965
2966 <div class="vigilante-db-tables-group">
2967 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
2968 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
2969 </div>
2970
2971 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
2972 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
2973 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
2974 </div>
2975
2976 <div class="vigilante-db-backup-actions">
2977 <button type="button" class="button button-primary vigilante-db-backup-download">
2978 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
2979 </button>
2980 </div>
2981 </div>
2982 </div>
2983 </div>
2984 <?php else : ?>
2985 <div class="vigilante-tool-card vigilante-tool-card-wide">
2986 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2987 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2988 <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>
2989 </div>
2990 <?php endif; ?>
2991 </div>
2992 <?php
2993 }
2994
2995 /**
2996 * Render firewall tab
2997 */
2998 private function render_tab_firewall() {
2999 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
3000 $options = $this->settings->get_section( 'firewall' );
3001 ?>
3002 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
3003 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
3004 <h2>
3005 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
3006 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3007 </h2>
3008 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
3009 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
3010 <p style="margin:0;">
3011 <?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' ); ?>
3012 </p>
3013 </div>
3014
3015 <table class="form-table">
3016 <tr>
3017 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
3018 <td>
3019 <label>
3020 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
3021 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
3022 </label>
3023 </td>
3024 </tr>
3025 <tr>
3026 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
3027 <td>
3028 <label>
3029 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
3030 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
3031 </label>
3032 </td>
3033 </tr>
3034 <tr>
3035 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
3036 <td>
3037 <label>
3038 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
3039 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
3040 </label>
3041 </td>
3042 </tr>
3043 <tr>
3044 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
3045 <td>
3046 <label>
3047 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
3048 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
3049 </label>
3050 </td>
3051 </tr>
3052 <tr>
3053 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3054 <td>
3055 <label>
3056 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3057 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3058 </label>
3059 </td>
3060 </tr>
3061 <tr>
3062 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3063 <td>
3064 <label>
3065 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3066 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3067 </label>
3068 </td>
3069 </tr>
3070 </table>
3071
3072 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3073 <table class="form-table">
3074 <tr>
3075 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3076 <td>
3077 <label>
3078 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3079 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3080 </label>
3081 </td>
3082 </tr>
3083 <tr>
3084 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3085 <td>
3086 <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">
3087 <p class="description">
3088 <?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' ); ?>
3089 </p>
3090 </td>
3091 </tr>
3092 <tr>
3093 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3094 <td>
3095 <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">
3096 </td>
3097 </tr>
3098 <tr>
3099 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3100 <td>
3101 <label>
3102 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3103 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3104 </label>
3105 <p class="description">
3106 <?php
3107 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3108 printf(
3109 /* translators: 1: First block duration, 2: Second, 3: Third */
3110 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3111 esc_html( human_time_diff( 0, $base ) ),
3112 esc_html( human_time_diff( 0, $base * 2 ) ),
3113 esc_html( human_time_diff( 0, $base * 4 ) )
3114 );
3115 ?>
3116 </p>
3117 </td>
3118 </tr>
3119 <tr>
3120 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3121 <td>
3122 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3123 <?php
3124 $max_options = array(
3125 3600 => __( '1 hour', 'vigilante' ),
3126 21600 => __( '6 hours', 'vigilante' ),
3127 43200 => __( '12 hours', 'vigilante' ),
3128 86400 => __( '24 hours', 'vigilante' ),
3129 604800 => __( '7 days', 'vigilante' ),
3130 );
3131 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3132 foreach ( $max_options as $val => $label ) :
3133 ?>
3134 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3135 <?php echo esc_html( $label ); ?>
3136 </option>
3137 <?php endforeach; ?>
3138 </select>
3139 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3140 </td>
3141 </tr>
3142 </table>
3143
3144 <?php
3145 // Currently blocked IPs from rate limiting
3146 $active_blocks = Vigilante_Firewall::get_active_blocks();
3147 if ( ! empty( $active_blocks ) ) :
3148 ?>
3149 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3150 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3151 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3152 <thead>
3153 <tr>
3154 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3155 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3156 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3157 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3158 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3159 </tr>
3160 </thead>
3161 <tbody>
3162 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3163 <tr>
3164 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3165 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3166 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3167 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3168 <td>
3169 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3170 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3171 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3172 </button>
3173 </td>
3174 </tr>
3175 <?php endforeach; ?>
3176 </tbody>
3177 </table>
3178 </div>
3179 <?php endif; ?>
3180
3181 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3182 <p class="description">
3183 <?php
3184 printf(
3185 /* translators: %s: Current visitor IP address */
3186 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3187 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3188 );
3189 ?>
3190 </p>
3191 <table class="form-table">
3192 <tr>
3193 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3194 <td>
3195 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3196 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]">
3197 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3198 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3199 <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>
3200 <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>
3201 </select>
3202 <p class="description">
3203 <?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' ); ?>
3204 </p>
3205 </td>
3206 </tr>
3207 <tr>
3208 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3209 <td>
3210 <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>
3211 <p class="description">
3212 <?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' ); ?>
3213 <br>
3214 <?php
3215 printf(
3216 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3217 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' ),
3218 '<code>',
3219 '</code>'
3220 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3221 ?>
3222 </p>
3223 </td>
3224 </tr>
3225 <tr>
3226 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3227 <td>
3228 <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>
3229 <p class="description">
3230 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3231 <br>
3232 <?php
3233 printf(
3234 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3235 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' ),
3236 '<code>',
3237 '</code>'
3238 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3239 ?>
3240 </p>
3241 </td>
3242 </tr>
3243 </table>
3244
3245 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3246 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3247 <table class="form-table">
3248 <tr>
3249 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3250 <td>
3251 <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>
3252 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3253 </td>
3254 </tr>
3255 <tr>
3256 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3257 <td>
3258 <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>
3259 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3260 </td>
3261 </tr>
3262 </table>
3263 </div>
3264
3265 <?php
3266 $vg_shared_locked = $this->shared_files_locked();
3267 // Paint what is actually in force, not this site's unused copy.
3268 $vg_local_options = $options;
3269 $options = $this->get_section_for_display( 'firewall' );
3270 ?>
3271 <?php $this->render_shared_files_notice(); ?>
3272 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3273 <h2>
3274 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3275 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3276 </h2>
3277 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3278
3279 <table class="form-table">
3280 <tr id="field-disable-directory-browsing">
3281 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3282 <td>
3283 <label>
3284 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3285 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3286 </label>
3287 </td>
3288 </tr>
3289 <tr>
3290 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3291 <td>
3292 <label>
3293 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3294 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3295 </label>
3296 </td>
3297 </tr>
3298 <tr id="field-protect-wp-cron">
3299 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3300 <td>
3301 <label>
3302 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3303 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3304 </label>
3305 <p class="description"><?php
3306 printf(
3307 /* translators: 1: opening <strong>, 2: closing </strong> */
3308 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' ),
3309 '<strong>',
3310 '</strong>',
3311 '<code>',
3312 '</code>'
3313 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3314 ?></p>
3315 </td>
3316 </tr>
3317 <tr>
3318 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3319 <td>
3320 <label>
3321 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3322 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3323 </label>
3324 </td>
3325 </tr>
3326 <tr>
3327 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3328 <td>
3329 <label>
3330 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3331 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3332 </label>
3333 </td>
3334 </tr>
3335 <tr>
3336 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3337 <td>
3338 <label>
3339 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3340 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3341 </label>
3342 </td>
3343 </tr>
3344 <tr>
3345 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3346 <td>
3347 <label>
3348 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3349 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3350 </label>
3351 </td>
3352 </tr>
3353 </table>
3354 </div>
3355 <?php $options = $vg_local_options; ?>
3356
3357 <p class="submit vigilante-submit-buttons">
3358 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3359 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3360 </button>
3361 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3362 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3363 </button>
3364 </p>
3365 </form>
3366 <?php
3367 }
3368
3369 /**
3370 * Render login security tab
3371 */
3372 private function render_tab_login() {
3373 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3374 $options = $this->settings->get_section( 'login_security' );
3375 $lockouts = $this->database->get_active_lockouts();
3376 ?>
3377 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3378 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3379 <h2>
3380 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3381 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3382 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3383 </h2>
3384 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3385
3386 <table class="form-table">
3387 <tr id="field-max-attempts">
3388 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3389 <td>
3390 <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">
3391 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3392 </td>
3393 </tr>
3394 <tr>
3395 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3396 <td>
3397 <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">
3398 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3399 </td>
3400 </tr>
3401 <tr>
3402 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3403 <td>
3404 <label>
3405 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3406 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3407 </label>
3408 </td>
3409 </tr>
3410 <tr>
3411 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3412 <td>
3413 <label>
3414 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3415 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3416 </label>
3417 </td>
3418 </tr>
3419 <tr>
3420 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3421 <td>
3422 <label>
3423 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3424 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3425 </label>
3426 </td>
3427 </tr>
3428 </table>
3429
3430 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3431 <table class="form-table">
3432 <tr id="field-custom-login-url">
3433 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3434 <td>
3435 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3436 <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' ); ?>">
3437 <p class="description">
3438 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3439 </p>
3440 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3441 <p class="description">
3442 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3443 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3444 </p>
3445 <p class="description">
3446 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3447 </p>
3448 <p class="description">
3449 <?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' ); ?>
3450 </p>
3451 </div>
3452 </td>
3453 </tr>
3454 </table>
3455
3456 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3457 <table class="form-table">
3458 <tr>
3459 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3460 <td>
3461 <label>
3462 <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 ); ?>>
3463 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3464 </label>
3465 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3466 <button type="button" id="vigilante_notify_login_url" class="button">
3467 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3468 </button>
3469 <span class="vigilante-login-url-notify-status"></span>
3470 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3471 </div>
3472 </td>
3473 </tr>
3474 </table>
3475 </div>
3476
3477 <?php $this->render_2fa_settings( $options ); ?>
3478
3479 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3480 <table class="form-table">
3481 <tr>
3482 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3483 <td>
3484 <label>
3485 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3486 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3487 </label>
3488 </td>
3489 </tr>
3490 <tr>
3491 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3492 <td>
3493 <label>
3494 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3495 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3496 </label>
3497 </td>
3498 </tr>
3499 </table>
3500
3501 <p class="description">
3502 <?php
3503 printf(
3504 /* translators: %s: Link to notification settings */
3505 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3506 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3507 );
3508 ?>
3509 </p>
3510 </div>
3511
3512 <p class="submit vigilante-submit-buttons">
3513 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3514 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3515 </button>
3516 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3517 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3518 </button>
3519 </p>
3520 </form>
3521
3522 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3523 <?php
3524 }
3525
3526 /**
3527 * Render lockout information and blocked IPs section
3528 *
3529 * @param array $options Login security options.
3530 * @param array $lockouts Currently locked out IPs.
3531 */
3532 private function render_lockout_info_section( $options, $lockouts ) {
3533 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3534 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3535 $lockout_increment = ! empty( $options['lockout_increment'] );
3536 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3537 $two_factor = $options['two_factor'] ?? array();
3538 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3539 ?>
3540 <div class="vigilante-settings-section vigilante-lockout-section">
3541 <h2><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3542
3543 <table class="form-table">
3544 <tr>
3545 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3546 <td>
3547 <?php
3548 printf(
3549 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3550 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3551 absint( $max_attempts ),
3552 absint( ceil( $lockout_duration / 60 ) )
3553 );
3554
3555 if ( $lockout_increment ) {
3556 echo '<br>';
3557 printf(
3558 /* translators: %d: Maximum lockout duration in hours */
3559 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3560 absint( ceil( $max_lockout / 3600 ) )
3561 );
3562 }
3563
3564 if ( $two_factor_enabled ) {
3565 echo '<br>';
3566 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3567 }
3568 ?>
3569 </td>
3570 </tr>
3571 <tr>
3572 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3573 <td>
3574 <?php if ( ! empty( $lockouts ) ) : ?>
3575 <div class="vigilante-paginated-section">
3576 <div class="vigilante-fi-pagination-wrap"></div>
3577 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3578 <thead>
3579 <tr>
3580 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3581 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3582 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3583 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3584 </tr>
3585 </thead>
3586 <tbody>
3587 <?php foreach ( $lockouts as $lockout ) :
3588 $lockout_time = strtotime( $lockout->locked_until );
3589 $remaining_seconds = $lockout_time - time();
3590 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3591 ?>
3592 <tr>
3593 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3594 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3595 <td>
3596 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3597 <br>
3598 <small class="description">
3599 <?php
3600 printf(
3601 /* translators: %s: Remaining time */
3602 esc_html__( '%s remaining', 'vigilante' ),
3603 esc_html( $remaining_text )
3604 );
3605 ?>
3606 </small>
3607 </td>
3608 <td>
3609 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3610 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3611 </button>
3612 </td>
3613 </tr>
3614 <?php endforeach; ?>
3615 </tbody>
3616 </table>
3617 </div>
3618 <p class="description" style="margin-top: 10px;">
3619 <button type="button" class="button vigilante-clear-all-lockouts">
3620 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3621 </button>
3622 <span style="margin-left: 10px;">
3623 <?php
3624 printf(
3625 /* translators: %d: Number of blocked IPs */
3626 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3627 count( $lockouts )
3628 );
3629 ?>
3630 </span>
3631 </p>
3632 <?php else : ?>
3633 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3634 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3635 <?php endif; ?>
3636 </td>
3637 </tr>
3638 </table>
3639 </div>
3640 <?php
3641 }
3642
3643 /**
3644 * Format remaining lockout time in human readable format
3645 *
3646 * @param int $seconds Remaining seconds.
3647 * @return string Formatted time string.
3648 */
3649 private function format_remaining_time( $seconds ) {
3650 if ( $seconds <= 0 ) {
3651 return __( 'expired', 'vigilante' );
3652 }
3653
3654 if ( $seconds < 60 ) {
3655 return sprintf(
3656 /* translators: %d: Number of seconds */
3657 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3658 $seconds
3659 );
3660 }
3661
3662 if ( $seconds < 3600 ) {
3663 $minutes = ceil( $seconds / 60 );
3664 return sprintf(
3665 /* translators: %d: Number of minutes */
3666 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3667 $minutes
3668 );
3669 }
3670
3671 $hours = floor( $seconds / 3600 );
3672 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3673
3674 if ( $remaining_minutes > 0 ) {
3675 return sprintf(
3676 /* translators: 1: Number of hours, 2: Number of minutes */
3677 __( '%1$d hours %2$d minutes', 'vigilante' ),
3678 $hours,
3679 $remaining_minutes
3680 );
3681 }
3682
3683 return sprintf(
3684 /* translators: %d: Number of hours */
3685 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3686 $hours
3687 );
3688 }
3689
3690 /**
3691 * Render 2FA settings section
3692 *
3693 * @param array $options Login security options.
3694 */
3695 private function render_2fa_settings( $options ) {
3696 $two_factor = $options['two_factor'] ?? array();
3697 $all_roles = wp_roles()->roles;
3698 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3699 $excluded = $two_factor['excluded_users'] ?? array();
3700 $method = $two_factor['method'] ?? 'email';
3701 $grace_days = $two_factor['grace_period_days'] ?? 3;
3702 ?>
3703 <h3>
3704 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3705 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3706 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3707 </h3>
3708 <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>
3709
3710 <table class="form-table">
3711 <tr>
3712 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3713 <td>
3714 <label>
3715 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3716 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3717 </label>
3718 </td>
3719 </tr>
3720 </table>
3721
3722 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3723 <table class="form-table">
3724 <tr>
3725 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3726 <td>
3727 <fieldset class="vigilante-2fa-method-selector">
3728 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3729 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3730 <span class="dashicons dashicons-email"></span>
3731 <span class="method-info">
3732 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3733 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3734 </span>
3735 </label>
3736 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3737 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3738 <span class="dashicons dashicons-smartphone"></span>
3739 <span class="method-info">
3740 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3741 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3742 </span>
3743 </label>
3744 </fieldset>
3745 </td>
3746 </tr>
3747 <tr>
3748 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3749 <td>
3750 <div class="vigilante-2fa-roles">
3751 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3752 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3753 ?>
3754 <label>
3755 <input type="checkbox"
3756 name="login_security[two_factor][enforced_roles][]"
3757 value="<?php echo esc_attr( $role_slug ); ?>"
3758 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3759 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3760 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3761 </label>
3762 <?php endforeach; ?>
3763 </div>
3764 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3765 </td>
3766 </tr>
3767 <tr>
3768 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3769 <td>
3770 <div class="vigilante-2fa-user-search-container">
3771 <div class="vigilante-2fa-user-search">
3772 <span class="search-icon"></span>
3773 <input type="text"
3774 id="vigilante_2fa_user_search"
3775 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3776 autocomplete="off">
3777 <div class="vigilante-2fa-search-results"></div>
3778 </div>
3779 <div class="vigilante-2fa-excluded-users">
3780 <?php
3781 foreach ( $excluded as $user_id ) :
3782 $user = get_user_by( 'ID', $user_id );
3783 if ( ! $user ) continue;
3784 ?>
3785 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3786 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3787 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3788 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3789 </div>
3790 <?php endforeach; ?>
3791 </div>
3792 </div>
3793 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3794 </td>
3795 </tr>
3796
3797 <!-- Remember device option -->
3798 <tr>
3799 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3800 <td>
3801 <label>
3802 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3803 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3804 </label>
3805 <p class="description">
3806 <?php
3807 printf(
3808 /* translators: %d: Number of days */
3809 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3810 absint( $two_factor['remember_device_days'] ?? 30 )
3811 );
3812 ?>
3813 </p>
3814 </td>
3815 </tr>
3816
3817 <!-- TOTP-specific: Grace period -->
3818 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3819 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3820 <td>
3821 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3822 name="login_security[two_factor][grace_period_days]"
3823 value="<?php echo esc_attr( $grace_days ); ?>"
3824 min="0" max="30" class="small-text">
3825 <?php esc_html_e( 'days', 'vigilante' ); ?>
3826 <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>
3827 </td>
3828 </tr>
3829
3830 <!-- Email-specific: Sender name -->
3831 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3832 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3833 <td>
3834 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3835 name="login_security[two_factor][email_from_name]"
3836 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3837 class="regular-text vigilante-2fa-email-from"
3838 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3839 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3840 </td>
3841 </tr>
3842
3843 <!-- TOTP-specific: Reset users -->
3844 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3845 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3846 <td>
3847 <div class="vigilante-totp-reset-container">
3848 <div class="vigilante-2fa-user-search">
3849 <span class="search-icon"></span>
3850 <input type="text"
3851 id="vigilante_totp_reset_search"
3852 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3853 autocomplete="off">
3854 <div class="vigilante-totp-reset-results"></div>
3855 </div>
3856 <div class="vigilante-totp-reset-selected"></div>
3857 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3858 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3859 </button>
3860 <span class="vigilante-totp-reset-status"></span>
3861 </div>
3862 <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>
3863 </td>
3864 </tr>
3865 </table>
3866
3867 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3868 <table class="form-table">
3869 <tr>
3870 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3871 <td>
3872 <label>
3873 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3874 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3875 </label>
3876
3877 <div class="vigilante-2fa-notification-options">
3878 <label>
3879 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3880 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3881 </label>
3882 <label>
3883 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3884 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3885 </label>
3886 </div>
3887
3888 <div class="vigilante-2fa-send-notification">
3889 <button type="button" id="vigilante_2fa_send_notification" class="button">
3890 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3891 </button>
3892 <span class="vigilante-2fa-notification-status"></span>
3893 </div>
3894 </td>
3895 </tr>
3896 </table>
3897 </div>
3898 <?php
3899 }
3900
3901 /**
3902 * Render security headers tab
3903 */
3904 /**
3905 * Offer back the header settings the 2.9.8 migration wiped.
3906 *
3907 * Rendered outside the settings form on purpose, so its buttons can never
3908 * submit it, and only when there is something to actually change. Shows the
3909 * difference before anything is written: nothing is applied that the owner
3910 * has not seen first.
3911 *
3912 * @since 2.10.0
3913 */
3914 private function render_headers_recovery_offer() {
3915 /*
3916 * On a network the .htaccess belongs to every site and only the main one
3917 * writes it, so this is not a decision a subsite gets to make. Its own
3918 * security_headers options are inert anyway: what the network serves
3919 * comes from the file the main site owns. Without this gate a subsite
3920 * administrator was shown a Restore button that could only ever answer
3921 * with a permission error, which is worse than showing nothing.
3922 */
3923 if ( ! Vigilante_Settings::can_write_shared_files() ) {
3924 return;
3925 }
3926
3927 if ( ! Vigilante_Htaccess_Recovery::is_available() ) {
3928 /*
3929 * Already restored. Offer to take it back for as long as the previous
3930 * section is still stored: a restore that cannot be undone is a second
3931 * irreversible change on top of the one being repaired.
3932 */
3933 if ( Vigilante_Htaccess_Recovery::has_undo() ) {
3934 ?>
3935 <div class="notice notice-info inline" id="vigilante-headers-recovery-undo">
3936 <p>
3937 <?php esc_html_e( 'The Security Headers settings were restored from the copy Vigilant had kept of your .htaccess.', 'vigilante' ); ?>
3938 <button type="button" class="button button-small" id="vigilante-recovery-undo">
3939 <?php esc_html_e( 'Undo the restore', 'vigilante' ); ?>
3940 </button>
3941 </p>
3942 </div>
3943 <?php
3944 }
3945
3946 return;
3947 }
3948
3949 $rows = Vigilante_Htaccess_Recovery::get_diff( $this->settings );
3950
3951 if ( empty( $rows ) ) {
3952 return;
3953 }
3954
3955 $snapshot = Vigilante_Htaccess_Recovery::get_snapshot();
3956 $taken = isset( $snapshot['time'] ) ? (int) $snapshot['time'] : 0;
3957 $block = Vigilante_Htaccess_Recovery::get_raw_block();
3958 ?>
3959 <div class="vigilante-settings-section" id="vigilante-headers-recovery">
3960 <h2><?php esc_html_e( 'Recover your previous header settings', 'vigilante' ); ?></h2>
3961 <p>
3962 <?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' ); ?>
3963 </p>
3964 <?php if ( $taken ) : ?>
3965 <p class="description">
3966 <?php
3967 printf(
3968 /* translators: %s: date and time the .htaccess copy was taken. */
3969 esc_html__( 'Copy taken on %s.', 'vigilante' ),
3970 esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $taken ) )
3971 );
3972 ?>
3973 </p>
3974 <?php endif; ?>
3975
3976 <table class="widefat striped">
3977 <thead>
3978 <tr>
3979 <th scope="col"><?php esc_html_e( 'Setting', 'vigilante' ); ?></th>
3980 <th scope="col"><?php esc_html_e( 'Now', 'vigilante' ); ?></th>
3981 <th scope="col"><?php esc_html_e( 'Would be restored to', 'vigilante' ); ?></th>
3982 </tr>
3983 </thead>
3984 <tbody>
3985 <?php foreach ( $rows as $row ) : ?>
3986 <tr>
3987 <th scope="row"><?php echo esc_html( $row['label'] ); ?></th>
3988 <td><?php echo esc_html( $row['current'] ); ?></td>
3989 <td>
3990 <?php echo esc_html( $row['recovered'] ); ?>
3991 <?php if ( ! empty( $row['detail'] ) ) : ?>
3992 <br><span class="description"><?php echo esc_html( $row['detail'] ); ?></span>
3993 <?php endif; ?>
3994 </td>
3995 </tr>
3996 <?php endforeach; ?>
3997 </tbody>
3998 </table>
3999
4000 <p class="description">
4001 <?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' ); ?>
4002 </p>
4003
4004 <?php if ( '' !== $block ) : ?>
4005 <details>
4006 <summary><?php esc_html_e( 'Show the saved .htaccess block', 'vigilante' ); ?></summary>
4007 <textarea readonly rows="12" class="large-text code" onclick="this.select();"><?php echo esc_textarea( $block ); ?></textarea>
4008 </details>
4009 <?php endif; ?>
4010
4011 <p class="submit vigilante-submit-buttons">
4012 <button type="button" class="button button-primary" id="vigilante-recovery-restore">
4013 <?php esc_html_e( 'Restore these settings', 'vigilante' ); ?>
4014 </button>
4015 <button type="button" class="button" id="vigilante-recovery-dismiss">
4016 <?php esc_html_e( 'No thanks, keep what I have', 'vigilante' ); ?>
4017 </button>
4018 </p>
4019 <div id="vigilante-recovery-result"></div>
4020 </div>
4021 <?php
4022 }
4023
4024 private function render_tab_headers() {
4025 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
4026 // Every setting on this tab ends up in .htaccess, so on a subsite the
4027 // whole tab is somebody else's, values included.
4028 $vg_shared_locked = $this->shared_files_locked();
4029 $options = $this->get_section_for_display( 'security_headers' );
4030 ?>
4031 <?php $this->render_headers_recovery_offer(); ?>
4032
4033 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
4034 <?php $this->render_shared_files_notice(); ?>
4035 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4036 <h2>
4037 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
4038 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4039 </h2>
4040 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
4041
4042 <table class="form-table">
4043 <tr>
4044 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
4045 <td>
4046 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
4047 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4048 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
4049 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
4050 </select>
4051 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
4052 </td>
4053 </tr>
4054 <tr>
4055 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
4056 <td>
4057 <label>
4058 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
4059 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
4060 </label>
4061 </td>
4062 </tr>
4063 <tr>
4064 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
4065 <td>
4066 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
4067 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
4068 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
4069 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
4070 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4071 </select>
4072 </td>
4073 </tr>
4074 </table>
4075
4076 <h3><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
4077 <table class="form-table">
4078 <tr>
4079 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
4080 <td>
4081 <label>
4082 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
4083 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
4084 </label>
4085 </td>
4086 </tr>
4087 <tr>
4088 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
4089 <td>
4090 <label>
4091 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
4092 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
4093 </label>
4094 </td>
4095 </tr>
4096 </table>
4097
4098 <h3><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
4099 <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>
4100 <table class="form-table">
4101 <tr>
4102 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
4103 <td>
4104 <label>
4105 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
4106 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
4107 </label>
4108 <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>
4109 </td>
4110 </tr>
4111 <tr>
4112 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
4113 <td>
4114 <label>
4115 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
4116 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
4117 </label>
4118 <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>
4119 </td>
4120 </tr>
4121 <tr id="field-upgrade-insecure-requests">
4122 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
4123 <td>
4124 <label>
4125 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
4126 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
4127 </label>
4128 <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>
4129 </td>
4130 </tr>
4131 <tr>
4132 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
4133 <td>
4134 <label>
4135 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
4136 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
4137 </label>
4138 <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>
4139 </td>
4140 </tr>
4141 </table>
4142
4143 <h3><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
4144 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
4145 <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>
4146 <?php if ( ! $vig_home_https ) : ?>
4147 <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>
4148 <?php endif; ?>
4149 <table class="form-table">
4150 <tr>
4151 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
4152 <td>
4153 <?php if ( ! $vig_home_https ) : ?>
4154 <?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. */ ?>
4155 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
4156 <?php endif; ?>
4157 <label>
4158 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
4159 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
4160 </label>
4161 <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>
4162 </td>
4163 </tr>
4164 <tr>
4165 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
4166 <td>
4167 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
4168 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
4169 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
4170 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
4171 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
4172 </select>
4173 </td>
4174 </tr>
4175 <tr>
4176 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4177 <td>
4178 <label>
4179 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4180 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4181 </label>
4182 </td>
4183 </tr>
4184 </table>
4185
4186 <h3><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4187 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4188 <table class="form-table">
4189 <tr>
4190 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4191 <td>
4192 <label>
4193 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4194 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4195 </label>
4196 </td>
4197 </tr>
4198 <tr>
4199 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4200 <td>
4201 <label>
4202 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4203 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4204 </label>
4205 </td>
4206 </tr>
4207 </table>
4208 </div>
4209
4210 <?php $vg_cop = ( isset( $options['cross_origin_policies'] ) && is_array( $options['cross_origin_policies'] ) ) ? $options['cross_origin_policies'] : array(); ?>
4211 <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' : ''; ?>>
4212 <h2>
4213 <?php esc_html_e( 'Cross-Origin Policies', 'vigilante' ); ?>
4214 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
4215 </h2>
4216 <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>
4217
4218 <table class="form-table">
4219 <tr>
4220 <th scope="row"><label for="vigilante-f-security-headers-coop"><?php esc_html_e( 'Cross-Origin-Opener-Policy (COOP)', 'vigilante' ); ?></label></th>
4221 <td>
4222 <select id="vigilante-f-security-headers-coop" name="security_headers[cross_origin_policies][opener_policy]">
4223 <option value="" <?php selected( empty( $vg_cop['opener_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4224 <option value="unsafe-none" <?php selected( $vg_cop['opener_policy'] ?? '', 'unsafe-none' ); ?>>unsafe-none</option>
4225 <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>
4226 <option value="same-origin" <?php selected( $vg_cop['opener_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4227 </select>
4228 <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>
4229 </td>
4230 </tr>
4231 <tr>
4232 <th scope="row"><label for="vigilante-f-security-headers-coep"><?php esc_html_e( 'Cross-Origin-Embedder-Policy (COEP)', 'vigilante' ); ?></label></th>
4233 <td>
4234 <select id="vigilante-f-security-headers-coep" name="security_headers[cross_origin_policies][embedder_policy]">
4235 <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>
4236 <option value="credentialless" <?php selected( $vg_cop['embedder_policy'] ?? '', 'credentialless' ); ?>>credentialless</option>
4237 <option value="require-corp" <?php selected( $vg_cop['embedder_policy'] ?? '', 'require-corp' ); ?>>require-corp</option>
4238 </select>
4239 <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>
4240 </td>
4241 </tr>
4242 <tr>
4243 <th scope="row"><label for="vigilante-f-security-headers-corp"><?php esc_html_e( 'Cross-Origin-Resource-Policy (CORP)', 'vigilante' ); ?></label></th>
4244 <td>
4245 <select id="vigilante-f-security-headers-corp" name="security_headers[cross_origin_policies][resource_policy]">
4246 <option value="" <?php selected( empty( $vg_cop['resource_policy'] ) ); ?>><?php esc_html_e( 'Disabled (header not sent)', 'vigilante' ); ?></option>
4247 <option value="same-site" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-site' ); ?>>same-site</option>
4248 <option value="same-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
4249 <option value="cross-origin" <?php selected( $vg_cop['resource_policy'] ?? '', 'cross-origin' ); ?>><?php esc_html_e( 'cross-origin (recommended)', 'vigilante' ); ?></option>
4250 </select>
4251 <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>
4252 </td>
4253 </tr>
4254 </table>
4255 </div>
4256
4257 <p class="submit vigilante-submit-buttons">
4258 <?php if ( ! $vg_shared_locked ) : ?>
4259 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4260 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4261 </button>
4262 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4263 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4264 </button>
4265 <?php endif; ?>
4266 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4267 <button type="button" class="button vigilante-test-headers">
4268 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4269 </button>
4270 </p>
4271 </form>
4272
4273 <div id="vigilante-headers-result"></div>
4274 <?php
4275 }
4276
4277 /**
4278 * Render REST API tab
4279 */
4280 private function render_tab_rest_api() {
4281 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4282 $options = $this->settings->get_section( 'rest_api_security' );
4283 ?>
4284 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4285 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4286 <h2>
4287 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4288 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4289 </h2>
4290 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4291
4292 <table class="form-table">
4293 <tr>
4294 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4295 <td>
4296 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4297 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4298 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4299 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4300 </select>
4301 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4302 </td>
4303 </tr>
4304 <tr id="field-block-user-enumeration">
4305 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4306 <td>
4307 <label>
4308 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4309 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4310 </label>
4311 </td>
4312 </tr>
4313 <tr>
4314 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4315 <td>
4316 <label>
4317 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4318 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4319 </label>
4320 </td>
4321 </tr>
4322 </table>
4323 </div>
4324
4325 <p class="submit vigilante-submit-buttons">
4326 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4327 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4328 </button>
4329 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4330 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4331 </button>
4332 </p>
4333 </form>
4334 <?php
4335 }
4336
4337 /**
4338 * Render User Security tab
4339 */
4340 private function render_tab_users() {
4341 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4342 $options = $this->settings->get_section( 'user_security' );
4343 $monitoring = $options['admin_monitoring'] ?? array();
4344 $registration = $options['registration_approval'] ?? array();
4345 $session_limits = $options['session_limits'] ?? array();
4346 $password_exp = $options['password_expiration'] ?? array();
4347 $email_verify = $options['email_verification'] ?? array();
4348 ?>
4349
4350 <!-- ============================================================
4351 SETTINGS SECTION - Single form for all configuration
4352 ============================================================ -->
4353 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4354
4355 <!-- Username & Password Protection -->
4356 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4357 <h2>
4358 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4359 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4360 </h2>
4361 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4362
4363 <table class="form-table">
4364 <tr>
4365 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4366 <td>
4367 <label>
4368 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4369 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4370 </label>
4371 </td>
4372 </tr>
4373 <?php
4374 $pw_policy = wp_parse_args(
4375 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4376 array(
4377 'require_uppercase' => false,
4378 'require_lowercase' => false,
4379 'require_number' => false,
4380 'require_special' => false,
4381 'block_common' => true,
4382 'block_username' => true,
4383 'affected_roles' => array(),
4384 )
4385 );
4386 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4387 ?>
4388 <tr>
4389 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4390 <td>
4391 <label>
4392 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4393 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4394 </label>
4395 </td>
4396 </tr>
4397 <tr>
4398 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4399 <td>
4400 <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">
4401 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4402 </td>
4403 </tr>
4404 <tr>
4405 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4406 <td>
4407 <label style="display:block;margin-bottom:5px;">
4408 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4409 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4410 </label>
4411 <label style="display:block;margin-bottom:5px;">
4412 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4413 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4414 </label>
4415 <label style="display:block;margin-bottom:5px;">
4416 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4417 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4418 </label>
4419 <label style="display:block;margin-bottom:5px;">
4420 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4421 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4422 </label>
4423 <label style="display:block;margin-bottom:5px;">
4424 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4425 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4426 </label>
4427 <label style="display:block;margin-bottom:5px;">
4428 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4429 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4430 </label>
4431 <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>
4432 </td>
4433 </tr>
4434 <tr>
4435 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4436 <td>
4437 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4438 <label style="display:block;margin-bottom:5px;">
4439 <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 ) ); ?>>
4440 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4441 </label>
4442 <?php endforeach; ?>
4443 <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>
4444 </td>
4445 </tr>
4446 <tr id="field-block-author-scanning">
4447 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4448 <td>
4449 <label>
4450 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4451 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4452 </label>
4453 </td>
4454 </tr>
4455 <tr>
4456 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4457 <td>
4458 <label>
4459 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4460 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4461 </label>
4462 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4463 </td>
4464 </tr>
4465 </table>
4466 </div>
4467
4468 <!-- Admin Monitoring -->
4469 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4470 <h2>
4471 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4472 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4473 </h2>
4474 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4475
4476 <table class="form-table">
4477 <tr>
4478 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4479 <td>
4480 <label>
4481 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4482 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4483 </label>
4484 </td>
4485 </tr>
4486 <tr>
4487 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4488 <td>
4489 <label>
4490 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4491 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4492 </label>
4493 </td>
4494 </tr>
4495 <tr>
4496 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4497 <td>
4498 <label>
4499 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4500 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4501 </label>
4502 </td>
4503 </tr>
4504 <tr>
4505 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4506 <td>
4507 <label>
4508 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4509 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4510 </label>
4511 </td>
4512 </tr>
4513 </table>
4514
4515 <p class="description">
4516 <?php
4517 printf(
4518 /* translators: %s: Link to notification settings */
4519 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4520 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4521 );
4522 ?>
4523 </p>
4524 </div>
4525
4526 <!-- Registration Approval -->
4527 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4528 <h2>
4529 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4530 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4531 </h2>
4532 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4533
4534 <table class="form-table">
4535 <tr>
4536 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4537 <td>
4538 <label>
4539 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4540 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4541 </label>
4542 </td>
4543 </tr>
4544 <tr>
4545 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4546 <td>
4547 <label>
4548 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4549 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4550 </label>
4551 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4552 </td>
4553 </tr>
4554 <tr>
4555 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4556 <td>
4557 <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">
4558 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4559 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4560 </td>
4561 </tr>
4562 </table>
4563 </div>
4564
4565 <!-- Session Limits -->
4566 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4567 <h2>
4568 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4569 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4570 </h2>
4571 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4572
4573 <table class="form-table">
4574 <tr>
4575 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4576 <td>
4577 <label>
4578 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4579 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4580 </label>
4581 </td>
4582 </tr>
4583 <tr>
4584 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4585 <td>
4586 <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">
4587 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4588 </td>
4589 </tr>
4590 <tr>
4591 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4592 <td>
4593 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4594 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4595 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4596 </select>
4597 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4598 </td>
4599 </tr>
4600 <tr>
4601 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4602 <td>
4603 <label>
4604 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4605 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4606 </label>
4607 </td>
4608 </tr>
4609 </table>
4610 </div>
4611
4612 <!-- Password Expiration -->
4613 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4614 <h2>
4615 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4616 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4617 </h2>
4618 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4619
4620 <table class="form-table">
4621 <tr>
4622 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4623 <td>
4624 <label>
4625 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4626 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4627 </label>
4628 </td>
4629 </tr>
4630 <tr>
4631 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4632 <td>
4633 <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">
4634 <?php esc_html_e( 'days', 'vigilante' ); ?>
4635 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4636 </td>
4637 </tr>
4638 <tr>
4639 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4640 <td>
4641 <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">
4642 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4643 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4644 </td>
4645 </tr>
4646 <tr>
4647 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4648 <td>
4649 <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">
4650 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4651 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4652 </td>
4653 </tr>
4654 <tr>
4655 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4656 <td>
4657 <label>
4658 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4659 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4660 </label>
4661 <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>
4662 </td>
4663 </tr>
4664 <tr>
4665 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4666 <td>
4667 <?php
4668 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4669 $all_roles = wp_roles()->get_names();
4670 foreach ( $all_roles as $role_slug => $role_name ) :
4671 ?>
4672 <label style="display: block; margin-bottom: 5px;">
4673 <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 ) ); ?>>
4674 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4675 </label>
4676 <?php endforeach; ?>
4677 </td>
4678 </tr>
4679 <tr>
4680 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4681 <td>
4682 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4683 <div class="vigilante-2fa-user-search-container">
4684 <div class="vigilante-2fa-user-search">
4685 <span class="search-icon"></span>
4686 <input type="text"
4687 id="vigilante_pwexp_user_search"
4688 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4689 autocomplete="off">
4690 <div class="vigilante-pwexp-search-results"></div>
4691 </div>
4692 <div class="vigilante-pwexp-excluded-users">
4693 <?php
4694 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4695 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4696 if ( ! $excluded_user ) {
4697 continue;
4698 }
4699 ?>
4700 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4701 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4702 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4703 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4704 </div>
4705 <?php endforeach; ?>
4706 </div>
4707 </div>
4708 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4709 </td>
4710 </tr>
4711 </table>
4712 </div>
4713
4714 <!-- Email Verification -->
4715 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4716 <h2>
4717 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4718 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4719 </h2>
4720 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4721
4722 <table class="form-table">
4723 <tr>
4724 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4725 <td>
4726 <label>
4727 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4728 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4729 </label>
4730 </td>
4731 </tr>
4732 <tr>
4733 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4734 <td>
4735 <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">
4736 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4737 </td>
4738 </tr>
4739 <tr>
4740 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4741 <td>
4742 <label>
4743 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4744 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4745 </label>
4746 </td>
4747 </tr>
4748 <tr>
4749 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4750 <td>
4751 <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">
4752 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4753 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4754 </td>
4755 </tr>
4756 </table>
4757 </div>
4758
4759 <p class="submit vigilante-submit-buttons">
4760 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4761 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4762 </button>
4763 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4764 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4765 </button>
4766 </p>
4767 </form>
4768
4769 <!-- ============================================================
4770 TOOLS SECTION - Actions and utilities (no save button)
4771 ============================================================ -->
4772 <div class="vigilante-tools-section">
4773 <h2 class="vigilante-tools-header">
4774 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4775 </h2>
4776
4777 <?php $this->render_user_actions_notice(); ?>
4778 <?php if ( ! $this->user_actions_locked() ) : ?>
4779
4780 <!-- Force Password Reset -->
4781 <div class="vigilante-tool-box">
4782 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4783 <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>
4784
4785 <!-- Reset Specific Users -->
4786 <div class="vigilante-password-reset-box">
4787 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4788
4789 <div class="vigilante-user-search-wrapper">
4790 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4791 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4792 </div>
4793
4794 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4795 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4796 <ul class="vigilante-selected-users-list"></ul>
4797 </div>
4798
4799 <p class="description" style="margin-top: 15px;">
4800 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4801 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4802 </p>
4803
4804 <p class="submit">
4805 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4806 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4807 </button>
4808 </p>
4809 </div>
4810
4811 <!-- Reset by Role -->
4812 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4813 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4814 <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>
4815
4816 <?php
4817 $wp_roles = wp_roles();
4818 $user_counts = count_users();
4819 $avail_roles = $user_counts['avail_roles'] ?? array();
4820 $current_user = wp_get_current_user();
4821 $current_roles = $current_user->roles;
4822 ?>
4823
4824 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4825 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4826 $count = $avail_roles[ $role_slug ] ?? 0;
4827 if ( 0 === $count ) {
4828 continue;
4829 }
4830 $role_name = translate_user_role( $role_data['name'] );
4831 ?>
4832 <label style="display: block; margin-bottom: 6px;">
4833 <input type="checkbox"
4834 class="vigilante-reset-role-checkbox"
4835 value="<?php echo esc_attr( $role_slug ); ?>"
4836 data-count="<?php echo absint( $count ); ?>">
4837 <?php
4838 printf(
4839 /* translators: 1: Role name, 2: Number of users */
4840 '%1$s <span class="description">(%2$d)</span>',
4841 esc_html( $role_name ),
4842 absint( $count )
4843 );
4844 ?>
4845 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4846 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4847 <?php endif; ?>
4848 </label>
4849 <?php endforeach; ?>
4850 </fieldset>
4851
4852 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4853 <p>
4854 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4855 <strong id="vigilante-reset-role-count">0</strong>
4856 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4857 </p>
4858 </div>
4859
4860 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4861 <label>
4862 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4863 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4864 </label>
4865 </div>
4866
4867 <p class="submit">
4868 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4869 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4870 </button>
4871 </p>
4872 </div>
4873
4874 <!-- Reset All Users -->
4875 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4876 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4877
4878 <?php
4879 $total_users = count_users();
4880 $total_count = $total_users['total_users'];
4881 ?>
4882 <p>
4883 <?php
4884 printf(
4885 /* translators: %d: Number of users */
4886 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4887 absint( $total_count )
4888 );
4889 ?>
4890 </p>
4891
4892 <p class="description" style="color: #d63638;">
4893 <span class="dashicons dashicons-warning"></span>
4894 <?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' ); ?>
4895 </p>
4896
4897 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4898 <label>
4899 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4900 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4901 </label>
4902 </div>
4903
4904 <p class="submit">
4905 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4906 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4907 </button>
4908 </p>
4909 </div>
4910 </div>
4911
4912 <!-- Pending Registrations -->
4913 <?php
4914 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
4915 $pending_users = $user_security->get_pending_users();
4916 ?>
4917 <div class="vigilante-tool-box vigilante-pending-users-section">
4918 <h3>
4919 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
4920 <?php if ( count( $pending_users ) > 0 ) : ?>
4921 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
4922 <?php endif; ?>
4923 </h3>
4924
4925 <?php if ( empty( $registration['enabled'] ) ) : ?>
4926 <p class="description">
4927 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
4928 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
4929 </p>
4930 <?php elseif ( empty( $pending_users ) ) : ?>
4931 <div class="vigilante-no-lockouts">
4932 <span class="dashicons dashicons-yes-alt"></span>
4933 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
4934 </div>
4935 <?php else : ?>
4936 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
4937 <thead>
4938 <tr>
4939 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
4940 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
4941 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
4942 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4943 </tr>
4944 </thead>
4945 <tbody>
4946 <?php foreach ( $pending_users as $pending_user ) :
4947 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
4948 ?>
4949 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4950 <td>
4951 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
4952 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
4953 </td>
4954 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
4955 <td>
4956 <?php
4957 if ( $pending_since ) {
4958 /* translators: %s: Time ago */
4959 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
4960 } else {
4961 echo esc_html( $pending_user->user_registered );
4962 }
4963 ?>
4964 </td>
4965 <td>
4966 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4967 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
4968 </button>
4969 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
4970 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
4971 </button>
4972 </td>
4973 </tr>
4974 <?php endforeach; ?>
4975 </tbody>
4976 </table>
4977 <?php endif; ?>
4978 </div>
4979
4980 <!-- Active Sessions Management -->
4981 <div class="vigilante-tool-box vigilante-session-management-section">
4982 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
4983 <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>
4984
4985 <!-- Current user sessions -->
4986 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
4987 <?php
4988 $current_user_id = get_current_user_id();
4989 $my_sessions = $user_security->get_user_sessions( $current_user_id );
4990 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
4991 $raw_count = $user_security->get_raw_session_count( $current_user_id );
4992 ?>
4993
4994 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
4995 <div class="notice notice-warning inline" style="margin: 10px 0;">
4996 <p>
4997 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
4998 <?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' ); ?>
4999 </p>
5000 </div>
5001 <?php endif; ?>
5002
5003 <?php if ( empty( $my_sessions ) ) : ?>
5004 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
5005 <?php if ( $has_corrupted ) : ?>
5006 <p style="margin-top: 10px;">
5007 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5008 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
5009 </button>
5010 </p>
5011 <?php endif; ?>
5012 <?php else : ?>
5013 <div class="vigilante-paginated-section">
5014 <div class="vigilante-fi-pagination-wrap"></div>
5015 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
5016 <thead>
5017 <tr>
5018 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5019 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5020 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5021 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5022 </tr>
5023 </thead>
5024 <tbody>
5025 <?php foreach ( $my_sessions as $session ) : ?>
5026 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
5027 <td><?php echo esc_html( $session['browser'] ); ?></td>
5028 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
5029 <td>
5030 <?php
5031 if ( $session['login'] ) {
5032 /* translators: %s: Time ago */
5033 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
5034 } else {
5035 esc_html_e( 'Unknown', 'vigilante' );
5036 }
5037 ?>
5038 </td>
5039 <td>
5040 <?php if ( ! $session['is_current'] ) : ?>
5041 <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'] ); ?>">
5042 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
5043 </button>
5044 <?php else : ?>
5045 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
5046 <?php endif; ?>
5047 </td>
5048 </tr>
5049 <?php endforeach; ?>
5050 </tbody>
5051 </table>
5052 </div>
5053
5054 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
5055 <p style="margin-top: 10px;">
5056 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
5057 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
5058 </button>
5059 </p>
5060 <?php endif; ?>
5061 <?php endif; ?>
5062
5063 <!-- Search user sessions (admin only) -->
5064 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
5065 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
5066
5067 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
5068 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
5069 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
5070 </div>
5071
5072 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
5073 <h4 id="vigilante-sessions-user-name"></h4>
5074 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
5075 <thead>
5076 <tr>
5077 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
5078 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
5079 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
5080 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5081 </tr>
5082 </thead>
5083 <tbody id="vigilante-user-sessions-list">
5084 </tbody>
5085 </table>
5086 <p style="margin-top: 10px;">
5087 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
5088 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
5089 </button>
5090 </p>
5091 </div>
5092 </div>
5093
5094 <?php endif; ?>
5095 </div>
5096 <?php
5097 }
5098
5099 /**
5100 * Render WordPress Hardening tab
5101 */
5102 private function render_tab_wp_hardening() {
5103 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
5104 $options = $this->settings->get_section( 'wp_hardening' );
5105 ?>
5106 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
5107 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
5108 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
5109 <?php $this->render_shared_files_notice(); ?>
5110 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5111 <h2>
5112 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
5113 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5114 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5115 </h2>
5116 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
5117
5118 <?php
5119 $db_prefix = new Vigilante_Database_Prefix();
5120 $current_prefix = $db_prefix->get_current_prefix();
5121 $is_default = $db_prefix->is_default_prefix();
5122 ?>
5123
5124 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
5125 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
5126 <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>
5127 </div>
5128 <?php endif; ?>
5129
5130 <table class="form-table">
5131 <tr>
5132 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
5133 <td>
5134 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
5135 <?php if ( $is_default ) : ?>
5136 <span class="vigilante-inline-warning">
5137 <span class="dashicons dashicons-warning"></span>
5138 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
5139 </span>
5140 <?php else : ?>
5141 <span class="vigilante-inline-ok">
5142 <span class="dashicons dashicons-yes-alt"></span>
5143 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
5144 </span>
5145 <?php endif; ?>
5146 </td>
5147 </tr>
5148 <tr>
5149 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
5150 <td>
5151 <div class="vigilante-db-prefix-row">
5152 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
5153 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
5154 <span class="dashicons dashicons-update"></span>
5155 </button>
5156 </div>
5157 </td>
5158 </tr>
5159 <tr>
5160 <th scope="row"></th>
5161 <td>
5162 <div class="vigilante-db-prefix-confirm">
5163 <label>
5164 <input type="checkbox" id="vigilante-prefix-backup-confirm">
5165 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
5166 </label>
5167 <p class="description">
5168 <?php
5169 printf(
5170 /* translators: %s: Link to tools tab */
5171 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
5172 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
5173 );
5174 ?>
5175 </p>
5176 </div>
5177 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
5178 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
5179 </button>
5180 </td>
5181 </tr>
5182 </table>
5183 </div>
5184
5185 <!-- wp-config Security -->
5186 <?php
5187 $vg_shared_locked = $this->shared_files_locked();
5188 // Paint what is actually in force, not this site's unused copy.
5189 $vg_local_options = $options;
5190 $options = $this->get_section_for_display( 'wp_hardening' );
5191 ?>
5192 <?php $this->render_shared_files_notice(); ?>
5193 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
5194 <h2>
5195 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
5196 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
5197 </h2>
5198 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
5199
5200 <table class="form-table">
5201 <tr>
5202 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
5203 <td>
5204 <label>
5205 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
5206 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
5207 </label>
5208 </td>
5209 </tr>
5210 <tr>
5211 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
5212 <td>
5213 <label>
5214 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
5215 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
5216 </label>
5217 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
5218 </td>
5219 </tr>
5220 <tr id="field-force-ssl-admin">
5221 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
5222 <td>
5223 <label>
5224 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
5225 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
5226 </label>
5227 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5228 </td>
5229 </tr>
5230 <tr id="field-wp-debug">
5231 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5232 <td>
5233 <label>
5234 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5235 <?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' ); ?>
5236 </label>
5237 </td>
5238 </tr>
5239 <tr id="field-disable-wp-cron">
5240 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5241 <td>
5242 <label>
5243 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5244 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5245 </label>
5246 <p class="description"><?php
5247 printf(
5248 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5249 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' ),
5250 '<strong>',
5251 '</strong>',
5252 '<code>',
5253 '</code>'
5254 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5255 ?></p>
5256 </td>
5257 </tr>
5258 </table>
5259 </div>
5260 <?php $options = $vg_local_options; ?>
5261
5262 <!-- Comment Security -->
5263 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5264 <h2>
5265 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5266 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5267 </h2>
5268 <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>
5269
5270 <table class="form-table">
5271 <tr id="field-disable-xmlrpc">
5272 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5273 <td>
5274 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5275 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5276 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5277 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5278 </option>
5279 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5280 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5281 </option>
5282 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5283 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5284 </option>
5285 </select>
5286 <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>
5287 </td>
5288 </tr>
5289 </table>
5290 </div>
5291
5292 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5293 <h2>
5294 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5295 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5296 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5297 </h2>
5298 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5299
5300 <table class="form-table">
5301 <tr>
5302 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5303 <td>
5304 <label>
5305 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5306 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5307 </label>
5308 </td>
5309 </tr>
5310 <tr>
5311 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5312 <td>
5313 <label>
5314 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5315 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5316 </label>
5317 </td>
5318 </tr>
5319 <tr>
5320 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5321 <td>
5322 <label>
5323 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5324 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5325 </label>
5326 </td>
5327 </tr>
5328 <tr>
5329 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5330 <td>
5331 <label>
5332 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5333 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5334 </label>
5335 <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">
5336 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5337 </td>
5338 </tr>
5339 <tr>
5340 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5341 <td>
5342 <label>
5343 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5344 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5345 </label>
5346 </td>
5347 </tr>
5348 </table>
5349 </div>
5350
5351 <!-- Head Cleaner -->
5352 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5353 <h2>
5354 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5355 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5356 </h2>
5357 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5358
5359 <table class="form-table">
5360 <tr>
5361 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5362 <td>
5363 <label>
5364 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5365 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5366 </label>
5367 </td>
5368 </tr>
5369 <tr id="field-remove-wp-version-assets">
5370 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5371 <td>
5372 <label>
5373 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5374 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5375 </label>
5376 <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>
5377 </td>
5378 </tr>
5379 <tr>
5380 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5381 <td>
5382 <label>
5383 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5384 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5385 </label>
5386 </td>
5387 </tr>
5388 <tr>
5389 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5390 <td>
5391 <label>
5392 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5393 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5394 </label>
5395 </td>
5396 </tr>
5397 <tr>
5398 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5399 <td>
5400 <label>
5401 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5402 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5403 </label>
5404 </td>
5405 </tr>
5406 <tr>
5407 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5408 <td>
5409 <label>
5410 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5411 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5412 </label>
5413 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5414 </td>
5415 </tr>
5416 </table>
5417 </div>
5418
5419 <!-- Feed Manager -->
5420 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5421 <h2>
5422 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5423 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5424 </h2>
5425 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5426
5427 <table class="form-table">
5428 <tr>
5429 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5430 <td>
5431 <label>
5432 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5433 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5434 </label>
5435 </td>
5436 </tr>
5437 <tr>
5438 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5439 <td>
5440 <label>
5441 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5442 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5443 </label>
5444 </td>
5445 </tr>
5446 <tr>
5447 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5448 <td>
5449 <label>
5450 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5451 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5452 </label>
5453 </td>
5454 </tr>
5455 </table>
5456 </div>
5457
5458 <p class="submit vigilante-submit-buttons">
5459 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5460 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5461 </button>
5462 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5463 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5464 </button>
5465 </p>
5466 </form>
5467 <?php
5468 }
5469
5470 /**
5471 * Render activity log tab
5472 */
5473 private function render_tab_activity_log() {
5474 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5475 $options = $this->settings->get_section( 'activity_log' );
5476 ?>
5477 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5478 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5479 <h2>
5480 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5481 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5482 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5483 </h2>
5484 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5485
5486 <table class="form-table">
5487 <tr>
5488 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5489 <td>
5490 <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">
5491 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5492 &nbsp;&nbsp;
5493 <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">
5494 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5495 <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>
5496 </td>
5497 </tr>
5498 <tr>
5499 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5500 <td>
5501 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5502 <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>
5503 <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>
5504 <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>
5505 <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>
5506 <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>
5507 <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>
5508 <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>
5509 <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>
5510 <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>
5511 <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>
5512 </fieldset>
5513 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5514 <p style="margin:0;">
5515 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5516 </p>
5517 </div>
5518 </td>
5519 </tr>
5520 <tr>
5521 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5522 <td>
5523 <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>
5524 <br>
5525 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5526 <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>
5527 <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>
5528 </td>
5529 </tr>
5530 <tr>
5531 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5532 <td>
5533 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5534 <div>
5535 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5536 <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>
5537 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5538 </div>
5539 <div>
5540 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5541 <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>
5542 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5543 </div>
5544 </div>
5545 </td>
5546 </tr>
5547 </table>
5548 </div>
5549
5550 <p class="submit vigilante-submit-buttons">
5551 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5552 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5553 </button>
5554 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5555 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5556 </button>
5557 </p>
5558 </form>
5559
5560 <?php
5561 // Audit Alerts — alerting layer on top of Security Audit. Its own
5562 // settings section and form, rendered right after the logging settings
5563 // so the tab reads as "log this, exclude that, and alert me about this".
5564 $alerts = $this->settings->get_section( 'audit_alerts' );
5565 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5566 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5567 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5568 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5569 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5570 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5571 ?>
5572 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5573 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5574 <h2>
5575 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5576 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5577 </h2>
5578 <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>
5579
5580 <table class="form-table">
5581 <tr id="field-audit-alerts-immediate">
5582 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5583 <td>
5584 <label>
5585 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5586 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5587 </label>
5588 <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>
5589 </td>
5590 </tr>
5591 <tr>
5592 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5593 <td>
5594 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5595 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5596 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5597 </select>
5598 <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>
5599 </td>
5600 </tr>
5601 <tr id="field-audit-alerts-threshold">
5602 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5603 <td>
5604 <label>
5605 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5606 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5607 </label>
5608 <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>
5609 </td>
5610 </tr>
5611 <tr>
5612 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5613 <td>
5614 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5615 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5616 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5617 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5618 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5619 </select>
5620 <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>
5621 </td>
5622 </tr>
5623 <tr>
5624 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5625 <td>
5626 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5627 <?php
5628 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5629 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5630 ?>
5631 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5632 <span><?php echo esc_html( $cat_label ); ?></span>
5633 <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">
5634 </label>
5635 <?php endforeach; ?>
5636 </fieldset>
5637 <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>
5638 </td>
5639 </tr>
5640 <tr>
5641 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5642 <td>
5643 <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">
5644 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5645 <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>
5646 </td>
5647 </tr>
5648
5649 <tr>
5650 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5651 <td>
5652 <p class="description" style="margin-top:0;">
5653 <?php
5654 printf(
5655 /* translators: %s: Link to notification settings */
5656 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5657 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5658 );
5659 ?>
5660 </p>
5661 <p style="margin:8px 0 0;">
5662 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5663 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5664 </button>
5665 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5666 </p>
5667 <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>
5668 </td>
5669 </tr>
5670 </table>
5671 </div>
5672
5673 <p class="submit vigilante-submit-buttons">
5674 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5675 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5676 </button>
5677 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5678 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5679 </button>
5680 </p>
5681 </form>
5682
5683 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5684 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5685
5686 <?php
5687 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5688 $total_logs = $this->activity_log->get_logs_count();
5689
5690 // Label maps for translated display
5691 $type_labels = array(
5692 'login' => __( 'Login', 'vigilante' ),
5693 'user' => __( 'User', 'vigilante' ),
5694 'content' => __( 'Content', 'vigilante' ),
5695 'plugin' => __( 'Plugin', 'vigilante' ),
5696 'theme' => __( 'Theme', 'vigilante' ),
5697 'settings' => __( 'Settings', 'vigilante' ),
5698 'comment' => __( 'Comment', 'vigilante' ),
5699 'media' => __( 'Media', 'vigilante' ),
5700 'firewall' => __( 'Firewall', 'vigilante' ),
5701 'file' => __( 'File', 'vigilante' ),
5702 'security' => __( 'Security', 'vigilante' ),
5703 'system' => __( 'System', 'vigilante' ),
5704 );
5705 $severity_labels = array(
5706 'info' => __( 'Info', 'vigilante' ),
5707 'warning' => __( 'Warning', 'vigilante' ),
5708 'critical' => __( 'Critical', 'vigilante' ),
5709 );
5710
5711 $firewall_options = $this->settings->get_section( 'firewall' );
5712 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5713 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5714 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5715 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5716 ?>
5717
5718 <div class="vigilante-log-filters">
5719 <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">
5720 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5721 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5722 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5723 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5724 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5725 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5726 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5727 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5728 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5729 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5730 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5731 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5732 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5733 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5734 </select>
5735 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5736 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5737 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5738 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5739 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5740 </select>
5741 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5742 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5743 <option value="GET">GET</option>
5744 <option value="POST">POST</option>
5745 <option value="PUT">PUT</option>
5746 <option value="DELETE">DELETE</option>
5747 <option value="PATCH">PATCH</option>
5748 <option value="OPTIONS">OPTIONS</option>
5749 <option value="HEAD">HEAD</option>
5750 </select>
5751 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5752 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5753 <?php if ( $total_logs > 20 ) : ?>
5754 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5755 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5756 <?php endif; ?>
5757 <span class="vigilante-page-info">
5758 <?php
5759 $showing = min( 20, $total_logs );
5760 printf(
5761 /* translators: 1: first item, 2: last item, 3: total items */
5762 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5763 $total_logs > 0 ? 1 : 0,
5764 absint( $showing ),
5765 absint( $total_logs )
5766 );
5767 ?>
5768 </span>
5769 <?php if ( $total_logs > 20 ) : ?>
5770 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5771 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5772 <?php endif; ?>
5773 </span>
5774 </div>
5775
5776 <div class="vigilante-log-table-wrap">
5777 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5778 <thead>
5779 <tr>
5780 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5781 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5782 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5783 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5784 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5785 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5786 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5787 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5788 </tr>
5789 </thead>
5790 <tbody>
5791 <?php
5792 if ( empty( $logs ) ) :
5793 ?>
5794 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5795 <?php else : ?>
5796 <?php foreach ( $logs as $log ) :
5797 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5798 // Prepare details as a simple object
5799 $ip_val = (string) ( $log->ip_address ?? '' );
5800 $ua_val = (string) ( $log->user_agent ?? '' );
5801 $details = array(
5802 'id' => (int) $log->id,
5803 'type' => (string) ( $log->event_type ?? '' ),
5804 'action' => (string) ( $log->event_action ?? '' ),
5805 'message' => (string) ( $log->event_message ?? '' ),
5806 'user' => (string) ( $log->user_login ?? '' ),
5807 'ip' => $ip_val,
5808 'user_agent' => $ua_val,
5809 'request_method' => (string) $request_method,
5810 'request_uri' => Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' ),
5811 'date' => (string) ( $log->created_at ?? '' ),
5812 'severity' => (string) ( $log->severity ?? 'info' ),
5813 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5814 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5815 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5816 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5817 );
5818 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5819 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5820 ?>
5821 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5822 <td><?php echo esc_html( $log->created_at ); ?></td>
5823 <td><?php echo esc_html( $display_type ); ?></td>
5824 <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>
5825 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5826 <td><?php echo esc_html( $log->event_message ); ?></td>
5827 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5828 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5829 <td>
5830 <button type="button" class="button button-small vigilante-view-log-details"
5831 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5832 <?php esc_html_e( 'View', 'vigilante' ); ?>
5833 </button>
5834 </td>
5835 </tr>
5836 <?php endforeach; ?>
5837 <?php endif; ?>
5838 </tbody>
5839 </table>
5840 </div>
5841
5842 <!-- Log Details Modal -->
5843 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5844 <div class="vigilante-modal-content">
5845 <span class="vigilante-modal-close">&times;</span>
5846 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5847 <div id="vigilante-log-details-content"></div>
5848 </div>
5849 </div>
5850
5851 <p>
5852 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5853 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5854 </p>
5855 </div>
5856 <?php
5857 }
5858
5859 /**
5860 * Render File Integrity tab
5861 */
5862 private function render_tab_file_integrity() {
5863 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5864 $options = $this->settings->get_section( 'file_integrity' );
5865 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5866 $last_results = get_option( 'vigilante_last_integrity_results' );
5867 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5868
5869 // Backward compat: convert old notify_on_changes to notify_level
5870 $notify_level = $options['notify_level'] ?? '';
5871 if ( empty( $notify_level ) ) {
5872 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5873 }
5874
5875 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5876 // user sees file findings and plugin closures together (same tier of risk,
5877 // same UI), and as the trigger to keep Last Scan Results open even when no
5878 // file scan has run yet (the daily cron may have populated this section).
5879 //
5880 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5881 // resets this block: the option vigilante_plugin_status_last_check is
5882 // deleted on Clear, but the state map and the ignored list survive so the
5883 // next scan reconstructs without degrading a 'removed' slug. While
5884 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5885 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5886 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5887 }
5888 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5889 $closed_last_check = $closed_checker->get_last_check_time();
5890 if ( $closed_last_check > 0 ) {
5891 $closed_plugins = $closed_checker->get_closed_plugins();
5892 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5893 } else {
5894 $closed_plugins = array();
5895 $ignored_closed_plugins = array();
5896 }
5897 $has_closed = ! empty( $closed_plugins );
5898 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5899 ?>
5900 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5901 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5902 <h2>
5903 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5904 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5905 </h2>
5906 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5907
5908 <table class="form-table">
5909 <tr>
5910 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5911 <td>
5912 <label>
5913 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5914 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
5915 </label>
5916 </td>
5917 </tr>
5918 <tr>
5919 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
5920 <td>
5921 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
5922 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
5923 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
5924 </select>
5925 </td>
5926 </tr>
5927 <tr>
5928 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
5929 <td>
5930 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
5931 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
5932 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
5933 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
5934 </select>
5935 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
5936 </td>
5937 </tr>
5938 <tr>
5939 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
5940 <td>
5941 <label>
5942 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
5943 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
5944 </label>
5945 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
5946 <p class="description">
5947 <?php
5948 printf(
5949 /* translators: %s: Link to notification settings */
5950 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5951 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5952 );
5953 ?>
5954 </p>
5955 </td>
5956 </tr>
5957 <tr>
5958 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
5959 <td>
5960 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5961 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5962 </button>
5963 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5964 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
5965 </td>
5966 </tr>
5967 <tr>
5968 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
5969 <td>
5970 <fieldset>
5971 <label>
5972 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
5973 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
5974 </label>
5975 <br>
5976 <label>
5977 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
5978 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
5979 </label>
5980 <br>
5981 <label>
5982 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
5983 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
5984 </label>
5985 <br>
5986 <label>
5987 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
5988 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
5989 </label>
5990 <br>
5991 <label>
5992 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
5993 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
5994 </label>
5995 <br>
5996 <label>
5997 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
5998 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
5999 </label>
6000 </fieldset>
6001 </td>
6002 </tr>
6003 <tr>
6004 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
6005 <td>
6006 <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>
6007 <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>
6008 </td>
6009 </tr>
6010 <tr>
6011 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
6012 <td>
6013 <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>
6014 <p class="description">
6015 <?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' ); ?>
6016 <br>
6017 <?php
6018 printf(
6019 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
6020 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' ),
6021 '<code>',
6022 '</code>'
6023 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
6024 ?>
6025 </p>
6026 </td>
6027 </tr>
6028 </table>
6029 </div>
6030
6031 <p class="submit vigilante-submit-buttons">
6032 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
6033 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
6034 </button>
6035 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
6036 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
6037 </button>
6038 <span class="vigilante-buttons-separator"></span>
6039 <button type="button" class="button button-primary vigilante-run-scan">
6040 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
6041 </button>
6042 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
6043 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
6044 </button>
6045 </p>
6046 </form>
6047
6048 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
6049
6050 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
6051 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
6052 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
6053 <?php if ( $last_scan ) : ?>
6054 <p>
6055 <?php
6056 // Build the "X files scanned" hint inline with the date so it doesn't
6057 // need its own stat box (keeps the row compact when closed plugins are
6058 // present).
6059 $scanned_total = 0;
6060 if ( $last_results ) {
6061 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
6062 + count( $last_results['modified'] ?? array() )
6063 + count( $last_results['suspicious'] ?? array() )
6064 + count( $last_results['extra'] ?? array() )
6065 + count( $ignored_files );
6066 }
6067 if ( $scanned_total > 0 ) {
6068 printf(
6069 /* translators: 1: date and time of last scan, 2: formatted file count */
6070 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
6071 esc_html( wp_date( $datetime_format, $last_scan ) ),
6072 esc_html( number_format_i18n( $scanned_total ) )
6073 );
6074 } else {
6075 printf(
6076 /* translators: %s: date and time of last scan */
6077 esc_html__( 'Last scan: %s', 'vigilante' ),
6078 esc_html( wp_date( $datetime_format, $last_scan ) )
6079 );
6080 }
6081 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
6082 echo ' &middot; ';
6083 printf(
6084 /* translators: %s: date and time of last closed plugins check */
6085 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
6086 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6087 );
6088 }
6089 ?>
6090 </p>
6091 <?php elseif ( $closed_last_check > 0 ) : ?>
6092 <p>
6093 <?php
6094 printf(
6095 /* translators: %s: date and time of last closed plugins check */
6096 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
6097 esc_html( wp_date( $datetime_format, $closed_last_check ) )
6098 );
6099 ?>
6100 </p>
6101 <?php endif; ?>
6102 <div id="vigilante-last-scan-results">
6103 <?php if ( $last_results || $has_closed ) : ?>
6104 <div class="vigilante-scan-summary">
6105 <?php if ( $last_results ) : ?>
6106 <div class="vigilante-scan-stat vigilante-stat-ok">
6107 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
6108 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
6109 </div>
6110 <div class="vigilante-scan-stat vigilante-stat-modified">
6111 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
6112 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
6113 </div>
6114 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6115 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
6116 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
6117 </div>
6118 <div class="vigilante-scan-stat vigilante-stat-extra">
6119 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
6120 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
6121 </div>
6122 <?php endif; ?>
6123 <?php if ( $has_closed ) : ?>
6124 <div class="vigilante-scan-stat vigilante-stat-suspicious">
6125 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
6126 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
6127 </div>
6128 <?php endif; ?>
6129 <?php if ( ! empty( $ignored_files ) ) : ?>
6130 <div class="vigilante-scan-stat vigilante-stat-ignored">
6131 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
6132 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
6133 </div>
6134 <?php endif; ?>
6135 </div>
6136
6137 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
6138 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
6139 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
6140 <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>
6141 <div class="vigilante-fi-bulk-bar">
6142 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6143 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6144 </div>
6145 <div class="vigilante-fi-pagination-wrap"></div>
6146 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6147 <thead>
6148 <tr>
6149 <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>
6150 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6151 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6152 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6153 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6154 </tr>
6155 </thead>
6156 <tbody>
6157 <?php
6158 foreach ( $last_results['suspicious'] as $item ) {
6159 $file_path = '';
6160 $file_reason = __( 'Unknown', 'vigilante' );
6161 $file_type = 'unknown';
6162
6163 if ( is_array( $item ) ) {
6164 if ( isset( $item['file'] ) ) {
6165 $file_path = $item['file'];
6166 }
6167 if ( isset( $item['reason'] ) ) {
6168 $file_reason = $item['reason'];
6169 }
6170 if ( isset( $item['type'] ) ) {
6171 $file_type = $item['type'];
6172 }
6173 } else {
6174 $file_path = (string) $item;
6175 }
6176 ?>
6177 <tr>
6178 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6179 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
6180 <td><?php echo esc_html( $file_reason ); ?></td>
6181 <td><?php echo esc_html( $file_type ); ?></td>
6182 <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>
6183 </tr>
6184 <?php
6185 }
6186 ?>
6187 </tbody>
6188 </table>
6189 </div>
6190 <?php endif; ?>
6191
6192 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
6193 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
6194 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
6195 <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>
6196 <div class="vigilante-fi-bulk-bar">
6197 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6198 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6199 </div>
6200 <div class="vigilante-fi-pagination-wrap"></div>
6201 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6202 <thead>
6203 <tr>
6204 <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>
6205 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6206 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6207 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6208 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6209 </tr>
6210 </thead>
6211 <tbody>
6212 <?php
6213 foreach ( $last_results['extra'] as $item ) {
6214 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
6215 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
6216 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
6217 ?>
6218 <tr>
6219 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6220 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
6221 <td><?php echo esc_html( $file_reason ); ?></td>
6222 <td><?php echo esc_html( $file_type ); ?></td>
6223 <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>
6224 </tr>
6225 <?php
6226 }
6227 ?>
6228 </tbody>
6229 </table>
6230 </div>
6231 <?php endif; ?>
6232
6233 <?php
6234 // Split critical config files from regular modified files.
6235 // Computed unconditionally so the three sub-sections that consume
6236 // these arrays (Critical Config, Closed + Removed, Modified Files)
6237 // can render independently and in the order the team picked.
6238 $critical_modified = array();
6239 $regular_modified = array();
6240 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6241 foreach ( $last_results['modified'] as $item ) {
6242 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6243 $critical_modified[] = $item;
6244 } else {
6245 $regular_modified[] = $item;
6246 }
6247 }
6248 }
6249 ?>
6250
6251 <?php if ( ! empty( $critical_modified ) ) : ?>
6252 <div class="vigilante-file-list vigilante-critical-config-files">
6253 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6254 <p class="description">
6255 <?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' ); ?>
6256 </p>
6257 <table class="wp-list-table widefat fixed striped">
6258 <thead>
6259 <tr>
6260 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6261 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6262 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6263 </tr>
6264 </thead>
6265 <tbody>
6266 <?php foreach ( $critical_modified as $crit_item ) :
6267 $crit_file = $crit_item['file'] ?? '';
6268 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6269 $crit_current_size = $crit_item['current_size'] ?? 0;
6270 $crit_diff = $crit_item['diff'] ?? array();
6271 $crit_id = sanitize_html_class( $crit_file );
6272 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6273 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6274 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6275 ?>
6276 <tr>
6277 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6278 <td>
6279 <?php if ( ! $diff_unavailable ) : ?>
6280 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6281 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6282 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6283 <?php endif; ?>
6284 <small style="color: #50575e;">
6285 <?php
6286 printf(
6287 /* translators: 1: baseline size, 2: current size */
6288 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6289 esc_html( number_format_i18n( $crit_baseline_size ) ),
6290 esc_html( number_format_i18n( $crit_current_size ) )
6291 );
6292 ?>
6293 </small>
6294 </td>
6295 <td>
6296 <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' ); ?>">
6297 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6298 </button>
6299 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6300 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6301 </button>
6302 </td>
6303 </tr>
6304 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6305 <td colspan="3" style="padding: 0;">
6306 <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;">
6307 <?php if ( $diff_unavailable ) : ?>
6308 <p style="color: #50575e; font-style: italic; margin: 0;">
6309 <?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' ); ?>
6310 </p>
6311 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6312 <p style="color: #50575e; font-style: italic; margin: 0;">
6313 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6314 </p>
6315 <?php else : ?>
6316 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6317 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6318 <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>
6319 <?php endforeach; ?>
6320 <?php endif; ?>
6321 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6322 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6323 <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>
6324 <?php endforeach; ?>
6325 <?php endif; ?>
6326 <?php endif; ?>
6327 </div>
6328 </td>
6329 </tr>
6330 <?php endforeach; ?>
6331 </tbody>
6332 </table>
6333 </div>
6334 <?php endif; ?>
6335
6336 <?php if ( $has_closed ) : ?>
6337 <div class="vigilante-file-list vigilante-closed-plugins">
6338 <h3 style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6339 <p class="description" style="color: #d63638;">
6340 <?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' ); ?>
6341 </p>
6342 <table class="wp-list-table widefat striped">
6343 <thead>
6344 <tr>
6345 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6346 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6347 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6348 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6349 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6350 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6351 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6352 </tr>
6353 </thead>
6354 <tbody>
6355 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6356 $cp_state = $cp_entry['state'] ?? '';
6357 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6358 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6359 $cp_reason = '';
6360 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6361 $cp_reason = $cp_entry['closed_reason_text'];
6362 } elseif ( 'removed' === $cp_state ) {
6363 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6364 }
6365 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6366 ?>
6367 <tr>
6368 <td>
6369 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6370 <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>
6371 </td>
6372 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6373 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6374 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6375 <td><?php echo esc_html( $cp_reason ); ?></td>
6376 <td>
6377 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6378 </td>
6379 <td>
6380 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6381 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6382 </button>
6383 </td>
6384 </tr>
6385 <?php endforeach; ?>
6386 </tbody>
6387 </table>
6388 </div>
6389 <?php endif; ?>
6390
6391 <?php if ( ! empty( $regular_modified ) ) : ?>
6392 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6393 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6394 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6395 <div class="vigilante-fi-bulk-bar">
6396 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6397 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6398 </div>
6399 <div class="vigilante-fi-pagination-wrap"></div>
6400 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6401 <thead>
6402 <tr>
6403 <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>
6404 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6405 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6406 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6407 </tr>
6408 </thead>
6409 <tbody>
6410 <?php
6411 foreach ( $regular_modified as $item ) {
6412 $file_path = '';
6413 $file_type = 'unknown';
6414
6415 if ( is_array( $item ) ) {
6416 if ( isset( $item['file'] ) ) {
6417 $file_path = $item['file'];
6418 }
6419 if ( isset( $item['type'] ) ) {
6420 $file_type = $item['type'];
6421 }
6422 } else {
6423 $file_path = (string) $item;
6424 }
6425 ?>
6426 <tr>
6427 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6428 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6429 <td><?php echo esc_html( $file_type ); ?></td>
6430 <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>
6431 </tr>
6432 <?php
6433 }
6434 ?>
6435 </tbody>
6436 </table>
6437 </div>
6438 <?php endif; ?>
6439
6440 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6441 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6442 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6443 </p>
6444 <?php endif; ?>
6445 <?php endif; ?>
6446 </div>
6447 </div>
6448 <?php endif; ?>
6449
6450 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6451 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6452 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6453 <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>
6454 <table class="wp-list-table widefat fixed striped">
6455 <thead>
6456 <tr>
6457 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6458 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6459 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6460 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6461 </tr>
6462 </thead>
6463 <tbody>
6464 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6465 $icp_state = $icp_entry['state'] ?? '';
6466 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6467 ?>
6468 <tr>
6469 <td>
6470 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6471 <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>
6472 </td>
6473 <td><?php echo esc_html( $icp_state_label ); ?></td>
6474 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6475 <td>
6476 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6477 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6478 </button>
6479 </td>
6480 </tr>
6481 <?php endforeach; ?>
6482 </tbody>
6483 </table>
6484 <p style="margin-top: 10px;">
6485 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6486 </p>
6487 </div>
6488 <?php endif; ?>
6489
6490 <?php if ( ! empty( $ignored_files ) ) : ?>
6491 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6492 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6493 <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>
6494 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6495 <div class="vigilante-fi-bulk-bar">
6496 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6497 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6498 </div>
6499 <div class="vigilante-fi-pagination-wrap"></div>
6500 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6501 <thead>
6502 <tr>
6503 <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>
6504 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6505 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6506 </tr>
6507 </thead>
6508 <tbody>
6509 <?php foreach ( $ignored_files as $file ) : ?>
6510 <tr>
6511 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6512 <td><code><?php echo esc_html( $file ); ?></code></td>
6513 <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>
6514 </tr>
6515 <?php endforeach; ?>
6516 </tbody>
6517 </table>
6518 </div>
6519 <p style="margin-top: 10px;">
6520 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6521 </p>
6522 </div>
6523 <?php endif; ?>
6524 <?php
6525 }
6526
6527 /**
6528 * Render sidebar with promotional widgets
6529 */
6530 private function render_sidebar() {
6531 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6532 $promo_banner->render();
6533 }
6534
6535 /**
6536 * AJAX: Download a ZIP backup of the critical config files.
6537 *
6538 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6539 * downloadable archive. Config backups are no longer left as files under the
6540 * web root, so this hands the admin the archive directly.
6541 */
6542 public function ajax_download_files_backup() {
6543 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6544
6545 if ( ! current_user_can( 'manage_options' ) ) {
6546 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6547 }
6548
6549 // The archive carries wp-config.php, which a whole network shares. On a
6550 // network manage_options is held by every subsite administrator, so the
6551 // same gate the writers use applies here.
6552 if ( ! Vigilante_Settings::can_write_shared_files() ) {
6553 wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
6554 }
6555
6556 $backup_manager = new Vigilante_Backup_Manager();
6557 $result = $backup_manager->stream_files_zip();
6558
6559 // stream_files_zip() exits on success; only a WP_Error returns here.
6560 if ( is_wp_error( $result ) ) {
6561 wp_die( esc_html( $result->get_error_message() ), 500 );
6562 }
6563 }
6564
6565 /**
6566 * AJAX: Save settings
6567 */
6568 public function ajax_save_settings() {
6569 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6570
6571 if ( ! current_user_can( 'manage_options' ) ) {
6572 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6573 }
6574
6575 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6576
6577 // Handle $_POST['data'] based on type
6578 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6579 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6580 } elseif ( isset( $_POST['data'] ) ) {
6581 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6582 $raw_data = wp_unslash( $_POST['data'] );
6583 parse_str( $raw_data, $data );
6584 $data = map_deep( $data, 'sanitize_textarea_field' );
6585 } else {
6586 $data = array();
6587 }
6588
6589 if ( empty( $section ) ) {
6590 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6591 }
6592
6593 // Check if 2FA is being enabled or method changed (for notification sending)
6594 $send_2fa_notification = false;
6595 $send_login_url_notification = false;
6596
6597 if ( 'login_security' === $section ) {
6598 // Read old state from DB
6599 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6600 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6601 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6602
6603 // Check new state from submitted data
6604 $new_2fa_enabled = false;
6605 $notify_on_enable = false;
6606 $new_method = isset( $data['login_security']['two_factor']['method'] )
6607 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6608 : 'email';
6609
6610 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6611 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6612 }
6613 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6614 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6615 }
6616
6617 // Send notification if:
6618 // 1. 2FA is being enabled (was off, now on) OR
6619 // 2. Method changed while 2FA is enabled
6620 if ( $notify_on_enable && $new_2fa_enabled ) {
6621 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6622 $send_2fa_notification = true;
6623 }
6624 }
6625
6626 // Check if login URL changed and notification is enabled
6627 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6628 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6629 ? sanitize_title( $data['login_security']['custom_login_url'] )
6630 : '';
6631 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6632 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6633 : false;
6634
6635 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6636 $send_login_url_notification = true;
6637 }
6638 }
6639
6640 // Get defaults
6641 $defaults = $this->settings->get_default_options();
6642
6643 // Read ONLY saved options from database (not merged with defaults)
6644 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6645
6646 $rejected_ips = array();
6647
6648 // Handle modules
6649 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6650 if ( ! isset( $saved_options['modules'] ) ) {
6651 $saved_options['modules'] = array();
6652 }
6653 foreach ( $data['modules'] as $module => $enabled ) {
6654 $module = sanitize_key( $module );
6655 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6656 }
6657 // Clear active preset when modules change
6658 update_option( 'vigilante_active_preset', '' );
6659 } else {
6660 // Process primary section
6661 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6662 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6663 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6664
6665 // Process the submitted data
6666 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6667
6668 // The IP boxes are free text and, until 2.9.9, whatever was typed
6669 // went straight into the option. An entry the matcher can never
6670 // match still sits in a security list looking like protection,
6671 // so the ones that cannot match are dropped and reported back
6672 // instead of being stored in silence.
6673 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6674
6675 // Save the processed section
6676 $saved_options[ $section ] = $processed;
6677
6678 // Clear active preset when any section settings change
6679 update_option( 'vigilante_active_preset', '' );
6680 }
6681 }
6682
6683 // Clear cache before saving
6684 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6685
6686 // Save to database
6687 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6688
6689 // Clear the settings cache
6690 $this->settings->clear_cache();
6691
6692 // Apply changes based on section
6693 $this->apply_section_changes( $section, $saved_options );
6694
6695 // Send 2FA notifications after settings are saved
6696 $notification_result = null;
6697 if ( $send_2fa_notification ) {
6698 $notification_result = $this->send_2fa_enable_notifications();
6699 }
6700
6701 // Send login URL notifications after settings are saved
6702 $login_url_result = null;
6703 if ( $send_login_url_notification ) {
6704 $login_url_result = $this->send_login_url_notifications();
6705 }
6706
6707 // Build success message
6708 $message = __( 'Settings saved successfully.', 'vigilante' );
6709
6710 if ( $notification_result && $notification_result['sent'] > 0 ) {
6711 $message .= ' ' . sprintf(
6712 /* translators: %d: Number of emails sent */
6713 _n(
6714 '2FA notification sent to %d user.',
6715 '2FA notifications sent to %d users.',
6716 $notification_result['sent'],
6717 'vigilante'
6718 ),
6719 $notification_result['sent']
6720 );
6721 }
6722
6723 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6724 $message .= ' ' . sprintf(
6725 /* translators: %d: Number of emails sent */
6726 _n(
6727 'Login URL notification sent to %d user.',
6728 'Login URL notifications sent to %d users.',
6729 $login_url_result['sent'],
6730 'vigilante'
6731 ),
6732 $login_url_result['sent']
6733 );
6734 }
6735
6736 if ( ! empty( $rejected_ips ) ) {
6737 $message .= ' ' . sprintf(
6738 /* translators: %s: comma separated list of the entries that were not saved. */
6739 _n(
6740 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6741 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6742 count( $rejected_ips ),
6743 'vigilante'
6744 ),
6745 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6746 );
6747 }
6748
6749 wp_send_json_success( $message );
6750 }
6751
6752 /**
6753 * Keep only the IP patterns the matcher can actually match
6754 *
6755 * @since 2.9.9
6756 *
6757 * @param string $section Section being saved.
6758 * @param array $processed Section data, edited in place.
6759 * @return array Entries that were dropped, for the message back to the user.
6760 */
6761 private function filter_ip_lists( $section, &$processed ) {
6762 $lists = array(
6763 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6764 'login_security' => array( 'ip_whitelist' ),
6765 );
6766
6767 if ( ! isset( $lists[ $section ] ) ) {
6768 return array();
6769 }
6770
6771 $rejected = array();
6772
6773 foreach ( $lists[ $section ] as $key ) {
6774 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6775 continue;
6776 }
6777
6778 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6779 $processed[ $key ] = $split['valid'];
6780 $rejected = array_merge( $rejected, $split['rejected'] );
6781 }
6782
6783 return array_values( array_unique( $rejected ) );
6784 }
6785
6786 /**
6787 * Send 2FA enable notifications to users
6788 *
6789 * @return array Result with 'sent' and 'failed' counts.
6790 */
6791 private function send_2fa_enable_notifications() {
6792 $result = array(
6793 'sent' => 0,
6794 'failed' => 0,
6795 );
6796
6797 // Get settings for roles and method
6798 $login_security = $this->settings->get_section( 'login_security' );
6799 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6800 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6801 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6802
6803 if ( empty( $roles ) ) {
6804 $roles = array( 'administrator' );
6805 }
6806
6807 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6808
6809 // Get users with these roles
6810 $args = array(
6811 'role__in' => $roles,
6812 );
6813 if ( ! empty( $excluded ) ) {
6814 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6815 $args['exclude'] = $excluded;
6816 }
6817 $users = get_users( $args );
6818
6819 if ( empty( $users ) ) {
6820 return $result;
6821 }
6822
6823 $site_name = get_bloginfo( 'name' );
6824 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6825
6826 if ( 'totp' === $method ) {
6827 // Use TOTP class for styled HTML emails
6828 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6829 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6830 }
6831 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6832
6833 foreach ( $users as $user ) {
6834 // Skip users who already have TOTP configured
6835 $totp_data = $this->database->get_totp_data( $user->ID );
6836 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6837 continue;
6838 }
6839
6840 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6841
6842 if ( $sent ) {
6843 $this->database->mark_2fa_notified( $user->ID );
6844 $result['sent']++;
6845 } else {
6846 $result['failed']++;
6847 }
6848 }
6849 } else {
6850 // Email method - use existing email 2FA class
6851 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6852 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6853 }
6854 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6855 return $email_2fa->send_activation_notifications( false );
6856 }
6857
6858 return $result;
6859 }
6860
6861 /**
6862 * Send login URL change notifications to users with admin access
6863 *
6864 * @return array Result with 'sent' and 'failed' counts.
6865 */
6866 private function send_login_url_notifications() {
6867 $login_options = $this->settings->get_section( 'login_security' );
6868 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6869
6870 if ( empty( $custom_url ) ) {
6871 return array( 'sent' => 0, 'failed' => 0 );
6872 }
6873
6874 $login_url = home_url( $custom_url . '/' );
6875 $site_name = get_bloginfo( 'name' );
6876
6877 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6878 $users = get_users( array( 'role__in' => $admin_roles ) );
6879
6880 if ( empty( $users ) ) {
6881 return array( 'sent' => 0, 'failed' => 0 );
6882 }
6883
6884 $subject = sprintf(
6885 /* translators: %s: Site name */
6886 __( '[%s] Your login URL has changed', 'vigilante' ),
6887 $site_name
6888 );
6889
6890 $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' ) );
6891 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6892 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6893 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6894
6895 $sent = 0;
6896 $failed = 0;
6897
6898 foreach ( $users as $user ) {
6899 $result = Vigilante_Email_Template::send(
6900 $user->user_email,
6901 $subject,
6902 __( 'Login URL changed', 'vigilante' ),
6903 $body
6904 );
6905 if ( $result ) {
6906 $sent++;
6907 } else {
6908 $failed++;
6909 }
6910 }
6911
6912 if ( $this->activity_log ) {
6913 $this->activity_log->log(
6914 'login',
6915 'login_url_notified',
6916 sprintf(
6917 /* translators: 1: Sent count, 2: Failed count */
6918 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
6919 $sent,
6920 $failed
6921 )
6922 );
6923 }
6924
6925 return array( 'sent' => $sent, 'failed' => $failed );
6926 }
6927
6928 /**
6929 * Process section data maintaining proper types from defaults
6930 *
6931 * @param array $submitted_data Data submitted from form.
6932 * @param array $defaults Default values for this section.
6933 * @param array $current Current saved values.
6934 * @param string $section_name Section name for special handling.
6935 * @return array Processed data.
6936 */
6937 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
6938 // Start with defaults, then merge current saved values
6939 $result = array_replace_recursive( $defaults, $current );
6940
6941 // Process each submitted value
6942 foreach ( $submitted_data as $key => $value ) {
6943 $key = sanitize_key( $key );
6944
6945 if ( is_array( $value ) ) {
6946 // Nested array (like rate_limiting)
6947 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
6948 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
6949 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
6950 } else {
6951 // Determine type from default value
6952 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
6953
6954 if ( null === $default_value ) {
6955 // No default, check current value type or use as string
6956 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
6957 if ( is_bool( $current_value ) ) {
6958 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6959 } elseif ( is_int( $current_value ) ) {
6960 $result[ $key ] = intval( $value );
6961 } elseif ( is_array( $current_value ) ) {
6962 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
6963 } else {
6964 $result[ $key ] = sanitize_text_field( $value );
6965 }
6966 } elseif ( is_bool( $default_value ) ) {
6967 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
6968 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6969 } elseif ( is_int( $default_value ) ) {
6970 // Integer - with special handling for time fields shown in minutes
6971 $int_value = intval( $value );
6972
6973 // Convert minutes to seconds for login_security duration fields
6974 // These are displayed as minutes in the form but stored as seconds
6975 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
6976 $int_value = $int_value * 60;
6977 }
6978
6979 $result[ $key ] = $int_value;
6980 } elseif ( is_array( $default_value ) ) {
6981 // Array from textarea (e.g., IP lists)
6982 if ( is_string( $value ) ) {
6983 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
6984 } else {
6985 $result[ $key ] = (array) $value;
6986 }
6987 } else {
6988 // String - preserve newlines for textarea fields
6989 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
6990 $result[ $key ] = sanitize_textarea_field( $value );
6991 } else {
6992 $result[ $key ] = sanitize_text_field( $value );
6993 }
6994 }
6995 }
6996 }
6997
6998 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
6999 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
7000 //
7001 // EXCEPTION: the top-level 'enabled' flag of every section is the
7002 // module's master switch and is controlled by the Dashboard module
7003 // toggle, NOT by a checkbox inside the section's form. Treating it
7004 // like a regular checkbox here would silently switch the module off
7005 // every time the user saves the tab — see the REST API enabled=false
7006 // regression. We only skip it at the top level (when section_name is
7007 // empty); nested 'enabled' fields like security_headers.csp.enabled
7008 // are real checkboxes and must keep the auto-unset behaviour.
7009 $preserve_top_level = array( 'enabled' );
7010
7011 foreach ( $defaults as $key => $default_value ) {
7012 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
7013 continue;
7014 }
7015 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
7016 $result[ $key ] = false;
7017 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
7018 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
7019 // vs a nested settings group (like rate_limiting, two_factor)
7020 // Flat lists: default is empty array OR all values are scalar
7021 $is_value_list = empty( $default_value );
7022 if ( ! $is_value_list ) {
7023 $is_value_list = true;
7024 foreach ( $default_value as $dv ) {
7025 if ( ! is_scalar( $dv ) ) {
7026 $is_value_list = false;
7027 break;
7028 }
7029 }
7030 }
7031
7032 if ( $is_value_list ) {
7033 // All items removed - reset to empty array
7034 $result[ $key ] = array();
7035 } else {
7036 // Nested settings group - handle boolean children
7037 foreach ( $default_value as $nested_key => $nested_default ) {
7038 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
7039 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
7040 ? $submitted_data[ $key ]
7041 : array();
7042 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
7043 $result[ $key ][ $nested_key ] = false;
7044 }
7045 }
7046 }
7047 }
7048 }
7049 }
7050
7051 return $result;
7052 }
7053
7054 /**
7055 * AJAX: Export settings
7056 */
7057 public function ajax_export_settings() {
7058 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7059
7060 if ( ! current_user_can( 'manage_options' ) ) {
7061 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7062 }
7063
7064 $options = $this->settings->get_all_options();
7065 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
7066
7067 wp_send_json_success( array(
7068 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
7069 'filename' => $filename,
7070 ) );
7071 }
7072
7073 /**
7074 * AJAX: Import settings
7075 */
7076 public function ajax_import_settings() {
7077 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7078
7079 if ( ! current_user_can( 'manage_options' ) ) {
7080 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7081 }
7082
7083 // Accept both 'settings' (from JS) and 'content' (legacy).
7084 // Do NOT run sanitize_text_field() on the raw payload: it calls
7085 // wp_strip_all_tags() internally, which removes any "<...>" substring
7086 // and turns a valid export JSON into garbage if any stored value
7087 // contains < or > (htaccess snippets, email templates, etc.). The
7088 // real sanitization happens after json_decode(), via map_deep() on
7089 // the parsed array.
7090 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7091 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
7092 if ( empty( $content ) ) {
7093 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
7094 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
7095 }
7096
7097 if ( empty( $content ) || ! is_string( $content ) ) {
7098 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
7099 }
7100
7101 $imported = json_decode( $content, true );
7102
7103 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
7104 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
7105 }
7106
7107 // Sanitize imported data recursively
7108 $imported = map_deep( $imported, 'sanitize_text_field' );
7109
7110 // Validate structure
7111 $defaults = $this->settings->get_default_options();
7112 $merged = array_replace_recursive( $defaults, $imported );
7113
7114 // Save
7115 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7116 $this->settings->clear_cache();
7117
7118 // Re-evaluate the active preset marker. The imported config may match
7119 // a known preset exactly, partially, or not at all — without this step
7120 // the dashboard would keep showing whatever preset was active before
7121 // the import even if the new config no longer matches it.
7122 $matched_preset = $this->detect_matching_preset( $merged );
7123 if ( null === $matched_preset ) {
7124 delete_option( 'vigilante_active_preset' );
7125 } else {
7126 update_option( 'vigilante_active_preset', $matched_preset );
7127 }
7128
7129 // Apply file changes after import
7130 $this->apply_all_file_changes( $merged );
7131
7132 // Refresh the Security Analyzer score so the dashboard widget reflects
7133 // the imported config rather than the pre-import scan. Reuse the
7134 // post-Under-Attack scan hook (same job: full scan, async).
7135 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
7136 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
7137 }
7138
7139 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
7140 }
7141
7142 /**
7143 * Detect whether a vigilante_options array matches a known preset.
7144 *
7145 * A preset matches when every field the preset explicitly declares is
7146 * present in the config with the same (normalised) value. Fields outside
7147 * the preset are ignored — they may have been modified by the user before
7148 * applying the preset and do not invalidate the match. This mirrors how
7149 * apply_preset() now layers presets on top of the user's existing config.
7150 *
7151 * @param array $options The current/imported vigilante_options.
7152 * @return string|null Preset id ('standard', 'maximum') or null if custom.
7153 */
7154 private function detect_matching_preset( $options ) {
7155 if ( ! is_array( $options ) ) {
7156 return null;
7157 }
7158
7159 $presets = $this->settings->get_presets();
7160
7161 foreach ( $presets as $preset_id => $preset_data ) {
7162 unset( $preset_data['name'], $preset_data['description'] );
7163 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
7164 return $preset_id;
7165 }
7166 }
7167
7168 return null;
7169 }
7170
7171 /**
7172 * Check whether every leaf value inside $preset_subset exists with the
7173 * same (normalised) value at the same path inside $config.
7174 *
7175 * @param mixed $preset_subset Branch of the preset definition.
7176 * @param mixed $config Same branch in the live/imported config.
7177 * @return bool
7178 */
7179 private function preset_subset_matches( $preset_subset, $config ) {
7180 if ( is_array( $preset_subset ) ) {
7181 if ( ! is_array( $config ) ) {
7182 return false;
7183 }
7184 foreach ( $preset_subset as $key => $value ) {
7185 if ( ! array_key_exists( $key, $config ) ) {
7186 return false;
7187 }
7188 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
7189 return false;
7190 }
7191 }
7192 return true;
7193 }
7194
7195 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
7196 }
7197
7198 /**
7199 * Normalise a scalar value so that the variants WordPress and the form
7200 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
7201 * null → "") compare equal. Other values become strings unchanged.
7202 *
7203 * @param mixed $value
7204 * @return string
7205 */
7206 private function normalise_scalar_for_compare( $value ) {
7207 if ( is_bool( $value ) ) {
7208 return $value ? '1' : '';
7209 }
7210 if ( null === $value ) {
7211 return '';
7212 }
7213 if ( is_int( $value ) || is_float( $value ) ) {
7214 return (string) $value;
7215 }
7216 if ( is_string( $value ) ) {
7217 if ( 'true' === $value ) {
7218 return '1';
7219 }
7220 if ( 'false' === $value ) {
7221 return '';
7222 }
7223 return $value;
7224 }
7225 // Arrays and objects shouldn't reach here (handled by recursion above),
7226 // but if they do, fall back to a stable comparable representation.
7227 return wp_json_encode( $value );
7228 }
7229
7230 /**
7231 * AJAX: Apply preset
7232 */
7233 public function ajax_apply_preset() {
7234 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7235
7236 if ( ! current_user_can( 'manage_options' ) ) {
7237 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7238 }
7239
7240 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7241
7242 // Handle reset to defaults
7243 if ( 'reset' === $preset ) {
7244 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7245 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7246 $this->settings->clear_cache();
7247
7248 // Clear active preset
7249 update_option( 'vigilante_active_preset', '' );
7250
7251 // Apply file changes after reset
7252 $this->apply_all_file_changes( $defaults );
7253
7254 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
7255 return;
7256 }
7257
7258 $presets = $this->settings->get_presets();
7259
7260 if ( ! isset( $presets[ $preset ] ) ) {
7261 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7262 }
7263
7264 $preset_options = $presets[ $preset ];
7265 unset( $preset_options['name'], $preset_options['description'] );
7266
7267 // Layer the preset on top of the user's CURRENT configuration, not on
7268 // top of defaults. This way applying a preset only changes the fields
7269 // the preset explicitly mentions; everything else stays as the user
7270 // had it. For example, applying Maximum will not flip HSTS off if the
7271 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7272 // Use "Reset to Defaults" if a clean slate is needed.
7273 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7274 if ( ! is_array( $current ) ) {
7275 $current = array();
7276 }
7277 // Make sure all known keys exist before merging — the merge does not
7278 // invent keys that are missing on both sides.
7279 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7280
7281 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7282
7283 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7284 $this->settings->clear_cache();
7285
7286 // Save active preset
7287 update_option( 'vigilante_active_preset', $preset );
7288
7289 // Apply file changes after preset
7290 $this->apply_all_file_changes( $merged );
7291
7292 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
7293 }
7294
7295 /**
7296 * AJAX: Reset a specific section to defaults
7297 */
7298 public function ajax_reset_section() {
7299 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7300
7301 if ( ! current_user_can( 'manage_options' ) ) {
7302 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7303 }
7304
7305 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7306
7307 if ( empty( $section ) ) {
7308 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7309 }
7310
7311 // Get current options and defaults. get_defaults_preserving_user_data()
7312 // applies the tweaks a fresh installation gets, so the button and a new
7313 // install agree, and keeps whatever the owner typed in.
7314 $current_options = $this->settings->get_all_options();
7315 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7316
7317 // Check if section exists in defaults
7318 if ( ! isset( $defaults[ $section ] ) ) {
7319 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7320 }
7321
7322 $new_values = $defaults[ $section ];
7323
7324 /*
7325 * On a subsite, the settings written to wp-config.php and .htaccess are
7326 * the main site's business. Resetting the local copy of those would only
7327 * make this screen disagree with the file, so they are carried over
7328 * untouched, and a section that is nothing but shared settings is not
7329 * reset at all.
7330 */
7331 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7332 $shared = Vigilante_Settings::get_shared_file_settings();
7333
7334 if ( isset( $shared[ $section ] ) ) {
7335 if ( true === $shared[ $section ] ) {
7336 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7337 }
7338
7339 foreach ( $shared[ $section ] as $shared_key ) {
7340 if ( array_key_exists( $shared_key, (array) $current_options[ $section ] ) ) {
7341 $new_values[ $shared_key ] = $current_options[ $section ][ $shared_key ];
7342 }
7343 }
7344 }
7345 }
7346
7347 $current_options[ $section ] = $new_values;
7348
7349 // Save
7350 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7351 $this->settings->clear_cache();
7352
7353 // Apply file changes if needed
7354 $this->apply_section_changes( $section, $current_options );
7355
7356 wp_send_json_success( array(
7357 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7358 'section' => $section,
7359 'reload' => true,
7360 ) );
7361 }
7362
7363 /**
7364 * AJAX: Clear lockouts
7365 */
7366 public function ajax_clear_lockouts() {
7367 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7368
7369 if ( ! current_user_can( 'manage_options' ) ) {
7370 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7371 }
7372
7373 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7374
7375 if ( ! empty( $ip ) ) {
7376 $this->database->clear_lockout( $ip );
7377 } else {
7378 $this->database->clear_all_lockouts();
7379 }
7380
7381 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7382 }
7383
7384 /**
7385 * AJAX: Clear logs
7386 */
7387 public function ajax_clear_logs() {
7388 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7389
7390 if ( ! current_user_can( 'manage_options' ) ) {
7391 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7392 }
7393
7394 if ( $this->activity_log ) {
7395 $result = $this->activity_log->clear_all_logs();
7396 if ( $result ) {
7397 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7398 } else {
7399 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7400 }
7401 } else {
7402 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7403 }
7404 }
7405
7406 /**
7407 * AJAX: Run file integrity scan.
7408 *
7409 * Triggers the file integrity scan, which now also runs the closed plugins
7410 * check at the end when the `check_closed_plugins` toggle is on. Activity
7411 * log is passed through so Security Audit entries (both file-level and
7412 * plugin-status) are recorded from this entry point.
7413 */
7414 public function ajax_run_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 // Clear previous results before running new scan
7422 delete_option( 'vigilante_last_integrity_results' );
7423 delete_option( 'vigilante_last_integrity_scan' );
7424
7425 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7426 $results = $file_integrity->run_scan();
7427
7428 // Save new results
7429 update_option( 'vigilante_last_integrity_scan', time() );
7430 update_option( 'vigilante_last_integrity_results', $results );
7431
7432 wp_send_json_success( array(
7433 'message' => __( 'Scan completed.', 'vigilante' ),
7434 'results' => $results,
7435 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7436 ) );
7437 }
7438
7439 /**
7440 * AJAX: Clear scan results.
7441 *
7442 * Wipes visually everything inside "Last Scan Results": file scan findings
7443 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7444 * Closed + Removed Plugins block.
7445 *
7446 * Implementation detail to keep persistence intact:
7447 * - We delete the file scan options + hashes outright.
7448 * - For plugin status we ONLY delete the last_check timestamp — the state
7449 * map and the ignore list are preserved in DB. The render gates the
7450 * plugin_status subsections on last_check > 0, so they hide after
7451 * Clear (visual reset) and reappear on the next Run Scan Now with the
7452 * state intact. This avoids degrading a 'removed' slug (404 without
7453 * metadata) back to 'not_in_repo' on the next scan, which would
7454 * silently lose the alert.
7455 *
7456 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7457 * are preserved on purpose; each has its own explicit "Clear All …"
7458 * button.
7459 */
7460 public function ajax_clear_scan() {
7461 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7462
7463 if ( ! current_user_can( 'manage_options' ) ) {
7464 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7465 }
7466
7467 delete_option( 'vigilante_last_integrity_results' );
7468 delete_option( 'vigilante_last_integrity_scan' );
7469
7470 if ( $this->database ) {
7471 $this->database->clear_file_hashes();
7472 }
7473
7474 // Visual reset of plugin_status block without touching the state map
7475 // or the ignored list. See PHPDoc above for the rationale.
7476 delete_option( 'vigilante_plugin_status_last_check' );
7477
7478 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7479 }
7480
7481 /**
7482 * AJAX: Ignore a file from scan results
7483 */
7484 public function ajax_ignore_file() {
7485 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7486
7487 if ( ! current_user_can( 'manage_options' ) ) {
7488 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7489 }
7490
7491 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7492
7493 if ( empty( $file ) ) {
7494 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7495 }
7496
7497 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7498 $file_integrity->ignore_file( $file );
7499
7500 // Also remove the file from stored scan results so UI updates
7501 $results = get_option( 'vigilante_last_integrity_results' );
7502 if ( $results ) {
7503 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7504 if ( ! empty( $results[ $category ] ) ) {
7505 $results[ $category ] = array_values(
7506 array_filter(
7507 $results[ $category ],
7508 function ( $item ) use ( $file ) {
7509 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7510 }
7511 )
7512 );
7513 }
7514 }
7515 update_option( 'vigilante_last_integrity_results', $results );
7516 }
7517
7518 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7519 }
7520
7521 /**
7522 * AJAX: Stop ignoring a file
7523 */
7524 public function ajax_unignore_file() {
7525 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7526
7527 if ( ! current_user_can( 'manage_options' ) ) {
7528 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7529 }
7530
7531 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7532
7533 if ( empty( $file ) ) {
7534 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7535 }
7536
7537 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7538 $file_integrity->unignore_file( $file );
7539
7540 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7541 }
7542
7543 /**
7544 * AJAX: Bulk ignore multiple files at once
7545 *
7546 * Processes a single batch into ignored list and prunes them from the
7547 * stored scan results so the UI updates without a re-scan.
7548 */
7549 public function ajax_bulk_ignore_files() {
7550 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7551
7552 if ( ! current_user_can( 'manage_options' ) ) {
7553 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7554 }
7555
7556 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7557 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7558 if ( ! is_array( $raw_files ) ) {
7559 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7560 }
7561
7562 $files = array();
7563 foreach ( $raw_files as $f ) {
7564 $clean = sanitize_text_field( $f );
7565 if ( '' !== $clean ) {
7566 $files[] = $clean;
7567 }
7568 }
7569
7570 if ( empty( $files ) ) {
7571 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7572 }
7573
7574 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7575 $count = 0;
7576 foreach ( $files as $file ) {
7577 $file_integrity->ignore_file( $file );
7578 $count++;
7579 }
7580
7581 // Also prune the stored scan results so the UI matches the new ignore list.
7582 $results = get_option( 'vigilante_last_integrity_results' );
7583 if ( $results ) {
7584 $files_set = array_flip( $files );
7585 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7586 if ( ! empty( $results[ $category ] ) ) {
7587 $results[ $category ] = array_values(
7588 array_filter(
7589 $results[ $category ],
7590 function ( $item ) use ( $files_set ) {
7591 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7592 return ! isset( $files_set[ $path ] );
7593 }
7594 )
7595 );
7596 }
7597 }
7598 update_option( 'vigilante_last_integrity_results', $results );
7599 }
7600
7601 wp_send_json_success(
7602 array(
7603 'count' => $count,
7604 'message' => sprintf(
7605 /* translators: %d: number of files added to the ignored list */
7606 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7607 $count
7608 ),
7609 )
7610 );
7611 }
7612
7613 /**
7614 * AJAX: Bulk un-ignore multiple files at once
7615 */
7616 public function ajax_bulk_unignore_files() {
7617 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7618
7619 if ( ! current_user_can( 'manage_options' ) ) {
7620 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7621 }
7622
7623 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7624 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7625 if ( ! is_array( $raw_files ) ) {
7626 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7627 }
7628
7629 $files = array();
7630 foreach ( $raw_files as $f ) {
7631 $clean = sanitize_text_field( $f );
7632 if ( '' !== $clean ) {
7633 $files[] = $clean;
7634 }
7635 }
7636
7637 if ( empty( $files ) ) {
7638 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7639 }
7640
7641 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7642 $count = 0;
7643 foreach ( $files as $file ) {
7644 $file_integrity->unignore_file( $file );
7645 $count++;
7646 }
7647
7648 wp_send_json_success(
7649 array(
7650 'count' => $count,
7651 'message' => sprintf(
7652 /* translators: %d: number of files removed from the ignored list */
7653 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7654 $count
7655 ),
7656 )
7657 );
7658 }
7659
7660 /**
7661 * AJAX: Clear all ignored files
7662 */
7663 public function ajax_clear_ignored() {
7664 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7665
7666 if ( ! current_user_can( 'manage_options' ) ) {
7667 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7668 }
7669
7670 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7671 $file_integrity->clear_ignored_files();
7672
7673 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7674 }
7675
7676 /**
7677 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7678 * main list and email digests. The plugin keeps running on the site;
7679 * silencing is purely cosmetic and reversible.
7680 */
7681 public function ajax_ignore_closed_plugin() {
7682 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7683
7684 if ( ! current_user_can( 'manage_options' ) ) {
7685 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7686 }
7687
7688 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7689 if ( '' === $slug ) {
7690 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7691 }
7692
7693 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7694 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7695 }
7696 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7697 $checker->ignore_slug( $slug );
7698
7699 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7700 }
7701
7702 /**
7703 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7704 */
7705 public function ajax_unignore_closed_plugin() {
7706 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7707
7708 if ( ! current_user_can( 'manage_options' ) ) {
7709 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7710 }
7711
7712 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7713 if ( '' === $slug ) {
7714 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7715 }
7716
7717 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7718 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7719 }
7720 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7721 $checker->unignore_slug( $slug );
7722
7723 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7724 }
7725
7726 /**
7727 * AJAX: Clear the entire ignored-closed-plugins list.
7728 */
7729 public function ajax_clear_ignored_closed_plugins() {
7730 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7731
7732 if ( ! current_user_can( 'manage_options' ) ) {
7733 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7734 }
7735
7736 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7737 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7738 }
7739 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7740 $checker->clear_ignored();
7741
7742 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7743 }
7744
7745 /**
7746 * AJAX: Test security headers
7747 */
7748 public function ajax_test_headers() {
7749 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7750
7751 if ( ! current_user_can( 'manage_options' ) ) {
7752 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7753 }
7754
7755 // Get security grade from settings (not from actual HTTP request)
7756 $security_headers = new Vigilante_Security_Headers( $this->settings );
7757 $results = $security_headers->get_security_grade();
7758
7759 wp_send_json_success( $results );
7760 }
7761
7762 /**
7763 * Sanitize section data (kept for compatibility)
7764 *
7765 * @param string $section Section name.
7766 * @param array $data Section data.
7767 * @return array
7768 */
7769 private function sanitize_section_data( $section, $data ) {
7770 $sanitized = array();
7771
7772 foreach ( $data as $key => $value ) {
7773 $key = sanitize_key( $key );
7774
7775 if ( is_array( $value ) ) {
7776 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7777 } elseif ( is_numeric( $value ) ) {
7778 $sanitized[ $key ] = intval( $value );
7779 } else {
7780 $sanitized[ $key ] = sanitize_text_field( $value );
7781 }
7782 }
7783
7784 return $sanitized;
7785 }
7786
7787 /**
7788 * Apply changes after saving settings
7789 *
7790 * @param string $section Section that was updated.
7791 * @param array $all_options All options.
7792 */
7793 private function apply_section_changes( $section, $all_options ) {
7794 // Create fresh settings instance to ensure we have the latest data
7795 $fresh_settings = new Vigilante_Settings();
7796
7797 // The shared Vigilant .htaccess block carries BOTH the firewall's
7798 // file-protection rules and the server-signature / fingerprinting rules
7799 // that are configured under Security Headers. So it must be regenerated
7800 // whenever either section (or the module toggles) changes, not only on
7801 // the firewall save — otherwise toggling "Hide server signature" or
7802 // "Remove fingerprinting headers" never reaches the .htaccess.
7803 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7804 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7805 $sh = $fresh_settings->get_section( 'security_headers' );
7806 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7807 || ! empty( $sh['hide_server_signature'] )
7808 || ! empty( $sh['remove_fingerprinting_headers'] );
7809
7810 if ( $needs_htaccess_block ) {
7811 $htaccess->apply_rules();
7812 } else {
7813 $htaccess->remove_rules();
7814 }
7815 }
7816
7817 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7818 if ( 'security_headers' === $section || 'modules' === $section ) {
7819 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7820 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7821
7822 if ( $headers_enabled ) {
7823 $security_headers->apply_rules();
7824 } else {
7825 $security_headers->remove_rules();
7826 }
7827 }
7828
7829 // Regenerate wp-config for wp_hardening section
7830 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7831 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7832 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7833
7834 if ( $hardening_enabled ) {
7835 $wpconfig->apply_security_constants();
7836 } else {
7837 $wpconfig->remove_constants();
7838 }
7839
7840 // Apply WordPress options for comments/pingbacks
7841 $hardening_options = $all_options['wp_hardening'] ?? array();
7842
7843 if ( $hardening_enabled ) {
7844 // Pingbacks
7845 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7846 update_option( 'default_pingback_flag', 0 );
7847 } else {
7848 // Restore default: pingbacks enabled
7849 update_option( 'default_pingback_flag', 1 );
7850 }
7851
7852 // Trackbacks and ping status
7853 // Only close if either pingbacks OR trackbacks are disabled
7854 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7855 update_option( 'default_ping_status', 'closed' );
7856 } else {
7857 // Restore default: pings open
7858 update_option( 'default_ping_status', 'open' );
7859 }
7860
7861 // Comment moderation
7862 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7863 update_option( 'comment_moderation', 1 );
7864 } else {
7865 // Restore default: no moderation required
7866 update_option( 'comment_moderation', 0 );
7867 }
7868 }
7869 }
7870
7871 // Trim activity log entries immediately when limits change
7872 if ( 'activity_log' === $section && $this->activity_log ) {
7873 $this->activity_log->cleanup_old_logs();
7874 }
7875
7876 // Flush rewrite rules if login URL changed
7877 if ( 'login_security' === $section ) {
7878 $login_options = $all_options['login_security'] ?? array();
7879 if ( ! empty( $login_options['custom_login_url'] ) ) {
7880 delete_option( 'vigilante_login_rules_version' );
7881 }
7882 }
7883
7884 // Log the settings change with readable section name
7885 if ( $this->activity_log ) {
7886 $section_names = array(
7887 'firewall' => __( 'Firewall', 'vigilante' ),
7888 'login_security' => __( 'Login Security', 'vigilante' ),
7889 'security_headers' => __( 'Security Headers', 'vigilante' ),
7890 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7891 'user_security' => __( 'User Security', 'vigilante' ),
7892 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7893 'activity_log' => __( 'Security Audit', 'vigilante' ),
7894 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7895 'email' => __( 'Notification Settings', 'vigilante' ),
7896 'backup' => __( 'Backup', 'vigilante' ),
7897 'advanced' => __( 'Advanced', 'vigilante' ),
7898 'modules' => __( 'Modules', 'vigilante' ),
7899 );
7900 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
7901
7902 $this->activity_log->log(
7903 'settings',
7904 'settings_updated',
7905 sprintf(
7906 /* translators: %s: Section name */
7907 __( 'Settings updated: %s', 'vigilante' ),
7908 $display_name
7909 ),
7910 array( 'section' => $section ),
7911 'info'
7912 );
7913 }
7914 }
7915
7916 /**
7917 * Apply all file changes (htaccess, wp-config) based on current options
7918 *
7919 * Used after preset, import, or reset operations
7920 *
7921 * @param array $all_options All plugin options.
7922 */
7923 private function apply_all_file_changes( $all_options ) {
7924 // Refresh settings cache first
7925 $this->settings->clear_cache();
7926
7927 // Create fresh settings instance
7928 $fresh_settings = new Vigilante_Settings();
7929
7930 // Apply firewall htaccess changes
7931 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7932 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
7933
7934 if ( $firewall_enabled ) {
7935 $htaccess->apply_rules();
7936 } else {
7937 $htaccess->remove_rules();
7938 }
7939
7940 // Apply security headers htaccess changes
7941 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7942 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7943
7944 if ( $headers_enabled ) {
7945 $security_headers->apply_rules();
7946 } else {
7947 $security_headers->remove_rules();
7948 }
7949
7950 // Apply wp-config changes
7951 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7952 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7953
7954 if ( $hardening_enabled ) {
7955 $wpconfig->apply_security_constants();
7956 } else {
7957 $wpconfig->remove_constants();
7958 }
7959
7960 // Apply WordPress options for comments/pingbacks
7961 $hardening_options = $all_options['wp_hardening'] ?? array();
7962
7963 if ( $hardening_enabled ) {
7964 // Pingbacks
7965 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7966 update_option( 'default_pingback_flag', 0 );
7967 } else {
7968 // Restore default: pingbacks enabled
7969 update_option( 'default_pingback_flag', 1 );
7970 }
7971
7972 // Trackbacks and ping status
7973 // Only close if either pingbacks OR trackbacks are disabled
7974 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7975 update_option( 'default_ping_status', 'closed' );
7976 } else {
7977 // Restore default: pings open
7978 update_option( 'default_ping_status', 'open' );
7979 }
7980
7981 // Comment moderation
7982 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7983 update_option( 'comment_moderation', 1 );
7984 } else {
7985 // Restore default: no moderation required
7986 update_option( 'comment_moderation', 0 );
7987 }
7988 }
7989
7990 // Log the change
7991 if ( $this->activity_log ) {
7992 $this->activity_log->log(
7993 'settings',
7994 'bulk_settings_applied',
7995 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
7996 array(),
7997 'info'
7998 );
7999 }
8000 }
8001 }