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

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