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

7,766 lines 497.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
32 /**
33 * Settings instance
34 *
35 * @var Vigilante_Settings
36 */
37 private $settings;
38
39 /**
40 * Database instance
41 *
42 * @var Vigilante_Database
43 */
44 private $database;
45
46 /**
47 * Activity log instance
48 *
49 * @var Vigilante_Activity_Log
50 */
51 private $activity_log;
52
53 /**
54 * Current tab
55 *
56 * @var string
57 */
58 private $current_tab = 'dashboard';
59
60 /**
61 * Available tabs
62 *
63 * @var array
64 */
65 private $tabs = array();
66
67 /**
68 * Constructor
69 *
70 * @param Vigilante_Settings $settings Settings instance.
71 * @param Vigilante_Database $database Database instance.
72 * @param Vigilante_Activity_Log $activity_log Activity log instance.
73 */
74 public function __construct( $settings, $database, $activity_log ) {
75 $this->settings = $settings;
76 $this->database = $database;
77 $this->activity_log = $activity_log;
78
79 $this->setup_tabs();
80 $this->init_hooks();
81 }
82
83 /**
84 * Setup available tabs
85 */
86 private function setup_tabs() {
87 $this->tabs = array(
88 'dashboard' => __( 'Dashboard', 'vigilante' ),
89 'firewall' => __( 'Firewall', 'vigilante' ),
90 'headers' => __( 'Security Headers', 'vigilante' ),
91 'login' => __( 'Login Security', 'vigilante' ),
92 'rest-api' => __( 'REST API', 'vigilante' ),
93 'users' => __( 'User Security', 'vigilante' ),
94 'wp-hardening' => __( 'WP Hardening', 'vigilante' ),
95 'file-integrity' => __( 'File Integrity', 'vigilante' ),
96 'activity-log' => __( 'Security Audit', 'vigilante' ),
97 'tools' => __( 'Settings & Tools', 'vigilante' ),
98 );
99 }
100
101 /**
102 * Initialize hooks
103 */
104 private function init_hooks() {
105 add_action( 'admin_menu', array( $this, 'add_menu' ) );
106 add_action( 'admin_init', array( $this, 'redirect_submenu_shortcuts' ) );
107 add_action( 'admin_init', array( $this, 'register_settings' ) );
108 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
109 add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
110
111 // Highlight correct submenu based on active tab
112 add_filter( 'submenu_file', array( $this, 'highlight_submenu_tab' ) );
113
114 // Set browser tab title to show plugin name and active tab
115 add_filter( 'admin_title', array( $this, 'set_admin_page_title' ), 10, 2 );
116
117 // AJAX handlers
118 add_action( 'wp_ajax_vigilante_save_settings', array( $this, 'ajax_save_settings' ) );
119 add_action( 'wp_ajax_vigilante_apply_preset', array( $this, 'ajax_apply_preset' ) );
120 add_action( 'wp_ajax_vigilante_reset_section', array( $this, 'ajax_reset_section' ) );
121 add_action( 'wp_ajax_vigilante_clear_lockouts', array( $this, 'ajax_clear_lockouts' ) );
122 add_action( 'wp_ajax_vigilante_clear_logs', array( $this, 'ajax_clear_logs' ) );
123 add_action( 'wp_ajax_vigilante_run_scan', array( $this, 'ajax_run_scan' ) );
124 add_action( 'wp_ajax_vigilante_clear_scan', array( $this, 'ajax_clear_scan' ) );
125 add_action( 'wp_ajax_vigilante_ignore_file', array( $this, 'ajax_ignore_file' ) );
126 add_action( 'wp_ajax_vigilante_unignore_file', array( $this, 'ajax_unignore_file' ) );
127 add_action( 'wp_ajax_vigilante_bulk_ignore_files', array( $this, 'ajax_bulk_ignore_files' ) );
128 add_action( 'wp_ajax_vigilante_bulk_unignore_files', array( $this, 'ajax_bulk_unignore_files' ) );
129 add_action( 'wp_ajax_vigilante_clear_ignored', array( $this, 'ajax_clear_ignored' ) );
130 add_action( 'wp_ajax_vigilante_ignore_closed_plugin', array( $this, 'ajax_ignore_closed_plugin' ) );
131 add_action( 'wp_ajax_vigilante_unignore_closed_plugin', array( $this, 'ajax_unignore_closed_plugin' ) );
132 add_action( 'wp_ajax_vigilante_clear_ignored_closed_plugins', array( $this, 'ajax_clear_ignored_closed_plugins' ) );
133 add_action( 'wp_ajax_vigilante_approve_critical_file', array( $this, 'ajax_approve_critical_file' ) );
134 add_action( 'wp_ajax_vigilante_export_settings', array( $this, 'ajax_export_settings' ) );
135 add_action( 'wp_ajax_vigilante_import_settings', array( $this, 'ajax_import_settings' ) );
136 add_action( 'wp_ajax_vigilante_get_logs', array( $this, 'ajax_get_logs' ) );
137 add_action( 'wp_ajax_vigilante_test_headers', array( $this, 'ajax_test_headers' ) );
138 add_action( 'wp_ajax_vigilante_download_files_backup', array( $this, 'ajax_download_files_backup' ) );
139
140 // 2FA AJAX handlers
141 add_action( 'wp_ajax_vigilante_search_users_2fa', array( $this, 'ajax_search_users_2fa' ) );
142 add_action( 'wp_ajax_vigilante_send_2fa_notification', array( $this, 'ajax_send_2fa_notification' ) );
143 add_action( 'wp_ajax_vigilante_search_totp_users', array( $this, 'ajax_search_totp_users' ) );
144 add_action( 'wp_ajax_vigilante_reset_totp_users', array( $this, 'ajax_reset_totp_users' ) );
145 add_action( 'wp_ajax_vigilante_totp_get_setup', array( $this, 'ajax_totp_get_setup' ) );
146 add_action( 'wp_ajax_vigilante_notify_login_url', array( $this, 'ajax_notify_login_url' ) );
147
148 // Password Reset AJAX handlers
149 add_action( 'wp_ajax_vigilante_search_users_password_reset', array( $this, 'ajax_search_users_password_reset' ) );
150 add_action( 'wp_ajax_vigilante_force_password_reset', array( $this, 'ajax_force_password_reset' ) );
151 add_action( 'wp_ajax_vigilante_force_password_reset_all', array( $this, 'ajax_force_password_reset_all' ) );
152 add_action( 'wp_ajax_vigilante_force_password_reset_by_role', array( $this, 'ajax_force_password_reset_by_role' ) );
153
154 // User approval AJAX handlers
155 add_action( 'wp_ajax_vigilante_approve_user', array( $this, 'ajax_approve_user' ) );
156 add_action( 'wp_ajax_vigilante_reject_user', array( $this, 'ajax_reject_user' ) );
157
158 // Session management AJAX handlers
159 add_action( 'wp_ajax_vigilante_get_user_sessions', array( $this, 'ajax_get_user_sessions' ) );
160 add_action( 'wp_ajax_vigilante_revoke_session', array( $this, 'ajax_revoke_session' ) );
161 add_action( 'wp_ajax_vigilante_revoke_all_sessions', array( $this, 'ajax_revoke_all_sessions' ) );
162
163 // Under Attack mode AJAX handlers
164 add_action( 'wp_ajax_vigilante_activate_under_attack', array( $this, 'ajax_activate_under_attack' ) );
165 add_action( 'wp_ajax_vigilante_deactivate_under_attack', array( $this, 'ajax_deactivate_under_attack' ) );
166 add_action( 'wp_ajax_vigilante_under_attack_status', array( $this, 'ajax_under_attack_status' ) );
167
168 // Database backup AJAX handlers
169 add_action( 'wp_ajax_vigilante_get_db_tables', array( $this, 'ajax_get_db_tables' ) );
170 add_action( 'wp_ajax_vigilante_download_db_backup', array( $this, 'ajax_download_db_backup' ) );
171
172 // Database prefix AJAX handlers
173 add_action( 'wp_ajax_vigilante_generate_prefix', array( $this, 'ajax_generate_prefix' ) );
174 add_action( 'wp_ajax_vigilante_change_prefix', array( $this, 'ajax_change_prefix' ) );
175
176 // Firewall list management from activity log popup
177 add_action( 'wp_ajax_vigilante_add_to_firewall_list', array( $this, 'ajax_add_to_firewall_list' ) );
178 add_action( 'wp_ajax_vigilante_unblock_firewall_ip', array( $this, 'ajax_unblock_firewall_ip' ) );
179
180 // Security Analyzer AJAX handlers (v2.1.0)
181 add_action( 'wp_ajax_vigilante_analyzer_run', array( $this, 'ajax_analyzer_run' ) );
182 add_action( 'wp_ajax_vigilante_analyzer_history', array( $this, 'ajax_analyzer_history' ) );
183 add_action( 'wp_ajax_vigilante_analyzer_dismiss_notice', array( $this, 'ajax_analyzer_dismiss_notice' ) );
184 add_action( 'wp_ajax_vigilante_analyzer_save_settings', array( $this, 'ajax_analyzer_save_settings' ) );
185
186 // Shared "Send test email" handler — Notification settings, File Integrity, Audit Alerts (v2.8.0)
187 add_action( 'wp_ajax_vigilante_send_test_email', array( $this, 'ajax_send_test_email' ) );
188
189 // Run migrations on admin load
190 add_action( 'admin_init', array( $this, 'run_migrations' ) );
191 }
192
193 /**
194 * Run database migrations based on stored version
195 */
196 public function run_migrations() {
197 $db_version = get_option( 'vigilante_db_version', '0' );
198
199 // 1.2.3: Fix IP lists corrupted by sanitize_text_field stripping newlines
200 if ( version_compare( $db_version, '1.2.3', '<' ) ) {
201 $this->migrate_fix_ip_lists();
202 update_option( 'vigilante_db_version', '1.2.3' );
203 }
204
205 // 1.3.0: Add request_method column to activity log table
206 if ( version_compare( $db_version, '1.3.0', '<' ) ) {
207 $this->database->run_migrations();
208 }
209
210 // 1.9.0: Re-apply wp-config constants (performance constants removed from managed list)
211 if ( version_compare( $db_version, '1.9.0', '<' ) ) {
212 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
213 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
214 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
215 $wpconfig->apply_security_constants();
216 }
217 update_option( 'vigilante_db_version', '1.9.0' );
218 }
219
220 // 1.10.0: Clean up orphaned email fields (centralized notification recipients)
221 if ( version_compare( $db_version, '1.10.0', '<' ) ) {
222 $this->migrate_cleanup_email_fields();
223 update_option( 'vigilante_db_version', '1.10.0' );
224 }
225
226 // 1.11.0: Remove stale 'enabled' key from activity_log settings
227 // + Convert additional_recipients from string to array
228 if ( version_compare( $db_version, '1.11.0', '<' ) ) {
229 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
230 $changed = false;
231
232 if ( isset( $options['activity_log']['enabled'] ) ) {
233 unset( $options['activity_log']['enabled'] );
234 $changed = true;
235 }
236
237 // Convert corrupted string to array for additional_recipients
238 if ( isset( $options['email']['additional_recipients'] ) && is_string( $options['email']['additional_recipients'] ) ) {
239 $raw = trim( $options['email']['additional_recipients'] );
240 if ( ! empty( $raw ) ) {
241 $emails = array_filter( array_map( 'trim', preg_split( '/[\r\n,; ]+/', $raw ) ) );
242 $options['email']['additional_recipients'] = array_values( array_filter( $emails, 'is_email' ) );
243 } else {
244 $options['email']['additional_recipients'] = array();
245 }
246 $changed = true;
247 }
248
249 if ( $changed ) {
250 update_option( Vigilante_Settings::OPTION_NAME, $options );
251 }
252 update_option( 'vigilante_db_version', '1.11.0' );
253 }
254
255 // 1.12.1: Regenerate htaccess (WooCommerce IPN exclusion in bot blocking rule)
256 if ( version_compare( $db_version, '1.12.1', '<' ) ) {
257 if ( ! empty( $this->settings->get_section( 'firewall' )['block_bad_bots'] ) ) {
258 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
259 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
260 $htaccess->apply_rules();
261 }
262 update_option( 'vigilante_db_version', '1.12.1' );
263 }
264
265 // 1.14.0: Generate critical config files baseline (wp-config.php, .htaccess)
266 if ( version_compare( $db_version, '1.14.0', '<' ) ) {
267 if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
268 require_once VIGILANTE_INCLUDES_DIR . 'class-file-integrity.php';
269 }
270 $fi = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
271 $fi->regenerate_all_baselines();
272 update_option( 'vigilante_db_version', '1.14.0' );
273 }
274
275 // 2.0.0: Move hide_server_signature and remove_fingerprinting_headers
276 // from firewall section to security_headers section
277 if ( version_compare( $db_version, '2.0.0', '<' ) ) {
278 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
279 $changed = false;
280
281 foreach ( array( 'hide_server_signature', 'remove_fingerprinting_headers' ) as $key ) {
282 if ( isset( $options['firewall'][ $key ] ) ) {
283 if ( ! isset( $options['security_headers'][ $key ] ) ) {
284 $options['security_headers'][ $key ] = $options['firewall'][ $key ];
285 }
286 unset( $options['firewall'][ $key ] );
287 $changed = true;
288 }
289 }
290
291 if ( $changed ) {
292 update_option( Vigilante_Settings::OPTION_NAME, $options );
293 }
294 update_option( 'vigilante_db_version', '2.0.0' );
295 }
296
297 // 2.6.1: Two things happen here.
298 //
299 // 1. Re-apply wp-config constants so the block is rewritten with
300 // "if ( ! defined() )" guards around every define(). Without guards,
301 // non-standard setups that pre-define WordPress constants outside
302 // wp-config.php (custom bootstraps that load constants from .env or
303 // similar) hit a fatal "Constant already defined" when wp-config.php
304 // is parsed and reaches our block.
305 //
306 // 2. Drop the cached Security Check report. The cached "max" per
307 // category was frozen at scan time; with the internal category
308 // bumping from 22 to 28 points (closed_plugins added in 2.6.0),
309 // the cached report would keep displaying 22/22 until the next
310 // full scan. Clearing it forces a fresh scan with the new caps.
311 if ( version_compare( $db_version, '2.6.1', '<' ) ) {
312 if ( $this->settings->is_module_enabled( 'wp_hardening' ) ) {
313 require_once VIGILANTE_INCLUDES_DIR . 'class-wpconfig-security.php';
314 $wpconfig = new Vigilante_Wpconfig_Security( $this->settings );
315 $wpconfig->apply_security_constants();
316 }
317 delete_option( 'vigilante_analyzer_last_scan' );
318
319 // Schedule an immediate background scan so the dashboard widget
320 // doesn't display "Last scan: never" right after the upgrade.
321 // Reuses the same hook the post-Under-Attack flow uses.
322 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
323 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
324 }
325
326 update_option( 'vigilante_db_version', '2.6.1' );
327 }
328
329 // 2.9.3: Regenerate the .htaccess protection block. The bad-bots
330 // User-Agent list dropped substring-prone tokens that 403'd
331 // legitimate clients (e.g. "rma" matched inside "Performance" and
332 // blocked WP Rocket's page fetch), and the blocking rules now honour
333 // the firewall IP / User-Agent whitelists as negated exceptions.
334 // Existing sites only rewrite the block when Server Protection is
335 // saved, so the upgrade has to refresh it once itself (same pattern
336 // as the 1.12.1 WooCommerce IPN migration).
337 if ( version_compare( $db_version, '2.9.3', '<' ) ) {
338 require_once VIGILANTE_INCLUDES_DIR . 'class-htaccess-protection.php';
339 $htaccess = new Vigilante_Htaccess_Protection( $this->settings );
340
341 if ( $htaccess->are_rules_active() ) {
342 $htaccess->apply_rules();
343 }
344
345 update_option( 'vigilante_db_version', '2.9.3' );
346 }
347
348 /*
349 * 2.9.8: the mixed content handling changes shape. "Upgrade Insecure
350 * Requests" becomes a setting of its own, and Fix Mixed Content ships
351 * off, where before it shipped on and carried the directive with it.
352 * Both have to be written down for sites that are updating, so their
353 * pages keep loading exactly what they loaded yesterday.
354 *
355 * Read the RAW stored options, not get_section(): that one merges the
356 * defaults, so a site that never stored the key would be read with the
357 * new default and silently lose the behaviour it had. Absent means the
358 * site was running on the old default, which was on.
359 */
360 if ( version_compare( $db_version, '2.9.8', '<' ) ) {
361 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
362 $stored = ( is_array( $raw ) && isset( $raw['security_headers'] ) && is_array( $raw['security_headers'] ) ) ? $raw['security_headers'] : array();
363 $had_fix = array_key_exists( 'fix_mixed_content', $stored ) ? ! empty( $stored['fix_mixed_content'] ) : true;
364
365 $this->settings->update_section(
366 'security_headers',
367 array(
368 'fix_mixed_content' => $had_fix,
369 'upgrade_insecure_requests' => $had_fix,
370 )
371 );
372
373 update_option( 'vigilante_db_version', '2.9.8' );
374 }
375
376 /*
377 * 2.9.9: drop the settings that no code has read for versions.
378 *
379 * They were carried in the defaults and therefore written into every
380 * saved configuration, they show up in an exported configuration, and
381 * anyone reading them assumes a feature exists behind them. Removing
382 * them from the defaults is not enough: the stored copies survive, so
383 * they are swept here too. Nothing reads them, so nothing changes.
384 */
385 if ( version_compare( $db_version, '2.9.9', '<' ) ) {
386 $raw = get_option( Vigilante_Settings::OPTION_NAME, array() );
387 $dead = array(
388 'firewall' => array( 'country_blocking', 'protected_file_extensions' ),
389 'file_integrity' => array( 'suspicious_patterns' ),
390 'backup' => array( 'auto_backup', 'backup_before_update' ),
391 'advanced' => array( 'block_author_archives', 'disable_embeds', 'uninstall_cleanup', 'debug_mode' ),
392 );
393
394 $changed = false;
395 foreach ( $dead as $section => $keys ) {
396 if ( ! isset( $raw[ $section ] ) || ! is_array( $raw[ $section ] ) ) {
397 continue;
398 }
399 foreach ( $keys as $key ) {
400 if ( array_key_exists( $key, $raw[ $section ] ) ) {
401 unset( $raw[ $section ][ $key ] );
402 $changed = true;
403 }
404 }
405 }
406
407 if ( $changed ) {
408 update_option( Vigilante_Settings::OPTION_NAME, $raw );
409 }
410
411 update_option( 'vigilante_db_version', '2.9.9' );
412 }
413 }
414
415 /**
416 * Migration: Remove orphaned email fields from saved options
417 *
418 * v1.10.0 centralized notification recipients into email section.
419 * Old per-module notify_email fields and dead email section fields
420 * are removed to avoid confusion.
421 */
422 private function migrate_cleanup_email_fields() {
423 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
424 $modified = false;
425
426 // Remove orphaned fields from email section
427 $dead_email_keys = array( 'enabled', 'from_name', 'from_email', 'admin_email', 'send_activation_email', 'custom_email' );
428 if ( isset( $options['email'] ) && is_array( $options['email'] ) ) {
429 foreach ( $dead_email_keys as $key ) {
430 if ( array_key_exists( $key, $options['email'] ) ) {
431 unset( $options['email'][ $key ] );
432 $modified = true;
433 }
434 }
435 // Ensure new fields exist with defaults
436 if ( ! array_key_exists( 'send_to_admin_email', $options['email'] ) ) {
437 $options['email']['send_to_admin_email'] = true;
438 $modified = true;
439 }
440 if ( ! array_key_exists( 'additional_recipients', $options['email'] ) ) {
441 $options['email']['additional_recipients'] = '';
442 $modified = true;
443 }
444 }
445
446 // Remove notify_email from login_security
447 if ( isset( $options['login_security']['notify_email'] ) ) {
448 unset( $options['login_security']['notify_email'] );
449 $modified = true;
450 }
451
452 // Remove notify_email from file_integrity
453 if ( isset( $options['file_integrity']['notify_email'] ) ) {
454 unset( $options['file_integrity']['notify_email'] );
455 $modified = true;
456 }
457
458 if ( $modified ) {
459 update_option( Vigilante_Settings::OPTION_NAME, $options );
460 // Clear settings cache so the plugin uses clean data immediately
461 $this->settings->clear_cache();
462 }
463 }
464
465 /**
466 * Migration: Fix IP whitelist/blacklist entries merged into single line
467 *
468 * Prior to 1.2.3, sanitize_text_field() stripped newlines from textarea data,
469 * causing multiple IPs to be stored as a single space-separated string.
470 */
471 private function migrate_fix_ip_lists() {
472 $options = get_option( Vigilante_Settings::OPTION_NAME, array() );
473 $fixed = false;
474
475 foreach ( array( 'ip_whitelist', 'ip_blacklist' ) as $key ) {
476 if ( ! empty( $options['firewall'][ $key ] ) && is_array( $options['firewall'][ $key ] ) ) {
477 $new_list = array();
478 foreach ( $options['firewall'][ $key ] as $entry ) {
479 // Split entries that were joined by spaces
480 $parts = preg_split( '/\s+/', trim( $entry ) );
481 foreach ( $parts as $part ) {
482 $part = trim( $part );
483 if ( '' !== $part ) {
484 $new_list[] = $part;
485 }
486 }
487 }
488 if ( count( $new_list ) !== count( $options['firewall'][ $key ] ) ) {
489 $options['firewall'][ $key ] = array_unique( $new_list );
490 $fixed = true;
491 }
492 }
493 }
494
495 if ( $fixed ) {
496 update_option( Vigilante_Settings::OPTION_NAME, $options );
497 // Clear settings cache so changes take effect immediately
498 $this->settings->clear_cache();
499 }
500 }
501
502 /**
503 * Add admin menu page in last position
504 */
505 public function add_menu() {
506 $menu_title = __( 'Vigilant', 'vigilante' );
507
508 // Count pending approvals (separate concern, always red if present)
509 $pending_count = $this->get_pending_approvals_count();
510
511 // Get security issues with severity
512 $security_status = $this->get_security_status_for_badge();
513
514 // Total count for badge
515 $total_badge = $pending_count + $security_status['count'];
516
517 if ( $total_badge > 0 ) {
518 // Determine badge color:
519 // - Red (awaiting-mod): pending approvals OR critical modules disabled
520 // - Orange (update-plugins): only non-critical modules disabled
521 if ( $pending_count > 0 || $security_status['has_critical'] ) {
522 $badge_class = 'awaiting-mod';
523 } else {
524 $badge_class = 'update-plugins vigilante-badge-warning';
525 }
526
527 $menu_title .= sprintf(
528 ' <span class="%s count-%d"><span class="pending-count">%d</span></span>',
529 esc_attr( $badge_class ),
530 $total_badge,
531 $total_badge
532 );
533 }
534
535 add_menu_page(
536 __( 'Vigilant', 'vigilante' ),
537 $menu_title,
538 'manage_options',
539 'vigilante',
540 array( $this, 'render_settings_page' ),
541 'dashicons-shield',
542 999
543 );
544
545 // Rename auto-generated first submenu to "Dashboard"
546 add_submenu_page(
547 'vigilante',
548 __( 'Dashboard', 'vigilante' ),
549 __( 'Dashboard', 'vigilante' ),
550 'manage_options',
551 'vigilante',
552 array( $this, 'render_settings_page' )
553 );
554
555 // Security Audit shortcut
556 add_submenu_page(
557 'vigilante',
558 __( 'Security Audit', 'vigilante' ),
559 __( 'Security Audit', 'vigilante' ),
560 'manage_options',
561 'vigilante-activity-log',
562 array( $this, 'redirect_to_tab' )
563 );
564
565 // File Integrity shortcut
566 add_submenu_page(
567 'vigilante',
568 __( 'File Integrity', 'vigilante' ),
569 __( 'File Integrity', 'vigilante' ),
570 'manage_options',
571 'vigilante-file-integrity',
572 array( $this, 'redirect_to_tab' )
573 );
574 }
575
576 /**
577 * Redirect submenu shortcuts early, before headers are sent
578 */
579 public function redirect_submenu_shortcuts() {
580 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
581 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
582
583 $tab_map = array(
584 'vigilante-activity-log' => 'activity-log',
585 'vigilante-file-integrity' => 'file-integrity',
586 );
587
588 if ( isset( $tab_map[ $page ] ) ) {
589 wp_safe_redirect( admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] ) );
590 exit;
591 }
592 }
593
594 /**
595 * Fallback redirect for submenu shortcuts (JS-based)
596 */
597 public function redirect_to_tab() {
598 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Just reading page slug for redirect
599 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
600
601 $tab_map = array(
602 'vigilante-activity-log' => 'activity-log',
603 'vigilante-file-integrity' => 'file-integrity',
604 );
605
606 if ( isset( $tab_map[ $page ] ) ) {
607 $url = admin_url( 'admin.php?page=vigilante&tab=' . $tab_map[ $page ] );
608 echo '<script>window.location.replace(' . wp_json_encode( esc_url( $url ) ) . ');</script>';
609 }
610 }
611
612 /**
613 * Highlight the correct submenu item based on active tab
614 *
615 * @param string $submenu_file Current submenu file.
616 * @return string
617 */
618 public function highlight_submenu_tab( $submenu_file ) {
619 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for menu highlight only
620 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
621 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
622 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : '';
623
624 if ( 'vigilante' !== $page || empty( $tab ) ) {
625 return $submenu_file;
626 }
627
628 $tab_to_submenu = array(
629 'activity-log' => 'vigilante-activity-log',
630 'file-integrity' => 'vigilante-file-integrity',
631 );
632
633 if ( isset( $tab_to_submenu[ $tab ] ) ) {
634 return $tab_to_submenu[ $tab ];
635 }
636
637 return $submenu_file;
638 }
639
640 /**
641 * Set browser tab title to show plugin name and active tab
642 *
643 * Changes "Dashboard ‹ Site Name — WordPress" to
644 * "Vigilant > Dashboard ‹ Site Name — WordPress"
645 *
646 * @param string $admin_title Full admin title.
647 * @param string $title Page title from add_menu_page/add_submenu_page.
648 * @return string Modified title.
649 */
650 public function set_admin_page_title( $admin_title, $title ) {
651 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading page slug for title only
652 $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
653
654 // Only modify on Vigilante pages
655 if ( 0 !== strpos( $page, 'vigilante' ) ) {
656 return $admin_title;
657 }
658
659 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
660 $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
661
662 if ( isset( $this->tabs[ $tab ] ) ) {
663 $tab_label = $this->tabs[ $tab ];
664 } else {
665 $tab_label = __( 'Dashboard', 'vigilante' );
666 }
667
668 $plugin_title = __( 'Vigilant', 'vigilante' ) . ' &rsaquo; ' . $tab_label;
669
670 // Replace the original page title portion
671 return str_replace( $title, $plugin_title, $admin_title );
672 }
673
674 /**
675 * Get count of users pending approval
676 *
677 * @return int Count of pending users.
678 */
679 private function get_pending_approvals_count() {
680 // Prevent early execution before WordPress is ready
681 if ( ! did_action( 'plugins_loaded' ) ) {
682 return 0;
683 }
684
685 $registration_approval = $this->settings->get_section( 'user_security' );
686 $approval_settings = $registration_approval['registration_approval'] ?? array();
687
688 if ( empty( $approval_settings['enabled'] ) ) {
689 return 0;
690 }
691
692 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Limited results in admin context.
693 $pending_users = get_users( array(
694 'meta_key' => 'vigilante_pending_approval',
695 'meta_value' => '1',
696 'fields' => 'ID',
697 ) );
698 // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key, WordPress.DB.SlowDBQuery.slow_db_query_meta_value
699
700 return count( $pending_users );
701 }
702
703 /**
704 * Calculate comprehensive security score (0-100)
705 *
706 * @param array $options Plugin options.
707 * @return int Security score.
708 */
709 private function calculate_security_score( $options ) {
710 $score = 0;
711 $max_score = 0;
712
713 // Module scores (60 points total)
714 $module_weights = array(
715 'firewall' => 10,
716 'security_headers' => 8,
717 'login_security' => 10,
718 'rest_api_security' => 6,
719 'user_security' => 8,
720 'wp_hardening' => 8,
721 'file_integrity' => 5,
722 'activity_log' => 5,
723 );
724
725 foreach ( $module_weights as $module => $weight ) {
726 $max_score += $weight;
727 if ( ! empty( $options['modules'][ $module ] ) ) {
728 $score += $weight;
729 }
730 }
731
732 // Firewall details (10 points)
733 if ( ! empty( $options['modules']['firewall'] ) ) {
734 $firewall = $options['firewall'] ?? array();
735 $max_score += 10;
736
737 $firewall_checks = array(
738 'block_sql_injection',
739 'block_xss_attacks',
740 'block_bad_query_strings',
741 'block_file_inclusion',
742 'block_directory_traversal',
743 );
744
745 $firewall_enabled = 0;
746 foreach ( $firewall_checks as $check ) {
747 if ( ! empty( $firewall[ $check ] ) ) {
748 $firewall_enabled++;
749 }
750 }
751 $score += min( 10, $firewall_enabled * 2 );
752 }
753
754 // Login security details (10 points)
755 if ( ! empty( $options['modules']['login_security'] ) ) {
756 $login = $options['login_security'] ?? array();
757 $max_score += 10;
758
759 // Max attempts configured
760 if ( isset( $login['max_attempts'] ) && $login['max_attempts'] <= 5 ) {
761 $score += 3;
762 }
763 // XML-RPC disabled
764 if ( ! empty( $login['disable_xmlrpc'] ) ) {
765 $score += 3;
766 }
767 // 2FA enabled
768 if ( ! empty( $login['two_factor']['enabled'] ) ) {
769 $score += 4;
770 }
771 }
772
773 // Security headers details (10 points)
774 if ( ! empty( $options['modules']['security_headers'] ) ) {
775 $headers = $options['security_headers'] ?? array();
776 $max_score += 10;
777
778 if ( ! empty( $headers['x_frame_options'] ) ) {
779 $score += 2;
780 }
781 if ( ! empty( $headers['x_content_type_options'] ) ) {
782 $score += 2;
783 }
784 if ( ! empty( $headers['hsts']['enabled'] ) ) {
785 $score += 3;
786 }
787 if ( ! empty( $headers['csp']['enabled'] ) ) {
788 $score += 3;
789 }
790 }
791
792 // User security details (10 points)
793 if ( ! empty( $options['modules']['user_security'] ) ) {
794 $user = $options['user_security'] ?? array();
795 $max_score += 10;
796
797 if ( ! empty( $user['block_insecure_usernames'] ) ) {
798 $score += 3;
799 }
800 if ( ! empty( $user['force_strong_passwords'] ) ) {
801 $score += 3;
802 }
803 if ( ! empty( $user['password_expiration']['enabled'] ) ) {
804 $score += 2;
805 }
806 if ( ! empty( $user['email_verification']['enabled'] ) ) {
807 $score += 2;
808 }
809 }
810
811 // Audit alerts details (6 points) - only when Security Audit is on,
812 // because the alerting layer rides on top of the activity log. Leaving
813 // both alert legs off keeps these points unearned.
814 if ( ! empty( $options['modules']['activity_log'] ) ) {
815 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
816 $max_score += 6;
817 if ( Vigilante_Audit_Alerts::immediate_is_active( $alerts ) ) {
818 $score += 3;
819 }
820 if ( Vigilante_Audit_Alerts::threshold_is_active( $alerts ) ) {
821 $score += 3;
822 }
823 }
824
825 // Environment checks (8 points) - penalize insecure server configuration
826 $max_score += 8;
827 $env_score = 8;
828
829 // WP_DEBUG active in production is a security risk (exposes paths, errors)
830 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
831 $env_score -= 5;
832 }
833
834 // Accounts with insecure usernames (targeted by brute force attacks)
835 $insecure_admins = $this->get_insecure_admin_usernames();
836 if ( ! empty( $insecure_admins ) ) {
837 $env_score -= 3;
838 }
839
840 $score += max( 0, $env_score );
841
842 return $max_score > 0 ? round( ( $score / $max_score ) * 100 ) : 0;
843 }
844
845 /**
846 * Get security recommendations based on current settings
847 *
848 * @param array $options Plugin options.
849 * @return array Array of recommendations.
850 */
851 private function get_security_recommendations( $options ) {
852 $recommendations = array();
853
854 // Critical: Firewall disabled
855 if ( empty( $options['modules']['firewall'] ) ) {
856 $recommendations[] = array(
857 'icon' => 'warning',
858 'priority' => 'critical',
859 'message' => __( 'Enable Firewall to protect against common attacks.', 'vigilante' ),
860 );
861 }
862
863 // Critical: Login security disabled
864 if ( empty( $options['modules']['login_security'] ) ) {
865 $recommendations[] = array(
866 'icon' => 'warning',
867 'priority' => 'critical',
868 'message' => __( 'Enable Login Security to prevent brute force attacks.', 'vigilante' ),
869 );
870 }
871
872 // High: Security headers disabled
873 if ( empty( $options['modules']['security_headers'] ) ) {
874 $recommendations[] = array(
875 'icon' => 'admin-generic',
876 'priority' => 'high',
877 'message' => __( 'Enable Security Headers to protect against clickjacking and XSS.', 'vigilante' ),
878 );
879 }
880
881 // High: User security disabled
882 if ( empty( $options['modules']['user_security'] ) ) {
883 $recommendations[] = array(
884 'icon' => 'admin-users',
885 'priority' => 'high',
886 'message' => __( 'Enable User Security to enforce password policies and username protection.', 'vigilante' ),
887 );
888 }
889
890 // High: 2FA not enabled (only if login security is active)
891 $login = $options['login_security'] ?? array();
892 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['two_factor']['enabled'] ) ) {
893 $recommendations[] = array(
894 'icon' => 'shield',
895 'priority' => 'high',
896 'message' => __( 'Enable Two-Factor Authentication for enhanced login security.', 'vigilante' ),
897 'tab' => 'login',
898 );
899 }
900
901 // Medium: REST API security disabled
902 if ( empty( $options['modules']['rest_api_security'] ) ) {
903 $recommendations[] = array(
904 'icon' => 'rest-api',
905 'priority' => 'medium',
906 'message' => __( 'Enable REST API Security to control API access and prevent enumeration.', 'vigilante' ),
907 );
908 }
909
910 // Medium: WP Hardening disabled
911 if ( empty( $options['modules']['wp_hardening'] ) ) {
912 $recommendations[] = array(
913 'icon' => 'lock',
914 'priority' => 'medium',
915 'message' => __( 'Enable WP Hardening to remove version info and protect core files.', 'vigilante' ),
916 );
917 }
918
919 // Medium: File integrity disabled
920 if ( empty( $options['modules']['file_integrity'] ) ) {
921 $recommendations[] = array(
922 'icon' => 'media-text',
923 'priority' => 'medium',
924 'message' => __( 'Enable File Integrity to detect unauthorized file changes.', 'vigilante' ),
925 );
926 }
927
928 // Medium: Security Audit disabled
929 if ( empty( $options['modules']['activity_log'] ) ) {
930 $recommendations[] = array(
931 'icon' => 'list-view',
932 'priority' => 'medium',
933 'message' => __( 'Enable Security Audit to track security events.', 'vigilante' ),
934 );
935 }
936
937 // Low: XML-RPC enabled (only if login security is active)
938 if ( ! empty( $options['modules']['login_security'] ) && empty( $login['disable_xmlrpc'] ) ) {
939 $recommendations[] = array(
940 'icon' => 'info',
941 'priority' => 'low',
942 'message' => __( 'Disable XML-RPC if not needed (reduces attack surface).', 'vigilante' ),
943 'tab' => 'login',
944 );
945 }
946
947 // Low: Strong passwords not enforced (only if user security is active)
948 $user = $options['user_security'] ?? array();
949 if ( ! empty( $options['modules']['user_security'] ) && empty( $user['force_strong_passwords'] ) ) {
950 $recommendations[] = array(
951 'icon' => 'admin-users',
952 'priority' => 'low',
953 'message' => __( 'Enforce strong passwords for all users.', 'vigilante' ),
954 'tab' => 'users',
955 );
956 }
957
958 // High: WP_DEBUG active in production (regardless of Vigilante settings)
959 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
960 $recommendations[] = array(
961 'icon' => 'warning',
962 'priority' => 'high',
963 'message' => __( 'WP_DEBUG is active. Debug mode exposes sensitive information and should be disabled in production.', 'vigilante' ),
964 'tab' => 'wp-hardening',
965 );
966 }
967
968 // Low: Users with display name matching login username (only if user security active)
969 if ( ! empty( $options['modules']['user_security'] ) ) {
970 $exposed_users = $this->get_users_with_exposed_login();
971 if ( ! empty( $exposed_users ) ) {
972 $recommendations[] = array(
973 'icon' => 'admin-users',
974 'priority' => 'low',
975 'message' => sprintf(
976 /* translators: %s: Comma-separated list of usernames */
977 __( 'These users have their login username as display name (publicly visible): %s', 'vigilante' ),
978 implode( ', ', $exposed_users )
979 ),
980 'tab' => 'users',
981 );
982 }
983 }
984
985 // High: Accounts with insecure usernames (regardless of module status)
986 $insecure_admins = $this->get_insecure_admin_usernames();
987 if ( ! empty( $insecure_admins ) ) {
988 $recommendations[] = array(
989 'icon' => 'warning',
990 'priority' => 'high',
991 'message' => sprintf(
992 /* translators: %s: Comma-separated list of usernames */
993 __( 'Insecure usernames detected: %s. These are commonly targeted in brute force attacks. Create new accounts with unique usernames and remove these.', 'vigilante' ),
994 implode( ', ', $insecure_admins )
995 ),
996 );
997 }
998
999 // Critical: Closed or removed plugins detected by the daily check.
1000 // Reads from the cached state map populated by Vigilante_Plugin_Status, so
1001 // there is no extra HTTP call here. Ignored slugs are filtered out so the
1002 // recommendation respects the user's per-slug Ignore decisions.
1003 if ( ! empty( $options['modules']['file_integrity'] ) && ! empty( $options['file_integrity']['check_closed_plugins'] ) ) {
1004 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
1005 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
1006 }
1007 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
1008 $closed_active = $closed_checker->get_closed_plugins();
1009 if ( ! empty( $closed_active ) ) {
1010 $names = array();
1011 foreach ( $closed_active as $slug => $entry ) {
1012 $names[] = isset( $entry['name'] ) ? $entry['name'] : $slug;
1013 }
1014 $recommendations[] = array(
1015 'icon' => 'warning',
1016 'priority' => 'critical',
1017 'message' => sprintf(
1018 /* translators: 1: count, 2: comma-separated plugin names */
1019 _n(
1020 '%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.',
1021 '%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.',
1022 count( $closed_active ),
1023 'vigilante'
1024 ),
1025 count( $closed_active ),
1026 implode( ', ', $names )
1027 ),
1028 'tab' => 'file-integrity',
1029 );
1030 }
1031 }
1032
1033 // Medium: Security Audit is on but no audit alert is configured. The
1034 // alerting layer only makes sense while the activity log is running.
1035 if ( ! empty( $options['modules']['activity_log'] ) ) {
1036 $alerts = isset( $options['audit_alerts'] ) ? (array) $options['audit_alerts'] : array();
1037 if ( ! Vigilante_Audit_Alerts::has_active_alerts( $alerts ) ) {
1038 $recommendations[] = array(
1039 'icon' => 'email-alt',
1040 'priority' => 'medium',
1041 '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' ),
1042 'tab' => 'activity-log',
1043 );
1044 }
1045 }
1046
1047 // Sort by priority
1048 $priority_order = array( 'critical' => 0, 'high' => 1, 'medium' => 2, 'low' => 3 );
1049 usort( $recommendations, function( $a, $b ) use ( $priority_order ) {
1050 return ( $priority_order[ $a['priority'] ] ?? 99 ) - ( $priority_order[ $b['priority'] ] ?? 99 );
1051 } );
1052
1053 return $recommendations;
1054 }
1055
1056 /**
1057 * Get users whose display name matches their login username
1058 *
1059 * Limited to administrators and editors for performance and relevance.
1060 * Cached with transient to avoid repeated queries on every dashboard load.
1061 *
1062 * @return array Array of usernames with exposed login.
1063 */
1064 private function get_users_with_exposed_login() {
1065 $cache_key = 'vigilante_exposed_display_names';
1066 $cached = get_transient( $cache_key );
1067
1068 if ( false !== $cached ) {
1069 return $cached;
1070 }
1071
1072 $exposed = array();
1073 $users = get_users( array(
1074 'role__in' => array( 'administrator', 'editor' ),
1075 'fields' => array( 'ID', 'user_login', 'display_name' ),
1076 ) );
1077
1078 foreach ( $users as $user ) {
1079 if ( strcasecmp( $user->display_name, $user->user_login ) === 0 ) {
1080 $exposed[] = $user->user_login;
1081 }
1082 }
1083
1084 // Cache for 12 hours
1085 set_transient( $cache_key, $exposed, 12 * HOUR_IN_SECONDS );
1086
1087 return $exposed;
1088 }
1089
1090 /**
1091 * Get accounts with insecure usernames
1092 *
1093 * Checks for common default usernames that are targeted by brute force attacks.
1094 * Detects any user regardless of role (consistent with username creation blocking).
1095 * Uses WordPress object cache via get_user_by() so no transient needed.
1096 *
1097 * @return array Array of insecure usernames found.
1098 */
1099 private function get_insecure_admin_usernames() {
1100 $priority_usernames = array( 'admin', 'administrator', 'root', 'test', 'user', 'guest', 'info', 'sysadmin', 'webmaster' );
1101 $found = array();
1102
1103 foreach ( $priority_usernames as $username ) {
1104 $user = get_user_by( 'login', $username );
1105 if ( $user ) {
1106 $found[] = $username;
1107 }
1108 }
1109
1110 return $found;
1111 }
1112
1113 /**
1114 * Get security status for menu badge
1115 *
1116 * Returns count of disabled modules and whether there are critical issues.
1117 * Critical = Firewall or Login Security disabled.
1118 *
1119 * @return array Array with 'count' and 'has_critical'.
1120 */
1121 public function get_security_status_for_badge() {
1122 $options = $this->settings->get_all_options();
1123 $modules = $options['modules'] ?? array();
1124
1125 // Count disabled modules
1126 $disabled_count = 0;
1127 $has_critical = false;
1128
1129 // Critical modules - if disabled, badge is red
1130 $critical_modules = array( 'firewall', 'login_security' );
1131
1132 foreach ( $modules as $module => $enabled ) {
1133 // Handle both boolean and string values ('1', '0', true, false)
1134 $is_enabled = filter_var( $enabled, FILTER_VALIDATE_BOOLEAN );
1135
1136 if ( ! $is_enabled ) {
1137 $disabled_count++;
1138
1139 // Check if this is a critical module
1140 if ( in_array( $module, $critical_modules, true ) ) {
1141 $has_critical = true;
1142 }
1143 }
1144 }
1145
1146 return array(
1147 'count' => $disabled_count,
1148 'has_critical' => $has_critical,
1149 );
1150 }
1151
1152 /**
1153 * Get count of security issues for menu badge (deprecated, use get_security_status_for_badge)
1154 *
1155 * @return int Count of critical/high issues.
1156 */
1157 public function get_security_issues_count() {
1158 $status = $this->get_security_status_for_badge();
1159 return $status['count'];
1160 }
1161
1162 /**
1163 * Register settings
1164 */
1165 public function register_settings() {
1166 register_setting(
1167 'vigilante_options',
1168 Vigilante_Settings::OPTION_NAME,
1169 array( $this->settings, 'validate_options' )
1170 );
1171 }
1172
1173 /**
1174 * Index behind the settings search box.
1175 *
1176 * Each entry points at one settings row. The search matches on the label,
1177 * on its English original and on 'keywords', which are extra terms someone
1178 * might type instead of the label itself.
1179 *
1180 * Those keywords are wrapped in _x() with the context "settings search
1181 * keywords" so every locale can supply its own: the source strings are in
1182 * English, and a Spanish user typing "contrasena" or a German one typing
1183 * "Kennwort" only reaches the password settings if that locale translated
1184 * them. Translators can add, drop or replace terms freely, one per space;
1185 * they are never displayed, only matched against what the user types.
1186 *
1187 * The list is maintained by hand, so a new settings row needs an entry here
1188 * or it cannot be found. It had drifted to 68 of 131 rows before 2.9.7.
1189 *
1190 * @return array
1191 */
1192 private function get_search_index() {
1193 return array(
1194 // Firewall - Main
1195 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' ) ),
1196 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' ) ),
1197 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' ) ),
1198 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' ) ),
1199 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' ) ),
1200 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' ) ),
1201 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' ) ),
1202 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' ) ),
1203 // Firewall - Server Protection
1204 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' ) ),
1205 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' ) ),
1206 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' ) ),
1207 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' ) ),
1208 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' ) ),
1209 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' ) ),
1210 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' ) ),
1211 // Security Headers
1212 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' ) ),
1213 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' ) ),
1214 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' ) ),
1215 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' ) ),
1216 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' ) ),
1217 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' ) ),
1218 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' ) ),
1219 // Login Security
1220 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' ) ),
1221 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' ) ),
1222 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' ) ),
1223 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' ) ),
1224 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' ) ),
1225 // REST API
1226 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' ) ),
1227 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' ) ),
1228 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' ) ),
1229 // User Security
1230 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' ) ),
1231 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' ) ),
1232 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' ) ),
1233 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' ) ),
1234 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' ) ),
1235 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' ) ),
1236 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' ) ),
1237 // WP Hardening
1238 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' ) ),
1239 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' ) ),
1240 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' ) ),
1241 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' ) ),
1242 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' ) ),
1243 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' ) ),
1244 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' ) ),
1245 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' ) ),
1246 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' ) ),
1247 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' ) ),
1248 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' ) ),
1249 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' ) ),
1250 // File Integrity
1251 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' ) ),
1252 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' ) ),
1253 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' ) ),
1254 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' ) ),
1255 // Security Audit
1256 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' ) ),
1257 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' ) ),
1258 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' ) ),
1259 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' ) ),
1260 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' ) ),
1261 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' ) ),
1262 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' ) ),
1263 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' ) ),
1264 // Settings & Tools
1265 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' ) ),
1266 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' ) ),
1267 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' ) ),
1268 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' ) ),
1269 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' ) ),
1270 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' ) ),
1271 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' ) ),
1272 // Entradas anadidas en la 2.9.7 tras comprobar que el indice cubria 68 de
1273 // las 131 filas de ajustes: buscar XML-RPC, por ejemplo, no devolvia nada.
1274 // El indice se mantiene a mano, asi que al anadir una fila de ajustes hay
1275 // que anadirla tambien aqui.
1276 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' ) ),
1277 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' ) ),
1278 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' ) ),
1279 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' ) ),
1280 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' ) ),
1281 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' ) ),
1282 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' ) ),
1283 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' ) ),
1284 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' ) ),
1285 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' ) ),
1286 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' ) ),
1287 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' ) ),
1288 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' ) ),
1289 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' ) ),
1290 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' ) ),
1291 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' ) ),
1292 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' ) ),
1293 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' ) ),
1294 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' ) ),
1295 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' ) ),
1296 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' ) ),
1297 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' ) ),
1298 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' ) ),
1299 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' ) ),
1300 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' ) ),
1301 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' ) ),
1302 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' ) ),
1303 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' ) ),
1304 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' ) ),
1305 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' ) ),
1306 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' ) ),
1307 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' ) ),
1308 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' ) ),
1309 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' ) ),
1310 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' ) ),
1311 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' ) ),
1312 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' ) ),
1313 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' ) ),
1314 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' ) ),
1315 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' ) ),
1316 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' ) ),
1317 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' ) ),
1318 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' ) ),
1319 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' ) ),
1320 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' ) ),
1321 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' ) ),
1322 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' ) ),
1323 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' ) ),
1324 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' ) ),
1325 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' ) ),
1326 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' ) ),
1327 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' ) ),
1328 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' ) ),
1329 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' ) ),
1330 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' ) ),
1331 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' ) ),
1332 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' ) ),
1333 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' ) ),
1334 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' ) ),
1335 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' ) ),
1336 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' ) ),
1337 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' ) ),
1338 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' ) ),
1339 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' ) ),
1340 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' ) ),
1341 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' ) ),
1342 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' ) ),
1343 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' ) ),
1344 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' ) ),
1345 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' ) ),
1346 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' ) ),
1347 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' ) ),
1348 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' ) ),
1349 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' ) ),
1350 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' ) ),
1351 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' ) ),
1352 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' ) ),
1353 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' ) ),
1354 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' ) ),
1355 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' ) ),
1356 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' ) ),
1357 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' ) ),
1358 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' ) ),
1359 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' ) ),
1360 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' ) ),
1361 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' ) ),
1362 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' ) ),
1363 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' ) ),
1364 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' ) ),
1365 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' ) ),
1366 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' ) ),
1367 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' ) ),
1368 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' ) ),
1369 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' ) ),
1370 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' ) ),
1371 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' ) ),
1372 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' ) ),
1373 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' ) ),
1374 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' ) ),
1375 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' ) ),
1376 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' ) ),
1377 );
1378 }
1379
1380 /**
1381 * Enqueue admin assets
1382 *
1383 * @param string $hook Current admin page.
1384 */
1385 public function enqueue_assets( $hook ) {
1386 // toplevel_page_vigilante for top-level menu page
1387 if ( 'toplevel_page_vigilante' !== $hook ) {
1388 return;
1389 }
1390
1391 wp_enqueue_style(
1392 'vigilante-admin',
1393 VIGILANTE_ASSETS_URL . 'css/admin.css',
1394 array(),
1395 VIGILANTE_VERSION
1396 );
1397
1398 wp_enqueue_script(
1399 'vigilante-admin',
1400 VIGILANTE_ASSETS_URL . 'js/admin.js',
1401 array( 'jquery' ),
1402 VIGILANTE_VERSION,
1403 true
1404 );
1405
1406 wp_localize_script( 'vigilante-admin', 'vigilanteAdmin', array(
1407 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
1408 'nonce' => wp_create_nonce( 'vigilante_admin_nonce' ),
1409 'currentUserId' => get_current_user_id(),
1410 'logoutUrl' => wp_logout_url( wp_login_url() ),
1411 'adminUrl' => admin_url( 'admin.php?page=vigilante' ),
1412 'searchIndex' => $this->get_search_index(),
1413 'underAttack' => array(
1414 'active' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->is_active(),
1415 'remaining' => ( new Vigilante_Under_Attack( $this->settings, $this->activity_log ) )->get_remaining_time(),
1416 ),
1417 'strings' => array(
1418 'saving' => __( 'Saving...', 'vigilante' ),
1419 'sendingTest' => __( 'Sending...', 'vigilante' ),
1420 'saved' => __( 'Settings saved', 'vigilante' ),
1421 'error' => __( 'Error saving settings', 'vigilante' ),
1422 'confirm' => __( 'Are you sure?', 'vigilante' ),
1423 'scanning' => __( 'Scanning...', 'vigilante' ),
1424 'scanComplete' => __( 'Scan complete', 'vigilante' ),
1425 'loading' => __( 'Loading...', 'vigilante' ),
1426 'searching' => __( 'Searching...', 'vigilante' ),
1427 'noUsersFound' => __( 'No users found', 'vigilante' ),
1428 'searchError' => __( 'Error searching users', 'vigilante' ),
1429 'sending' => __( 'Sending...', 'vigilante' ),
1430 'sendNotification' => __( 'Send notification now', 'vigilante' ),
1431 'notificationsSent' => __( 'notifications sent', 'vigilante' ),
1432 'skipped' => __( 'skipped', 'vigilante' ),
1433 'failed' => __( 'failed', 'vigilante' ),
1434 'customConfig' => __( 'Custom Configuration', 'vigilante' ),
1435 // Header tester strings
1436 'testHeaders' => __( 'Test Headers', 'vigilante' ),
1437 'testing' => __( 'Testing...', 'vigilante' ),
1438 'score' => __( 'Score', 'vigilante' ),
1439 'enabledHeaders' => __( 'Enabled headers', 'vigilante' ),
1440 'missingHeaders' => __( 'Missing headers', 'vigilante' ),
1441 'warnings' => __( 'Warnings', 'vigilante' ),
1442 // File integrity scan results strings
1443 'scanResults' => __( 'Scan Results', 'vigilante' ),
1444 'ok' => __( 'OK', 'vigilante' ),
1445 'modified' => __( 'Modified', 'vigilante' ),
1446 'suspicious' => __( 'Suspicious', 'vigilante' ),
1447 'totalScanned' => __( 'Total Scanned', 'vigilante' ),
1448 'suspiciousFiles' => __( 'Suspicious Files', 'vigilante' ),
1449 'suspiciousWarning' => __( 'These files may contain malicious code or are in unexpected locations. Review immediately!', 'vigilante' ),
1450 'file' => __( 'File', 'vigilante' ),
1451 'reason' => __( 'Reason', 'vigilante' ),
1452 'type' => __( 'Type', 'vigilante' ),
1453 'unknown' => __( 'Unknown', 'vigilante' ),
1454 'modifiedFiles' => __( 'Modified Files', 'vigilante' ),
1455 'modifiedDescription' => __( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ),
1456 'extraFiles' => __( 'Extra Files', 'vigilante' ),
1457 'extra' => __( 'Extra', 'vigilante' ),
1458 'ignored' => __( 'Ignored', 'vigilante' ),
1459 'extraDescription' => __( 'PHP files found in plugins or themes that are not part of the original distribution from WordPress.org.', 'vigilante' ),
1460 'actions' => __( 'Actions', 'vigilante' ),
1461 'ignore' => __( 'Ignore', 'vigilante' ),
1462 'ignoring' => __( 'Ignoring...', 'vigilante' ),
1463 'fileIgnored' => __( 'File added to ignored list.', 'vigilante' ),
1464 'fileUnignored' => __( 'File removed from ignored list.', 'vigilante' ),
1465 'confirmClearIgnored' => __( 'Remove all files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1466 'ignoredCleared' => __( 'Ignored files list cleared. Page will reload...', 'vigilante' ),
1467 'selectAll' => __( 'Select all', 'vigilante' ),
1468 'bulkIgnoreSelected' => __( 'Ignore selected', 'vigilante' ),
1469 'bulkUnignoreSelected'=> __( 'Stop ignoring selected', 'vigilante' ),
1470 'bulkNoSelection' => __( 'Select at least one file first.', 'vigilante' ),
1471 'bulkConfirmIgnore' => __( 'Ignore the selected files? They will be hidden from future scan results until you remove them from the ignored list.', 'vigilante' ),
1472 'bulkConfirmUnignore' => __( 'Remove the selected files from the ignored list? They will appear in scan results again.', 'vigilante' ),
1473 'bulkProcessing' => __( 'Processing...', 'vigilante' ),
1474 /* translators: %d: number of files selected for bulk action. */
1475 'bulkSelectedCount' => __( '%d selected', 'vigilante' ),
1476 'allClear' => __( 'All files verified - no issues found!', 'vigilante' ),
1477 'criticalConfigTitle' => __( 'Critical config files modified', 'vigilante' ),
1478 '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' ),
1479 'approve' => __( 'Approve', 'vigilante' ),
1480 'approving' => __( 'Approving...', 'vigilante' ),
1481 'criticalApproved' => __( 'Change approved. Next scan will use the current state as baseline.', 'vigilante' ),
1482 'reviewChanges' => __( 'Review changes', 'vigilante' ),
1483 'hideChanges' => __( 'Hide changes', 'vigilante' ),
1484 'changes' => __( 'Changes', 'vigilante' ),
1485 'diffUnavailable' => __( 'Diff not available for this file (baseline was created before diff tracking was added). Approve to enable diff on future changes.', 'vigilante' ),
1486 'diffEmpty' => __( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ),
1487 'diffLines' => __( 'lines', 'vigilante' ),
1488 // Under Attack mode strings
1489 'underAttackConfirmActivate' => __( 'Activate Under Attack mode? All visitors will see a verification page for the next 4 hours.', 'vigilante' ),
1490 'underAttackConfirmDeactivate' => __( 'Deactivate Under Attack mode?', 'vigilante' ),
1491 'underAttackActivating' => __( 'Activating...', 'vigilante' ),
1492 'underAttackDeactivating' => __( 'Deactivating...', 'vigilante' ),
1493 // Database backup strings
1494 'dbBackupDownloading' => __( 'Generating backup...', 'vigilante' ),
1495 'dbBackupNoTables' => __( 'Please select at least one table.', 'vigilante' ),
1496 'dbBackupSuccess' => __( 'Database backup downloaded successfully.', 'vigilante' ),
1497 // Firewall unblock
1498 'confirmUnblockIp' => __( 'Unblock this IP from firewall rate limiting?', 'vigilante' ),
1499 // Database prefix strings
1500 'dbPrefixConfirm' => __( 'This operation will change your database prefix. It is irreversible. Make sure you have a current database backup before proceeding.', 'vigilante' ),
1501 'dbPrefixChanging' => __( 'Changing prefix...', 'vigilante' ),
1502 'dbPrefixSuccess' => __( 'Database prefix changed successfully. The page will reload now.', 'vigilante' ),
1503 'dbPrefixCheckbox' => __( 'You must confirm that you have a database backup.', 'vigilante' ),
1504 /* translators: 1: Hours, 2: Minutes */
1505 'underAttackRemaining' => __( '%1$dh %2$dm remaining', 'vigilante' ),
1506 'underAttackLabel' => __( 'Under Attack', 'vigilante' ),
1507 'standardLabel' => __( 'Standard', 'vigilante' ),
1508 'maximumLabel' => __( 'Maximum Security', 'vigilante' ),
1509 'deactivate' => __( 'Deactivate', 'vigilante' ),
1510 'underAttackActivate' => __( 'Activate for 4 hours', 'vigilante' ),
1511 // Settings strings
1512 'saveSettings' => __( 'Save Settings', 'vigilante' ),
1513 'settingsResetDefaults' => __( 'Settings reset to defaults.', 'vigilante' ),
1514 'confirmOverwrite' => __( 'This will overwrite your current settings.', 'vigilante' ),
1515 'importFailed' => __( 'Could not import settings. Check the file and try again.', 'vigilante' ),
1516 /* translators: 1: tests passed, 2: total tests in this category */
1517 'testsCounter' => __( '%1$d/%2$d tests', 'vigilante' ),
1518 'confirmResetAll' => __( 'This will reset ALL settings to defaults.', 'vigilante' ),
1519 'couldNotDetermineSection' => __( 'Could not determine section.', 'vigilante' ),
1520 'confirmResetSection' => __( 'Reset this section to default values? This cannot be undone.', 'vigilante' ),
1521 'sectionResetDefaults' => __( 'Section reset to defaults.', 'vigilante' ),
1522 /* translators: %s: preset name */
1523 'confirmApplyPreset' => __( 'Apply the "%s" preset?', 'vigilante' ),
1524 // Scan strings
1525 'scanFailed' => __( 'Scan failed', 'vigilante' ),
1526 /* translators: %s: error message */
1527 'scanError' => __( 'Scan error: %s', 'vigilante' ),
1528 'runScanNow' => __( 'Run Scan Now', 'vigilante' ),
1529 'confirmClearScan' => __( 'Are you sure you want to clear all scan results?', 'vigilante' ),
1530 'clearing' => __( 'Clearing...', 'vigilante' ),
1531 'scanResultsCleared' => __( 'Scan results cleared. Page will reload...', 'vigilante' ),
1532 'failedClearResults' => __( 'Failed to clear results', 'vigilante' ),
1533 /* translators: %s: error message */
1534 'ajaxError' => __( 'AJAX Error: %s', 'vigilante' ),
1535 // Activity log popup strings
1536 'logRequest' => __( 'Request', 'vigilante' ),
1537 'logDate' => __( 'Date', 'vigilante' ),
1538 'logMethod' => __( 'Method', 'vigilante' ),
1539 'logType' => __( 'Type', 'vigilante' ),
1540 'logAction' => __( 'Action', 'vigilante' ),
1541 'logSeverity' => __( 'Severity', 'vigilante' ),
1542 'logMessage' => __( 'Message', 'vigilante' ),
1543 'logClient' => __( 'Client', 'vigilante' ),
1544 'logUser' => __( 'User', 'vigilante' ),
1545 'logIpAddress' => __( 'IP Address', 'vigilante' ),
1546 'logUserAgent' => __( 'User Agent', 'vigilante' ),
1547 'logIpLabel' => __( 'IP:', 'vigilante' ),
1548 'logUaLabel' => __( 'UA:', 'vigilante' ),
1549 'logWhitelist' => __( 'Whitelist', 'vigilante' ),
1550 'logBlacklist' => __( 'Blacklist', 'vigilante' ),
1551 'logInWhitelist' => __( 'In whitelist', 'vigilante' ),
1552 'logInBlacklist' => __( 'In blacklist', 'vigilante' ),
1553 'logAdded' => __( 'Added!', 'vigilante' ),
1554 'logErrorAddingToList' => __( 'Error adding to list', 'vigilante' ),
1555 'logRequestFailed' => __( 'Request failed', 'vigilante' ),
1556 // Activity log table strings
1557 'noLogEntries' => __( 'No log entries found.', 'vigilante' ),
1558 'view' => __( 'View', 'vigilante' ),
1559 'confirmClearLogs' => __( 'This will delete all audit logs.', 'vigilante' ),
1560 // Export logs strings
1561 'exporting' => __( 'Exporting...', 'vigilante' ),
1562 /* translators: %d: number of entries */
1563 'logsExported' => __( 'Logs exported (%d entries)', 'vigilante' ),
1564 'noLogsToExport' => __( 'No logs to export', 'vigilante' ),
1565 'exportFailed' => __( 'Export failed', 'vigilante' ),
1566 'exportLogs' => __( 'Export Logs', 'vigilante' ),
1567 // Backup strings
1568 'backupCreated' => __( 'Backup created successfully.', 'vigilante' ),
1569 'createBackupNow' => __( 'Download Backup', 'vigilante' ),
1570 'downloadBackup' => __( 'Download Backup (.zip)', 'vigilante' ),
1571 /* translators: %d: number of tables */
1572 'tablesCount' => __( '%d tables', 'vigilante' ),
1573 /* translators: 1: table count, 2: human-readable size */
1574 'dbTablesTotal' => __( '%1$d tables total (%2$s)', 'vigilante' ),
1575 /* translators: 1: selected count, 2: human-readable size */
1576 'dbTablesSelected' => __( '%1$d tables selected (%2$s)', 'vigilante' ),
1577 // Settings search strings
1578 'searchNoResults' => __( 'No matching settings found.', 'vigilante' ),
1579 /* translators: %d: number of results that did not fit in the list. */
1580 'searchMoreResults' => __( '%d more results. Refine the search to see them.', 'vigilante' ),
1581 'searchInTab' => __( 'in', 'vigilante' ),
1582 // Modules string
1583 /* translators: 1: enabled count, 2: total count */
1584 'modulesEnabled' => __( '%1$d / %2$d modules enabled', 'vigilante' ),
1585 // Activity log label maps for JS rendering
1586 'eventTypeLabels' => array(
1587 'login' => __( 'Login', 'vigilante' ),
1588 'user' => __( 'User', 'vigilante' ),
1589 'content' => __( 'Content', 'vigilante' ),
1590 'plugin' => __( 'Plugin', 'vigilante' ),
1591 'theme' => __( 'Theme', 'vigilante' ),
1592 'settings' => __( 'Settings', 'vigilante' ),
1593 'comment' => __( 'Comment', 'vigilante' ),
1594 'media' => __( 'Media', 'vigilante' ),
1595 'firewall' => __( 'Firewall', 'vigilante' ),
1596 'file' => __( 'File', 'vigilante' ),
1597 'security' => __( 'Security', 'vigilante' ),
1598 'system' => __( 'System', 'vigilante' ),
1599 ),
1600 'severityLabels' => array(
1601 'info' => __( 'Info', 'vigilante' ),
1602 'warning' => __( 'Warning', 'vigilante' ),
1603 'critical' => __( 'Critical', 'vigilante' ),
1604 ),
1605 // Password reset strings
1606 'noUsersFoundSearch' => __( 'No users found', 'vigilante' ),
1607 /* translators: %d: number of users */
1608 'confirmForceReset' => __( 'Force password reset for %d user(s)? A password reset email will be sent to each user.', 'vigilante' ),
1609 'warningResettingSelf' => __( 'WARNING: You are including yourself. Your session will end and you will need to set a new password.', 'vigilante' ),
1610 'processing' => __( 'Processing...', 'vigilante' ),
1611 'anErrorOccurred' => __( 'An error occurred', 'vigilante' ),
1612 'forceResetSelected' => __( 'Force Reset for Selected Users', 'vigilante' ),
1613 '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' ),
1614 'warningResettingSelfAll' => __( 'WARNING: You are including yourself. Your session will end immediately.', 'vigilante' ),
1615 'forceResetAll' => __( 'Force Reset for ALL Users', 'vigilante' ),
1616 // Role-based password reset strings
1617 /* translators: %d: number of users */
1618 'confirmForceResetByRole' => __( 'Force password reset for %d user(s) with the selected roles? A password reset email will be sent to each user.', 'vigilante' ),
1619 'noRolesSelected' => __( 'Please select at least one role.', 'vigilante' ),
1620 'forceResetByRole' => __( 'Force Reset for Selected Roles', 'vigilante' ),
1621 // User approval strings
1622 'confirmApprove' => __( 'Approve this user?', 'vigilante' ),
1623 'approve' => __( 'Approve', 'vigilante' ),
1624 'rejectReason' => __( 'Enter rejection reason (optional):', 'vigilante' ),
1625 'reject' => __( 'Reject', 'vigilante' ),
1626 'noPending' => __( 'No pending registrations.', 'vigilante' ),
1627 // Session management strings
1628 'confirmRevoke' => __( 'Revoke this session?', 'vigilante' ),
1629 'confirmRevokeAll' => __( 'Revoke all other sessions?', 'vigilante' ),
1630 'revokeOthers' => __( 'Revoke All Other Sessions', 'vigilante' ),
1631 'confirmRevokeAllUser' => __( 'Revoke ALL sessions for this user? They will be logged out everywhere.', 'vigilante' ),
1632 'sessionsFor' => __( 'Sessions for:', 'vigilante' ),
1633 'noSessions' => __( 'No active sessions', 'vigilante' ),
1634 'revoke' => __( 'Revoke', 'vigilante' ),
1635 'noUsers' => __( 'No users found', 'vigilante' ),
1636 // Time ago strings
1637 'timeYear' => __( 'year', 'vigilante' ),
1638 'timeYears' => __( 'years', 'vigilante' ),
1639 'timeMonth' => __( 'month', 'vigilante' ),
1640 'timeMonths' => __( 'months', 'vigilante' ),
1641 'timeDay' => __( 'day', 'vigilante' ),
1642 'timeDays' => __( 'days', 'vigilante' ),
1643 'timeHour' => __( 'hour', 'vigilante' ),
1644 'timeHours' => __( 'hours', 'vigilante' ),
1645 'timeMinute' => __( 'minute', 'vigilante' ),
1646 'timeMinutes' => __( 'minutes', 'vigilante' ),
1647 /* translators: %1$d: count, %2$s: time unit */
1648 'timeAgo' => __( '%1$d %2$s ago', 'vigilante' ),
1649 'justNow' => __( 'Just now', 'vigilante' ),
1650 // Pagination strings
1651 /* translators: 1: first item number, 2: last item number, 3: total items */
1652 'paginationOf' => __( '%1$d–%2$d of %3$d', 'vigilante' ),
1653 'paginationEmpty' => __( '0 items', 'vigilante' ),
1654 // Security Analyzer strings
1655 'analyzerScanNow' => __( 'Scan now', 'vigilante' ),
1656 'analyzerScanning' => __( 'Scanning…', 'vigilante' ),
1657 'analyzerFastPhase' => __( 'Running fast checks…', 'vigilante' ),
1658 'analyzerSlowPhase' => __( 'Running remote checks…', 'vigilante' ),
1659 'analyzerScanComplete' => __( 'Security scan complete.', 'vigilante' ),
1660 'analyzerScanFailed' => __( 'Security scan failed.', 'vigilante' ),
1661 'analyzerShowDetails' => __( 'Show detailed breakdown', 'vigilante' ),
1662 'analyzerHideDetails' => __( 'Hide detailed breakdown', 'vigilante' ),
1663 'analyzerGoToSetting' => __( 'Go to setting', 'vigilante' ),
1664 'analyzerNoData' => __( 'No data yet — run a scan to populate this category.', 'vigilante' ),
1665 'analyzerJustNow' => __( 'just now', 'vigilante' ),
1666 'analyzerAgo' => __( 'ago', 'vigilante' ),
1667 'analyzerSettingsSaved' => __( 'Analyzer settings saved.', 'vigilante' ),
1668 'analyzerLastScanJustNow' => __( 'Last scan just now', 'vigilante' ),
1669 'analyzerQualityExcellent' => __( 'Excellent', 'vigilante' ),
1670 'analyzerQualityGood' => __( 'Good', 'vigilante' ),
1671 'analyzerQualityFair' => __( 'Fair', 'vigilante' ),
1672 'analyzerQualityPoor' => __( 'Poor', 'vigilante' ),
1673 'analyzerQualityCritical' => __( 'Critical', 'vigilante' ),
1674 'analyzerPts' => __( 'pts', 'vigilante' ),
1675 'analyzerLearnMore' => __( 'Learn more', 'vigilante' ),
1676 'analyzerInfoAllClear' => __( 'All clear', 'vigilante' ),
1677 /* translators: %d: number of findings in an info-only category */
1678 'analyzerInfoFindings' => __( '%d findings', 'vigilante' ),
1679 ),
1680 ) );
1681
1682 // 2FA Admin assets
1683 wp_enqueue_style(
1684 'vigilante-2fa-admin',
1685 VIGILANTE_ASSETS_URL . 'css/two-factor-admin.css',
1686 array( 'vigilante-admin' ),
1687 VIGILANTE_VERSION
1688 );
1689
1690 wp_enqueue_script(
1691 'vigilante-2fa-admin',
1692 VIGILANTE_ASSETS_URL . 'js/two-factor-admin.js',
1693 array( 'jquery', 'vigilante-admin' ),
1694 VIGILANTE_VERSION,
1695 true
1696 );
1697 }
1698
1699 /**
1700 * Show admin notices
1701 */
1702 public function show_admin_notices() {
1703 // Activation notice
1704 if ( get_transient( 'vigilante_activated' ) ) {
1705 ?>
1706 <div class="notice notice-success is-dismissible vigilante-activation-notice">
1707 <p>
1708 <span class="dashicons dashicons-shield vigilante-notice-icon"></span>
1709 <strong><?php esc_html_e( 'Vigilant activated successfully!', 'vigilante' ); ?></strong>
1710 <?php esc_html_e( 'Security protection is now active.', 'vigilante' ); ?>
1711 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante' ) ); ?>">
1712 <?php esc_html_e( 'Configure settings', 'vigilante' ); ?>
1713 </a>
1714 </p>
1715 </div>
1716 <?php
1717 delete_transient( 'vigilante_activated' );
1718 }
1719
1720 // Under Attack mode notice (non-dismissible, shown on all admin pages)
1721 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
1722 if ( ! empty( $ua_status['active'] ) ) {
1723 $ua_remaining = ( $ua_status['activated_at'] + $ua_status['duration'] ) - time();
1724 if ( $ua_remaining > 0 ) {
1725 $ua_hours = floor( $ua_remaining / 3600 );
1726 $ua_mins = floor( ( $ua_remaining % 3600 ) / 60 );
1727 $dashboard_url = admin_url( 'admin.php?page=vigilante' );
1728 ?>
1729 <div class="notice notice-warning vigilante-ua-notice">
1730 <p>
1731 <span class="dashicons dashicons-shield"></span>
1732 <strong><?php esc_html_e( 'Under Attack mode is active', 'vigilante' ); ?></strong>
1733 &mdash;
1734 <?php
1735 printf(
1736 /* translators: 1: Hours, 2: Minutes */
1737 esc_html__( '%1$dh %2$dm remaining.', 'vigilante' ),
1738 absint( $ua_hours ),
1739 absint( $ua_mins )
1740 );
1741 ?>
1742 <a href="<?php echo esc_url( $dashboard_url ); ?>">
1743 <?php esc_html_e( 'Go to Vigilant dashboard', 'vigilante' ); ?>
1744 </a>
1745 </p>
1746 <p>
1747 <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>
1748 </p>
1749 </div>
1750 <?php
1751 }
1752 }
1753
1754 // Proxy/CDN detection: if IP detection is set to "direct" but requests
1755 // arrive with a forwarded-for header carrying a different valid IP, the
1756 // site is very likely behind a proxy/CDN that has not been declared, so
1757 // the firewall is seeing the proxy IP for every visitor. Guide the admin.
1758 //
1759 // Two deliberate silencers (2.9.2):
1760 // - A loopback forwarded IP (::1 / 127.x) means the person browsing IS
1761 // the machine itself: that only happens in local development stacks
1762 // (Local's nginx router, Docker...), never behind a production
1763 // proxy/CDN, so the notice would be pure noise there.
1764 // - The notice is dismissible and the dismissal persists site-wide via
1765 // the vigilante_dismissed_notices option (the admin evaluated it and
1766 // decided; nagging forever helps nobody).
1767 $dismissed_notices = get_option( 'vigilante_dismissed_notices', array() );
1768 if (
1769 current_user_can( 'manage_options' )
1770 && '' === Vigilante_IP_Utils::trusted_proxy_header()
1771 && ! isset( $dismissed_notices['proxy_detection'] )
1772 ) {
1773 $remote = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
1774 $detected = '';
1775 foreach ( Vigilante_IP_Utils::trusted_header_map() as $proxy_label => $server_key ) {
1776 if ( empty( $_SERVER[ $server_key ] ) ) {
1777 continue;
1778 }
1779 $candidate = sanitize_text_field( wp_unslash( $_SERVER[ $server_key ] ) );
1780 if ( false !== strpos( $candidate, ',' ) ) {
1781 $parts = explode( ',', $candidate );
1782 $candidate = trim( $parts[0] );
1783 }
1784 if ( ! filter_var( $candidate, FILTER_VALIDATE_IP ) || $candidate === $remote ) {
1785 continue;
1786 }
1787 // Loopback forwarded IP = local development, not a real proxy.
1788 if ( '::1' === $candidate || 0 === strpos( $candidate, '127.' ) ) {
1789 continue;
1790 }
1791 $detected = $proxy_label;
1792 break;
1793 }
1794
1795 if ( '' !== $detected ) {
1796 $firewall_url = admin_url( 'admin.php?page=vigilante&tab=firewall' );
1797 $detail_message = sprintf(
1798 /* translators: %s: detected forwarded header name wrapped in a code tag. */
1799 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' ),
1800 '<code>' . esc_html( strtoupper( $detected ) ) . '</code>'
1801 );
1802 ?>
1803 <div class="notice notice-warning is-dismissible vigilante-proxy-notice">
1804 <p>
1805 <span class="dashicons dashicons-shield"></span>
1806 <strong><?php esc_html_e( 'Vigilant: this site looks like it is behind a proxy or CDN', 'vigilante' ); ?></strong>
1807 </p>
1808 <p><?php echo wp_kses_post( $detail_message ); ?></p>
1809 <p>
1810 <a href="<?php echo esc_url( $firewall_url ); ?>" class="button button-secondary">
1811 <?php esc_html_e( 'Set your proxy in Firewall settings', 'vigilante' ); ?>
1812 </a>
1813 </p>
1814 </div>
1815 <script>
1816 jQuery( function ( $ ) {
1817 $( document ).on( 'click', '.vigilante-proxy-notice .notice-dismiss', function () {
1818 $.post( ajaxurl, {
1819 action: 'vigilante_dismiss_notice',
1820 notice_id: 'proxy_detection',
1821 nonce: <?php echo wp_json_encode( wp_create_nonce( 'vigilante_dismiss_notice' ) ); ?>
1822 } );
1823 } );
1824 } );
1825 </script>
1826 <?php
1827 }
1828 }
1829 }
1830
1831 /**
1832 * Render settings page
1833 */
1834 public function render_settings_page() {
1835 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1836 $this->current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'dashboard';
1837
1838 if ( ! array_key_exists( $this->current_tab, $this->tabs ) ) {
1839 $this->current_tab = 'dashboard';
1840 }
1841 ?>
1842 <div class="wrap vigilante-admin-wrap">
1843 <div class="vigilante-header-row">
1844 <h1 class="vigilante-page-title">
1845 <img src="<?php echo esc_url( VIGILANTE_ASSETS_URL . 'images/icon.png' ); ?>" alt="Vigilante" class="vigilante-title-icon">
1846 <?php esc_html_e( 'Vigilant', 'vigilante' ); ?>
1847 <span class="vigilante-version">v<?php echo esc_html( VIGILANTE_VERSION ); ?></span>
1848 </h1>
1849 <div class="vigilante-search-wrapper">
1850 <div class="vigilante-search-input-wrap">
1851 <span class="vigilante-search-icon dashicons dashicons-search" aria-hidden="true"></span>
1852 <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">
1853 <span class="vigilante-search-shortcut" aria-hidden="true">/</span>
1854 </div>
1855 <div id="vigilante-settings-search-results" class="vigilante-search-results" hidden role="listbox"></div>
1856 </div>
1857 </div>
1858
1859 <?php $this->render_tabs(); ?>
1860
1861 <div class="vigilante-content">
1862 <div class="vigilante-main">
1863 <?php $this->render_tab_content(); ?>
1864 </div>
1865 <div class="vigilante-sidebar">
1866 <?php $this->render_sidebar(); ?>
1867 </div>
1868 </div>
1869 </div>
1870 <?php
1871 }
1872
1873 /**
1874 * Render tabs navigation
1875 */
1876 private function render_tabs() {
1877 $options = $this->settings->get_all_options();
1878
1879 // Map tabs to modules
1880 $tab_to_module = array(
1881 'firewall' => 'firewall',
1882 'headers' => 'security_headers',
1883 'login' => 'login_security',
1884 'rest-api' => 'rest_api_security',
1885 'users' => 'user_security',
1886 'wp-hardening' => 'wp_hardening',
1887 'file-integrity' => 'file_integrity',
1888 'activity-log' => 'activity_log',
1889 );
1890 ?>
1891 <nav class="nav-tab-wrapper vigilante-nav-tabs">
1892 <?php foreach ( $this->tabs as $tab_id => $tab_name ) :
1893 $is_disabled = false;
1894 $module = isset( $tab_to_module[ $tab_id ] ) ? $tab_to_module[ $tab_id ] : null;
1895 if ( $module && empty( $options['modules'][ $module ] ) ) {
1896 $is_disabled = true;
1897 }
1898 ?>
1899 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $tab_id ) ); ?>"
1900 class="nav-tab <?php echo $this->current_tab === $tab_id ? 'nav-tab-active' : ''; ?> <?php echo $is_disabled ? 'vigilante-tab-disabled' : ''; ?>"
1901 <?php if ( $is_disabled ) : ?>title="<?php esc_attr_e( 'Module Disabled', 'vigilante' ); ?>"<?php endif; ?>>
1902 <?php echo esc_html( $tab_name ); ?>
1903 <?php if ( $is_disabled ) : ?><span class="vigilante-tab-off">OFF</span><?php endif; ?>
1904 </a>
1905 <?php endforeach; ?>
1906 </nav>
1907 <?php
1908 }
1909
1910 /**
1911 * Render current tab content
1912 */
1913 private function render_tab_content() {
1914 $method = 'render_tab_' . str_replace( '-', '_', $this->current_tab );
1915
1916 if ( method_exists( $this, $method ) ) {
1917 $this->$method();
1918 } else {
1919 $this->render_tab_coming_soon();
1920 }
1921 }
1922
1923 /**
1924 * Render coming soon placeholder
1925 */
1926 private function render_tab_coming_soon() {
1927 ?>
1928 <div class="vigilante-settings-section">
1929 <h2><?php esc_html_e( 'Coming Soon', 'vigilante' ); ?></h2>
1930 <p><?php esc_html_e( 'This section is under development.', 'vigilante' ); ?></p>
1931 </div>
1932 <?php
1933 }
1934
1935 /**
1936 * Values to display for a section that this site does not control
1937 *
1938 * On a subsite the stored options are its own copy, which nothing acts on:
1939 * wp-config.php and .htaccess are written from the main site. Painting the
1940 * local copy describes a configuration that is not running, so a subsite
1941 * admin sees a box ticked here and the constant absent from the file, or the
1942 * other way round. Read the main site's values instead, which are the ones in
1943 * force, and fall back to the local ones if they cannot be read.
1944 *
1945 * @since 2.9.8
1946 *
1947 * @param string $section Settings section.
1948 * @return array
1949 */
1950 private function get_section_for_display( $section ) {
1951 $local = $this->settings->get_section( $section );
1952
1953 if ( ! $this->shared_files_locked() ) {
1954 return $local;
1955 }
1956
1957 // shared_files_locked() is only true on multisite, where get_blog_option() exists.
1958 $main = get_blog_option( get_main_site_id(), Vigilante_Settings::OPTION_NAME, array() );
1959
1960 if ( ! is_array( $main ) || empty( $main[ $section ] ) || ! is_array( $main[ $section ] ) ) {
1961 return $local;
1962 }
1963
1964 return wp_parse_args( $main[ $section ], $local );
1965 }
1966
1967 /**
1968 * Whether the sections that write wp-config.php and .htaccess are read-only here
1969 *
1970 * True on a network when this is not the main site, or the user is not a
1971 * network administrator. See Vigilante_Settings::can_write_shared_files().
1972 *
1973 * @since 2.9.8
1974 *
1975 * @return bool
1976 */
1977 private function shared_files_locked() {
1978 return ! Vigilante_Settings::can_write_shared_files();
1979 }
1980
1981 /**
1982 * Print the shared-files notice for a section that cannot be edited here
1983 *
1984 * @since 2.9.8
1985 */
1986 private function render_shared_files_notice() {
1987 if ( ! $this->shared_files_locked() ) {
1988 return;
1989 }
1990 ?>
1991 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
1992 <p style="margin:0;"><?php echo esc_html( Vigilante_Settings::get_shared_files_notice() ); ?></p>
1993 </div>
1994 <?php
1995 }
1996
1997 /**
1998 * Check if module is disabled and render warning
1999 *
2000 * @param string $module_key Module key.
2001 * @return bool True if disabled.
2002 */
2003 private function render_module_disabled_notice( $module_key ) {
2004 if ( $this->settings->is_module_enabled( $module_key ) ) {
2005 return false;
2006 }
2007
2008 $module_labels = $this->settings->get_module_labels();
2009 $module_name = isset( $module_labels[ $module_key ] ) ? $module_labels[ $module_key ] : $module_key;
2010 ?>
2011 <div class="notice notice-warning vigilante-module-disabled-notice">
2012 <p>
2013 <strong><?php esc_html_e( 'Module Disabled', 'vigilante' ); ?></strong> -
2014 <?php
2015 printf(
2016 /* translators: %s: Module name */
2017 esc_html__( 'The %s module is currently disabled. Enable it from the Dashboard to use these settings.', 'vigilante' ),
2018 esc_html( $module_name )
2019 );
2020 ?>
2021 </p>
2022 <p>
2023 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=dashboard' ) ); ?>" class="button">
2024 <?php esc_html_e( 'Go to Dashboard', 'vigilante' ); ?>
2025 </a>
2026 </p>
2027 </div>
2028 <?php
2029 return true;
2030 }
2031
2032 /**
2033 * Render the Security Analyzer (Security Check) widget + expandable full report.
2034 *
2035 * Lives in the Dashboard tab between the Configuration Score status card and
2036 * the modules grid. Uses the last persisted scan to hydrate server-side so the
2037 * first paint shows real data; "Scan now" runs the 2-phase AJAX to refresh.
2038 *
2039 * @param array $last_scan Result of Vigilante_Security_Analyzer::get_last_scan().
2040 * @param array $history Score history (oldest first).
2041 * @param array $categories_def Category metadata (slug => label/max).
2042 * @param array $analyzer_settings Settings subsection for weekly cron + email.
2043 */
2044 private function render_analyzer_widget( $last_scan, $history, $categories_def, $analyzer_settings ) {
2045 $has_data = ! empty( $last_scan['ran_at'] );
2046 $score = isset( $last_scan['score'] ) ? (int) $last_scan['score'] : 0;
2047 $grade = isset( $last_scan['grade'] ) ? (string) $last_scan['grade'] : '';
2048 $counts = isset( $last_scan['counts'] ) && is_array( $last_scan['counts'] ) ? $last_scan['counts'] : array();
2049 $ran_at_human = $has_data
2050 ? sprintf(
2051 /* translators: %s: relative time like "2 hours" */
2052 __( 'Last scan %s ago', 'vigilante' ),
2053 human_time_diff( (int) $last_scan['ran_at'], time() )
2054 )
2055 : __( 'Never scanned', 'vigilante' );
2056 $categories = isset( $last_scan['categories'] ) && is_array( $last_scan['categories'] ) ? $last_scan['categories'] : array();
2057 $weekly_enabled = ! isset( $analyzer_settings['weekly_scan_enabled'] ) || ! empty( $analyzer_settings['weekly_scan_enabled'] );
2058 $email_enabled = ! empty( $analyzer_settings['email_on_regression'] );
2059
2060 $quality = self::analyzer_quality_tag( $score );
2061 ?>
2062 <div class="vigilante-analyzer" id="vigilante-analyzer"
2063 data-has-data="<?php echo $has_data ? '1' : '0'; ?>">
2064 <div class="vigilante-analyzer-header">
2065 <div class="vigilante-analyzer-title">
2066 <h2>
2067 <span class="dashicons dashicons-shield-alt" aria-hidden="true"></span>
2068 <?php esc_html_e( 'Security Check', 'vigilante' ); ?>
2069 </h2>
2070 <p class="description">
2071 <?php esc_html_e( 'On-demand audit of what an attacker would see right now, plus 13 internal checks impossible from the outside.', 'vigilante' ); ?>
2072 </p>
2073 <p class="vigilante-analyzer-last-scan" data-role="ran-at">
2074 <span class="dashicons dashicons-clock" aria-hidden="true"></span>
2075 <?php echo esc_html( $ran_at_human ); ?>
2076 </p>
2077 </div>
2078 <div class="vigilante-analyzer-actions">
2079 <button type="button" class="button button-primary" id="vigilante-analyzer-scan">
2080 <span class="dashicons dashicons-update" aria-hidden="true"></span>
2081 <?php esc_html_e( 'Scan now', 'vigilante' ); ?>
2082 </button>
2083 </div>
2084 </div>
2085
2086 <div class="vigilante-analyzer-summary">
2087 <div class="vigilante-analyzer-score-card">
2088 <?php if ( $has_data && $grade ) : ?>
2089 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2090 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2091 <span class="vigilante-score-text"><?php echo esc_html( $score ); ?>%</span>
2092 </div>
2093 <?php else : ?>
2094 <div class="vigilante-score-circle vigilante-grade-empty">
2095 <span class="vigilante-grade">—</span>
2096 <span class="vigilante-score-text"><?php esc_html_e( 'N/A', 'vigilante' ); ?></span>
2097 </div>
2098 <?php endif; ?>
2099 <div class="vigilante-analyzer-score-meta">
2100 <p class="vigilante-analyzer-score-label">
2101 <?php esc_html_e( 'Security Score', 'vigilante' ); ?>
2102 </p>
2103 <span class="vigilante-analyzer-quality-tag vigilante-analyzer-quality-<?php echo esc_attr( $quality['slug'] ); ?>"
2104 data-role="quality-tag">
2105 <?php echo esc_html( $quality['label'] ); ?>
2106 </span>
2107 </div>
2108 </div>
2109
2110 <div class="vigilante-analyzer-counts">
2111 <span class="vigilante-analyzer-count vigilante-analyzer-count--pass">
2112 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2113 <strong data-role="pass"><?php echo esc_html( isset( $counts['pass'] ) ? $counts['pass'] : 0 ); ?></strong>
2114 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Passed', 'vigilante' ); ?></span>
2115 </span>
2116 <span class="vigilante-analyzer-count vigilante-analyzer-count--warn">
2117 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2118 <strong data-role="warn"><?php echo esc_html( isset( $counts['warn'] ) ? $counts['warn'] : 0 ); ?></strong>
2119 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Warnings', 'vigilante' ); ?></span>
2120 </span>
2121 <span class="vigilante-analyzer-count vigilante-analyzer-count--fail">
2122 <span class="dashicons dashicons-dismiss" aria-hidden="true"></span>
2123 <strong data-role="fail"><?php echo esc_html( isset( $counts['fail'] ) ? $counts['fail'] : 0 ); ?></strong>
2124 <span class="vigilante-analyzer-count-label"><?php esc_html_e( 'Failing', 'vigilante' ); ?></span>
2125 </span>
2126 </div>
2127
2128 <?php
2129 // Sparkline of recent scores. Require at least 3 data points so the trend
2130 // is meaningful (2 points is just a line between dots, no real trend).
2131 $hist_points = array();
2132 foreach ( $history as $h ) {
2133 $hist_points[] = (int) $h['score'];
2134 }
2135 $hist_count = count( $hist_points );
2136 if ( $hist_count >= 3 ) :
2137 $current_score = (int) end( $hist_points );
2138 $previous_score = (int) $hist_points[ $hist_count - 2 ];
2139 $delta = $current_score - $previous_score;
2140 $delta_class = $delta > 0 ? 'vigilante-analyzer-delta--up' : ( $delta < 0 ? 'vigilante-analyzer-delta--down' : 'vigilante-analyzer-delta--flat' );
2141 $delta_icon = $delta > 0 ? 'arrow-up-alt' : ( $delta < 0 ? 'arrow-down-alt' : 'minus' );
2142 if ( 0 === $delta ) {
2143 $delta_text = __( 'No change', 'vigilante' );
2144 } else {
2145 $delta_text = sprintf(
2146 /* translators: %s: signed delta, e.g. "+3" or "-5" */
2147 _n( '%s pt vs. previous scan', '%s pts vs. previous scan', abs( $delta ), 'vigilante' ),
2148 ( $delta > 0 ? '+' : '' ) . (int) $delta
2149 );
2150 }
2151 ?>
2152 <div class="vigilante-analyzer-sparkline-wrap">
2153 <div class="vigilante-analyzer-sparkline-head">
2154 <span class="vigilante-analyzer-sparkline-label">
2155 <?php
2156 echo esc_html( sprintf(
2157 /* translators: %d: number of scans */
2158 _n( 'Score trend (last %d scan)', 'Score trend (last %d scans)', $hist_count, 'vigilante' ),
2159 $hist_count
2160 ) );
2161 ?>
2162 </span>
2163 <span class="vigilante-analyzer-delta <?php echo esc_attr( $delta_class ); ?>">
2164 <span class="dashicons dashicons-<?php echo esc_attr( $delta_icon ); ?>" aria-hidden="true"></span>
2165 <?php echo esc_html( $delta_text ); ?>
2166 </span>
2167 </div>
2168 <div class="vigilante-analyzer-sparkline" data-role="sparkline"
2169 data-points="<?php echo esc_attr( wp_json_encode( $hist_points ) ); ?>">
2170 <?php echo self::sparkline_svg( $hist_points ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe SVG from helper ?>
2171 </div>
2172 </div>
2173 <?php elseif ( $has_data ) : ?>
2174 <div class="vigilante-analyzer-sparkline-wrap vigilante-analyzer-sparkline-wrap--placeholder">
2175 <span class="vigilante-analyzer-sparkline-label">
2176 <?php esc_html_e( 'Score trend', 'vigilante' ); ?>
2177 </span>
2178 <p class="vigilante-analyzer-sparkline-hint">
2179 <span class="dashicons dashicons-chart-line" aria-hidden="true"></span>
2180 <?php
2181 $needed = 3 - $hist_count;
2182 echo esc_html( sprintf(
2183 /* translators: %d: number of additional scans needed */
2184 _n( '%d more scan needed to show a trend.', '%d more scans needed to show a trend.', $needed, 'vigilante' ),
2185 $needed
2186 ) );
2187 ?>
2188 </p>
2189 </div>
2190 <?php endif; ?>
2191 </div>
2192
2193 <div class="vigilante-analyzer-toggle-row">
2194 <button type="button" class="button-link vigilante-analyzer-toggle" aria-expanded="false">
2195 <?php esc_html_e( 'Show detailed breakdown', 'vigilante' ); ?>
2196 <span class="vigilante-analyzer-toggle-chevron" aria-hidden="true"></span>
2197 </button>
2198 </div>
2199
2200 <div class="vigilante-analyzer-details" hidden>
2201 <div class="vigilante-analyzer-categories" data-role="categories">
2202 <?php foreach ( $categories_def as $slug => $meta ) :
2203 $cat = isset( $categories[ $slug ] ) ? $categories[ $slug ] : array();
2204 $earned = isset( $cat['earned'] ) ? (int) $cat['earned'] : 0;
2205 // Always use the declared meta as the source of truth for the maximum.
2206 // The cached scan may carry an old max if a check was added/removed
2207 // between releases (see 2.6.1: closed_plugins raised internal from 22 to 28
2208 // but cached scans still reported max=22 until reset).
2209 $cat_max = (int) $meta['max'];
2210 $info_only = ! empty( $meta['info_only'] ) || 0 === (int) $meta['max'];
2211 $cat_pct = $cat_max > 0 ? (int) round( ( $earned / $cat_max ) * 100 ) : 0;
2212 $checks = isset( $cat['checks'] ) ? (array) $cat['checks'] : array();
2213 $cat_counts = isset( $cat['counts'] ) && is_array( $cat['counts'] ) ? $cat['counts'] : array( 'pass' => 0, 'warn' => 0, 'fail' => 0, 'info' => 0 );
2214 $cat_quality = self::analyzer_quality_tag( $cat_pct );
2215 $info_count = isset( $cat_counts['info'] ) ? (int) $cat_counts['info'] : 0;
2216 ?>
2217 <details class="vigilante-analyzer-category<?php echo $info_only ? ' vigilante-analyzer-category--info' : ''; ?>"
2218 data-category="<?php echo esc_attr( $slug ); ?>"
2219 data-info-only="<?php echo $info_only ? '1' : '0'; ?>">
2220 <summary class="vigilante-analyzer-category-summary">
2221 <span class="vigilante-analyzer-category-chevron" aria-hidden="true"></span>
2222 <span class="vigilante-analyzer-category-label"><?php echo esc_html( $meta['label'] ); ?></span>
2223 <?php if ( $info_only ) : ?>
2224 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-info"
2225 data-role="category-quality"
2226 title="<?php esc_attr_e( 'Informational — does not affect the security score.', 'vigilante' ); ?>">
2227 <span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2228 <?php esc_html_e( 'Informational', 'vigilante' ); ?>
2229 </span>
2230 <?php else :
2231 $passed_count = (int) ( $cat_counts['pass'] ?? 0 );
2232 $scored_total = $passed_count
2233 + (int) ( $cat_counts['warn'] ?? 0 )
2234 + (int) ( $cat_counts['fail'] ?? 0 );
2235 ?>
2236 <span class="vigilante-analyzer-category-quality vigilante-analyzer-quality-<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2237 data-role="category-quality">
2238 <span data-role="category-quality-label"><?php echo esc_html( $cat_quality['label'] ); ?></span>
2239 <span class="vigilante-analyzer-category-quality-sep" aria-hidden="true">·</span>
2240 <span class="vigilante-analyzer-category-tests" data-role="category-tests"
2241 data-passed="<?php echo esc_attr( $passed_count ); ?>"
2242 data-total="<?php echo esc_attr( $scored_total ); ?>">
2243 <?php
2244 echo esc_html( sprintf(
2245 /* translators: 1: tests passed, 2: total tests in this category */
2246 __( '%1$d/%2$d tests', 'vigilante' ),
2247 $passed_count,
2248 $scored_total
2249 ) );
2250 ?>
2251 </span>
2252 </span>
2253 <?php endif; ?>
2254 <?php if ( $info_only ) : ?>
2255 <span class="vigilante-analyzer-category-states" data-role="category-states">
2256 <?php if ( $info_count > 0 ) : ?>
2257 <span class="vigilante-analyzer-category-state vigilante-analyzer-category-state--info" title="<?php esc_attr_e( 'Informational', 'vigilante' ); ?>">
2258 <span data-role="state-info"><?php echo esc_html( $info_count ); ?></span><span class="dashicons dashicons-info-outline" aria-hidden="true"></span>
2259 </span>
2260 <?php endif; ?>
2261 </span>
2262 <?php endif; ?>
2263 <?php if ( ! $info_only ) : ?>
2264 <span class="vigilante-analyzer-category-score">
2265 <span data-role="earned"><?php echo esc_html( $earned ); ?></span><span class="vigilante-analyzer-category-score-sep">/</span><?php echo esc_html( $cat_max ); ?>
2266 <span class="vigilante-analyzer-category-score-unit"><?php esc_html_e( 'pts', 'vigilante' ); ?></span>
2267 </span>
2268 <span class="vigilante-analyzer-category-bar" aria-hidden="true">
2269 <span class="vigilante-analyzer-category-bar-fill vigilante-analyzer-category-bar-fill--<?php echo esc_attr( $cat_quality['slug'] ); ?>"
2270 style="width: <?php echo esc_attr( $cat_pct ); ?>%"
2271 data-role="category-bar"></span>
2272 </span>
2273 <?php else :
2274 $info_warn = isset( $cat_counts['warn'] ) ? (int) $cat_counts['warn'] : 0;
2275 $info_fail = isset( $cat_counts['fail'] ) ? (int) $cat_counts['fail'] : 0;
2276 $info_issues = $info_warn + $info_fail;
2277 if ( $info_issues > 0 ) : ?>
2278 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--attention" data-role="info-status">
2279 <span class="dashicons dashicons-warning" aria-hidden="true"></span>
2280 <?php
2281 echo esc_html( sprintf(
2282 /* translators: %d: number of findings */
2283 _n( '%d finding', '%d findings', $info_issues, 'vigilante' ),
2284 $info_issues
2285 ) );
2286 ?>
2287 </span>
2288 <?php else : ?>
2289 <span class="vigilante-analyzer-category-status vigilante-analyzer-category-status--clear" data-role="info-status">
2290 <span class="dashicons dashicons-yes-alt" aria-hidden="true"></span>
2291 <?php esc_html_e( 'All clear', 'vigilante' ); ?>
2292 </span>
2293 <?php endif; ?>
2294 <?php endif; ?>
2295 </summary>
2296 <ul class="vigilante-analyzer-check-list" data-role="check-list">
2297 <?php if ( empty( $checks ) ) : ?>
2298 <li class="vigilante-analyzer-check-empty">
2299 <?php esc_html_e( 'No data yet — run a scan to populate this category.', 'vigilante' ); ?>
2300 </li>
2301 <?php else : ?>
2302 <?php foreach ( $checks as $c ) : ?>
2303 <?php echo self::render_analyzer_check_row( $c ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped inside helper ?>
2304 <?php endforeach; ?>
2305 <?php endif; ?>
2306 </ul>
2307 </details>
2308 <?php endforeach; ?>
2309 </div>
2310
2311 <div class="vigilante-analyzer-weekly">
2312 <h3><?php esc_html_e( 'Automatic weekly scan', 'vigilante' ); ?></h3>
2313 <p class="description">
2314 <?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' ); ?>
2315 </p>
2316 <label class="vigilante-analyzer-toggle-option">
2317 <input type="checkbox"
2318 name="security_analyzer[weekly_scan_enabled]"
2319 value="1"
2320 <?php checked( $weekly_enabled ); ?>>
2321 <?php esc_html_e( 'Run a weekly automatic scan', 'vigilante' ); ?>
2322 </label>
2323 <label class="vigilante-analyzer-toggle-option">
2324 <input type="checkbox"
2325 name="security_analyzer[email_on_regression]"
2326 value="1"
2327 <?php checked( $email_enabled ); ?>>
2328 <?php esc_html_e( 'Email me when the score drops significantly', 'vigilante' ); ?>
2329 </label>
2330 </div>
2331 </div>
2332 </div>
2333 <?php
2334 }
2335
2336 /**
2337 * Map a 0-100 percentage to a quality tag { label, slug } aligned with the
2338 * Dashboard grade palette (a/b/c/d/e).
2339 *
2340 * @param int $pct 0..100.
2341 * @return array{label:string,slug:string}
2342 */
2343 public static function analyzer_quality_tag( $pct ) {
2344 $pct = max( 0, min( 100, (int) $pct ) );
2345 // "Excellent" is reserved for a perfect score — a single missing point drops to Good.
2346 if ( 100 === $pct ) {
2347 return array( 'label' => __( 'Excellent', 'vigilante' ), 'slug' => 'a' );
2348 }
2349 if ( $pct >= 70 ) {
2350 return array( 'label' => __( 'Good', 'vigilante' ), 'slug' => 'b' );
2351 }
2352 if ( $pct >= 50 ) {
2353 return array( 'label' => __( 'Fair', 'vigilante' ), 'slug' => 'c' );
2354 }
2355 if ( $pct >= 30 ) {
2356 return array( 'label' => __( 'Poor', 'vigilante' ), 'slug' => 'd' );
2357 }
2358 return array( 'label' => __( 'Critical', 'vigilante' ), 'slug' => 'e' );
2359 }
2360
2361 /**
2362 * Render a single analyzer check row (used both server-side and via JS template).
2363 *
2364 * @param array $check Check result array (from Vigilante_SA_Check_Result::to_array()).
2365 * @return string HTML (escaped).
2366 */
2367 private static function render_analyzer_check_row( $check ) {
2368 $id = isset( $check['id'] ) ? $check['id'] : '';
2369 $state = isset( $check['state'] ) ? $check['state'] : 'skip';
2370 $label = isset( $check['label'] ) ? $check['label'] : '';
2371 $detail = isset( $check['detail'] ) ? $check['detail'] : '';
2372 $score = isset( $check['score'] ) ? (int) $check['score'] : 0;
2373 $max = isset( $check['max'] ) ? (int) $check['max'] : 0;
2374 $fix_link = isset( $check['fix_link'] ) ? $check['fix_link'] : '';
2375
2376 $icons = array(
2377 'pass' => 'yes-alt',
2378 'warn' => 'warning',
2379 'fail' => 'dismiss',
2380 'info' => 'info',
2381 'skip' => 'minus',
2382 );
2383 $icon = isset( $icons[ $state ] ) ? $icons[ $state ] : 'minus';
2384
2385 $html = '<li class="vigilante-analyzer-check vigilante-analyzer-check--' . esc_attr( $state ) . '"';
2386 $html .= ' data-check-id="' . esc_attr( $id ) . '">';
2387 $html .= '<span class="vigilante-analyzer-check-icon dashicons dashicons-' . esc_attr( $icon ) . '" aria-hidden="true"></span>';
2388 $html .= '<div class="vigilante-analyzer-check-body">';
2389 $html .= '<div class="vigilante-analyzer-check-label">';
2390 $html .= '<span>' . esc_html( $label ) . '</span>';
2391 if ( $max > 0 && 'info' !== $state && 'skip' !== $state ) {
2392 $html .= '<span class="vigilante-analyzer-check-score">'
2393 . esc_html( $score . '/' . $max )
2394 . ' <span class="vigilante-analyzer-check-score-unit">' . esc_html__( 'pts', 'vigilante' ) . '</span>'
2395 . '</span>';
2396 }
2397 $html .= '</div>';
2398 if ( $detail ) {
2399 $html .= '<p class="vigilante-analyzer-check-detail">' . esc_html( $detail ) . '</p>';
2400 }
2401 if ( $fix_link && in_array( $state, array( 'fail', 'warn' ), true ) ) {
2402 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link">'
2403 . esc_html__( 'Go to setting', 'vigilante' )
2404 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2405 } elseif ( $fix_link && 'info' === $state ) {
2406 // Info rows (e.g. DNSBL lookups) get an external "Learn more" link instead.
2407 $is_external = 0 === strpos( $fix_link, 'http' );
2408 $html .= '<a href="' . esc_url( $fix_link ) . '" class="vigilante-analyzer-fix-link"'
2409 . ( $is_external ? ' target="_blank" rel="noopener noreferrer"' : '' ) . '>'
2410 . esc_html__( 'Learn more', 'vigilante' )
2411 . '<span class="vigilante-analyzer-fix-arrow" aria-hidden="true">&rarr;</span></a>';
2412 }
2413 $html .= '</div>';
2414 $html .= '</li>';
2415 return $html;
2416 }
2417
2418 /**
2419 * Build a minimal SVG sparkline for the score history.
2420 *
2421 * @param int[] $points Score values (0..100), oldest to newest.
2422 * @return string SVG markup.
2423 */
2424 private static function sparkline_svg( $points ) {
2425 $points = array_map( 'intval', (array) $points );
2426 $count = count( $points );
2427 if ( $count < 2 ) {
2428 return '';
2429 }
2430 $width = 280;
2431 $height = 60;
2432 $padding = 4;
2433
2434 $usable_w = $width - ( $padding * 2 );
2435 $usable_h = $height - ( $padding * 2 );
2436
2437 $step = $usable_w / max( 1, $count - 1 );
2438 $max = 100; // Fixed scale — scores are 0..100.
2439
2440 $coords = array();
2441 foreach ( $points as $i => $v ) {
2442 $x = $padding + ( $i * $step );
2443 $y = $padding + ( $usable_h - ( ( $v / $max ) * $usable_h ) );
2444 $coords[] = round( $x, 2 ) . ',' . round( $y, 2 );
2445 }
2446 $path = 'M ' . implode( ' L ', $coords );
2447 $last = end( $points );
2448 $last_x = $padding + ( ( $count - 1 ) * $step );
2449 $last_y = $padding + ( $usable_h - ( ( $last / $max ) * $usable_h ) );
2450
2451 $svg = '<svg viewBox="0 0 ' . $width . ' ' . $height . '" preserveAspectRatio="none" role="img" aria-label="' . esc_attr__( 'Security Score history', 'vigilante' ) . '" focusable="false">';
2452 $svg .= '<path d="' . esc_attr( $path ) . '" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>';
2453 $svg .= '<circle cx="' . esc_attr( round( $last_x, 2 ) ) . '" cy="' . esc_attr( round( $last_y, 2 ) ) . '" r="3" fill="currentColor"/>';
2454 $svg .= '</svg>';
2455 return $svg;
2456 }
2457
2458 /**
2459 * Render dashboard tab
2460 */
2461 private function render_tab_dashboard() {
2462 $options = $this->settings->get_all_options();
2463 $module_labels = $this->settings->get_module_labels();
2464 $module_descriptions = $this->settings->get_module_descriptions();
2465 $presets = $this->settings->get_presets();
2466 $active_preset = get_option( 'vigilante_active_preset', '' );
2467
2468 // Calculate security score with more factors
2469 $security_score = $this->calculate_security_score( $options );
2470
2471 // Security Analyzer (v2.1.0) — hydrate widget with the last persisted scan, if any.
2472 if ( ! class_exists( 'Vigilante_Security_Analyzer' ) ) {
2473 require_once VIGILANTE_INCLUDES_DIR . 'class-security-analyzer.php';
2474 }
2475 $analyzer_instance = new Vigilante_Security_Analyzer( $this->settings, $this->activity_log );
2476 $analyzer_last_scan = $analyzer_instance->get_last_scan();
2477 $analyzer_history = $analyzer_instance->get_score_history();
2478 $analyzer_categories_def = Vigilante_Security_Analyzer::get_categories();
2479 $analyzer_settings = isset( $options['security_analyzer'] ) ? $options['security_analyzer'] : array();
2480 ?>
2481 <div class="vigilante-dashboard">
2482 <div class="vigilante-status-card">
2483 <h2><?php esc_html_e( 'Configuration Score', 'vigilante' ); ?></h2>
2484 <p class="vigilante-score-kind description">
2485 <?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' ); ?>
2486 </p>
2487 <div class="vigilante-security-score">
2488 <?php
2489 // Grade thresholds: A (90+), B (70-89), C (50-69), D (30-49), E (0-29)
2490 if ( $security_score >= 90 ) {
2491 $grade = 'A';
2492 } elseif ( $security_score >= 70 ) {
2493 $grade = 'B';
2494 } elseif ( $security_score >= 50 ) {
2495 $grade = 'C';
2496 } elseif ( $security_score >= 30 ) {
2497 $grade = 'D';
2498 } else {
2499 $grade = 'E';
2500 }
2501 ?>
2502 <div class="vigilante-score-circle vigilante-grade-<?php echo esc_attr( strtolower( $grade ) ); ?>">
2503 <span class="vigilante-grade"><?php echo esc_html( $grade ); ?></span>
2504 <span class="vigilante-score-text"><?php echo esc_html( $security_score ); ?>%</span>
2505 </div>
2506 <div class="vigilante-config-status">
2507 <?php if ( $active_preset && isset( $presets[ $active_preset ] ) ) : ?>
2508 <span class="vigilante-preset-badge vigilante-preset-<?php echo esc_attr( $active_preset ); ?>">
2509 <?php echo esc_html( $presets[ $active_preset ]['name'] ); ?>
2510 </span>
2511 <?php else : ?>
2512 <span class="vigilante-preset-badge vigilante-preset-custom">
2513 <?php esc_html_e( 'Custom Configuration', 'vigilante' ); ?>
2514 </span>
2515 <?php endif; ?>
2516 </div>
2517 </div>
2518
2519 <?php
2520 $recommendations = $this->get_security_recommendations( $options );
2521 if ( ! empty( $recommendations ) ) :
2522 ?>
2523 <div class="vigilante-recommendations">
2524 <h4><?php esc_html_e( 'Recommendations', 'vigilante' ); ?></h4>
2525 <ul class="vigilante-recommendations-grid">
2526 <?php foreach ( $recommendations as $rec ) : ?>
2527 <li>
2528 <span class="dashicons dashicons-<?php echo esc_attr( $rec['icon'] ); ?> vigilante-priority-<?php echo esc_attr( $rec['priority'] ); ?>"></span>
2529 <?php echo esc_html( $rec['message'] ); ?>
2530 <?php if ( ! empty( $rec['tab'] ) ) : ?>
2531 <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>
2532 <?php endif; ?>
2533 </li>
2534 <?php endforeach; ?>
2535 </ul>
2536 </div>
2537 <?php endif; ?>
2538 </div>
2539
2540 <?php $this->render_analyzer_widget( $analyzer_last_scan, $analyzer_history, $analyzer_categories_def, $analyzer_settings ); ?>
2541
2542 <div class="vigilante-modules-grid">
2543 <h2><?php esc_html_e( 'Security Modules', 'vigilante' ); ?></h2>
2544 <p class="description"><?php esc_html_e( 'Enable or disable security modules. Each module controls a tab with detailed settings.', 'vigilante' ); ?></p>
2545 <div class="vigilante-modules-list">
2546 <?php foreach ( $options['modules'] as $module => $enabled ) :
2547 $label = isset( $module_labels[ $module ] ) ? $module_labels[ $module ] : ucwords( str_replace( '_', ' ', $module ) );
2548 $description = isset( $module_descriptions[ $module ] ) ? $module_descriptions[ $module ] : '';
2549 ?>
2550 <div class="vigilante-module-item <?php echo $enabled ? 'enabled' : 'disabled'; ?>">
2551 <div class="vigilante-module-header">
2552 <span class="vigilante-module-status"></span>
2553 <span class="vigilante-module-name"><?php echo esc_html( $label ); ?></span>
2554 <label class="vigilante-toggle">
2555 <?php
2556 /* translators: %s: Security module name, for example Firewall. */
2557 $toggle_label = sprintf( __( 'Enable %s', 'vigilante' ), $label );
2558 ?>
2559 <input type="checkbox"
2560 name="modules[<?php echo esc_attr( $module ); ?>]"
2561 value="1"
2562 <?php checked( $enabled ); ?>
2563 aria-label="<?php echo esc_attr( $toggle_label ); ?>"
2564 data-module="<?php echo esc_attr( $module ); ?>">
2565 <span class="vigilante-toggle-slider"></span>
2566 </label>
2567 </div>
2568 <?php if ( $description ) : ?>
2569 <p class="vigilante-module-desc"><?php echo esc_html( $description ); ?></p>
2570 <?php endif; ?>
2571 </div>
2572 <?php endforeach; ?>
2573 </div>
2574 </div>
2575
2576 <div class="vigilante-presets-card">
2577 <h2><?php esc_html_e( 'Quick Configuration Presets', 'vigilante' ); ?></h2>
2578 <p><?php esc_html_e( 'Apply a preset to quickly set up recommended settings for standard or maximum security level.', 'vigilante' ); ?></p>
2579 <div class="vigilante-presets-grid">
2580 <?php foreach ( $presets as $preset_id => $preset ) :
2581 $is_active = ( $active_preset === $preset_id );
2582 ?>
2583 <div class="vigilante-preset-card <?php echo $is_active ? 'vigilante-preset-active' : ''; ?>">
2584 <?php if ( $is_active ) : ?>
2585 <span class="vigilante-active-indicator"><?php esc_html_e( 'Active', 'vigilante' ); ?></span>
2586 <?php endif; ?>
2587 <h3><?php echo esc_html( $preset['name'] ); ?></h3>
2588 <p><?php echo esc_html( $preset['description'] ); ?></p>
2589 <button type="button" class="button vigilante-preset-btn <?php echo $is_active ? 'button-primary' : ''; ?>" data-preset="<?php echo esc_attr( $preset_id ); ?>">
2590 <?php esc_html_e( 'Apply Preset', 'vigilante' ); ?>
2591 </button>
2592 </div>
2593 <?php endforeach; ?>
2594
2595 <?php
2596 // Under Attack mode card
2597 $under_attack = new Vigilante_Under_Attack( $this->settings, $this->activity_log );
2598 $ua_active = $under_attack->is_active();
2599 $ua_remaining = $under_attack->get_remaining_time();
2600 $ua_remaining_hours = floor( $ua_remaining / 3600 );
2601 $ua_remaining_mins = floor( ( $ua_remaining % 3600 ) / 60 );
2602 ?>
2603 <div class="vigilante-preset-card vigilante-under-attack-card <?php echo $ua_active ? 'vigilante-under-attack-active' : ''; ?>">
2604 <h3>
2605 <span class="dashicons dashicons-shield"></span>
2606 <?php esc_html_e( 'Under Attack', 'vigilante' ); ?>
2607 </h3>
2608 <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>
2609 <?php if ( $ua_active ) : ?>
2610 <div class="vigilante-ua-countdown" data-expires="<?php echo esc_attr( $under_attack->get_status()['activated_at'] + $under_attack->get_status()['duration'] ); ?>">
2611 <span class="dashicons dashicons-clock"></span>
2612 <span class="vigilante-ua-time">
2613 <?php
2614 printf(
2615 /* translators: 1: Hours, 2: Minutes */
2616 esc_html__( '%1$dh %2$dm remaining', 'vigilante' ),
2617 absint( $ua_remaining_hours ),
2618 absint( $ua_remaining_mins )
2619 );
2620 ?>
2621 </span>
2622 </div>
2623 <button type="button" class="button vigilante-ua-btn vigilante-ua-deactivate">
2624 <?php esc_html_e( 'Deactivate', 'vigilante' ); ?>
2625 </button>
2626 <?php else : ?>
2627 <button type="button" class="button vigilante-ua-btn vigilante-ua-activate">
2628 <?php esc_html_e( 'Activate for 4 hours', 'vigilante' ); ?>
2629 </button>
2630 <?php endif; ?>
2631 </div>
2632 </div>
2633 </div>
2634 </div>
2635 <?php
2636 }
2637
2638 /**
2639 * Render tools tab
2640 */
2641 private function render_tab_tools() {
2642 // Get current settings for notification summary
2643 $email_options = $this->settings->get_section( 'email' );
2644 $login_options = $this->settings->get_section( 'login_security' );
2645 $user_options = $this->settings->get_section( 'user_security' );
2646 $fi_options = $this->settings->get_section( 'file_integrity' );
2647 $alerts_options = $this->settings->get_section( 'audit_alerts' );
2648 $monitoring = $user_options['admin_monitoring'] ?? array();
2649 $registration = $user_options['registration_approval'] ?? array();
2650 $current_admin = get_option( 'admin_email' );
2651 $send_to_admin = ! isset( $email_options['send_to_admin_email'] ) || ! empty( $email_options['send_to_admin_email'] );
2652 $additional_raw = $email_options['additional_recipients'] ?? array();
2653 $additional = is_array( $additional_raw ) ? implode( "\n", $additional_raw ) : trim( $additional_raw );
2654 ?>
2655
2656 <!-- Notification Settings -->
2657 <div id="vigilante-section-tools-notifications" class="vigilante-settings-section vigilante-notification-section">
2658 <h2><?php esc_html_e( 'Notification settings', 'vigilante' ); ?></h2>
2659 <p><?php esc_html_e( 'Configure who receives all administrative email notifications from Vigilant. Individual notifications are enabled in their respective tabs.', 'vigilante' ); ?></p>
2660
2661 <div class="vigilante-notification-layout">
2662
2663 <!-- Left column: Recipients settings -->
2664 <div class="vigilante-notification-settings">
2665 <form class="vigilante-settings-form" data-section="email">
2666
2667 <table class="form-table vigilante-compact-form">
2668 <tr>
2669 <th scope="row"><?php esc_html_e( 'WordPress Admin Email', 'vigilante' ); ?></th>
2670 <td>
2671 <label>
2672 <input type="checkbox" name="email[send_to_admin_email]" value="1" <?php checked( $send_to_admin ); ?>>
2673 <?php
2674 printf(
2675 /* translators: %s: Admin email address */
2676 esc_html__( 'Send to admin email (%s)', 'vigilante' ),
2677 '<code>' . esc_html( $current_admin ) . '</code>'
2678 );
2679 ?>
2680 </label>
2681 </td>
2682 </tr>
2683 <tr>
2684 <th scope="row"><label for="vigilante-f-email-additional-recipients"><?php esc_html_e( 'Additional Recipients', 'vigilante' ); ?></label></th>
2685 <td>
2686 <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>
2687 <p class="description"><?php esc_html_e( 'One email per line.', 'vigilante' ); ?></p>
2688 </td>
2689 </tr>
2690 <tr>
2691 <th scope="row"><?php esc_html_e( 'Plugin Deactivation', 'vigilante' ); ?></th>
2692 <td>
2693 <label>
2694 <input type="checkbox" name="email[send_deactivation_email]" value="1" <?php checked( ! empty( $email_options['send_deactivation_email'] ) ); ?>>
2695 <?php esc_html_e( 'Send email when Vigilant is deactivated', 'vigilante' ); ?>
2696 </label>
2697 </td>
2698 </tr>
2699 </table>
2700
2701 <p class="submit vigilante-notification-submit">
2702 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
2703 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
2704 </button>
2705 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
2706 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
2707 </button>
2708 <span class="vigilante-test-email-result" style="margin-left:8px;vertical-align:middle;"></span>
2709 </p>
2710 <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>
2711
2712 </form>
2713 </div>
2714
2715 <!-- Right column: Active notifications summary -->
2716 <div class="vigilante-notification-summary">
2717 <h4><?php esc_html_e( 'Active notifications', 'vigilante' ); ?></h4>
2718
2719 <table class="widefat striped">
2720 <thead>
2721 <tr>
2722 <th><?php esc_html_e( 'Notification', 'vigilante' ); ?></th>
2723 <th style="width: 1%; white-space: nowrap; text-align: center;"><?php esc_html_e( 'Status', 'vigilante' ); ?></th>
2724 <th style="width: 50px; text-align: center;"></th>
2725 </tr>
2726 </thead>
2727 <tbody>
2728 <?php
2729 $notifications = array(
2730 array(
2731 'label' => __( 'Login lockout', 'vigilante' ),
2732 'active' => ! empty( $login_options['notify_on_lockout'] ),
2733 'tab' => 'login',
2734 ),
2735 array(
2736 'label' => __( 'Administrator login', 'vigilante' ),
2737 'active' => ! empty( $login_options['notify_on_admin_login'] ),
2738 'tab' => 'login',
2739 ),
2740 array(
2741 'label' => __( 'New administrator created', 'vigilante' ),
2742 'active' => ! empty( $monitoring['alert_new_admin'] ),
2743 'tab' => 'users',
2744 ),
2745 array(
2746 'label' => __( 'Administrator email changed', 'vigilante' ),
2747 'active' => ! empty( $monitoring['alert_admin_email_change'] ),
2748 'tab' => 'users',
2749 ),
2750 array(
2751 'label' => __( 'Permission elevation', 'vigilante' ),
2752 'active' => ! empty( $monitoring['alert_permission_elevation'] ),
2753 'tab' => 'users',
2754 ),
2755 array(
2756 'label' => __( 'Admin password changed', 'vigilante' ),
2757 'active' => ! empty( $monitoring['alert_admin_password_change'] ),
2758 'tab' => 'users',
2759 ),
2760 array(
2761 'label' => __( 'Registration pending approval', 'vigilante' ),
2762 'active' => ! empty( $registration['enabled'] ) && ! empty( $registration['notify_admin'] ),
2763 'tab' => 'users',
2764 ),
2765 array(
2766 'label' => __( 'File integrity scan report', 'vigilante' ),
2767 'active' => ( $fi_options['notify_level'] ?? 'disabled' ) !== 'disabled',
2768 'tab' => 'file-integrity',
2769 ),
2770 array(
2771 'label' => __( 'File integrity instant alert', 'vigilante' ),
2772 'active' => ! empty( $fi_options['instant_alert'] ),
2773 'tab' => 'file-integrity',
2774 ),
2775 array(
2776 'label' => __( 'Audit alert: immediate', 'vigilante' ),
2777 'active' => Vigilante_Audit_Alerts::immediate_is_active( $alerts_options ),
2778 'tab' => 'activity-log',
2779 'anchor' => 'vigilante-section-audit-alerts',
2780 ),
2781 array(
2782 'label' => __( 'Audit alert: threshold', 'vigilante' ),
2783 'active' => Vigilante_Audit_Alerts::threshold_is_active( $alerts_options ),
2784 'tab' => 'activity-log',
2785 'anchor' => 'vigilante-section-audit-alerts',
2786 ),
2787 array(
2788 'label' => __( 'Under Attack mode', 'vigilante' ),
2789 'active' => true,
2790 'tab' => '',
2791 'note' => __( 'Always active', 'vigilante' ),
2792 ),
2793 array(
2794 'label' => __( 'Plugin deactivation', 'vigilante' ),
2795 'active' => ! empty( $email_options['send_deactivation_email'] ),
2796 'tab' => 'tools',
2797 ),
2798 );
2799
2800 foreach ( $notifications as $notif ) :
2801 $status_class = $notif['active'] ? 'vigilante-status-active' : 'vigilante-status-inactive';
2802 $status_label = $notif['active'] ? __( 'Active', 'vigilante' ) : __( 'Inactive', 'vigilante' );
2803 if ( ! empty( $notif['note'] ) ) {
2804 $status_label = $notif['note'];
2805 }
2806 ?>
2807 <tr>
2808 <td><?php echo esc_html( $notif['label'] ); ?></td>
2809 <td style="text-align: center; white-space: nowrap;">
2810 <span class="<?php echo esc_attr( $status_class ); ?>"><?php echo esc_html( $status_label ); ?></span>
2811 </td>
2812 <td style="text-align: center;">
2813 <?php if ( ! empty( $notif['tab'] ) ) : ?>
2814 <a href="<?php echo esc_url( admin_url( 'admin.php?page=vigilante&tab=' . $notif['tab'] ) . ( ! empty( $notif['anchor'] ) ? '#' . $notif['anchor'] : '' ) ); ?>" class="button button-small">
2815 <span class="dashicons dashicons-admin-generic" style="font-size: 14px; line-height: 1.8;"></span>
2816 </a>
2817 <?php else : ?>
2818 &mdash;
2819 <?php endif; ?>
2820 </td>
2821 </tr>
2822 <?php endforeach; ?>
2823 </tbody>
2824 </table>
2825 </div>
2826
2827 </div>
2828 </div>
2829
2830 <h2 id="vigilante-section-tools-main" class="vigilante-tools-heading"><?php esc_html_e( 'Tools', 'vigilante' ); ?></h2>
2831
2832 <?php
2833 // Warn that during Under Attack mode the export/import operate against
2834 // the temporary hardened config and any imported changes will be
2835 // reverted when the mode ends.
2836 $ua_status = get_option( Vigilante_Under_Attack::OPTION_NAME, array() );
2837 if ( ! empty( $ua_status['active'] ) ) :
2838 ?>
2839 <div class="vigilante-ua-tools-notice-wrap">
2840 <div class="notice notice-warning inline vigilante-ua-tools-notice">
2841 <p>
2842 <strong><?php esc_html_e( 'Under Attack mode is active.', 'vigilante' ); ?></strong>
2843 <?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' ); ?>
2844 </p>
2845 </div>
2846 </div>
2847 <?php
2848 endif;
2849 ?>
2850
2851 <div class="vigilante-tools-grid">
2852 <div class="vigilante-tool-card">
2853 <h3><?php esc_html_e( 'Export Settings', 'vigilante' ); ?></h3>
2854 <p><?php esc_html_e( 'Download your current security settings as a JSON file.', 'vigilante' ); ?></p>
2855 <button type="button" class="button vigilante-export-settings">
2856 <?php esc_html_e( 'Export Settings', 'vigilante' ); ?>
2857 </button>
2858 </div>
2859
2860 <div class="vigilante-tool-card">
2861 <h3><?php esc_html_e( 'Import Settings', 'vigilante' ); ?></h3>
2862 <p><?php esc_html_e( 'Import settings from a previously exported JSON file.', 'vigilante' ); ?></p>
2863 <input type="file" id="vigilante-import-file" aria-label="<?php esc_attr_e( 'Configuration file to import', 'vigilante' ); ?>" accept=".json" style="display: none;">
2864 <button type="button" class="button vigilante-import-settings">
2865 <?php esc_html_e( 'Import Settings', 'vigilante' ); ?>
2866 </button>
2867 </div>
2868
2869 <div class="vigilante-tool-card">
2870 <h3><?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?></h3>
2871 <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>
2872 <button type="button" class="button vigilante-reset-settings" style="color: #a00;">
2873 <?php esc_html_e( 'Reset All Settings', 'vigilante' ); ?>
2874 </button>
2875 </div>
2876
2877 <div class="vigilante-tool-card">
2878 <h3><?php esc_html_e( 'Download Config Backup', 'vigilante' ); ?></h3>
2879 <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>
2880 <?php if ( $this->shared_files_locked() ) : ?>
2881 <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>
2882 <?php else : ?>
2883 <button type="button" class="button vigilante-create-backup">
2884 <?php esc_html_e( 'Download Backup', 'vigilante' ); ?>
2885 </button>
2886 <?php endif; ?>
2887 </div>
2888
2889 <?php if ( ! $this->shared_files_locked() ) : ?>
2890
2891 <div class="vigilante-tool-card vigilante-tool-card-wide">
2892 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2893 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2894 <button type="button" class="button vigilante-db-backup-toggle">
2895 <?php esc_html_e( 'Download Database Backup', 'vigilante' ); ?>
2896 </button>
2897
2898 <div class="vigilante-db-backup-panel" style="display: none;">
2899 <div class="vigilante-db-tables-loading">
2900 <span class="spinner is-active"></span>
2901 <?php esc_html_e( 'Loading tables...', 'vigilante' ); ?>
2902 </div>
2903
2904 <div class="vigilante-db-tables-content" style="display: none;">
2905 <div class="vigilante-db-tables-controls">
2906 <label>
2907 <input type="checkbox" id="vigilante-db-select-all" checked>
2908 <strong><?php esc_html_e( 'Select / deselect all', 'vigilante' ); ?></strong>
2909 </label>
2910 <span class="vigilante-db-tables-info"></span>
2911 </div>
2912
2913 <div class="vigilante-db-tables-group">
2914 <h4><?php esc_html_e( 'WordPress core tables', 'vigilante' ); ?></h4>
2915 <div class="vigilante-db-tables-list" id="vigilante-db-core-tables"></div>
2916 </div>
2917
2918 <div class="vigilante-db-tables-group" id="vigilante-db-other-group" style="display: none;">
2919 <h4><?php esc_html_e( 'Plugin and custom tables', 'vigilante' ); ?></h4>
2920 <div class="vigilante-db-tables-list" id="vigilante-db-other-tables"></div>
2921 </div>
2922
2923 <div class="vigilante-db-backup-actions">
2924 <button type="button" class="button button-primary vigilante-db-backup-download">
2925 <?php esc_html_e( 'Download Backup (.zip)', 'vigilante' ); ?>
2926 </button>
2927 </div>
2928 </div>
2929 </div>
2930 </div>
2931 <?php else : ?>
2932 <div class="vigilante-tool-card vigilante-tool-card-wide">
2933 <h3><?php esc_html_e( 'Database Backup', 'vigilante' ); ?></h3>
2934 <p><?php esc_html_e( 'Download a backup of your database as a ZIP file. Select which tables to include.', 'vigilante' ); ?></p>
2935 <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>
2936 </div>
2937 <?php endif; ?>
2938 </div>
2939 <?php
2940 }
2941
2942 /**
2943 * Render firewall tab
2944 */
2945 private function render_tab_firewall() {
2946 $is_disabled = $this->render_module_disabled_notice( 'firewall' );
2947 $options = $this->settings->get_section( 'firewall' );
2948 ?>
2949 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="firewall" <?php echo $is_disabled ? 'inert' : ''; ?>>
2950 <div id="vigilante-section-firewall-main" class="vigilante-settings-section">
2951 <h2>
2952 <?php esc_html_e( 'Firewall Protection', 'vigilante' ); ?>
2953 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
2954 </h2>
2955 <p><?php esc_html_e( 'PHP-based request filtering. Analyzes each request before WordPress loads.', 'vigilante' ); ?></p>
2956 <div class="notice notice-info inline" style="margin:10px 0 16px;padding:8px 12px;">
2957 <p style="margin:0;">
2958 <?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' ); ?>
2959 </p>
2960 </div>
2961
2962 <table class="form-table">
2963 <tr>
2964 <th scope="row"><?php esc_html_e( 'Block Bad Query Strings', 'vigilante' ); ?></th>
2965 <td>
2966 <label>
2967 <input type="checkbox" name="firewall[block_bad_query_strings]" value="1" <?php checked( ! empty( $options['block_bad_query_strings'] ) ); ?>>
2968 <?php esc_html_e( 'Block malicious query string patterns', 'vigilante' ); ?>
2969 </label>
2970 </td>
2971 </tr>
2972 <tr>
2973 <th scope="row"><?php esc_html_e( 'SQL Injection Protection', 'vigilante' ); ?></th>
2974 <td>
2975 <label>
2976 <input type="checkbox" name="firewall[block_sql_injection]" value="1" <?php checked( ! empty( $options['block_sql_injection'] ) ); ?>>
2977 <?php esc_html_e( 'Block SQL injection attempts', 'vigilante' ); ?>
2978 </label>
2979 </td>
2980 </tr>
2981 <tr>
2982 <th scope="row"><?php esc_html_e( 'XSS Protection', 'vigilante' ); ?></th>
2983 <td>
2984 <label>
2985 <input type="checkbox" name="firewall[block_xss_attacks]" value="1" <?php checked( ! empty( $options['block_xss_attacks'] ) ); ?>>
2986 <?php esc_html_e( 'Block cross-site scripting attacks', 'vigilante' ); ?>
2987 </label>
2988 </td>
2989 </tr>
2990 <tr>
2991 <th scope="row"><?php esc_html_e( 'File Inclusion Protection', 'vigilante' ); ?></th>
2992 <td>
2993 <label>
2994 <input type="checkbox" name="firewall[block_file_inclusion]" value="1" <?php checked( ! empty( $options['block_file_inclusion'] ) ); ?>>
2995 <?php esc_html_e( 'Block local/remote file inclusion attempts', 'vigilante' ); ?>
2996 </label>
2997 </td>
2998 </tr>
2999 <tr>
3000 <th scope="row"><?php esc_html_e( 'Directory Traversal Protection', 'vigilante' ); ?></th>
3001 <td>
3002 <label>
3003 <input type="checkbox" name="firewall[block_directory_traversal]" value="1" <?php checked( ! empty( $options['block_directory_traversal'] ) ); ?>>
3004 <?php esc_html_e( 'Block path traversal attempts', 'vigilante' ); ?>
3005 </label>
3006 </td>
3007 </tr>
3008 <tr>
3009 <th scope="row"><?php esc_html_e( 'Block Bad Bots', 'vigilante' ); ?></th>
3010 <td>
3011 <label>
3012 <input type="checkbox" name="firewall[block_bad_bots]" value="1" <?php checked( ! empty( $options['block_bad_bots'] ) ); ?>>
3013 <?php esc_html_e( 'Block known malicious bots and scanners', 'vigilante' ); ?>
3014 </label>
3015 </td>
3016 </tr>
3017 </table>
3018
3019 <h3><?php esc_html_e( 'Rate Limiting', 'vigilante' ); ?></h3>
3020 <table class="form-table">
3021 <tr>
3022 <th scope="row"><?php esc_html_e( 'Enable Rate Limiting', 'vigilante' ); ?></th>
3023 <td>
3024 <label>
3025 <input type="checkbox" name="firewall[rate_limiting][enabled]" value="1" <?php checked( ! empty( $options['rate_limiting']['enabled'] ) ); ?>>
3026 <?php esc_html_e( 'Limit requests per IP address', 'vigilante' ); ?>
3027 </label>
3028 </td>
3029 </tr>
3030 <tr>
3031 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-requests-per-minute"><?php esc_html_e( 'Requests per Minute', 'vigilante' ); ?></label></th>
3032 <td>
3033 <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">
3034 <p class="description">
3035 <?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' ); ?>
3036 </p>
3037 </td>
3038 </tr>
3039 <tr>
3040 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-block-duration"><?php esc_html_e( 'Block Duration (seconds)', 'vigilante' ); ?></label></th>
3041 <td>
3042 <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">
3043 </td>
3044 </tr>
3045 <tr>
3046 <th scope="row"><?php esc_html_e( 'Progressive Blocking', 'vigilante' ); ?></th>
3047 <td>
3048 <label>
3049 <input type="checkbox" name="firewall[rate_limiting][progressive]" value="1" <?php checked( ! empty( $options['rate_limiting']['progressive'] ) ); ?>>
3050 <?php esc_html_e( 'Double block duration on each repeat offense', 'vigilante' ); ?>
3051 </label>
3052 <p class="description">
3053 <?php
3054 $base = absint( $options['rate_limiting']['block_duration'] ?? 300 );
3055 printf(
3056 /* translators: 1: First block duration, 2: Second, 3: Third */
3057 esc_html__( 'Example: %1$s → %2$s → %3$s and so on, up to the maximum.', 'vigilante' ),
3058 esc_html( human_time_diff( 0, $base ) ),
3059 esc_html( human_time_diff( 0, $base * 2 ) ),
3060 esc_html( human_time_diff( 0, $base * 4 ) )
3061 );
3062 ?>
3063 </p>
3064 </td>
3065 </tr>
3066 <tr>
3067 <th scope="row"><label for="vigilante-f-firewall-rate-limiting-max-block-duration"><?php esc_html_e( 'Maximum Block Duration', 'vigilante' ); ?></label></th>
3068 <td>
3069 <select id="vigilante-f-firewall-rate-limiting-max-block-duration" name="firewall[rate_limiting][max_block_duration]">
3070 <?php
3071 $max_options = array(
3072 3600 => __( '1 hour', 'vigilante' ),
3073 21600 => __( '6 hours', 'vigilante' ),
3074 43200 => __( '12 hours', 'vigilante' ),
3075 86400 => __( '24 hours', 'vigilante' ),
3076 604800 => __( '7 days', 'vigilante' ),
3077 );
3078 $current_max = absint( $options['rate_limiting']['max_block_duration'] ?? 86400 );
3079 foreach ( $max_options as $val => $label ) :
3080 ?>
3081 <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $current_max, $val ); ?>>
3082 <?php echo esc_html( $label ); ?>
3083 </option>
3084 <?php endforeach; ?>
3085 </select>
3086 <p class="description"><?php esc_html_e( 'Upper limit for progressive blocking.', 'vigilante' ); ?></p>
3087 </td>
3088 </tr>
3089 </table>
3090
3091 <?php
3092 // Currently blocked IPs from rate limiting
3093 $active_blocks = Vigilante_Firewall::get_active_blocks();
3094 if ( ! empty( $active_blocks ) ) :
3095 ?>
3096 <div class="vigilante-settings-section vigilante-lockout-section" style="margin-top:20px;">
3097 <h3><?php esc_html_e( 'Currently Blocked IPs', 'vigilante' ); ?></h3>
3098 <table class="wp-list-table widefat fixed striped" style="max-width:800px;">
3099 <thead>
3100 <tr>
3101 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3102 <th><?php esc_html_e( 'Blocked', 'vigilante' ); ?></th>
3103 <th><?php esc_html_e( 'Expires in', 'vigilante' ); ?></th>
3104 <th><?php esc_html_e( 'Strikes', 'vigilante' ); ?></th>
3105 <th><?php esc_html_e( 'Action', 'vigilante' ); ?></th>
3106 </tr>
3107 </thead>
3108 <tbody>
3109 <?php foreach ( $active_blocks as $blocked_ip => $block_data ) : ?>
3110 <tr>
3111 <td><code><?php echo esc_html( $blocked_ip ); ?></code></td>
3112 <td><?php echo esc_html( human_time_diff( $block_data['blocked_at'] ) . ' ' . __( 'ago', 'vigilante' ) ); ?></td>
3113 <td><?php echo esc_html( human_time_diff( time(), $block_data['expires'] ) ); ?></td>
3114 <td><?php echo esc_html( $block_data['strikes'] ?? 1 ); ?></td>
3115 <td>
3116 <button type="button" class="button button-small vigilante-unblock-firewall-ip"
3117 data-ip="<?php echo esc_attr( $blocked_ip ); ?>">
3118 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3119 </button>
3120 </td>
3121 </tr>
3122 <?php endforeach; ?>
3123 </tbody>
3124 </table>
3125 </div>
3126 <?php endif; ?>
3127
3128 <h3><?php esc_html_e( 'IP Lists', 'vigilante' ); ?></h3>
3129 <p class="description">
3130 <?php
3131 printf(
3132 /* translators: %s: Current visitor IP address */
3133 esc_html__( 'Your current IP address: %s', 'vigilante' ),
3134 '<code>' . esc_html( $this->database->get_client_ip() ) . '</code>'
3135 );
3136 ?>
3137 </p>
3138 <table class="form-table">
3139 <tr>
3140 <th scope="row"><label for="vigilante-f-firewall-trusted-proxy-header"><?php esc_html_e( 'Visitor IP detection', 'vigilante' ); ?></label></th>
3141 <td>
3142 <?php $proxy_header = $options['trusted_proxy_header'] ?? ''; ?>
3143 <select id="vigilante-f-firewall-trusted-proxy-header" name="firewall[trusted_proxy_header]">
3144 <option value="" <?php selected( $proxy_header, '' ); ?>><?php esc_html_e( 'Direct connection, only REMOTE_ADDR (recommended)', 'vigilante' ); ?></option>
3145 <option value="cf-connecting-ip" <?php selected( $proxy_header, 'cf-connecting-ip' ); ?>><?php esc_html_e( 'Behind Cloudflare (CF-Connecting-IP)', 'vigilante' ); ?></option>
3146 <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>
3147 <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>
3148 </select>
3149 <p class="description">
3150 <?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' ); ?>
3151 </p>
3152 </td>
3153 </tr>
3154 <tr>
3155 <th scope="row"><label for="vigilante-f-firewall-ip-whitelist"><?php esc_html_e( 'IP Whitelist', 'vigilante' ); ?></label></th>
3156 <td>
3157 <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>
3158 <p class="description">
3159 <?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' ); ?>
3160 <br>
3161 <?php
3162 printf(
3163 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3164 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' ),
3165 '<code>',
3166 '</code>'
3167 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3168 ?>
3169 </p>
3170 </td>
3171 </tr>
3172 <tr>
3173 <th scope="row"><label for="vigilante-f-firewall-ip-blacklist"><?php esc_html_e( 'IP Blacklist', 'vigilante' ); ?></label></th>
3174 <td>
3175 <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>
3176 <p class="description">
3177 <?php esc_html_e( 'One IP per line. These IPs will be blocked immediately.', 'vigilante' ); ?>
3178 <br>
3179 <?php
3180 printf(
3181 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the IP, CIDR and wildcard examples. */
3182 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' ),
3183 '<code>',
3184 '</code>'
3185 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3186 ?>
3187 </p>
3188 </td>
3189 </tr>
3190 </table>
3191
3192 <h3><?php esc_html_e( 'User-Agent Lists', 'vigilante' ); ?></h3>
3193 <p><?php esc_html_e( 'Partial matching: enter a keyword and any User-Agent containing it will be matched.', 'vigilante' ); ?></p>
3194 <table class="form-table">
3195 <tr>
3196 <th scope="row"><label for="vigilante-f-firewall-ua-whitelist"><?php esc_html_e( 'User-Agent Whitelist', 'vigilante' ); ?></label></th>
3197 <td>
3198 <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>
3199 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will bypass all firewall checks. Example: ManageWP, MainWP, UptimeRobot.', 'vigilante' ); ?></p>
3200 </td>
3201 </tr>
3202 <tr>
3203 <th scope="row"><label for="vigilante-f-firewall-ua-blacklist"><?php esc_html_e( 'User-Agent Blacklist', 'vigilante' ); ?></label></th>
3204 <td>
3205 <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>
3206 <p class="description"><?php esc_html_e( 'One User-Agent per line. These will be blocked immediately.', 'vigilante' ); ?></p>
3207 </td>
3208 </tr>
3209 </table>
3210 </div>
3211
3212 <?php
3213 $vg_shared_locked = $this->shared_files_locked();
3214 // Paint what is actually in force, not this site's unused copy.
3215 $vg_local_options = $options;
3216 $options = $this->get_section_for_display( 'firewall' );
3217 ?>
3218 <?php $this->render_shared_files_notice(); ?>
3219 <div id="vigilante-section-firewall-server" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3220 <h2>
3221 <?php esc_html_e( 'Server Protection', 'vigilante' ); ?>
3222 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3223 </h2>
3224 <p><?php esc_html_e( 'Server-level rules for Apache/LiteSpeed. These rules are processed before PHP.', 'vigilante' ); ?></p>
3225
3226 <table class="form-table">
3227 <tr id="field-disable-directory-browsing">
3228 <th scope="row"><?php esc_html_e( 'Directory Browsing', 'vigilante' ); ?></th>
3229 <td>
3230 <label>
3231 <input type="checkbox" name="firewall[disable_directory_browsing]" value="1" <?php checked( ! empty( $options['disable_directory_browsing'] ) ); ?>>
3232 <?php esc_html_e( 'Disable directory listing (Options -Indexes)', 'vigilante' ); ?>
3233 </label>
3234 </td>
3235 </tr>
3236 <tr>
3237 <th scope="row"><?php esc_html_e( 'Protect wp-config.php', 'vigilante' ); ?></th>
3238 <td>
3239 <label>
3240 <input type="checkbox" name="firewall[protect_wp_config]" value="1" <?php checked( ! empty( $options['protect_wp_config'] ) ); ?>>
3241 <?php esc_html_e( 'Block direct HTTP access to wp-config.php', 'vigilante' ); ?>
3242 </label>
3243 </td>
3244 </tr>
3245 <tr id="field-protect-wp-cron">
3246 <th scope="row"><?php esc_html_e( 'Protect wp-cron.php', 'vigilante' ); ?></th>
3247 <td>
3248 <label>
3249 <input type="checkbox" name="firewall[protect_wp_cron]" value="1" <?php checked( ! empty( $options['protect_wp_cron'] ) ); ?>>
3250 <?php esc_html_e( 'Block direct HTTP access to wp-cron.php (prevents cron-spam DoS abuse)', 'vigilante' ); ?>
3251 </label>
3252 <p class="description"><?php
3253 printf(
3254 /* translators: 1: opening <strong>, 2: closing </strong> */
3255 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' ),
3256 '<strong>',
3257 '</strong>',
3258 '<code>',
3259 '</code>'
3260 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
3261 ?></p>
3262 </td>
3263 </tr>
3264 <tr>
3265 <th scope="row"><?php esc_html_e( 'Protect wp-includes', 'vigilante' ); ?></th>
3266 <td>
3267 <label>
3268 <input type="checkbox" name="firewall[protect_wp_includes]" value="1" <?php checked( ! empty( $options['protect_wp_includes'] ) ); ?>>
3269 <?php esc_html_e( 'Block direct access to PHP files in wp-includes', 'vigilante' ); ?>
3270 </label>
3271 </td>
3272 </tr>
3273 <tr>
3274 <th scope="row"><?php esc_html_e( 'PHP in Uploads', 'vigilante' ); ?></th>
3275 <td>
3276 <label>
3277 <input type="checkbox" name="firewall[protect_uploads_php]" value="1" <?php checked( ! empty( $options['protect_uploads_php'] ) ); ?>>
3278 <?php esc_html_e( 'Block PHP execution in wp-content/uploads', 'vigilante' ); ?>
3279 </label>
3280 </td>
3281 </tr>
3282 <tr>
3283 <th scope="row"><?php esc_html_e( 'Sensitive Files', 'vigilante' ); ?></th>
3284 <td>
3285 <label>
3286 <input type="checkbox" name="firewall[protect_sensitive_files]" value="1" <?php checked( ! empty( $options['protect_sensitive_files'] ) ); ?>>
3287 <?php esc_html_e( 'Block access to .sql, .bak, .log, .ini, readme.html, license.txt, licencia.txt', 'vigilante' ); ?>
3288 </label>
3289 </td>
3290 </tr>
3291 <tr>
3292 <th scope="row"><?php esc_html_e( 'Limit HTTP Methods', 'vigilante' ); ?></th>
3293 <td>
3294 <label>
3295 <input type="checkbox" name="firewall[limit_http_methods]" value="1" <?php checked( ! empty( $options['limit_http_methods'] ) ); ?>>
3296 <?php esc_html_e( 'Allow only GET, POST, HEAD (blocks PUT, DELETE, TRACE, etc.)', 'vigilante' ); ?>
3297 </label>
3298 </td>
3299 </tr>
3300 </table>
3301 </div>
3302 <?php $options = $vg_local_options; ?>
3303
3304 <p class="submit vigilante-submit-buttons">
3305 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3306 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3307 </button>
3308 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3309 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3310 </button>
3311 </p>
3312 </form>
3313 <?php
3314 }
3315
3316 /**
3317 * Render login security tab
3318 */
3319 private function render_tab_login() {
3320 $is_disabled = $this->render_module_disabled_notice( 'login_security' );
3321 $options = $this->settings->get_section( 'login_security' );
3322 $lockouts = $this->database->get_active_lockouts();
3323 ?>
3324 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="login_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
3325 <div id="vigilante-section-login-main" class="vigilante-settings-section">
3326 <h2>
3327 <?php esc_html_e( 'Login Protection', 'vigilante' ); ?>
3328 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3329 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3330 </h2>
3331 <p><?php esc_html_e( 'Brute force protection and WordPress login hardening.', 'vigilante' ); ?></p>
3332
3333 <table class="form-table">
3334 <tr id="field-max-attempts">
3335 <th scope="row"><label for="vigilante-f-login-security-max-attempts"><?php esc_html_e( 'Max Login Attempts', 'vigilante' ); ?></label></th>
3336 <td>
3337 <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">
3338 <p class="description"><?php esc_html_e( 'Number of failed attempts before lockout.', 'vigilante' ); ?></p>
3339 </td>
3340 </tr>
3341 <tr>
3342 <th scope="row"><label for="vigilante-f-login-security-lockout-duration"><?php esc_html_e( 'Lockout Duration', 'vigilante' ); ?></label></th>
3343 <td>
3344 <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">
3345 <?php esc_html_e( 'minutes', 'vigilante' ); ?>
3346 </td>
3347 </tr>
3348 <tr>
3349 <th scope="row"><?php esc_html_e( 'Progressive Lockout', 'vigilante' ); ?></th>
3350 <td>
3351 <label>
3352 <input type="checkbox" name="login_security[lockout_increment]" value="1" <?php checked( ! empty( $options['lockout_increment'] ) ); ?>>
3353 <?php esc_html_e( 'Double lockout duration for repeat offenders', 'vigilante' ); ?>
3354 </label>
3355 </td>
3356 </tr>
3357 <tr>
3358 <th scope="row"><?php esc_html_e( 'Hide Login Errors', 'vigilante' ); ?></th>
3359 <td>
3360 <label>
3361 <input type="checkbox" name="login_security[hide_login_errors]" value="1" <?php checked( ! empty( $options['hide_login_errors'] ) ); ?>>
3362 <?php esc_html_e( 'Show generic error message instead of specific errors', 'vigilante' ); ?>
3363 </label>
3364 </td>
3365 </tr>
3366 <tr>
3367 <th scope="row"><?php esc_html_e( 'Disable Application Passwords', 'vigilante' ); ?></th>
3368 <td>
3369 <label>
3370 <input type="checkbox" name="login_security[disable_application_passwords]" value="1" <?php checked( ! empty( $options['disable_application_passwords'] ) ); ?>>
3371 <?php esc_html_e( 'Disable WordPress application passwords feature', 'vigilante' ); ?>
3372 </label>
3373 </td>
3374 </tr>
3375 </table>
3376
3377 <h3><?php esc_html_e( 'Custom Login URL', 'vigilante' ); ?></h3>
3378 <table class="form-table">
3379 <tr id="field-custom-login-url">
3380 <th scope="row"><?php esc_html_e( 'Login URL Slug', 'vigilante' ); ?></th>
3381 <td>
3382 <code><?php echo esc_url( home_url( '/' ) ); ?></code>
3383 <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' ); ?>">
3384 <p class="description">
3385 <?php esc_html_e( '&#9432; Leave empty to use default wp-login.php. Use only lowercase letters, numbers and hyphens.', 'vigilante' ); ?>
3386 </p>
3387 <div class="vigilante-login-url-preview" <?php echo empty( $options['custom_login_url'] ) ? 'style="display:none;"' : ''; ?>>
3388 <p class="description">
3389 <strong><?php esc_html_e( 'Your login URL:', 'vigilante' ); ?></strong>
3390 <code class="vigilante-login-url-display"><?php echo esc_url( home_url( sanitize_title( $options['custom_login_url'] ?? '' ) . '/' ) ); ?></code>
3391 </p>
3392 <p class="description">
3393 <?php esc_html_e( 'Direct access to wp-login.php and wp-admin will return a 404 error for non-logged users.', 'vigilante' ); ?>
3394 </p>
3395 <p class="description">
3396 <?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' ); ?>
3397 </p>
3398 </div>
3399 </td>
3400 </tr>
3401 </table>
3402
3403 <div class="vigilante-login-url-notify-wrapper <?php echo empty( $options['custom_login_url'] ) ? 'vigilante-login-url-notify-disabled' : ''; ?>">
3404 <table class="form-table">
3405 <tr>
3406 <th scope="row"><?php esc_html_e( 'Notify users', 'vigilante' ); ?></th>
3407 <td>
3408 <label>
3409 <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 ); ?>>
3410 <?php esc_html_e( 'Notify affected users when the login URL changes', 'vigilante' ); ?>
3411 </label>
3412 <div class="vigilante-login-url-send-notification" style="margin-top:12px;">
3413 <button type="button" id="vigilante_notify_login_url" class="button">
3414 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3415 </button>
3416 <span class="vigilante-login-url-notify-status"></span>
3417 <p class="description"><?php esc_html_e( 'Sends the new URL to administrators, editors, authors, and contributors.', 'vigilante' ); ?></p>
3418 </div>
3419 </td>
3420 </tr>
3421 </table>
3422 </div>
3423
3424 <?php $this->render_2fa_settings( $options ); ?>
3425
3426 <h3><?php esc_html_e( 'Notifications', 'vigilante' ); ?></h3>
3427 <table class="form-table">
3428 <tr>
3429 <th scope="row"><?php esc_html_e( 'Notify on Lockout', 'vigilante' ); ?></th>
3430 <td>
3431 <label>
3432 <input type="checkbox" name="login_security[notify_on_lockout]" value="1" <?php checked( ! empty( $options['notify_on_lockout'] ) ); ?>>
3433 <?php esc_html_e( 'Send email when an IP is locked out', 'vigilante' ); ?>
3434 </label>
3435 </td>
3436 </tr>
3437 <tr>
3438 <th scope="row"><?php esc_html_e( 'Notify on Admin Login', 'vigilante' ); ?></th>
3439 <td>
3440 <label>
3441 <input type="checkbox" name="login_security[notify_on_admin_login]" value="1" <?php checked( ! empty( $options['notify_on_admin_login'] ) ); ?>>
3442 <?php esc_html_e( 'Send email when an administrator logs in', 'vigilante' ); ?>
3443 </label>
3444 </td>
3445 </tr>
3446 </table>
3447
3448 <p class="description">
3449 <?php
3450 printf(
3451 /* translators: %s: Link to notification settings */
3452 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
3453 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
3454 );
3455 ?>
3456 </p>
3457 </div>
3458
3459 <p class="submit vigilante-submit-buttons">
3460 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
3461 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
3462 </button>
3463 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
3464 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
3465 </button>
3466 </p>
3467 </form>
3468
3469 <?php $this->render_lockout_info_section( $options, $lockouts ); ?>
3470 <?php
3471 }
3472
3473 /**
3474 * Render lockout information and blocked IPs section
3475 *
3476 * @param array $options Login security options.
3477 * @param array $lockouts Currently locked out IPs.
3478 */
3479 private function render_lockout_info_section( $options, $lockouts ) {
3480 $max_attempts = absint( $options['max_attempts'] ?? 5 );
3481 $lockout_duration = absint( $options['lockout_duration'] ?? 1800 );
3482 $lockout_increment = ! empty( $options['lockout_increment'] );
3483 $max_lockout = absint( $options['max_lockout_duration'] ?? 86400 );
3484 $two_factor = $options['two_factor'] ?? array();
3485 $two_factor_enabled = ! empty( $two_factor['enabled'] );
3486 ?>
3487 <div class="vigilante-settings-section vigilante-lockout-section">
3488 <h2><?php esc_html_e( 'Login Protection Status', 'vigilante' ); ?></h2>
3489
3490 <table class="form-table">
3491 <tr>
3492 <th scope="row"><?php esc_html_e( 'Current settings', 'vigilante' ); ?></th>
3493 <td>
3494 <?php
3495 printf(
3496 /* translators: 1: Maximum login attempts, 2: Lockout duration in minutes */
3497 esc_html__( 'After %1$d failed login attempts, the IP address is blocked for %2$d minutes.', 'vigilante' ),
3498 absint( $max_attempts ),
3499 absint( ceil( $lockout_duration / 60 ) )
3500 );
3501
3502 if ( $lockout_increment ) {
3503 echo '<br>';
3504 printf(
3505 /* translators: %d: Maximum lockout duration in hours */
3506 esc_html__( 'Progressive lockout enabled (max: %d hours).', 'vigilante' ),
3507 absint( ceil( $max_lockout / 3600 ) )
3508 );
3509 }
3510
3511 if ( $two_factor_enabled ) {
3512 echo '<br>';
3513 esc_html_e( 'Failed 2FA codes also count toward the lockout limit.', 'vigilante' );
3514 }
3515 ?>
3516 </td>
3517 </tr>
3518 <tr>
3519 <th scope="row"><?php esc_html_e( 'Blocked IPs', 'vigilante' ); ?></th>
3520 <td>
3521 <?php if ( ! empty( $lockouts ) ) : ?>
3522 <div class="vigilante-paginated-section">
3523 <div class="vigilante-fi-pagination-wrap"></div>
3524 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
3525 <thead>
3526 <tr>
3527 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
3528 <th><?php esc_html_e( 'Attempts', 'vigilante' ); ?></th>
3529 <th><?php esc_html_e( 'Blocked Until', 'vigilante' ); ?></th>
3530 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
3531 </tr>
3532 </thead>
3533 <tbody>
3534 <?php foreach ( $lockouts as $lockout ) :
3535 $lockout_time = strtotime( $lockout->locked_until );
3536 $remaining_seconds = $lockout_time - time();
3537 $remaining_text = $this->format_remaining_time( $remaining_seconds );
3538 ?>
3539 <tr>
3540 <td><code><?php echo esc_html( $lockout->ip_address ); ?></code></td>
3541 <td><?php echo esc_html( $lockout->attempts ); ?></td>
3542 <td>
3543 <?php echo esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $lockout_time ) ); ?>
3544 <br>
3545 <small class="description">
3546 <?php
3547 printf(
3548 /* translators: %s: Remaining time */
3549 esc_html__( '%s remaining', 'vigilante' ),
3550 esc_html( $remaining_text )
3551 );
3552 ?>
3553 </small>
3554 </td>
3555 <td>
3556 <button type="button" class="button button-small vigilante-clear-lockout" data-ip="<?php echo esc_attr( $lockout->ip_address ); ?>">
3557 <?php esc_html_e( 'Unblock', 'vigilante' ); ?>
3558 </button>
3559 </td>
3560 </tr>
3561 <?php endforeach; ?>
3562 </tbody>
3563 </table>
3564 </div>
3565 <p class="description" style="margin-top: 10px;">
3566 <button type="button" class="button vigilante-clear-all-lockouts">
3567 <?php esc_html_e( 'Unblock All IPs', 'vigilante' ); ?>
3568 </button>
3569 <span style="margin-left: 10px;">
3570 <?php
3571 printf(
3572 /* translators: %d: Number of blocked IPs */
3573 esc_html( _n( '%d IP currently blocked', '%d IPs currently blocked', count( $lockouts ), 'vigilante' ) ),
3574 count( $lockouts )
3575 );
3576 ?>
3577 </span>
3578 </p>
3579 <?php else : ?>
3580 <span class="dashicons dashicons-yes-alt" style="color: #00a32a; font-size: 20px; width: 20px; height: 20px; vertical-align: middle;"></span>
3581 <span style="vertical-align: middle; margin-left: 5px;"><?php esc_html_e( 'No IPs are currently blocked. All clear!', 'vigilante' ); ?></span>
3582 <?php endif; ?>
3583 </td>
3584 </tr>
3585 </table>
3586 </div>
3587 <?php
3588 }
3589
3590 /**
3591 * Format remaining lockout time in human readable format
3592 *
3593 * @param int $seconds Remaining seconds.
3594 * @return string Formatted time string.
3595 */
3596 private function format_remaining_time( $seconds ) {
3597 if ( $seconds <= 0 ) {
3598 return __( 'expired', 'vigilante' );
3599 }
3600
3601 if ( $seconds < 60 ) {
3602 return sprintf(
3603 /* translators: %d: Number of seconds */
3604 _n( '%d second', '%d seconds', $seconds, 'vigilante' ),
3605 $seconds
3606 );
3607 }
3608
3609 if ( $seconds < 3600 ) {
3610 $minutes = ceil( $seconds / 60 );
3611 return sprintf(
3612 /* translators: %d: Number of minutes */
3613 _n( '%d minute', '%d minutes', $minutes, 'vigilante' ),
3614 $minutes
3615 );
3616 }
3617
3618 $hours = floor( $seconds / 3600 );
3619 $remaining_minutes = ceil( ( $seconds % 3600 ) / 60 );
3620
3621 if ( $remaining_minutes > 0 ) {
3622 return sprintf(
3623 /* translators: 1: Number of hours, 2: Number of minutes */
3624 __( '%1$d hours %2$d minutes', 'vigilante' ),
3625 $hours,
3626 $remaining_minutes
3627 );
3628 }
3629
3630 return sprintf(
3631 /* translators: %d: Number of hours */
3632 _n( '%d hour', '%d hours', $hours, 'vigilante' ),
3633 $hours
3634 );
3635 }
3636
3637 /**
3638 * Render 2FA settings section
3639 *
3640 * @param array $options Login security options.
3641 */
3642 private function render_2fa_settings( $options ) {
3643 $two_factor = $options['two_factor'] ?? array();
3644 $all_roles = wp_roles()->roles;
3645 $enforced = $two_factor['enforced_roles'] ?? array( 'administrator', 'editor' );
3646 $excluded = $two_factor['excluded_users'] ?? array();
3647 $method = $two_factor['method'] ?? 'email';
3648 $grace_days = $two_factor['grace_period_days'] ?? 3;
3649 ?>
3650 <h3>
3651 <?php esc_html_e( 'Two-Factor Authentication (2FA)', 'vigilante' ); ?>
3652 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
3653 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
3654 </h3>
3655 <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>
3656
3657 <table class="form-table">
3658 <tr>
3659 <th scope="row"><?php esc_html_e( 'Enable 2FA', 'vigilante' ); ?></th>
3660 <td>
3661 <label>
3662 <input type="checkbox" name="login_security[two_factor][enabled]" id="vigilante_2fa_enabled" value="1" <?php checked( ! empty( $two_factor['enabled'] ) ); ?>>
3663 <?php esc_html_e( 'Enable two-factor authentication', 'vigilante' ); ?>
3664 </label>
3665 </td>
3666 </tr>
3667 </table>
3668
3669 <div class="vigilante-2fa-settings-wrapper <?php echo empty( $two_factor['enabled'] ) ? 'vigilante-2fa-settings-disabled' : ''; ?>">
3670 <table class="form-table">
3671 <tr>
3672 <th scope="row"><?php esc_html_e( 'Verification method', 'vigilante' ); ?></th>
3673 <td>
3674 <fieldset class="vigilante-2fa-method-selector">
3675 <label class="vigilante-2fa-method-option <?php echo 'email' === $method ? 'selected' : ''; ?>">
3676 <input type="radio" name="login_security[two_factor][method]" value="email" <?php checked( $method, 'email' ); ?>>
3677 <span class="dashicons dashicons-email"></span>
3678 <span class="method-info">
3679 <strong><?php esc_html_e( 'Email code', 'vigilante' ); ?></strong>
3680 <span><?php esc_html_e( 'Users receive a 6-digit code via email after entering their password.', 'vigilante' ); ?></span>
3681 </span>
3682 </label>
3683 <label class="vigilante-2fa-method-option <?php echo 'totp' === $method ? 'selected' : ''; ?>">
3684 <input type="radio" name="login_security[two_factor][method]" value="totp" <?php checked( $method, 'totp' ); ?>>
3685 <span class="dashicons dashicons-smartphone"></span>
3686 <span class="method-info">
3687 <strong><?php esc_html_e( 'Authenticator app (TOTP)', 'vigilante' ); ?></strong>
3688 <span><?php esc_html_e( 'Users verify with a time-based code from Google Authenticator, Authy, etc.', 'vigilante' ); ?></span>
3689 </span>
3690 </label>
3691 </fieldset>
3692 </td>
3693 </tr>
3694 <tr>
3695 <th scope="row"><?php esc_html_e( 'Enforce for roles', 'vigilante' ); ?></th>
3696 <td>
3697 <div class="vigilante-2fa-roles">
3698 <?php foreach ( $all_roles as $role_slug => $role_data ) :
3699 $user_count = count( get_users( array( 'role' => $role_slug, 'fields' => 'ID' ) ) );
3700 ?>
3701 <label>
3702 <input type="checkbox"
3703 name="login_security[two_factor][enforced_roles][]"
3704 value="<?php echo esc_attr( $role_slug ); ?>"
3705 <?php checked( in_array( $role_slug, $enforced, true ) ); ?>>
3706 <span class="role-name"><?php echo esc_html( translate_user_role( $role_data['name'] ) ); ?></span>
3707 <span class="role-count">(<?php echo esc_html( $user_count ); ?>)</span>
3708 </label>
3709 <?php endforeach; ?>
3710 </div>
3711 <p class="description"><?php esc_html_e( 'Users with these roles will be required to verify with the selected method.', 'vigilante' ); ?></p>
3712 </td>
3713 </tr>
3714 <tr>
3715 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
3716 <td>
3717 <div class="vigilante-2fa-user-search-container">
3718 <div class="vigilante-2fa-user-search">
3719 <span class="search-icon"></span>
3720 <input type="text"
3721 id="vigilante_2fa_user_search"
3722 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
3723 autocomplete="off">
3724 <div class="vigilante-2fa-search-results"></div>
3725 </div>
3726 <div class="vigilante-2fa-excluded-users">
3727 <?php
3728 foreach ( $excluded as $user_id ) :
3729 $user = get_user_by( 'ID', $user_id );
3730 if ( ! $user ) continue;
3731 ?>
3732 <div class="vigilante-2fa-excluded-user" data-user-id="<?php echo esc_attr( $user_id ); ?>">
3733 <span class="user-display"><?php echo esc_html( $user->display_name . ' (' . $user->user_email . ')' ); ?></span>
3734 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
3735 <input type="hidden" name="login_security[two_factor][excluded_users][]" value="<?php echo esc_attr( $user_id ); ?>">
3736 </div>
3737 <?php endforeach; ?>
3738 </div>
3739 </div>
3740 <p class="description"><?php esc_html_e( 'These users will not be required to use 2FA regardless of their role.', 'vigilante' ); ?></p>
3741 </td>
3742 </tr>
3743
3744 <!-- Remember device option -->
3745 <tr>
3746 <th scope="row"><?php esc_html_e( 'Remember device', 'vigilante' ); ?></th>
3747 <td>
3748 <label>
3749 <input type="checkbox" name="login_security[two_factor][allow_remember_device]" value="1" <?php checked( ! empty( $two_factor['allow_remember_device'] ) ); ?>>
3750 <?php esc_html_e( 'Allow users to skip 2FA verification on trusted devices', 'vigilante' ); ?>
3751 </label>
3752 <p class="description">
3753 <?php
3754 printf(
3755 /* translators: %d: Number of days */
3756 esc_html__( 'When enabled, users can check "Remember this device" on the verification screen to skip 2FA for %d days.', 'vigilante' ),
3757 absint( $two_factor['remember_device_days'] ?? 30 )
3758 );
3759 ?>
3760 </p>
3761 </td>
3762 </tr>
3763
3764 <!-- TOTP-specific: Grace period -->
3765 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3766 <th scope="row"><label for="vigilante-f-login-security-two-factor-grace-period-days"><?php esc_html_e( 'Grace period', 'vigilante' ); ?></label></th>
3767 <td>
3768 <input id="vigilante-f-login-security-two-factor-grace-period-days" type="number"
3769 name="login_security[two_factor][grace_period_days]"
3770 value="<?php echo esc_attr( $grace_days ); ?>"
3771 min="0" max="30" class="small-text">
3772 <?php esc_html_e( 'days', 'vigilante' ); ?>
3773 <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>
3774 </td>
3775 </tr>
3776
3777 <!-- Email-specific: Sender name -->
3778 <tr class="vigilante-2fa-email-only" <?php echo 'email' !== $method ? 'style="display:none;"' : ''; ?>>
3779 <th scope="row"><label for="vigilante-f-login-security-two-factor-email-from-name"><?php esc_html_e( 'Email sender name', 'vigilante' ); ?></label></th>
3780 <td>
3781 <input id="vigilante-f-login-security-two-factor-email-from-name" type="text"
3782 name="login_security[two_factor][email_from_name]"
3783 value="<?php echo esc_attr( $two_factor['email_from_name'] ?? '' ); ?>"
3784 class="regular-text vigilante-2fa-email-from"
3785 placeholder="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
3786 <p class="description"><?php esc_html_e( 'Name shown in verification emails. Leave empty to use site name.', 'vigilante' ); ?></p>
3787 </td>
3788 </tr>
3789
3790 <!-- TOTP-specific: Reset users -->
3791 <tr class="vigilante-2fa-totp-only" <?php echo 'totp' !== $method ? 'style="display:none;"' : ''; ?>>
3792 <th scope="row"><?php esc_html_e( 'Reset user TOTP', 'vigilante' ); ?></th>
3793 <td>
3794 <div class="vigilante-totp-reset-container">
3795 <div class="vigilante-2fa-user-search">
3796 <span class="search-icon"></span>
3797 <input type="text"
3798 id="vigilante_totp_reset_search"
3799 placeholder="<?php esc_attr_e( 'Search users with TOTP configured...', 'vigilante' ); ?>"
3800 autocomplete="off">
3801 <div class="vigilante-totp-reset-results"></div>
3802 </div>
3803 <div class="vigilante-totp-reset-selected"></div>
3804 <button type="button" id="vigilante_totp_reset_btn" class="button" style="display:none;">
3805 <?php esc_html_e( 'Reset selected', 'vigilante' ); ?>
3806 </button>
3807 <span class="vigilante-totp-reset-status"></span>
3808 </div>
3809 <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>
3810 </td>
3811 </tr>
3812 </table>
3813
3814 <h3><?php esc_html_e( 'User notification', 'vigilante' ); ?></h3>
3815 <table class="form-table">
3816 <tr>
3817 <th scope="row"><?php esc_html_e( 'Notify on enable', 'vigilante' ); ?></th>
3818 <td>
3819 <label>
3820 <input type="checkbox" name="login_security[two_factor][notify_on_enable]" value="1" <?php checked( $two_factor['notify_on_enable'] ?? true ); ?>>
3821 <?php esc_html_e( 'Send notification email to affected users when 2FA is enabled', 'vigilante' ); ?>
3822 </label>
3823
3824 <div class="vigilante-2fa-notification-options">
3825 <label>
3826 <input type="radio" name="vigilante_2fa_notify_mode" value="all" checked>
3827 <?php esc_html_e( 'Send to all affected users', 'vigilante' ); ?>
3828 </label>
3829 <label>
3830 <input type="radio" name="vigilante_2fa_notify_mode" value="new">
3831 <?php esc_html_e( 'Send only to users not previously notified', 'vigilante' ); ?>
3832 </label>
3833 </div>
3834
3835 <div class="vigilante-2fa-send-notification">
3836 <button type="button" id="vigilante_2fa_send_notification" class="button">
3837 <?php esc_html_e( 'Send notification now', 'vigilante' ); ?>
3838 </button>
3839 <span class="vigilante-2fa-notification-status"></span>
3840 </div>
3841 </td>
3842 </tr>
3843 </table>
3844 </div>
3845 <?php
3846 }
3847
3848 /**
3849 * Render security headers tab
3850 */
3851 private function render_tab_headers() {
3852 $is_disabled = $this->render_module_disabled_notice( 'security_headers' );
3853 // Every setting on this tab ends up in .htaccess, so on a subsite the
3854 // whole tab is somebody else's, values included.
3855 $vg_shared_locked = $this->shared_files_locked();
3856 $options = $this->get_section_for_display( 'security_headers' );
3857 ?>
3858 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="security_headers" <?php echo $is_disabled ? 'inert' : ''; ?>>
3859 <?php $this->render_shared_files_notice(); ?>
3860 <div id="vigilante-section-headers-main" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
3861 <h2>
3862 <?php esc_html_e( 'Security Headers', 'vigilante' ); ?>
3863 <span class="vigilante-method-badge htaccess"><?php esc_html_e( 'HTACCESS', 'vigilante' ); ?></span>
3864 </h2>
3865 <p><?php esc_html_e( 'HTTP headers sent with every response via .htaccess (mod_headers).', 'vigilante' ); ?></p>
3866
3867 <table class="form-table">
3868 <tr>
3869 <th scope="row"><label for="vigilante-f-security-headers-x-frame-options"><?php esc_html_e( 'X-Frame-Options', 'vigilante' ); ?></label></th>
3870 <td>
3871 <select id="vigilante-f-security-headers-x-frame-options" name="security_headers[x_frame_options]">
3872 <option value="" <?php selected( empty( $options['x_frame_options'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
3873 <option value="SAMEORIGIN" <?php selected( $options['x_frame_options'] ?? '', 'SAMEORIGIN' ); ?>>SAMEORIGIN</option>
3874 <option value="DENY" <?php selected( $options['x_frame_options'] ?? '', 'DENY' ); ?>>DENY</option>
3875 </select>
3876 <p class="description"><?php esc_html_e( '&#9432; Prevents clickjacking attacks. Also sets CSP frame-ancestors automatically.', 'vigilante' ); ?></p>
3877 </td>
3878 </tr>
3879 <tr>
3880 <th scope="row"><?php esc_html_e( 'X-Content-Type-Options', 'vigilante' ); ?></th>
3881 <td>
3882 <label>
3883 <input type="checkbox" name="security_headers[x_content_type_options]" value="1" <?php checked( ! empty( $options['x_content_type_options'] ) ); ?>>
3884 <?php esc_html_e( 'Add nosniff header to prevent MIME type sniffing', 'vigilante' ); ?>
3885 </label>
3886 </td>
3887 </tr>
3888 <tr>
3889 <th scope="row"><label for="vigilante-f-security-headers-referrer-policy"><?php esc_html_e( 'Referrer-Policy', 'vigilante' ); ?></label></th>
3890 <td>
3891 <select id="vigilante-f-security-headers-referrer-policy" name="security_headers[referrer_policy]">
3892 <option value="" <?php selected( empty( $options['referrer_policy'] ) ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
3893 <option value="no-referrer" <?php selected( $options['referrer_policy'] ?? '', 'no-referrer' ); ?>>no-referrer</option>
3894 <option value="strict-origin-when-cross-origin" <?php selected( $options['referrer_policy'] ?? '', 'strict-origin-when-cross-origin' ); ?>>strict-origin-when-cross-origin</option>
3895 <option value="same-origin" <?php selected( $options['referrer_policy'] ?? '', 'same-origin' ); ?>>same-origin</option>
3896 </select>
3897 </td>
3898 </tr>
3899 </table>
3900
3901 <h3><?php esc_html_e( 'Content Security Policy', 'vigilante' ); ?></h3>
3902 <table class="form-table">
3903 <tr>
3904 <th scope="row"><?php esc_html_e( 'Enable CSP', 'vigilante' ); ?></th>
3905 <td>
3906 <label>
3907 <input type="checkbox" name="security_headers[csp][enabled]" value="1" <?php checked( ! empty( $options['csp']['enabled'] ) ); ?>>
3908 <?php esc_html_e( 'Enable Content Security Policy', 'vigilante' ); ?>
3909 </label>
3910 </td>
3911 </tr>
3912 <tr>
3913 <th scope="row"><?php esc_html_e( 'Report Only Mode', 'vigilante' ); ?></th>
3914 <td>
3915 <label>
3916 <input type="checkbox" name="security_headers[csp][report_only]" value="1" <?php checked( ! empty( $options['csp']['report_only'] ) ); ?>>
3917 <?php esc_html_e( 'Report violations without blocking (for testing)', 'vigilante' ); ?>
3918 </label>
3919 </td>
3920 </tr>
3921 </table>
3922
3923 <h3><?php esc_html_e( 'HTTPS', 'vigilante' ); ?></h3>
3924 <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>
3925 <table class="form-table">
3926 <tr>
3927 <th scope="row"><?php esc_html_e( 'Redirect HTTP to HTTPS', 'vigilante' ); ?></th>
3928 <td>
3929 <label>
3930 <input type="checkbox" name="security_headers[redirect_http_to_https]" value="1" <?php checked( ! empty( $options['redirect_http_to_https'] ) ); ?>>
3931 <?php esc_html_e( 'Send visitors arriving over HTTP to the HTTPS address', 'vigilante' ); ?>
3932 </label>
3933 <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>
3934 </td>
3935 </tr>
3936 <tr>
3937 <th scope="row"><?php esc_html_e( 'Fix Mixed Content', 'vigilante' ); ?></th>
3938 <td>
3939 <label>
3940 <input type="checkbox" name="security_headers[fix_mixed_content]" value="1" <?php checked( ! empty( $options['fix_mixed_content'] ) ); ?>>
3941 <?php esc_html_e( 'Rewrite this site http:// resources to https://', 'vigilante' ); ?>
3942 </label>
3943 <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>
3944 </td>
3945 </tr>
3946 <tr id="field-upgrade-insecure-requests">
3947 <th scope="row"><?php esc_html_e( 'Upgrade Insecure Requests', 'vigilante' ); ?></th>
3948 <td>
3949 <label>
3950 <input type="checkbox" name="security_headers[upgrade_insecure_requests]" value="1" <?php checked( ! empty( $options['upgrade_insecure_requests'] ) ); ?>>
3951 <?php esc_html_e( 'Ask browsers to upgrade every http:// request to https://', 'vigilante' ); ?>
3952 </label>
3953 <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>
3954 </td>
3955 </tr>
3956 <tr>
3957 <th scope="row"><?php esc_html_e( 'Rewrite Site Address on Activation', 'vigilante' ); ?></th>
3958 <td>
3959 <label>
3960 <input type="checkbox" name="security_headers[force_https]" value="1" <?php checked( ! empty( $options['force_https'] ) ); ?>>
3961 <?php esc_html_e( 'Change the WordPress and site addresses to https:// when the plugin is activated', 'vigilante' ); ?>
3962 </label>
3963 <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>
3964 </td>
3965 </tr>
3966 </table>
3967
3968 <h3><?php esc_html_e( 'HSTS (HTTP Strict Transport Security)', 'vigilante' ); ?></h3>
3969 <?php $vig_home_https = ( 0 === strpos( (string) get_option( 'home' ), 'https://' ) ); ?>
3970 <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>
3971 <?php if ( ! $vig_home_https ) : ?>
3972 <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>
3973 <?php endif; ?>
3974 <table class="form-table">
3975 <tr>
3976 <th scope="row"><?php esc_html_e( 'Enable HSTS', 'vigilante' ); ?></th>
3977 <td>
3978 <?php if ( ! $vig_home_https ) : ?>
3979 <?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. */ ?>
3980 <input type="hidden" name="security_headers[hsts][enabled]" value="<?php echo ! empty( $options['hsts']['enabled'] ) ? '1' : '0'; ?>">
3981 <?php endif; ?>
3982 <label>
3983 <input type="checkbox" name="security_headers[hsts][enabled]" value="1" <?php checked( ! empty( $options['hsts']['enabled'] ) ); ?> <?php disabled( ! $vig_home_https ); ?>>
3984 <?php esc_html_e( 'Send the Strict-Transport-Security header', 'vigilante' ); ?>
3985 </label>
3986 <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>
3987 </td>
3988 </tr>
3989 <tr>
3990 <th scope="row"><label for="vigilante-f-security-headers-hsts-max-age"><?php esc_html_e( 'Max Age', 'vigilante' ); ?></label></th>
3991 <td>
3992 <select id="vigilante-f-security-headers-hsts-max-age" name="security_headers[hsts][max_age]">
3993 <option value="86400" <?php selected( $options['hsts']['max_age'] ?? 31536000, 86400 ); ?>><?php esc_html_e( '1 day (testing)', 'vigilante' ); ?></option>
3994 <option value="2592000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 2592000 ); ?>><?php esc_html_e( '30 days', 'vigilante' ); ?></option>
3995 <option value="31536000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 31536000 ); ?>><?php esc_html_e( '1 year (recommended)', 'vigilante' ); ?></option>
3996 <option value="63072000" <?php selected( $options['hsts']['max_age'] ?? 31536000, 63072000 ); ?>><?php esc_html_e( '2 years', 'vigilante' ); ?></option>
3997 </select>
3998 </td>
3999 </tr>
4000 <tr>
4001 <th scope="row"><?php esc_html_e( 'Include Subdomains', 'vigilante' ); ?></th>
4002 <td>
4003 <label>
4004 <input type="checkbox" name="security_headers[hsts][include_subdomains]" value="1" <?php checked( ! empty( $options['hsts']['include_subdomains'] ) ); ?>>
4005 <?php esc_html_e( 'Apply HSTS to all subdomains', 'vigilante' ); ?>
4006 </label>
4007 </td>
4008 </tr>
4009 </table>
4010
4011 <h3><?php esc_html_e( 'Server Identity', 'vigilante' ); ?></h3>
4012 <p class="description"><?php esc_html_e( 'Hide identifying information that servers expose in responses.', 'vigilante' ); ?></p>
4013 <table class="form-table">
4014 <tr>
4015 <th scope="row"><?php esc_html_e( 'Server Signature', 'vigilante' ); ?></th>
4016 <td>
4017 <label>
4018 <input type="checkbox" name="security_headers[hide_server_signature]" value="1" <?php checked( ! empty( $options['hide_server_signature'] ) ); ?>>
4019 <?php esc_html_e( 'Hide server signature (ServerSignature Off)', 'vigilante' ); ?>
4020 </label>
4021 </td>
4022 </tr>
4023 <tr>
4024 <th scope="row"><?php esc_html_e( 'Remove Fingerprinting Headers', 'vigilante' ); ?></th>
4025 <td>
4026 <label>
4027 <input type="checkbox" name="security_headers[remove_fingerprinting_headers]" value="1" <?php checked( ! empty( $options['remove_fingerprinting_headers'] ) ); ?>>
4028 <?php esc_html_e( 'Remove X-Powered-By and Server headers', 'vigilante' ); ?>
4029 </label>
4030 </td>
4031 </tr>
4032 </table>
4033 </div>
4034
4035 <p class="submit vigilante-submit-buttons">
4036 <?php if ( ! $vg_shared_locked ) : ?>
4037 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4038 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4039 </button>
4040 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4041 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4042 </button>
4043 <?php endif; ?>
4044 <?php /* Testing what the server actually sends is read-only and useful from any site of a network. */ ?>
4045 <button type="button" class="button vigilante-test-headers">
4046 <?php esc_html_e( 'Test Headers', 'vigilante' ); ?>
4047 </button>
4048 </p>
4049 </form>
4050
4051 <div id="vigilante-headers-result"></div>
4052 <?php
4053 }
4054
4055 /**
4056 * Render REST API tab
4057 */
4058 private function render_tab_rest_api() {
4059 $is_disabled = $this->render_module_disabled_notice( 'rest_api_security' );
4060 $options = $this->settings->get_section( 'rest_api_security' );
4061 ?>
4062 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="rest_api_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4063 <div id="vigilante-section-rest-api-main" class="vigilante-settings-section">
4064 <h2>
4065 <?php esc_html_e( 'REST API Security', 'vigilante' ); ?>
4066 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4067 </h2>
4068 <p><?php esc_html_e( 'Control access to WordPress REST API endpoints.', 'vigilante' ); ?></p>
4069
4070 <table class="form-table">
4071 <tr>
4072 <th scope="row"><label for="vigilante-f-rest-api-security-mode"><?php esc_html_e( 'Access Mode', 'vigilante' ); ?></label></th>
4073 <td>
4074 <select id="vigilante-f-rest-api-security-mode" name="rest_api_security[mode]">
4075 <option value="open" <?php selected( $options['mode'] ?? 'selective', 'open' ); ?>><?php esc_html_e( 'Open - Allow all requests', 'vigilante' ); ?></option>
4076 <option value="selective" <?php selected( $options['mode'] ?? 'selective', 'selective' ); ?>><?php esc_html_e( 'Selective - Protect sensitive endpoints', 'vigilante' ); ?></option>
4077 <option value="authenticated_only" <?php selected( $options['mode'] ?? 'selective', 'authenticated_only' ); ?>><?php esc_html_e( 'Authenticated - Require login for all', 'vigilante' ); ?></option>
4078 </select>
4079 <p class="description"><?php esc_html_e( 'Selective mode is recommended.', 'vigilante' ); ?></p>
4080 </td>
4081 </tr>
4082 <tr id="field-block-user-enumeration">
4083 <th scope="row"><?php esc_html_e( 'Block User Enumeration', 'vigilante' ); ?></th>
4084 <td>
4085 <label>
4086 <input type="checkbox" name="rest_api_security[block_user_enumeration]" value="1" <?php checked( ! empty( $options['block_user_enumeration'] ) ); ?>>
4087 <?php esc_html_e( 'Protect /wp/v2/users endpoint for unauthenticated users', 'vigilante' ); ?>
4088 </label>
4089 </td>
4090 </tr>
4091 <tr>
4092 <th scope="row"><?php esc_html_e( 'Disable JSONP', 'vigilante' ); ?></th>
4093 <td>
4094 <label>
4095 <input type="checkbox" name="rest_api_security[disable_jsonp]" value="1" <?php checked( ! empty( $options['disable_jsonp'] ) ); ?>>
4096 <?php esc_html_e( 'Disable JSONP support in REST API', 'vigilante' ); ?>
4097 </label>
4098 </td>
4099 </tr>
4100 </table>
4101 </div>
4102
4103 <p class="submit vigilante-submit-buttons">
4104 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4105 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4106 </button>
4107 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4108 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4109 </button>
4110 </p>
4111 </form>
4112 <?php
4113 }
4114
4115 /**
4116 * Render User Security tab
4117 */
4118 private function render_tab_users() {
4119 $is_disabled = $this->render_module_disabled_notice( 'user_security' );
4120 $options = $this->settings->get_section( 'user_security' );
4121 $monitoring = $options['admin_monitoring'] ?? array();
4122 $registration = $options['registration_approval'] ?? array();
4123 $session_limits = $options['session_limits'] ?? array();
4124 $password_exp = $options['password_expiration'] ?? array();
4125 $email_verify = $options['email_verification'] ?? array();
4126 ?>
4127
4128 <!-- ============================================================
4129 SETTINGS SECTION - Single form for all configuration
4130 ============================================================ -->
4131 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="user_security" <?php echo $is_disabled ? 'inert' : ''; ?>>
4132
4133 <!-- Username & Password Protection -->
4134 <div id="vigilante-section-users-password" class="vigilante-settings-section">
4135 <h2>
4136 <?php esc_html_e( 'Username & password protection', 'vigilante' ); ?>
4137 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4138 </h2>
4139 <p><?php esc_html_e( 'Enforce secure username and password policies.', 'vigilante' ); ?></p>
4140
4141 <table class="form-table">
4142 <tr>
4143 <th scope="row"><?php esc_html_e( 'Block Insecure Usernames', 'vigilante' ); ?></th>
4144 <td>
4145 <label>
4146 <input type="checkbox" name="user_security[block_insecure_usernames]" value="1" <?php checked( ! empty( $options['block_insecure_usernames'] ) ); ?>>
4147 <?php esc_html_e( 'Prevent creation of users with common usernames (admin, administrator, etc.)', 'vigilante' ); ?>
4148 </label>
4149 </td>
4150 </tr>
4151 <?php
4152 $pw_policy = wp_parse_args(
4153 ( isset( $options['password_policy'] ) && is_array( $options['password_policy'] ) ) ? $options['password_policy'] : array(),
4154 array(
4155 'require_uppercase' => false,
4156 'require_lowercase' => false,
4157 'require_number' => false,
4158 'require_special' => false,
4159 'block_common' => true,
4160 'block_username' => true,
4161 'affected_roles' => array(),
4162 )
4163 );
4164 $pw_policy_roles = (array) $pw_policy['affected_roles'];
4165 ?>
4166 <tr>
4167 <th scope="row"><?php esc_html_e( 'Enforce Strong Passwords', 'vigilante' ); ?></th>
4168 <td>
4169 <label>
4170 <input type="checkbox" name="user_security[force_strong_passwords]" value="1" <?php checked( ! empty( $options['force_strong_passwords'] ) ); ?>>
4171 <?php esc_html_e( 'Check passwords against the requirements below when a user sets or changes one', 'vigilante' ); ?>
4172 </label>
4173 </td>
4174 </tr>
4175 <tr>
4176 <th scope="row"><label for="vigilante-f-user-security-min-password-length"><?php esc_html_e( 'Minimum Password Length', 'vigilante' ); ?></label></th>
4177 <td>
4178 <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">
4179 <?php esc_html_e( 'characters', 'vigilante' ); ?>
4180 </td>
4181 </tr>
4182 <tr>
4183 <th scope="row"><?php esc_html_e( 'Password Requirements', 'vigilante' ); ?></th>
4184 <td>
4185 <label style="display:block;margin-bottom:5px;">
4186 <input type="checkbox" name="user_security[password_policy][require_uppercase]" value="1" <?php checked( ! empty( $pw_policy['require_uppercase'] ) ); ?>>
4187 <?php esc_html_e( 'Require an uppercase letter (A-Z)', 'vigilante' ); ?>
4188 </label>
4189 <label style="display:block;margin-bottom:5px;">
4190 <input type="checkbox" name="user_security[password_policy][require_lowercase]" value="1" <?php checked( ! empty( $pw_policy['require_lowercase'] ) ); ?>>
4191 <?php esc_html_e( 'Require a lowercase letter (a-z)', 'vigilante' ); ?>
4192 </label>
4193 <label style="display:block;margin-bottom:5px;">
4194 <input type="checkbox" name="user_security[password_policy][require_number]" value="1" <?php checked( ! empty( $pw_policy['require_number'] ) ); ?>>
4195 <?php esc_html_e( 'Require a number (0-9)', 'vigilante' ); ?>
4196 </label>
4197 <label style="display:block;margin-bottom:5px;">
4198 <input type="checkbox" name="user_security[password_policy][require_special]" value="1" <?php checked( ! empty( $pw_policy['require_special'] ) ); ?>>
4199 <?php esc_html_e( 'Require a special character (!, @, #, ...)', 'vigilante' ); ?>
4200 </label>
4201 <label style="display:block;margin-bottom:5px;">
4202 <input type="checkbox" name="user_security[password_policy][block_common]" value="1" <?php checked( ! empty( $pw_policy['block_common'] ) ); ?>>
4203 <?php esc_html_e( 'Reject well-known common passwords', 'vigilante' ); ?>
4204 </label>
4205 <label style="display:block;margin-bottom:5px;">
4206 <input type="checkbox" name="user_security[password_policy][block_username]" value="1" <?php checked( ! empty( $pw_policy['block_username'] ) ); ?>>
4207 <?php esc_html_e( 'Do not allow the username inside the password', 'vigilante' ); ?>
4208 </label>
4209 <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>
4210 </td>
4211 </tr>
4212 <tr>
4213 <th scope="row"><?php esc_html_e( 'Apply Password Rules To', 'vigilante' ); ?></th>
4214 <td>
4215 <?php foreach ( wp_roles()->get_names() as $role_slug => $role_name ) : ?>
4216 <label style="display:block;margin-bottom:5px;">
4217 <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 ) ); ?>>
4218 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4219 </label>
4220 <?php endforeach; ?>
4221 <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>
4222 </td>
4223 </tr>
4224 <tr id="field-block-author-scanning">
4225 <th scope="row"><?php esc_html_e( 'Block Author Scanning', 'vigilante' ); ?></th>
4226 <td>
4227 <label>
4228 <input type="checkbox" name="user_security[block_author_scanning]" value="1" <?php checked( ! empty( $options['block_author_scanning'] ) ); ?>>
4229 <?php esc_html_e( 'Prevent username discovery via ?author=N URLs', 'vigilante' ); ?>
4230 </label>
4231 </td>
4232 </tr>
4233 <tr>
4234 <th scope="row"><?php esc_html_e( 'Display Name Protection', 'vigilante' ); ?></th>
4235 <td>
4236 <label>
4237 <input type="checkbox" name="user_security[prevent_display_name_login_match]" value="1" <?php checked( ! empty( $options['prevent_display_name_login_match'] ) ); ?>>
4238 <?php esc_html_e( 'Prevent users from saving a display name that matches their login username', 'vigilante' ); ?>
4239 </label>
4240 <p class="description"><?php esc_html_e( 'The display name is publicly visible and should not reveal the login username.', 'vigilante' ); ?></p>
4241 </td>
4242 </tr>
4243 </table>
4244 </div>
4245
4246 <!-- Admin Monitoring -->
4247 <div id="vigilante-section-users-admin-monitoring" class="vigilante-settings-section">
4248 <h2>
4249 <?php esc_html_e( 'Admin monitoring', 'vigilante' ); ?>
4250 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4251 </h2>
4252 <p><?php esc_html_e( 'Receive email alerts when administrator accounts are modified. All events are always logged to the Security Audit.', 'vigilante' ); ?></p>
4253
4254 <table class="form-table">
4255 <tr>
4256 <th scope="row"><?php esc_html_e( 'New Administrator Alert', 'vigilante' ); ?></th>
4257 <td>
4258 <label>
4259 <input type="checkbox" name="user_security[admin_monitoring][alert_new_admin]" value="1" <?php checked( ! empty( $monitoring['alert_new_admin'] ) ); ?>>
4260 <?php esc_html_e( 'Send email alert when a new administrator account is created', 'vigilante' ); ?>
4261 </label>
4262 </td>
4263 </tr>
4264 <tr>
4265 <th scope="row"><?php esc_html_e( 'Admin Email Change Alert', 'vigilante' ); ?></th>
4266 <td>
4267 <label>
4268 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_email_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_email_change'] ) ); ?>>
4269 <?php esc_html_e( 'Send email alert when an administrator email address is changed', 'vigilante' ); ?>
4270 </label>
4271 </td>
4272 </tr>
4273 <tr>
4274 <th scope="row"><?php esc_html_e( 'Permission Elevation Alert', 'vigilante' ); ?></th>
4275 <td>
4276 <label>
4277 <input type="checkbox" name="user_security[admin_monitoring][alert_permission_elevation]" value="1" <?php checked( ! empty( $monitoring['alert_permission_elevation'] ) ); ?>>
4278 <?php esc_html_e( 'Send email alert when a user is elevated to administrator role', 'vigilante' ); ?>
4279 </label>
4280 </td>
4281 </tr>
4282 <tr>
4283 <th scope="row"><?php esc_html_e( 'Admin Password Change Alert', 'vigilante' ); ?></th>
4284 <td>
4285 <label>
4286 <input type="checkbox" name="user_security[admin_monitoring][alert_admin_password_change]" value="1" <?php checked( ! empty( $monitoring['alert_admin_password_change'] ) ); ?>>
4287 <?php esc_html_e( 'Send email alert when an administrator password is changed', 'vigilante' ); ?>
4288 </label>
4289 </td>
4290 </tr>
4291 </table>
4292
4293 <p class="description">
4294 <?php
4295 printf(
4296 /* translators: %s: Link to notification settings */
4297 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
4298 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
4299 );
4300 ?>
4301 </p>
4302 </div>
4303
4304 <!-- Registration Approval -->
4305 <div id="vigilante-section-users-registration" class="vigilante-settings-section">
4306 <h2>
4307 <?php esc_html_e( 'Registration approval', 'vigilante' ); ?>
4308 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4309 </h2>
4310 <p><?php esc_html_e( 'Require manual approval for new user registrations.', 'vigilante' ); ?></p>
4311
4312 <table class="form-table">
4313 <tr>
4314 <th scope="row"><?php esc_html_e( 'Enable Registration Approval', 'vigilante' ); ?></th>
4315 <td>
4316 <label>
4317 <input type="checkbox" name="user_security[registration_approval][enabled]" value="1" <?php checked( ! empty( $registration['enabled'] ) ); ?>>
4318 <?php esc_html_e( 'New users must be approved by an administrator before they can log in', 'vigilante' ); ?>
4319 </label>
4320 </td>
4321 </tr>
4322 <tr>
4323 <th scope="row"><?php esc_html_e( 'Notify Admin', 'vigilante' ); ?></th>
4324 <td>
4325 <label>
4326 <input type="checkbox" name="user_security[registration_approval][notify_admin]" value="1" <?php checked( ! empty( $registration['notify_admin'] ) ); ?>>
4327 <?php esc_html_e( 'Send email notification when a new user registers', 'vigilante' ); ?>
4328 </label>
4329 <p class="description"><?php esc_html_e( 'Disable on high-traffic sites to avoid email overload.', 'vigilante' ); ?></p>
4330 </td>
4331 </tr>
4332 <tr>
4333 <th scope="row"><label for="vigilante-f-user-security-registration-approval-auto-reject-days"><?php esc_html_e( 'Auto-reject After', 'vigilante' ); ?></label></th>
4334 <td>
4335 <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">
4336 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4337 <p class="description"><?php esc_html_e( 'Automatically reject pending registrations after this many days.', 'vigilante' ); ?></p>
4338 </td>
4339 </tr>
4340 </table>
4341 </div>
4342
4343 <!-- Session Limits -->
4344 <div id="vigilante-section-users-sessions" class="vigilante-settings-section">
4345 <h2>
4346 <?php esc_html_e( 'Session limits', 'vigilante' ); ?>
4347 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4348 </h2>
4349 <p><?php esc_html_e( 'Limit the number of simultaneous sessions per user.', 'vigilante' ); ?></p>
4350
4351 <table class="form-table">
4352 <tr>
4353 <th scope="row"><?php esc_html_e( 'Enable Session Limits', 'vigilante' ); ?></th>
4354 <td>
4355 <label>
4356 <input type="checkbox" name="user_security[session_limits][enabled]" value="1" <?php checked( ! empty( $session_limits['enabled'] ) ); ?>>
4357 <?php esc_html_e( 'Limit the number of active sessions per user', 'vigilante' ); ?>
4358 </label>
4359 </td>
4360 </tr>
4361 <tr>
4362 <th scope="row"><label for="vigilante-f-user-security-session-limits-max-sessions"><?php esc_html_e( 'Maximum Sessions', 'vigilante' ); ?></label></th>
4363 <td>
4364 <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">
4365 <?php esc_html_e( 'sessions per user', 'vigilante' ); ?>
4366 </td>
4367 </tr>
4368 <tr>
4369 <th scope="row"><label for="vigilante-f-user-security-session-limits-behavior"><?php esc_html_e( 'When Limit Exceeded', 'vigilante' ); ?></label></th>
4370 <td>
4371 <select id="vigilante-f-user-security-session-limits-behavior" name="user_security[session_limits][behavior]">
4372 <option value="block_new" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'block_new' ); ?>><?php esc_html_e( 'Block new login', 'vigilante' ); ?></option>
4373 <option value="close_oldest" <?php selected( ( $session_limits['behavior'] ?? 'close_oldest' ), 'close_oldest' ); ?>><?php esc_html_e( 'Close oldest session', 'vigilante' ); ?></option>
4374 </select>
4375 <p class="description"><?php esc_html_e( '"Close oldest" is recommended for security - ensures attackers cannot lock out legitimate users.', 'vigilante' ); ?></p>
4376 </td>
4377 </tr>
4378 <tr>
4379 <th scope="row"><?php esc_html_e( 'Exclude Administrators', 'vigilante' ); ?></th>
4380 <td>
4381 <label>
4382 <input type="checkbox" name="user_security[session_limits][exclude_admins]" value="1" <?php checked( ! empty( $session_limits['exclude_admins'] ) ); ?>>
4383 <?php esc_html_e( 'Do not apply session limits to administrators', 'vigilante' ); ?>
4384 </label>
4385 </td>
4386 </tr>
4387 </table>
4388 </div>
4389
4390 <!-- Password Expiration -->
4391 <div id="vigilante-section-users-password-exp" class="vigilante-settings-section">
4392 <h2>
4393 <?php esc_html_e( 'Password expiration', 'vigilante' ); ?>
4394 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4395 </h2>
4396 <p><?php esc_html_e( 'Force users to change their password periodically.', 'vigilante' ); ?></p>
4397
4398 <table class="form-table">
4399 <tr>
4400 <th scope="row"><?php esc_html_e( 'Enable Password Expiration', 'vigilante' ); ?></th>
4401 <td>
4402 <label>
4403 <input type="checkbox" name="user_security[password_expiration][enabled]" value="1" <?php checked( ! empty( $password_exp['enabled'] ) ); ?>>
4404 <?php esc_html_e( 'Force password change after a set number of days', 'vigilante' ); ?>
4405 </label>
4406 </td>
4407 </tr>
4408 <tr>
4409 <th scope="row"><label for="vigilante-f-user-security-password-expiration-expire-days"><?php esc_html_e( 'Expire After', 'vigilante' ); ?></label></th>
4410 <td>
4411 <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">
4412 <?php esc_html_e( 'days', 'vigilante' ); ?>
4413 <p class="description"><?php esc_html_e( 'PCI-DSS recommends 90 days.', 'vigilante' ); ?></p>
4414 </td>
4415 </tr>
4416 <tr>
4417 <th scope="row"><label for="vigilante-f-user-security-password-expiration-warning-days"><?php esc_html_e( 'Warning Period', 'vigilante' ); ?></label></th>
4418 <td>
4419 <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">
4420 <?php esc_html_e( 'days before expiration', 'vigilante' ); ?>
4421 <p class="description"><?php esc_html_e( 'Show warning notice this many days before password expires.', 'vigilante' ); ?></p>
4422 </td>
4423 </tr>
4424 <tr>
4425 <th scope="row"><label for="vigilante-f-user-security-password-expiration-password-history"><?php esc_html_e( 'Password History', 'vigilante' ); ?></label></th>
4426 <td>
4427 <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">
4428 <?php esc_html_e( 'passwords to remember', 'vigilante' ); ?>
4429 <p class="description"><?php esc_html_e( 'Prevent reusing recent passwords. Set to 0 to disable.', 'vigilante' ); ?></p>
4430 </td>
4431 </tr>
4432 <tr>
4433 <th scope="row"><?php esc_html_e( 'Email Reminder', 'vigilante' ); ?></th>
4434 <td>
4435 <label>
4436 <input type="checkbox" name="user_security[password_expiration][send_reminder]" value="1" <?php checked( ! empty( $password_exp['send_reminder'] ) ); ?>>
4437 <?php esc_html_e( 'Send email reminder when password is about to expire', 'vigilante' ); ?>
4438 </label>
4439 <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>
4440 </td>
4441 </tr>
4442 <tr>
4443 <th scope="row"><?php esc_html_e( 'Affected Roles', 'vigilante' ); ?></th>
4444 <td>
4445 <?php
4446 $affected_roles = $password_exp['affected_roles'] ?? array( 'administrator', 'editor' );
4447 $all_roles = wp_roles()->get_names();
4448 foreach ( $all_roles as $role_slug => $role_name ) :
4449 ?>
4450 <label style="display: block; margin-bottom: 5px;">
4451 <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 ) ); ?>>
4452 <?php echo esc_html( translate_user_role( $role_name ) ); ?>
4453 </label>
4454 <?php endforeach; ?>
4455 </td>
4456 </tr>
4457 <tr>
4458 <th scope="row"><?php esc_html_e( 'Exclude specific users', 'vigilante' ); ?></th>
4459 <td>
4460 <?php $pwexp_excluded = $password_exp['excluded_users'] ?? array(); ?>
4461 <div class="vigilante-2fa-user-search-container">
4462 <div class="vigilante-2fa-user-search">
4463 <span class="search-icon"></span>
4464 <input type="text"
4465 id="vigilante_pwexp_user_search"
4466 placeholder="<?php esc_attr_e( 'Search users by name or email...', 'vigilante' ); ?>"
4467 autocomplete="off">
4468 <div class="vigilante-pwexp-search-results"></div>
4469 </div>
4470 <div class="vigilante-pwexp-excluded-users">
4471 <?php
4472 foreach ( $pwexp_excluded as $pwexp_excluded_id ) :
4473 $excluded_user = get_user_by( 'ID', $pwexp_excluded_id );
4474 if ( ! $excluded_user ) {
4475 continue;
4476 }
4477 ?>
4478 <div class="vigilante-pwexp-excluded-user" data-user-id="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4479 <span class="user-display"><?php echo esc_html( $excluded_user->display_name . ' (' . $excluded_user->user_email . ')' ); ?></span>
4480 <button type="button" class="remove-user" aria-label="<?php esc_attr_e( 'Remove', 'vigilante' ); ?>">&times;</button>
4481 <input type="hidden" name="user_security[password_expiration][excluded_users][]" value="<?php echo esc_attr( $pwexp_excluded_id ); ?>">
4482 </div>
4483 <?php endforeach; ?>
4484 </div>
4485 </div>
4486 <p class="description"><?php esc_html_e( 'Listed users will be excluded from password expiration regardless of their role.', 'vigilante' ); ?></p>
4487 </td>
4488 </tr>
4489 </table>
4490 </div>
4491
4492 <!-- Email Verification -->
4493 <div id="vigilante-section-users-email-verify" class="vigilante-settings-section">
4494 <h2>
4495 <?php esc_html_e( 'Email verification', 'vigilante' ); ?>
4496 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
4497 </h2>
4498 <p><?php esc_html_e( 'Require new users to verify their email address before logging in.', 'vigilante' ); ?></p>
4499
4500 <table class="form-table">
4501 <tr>
4502 <th scope="row"><?php esc_html_e( 'Enable Email Verification', 'vigilante' ); ?></th>
4503 <td>
4504 <label>
4505 <input type="checkbox" name="user_security[email_verification][enabled]" value="1" <?php checked( ! empty( $email_verify['enabled'] ) ); ?>>
4506 <?php esc_html_e( 'New users must verify their email before logging in', 'vigilante' ); ?>
4507 </label>
4508 </td>
4509 </tr>
4510 <tr>
4511 <th scope="row"><label for="vigilante-f-user-security-email-verification-token-expiry-hours"><?php esc_html_e( 'Link Expiration', 'vigilante' ); ?></label></th>
4512 <td>
4513 <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">
4514 <?php esc_html_e( 'hours', 'vigilante' ); ?>
4515 </td>
4516 </tr>
4517 <tr>
4518 <th scope="row"><?php esc_html_e( 'Allow Resend', 'vigilante' ); ?></th>
4519 <td>
4520 <label>
4521 <input type="checkbox" name="user_security[email_verification][allow_resend]" value="1" <?php checked( ! empty( $email_verify['allow_resend'] ) ); ?>>
4522 <?php esc_html_e( 'Allow users to request a new verification email', 'vigilante' ); ?>
4523 </label>
4524 </td>
4525 </tr>
4526 <tr>
4527 <th scope="row"><label for="vigilante-f-user-security-email-verification-auto-delete-days"><?php esc_html_e( 'Auto-delete Unverified', 'vigilante' ); ?></label></th>
4528 <td>
4529 <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">
4530 <?php esc_html_e( 'days (0 = never)', 'vigilante' ); ?>
4531 <p class="description"><?php esc_html_e( 'Automatically delete users who never verify their email.', 'vigilante' ); ?></p>
4532 </td>
4533 </tr>
4534 </table>
4535 </div>
4536
4537 <p class="submit vigilante-submit-buttons">
4538 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
4539 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
4540 </button>
4541 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
4542 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
4543 </button>
4544 </p>
4545 </form>
4546
4547 <!-- ============================================================
4548 TOOLS SECTION - Actions and utilities (no save button)
4549 ============================================================ -->
4550 <div class="vigilante-tools-section">
4551 <h2 class="vigilante-tools-header">
4552 <?php esc_html_e( 'User security tools', 'vigilante' ); ?>
4553 </h2>
4554
4555 <!-- Force Password Reset -->
4556 <div class="vigilante-tool-box">
4557 <h3><?php esc_html_e( 'Force password reset', 'vigilante' ); ?></h3>
4558 <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>
4559
4560 <!-- Reset Specific Users -->
4561 <div class="vigilante-password-reset-box">
4562 <h4><?php esc_html_e( 'Reset specific users', 'vigilante' ); ?></h4>
4563
4564 <div class="vigilante-user-search-wrapper">
4565 <input type="text" id="vigilante-password-reset-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username, email, or display name...', 'vigilante' ); ?>">
4566 <div id="vigilante-password-reset-results" class="vigilante-user-search-results" style="display: none;"></div>
4567 </div>
4568
4569 <div id="vigilante-password-reset-selected" class="vigilante-selected-users" style="display: none;">
4570 <strong><?php esc_html_e( 'Selected Users:', 'vigilante' ); ?></strong>
4571 <ul class="vigilante-selected-users-list"></ul>
4572 </div>
4573
4574 <p class="description" style="margin-top: 15px;">
4575 <span class="dashicons dashicons-email-alt" style="color: #2271b1;"></span>
4576 <?php esc_html_e( 'Selected users will receive an email with a password reset link.', 'vigilante' ); ?>
4577 </p>
4578
4579 <p class="submit">
4580 <button type="button" id="vigilante-reset-selected-users" class="button button-primary" disabled>
4581 <?php esc_html_e( 'Force Reset for Selected Users', 'vigilante' ); ?>
4582 </button>
4583 </p>
4584 </div>
4585
4586 <!-- Reset by Role -->
4587 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4588 <h4><?php esc_html_e( 'Reset by role', 'vigilante' ); ?></h4>
4589 <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>
4590
4591 <?php
4592 $wp_roles = wp_roles();
4593 $user_counts = count_users();
4594 $avail_roles = $user_counts['avail_roles'] ?? array();
4595 $current_user = wp_get_current_user();
4596 $current_roles = $current_user->roles;
4597 ?>
4598
4599 <fieldset class="vigilante-role-checkboxes" style="margin-top: 10px;">
4600 <?php foreach ( $wp_roles->roles as $role_slug => $role_data ) :
4601 $count = $avail_roles[ $role_slug ] ?? 0;
4602 if ( 0 === $count ) {
4603 continue;
4604 }
4605 $role_name = translate_user_role( $role_data['name'] );
4606 ?>
4607 <label style="display: block; margin-bottom: 6px;">
4608 <input type="checkbox"
4609 class="vigilante-reset-role-checkbox"
4610 value="<?php echo esc_attr( $role_slug ); ?>"
4611 data-count="<?php echo absint( $count ); ?>">
4612 <?php
4613 printf(
4614 /* translators: 1: Role name, 2: Number of users */
4615 '%1$s <span class="description">(%2$d)</span>',
4616 esc_html( $role_name ),
4617 absint( $count )
4618 );
4619 ?>
4620 <?php if ( in_array( $role_slug, $current_roles, true ) ) : ?>
4621 <em class="description"><?php esc_html_e( '(includes you)', 'vigilante' ); ?></em>
4622 <?php endif; ?>
4623 </label>
4624 <?php endforeach; ?>
4625 </fieldset>
4626
4627 <div id="vigilante-reset-role-summary" style="display: none; margin-top: 10px;">
4628 <p>
4629 <span class="dashicons dashicons-groups" style="color: #2271b1;"></span>
4630 <strong id="vigilante-reset-role-count">0</strong>
4631 <?php esc_html_e( 'user(s) will be affected.', 'vigilante' ); ?>
4632 </p>
4633 </div>
4634
4635 <div class="vigilante-password-reset-options" id="vigilante-reset-role-self-option" style="display: none; margin-top: 10px;">
4636 <label>
4637 <input type="checkbox" id="vigilante-reset-role-include-self" value="1">
4638 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4639 </label>
4640 </div>
4641
4642 <p class="submit">
4643 <button type="button" id="vigilante-reset-by-role" class="button button-primary" disabled>
4644 <?php esc_html_e( 'Force Reset for Selected Roles', 'vigilante' ); ?>
4645 </button>
4646 </p>
4647 </div>
4648
4649 <!-- Reset All Users -->
4650 <div class="vigilante-password-reset-box" style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #ddd;">
4651 <h4><?php esc_html_e( 'Reset all users', 'vigilante' ); ?></h4>
4652
4653 <?php
4654 $total_users = count_users();
4655 $total_count = $total_users['total_users'];
4656 ?>
4657 <p>
4658 <?php
4659 printf(
4660 /* translators: %d: Number of users */
4661 esc_html__( 'This will affect %d user(s).', 'vigilante' ),
4662 absint( $total_count )
4663 );
4664 ?>
4665 </p>
4666
4667 <p class="description" style="color: #d63638;">
4668 <span class="dashicons dashicons-warning"></span>
4669 <?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' ); ?>
4670 </p>
4671
4672 <div class="vigilante-password-reset-options" style="margin-top: 10px;">
4673 <label>
4674 <input type="checkbox" id="vigilante-reset-all-include-self" value="1">
4675 <?php esc_html_e( 'Include myself (your current session will end)', 'vigilante' ); ?>
4676 </label>
4677 </div>
4678
4679 <p class="submit">
4680 <button type="button" id="vigilante-reset-all-users" class="button" style="color: #d63638; border-color: #d63638;">
4681 <?php esc_html_e( 'Force Reset for ALL Users', 'vigilante' ); ?>
4682 </button>
4683 </p>
4684 </div>
4685 </div>
4686
4687 <!-- Pending Registrations -->
4688 <?php
4689 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
4690 $pending_users = $user_security->get_pending_users();
4691 ?>
4692 <div class="vigilante-tool-box vigilante-pending-users-section">
4693 <h3>
4694 <?php esc_html_e( 'Pending registrations', 'vigilante' ); ?>
4695 <?php if ( count( $pending_users ) > 0 ) : ?>
4696 <span class="vigilante-badge vigilante-badge-warning"><?php echo esc_html( count( $pending_users ) ); ?></span>
4697 <?php endif; ?>
4698 </h3>
4699
4700 <?php if ( empty( $registration['enabled'] ) ) : ?>
4701 <p class="description">
4702 <span class="dashicons dashicons-info" style="color: #72aee6;"></span>
4703 <?php esc_html_e( 'Registration approval is disabled. Enable it in the settings above to require manual approval for new users.', 'vigilante' ); ?>
4704 </p>
4705 <?php elseif ( empty( $pending_users ) ) : ?>
4706 <div class="vigilante-no-lockouts">
4707 <span class="dashicons dashicons-yes-alt"></span>
4708 <p><?php esc_html_e( 'No pending registrations.', 'vigilante' ); ?></p>
4709 </div>
4710 <?php else : ?>
4711 <table class="wp-list-table widefat fixed striped vigilante-pending-users-table">
4712 <thead>
4713 <tr>
4714 <th><?php esc_html_e( 'User', 'vigilante' ); ?></th>
4715 <th><?php esc_html_e( 'Email', 'vigilante' ); ?></th>
4716 <th><?php esc_html_e( 'Registered', 'vigilante' ); ?></th>
4717 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4718 </tr>
4719 </thead>
4720 <tbody>
4721 <?php foreach ( $pending_users as $pending_user ) :
4722 $pending_since = get_user_meta( $pending_user->ID, 'vigilante_pending_since', true );
4723 ?>
4724 <tr data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4725 <td>
4726 <?php echo get_avatar( $pending_user->ID, 32 ); ?>
4727 <strong><?php echo esc_html( $pending_user->user_login ); ?></strong>
4728 </td>
4729 <td><?php echo esc_html( $pending_user->user_email ); ?></td>
4730 <td>
4731 <?php
4732 if ( $pending_since ) {
4733 /* translators: %s: Time ago */
4734 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $pending_since ) ) );
4735 } else {
4736 echo esc_html( $pending_user->user_registered );
4737 }
4738 ?>
4739 </td>
4740 <td>
4741 <button type="button" class="button button-small vigilante-approve-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>">
4742 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
4743 </button>
4744 <button type="button" class="button button-small vigilante-reject-user" data-user-id="<?php echo esc_attr( $pending_user->ID ); ?>" style="color: #d63638;">
4745 <?php esc_html_e( 'Reject', 'vigilante' ); ?>
4746 </button>
4747 </td>
4748 </tr>
4749 <?php endforeach; ?>
4750 </tbody>
4751 </table>
4752 <?php endif; ?>
4753 </div>
4754
4755 <!-- Active Sessions Management -->
4756 <div class="vigilante-tool-box vigilante-session-management-section">
4757 <h3><?php esc_html_e( 'Active sessions', 'vigilante' ); ?></h3>
4758 <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>
4759
4760 <!-- Current user sessions -->
4761 <h4><?php esc_html_e( 'Your sessions', 'vigilante' ); ?></h4>
4762 <?php
4763 $current_user_id = get_current_user_id();
4764 $my_sessions = $user_security->get_user_sessions( $current_user_id );
4765 $has_corrupted = $user_security->has_corrupted_sessions( $current_user_id );
4766 $raw_count = $user_security->get_raw_session_count( $current_user_id );
4767 ?>
4768
4769 <?php if ( $has_corrupted && $raw_count > 0 ) : ?>
4770 <div class="notice notice-warning inline" style="margin: 10px 0;">
4771 <p>
4772 <span class="dashicons dashicons-warning" style="color: #dba617;"></span>
4773 <?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' ); ?>
4774 </p>
4775 </div>
4776 <?php endif; ?>
4777
4778 <?php if ( empty( $my_sessions ) ) : ?>
4779 <p class="description"><?php esc_html_e( 'No active sessions found.', 'vigilante' ); ?></p>
4780 <?php if ( $has_corrupted ) : ?>
4781 <p style="margin-top: 10px;">
4782 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
4783 <?php esc_html_e( 'Clean Up Corrupted Sessions', 'vigilante' ); ?>
4784 </button>
4785 </p>
4786 <?php endif; ?>
4787 <?php else : ?>
4788 <div class="vigilante-paginated-section">
4789 <div class="vigilante-fi-pagination-wrap"></div>
4790 <table class="wp-list-table widefat fixed striped vigilante-sessions-table vigilante-fi-paginated">
4791 <thead>
4792 <tr>
4793 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
4794 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4795 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
4796 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4797 </tr>
4798 </thead>
4799 <tbody>
4800 <?php foreach ( $my_sessions as $session ) : ?>
4801 <tr data-token="<?php echo esc_attr( $session['token_hash'] ); ?>">
4802 <td><?php echo esc_html( $session['browser'] ); ?></td>
4803 <td><code><?php echo esc_html( $session['ip'] ); ?></code></td>
4804 <td>
4805 <?php
4806 if ( $session['login'] ) {
4807 /* translators: %s: Time ago */
4808 printf( esc_html__( '%s ago', 'vigilante' ), esc_html( human_time_diff( $session['login'] ) ) );
4809 } else {
4810 esc_html_e( 'Unknown', 'vigilante' );
4811 }
4812 ?>
4813 </td>
4814 <td>
4815 <?php if ( ! $session['is_current'] ) : ?>
4816 <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'] ); ?>">
4817 <?php esc_html_e( 'Revoke', 'vigilante' ); ?>
4818 </button>
4819 <?php else : ?>
4820 <span class="description"><?php esc_html_e( 'Current session', 'vigilante' ); ?></span>
4821 <?php endif; ?>
4822 </td>
4823 </tr>
4824 <?php endforeach; ?>
4825 </tbody>
4826 </table>
4827 </div>
4828
4829 <?php if ( count( $my_sessions ) > 1 || $has_corrupted ) : ?>
4830 <p style="margin-top: 10px;">
4831 <button type="button" class="button vigilante-revoke-other-sessions" data-user-id="<?php echo esc_attr( $current_user_id ); ?>">
4832 <?php esc_html_e( 'Revoke All Other Sessions', 'vigilante' ); ?>
4833 </button>
4834 </p>
4835 <?php endif; ?>
4836 <?php endif; ?>
4837
4838 <!-- Search user sessions (admin only) -->
4839 <h4 style="margin-top: 30px;"><?php esc_html_e( 'Manage user sessions', 'vigilante' ); ?></h4>
4840 <p class="description"><?php esc_html_e( 'Search for a user to view and manage their sessions.', 'vigilante' ); ?></p>
4841
4842 <div class="vigilante-user-search-wrapper" style="margin-top: 10px;">
4843 <input type="text" id="vigilante-session-user-search" class="regular-text" placeholder="<?php esc_attr_e( 'Search by username or email...', 'vigilante' ); ?>">
4844 <div id="vigilante-session-search-results" class="vigilante-user-search-results" style="display: none;"></div>
4845 </div>
4846
4847 <div id="vigilante-user-sessions-container" style="display: none; margin-top: 20px;">
4848 <h4 id="vigilante-sessions-user-name"></h4>
4849 <table class="wp-list-table widefat fixed striped vigilante-sessions-table">
4850 <thead>
4851 <tr>
4852 <th><?php esc_html_e( 'Browser', 'vigilante' ); ?></th>
4853 <th><?php esc_html_e( 'IP Address', 'vigilante' ); ?></th>
4854 <th><?php esc_html_e( 'Login Time', 'vigilante' ); ?></th>
4855 <th><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
4856 </tr>
4857 </thead>
4858 <tbody id="vigilante-user-sessions-list">
4859 </tbody>
4860 </table>
4861 <p style="margin-top: 10px;">
4862 <button type="button" class="button vigilante-revoke-all-user-sessions" style="color: #d63638;">
4863 <?php esc_html_e( 'Revoke All Sessions', 'vigilante' ); ?>
4864 </button>
4865 </p>
4866 </div>
4867 </div>
4868 </div>
4869 <?php
4870 }
4871
4872 /**
4873 * Render WordPress Hardening tab
4874 */
4875 private function render_tab_wp_hardening() {
4876 $is_disabled = $this->render_module_disabled_notice( 'wp_hardening' );
4877 $options = $this->settings->get_section( 'wp_hardening' );
4878 ?>
4879 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="wp_hardening" <?php echo $is_disabled ? 'inert' : ''; ?>>
4880 <!-- Database Hardening (outside form save flow - uses its own AJAX action) -->
4881 <?php $vg_shared_locked = $this->shared_files_locked(); ?>
4882 <?php $this->render_shared_files_notice(); ?>
4883 <div id="vigilante-section-hardening-database" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4884 <h2>
4885 <?php esc_html_e( 'Database Hardening', 'vigilante' ); ?>
4886 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
4887 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
4888 </h2>
4889 <p><?php esc_html_e( 'Change the database table prefix to prevent SQL injection attacks that target default WordPress tables.', 'vigilante' ); ?></p>
4890
4891 <?php
4892 $db_prefix = new Vigilante_Database_Prefix();
4893 $current_prefix = $db_prefix->get_current_prefix();
4894 $is_default = $db_prefix->is_default_prefix();
4895 ?>
4896
4897 <?php if ( is_multisite() && ! $vg_shared_locked ) : ?>
4898 <div class="notice notice-warning inline" style="margin:10px 0 16px;padding:8px 12px;">
4899 <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>
4900 </div>
4901 <?php endif; ?>
4902
4903 <table class="form-table">
4904 <tr>
4905 <th scope="row"><?php esc_html_e( 'Current prefix', 'vigilante' ); ?></th>
4906 <td>
4907 <code class="vigilante-db-current-prefix"><?php echo esc_html( $current_prefix ); ?></code>
4908 <?php if ( $is_default ) : ?>
4909 <span class="vigilante-inline-warning">
4910 <span class="dashicons dashicons-warning"></span>
4911 <?php esc_html_e( 'Default prefix detected. Changing it adds a layer of protection against automated SQL injection attacks.', 'vigilante' ); ?>
4912 </span>
4913 <?php else : ?>
4914 <span class="vigilante-inline-ok">
4915 <span class="dashicons dashicons-yes-alt"></span>
4916 <?php esc_html_e( 'Custom prefix in use.', 'vigilante' ); ?>
4917 </span>
4918 <?php endif; ?>
4919 </td>
4920 </tr>
4921 <tr>
4922 <th scope="row"><?php esc_html_e( 'New prefix', 'vigilante' ); ?></th>
4923 <td>
4924 <div class="vigilante-db-prefix-row">
4925 <code class="vigilante-db-new-prefix" id="vigilante-new-prefix"><?php echo esc_html( $db_prefix->generate_prefix() ); ?></code>
4926 <button type="button" class="button button-small vigilante-db-regenerate-prefix" title="<?php esc_attr_e( 'Generate new prefix', 'vigilante' ); ?>">
4927 <span class="dashicons dashicons-update"></span>
4928 </button>
4929 </div>
4930 </td>
4931 </tr>
4932 <tr>
4933 <th scope="row"></th>
4934 <td>
4935 <div class="vigilante-db-prefix-confirm">
4936 <label>
4937 <input type="checkbox" id="vigilante-prefix-backup-confirm">
4938 <?php esc_html_e( 'I understand this operation is irreversible and I have a current database backup', 'vigilante' ); ?>
4939 </label>
4940 <p class="description">
4941 <?php
4942 printf(
4943 /* translators: %s: Link to tools tab */
4944 esc_html__( 'Need a backup? %s first.', 'vigilante' ),
4945 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Download a database backup', 'vigilante' ) . '</a>'
4946 );
4947 ?>
4948 </p>
4949 </div>
4950 <button type="button" class="button button-primary vigilante-db-change-prefix" disabled data-original-text="<?php esc_attr_e( 'Change Database Prefix', 'vigilante' ); ?>">
4951 <?php esc_html_e( 'Change Database Prefix', 'vigilante' ); ?>
4952 </button>
4953 </td>
4954 </tr>
4955 </table>
4956 </div>
4957
4958 <!-- wp-config Security -->
4959 <?php
4960 $vg_shared_locked = $this->shared_files_locked();
4961 // Paint what is actually in force, not this site's unused copy.
4962 $vg_local_options = $options;
4963 $options = $this->get_section_for_display( 'wp_hardening' );
4964 ?>
4965 <?php $this->render_shared_files_notice(); ?>
4966 <div id="vigilante-section-hardening-wpconfig" class="vigilante-settings-section <?php echo $vg_shared_locked ? 'vigilante-form-disabled' : ''; ?>" <?php echo $vg_shared_locked ? 'inert' : ''; ?>>
4967 <h2>
4968 <?php esc_html_e( 'wp-config.php Security', 'vigilante' ); ?>
4969 <span class="vigilante-method-badge config"><?php esc_html_e( 'WP-CONFIG', 'vigilante' ); ?></span>
4970 </h2>
4971 <p><?php esc_html_e( 'Security constants added directly to wp-config.php file.', 'vigilante' ); ?></p>
4972
4973 <table class="form-table">
4974 <tr>
4975 <th scope="row"><?php esc_html_e( 'Disable File Editor', 'vigilante' ); ?></th>
4976 <td>
4977 <label>
4978 <input type="checkbox" name="wp_hardening[disallow_file_edit]" value="1" <?php checked( ! empty( $options['disallow_file_edit'] ) ); ?>>
4979 <?php esc_html_e( 'Disable plugin and theme editor in admin (DISALLOW_FILE_EDIT)', 'vigilante' ); ?>
4980 </label>
4981 </td>
4982 </tr>
4983 <tr>
4984 <th scope="row"><?php esc_html_e( 'Disable File Modifications', 'vigilante' ); ?></th>
4985 <td>
4986 <label>
4987 <input type="checkbox" name="wp_hardening[disallow_file_mods]" value="1" <?php checked( ! empty( $options['disallow_file_mods'] ) ); ?>>
4988 <?php esc_html_e( 'Disable all file modifications including updates (DISALLOW_FILE_MODS)', 'vigilante' ); ?>
4989 </label>
4990 <p class="description"><?php esc_html_e( '&#9888; Warning: This prevents automatic updates.', 'vigilante' ); ?></p>
4991 </td>
4992 </tr>
4993 <tr id="field-force-ssl-admin">
4994 <th scope="row"><?php esc_html_e( 'Force SSL Admin', 'vigilante' ); ?></th>
4995 <td>
4996 <label>
4997 <input type="checkbox" name="wp_hardening[force_ssl_admin]" value="1" <?php checked( ! empty( $options['force_ssl_admin'] ) ); ?>>
4998 <?php esc_html_e( 'Force HTTPS for admin area (FORCE_SSL_ADMIN)', 'vigilante' ); ?>
4999 </label>
5000 <p class="description"><?php esc_html_e( '&#9888; Warning: Only enable if your site fully supports HTTPS.', 'vigilante' ); ?></p>
5001 </td>
5002 </tr>
5003 <tr id="field-wp-debug">
5004 <th scope="row"><?php esc_html_e( 'Hide PHP errors from visitors', 'vigilante' ); ?></th>
5005 <td>
5006 <label>
5007 <input type="checkbox" name="wp_hardening[wp_debug]" value="1" <?php checked( ! empty( $options['wp_debug'] ) ); ?>>
5008 <?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' ); ?>
5009 </label>
5010 </td>
5011 </tr>
5012 <tr id="field-disable-wp-cron">
5013 <th scope="row"><?php esc_html_e( 'Disable WP Cron', 'vigilante' ); ?></th>
5014 <td>
5015 <label>
5016 <input type="checkbox" name="wp_hardening[disable_wp_cron]" value="1" <?php checked( ! empty( $options['disable_wp_cron'] ) ); ?>>
5017 <?php esc_html_e( 'Disable WordPress\'s page-view cron trigger (DISABLE_WP_CRON)', 'vigilante' ); ?>
5018 </label>
5019 <p class="description"><?php
5020 printf(
5021 /* translators: 1: opening <strong>, 2: closing </strong>, 3: opening <code>, 4: closing </code> */
5022 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' ),
5023 '<strong>',
5024 '</strong>',
5025 '<code>',
5026 '</code>'
5027 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5028 ?></p>
5029 </td>
5030 </tr>
5031 </table>
5032 </div>
5033 <?php $options = $vg_local_options; ?>
5034
5035 <!-- Comment Security -->
5036 <div id="vigilante-section-hardening-xmlrpc" class="vigilante-settings-section">
5037 <h2>
5038 <?php esc_html_e( 'XML-RPC', 'vigilante' ); ?>
5039 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5040 </h2>
5041 <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>
5042
5043 <table class="form-table">
5044 <tr id="field-disable-xmlrpc">
5045 <th scope="row"><label for="vigilante-f-wp-hardening-xmlrpc-mode"><?php esc_html_e( 'XML-RPC access', 'vigilante' ); ?></label></th>
5046 <td>
5047 <?php $vig_xmlrpc_mode = Vigilante_Comment_Security::resolve_xmlrpc_mode( $this->settings ); ?>
5048 <select id="vigilante-f-wp-hardening-xmlrpc-mode" name="wp_hardening[xmlrpc_mode]">
5049 <option value="none" <?php selected( $vig_xmlrpc_mode, 'none' ); ?>>
5050 <?php esc_html_e( 'Leave XML-RPC enabled', 'vigilante' ); ?>
5051 </option>
5052 <option value="pingback" <?php selected( $vig_xmlrpc_mode, 'pingback' ); ?>>
5053 <?php esc_html_e( 'Block the pingback methods only', 'vigilante' ); ?>
5054 </option>
5055 <option value="full" <?php selected( $vig_xmlrpc_mode, 'full' ); ?>>
5056 <?php esc_html_e( 'Disable XML-RPC completely (recommended)', 'vigilante' ); ?>
5057 </option>
5058 </select>
5059 <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>
5060 </td>
5061 </tr>
5062 </table>
5063 </div>
5064
5065 <div id="vigilante-section-hardening-comments" class="vigilante-settings-section">
5066 <h2>
5067 <?php esc_html_e( 'Comment Security', 'vigilante' ); ?>
5068 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5069 <span class="vigilante-method-badge settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></span>
5070 </h2>
5071 <p><?php esc_html_e( 'Comment protection using WordPress settings and PHP hooks.', 'vigilante' ); ?></p>
5072
5073 <table class="form-table">
5074 <tr>
5075 <th scope="row"><?php esc_html_e( 'Disable Pingbacks', 'vigilante' ); ?></th>
5076 <td>
5077 <label>
5078 <input type="checkbox" name="wp_hardening[disable_pingbacks]" value="1" <?php checked( ! empty( $options['disable_pingbacks'] ) ); ?>>
5079 <?php esc_html_e( 'Disable pingbacks (commonly exploited for DDoS)', 'vigilante' ); ?>
5080 </label>
5081 </td>
5082 </tr>
5083 <tr>
5084 <th scope="row"><?php esc_html_e( 'Disable Trackbacks', 'vigilante' ); ?></th>
5085 <td>
5086 <label>
5087 <input type="checkbox" name="wp_hardening[disable_trackbacks]" value="1" <?php checked( ! empty( $options['disable_trackbacks'] ) ); ?>>
5088 <?php esc_html_e( 'Disable trackbacks (rarely used legitimately)', 'vigilante' ); ?>
5089 </label>
5090 </td>
5091 </tr>
5092 <tr>
5093 <th scope="row"><?php esc_html_e( 'Require Moderation', 'vigilante' ); ?></th>
5094 <td>
5095 <label>
5096 <input type="checkbox" name="wp_hardening[require_comment_moderation]" value="1" <?php checked( ! empty( $options['require_comment_moderation'] ) ); ?>>
5097 <?php esc_html_e( 'All comments must be manually approved', 'vigilante' ); ?>
5098 </label>
5099 </td>
5100 </tr>
5101 <tr>
5102 <th scope="row"><?php esc_html_e( 'Close Old Comments', 'vigilante' ); ?></th>
5103 <td>
5104 <label>
5105 <input type="checkbox" name="wp_hardening[close_old_comments]" value="1" <?php checked( ! empty( $options['close_old_comments'] ) ); ?>>
5106 <?php esc_html_e( 'Automatically close comments on old posts after', 'vigilante' ); ?>
5107 </label>
5108 <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">
5109 <label for="vigilante-f-wp-hardening-close-comments-after-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5110 </td>
5111 </tr>
5112 <tr>
5113 <th scope="row"><?php esc_html_e( 'Honeypot Protection', 'vigilante' ); ?></th>
5114 <td>
5115 <label>
5116 <input type="checkbox" name="wp_hardening[honeypot_comments]" value="1" <?php checked( ! empty( $options['honeypot_comments'] ) ); ?>>
5117 <?php esc_html_e( 'Add hidden honeypot field to catch bots', 'vigilante' ); ?>
5118 </label>
5119 </td>
5120 </tr>
5121 </table>
5122 </div>
5123
5124 <!-- Head Cleaner -->
5125 <div id="vigilante-section-hardening-headers" class="vigilante-settings-section">
5126 <h2>
5127 <?php esc_html_e( 'Header Cleanup', 'vigilante' ); ?>
5128 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5129 </h2>
5130 <p><?php esc_html_e( 'Remove meta tags from HTML head.', 'vigilante' ); ?></p>
5131
5132 <table class="form-table">
5133 <tr>
5134 <th scope="row"><?php esc_html_e( 'Remove Generator', 'vigilante' ); ?></th>
5135 <td>
5136 <label>
5137 <input type="checkbox" name="wp_hardening[remove_wp_generator]" value="1" <?php checked( ! empty( $options['remove_wp_generator'] ) ); ?>>
5138 <?php esc_html_e( 'Remove WordPress version from HTML head', 'vigilante' ); ?>
5139 </label>
5140 </td>
5141 </tr>
5142 <tr id="field-remove-wp-version-assets">
5143 <th scope="row"><?php esc_html_e( 'Remove version from assets', 'vigilante' ); ?></th>
5144 <td>
5145 <label>
5146 <input type="checkbox" name="wp_hardening[remove_wp_version_assets]" value="1" <?php checked( ! empty( $options['remove_wp_version_assets'] ) ); ?>>
5147 <?php esc_html_e( 'Remove WordPress version from script/style URLs (?ver=)', 'vigilante' ); ?>
5148 </label>
5149 <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>
5150 </td>
5151 </tr>
5152 <tr>
5153 <th scope="row"><?php esc_html_e( 'Remove RSD Link', 'vigilante' ); ?></th>
5154 <td>
5155 <label>
5156 <input type="checkbox" name="wp_hardening[remove_rsd_link]" value="1" <?php checked( ! empty( $options['remove_rsd_link'] ) ); ?>>
5157 <?php esc_html_e( 'Remove Really Simple Discovery link', 'vigilante' ); ?>
5158 </label>
5159 </td>
5160 </tr>
5161 <tr>
5162 <th scope="row"><?php esc_html_e( 'Remove WLW Manifest', 'vigilante' ); ?></th>
5163 <td>
5164 <label>
5165 <input type="checkbox" name="wp_hardening[remove_wlw_manifest]" value="1" <?php checked( ! empty( $options['remove_wlw_manifest'] ) ); ?>>
5166 <?php esc_html_e( 'Remove Windows Live Writer manifest link', 'vigilante' ); ?>
5167 </label>
5168 </td>
5169 </tr>
5170 <tr>
5171 <th scope="row"><?php esc_html_e( 'Remove Shortlink', 'vigilante' ); ?></th>
5172 <td>
5173 <label>
5174 <input type="checkbox" name="wp_hardening[remove_shortlink]" value="1" <?php checked( ! empty( $options['remove_shortlink'] ) ); ?>>
5175 <?php esc_html_e( 'Remove shortlink tag from header', 'vigilante' ); ?>
5176 </label>
5177 </td>
5178 </tr>
5179 <tr>
5180 <th scope="row"><?php esc_html_e( 'Remove REST API Link', 'vigilante' ); ?></th>
5181 <td>
5182 <label>
5183 <input type="checkbox" name="wp_hardening[remove_rest_api_link]" value="1" <?php checked( ! empty( $options['remove_rest_api_link'] ) ); ?>>
5184 <?php esc_html_e( 'Remove REST API discovery link from header', 'vigilante' ); ?>
5185 </label>
5186 <p class="description"><?php esc_html_e( '&#9888; Notice: Some plugins may need this link.', 'vigilante' ); ?></p>
5187 </td>
5188 </tr>
5189 </table>
5190 </div>
5191
5192 <!-- Feed Manager -->
5193 <div id="vigilante-section-hardening-rss" class="vigilante-settings-section">
5194 <h2>
5195 <?php esc_html_e( 'RSS Feed Settings', 'vigilante' ); ?>
5196 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5197 </h2>
5198 <p><?php esc_html_e( 'Control RSS/Atom feeds.', 'vigilante' ); ?></p>
5199
5200 <table class="form-table">
5201 <tr>
5202 <th scope="row"><?php esc_html_e( 'Disable Feeds', 'vigilante' ); ?></th>
5203 <td>
5204 <label>
5205 <input type="checkbox" name="wp_hardening[disable_feeds]" value="1" <?php checked( ! empty( $options['disable_feeds'] ) ); ?>>
5206 <?php esc_html_e( 'Completely disable RSS/Atom feeds', 'vigilante' ); ?>
5207 </label>
5208 </td>
5209 </tr>
5210 <tr>
5211 <th scope="row"><?php esc_html_e( 'Disable If No Content', 'vigilante' ); ?></th>
5212 <td>
5213 <label>
5214 <input type="checkbox" name="wp_hardening[disable_if_no_content]" value="1" <?php checked( ! empty( $options['disable_if_no_content'] ) ); ?>>
5215 <?php esc_html_e( 'Only disable feeds if site has no published posts', 'vigilante' ); ?>
5216 </label>
5217 </td>
5218 </tr>
5219 <tr>
5220 <th scope="row"><?php esc_html_e( 'Remove Feed Version', 'vigilante' ); ?></th>
5221 <td>
5222 <label>
5223 <input type="checkbox" name="wp_hardening[remove_feed_version]" value="1" <?php checked( ! empty( $options['remove_feed_version'] ) ); ?>>
5224 <?php esc_html_e( 'Remove WordPress version from feed generator tag', 'vigilante' ); ?>
5225 </label>
5226 </td>
5227 </tr>
5228 </table>
5229 </div>
5230
5231 <p class="submit vigilante-submit-buttons">
5232 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5233 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5234 </button>
5235 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5236 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5237 </button>
5238 </p>
5239 </form>
5240 <?php
5241 }
5242
5243 /**
5244 * Render activity log tab
5245 */
5246 private function render_tab_activity_log() {
5247 $is_disabled = $this->render_module_disabled_notice( 'activity_log' );
5248 $options = $this->settings->get_section( 'activity_log' );
5249 ?>
5250 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="activity_log" <?php echo $is_disabled ? 'inert' : ''; ?>>
5251 <div id="vigilante-section-audit-settings" class="vigilante-settings-section">
5252 <h2>
5253 <?php esc_html_e( 'Security Audit Settings', 'vigilante' ); ?>
5254 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5255 <span class="vigilante-method-badge database"><?php esc_html_e( 'Database', 'vigilante' ); ?></span>
5256 </h2>
5257 <p><?php esc_html_e( 'Security event logging and auditing.', 'vigilante' ); ?></p>
5258
5259 <table class="form-table">
5260 <tr>
5261 <th scope="row"><?php esc_html_e( 'Retention', 'vigilante' ); ?></th>
5262 <td>
5263 <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">
5264 <label for="vigilante-f-activity-log-retention-days"><?php esc_html_e( 'days', 'vigilante' ); ?></label>
5265 &nbsp;&nbsp;
5266 <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">
5267 <label for="vigilante-f-activity-log-max-entries"><?php esc_html_e( 'max entries', 'vigilante' ); ?></label>
5268 <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>
5269 </td>
5270 </tr>
5271 <tr>
5272 <th scope="row"><?php esc_html_e( 'Events to Log', 'vigilante' ); ?></th>
5273 <td>
5274 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(240px, 1fr)); gap:6px 24px; max-width:600px;">
5275 <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>
5276 <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>
5277 <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>
5278 <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>
5279 <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>
5280 <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>
5281 <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>
5282 <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>
5283 <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>
5284 <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>
5285 </fieldset>
5286 <div class="notice notice-info inline" style="margin:10px 0 0;padding:8px 12px;">
5287 <p style="margin:0;">
5288 <?php esc_html_e( 'Firewall blocks, security events, and Vigilant settings changes are always logged regardless of the above selections.', 'vigilante' ); ?>
5289 </p>
5290 </div>
5291 </td>
5292 </tr>
5293 <tr>
5294 <th scope="row"><label for="vigilante-f-activity-log-tracked-options"><?php esc_html_e( 'Option Tracking', 'vigilante' ); ?></label></th>
5295 <td>
5296 <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>
5297 <br>
5298 <label><?php esc_html_e( 'Additional options to track:', 'vigilante' ); ?></label><br>
5299 <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>
5300 <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>
5301 </td>
5302 </tr>
5303 <tr>
5304 <th scope="row"><?php esc_html_e( 'Exclusions', 'vigilante' ); ?></th>
5305 <td>
5306 <div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:16px; max-width:600px;">
5307 <div>
5308 <label for="vigilante-f-activity-log-excluded-users"><?php esc_html_e( 'Excluded user IDs:', 'vigilante' ); ?></label><br>
5309 <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>
5310 <p class="description"><?php esc_html_e( 'One user ID per line. Actions by these users will not be logged.', 'vigilante' ); ?></p>
5311 </div>
5312 <div>
5313 <label for="vigilante-f-activity-log-excluded-ips"><?php esc_html_e( 'Excluded IPs:', 'vigilante' ); ?></label><br>
5314 <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>
5315 <p class="description"><?php esc_html_e( 'One IP per line. Requests from these IPs will not be logged.', 'vigilante' ); ?></p>
5316 </div>
5317 </div>
5318 </td>
5319 </tr>
5320 </table>
5321 </div>
5322
5323 <p class="submit vigilante-submit-buttons">
5324 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5325 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5326 </button>
5327 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5328 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5329 </button>
5330 </p>
5331 </form>
5332
5333 <?php
5334 // Audit Alerts — alerting layer on top of Security Audit. Its own
5335 // settings section and form, rendered right after the logging settings
5336 // so the tab reads as "log this, exclude that, and alert me about this".
5337 $alerts = $this->settings->get_section( 'audit_alerts' );
5338 $immediate = isset( $alerts['immediate'] ) ? $alerts['immediate'] : array();
5339 $threshold = isset( $alerts['threshold'] ) ? $alerts['threshold'] : array();
5340 $alert_severity = isset( $immediate['min_severity'] ) ? $immediate['min_severity'] : 'critical';
5341 $alert_window = isset( $threshold['window'] ) ? $threshold['window'] : '1h';
5342 $threshold_cats = isset( $threshold['categories'] ) ? (array) $threshold['categories'] : array();
5343 $cat_labels = Vigilante_Audit_Alerts::category_labels();
5344 ?>
5345 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="audit_alerts" <?php echo $is_disabled ? 'inert' : ''; ?>>
5346 <div id="vigilante-section-audit-alerts" class="vigilante-settings-section">
5347 <h2>
5348 <?php esc_html_e( 'Audit Alerts', 'vigilante' ); ?>
5349 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5350 </h2>
5351 <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>
5352
5353 <table class="form-table">
5354 <tr id="field-audit-alerts-immediate">
5355 <th scope="row"><?php esc_html_e( 'Immediate alerts', 'vigilante' ); ?></th>
5356 <td>
5357 <label>
5358 <input type="checkbox" name="audit_alerts[immediate][enabled]" value="1" <?php checked( ! empty( $immediate['enabled'] ) ); ?>>
5359 <?php esc_html_e( 'Email me as soon as a serious event is logged', 'vigilante' ); ?>
5360 </label>
5361 <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>
5362 </td>
5363 </tr>
5364 <tr>
5365 <th scope="row"><label for="vigilante-f-audit-alerts-immediate-min-severity"><?php esc_html_e( 'Alert on severity', 'vigilante' ); ?></label></th>
5366 <td>
5367 <select id="vigilante-f-audit-alerts-immediate-min-severity" name="audit_alerts[immediate][min_severity]">
5368 <option value="critical" <?php selected( $alert_severity, 'critical' ); ?>><?php esc_html_e( 'Critical only (recommended)', 'vigilante' ); ?></option>
5369 <option value="warning" <?php selected( $alert_severity, 'warning' ); ?>><?php esc_html_e( 'Warning and Critical', 'vigilante' ); ?></option>
5370 </select>
5371 <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>
5372 </td>
5373 </tr>
5374 <tr id="field-audit-alerts-threshold">
5375 <th scope="row"><?php esc_html_e( 'Threshold alerts', 'vigilante' ); ?></th>
5376 <td>
5377 <label>
5378 <input type="checkbox" name="audit_alerts[threshold][enabled]" value="1" <?php checked( ! empty( $threshold['enabled'] ) ); ?>>
5379 <?php esc_html_e( 'Email me when a category spikes within a time window', 'vigilante' ); ?>
5380 </label>
5381 <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>
5382 </td>
5383 </tr>
5384 <tr>
5385 <th scope="row"><label for="vigilante-f-audit-alerts-threshold-window"><?php esc_html_e( 'Time window', 'vigilante' ); ?></label></th>
5386 <td>
5387 <select id="vigilante-f-audit-alerts-threshold-window" name="audit_alerts[threshold][window]">
5388 <option value="30m" <?php selected( $alert_window, '30m' ); ?>><?php esc_html_e( '30 minutes', 'vigilante' ); ?></option>
5389 <option value="1h" <?php selected( $alert_window, '1h' ); ?>><?php esc_html_e( '1 hour', 'vigilante' ); ?></option>
5390 <option value="6h" <?php selected( $alert_window, '6h' ); ?>><?php esc_html_e( '6 hours', 'vigilante' ); ?></option>
5391 <option value="24h" <?php selected( $alert_window, '24h' ); ?>><?php esc_html_e( '24 hours', 'vigilante' ); ?></option>
5392 </select>
5393 <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>
5394 </td>
5395 </tr>
5396 <tr>
5397 <th scope="row"><?php esc_html_e( 'Thresholds per category', 'vigilante' ); ?></th>
5398 <td>
5399 <fieldset style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:8px 24px; max-width:760px;">
5400 <?php
5401 foreach ( $cat_labels as $cat_slug => $cat_label ) :
5402 $cat_value = isset( $threshold_cats[ $cat_slug ] ) ? (int) $threshold_cats[ $cat_slug ] : 0;
5403 ?>
5404 <label style="display:flex;align-items:center;gap:8px;justify-content:space-between;">
5405 <span><?php echo esc_html( $cat_label ); ?></span>
5406 <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">
5407 </label>
5408 <?php endforeach; ?>
5409 </fieldset>
5410 <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>
5411 </td>
5412 </tr>
5413 <tr>
5414 <th scope="row"><?php esc_html_e( "Don't repeat alerts", 'vigilante' ); ?></th>
5415 <td>
5416 <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">
5417 <label for="vigilante-f-audit-alerts-cooldown-minutes"><?php esc_html_e( 'minutes', 'vigilante' ); ?></label>
5418 <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>
5419 </td>
5420 </tr>
5421
5422 <tr>
5423 <th scope="row"><?php esc_html_e( 'Recipients', 'vigilante' ); ?></th>
5424 <td>
5425 <p class="description" style="margin-top:0;">
5426 <?php
5427 printf(
5428 /* translators: %s: Link to notification settings */
5429 esc_html__( 'Alerts go to the recipients configured in %s.', 'vigilante' ),
5430 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5431 );
5432 ?>
5433 </p>
5434 <p style="margin:8px 0 0;">
5435 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5436 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5437 </button>
5438 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5439 </p>
5440 <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>
5441 </td>
5442 </tr>
5443 </table>
5444 </div>
5445
5446 <p class="submit vigilante-submit-buttons">
5447 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5448 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5449 </button>
5450 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5451 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5452 </button>
5453 </p>
5454 </form>
5455
5456 <div id="vigilante-section-audit-recent" class="vigilante-settings-section">
5457 <h2><?php esc_html_e( 'Recent Activity', 'vigilante' ); ?></h2>
5458
5459 <?php
5460 $logs = $this->activity_log->get_logs( array( 'per_page' => 20 ) );
5461 $total_logs = $this->activity_log->get_logs_count();
5462
5463 // Label maps for translated display
5464 $type_labels = array(
5465 'login' => __( 'Login', 'vigilante' ),
5466 'user' => __( 'User', 'vigilante' ),
5467 'content' => __( 'Content', 'vigilante' ),
5468 'plugin' => __( 'Plugin', 'vigilante' ),
5469 'theme' => __( 'Theme', 'vigilante' ),
5470 'settings' => __( 'Settings', 'vigilante' ),
5471 'comment' => __( 'Comment', 'vigilante' ),
5472 'media' => __( 'Media', 'vigilante' ),
5473 'firewall' => __( 'Firewall', 'vigilante' ),
5474 'file' => __( 'File', 'vigilante' ),
5475 'security' => __( 'Security', 'vigilante' ),
5476 'system' => __( 'System', 'vigilante' ),
5477 );
5478 $severity_labels = array(
5479 'info' => __( 'Info', 'vigilante' ),
5480 'warning' => __( 'Warning', 'vigilante' ),
5481 'critical' => __( 'Critical', 'vigilante' ),
5482 );
5483
5484 $firewall_options = $this->settings->get_section( 'firewall' );
5485 $ip_whitelist = $firewall_options['ip_whitelist'] ?? array();
5486 $ip_blacklist = $firewall_options['ip_blacklist'] ?? array();
5487 $ua_whitelist = $firewall_options['ua_whitelist'] ?? array();
5488 $ua_blacklist = $firewall_options['ua_blacklist'] ?? array();
5489 ?>
5490
5491 <div class="vigilante-log-filters">
5492 <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">
5493 <select id="vigilante-log-type-filter" aria-label="<?php esc_attr_e( 'Filter the log by event type', 'vigilante' ); ?>">
5494 <option value=""><?php esc_html_e( 'All Types', 'vigilante' ); ?></option>
5495 <option value="login"><?php esc_html_e( 'Login', 'vigilante' ); ?></option>
5496 <option value="user"><?php esc_html_e( 'User', 'vigilante' ); ?></option>
5497 <option value="content"><?php esc_html_e( 'Content', 'vigilante' ); ?></option>
5498 <option value="plugin"><?php esc_html_e( 'Plugin', 'vigilante' ); ?></option>
5499 <option value="theme"><?php esc_html_e( 'Theme', 'vigilante' ); ?></option>
5500 <option value="settings"><?php esc_html_e( 'Settings', 'vigilante' ); ?></option>
5501 <option value="comment"><?php esc_html_e( 'Comment', 'vigilante' ); ?></option>
5502 <option value="media"><?php esc_html_e( 'Media', 'vigilante' ); ?></option>
5503 <option value="firewall"><?php esc_html_e( 'Firewall', 'vigilante' ); ?></option>
5504 <option value="file"><?php esc_html_e( 'File', 'vigilante' ); ?></option>
5505 <option value="security"><?php esc_html_e( 'Security', 'vigilante' ); ?></option>
5506 <option value="system"><?php esc_html_e( 'System', 'vigilante' ); ?></option>
5507 </select>
5508 <select id="vigilante-log-severity-filter" aria-label="<?php esc_attr_e( 'Filter the log by severity', 'vigilante' ); ?>">
5509 <option value=""><?php esc_html_e( 'All Severities', 'vigilante' ); ?></option>
5510 <option value="info"><?php esc_html_e( 'Info', 'vigilante' ); ?></option>
5511 <option value="warning"><?php esc_html_e( 'Warning', 'vigilante' ); ?></option>
5512 <option value="critical"><?php esc_html_e( 'Critical', 'vigilante' ); ?></option>
5513 </select>
5514 <select id="vigilante-log-method-filter" aria-label="<?php esc_attr_e( 'Filter the log by HTTP method', 'vigilante' ); ?>">
5515 <option value=""><?php esc_html_e( 'All Methods', 'vigilante' ); ?></option>
5516 <option value="GET">GET</option>
5517 <option value="POST">POST</option>
5518 <option value="PUT">PUT</option>
5519 <option value="DELETE">DELETE</option>
5520 <option value="PATCH">PATCH</option>
5521 <option value="OPTIONS">OPTIONS</option>
5522 <option value="HEAD">HEAD</option>
5523 </select>
5524 <button type="button" id="vigilante-log-refresh" class="button"><?php esc_html_e( 'Refresh', 'vigilante' ); ?></button>
5525 <span class="vigilante-pagination" id="vigilante-log-pagination" data-total="<?php echo esc_attr( $total_logs ); ?>" data-per-page="20" data-page="1">
5526 <?php if ( $total_logs > 20 ) : ?>
5527 <button type="button" class="vigilante-page-first" title="<?php esc_attr_e( 'First page', 'vigilante' ); ?>" disabled>&laquo;</button>
5528 <button type="button" class="vigilante-page-prev" title="<?php esc_attr_e( 'Previous page', 'vigilante' ); ?>" disabled>&lsaquo;</button>
5529 <?php endif; ?>
5530 <span class="vigilante-page-info">
5531 <?php
5532 $showing = min( 20, $total_logs );
5533 printf(
5534 /* translators: 1: first item, 2: last item, 3: total items */
5535 esc_html__( '%1$d–%2$d of %3$d', 'vigilante' ),
5536 $total_logs > 0 ? 1 : 0,
5537 absint( $showing ),
5538 absint( $total_logs )
5539 );
5540 ?>
5541 </span>
5542 <?php if ( $total_logs > 20 ) : ?>
5543 <button type="button" class="vigilante-page-next" title="<?php esc_attr_e( 'Next page', 'vigilante' ); ?>">&rsaquo;</button>
5544 <button type="button" class="vigilante-page-last" title="<?php esc_attr_e( 'Last page', 'vigilante' ); ?>">&raquo;</button>
5545 <?php endif; ?>
5546 </span>
5547 </div>
5548
5549 <div class="vigilante-log-table-wrap">
5550 <table id="vigilante-activity-log-table" class="wp-list-table widefat striped">
5551 <thead>
5552 <tr>
5553 <th class="column-date"><?php esc_html_e( 'Date', 'vigilante' ); ?></th>
5554 <th class="column-type"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5555 <th class="column-method"><?php esc_html_e( 'Method', 'vigilante' ); ?></th>
5556 <th class="column-severity"><?php esc_html_e( 'Severity', 'vigilante' ); ?></th>
5557 <th class="column-message"><?php esc_html_e( 'Message', 'vigilante' ); ?></th>
5558 <th class="column-user"><?php esc_html_e( 'User', 'vigilante' ); ?></th>
5559 <th class="column-ip"><?php esc_html_e( 'IP', 'vigilante' ); ?></th>
5560 <th class="column-details"><?php esc_html_e( 'Details', 'vigilante' ); ?></th>
5561 </tr>
5562 </thead>
5563 <tbody>
5564 <?php
5565 if ( empty( $logs ) ) :
5566 ?>
5567 <tr><td colspan="8"><?php esc_html_e( 'No log entries found.', 'vigilante' ); ?></td></tr>
5568 <?php else : ?>
5569 <?php foreach ( $logs as $log ) :
5570 $request_method = isset( $log->request_method ) ? $log->request_method : '';
5571 // Prepare details as a simple object
5572 $ip_val = (string) ( $log->ip_address ?? '' );
5573 $ua_val = (string) ( $log->user_agent ?? '' );
5574 $details = array(
5575 'id' => (int) $log->id,
5576 'type' => (string) ( $log->event_type ?? '' ),
5577 'action' => (string) ( $log->event_action ?? '' ),
5578 'message' => (string) ( $log->event_message ?? '' ),
5579 'user' => (string) ( $log->user_login ?? '' ),
5580 'ip' => $ip_val,
5581 'user_agent' => $ua_val,
5582 'request_method' => (string) $request_method,
5583 'date' => (string) ( $log->created_at ?? '' ),
5584 'severity' => (string) ( $log->severity ?? 'info' ),
5585 'is_ip_whitelisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) ),
5586 'is_ip_blacklisted' => ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) ),
5587 'is_ua_whitelisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) ),
5588 'is_ua_blacklisted' => ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) ),
5589 );
5590 $display_type = isset( $type_labels[ $log->event_type ] ) ? $type_labels[ $log->event_type ] : $log->event_type;
5591 $display_severity = isset( $severity_labels[ $log->severity ] ) ? $severity_labels[ $log->severity ] : $log->severity;
5592 ?>
5593 <tr class="vigilante-severity-<?php echo esc_attr( $log->severity ); ?>">
5594 <td><?php echo esc_html( $log->created_at ); ?></td>
5595 <td><?php echo esc_html( $display_type ); ?></td>
5596 <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>
5597 <td><span class="vigilante-badge vigilante-badge-<?php echo esc_attr( $log->severity ); ?>"><?php echo esc_html( $display_severity ); ?></span></td>
5598 <td><?php echo esc_html( $log->event_message ); ?></td>
5599 <td><?php echo esc_html( $log->user_login ?? '-' ); ?></td>
5600 <td><code><?php echo esc_html( $log->ip_address ); ?></code></td>
5601 <td>
5602 <button type="button" class="button button-small vigilante-view-log-details"
5603 data-details='<?php echo esc_attr( wp_json_encode( $details, JSON_HEX_APOS | JSON_HEX_QUOT ) ); ?>'>
5604 <?php esc_html_e( 'View', 'vigilante' ); ?>
5605 </button>
5606 </td>
5607 </tr>
5608 <?php endforeach; ?>
5609 <?php endif; ?>
5610 </tbody>
5611 </table>
5612 </div>
5613
5614 <!-- Log Details Modal -->
5615 <div id="vigilante-log-details-modal" class="vigilante-modal" style="display: none;">
5616 <div class="vigilante-modal-content">
5617 <span class="vigilante-modal-close">&times;</span>
5618 <h3><?php esc_html_e( 'Log Entry Details', 'vigilante' ); ?></h3>
5619 <div id="vigilante-log-details-content"></div>
5620 </div>
5621 </div>
5622
5623 <p>
5624 <button type="button" class="button vigilante-export-logs"><?php esc_html_e( 'Export Audit Log', 'vigilante' ); ?></button>
5625 <button type="button" class="button vigilante-clear-logs" style="color: #a00;"><?php esc_html_e( 'Clear All Logs', 'vigilante' ); ?></button>
5626 </p>
5627 </div>
5628 <?php
5629 }
5630
5631 /**
5632 * Render File Integrity tab
5633 */
5634 private function render_tab_file_integrity() {
5635 $is_disabled = $this->render_module_disabled_notice( 'file_integrity' );
5636 $options = $this->settings->get_section( 'file_integrity' );
5637 $last_scan = get_option( 'vigilante_last_integrity_scan' );
5638 $last_results = get_option( 'vigilante_last_integrity_results' );
5639 $ignored_files = get_option( 'vigilante_ignored_files', array() );
5640
5641 // Backward compat: convert old notify_on_changes to notify_level
5642 $notify_level = $options['notify_level'] ?? '';
5643 if ( empty( $notify_level ) ) {
5644 $notify_level = ! empty( $options['notify_on_changes'] ) ? 'all' : 'disabled';
5645 }
5646
5647 // Closed + Removed plugins data. Surfaced inside Last Scan Results so the
5648 // user sees file findings and plugin closures together (same tier of risk,
5649 // same UI), and as the trigger to keep Last Scan Results open even when no
5650 // file scan has run yet (the daily cron may have populated this section).
5651 //
5652 // Gating by last_check_time > 0 is how "Clear Previous Results" visually
5653 // resets this block: the option vigilante_plugin_status_last_check is
5654 // deleted on Clear, but the state map and the ignored list survive so the
5655 // next scan reconstructs without degrading a 'removed' slug. While
5656 // last_check is 0, we treat the plugin_status data as if it didn't exist.
5657 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
5658 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
5659 }
5660 $closed_checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
5661 $closed_last_check = $closed_checker->get_last_check_time();
5662 if ( $closed_last_check > 0 ) {
5663 $closed_plugins = $closed_checker->get_closed_plugins();
5664 $ignored_closed_plugins = $closed_checker->get_ignored_closed_plugins();
5665 } else {
5666 $closed_plugins = array();
5667 $ignored_closed_plugins = array();
5668 }
5669 $has_closed = ! empty( $closed_plugins );
5670 $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
5671 ?>
5672 <form class="vigilante-settings-form <?php echo $is_disabled ? 'vigilante-form-disabled' : ''; ?>" data-section="file_integrity" <?php echo $is_disabled ? 'inert' : ''; ?>>
5673 <div id="vigilante-section-fi-monitoring" class="vigilante-settings-section">
5674 <h2>
5675 <?php esc_html_e( 'File Integrity Monitoring', 'vigilante' ); ?>
5676 <span class="vigilante-method-badge php"><?php esc_html_e( 'PHP', 'vigilante' ); ?></span>
5677 </h2>
5678 <p><?php esc_html_e( 'Detects file modifications using WordPress.org checksums.', 'vigilante' ); ?></p>
5679
5680 <table class="form-table">
5681 <tr>
5682 <th scope="row"><?php esc_html_e( 'Automatic Scans', 'vigilante' ); ?></th>
5683 <td>
5684 <label>
5685 <input type="checkbox" name="file_integrity[auto_scan]" value="1" <?php checked( ! empty( $options['auto_scan'] ) ); ?>>
5686 <?php esc_html_e( 'Enable scheduled file integrity scans', 'vigilante' ); ?>
5687 </label>
5688 </td>
5689 </tr>
5690 <tr>
5691 <th scope="row"><label for="vigilante-f-file-integrity-scan-frequency"><?php esc_html_e( 'Scan Frequency', 'vigilante' ); ?></label></th>
5692 <td>
5693 <select id="vigilante-f-file-integrity-scan-frequency" name="file_integrity[scan_frequency]">
5694 <option value="daily" <?php selected( $options['scan_frequency'] ?? 'daily', 'daily' ); ?>><?php esc_html_e( 'Daily', 'vigilante' ); ?></option>
5695 <option value="weekly" <?php selected( $options['scan_frequency'] ?? 'daily', 'weekly' ); ?>><?php esc_html_e( 'Weekly', 'vigilante' ); ?></option>
5696 </select>
5697 </td>
5698 </tr>
5699 <tr>
5700 <th scope="row"><label for="vigilante-f-file-integrity-notify-level"><?php esc_html_e( 'Email Notifications', 'vigilante' ); ?></label></th>
5701 <td>
5702 <select id="vigilante-f-file-integrity-notify-level" name="file_integrity[notify_level]">
5703 <option value="all" <?php selected( $notify_level, 'all' ); ?>><?php esc_html_e( 'All issues (modified + suspicious)', 'vigilante' ); ?></option>
5704 <option value="suspicious_only" <?php selected( $notify_level, 'suspicious_only' ); ?>><?php esc_html_e( 'Suspicious files only', 'vigilante' ); ?></option>
5705 <option value="disabled" <?php selected( $notify_level, 'disabled' ); ?>><?php esc_html_e( 'Disabled', 'vigilante' ); ?></option>
5706 </select>
5707 <p class="description"><?php esc_html_e( '"Suspicious files only" reduces noise by skipping modified file notifications. Recommended for most sites.', 'vigilante' ); ?></p>
5708 </td>
5709 </tr>
5710 <tr>
5711 <th scope="row"><?php esc_html_e( 'Instant Alert', 'vigilante' ); ?></th>
5712 <td>
5713 <label>
5714 <input type="checkbox" name="file_integrity[instant_alert]" value="1" <?php checked( ! empty( $options['instant_alert'] ) ); ?>>
5715 <?php esc_html_e( 'Send immediate alert when modified, suspicious or additional files are detected, or when a closed plugin is found', 'vigilante' ); ?>
5716 </label>
5717 <p class="description"><?php esc_html_e( 'Fires even if the Email Notifications setting above is set to Disabled.', 'vigilante' ); ?></p>
5718 <p class="description">
5719 <?php
5720 printf(
5721 /* translators: %s: Link to notification settings */
5722 esc_html__( '&#9432; Notifications are sent to the recipients configured in %s.', 'vigilante' ),
5723 '<a href="' . esc_url( admin_url( 'admin.php?page=vigilante&tab=tools' ) ) . '">' . esc_html__( 'Settings & Tools', 'vigilante' ) . '</a>'
5724 );
5725 ?>
5726 </p>
5727 </td>
5728 </tr>
5729 <tr>
5730 <th scope="row"><?php esc_html_e( 'Test email', 'vigilante' ); ?></th>
5731 <td>
5732 <button type="button" class="button vigilante-test-email-btn" data-original-text="<?php esc_attr_e( 'Send test email', 'vigilante' ); ?>">
5733 <?php esc_html_e( 'Send test email', 'vigilante' ); ?>
5734 </button>
5735 <span class="vigilante-test-email-result" style="margin-left:8px;"></span>
5736 <p class="description"><?php esc_html_e( 'Sends a test message to the configured recipients to confirm email delivery works.', 'vigilante' ); ?></p>
5737 </td>
5738 </tr>
5739 <tr>
5740 <th scope="row"><?php esc_html_e( 'Scan Scope', 'vigilante' ); ?></th>
5741 <td>
5742 <fieldset>
5743 <label>
5744 <input type="checkbox" name="file_integrity[scan_core]" value="1" <?php checked( $options['scan_core'] ?? true ); ?>>
5745 <?php esc_html_e( 'Core files (compare against WordPress.org checksums)', 'vigilante' ); ?>
5746 </label>
5747 <br>
5748 <label>
5749 <input type="checkbox" name="file_integrity[scan_plugins]" value="1" <?php checked( $options['scan_plugins'] ?? true ); ?>>
5750 <?php esc_html_e( 'Plugins (WordPress.org repository plugins)', 'vigilante' ); ?>
5751 </label>
5752 <br>
5753 <label>
5754 <input type="checkbox" name="file_integrity[scan_themes]" value="1" <?php checked( $options['scan_themes'] ?? true ); ?>>
5755 <?php esc_html_e( 'Themes (WordPress.org repository themes)', 'vigilante' ); ?>
5756 </label>
5757 <br>
5758 <label>
5759 <input type="checkbox" name="file_integrity[scan_uploads]" value="1" <?php checked( $options['scan_uploads'] ?? true ); ?>>
5760 <?php esc_html_e( 'Uploads directory (detect PHP files, double extensions, .htaccess)', 'vigilante' ); ?>
5761 </label>
5762 <br>
5763 <label>
5764 <input type="checkbox" name="file_integrity[scan_critical_config]" value="1" <?php checked( $options['scan_critical_config'] ?? true ); ?>>
5765 <?php esc_html_e( 'Critical config files (wp-config.php, .htaccess baseline monitoring)', 'vigilante' ); ?>
5766 </label>
5767 <br>
5768 <label>
5769 <input type="checkbox" name="file_integrity[check_closed_plugins]" value="1" <?php checked( $options['check_closed_plugins'] ?? true ); ?>>
5770 <?php esc_html_e( 'Closed plugins (daily check against the WordPress.org repository)', 'vigilante' ); ?>
5771 </label>
5772 </fieldset>
5773 </td>
5774 </tr>
5775 <tr>
5776 <th scope="row"><label for="vigilante-f-file-integrity-excluded-paths"><?php esc_html_e( 'Excluded Paths', 'vigilante' ); ?></label></th>
5777 <td>
5778 <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>
5779 <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>
5780 </td>
5781 </tr>
5782 <tr>
5783 <th scope="row"><label for="vigilante-f-file-integrity-excluded-extensions"><?php esc_html_e( 'Excluded Extensions', 'vigilante' ); ?></label></th>
5784 <td>
5785 <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>
5786 <p class="description">
5787 <?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' ); ?>
5788 <br>
5789 <?php
5790 printf(
5791 /* translators: 1: opening <code>, 2: closing </code>. Placeholders wrap the scoped-extension example. */
5792 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' ),
5793 '<code>',
5794 '</code>'
5795 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML tags are hardcoded.
5796 ?>
5797 </p>
5798 </td>
5799 </tr>
5800 </table>
5801 </div>
5802
5803 <p class="submit vigilante-submit-buttons">
5804 <button type="submit" class="button button-primary vigilante-save-btn" data-original-text="<?php esc_attr_e( 'Save Settings', 'vigilante' ); ?>">
5805 <?php esc_html_e( 'Save Settings', 'vigilante' ); ?>
5806 </button>
5807 <button type="button" class="button vigilante-reset-section-btn" data-original-text="<?php esc_attr_e( 'Reset to Defaults', 'vigilante' ); ?>">
5808 <?php esc_html_e( 'Reset to Defaults', 'vigilante' ); ?>
5809 </button>
5810 <span class="vigilante-buttons-separator"></span>
5811 <button type="button" class="button button-primary vigilante-run-scan">
5812 <?php esc_html_e( 'Run Scan Now', 'vigilante' ); ?>
5813 </button>
5814 <button type="button" class="button vigilante-clear-scan-btn vigilante-clear-scan">
5815 <?php esc_html_e( 'Clear Previous Results', 'vigilante' ); ?>
5816 </button>
5817 </p>
5818 </form>
5819
5820 <div id="vigilante-scan-results" class="vigilante-settings-section" style="display:none;"></div>
5821
5822 <?php if ( $last_scan || $has_closed || $closed_last_check > 0 ) : ?>
5823 <div id="vigilante-section-fi-last-scan" class="vigilante-settings-section">
5824 <h2><?php esc_html_e( 'Last Scan Results', 'vigilante' ); ?></h2>
5825 <?php if ( $last_scan ) : ?>
5826 <p>
5827 <?php
5828 // Build the "X files scanned" hint inline with the date so it doesn't
5829 // need its own stat box (keeps the row compact when closed plugins are
5830 // present).
5831 $scanned_total = 0;
5832 if ( $last_results ) {
5833 $scanned_total = (int) ( $last_results['ok'] ?? 0 )
5834 + count( $last_results['modified'] ?? array() )
5835 + count( $last_results['suspicious'] ?? array() )
5836 + count( $last_results['extra'] ?? array() )
5837 + count( $ignored_files );
5838 }
5839 if ( $scanned_total > 0 ) {
5840 printf(
5841 /* translators: 1: date and time of last scan, 2: formatted file count */
5842 esc_html__( 'Last scan: %1$s (%2$s files scanned)', 'vigilante' ),
5843 esc_html( wp_date( $datetime_format, $last_scan ) ),
5844 esc_html( number_format_i18n( $scanned_total ) )
5845 );
5846 } else {
5847 printf(
5848 /* translators: %s: date and time of last scan */
5849 esc_html__( 'Last scan: %s', 'vigilante' ),
5850 esc_html( wp_date( $datetime_format, $last_scan ) )
5851 );
5852 }
5853 if ( $closed_last_check > 0 && $closed_last_check !== (int) $last_scan ) {
5854 echo ' &middot; ';
5855 printf(
5856 /* translators: %s: date and time of last closed plugins check */
5857 esc_html__( 'Closed plugins last checked: %s', 'vigilante' ),
5858 esc_html( wp_date( $datetime_format, $closed_last_check ) )
5859 );
5860 }
5861 ?>
5862 </p>
5863 <?php elseif ( $closed_last_check > 0 ) : ?>
5864 <p>
5865 <?php
5866 printf(
5867 /* translators: %s: date and time of last closed plugins check */
5868 esc_html__( 'Closed plugins last checked: %s &middot; the daily cron is running, no full integrity scan yet.', 'vigilante' ),
5869 esc_html( wp_date( $datetime_format, $closed_last_check ) )
5870 );
5871 ?>
5872 </p>
5873 <?php endif; ?>
5874 <div id="vigilante-last-scan-results">
5875 <?php if ( $last_results || $has_closed ) : ?>
5876 <div class="vigilante-scan-summary">
5877 <?php if ( $last_results ) : ?>
5878 <div class="vigilante-scan-stat vigilante-stat-ok">
5879 <span class="vigilante-stat-number"><?php echo esc_html( $last_results['ok'] ?? 0 ); ?></span>
5880 <span class="vigilante-stat-label"><?php esc_html_e( 'OK', 'vigilante' ); ?></span>
5881 </div>
5882 <div class="vigilante-scan-stat vigilante-stat-modified">
5883 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['modified'] ?? array() ) ); ?></span>
5884 <span class="vigilante-stat-label"><?php esc_html_e( 'Modified', 'vigilante' ); ?></span>
5885 </div>
5886 <div class="vigilante-scan-stat vigilante-stat-suspicious">
5887 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['suspicious'] ?? array() ) ); ?></span>
5888 <span class="vigilante-stat-label"><?php esc_html_e( 'Suspicious', 'vigilante' ); ?></span>
5889 </div>
5890 <div class="vigilante-scan-stat vigilante-stat-extra">
5891 <span class="vigilante-stat-number"><?php echo esc_html( count( $last_results['extra'] ?? array() ) ); ?></span>
5892 <span class="vigilante-stat-label"><?php esc_html_e( 'Extra', 'vigilante' ); ?></span>
5893 </div>
5894 <?php endif; ?>
5895 <?php if ( $has_closed ) : ?>
5896 <div class="vigilante-scan-stat vigilante-stat-suspicious">
5897 <span class="vigilante-stat-number" style="color: #d63638;"><?php echo (int) count( $closed_plugins ); ?></span>
5898 <span class="vigilante-stat-label"><?php esc_html_e( 'Closed/Removed', 'vigilante' ); ?></span>
5899 </div>
5900 <?php endif; ?>
5901 <?php if ( ! empty( $ignored_files ) ) : ?>
5902 <div class="vigilante-scan-stat vigilante-stat-ignored">
5903 <span class="vigilante-stat-number"><?php echo esc_html( count( $ignored_files ) ); ?></span>
5904 <span class="vigilante-stat-label"><?php esc_html_e( 'Ignored', 'vigilante' ); ?></span>
5905 </div>
5906 <?php endif; ?>
5907 </div>
5908
5909 <?php if ( ! empty( $last_results['suspicious'] ) ) : ?>
5910 <div class="vigilante-file-list vigilante-suspicious-files vigilante-paginated-section" data-bulk-mode="ignore">
5911 <h3 style="color: #d63638;"><?php esc_html_e( 'Suspicious Files', 'vigilante' ); ?></h3>
5912 <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>
5913 <div class="vigilante-fi-bulk-bar">
5914 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
5915 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5916 </div>
5917 <div class="vigilante-fi-pagination-wrap"></div>
5918 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5919 <thead>
5920 <tr>
5921 <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>
5922 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5923 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
5924 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5925 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5926 </tr>
5927 </thead>
5928 <tbody>
5929 <?php
5930 foreach ( $last_results['suspicious'] as $item ) {
5931 $file_path = '';
5932 $file_reason = __( 'Unknown', 'vigilante' );
5933 $file_type = 'unknown';
5934
5935 if ( is_array( $item ) ) {
5936 if ( isset( $item['file'] ) ) {
5937 $file_path = $item['file'];
5938 }
5939 if ( isset( $item['reason'] ) ) {
5940 $file_reason = $item['reason'];
5941 }
5942 if ( isset( $item['type'] ) ) {
5943 $file_type = $item['type'];
5944 }
5945 } else {
5946 $file_path = (string) $item;
5947 }
5948 ?>
5949 <tr>
5950 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
5951 <td><code style="color: #d63638;"><?php echo esc_html( $file_path ); ?></code></td>
5952 <td><?php echo esc_html( $file_reason ); ?></td>
5953 <td><?php echo esc_html( $file_type ); ?></td>
5954 <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>
5955 </tr>
5956 <?php
5957 }
5958 ?>
5959 </tbody>
5960 </table>
5961 </div>
5962 <?php endif; ?>
5963
5964 <?php if ( ! empty( $last_results['extra'] ) ) : ?>
5965 <div class="vigilante-file-list vigilante-extra-files vigilante-paginated-section" data-bulk-mode="ignore">
5966 <h3 style="color: #b32d2e;"><?php esc_html_e( 'Extra Files', 'vigilante' ); ?></h3>
5967 <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>
5968 <div class="vigilante-fi-bulk-bar">
5969 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
5970 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
5971 </div>
5972 <div class="vigilante-fi-pagination-wrap"></div>
5973 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
5974 <thead>
5975 <tr>
5976 <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>
5977 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
5978 <th style="width: 250px;"><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
5979 <th style="width: 120px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
5980 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
5981 </tr>
5982 </thead>
5983 <tbody>
5984 <?php
5985 foreach ( $last_results['extra'] as $item ) {
5986 $file_path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
5987 $file_reason = is_array( $item ) ? ( $item['reason'] ?? __( 'Unknown', 'vigilante' ) ) : __( 'Unknown', 'vigilante' );
5988 $file_type = is_array( $item ) ? ( $item['type'] ?? 'unknown' ) : 'unknown';
5989 ?>
5990 <tr>
5991 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
5992 <td><code style="color: #b32d2e;"><?php echo esc_html( $file_path ); ?></code></td>
5993 <td><?php echo esc_html( $file_reason ); ?></td>
5994 <td><?php echo esc_html( $file_type ); ?></td>
5995 <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>
5996 </tr>
5997 <?php
5998 }
5999 ?>
6000 </tbody>
6001 </table>
6002 </div>
6003 <?php endif; ?>
6004
6005 <?php
6006 // Split critical config files from regular modified files.
6007 // Computed unconditionally so the three sub-sections that consume
6008 // these arrays (Critical Config, Closed + Removed, Modified Files)
6009 // can render independently and in the order the team picked.
6010 $critical_modified = array();
6011 $regular_modified = array();
6012 if ( $last_results && ! empty( $last_results['modified'] ) ) {
6013 foreach ( $last_results['modified'] as $item ) {
6014 if ( is_array( $item ) && isset( $item['type'] ) && 'critical_config' === $item['type'] ) {
6015 $critical_modified[] = $item;
6016 } else {
6017 $regular_modified[] = $item;
6018 }
6019 }
6020 }
6021 ?>
6022
6023 <?php if ( ! empty( $critical_modified ) ) : ?>
6024 <div class="vigilante-file-list vigilante-critical-config-files">
6025 <h3 style="color: #e36210;"><?php esc_html_e( 'Critical config files modified', 'vigilante' ); ?></h3>
6026 <p class="description">
6027 <?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' ); ?>
6028 </p>
6029 <table class="wp-list-table widefat fixed striped">
6030 <thead>
6031 <tr>
6032 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6033 <th style="width: 200px;"><?php esc_html_e( 'Changes', 'vigilante' ); ?></th>
6034 <th style="width: 220px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6035 </tr>
6036 </thead>
6037 <tbody>
6038 <?php foreach ( $critical_modified as $crit_item ) :
6039 $crit_file = $crit_item['file'] ?? '';
6040 $crit_baseline_size = $crit_item['baseline_size'] ?? 0;
6041 $crit_current_size = $crit_item['current_size'] ?? 0;
6042 $crit_diff = $crit_item['diff'] ?? array();
6043 $crit_id = sanitize_html_class( $crit_file );
6044 $added_count = is_array( $crit_diff ) ? count( $crit_diff['added'] ?? array() ) : 0;
6045 $removed_count = is_array( $crit_diff ) ? count( $crit_diff['removed'] ?? array() ) : 0;
6046 $diff_unavailable = is_array( $crit_diff ) && ! empty( $crit_diff['unavailable'] );
6047 ?>
6048 <tr>
6049 <td><code style="color: #e36210;"><?php echo esc_html( $crit_file ); ?></code></td>
6050 <td>
6051 <?php if ( ! $diff_unavailable ) : ?>
6052 <span style="color: #007017;">+<?php echo (int) $added_count; ?></span>
6053 <span style="color: #b32d2e;">-<?php echo (int) $removed_count; ?></span>
6054 <?php esc_html_e( 'lines', 'vigilante' ); ?><br>
6055 <?php endif; ?>
6056 <small style="color: #50575e;">
6057 <?php
6058 printf(
6059 /* translators: 1: baseline size, 2: current size */
6060 esc_html__( '%1$s &rarr; %2$s bytes', 'vigilante' ),
6061 esc_html( number_format_i18n( $crit_baseline_size ) ),
6062 esc_html( number_format_i18n( $crit_current_size ) )
6063 );
6064 ?>
6065 </small>
6066 </td>
6067 <td>
6068 <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' ); ?>">
6069 <?php esc_html_e( 'Review changes', 'vigilante' ); ?>
6070 </button>
6071 <button type="button" class="button button-small button-primary vigilante-approve-critical-file" data-file="<?php echo esc_attr( $crit_file ); ?>">
6072 <?php esc_html_e( 'Approve', 'vigilante' ); ?>
6073 </button>
6074 </td>
6075 </tr>
6076 <tr id="vigilante-critical-content-<?php echo esc_attr( $crit_id ); ?>" class="vigilante-critical-content-row" style="display:none;">
6077 <td colspan="3" style="padding: 0;">
6078 <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;">
6079 <?php if ( $diff_unavailable ) : ?>
6080 <p style="color: #50575e; font-style: italic; margin: 0;">
6081 <?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' ); ?>
6082 </p>
6083 <?php elseif ( empty( $crit_diff['added'] ) && empty( $crit_diff['removed'] ) ) : ?>
6084 <p style="color: #50575e; font-style: italic; margin: 0;">
6085 <?php esc_html_e( 'No line-level changes detected (may be whitespace or reordering).', 'vigilante' ); ?>
6086 </p>
6087 <?php else : ?>
6088 <?php if ( ! empty( $crit_diff['removed'] ) ) : ?>
6089 <?php foreach ( $crit_diff['removed'] as $rline ) : ?>
6090 <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>
6091 <?php endforeach; ?>
6092 <?php endif; ?>
6093 <?php if ( ! empty( $crit_diff['added'] ) ) : ?>
6094 <?php foreach ( $crit_diff['added'] as $aline ) : ?>
6095 <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>
6096 <?php endforeach; ?>
6097 <?php endif; ?>
6098 <?php endif; ?>
6099 </div>
6100 </td>
6101 </tr>
6102 <?php endforeach; ?>
6103 </tbody>
6104 </table>
6105 </div>
6106 <?php endif; ?>
6107
6108 <?php if ( $has_closed ) : ?>
6109 <div class="vigilante-file-list vigilante-closed-plugins">
6110 <h3 style="color: #d63638;"><?php esc_html_e( 'Closed + Removed Plugins', 'vigilante' ); ?></h3>
6111 <p class="description" style="color: #d63638;">
6112 <?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' ); ?>
6113 </p>
6114 <table class="wp-list-table widefat striped">
6115 <thead>
6116 <tr>
6117 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6118 <th style="width: 70px;"><?php esc_html_e( 'Version', 'vigilante' ); ?></th>
6119 <th style="width: 90px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6120 <th style="width: 110px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6121 <th><?php esc_html_e( 'Reason', 'vigilante' ); ?></th>
6122 <th style="width: 130px;"><?php esc_html_e( 'Detected', 'vigilante' ); ?></th>
6123 <th style="width: 90px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6124 </tr>
6125 </thead>
6126 <tbody>
6127 <?php foreach ( $closed_plugins as $cp_slug => $cp_entry ) :
6128 $cp_state = $cp_entry['state'] ?? '';
6129 $cp_state_label = 'closed' === $cp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6130 $cp_state_color = 'closed' === $cp_state ? '#d63638' : '#b32d2e';
6131 $cp_reason = '';
6132 if ( ! empty( $cp_entry['closed_reason_text'] ) ) {
6133 $cp_reason = $cp_entry['closed_reason_text'];
6134 } elseif ( 'removed' === $cp_state ) {
6135 $cp_reason = __( 'Removed from repository (metadata hidden, typical of Security Issue closures)', 'vigilante' );
6136 }
6137 $cp_detected = isset( $cp_entry['first_detected'] ) ? (int) $cp_entry['first_detected'] : 0;
6138 ?>
6139 <tr>
6140 <td>
6141 <strong><?php echo esc_html( $cp_entry['name'] ?? $cp_slug ); ?></strong><br>
6142 <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>
6143 </td>
6144 <td><?php echo esc_html( $cp_entry['version'] ?? '' ); ?></td>
6145 <td><span style="color: <?php echo esc_attr( $cp_state_color ); ?>; font-weight: 600;"><?php echo esc_html( $cp_state_label ); ?></span></td>
6146 <td><?php echo esc_html( $cp_entry['closed_date'] ?? '' ); ?></td>
6147 <td><?php echo esc_html( $cp_reason ); ?></td>
6148 <td>
6149 <?php echo $cp_detected > 0 ? esc_html( wp_date( $datetime_format, $cp_detected ) ) : '&mdash;'; ?>
6150 </td>
6151 <td>
6152 <button type="button" class="button button-small vigilante-ignore-closed-plugin" data-slug="<?php echo esc_attr( $cp_slug ); ?>">
6153 <?php esc_html_e( 'Ignore', 'vigilante' ); ?>
6154 </button>
6155 </td>
6156 </tr>
6157 <?php endforeach; ?>
6158 </tbody>
6159 </table>
6160 </div>
6161 <?php endif; ?>
6162
6163 <?php if ( ! empty( $regular_modified ) ) : ?>
6164 <div class="vigilante-file-list vigilante-paginated-section" data-bulk-mode="ignore">
6165 <h3><?php esc_html_e( 'Modified Files', 'vigilante' ); ?></h3>
6166 <p class="description"><?php esc_html_e( 'These files (apparently) differ from the original WordPress or plugin versions.', 'vigilante' ); ?></p>
6167 <div class="vigilante-fi-bulk-bar">
6168 <button type="button" class="button vigilante-bulk-ignore" disabled><?php esc_html_e( 'Ignore selected', 'vigilante' ); ?></button>
6169 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6170 </div>
6171 <div class="vigilante-fi-pagination-wrap"></div>
6172 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6173 <thead>
6174 <tr>
6175 <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>
6176 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6177 <th style="width: 100px;"><?php esc_html_e( 'Type', 'vigilante' ); ?></th>
6178 <th style="width: 80px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6179 </tr>
6180 </thead>
6181 <tbody>
6182 <?php
6183 foreach ( $regular_modified as $item ) {
6184 $file_path = '';
6185 $file_type = 'unknown';
6186
6187 if ( is_array( $item ) ) {
6188 if ( isset( $item['file'] ) ) {
6189 $file_path = $item['file'];
6190 }
6191 if ( isset( $item['type'] ) ) {
6192 $file_type = $item['type'];
6193 }
6194 } else {
6195 $file_path = (string) $item;
6196 }
6197 ?>
6198 <tr>
6199 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file_path ); ?>"></th>
6200 <td><code><?php echo esc_html( $file_path ); ?></code></td>
6201 <td><?php echo esc_html( $file_type ); ?></td>
6202 <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>
6203 </tr>
6204 <?php
6205 }
6206 ?>
6207 </tbody>
6208 </table>
6209 </div>
6210 <?php endif; ?>
6211
6212 <?php if ( $last_results && empty( $last_results['modified'] ) && empty( $last_results['suspicious'] ) && empty( $last_results['extra'] ) && ! $has_closed ) : ?>
6213 <p class="vigilante-all-clear" style="color: #00a32a; font-weight: bold;">
6214 <?php esc_html_e( 'Good Job! All files passed integrity check. No issues found.', 'vigilante' ); ?>
6215 </p>
6216 <?php endif; ?>
6217 <?php endif; ?>
6218 </div>
6219 </div>
6220 <?php endif; ?>
6221
6222 <?php if ( ! empty( $ignored_closed_plugins ) ) : ?>
6223 <div id="vigilante-section-fi-ignored-closed" class="vigilante-settings-section">
6224 <h2><?php esc_html_e( 'Ignored Closed + Removed Plugins', 'vigilante' ); ?></h2>
6225 <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>
6226 <table class="wp-list-table widefat fixed striped">
6227 <thead>
6228 <tr>
6229 <th><?php esc_html_e( 'Plugin', 'vigilante' ); ?></th>
6230 <th style="width: 110px;"><?php esc_html_e( 'State', 'vigilante' ); ?></th>
6231 <th style="width: 120px;"><?php esc_html_e( 'Closed date', 'vigilante' ); ?></th>
6232 <th style="width: 130px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6233 </tr>
6234 </thead>
6235 <tbody>
6236 <?php foreach ( $ignored_closed_plugins as $icp_slug => $icp_entry ) :
6237 $icp_state = $icp_entry['state'] ?? '';
6238 $icp_state_label = 'closed' === $icp_state ? __( 'Closed', 'vigilante' ) : __( 'Removed', 'vigilante' );
6239 ?>
6240 <tr>
6241 <td>
6242 <strong><?php echo esc_html( $icp_entry['name'] ?? $icp_slug ); ?></strong><br>
6243 <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>
6244 </td>
6245 <td><?php echo esc_html( $icp_state_label ); ?></td>
6246 <td><?php echo esc_html( $icp_entry['closed_date'] ?? '' ); ?></td>
6247 <td>
6248 <button type="button" class="button button-small vigilante-unignore-closed-plugin" data-slug="<?php echo esc_attr( $icp_slug ); ?>">
6249 <?php esc_html_e( 'Stop ignoring', 'vigilante' ); ?>
6250 </button>
6251 </td>
6252 </tr>
6253 <?php endforeach; ?>
6254 </tbody>
6255 </table>
6256 <p style="margin-top: 10px;">
6257 <button type="button" class="button vigilante-clear-ignored-closed-plugins"><?php esc_html_e( 'Clear All Ignored Closed + Removed Plugins', 'vigilante' ); ?></button>
6258 </p>
6259 </div>
6260 <?php endif; ?>
6261
6262 <?php if ( ! empty( $ignored_files ) ) : ?>
6263 <div id="vigilante-section-fi-ignored" class="vigilante-settings-section">
6264 <h2><?php esc_html_e( 'Ignored Files', 'vigilante' ); ?></h2>
6265 <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>
6266 <div class="vigilante-paginated-section" data-bulk-mode="unignore">
6267 <div class="vigilante-fi-bulk-bar">
6268 <button type="button" class="button vigilante-bulk-unignore" disabled><?php esc_html_e( 'Stop ignoring selected', 'vigilante' ); ?></button>
6269 <span class="vigilante-fi-bulk-count" aria-live="polite"></span>
6270 </div>
6271 <div class="vigilante-fi-pagination-wrap"></div>
6272 <table class="wp-list-table widefat fixed striped vigilante-fi-paginated">
6273 <thead>
6274 <tr>
6275 <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>
6276 <th><?php esc_html_e( 'File', 'vigilante' ); ?></th>
6277 <th style="width: 120px;"><?php esc_html_e( 'Actions', 'vigilante' ); ?></th>
6278 </tr>
6279 </thead>
6280 <tbody>
6281 <?php foreach ( $ignored_files as $file ) : ?>
6282 <tr>
6283 <th scope="row" class="check-column"><input type="checkbox" class="vigilante-fi-cb" value="<?php echo esc_attr( $file ); ?>"></th>
6284 <td><code><?php echo esc_html( $file ); ?></code></td>
6285 <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>
6286 </tr>
6287 <?php endforeach; ?>
6288 </tbody>
6289 </table>
6290 </div>
6291 <p style="margin-top: 10px;">
6292 <button type="button" class="button vigilante-clear-ignored"><?php esc_html_e( 'Clear All Ignored Files', 'vigilante' ); ?></button>
6293 </p>
6294 </div>
6295 <?php endif; ?>
6296 <?php
6297 }
6298
6299 /**
6300 * Render sidebar with promotional widgets
6301 */
6302 private function render_sidebar() {
6303 $promo_banner = new Vigilante_Promo_Banner( 'vigilante' );
6304 $promo_banner->render();
6305 }
6306
6307 /**
6308 * AJAX: Download a ZIP backup of the critical config files.
6309 *
6310 * Streams wp-config.php and .htaccess (and robots.txt if present) as a
6311 * downloadable archive. Config backups are no longer left as files under the
6312 * web root, so this hands the admin the archive directly.
6313 */
6314 public function ajax_download_files_backup() {
6315 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6316
6317 if ( ! current_user_can( 'manage_options' ) ) {
6318 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
6319 }
6320
6321 $backup_manager = new Vigilante_Backup_Manager();
6322 $result = $backup_manager->stream_files_zip();
6323
6324 // stream_files_zip() exits on success; only a WP_Error returns here.
6325 if ( is_wp_error( $result ) ) {
6326 wp_die( esc_html( $result->get_error_message() ), 500 );
6327 }
6328 }
6329
6330 /**
6331 * AJAX: Save settings
6332 */
6333 public function ajax_save_settings() {
6334 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6335
6336 if ( ! current_user_can( 'manage_options' ) ) {
6337 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6338 }
6339
6340 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
6341
6342 // Handle $_POST['data'] based on type
6343 if ( isset( $_POST['data'] ) && is_array( $_POST['data'] ) ) {
6344 $data = map_deep( wp_unslash( $_POST['data'] ), 'sanitize_text_field' );
6345 } elseif ( isset( $_POST['data'] ) ) {
6346 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
6347 $raw_data = wp_unslash( $_POST['data'] );
6348 parse_str( $raw_data, $data );
6349 $data = map_deep( $data, 'sanitize_textarea_field' );
6350 } else {
6351 $data = array();
6352 }
6353
6354 if ( empty( $section ) ) {
6355 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
6356 }
6357
6358 // Check if 2FA is being enabled or method changed (for notification sending)
6359 $send_2fa_notification = false;
6360 $send_login_url_notification = false;
6361
6362 if ( 'login_security' === $section ) {
6363 // Read old state from DB
6364 $db_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6365 $old_2fa_enabled = ! empty( $db_options['login_security']['two_factor']['enabled'] );
6366 $old_method = $db_options['login_security']['two_factor']['method'] ?? 'email';
6367
6368 // Check new state from submitted data
6369 $new_2fa_enabled = false;
6370 $notify_on_enable = false;
6371 $new_method = isset( $data['login_security']['two_factor']['method'] )
6372 ? sanitize_key( $data['login_security']['two_factor']['method'] )
6373 : 'email';
6374
6375 if ( isset( $data['login_security']['two_factor']['enabled'] ) ) {
6376 $new_2fa_enabled = filter_var( $data['login_security']['two_factor']['enabled'], FILTER_VALIDATE_BOOLEAN );
6377 }
6378 if ( isset( $data['login_security']['two_factor']['notify_on_enable'] ) ) {
6379 $notify_on_enable = filter_var( $data['login_security']['two_factor']['notify_on_enable'], FILTER_VALIDATE_BOOLEAN );
6380 }
6381
6382 // Send notification if:
6383 // 1. 2FA is being enabled (was off, now on) OR
6384 // 2. Method changed while 2FA is enabled
6385 if ( $notify_on_enable && $new_2fa_enabled ) {
6386 if ( ! $old_2fa_enabled || ( $old_2fa_enabled && $old_method !== $new_method ) ) {
6387 $send_2fa_notification = true;
6388 }
6389 }
6390
6391 // Check if login URL changed and notification is enabled
6392 $old_login_url = $db_options['login_security']['custom_login_url'] ?? '';
6393 $new_login_url = isset( $data['login_security']['custom_login_url'] )
6394 ? sanitize_title( $data['login_security']['custom_login_url'] )
6395 : '';
6396 $notify_on_url_change = isset( $data['login_security']['notify_on_login_url_change'] )
6397 ? filter_var( $data['login_security']['notify_on_login_url_change'], FILTER_VALIDATE_BOOLEAN )
6398 : false;
6399
6400 if ( $notify_on_url_change && ! empty( $new_login_url ) && $new_login_url !== $old_login_url ) {
6401 $send_login_url_notification = true;
6402 }
6403 }
6404
6405 // Get defaults
6406 $defaults = $this->settings->get_default_options();
6407
6408 // Read ONLY saved options from database (not merged with defaults)
6409 $saved_options = get_option( Vigilante_Settings::OPTION_NAME, array() );
6410
6411 $rejected_ips = array();
6412
6413 // Handle modules
6414 if ( 'modules' === $section && isset( $data['modules'] ) ) {
6415 if ( ! isset( $saved_options['modules'] ) ) {
6416 $saved_options['modules'] = array();
6417 }
6418 foreach ( $data['modules'] as $module => $enabled ) {
6419 $module = sanitize_key( $module );
6420 $saved_options['modules'][ $module ] = in_array( $enabled, array( '1', 1, 'true', true ), true );
6421 }
6422 // Clear active preset when modules change
6423 update_option( 'vigilante_active_preset', '' );
6424 } else {
6425 // Process primary section
6426 if ( isset( $data[ $section ] ) && is_array( $data[ $section ] ) ) {
6427 $section_defaults = isset( $defaults[ $section ] ) ? $defaults[ $section ] : array();
6428 $current_section = isset( $saved_options[ $section ] ) ? $saved_options[ $section ] : array();
6429
6430 // Process the submitted data
6431 $processed = $this->process_section_data( $data[ $section ], $section_defaults, $current_section );
6432
6433 // The IP boxes are free text and, until 2.9.9, whatever was typed
6434 // went straight into the option. An entry the matcher can never
6435 // match still sits in a security list looking like protection,
6436 // so the ones that cannot match are dropped and reported back
6437 // instead of being stored in silence.
6438 $rejected_ips = $this->filter_ip_lists( $section, $processed );
6439
6440 // Save the processed section
6441 $saved_options[ $section ] = $processed;
6442
6443 // Clear active preset when any section settings change
6444 update_option( 'vigilante_active_preset', '' );
6445 }
6446 }
6447
6448 // Clear cache before saving
6449 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
6450
6451 // Save to database
6452 update_option( Vigilante_Settings::OPTION_NAME, $saved_options );
6453
6454 // Clear the settings cache
6455 $this->settings->clear_cache();
6456
6457 // Apply changes based on section
6458 $this->apply_section_changes( $section, $saved_options );
6459
6460 // Send 2FA notifications after settings are saved
6461 $notification_result = null;
6462 if ( $send_2fa_notification ) {
6463 $notification_result = $this->send_2fa_enable_notifications();
6464 }
6465
6466 // Send login URL notifications after settings are saved
6467 $login_url_result = null;
6468 if ( $send_login_url_notification ) {
6469 $login_url_result = $this->send_login_url_notifications();
6470 }
6471
6472 // Build success message
6473 $message = __( 'Settings saved successfully.', 'vigilante' );
6474
6475 if ( $notification_result && $notification_result['sent'] > 0 ) {
6476 $message .= ' ' . sprintf(
6477 /* translators: %d: Number of emails sent */
6478 _n(
6479 '2FA notification sent to %d user.',
6480 '2FA notifications sent to %d users.',
6481 $notification_result['sent'],
6482 'vigilante'
6483 ),
6484 $notification_result['sent']
6485 );
6486 }
6487
6488 if ( $login_url_result && $login_url_result['sent'] > 0 ) {
6489 $message .= ' ' . sprintf(
6490 /* translators: %d: Number of emails sent */
6491 _n(
6492 'Login URL notification sent to %d user.',
6493 'Login URL notifications sent to %d users.',
6494 $login_url_result['sent'],
6495 'vigilante'
6496 ),
6497 $login_url_result['sent']
6498 );
6499 }
6500
6501 if ( ! empty( $rejected_ips ) ) {
6502 $message .= ' ' . sprintf(
6503 /* translators: %s: comma separated list of the entries that were not saved. */
6504 _n(
6505 'This entry is not a valid IP, CIDR range or wildcard, so it was not saved: %s',
6506 'These entries are not valid IPs, CIDR ranges or wildcards, so they were not saved: %s',
6507 count( $rejected_ips ),
6508 'vigilante'
6509 ),
6510 implode( ', ', array_map( 'esc_html', $rejected_ips ) )
6511 );
6512 }
6513
6514 wp_send_json_success( $message );
6515 }
6516
6517 /**
6518 * Keep only the IP patterns the matcher can actually match
6519 *
6520 * @since 2.9.9
6521 *
6522 * @param string $section Section being saved.
6523 * @param array $processed Section data, edited in place.
6524 * @return array Entries that were dropped, for the message back to the user.
6525 */
6526 private function filter_ip_lists( $section, &$processed ) {
6527 $lists = array(
6528 'firewall' => array( 'ip_whitelist', 'ip_blacklist' ),
6529 'login_security' => array( 'ip_whitelist' ),
6530 );
6531
6532 if ( ! isset( $lists[ $section ] ) ) {
6533 return array();
6534 }
6535
6536 $rejected = array();
6537
6538 foreach ( $lists[ $section ] as $key ) {
6539 if ( ! isset( $processed[ $key ] ) || ! is_array( $processed[ $key ] ) ) {
6540 continue;
6541 }
6542
6543 $split = Vigilante_IP_Utils::split_list( $processed[ $key ] );
6544 $processed[ $key ] = $split['valid'];
6545 $rejected = array_merge( $rejected, $split['rejected'] );
6546 }
6547
6548 return array_values( array_unique( $rejected ) );
6549 }
6550
6551 /**
6552 * Send 2FA enable notifications to users
6553 *
6554 * @return array Result with 'sent' and 'failed' counts.
6555 */
6556 private function send_2fa_enable_notifications() {
6557 $result = array(
6558 'sent' => 0,
6559 'failed' => 0,
6560 );
6561
6562 // Get settings for roles and method
6563 $login_security = $this->settings->get_section( 'login_security' );
6564 $two_factor = isset( $login_security['two_factor'] ) ? $login_security['two_factor'] : array();
6565 $roles = isset( $two_factor['enforced_roles'] ) ? $two_factor['enforced_roles'] : array( 'administrator' );
6566 $method = isset( $two_factor['method'] ) ? $two_factor['method'] : 'email';
6567
6568 if ( empty( $roles ) ) {
6569 $roles = array( 'administrator' );
6570 }
6571
6572 $excluded = isset( $two_factor['excluded_users'] ) ? array_map( 'absint', $two_factor['excluded_users'] ) : array();
6573
6574 // Get users with these roles
6575 $args = array(
6576 'role__in' => $roles,
6577 );
6578 if ( ! empty( $excluded ) ) {
6579 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Small excluded users list from settings.
6580 $args['exclude'] = $excluded;
6581 }
6582 $users = get_users( $args );
6583
6584 if ( empty( $users ) ) {
6585 return $result;
6586 }
6587
6588 $site_name = get_bloginfo( 'name' );
6589 $from_name = ! empty( $two_factor['email_from_name'] ) ? $two_factor['email_from_name'] : $site_name;
6590
6591 if ( 'totp' === $method ) {
6592 // Use TOTP class for styled HTML emails
6593 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
6594 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
6595 }
6596 $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
6597
6598 foreach ( $users as $user ) {
6599 // Skip users who already have TOTP configured
6600 $totp_data = $this->database->get_totp_data( $user->ID );
6601 if ( $totp_data && ! empty( $totp_data['is_configured'] ) ) {
6602 continue;
6603 }
6604
6605 $sent = $totp->send_activation_email( $user, $site_name, $from_name );
6606
6607 if ( $sent ) {
6608 $this->database->mark_2fa_notified( $user->ID );
6609 $result['sent']++;
6610 } else {
6611 $result['failed']++;
6612 }
6613 }
6614 } else {
6615 // Email method - use existing email 2FA class
6616 if ( ! class_exists( 'Vigilante_Two_Factor_Email' ) ) {
6617 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-email.php';
6618 }
6619 $email_2fa = new Vigilante_Two_Factor_Email( $this->settings, $this->database, $this->activity_log );
6620 return $email_2fa->send_activation_notifications( false );
6621 }
6622
6623 return $result;
6624 }
6625
6626 /**
6627 * Send login URL change notifications to users with admin access
6628 *
6629 * @return array Result with 'sent' and 'failed' counts.
6630 */
6631 private function send_login_url_notifications() {
6632 $login_options = $this->settings->get_section( 'login_security' );
6633 $custom_url = ! empty( $login_options['custom_login_url'] ) ? sanitize_title( $login_options['custom_login_url'] ) : '';
6634
6635 if ( empty( $custom_url ) ) {
6636 return array( 'sent' => 0, 'failed' => 0 );
6637 }
6638
6639 $login_url = home_url( $custom_url . '/' );
6640 $site_name = get_bloginfo( 'name' );
6641
6642 $admin_roles = array( 'administrator', 'editor', 'author', 'contributor' );
6643 $users = get_users( array( 'role__in' => $admin_roles ) );
6644
6645 if ( empty( $users ) ) {
6646 return array( 'sent' => 0, 'failed' => 0 );
6647 }
6648
6649 $subject = sprintf(
6650 /* translators: %s: Site name */
6651 __( '[%s] Your login URL has changed', 'vigilante' ),
6652 $site_name
6653 );
6654
6655 $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' ) );
6656 $body .= Vigilante_Email_Template::url_box( $login_url, __( 'Your new login URL:', 'vigilante' ) );
6657 $body .= Vigilante_Email_Template::alert_box( __( 'The old login address (wp-login.php) will no longer work.', 'vigilante' ) );
6658 $body .= Vigilante_Email_Template::button( $login_url, __( 'Go to login', 'vigilante' ) );
6659
6660 $sent = 0;
6661 $failed = 0;
6662
6663 foreach ( $users as $user ) {
6664 $result = Vigilante_Email_Template::send(
6665 $user->user_email,
6666 $subject,
6667 __( 'Login URL changed', 'vigilante' ),
6668 $body
6669 );
6670 if ( $result ) {
6671 $sent++;
6672 } else {
6673 $failed++;
6674 }
6675 }
6676
6677 if ( $this->activity_log ) {
6678 $this->activity_log->log(
6679 'login',
6680 'login_url_notified',
6681 sprintf(
6682 /* translators: 1: Sent count, 2: Failed count */
6683 __( 'Login URL notification sent on save: %1$d sent, %2$d failed', 'vigilante' ),
6684 $sent,
6685 $failed
6686 )
6687 );
6688 }
6689
6690 return array( 'sent' => $sent, 'failed' => $failed );
6691 }
6692
6693 /**
6694 * Process section data maintaining proper types from defaults
6695 *
6696 * @param array $submitted_data Data submitted from form.
6697 * @param array $defaults Default values for this section.
6698 * @param array $current Current saved values.
6699 * @param string $section_name Section name for special handling.
6700 * @return array Processed data.
6701 */
6702 private function process_section_data( $submitted_data, $defaults, $current, $section_name = '' ) {
6703 // Start with defaults, then merge current saved values
6704 $result = array_replace_recursive( $defaults, $current );
6705
6706 // Process each submitted value
6707 foreach ( $submitted_data as $key => $value ) {
6708 $key = sanitize_key( $key );
6709
6710 if ( is_array( $value ) ) {
6711 // Nested array (like rate_limiting)
6712 $nested_defaults = isset( $defaults[ $key ] ) && is_array( $defaults[ $key ] ) ? $defaults[ $key ] : array();
6713 $nested_current = isset( $result[ $key ] ) && is_array( $result[ $key ] ) ? $result[ $key ] : array();
6714 $result[ $key ] = $this->process_section_data( $value, $nested_defaults, $nested_current, $key );
6715 } else {
6716 // Determine type from default value
6717 $default_value = isset( $defaults[ $key ] ) ? $defaults[ $key ] : null;
6718
6719 if ( null === $default_value ) {
6720 // No default, check current value type or use as string
6721 $current_value = isset( $current[ $key ] ) ? $current[ $key ] : null;
6722 if ( is_bool( $current_value ) ) {
6723 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6724 } elseif ( is_int( $current_value ) ) {
6725 $result[ $key ] = intval( $value );
6726 } elseif ( is_array( $current_value ) ) {
6727 $result[ $key ] = is_string( $value ) ? array_filter( array_map( 'trim', explode( "\n", $value ) ) ) : (array) $value;
6728 } else {
6729 $result[ $key ] = sanitize_text_field( $value );
6730 }
6731 } elseif ( is_bool( $default_value ) ) {
6732 // Boolean: '1', 1, 'true' become true; '0', 0, '', 'false' become false
6733 $result[ $key ] = in_array( $value, array( '1', 1, 'true', true ), true );
6734 } elseif ( is_int( $default_value ) ) {
6735 // Integer - with special handling for time fields shown in minutes
6736 $int_value = intval( $value );
6737
6738 // Convert minutes to seconds for login_security duration fields
6739 // These are displayed as minutes in the form but stored as seconds
6740 if ( in_array( $key, array( 'lockout_duration', 'max_lockout_duration' ), true ) ) {
6741 $int_value = $int_value * 60;
6742 }
6743
6744 $result[ $key ] = $int_value;
6745 } elseif ( is_array( $default_value ) ) {
6746 // Array from textarea (e.g., IP lists)
6747 if ( is_string( $value ) ) {
6748 $result[ $key ] = array_filter( array_map( 'trim', explode( "\n", $value ) ) );
6749 } else {
6750 $result[ $key ] = (array) $value;
6751 }
6752 } else {
6753 // String - preserve newlines for textarea fields
6754 if ( is_string( $value ) && ( strpos( $value, "\n" ) !== false || strpos( $value, "\r" ) !== false ) ) {
6755 $result[ $key ] = sanitize_textarea_field( $value );
6756 } else {
6757 $result[ $key ] = sanitize_text_field( $value );
6758 }
6759 }
6760 }
6761 }
6762
6763 // Handle unchecked checkboxes: HTML forms don't submit unchecked boxes
6764 // If a boolean field exists in defaults but NOT in submitted_data, set it to false
6765 //
6766 // EXCEPTION: the top-level 'enabled' flag of every section is the
6767 // module's master switch and is controlled by the Dashboard module
6768 // toggle, NOT by a checkbox inside the section's form. Treating it
6769 // like a regular checkbox here would silently switch the module off
6770 // every time the user saves the tab — see the REST API enabled=false
6771 // regression. We only skip it at the top level (when section_name is
6772 // empty); nested 'enabled' fields like security_headers.csp.enabled
6773 // are real checkboxes and must keep the auto-unset behaviour.
6774 $preserve_top_level = array( 'enabled' );
6775
6776 foreach ( $defaults as $key => $default_value ) {
6777 if ( '' === $section_name && in_array( $key, $preserve_top_level, true ) ) {
6778 continue;
6779 }
6780 if ( is_bool( $default_value ) && ! array_key_exists( $key, $submitted_data ) ) {
6781 $result[ $key ] = false;
6782 } elseif ( is_array( $default_value ) && ! isset( $submitted_data[ $key ] ) ) {
6783 // Check if this is a flat value list (like excluded_users, enforced_roles, ip_whitelist)
6784 // vs a nested settings group (like rate_limiting, two_factor)
6785 // Flat lists: default is empty array OR all values are scalar
6786 $is_value_list = empty( $default_value );
6787 if ( ! $is_value_list ) {
6788 $is_value_list = true;
6789 foreach ( $default_value as $dv ) {
6790 if ( ! is_scalar( $dv ) ) {
6791 $is_value_list = false;
6792 break;
6793 }
6794 }
6795 }
6796
6797 if ( $is_value_list ) {
6798 // All items removed - reset to empty array
6799 $result[ $key ] = array();
6800 } else {
6801 // Nested settings group - handle boolean children
6802 foreach ( $default_value as $nested_key => $nested_default ) {
6803 if ( is_bool( $nested_default ) && isset( $result[ $key ] ) && is_array( $result[ $key ] ) ) {
6804 $nested_submitted = isset( $submitted_data[ $key ] ) && is_array( $submitted_data[ $key ] )
6805 ? $submitted_data[ $key ]
6806 : array();
6807 if ( ! array_key_exists( $nested_key, $nested_submitted ) ) {
6808 $result[ $key ][ $nested_key ] = false;
6809 }
6810 }
6811 }
6812 }
6813 }
6814 }
6815
6816 return $result;
6817 }
6818
6819 /**
6820 * AJAX: Export settings
6821 */
6822 public function ajax_export_settings() {
6823 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6824
6825 if ( ! current_user_can( 'manage_options' ) ) {
6826 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6827 }
6828
6829 $options = $this->settings->get_all_options();
6830 $filename = 'vigilante-settings-' . gmdate( 'Y-m-d-His' ) . '.json';
6831
6832 wp_send_json_success( array(
6833 'content' => wp_json_encode( $options, JSON_PRETTY_PRINT ),
6834 'filename' => $filename,
6835 ) );
6836 }
6837
6838 /**
6839 * AJAX: Import settings
6840 */
6841 public function ajax_import_settings() {
6842 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
6843
6844 if ( ! current_user_can( 'manage_options' ) ) {
6845 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
6846 }
6847
6848 // Accept both 'settings' (from JS) and 'content' (legacy).
6849 // Do NOT run sanitize_text_field() on the raw payload: it calls
6850 // wp_strip_all_tags() internally, which removes any "<...>" substring
6851 // and turns a valid export JSON into garbage if any stored value
6852 // contains < or > (htaccess snippets, email templates, etc.). The
6853 // real sanitization happens after json_decode(), via map_deep() on
6854 // the parsed array.
6855 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
6856 $content = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '';
6857 if ( empty( $content ) ) {
6858 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
6859 $content = isset( $_POST['content'] ) ? wp_unslash( $_POST['content'] ) : '';
6860 }
6861
6862 if ( empty( $content ) || ! is_string( $content ) ) {
6863 wp_send_json_error( __( 'No content provided.', 'vigilante' ) );
6864 }
6865
6866 $imported = json_decode( $content, true );
6867
6868 if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $imported ) ) {
6869 wp_send_json_error( __( 'Invalid JSON format.', 'vigilante' ) );
6870 }
6871
6872 // Sanitize imported data recursively
6873 $imported = map_deep( $imported, 'sanitize_text_field' );
6874
6875 // Validate structure
6876 $defaults = $this->settings->get_default_options();
6877 $merged = array_replace_recursive( $defaults, $imported );
6878
6879 // Save
6880 update_option( Vigilante_Settings::OPTION_NAME, $merged );
6881 $this->settings->clear_cache();
6882
6883 // Re-evaluate the active preset marker. The imported config may match
6884 // a known preset exactly, partially, or not at all — without this step
6885 // the dashboard would keep showing whatever preset was active before
6886 // the import even if the new config no longer matches it.
6887 $matched_preset = $this->detect_matching_preset( $merged );
6888 if ( null === $matched_preset ) {
6889 delete_option( 'vigilante_active_preset' );
6890 } else {
6891 update_option( 'vigilante_active_preset', $matched_preset );
6892 }
6893
6894 // Apply file changes after import
6895 $this->apply_all_file_changes( $merged );
6896
6897 // Refresh the Security Analyzer score so the dashboard widget reflects
6898 // the imported config rather than the pre-import scan. Reuse the
6899 // post-Under-Attack scan hook (same job: full scan, async).
6900 if ( ! wp_next_scheduled( 'vigilante_under_attack_post_scan' ) ) {
6901 wp_schedule_single_event( time() + 5, 'vigilante_under_attack_post_scan' );
6902 }
6903
6904 wp_send_json_success( __( 'Settings imported successfully.', 'vigilante' ) );
6905 }
6906
6907 /**
6908 * Detect whether a vigilante_options array matches a known preset.
6909 *
6910 * A preset matches when every field the preset explicitly declares is
6911 * present in the config with the same (normalised) value. Fields outside
6912 * the preset are ignored — they may have been modified by the user before
6913 * applying the preset and do not invalidate the match. This mirrors how
6914 * apply_preset() now layers presets on top of the user's existing config.
6915 *
6916 * @param array $options The current/imported vigilante_options.
6917 * @return string|null Preset id ('standard', 'maximum') or null if custom.
6918 */
6919 private function detect_matching_preset( $options ) {
6920 if ( ! is_array( $options ) ) {
6921 return null;
6922 }
6923
6924 $presets = $this->settings->get_presets();
6925
6926 foreach ( $presets as $preset_id => $preset_data ) {
6927 unset( $preset_data['name'], $preset_data['description'] );
6928 if ( $this->preset_subset_matches( $preset_data, $options ) ) {
6929 return $preset_id;
6930 }
6931 }
6932
6933 return null;
6934 }
6935
6936 /**
6937 * Check whether every leaf value inside $preset_subset exists with the
6938 * same (normalised) value at the same path inside $config.
6939 *
6940 * @param mixed $preset_subset Branch of the preset definition.
6941 * @param mixed $config Same branch in the live/imported config.
6942 * @return bool
6943 */
6944 private function preset_subset_matches( $preset_subset, $config ) {
6945 if ( is_array( $preset_subset ) ) {
6946 if ( ! is_array( $config ) ) {
6947 return false;
6948 }
6949 foreach ( $preset_subset as $key => $value ) {
6950 if ( ! array_key_exists( $key, $config ) ) {
6951 return false;
6952 }
6953 if ( ! $this->preset_subset_matches( $value, $config[ $key ] ) ) {
6954 return false;
6955 }
6956 }
6957 return true;
6958 }
6959
6960 return $this->normalise_scalar_for_compare( $preset_subset ) === $this->normalise_scalar_for_compare( $config );
6961 }
6962
6963 /**
6964 * Normalise a scalar value so that the variants WordPress and the form
6965 * layer routinely produce ('1' / 1 / true → "1"; '' / '0' / 0 / false /
6966 * null → "") compare equal. Other values become strings unchanged.
6967 *
6968 * @param mixed $value
6969 * @return string
6970 */
6971 private function normalise_scalar_for_compare( $value ) {
6972 if ( is_bool( $value ) ) {
6973 return $value ? '1' : '';
6974 }
6975 if ( null === $value ) {
6976 return '';
6977 }
6978 if ( is_int( $value ) || is_float( $value ) ) {
6979 return (string) $value;
6980 }
6981 if ( is_string( $value ) ) {
6982 if ( 'true' === $value ) {
6983 return '1';
6984 }
6985 if ( 'false' === $value ) {
6986 return '';
6987 }
6988 return $value;
6989 }
6990 // Arrays and objects shouldn't reach here (handled by recursion above),
6991 // but if they do, fall back to a stable comparable representation.
6992 return wp_json_encode( $value );
6993 }
6994
6995 /**
6996 * AJAX: Apply preset
6997 */
6998 public function ajax_apply_preset() {
6999 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7000
7001 if ( ! current_user_can( 'manage_options' ) ) {
7002 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7003 }
7004
7005 $preset = isset( $_POST['preset'] ) ? sanitize_key( $_POST['preset'] ) : '';
7006
7007 // Handle reset to defaults
7008 if ( 'reset' === $preset ) {
7009 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( get_option( Vigilante_Settings::OPTION_NAME, array() ) );
7010 update_option( Vigilante_Settings::OPTION_NAME, $defaults );
7011 $this->settings->clear_cache();
7012
7013 // Clear active preset
7014 update_option( 'vigilante_active_preset', '' );
7015
7016 // Apply file changes after reset
7017 $this->apply_all_file_changes( $defaults );
7018
7019 wp_send_json_success( __( 'Settings reset to defaults.', 'vigilante' ) );
7020 return;
7021 }
7022
7023 $presets = $this->settings->get_presets();
7024
7025 if ( ! isset( $presets[ $preset ] ) ) {
7026 wp_send_json_error( __( 'Invalid preset.', 'vigilante' ) );
7027 }
7028
7029 $preset_options = $presets[ $preset ];
7030 unset( $preset_options['name'], $preset_options['description'] );
7031
7032 // Layer the preset on top of the user's CURRENT configuration, not on
7033 // top of defaults. This way applying a preset only changes the fields
7034 // the preset explicitly mentions; everything else stays as the user
7035 // had it. For example, applying Maximum will not flip HSTS off if the
7036 // user had it on — Maximum doesn't touch HSTS, so it's left alone.
7037 // Use "Reset to Defaults" if a clean slate is needed.
7038 $current = get_option( Vigilante_Settings::OPTION_NAME, array() );
7039 if ( ! is_array( $current ) ) {
7040 $current = array();
7041 }
7042 // Make sure all known keys exist before merging — the merge does not
7043 // invent keys that are missing on both sides.
7044 $current = Vigilante_Settings::merge_preset( $this->settings->get_default_options(), $current );
7045
7046 $merged = Vigilante_Settings::merge_preset( $current, $preset_options );
7047
7048 update_option( Vigilante_Settings::OPTION_NAME, $merged );
7049 $this->settings->clear_cache();
7050
7051 // Save active preset
7052 update_option( 'vigilante_active_preset', $preset );
7053
7054 // Apply file changes after preset
7055 $this->apply_all_file_changes( $merged );
7056
7057 wp_send_json_success( __( 'Preset applied successfully.', 'vigilante' ) );
7058 }
7059
7060 /**
7061 * AJAX: Reset a specific section to defaults
7062 */
7063 public function ajax_reset_section() {
7064 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7065
7066 if ( ! current_user_can( 'manage_options' ) ) {
7067 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7068 }
7069
7070 $section = isset( $_POST['section'] ) ? sanitize_key( $_POST['section'] ) : '';
7071
7072 if ( empty( $section ) ) {
7073 wp_send_json_error( __( 'No section specified.', 'vigilante' ) );
7074 }
7075
7076 // Get current options and defaults. get_defaults_preserving_user_data()
7077 // applies the tweaks a fresh installation gets, so the button and a new
7078 // install agree, and keeps whatever the owner typed in.
7079 $current_options = $this->settings->get_all_options();
7080 $defaults = Vigilante_Settings::get_defaults_preserving_user_data( $current_options );
7081
7082 // Check if section exists in defaults
7083 if ( ! isset( $defaults[ $section ] ) ) {
7084 wp_send_json_error( __( 'Invalid section.', 'vigilante' ) );
7085 }
7086
7087 $new_values = $defaults[ $section ];
7088
7089 /*
7090 * On a subsite, the settings written to wp-config.php and .htaccess are
7091 * the main site's business. Resetting the local copy of those would only
7092 * make this screen disagree with the file, so they are carried over
7093 * untouched, and a section that is nothing but shared settings is not
7094 * reset at all.
7095 */
7096 if ( ! Vigilante_Settings::can_write_shared_files() ) {
7097 $shared = Vigilante_Settings::get_shared_file_settings();
7098
7099 if ( isset( $shared[ $section ] ) ) {
7100 if ( true === $shared[ $section ] ) {
7101 wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
7102 }
7103
7104 foreach ( $shared[ $section ] as $shared_key ) {
7105 if ( array_key_exists( $shared_key, (array) $current_options[ $section ] ) ) {
7106 $new_values[ $shared_key ] = $current_options[ $section ][ $shared_key ];
7107 }
7108 }
7109 }
7110 }
7111
7112 $current_options[ $section ] = $new_values;
7113
7114 // Save
7115 update_option( Vigilante_Settings::OPTION_NAME, $current_options );
7116 $this->settings->clear_cache();
7117
7118 // Apply file changes if needed
7119 $this->apply_section_changes( $section, $current_options );
7120
7121 wp_send_json_success( array(
7122 'message' => __( 'Section reset to defaults.', 'vigilante' ),
7123 'section' => $section,
7124 'reload' => true,
7125 ) );
7126 }
7127
7128 /**
7129 * AJAX: Clear lockouts
7130 */
7131 public function ajax_clear_lockouts() {
7132 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7133
7134 if ( ! current_user_can( 'manage_options' ) ) {
7135 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7136 }
7137
7138 $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
7139
7140 if ( ! empty( $ip ) ) {
7141 $this->database->clear_lockout( $ip );
7142 } else {
7143 $this->database->clear_all_lockouts();
7144 }
7145
7146 wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
7147 }
7148
7149 /**
7150 * AJAX: Clear logs
7151 */
7152 public function ajax_clear_logs() {
7153 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7154
7155 if ( ! current_user_can( 'manage_options' ) ) {
7156 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7157 }
7158
7159 if ( $this->activity_log ) {
7160 $result = $this->activity_log->clear_all_logs();
7161 if ( $result ) {
7162 wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
7163 } else {
7164 wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
7165 }
7166 } else {
7167 wp_send_json_error( __( 'Activity log not available.', 'vigilante' ) );
7168 }
7169 }
7170
7171 /**
7172 * AJAX: Run file integrity scan.
7173 *
7174 * Triggers the file integrity scan, which now also runs the closed plugins
7175 * check at the end when the `check_closed_plugins` toggle is on. Activity
7176 * log is passed through so Security Audit entries (both file-level and
7177 * plugin-status) are recorded from this entry point.
7178 */
7179 public function ajax_run_scan() {
7180 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7181
7182 if ( ! current_user_can( 'manage_options' ) ) {
7183 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7184 }
7185
7186 // Clear previous results before running new scan
7187 delete_option( 'vigilante_last_integrity_results' );
7188 delete_option( 'vigilante_last_integrity_scan' );
7189
7190 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database, $this->activity_log );
7191 $results = $file_integrity->run_scan();
7192
7193 // Save new results
7194 update_option( 'vigilante_last_integrity_scan', time() );
7195 update_option( 'vigilante_last_integrity_results', $results );
7196
7197 wp_send_json_success( array(
7198 'message' => __( 'Scan completed.', 'vigilante' ),
7199 'results' => $results,
7200 'ignored_count' => count( get_option( 'vigilante_ignored_files', array() ) ),
7201 ) );
7202 }
7203
7204 /**
7205 * AJAX: Clear scan results.
7206 *
7207 * Wipes visually everything inside "Last Scan Results": file scan findings
7208 * (Suspicious / Modified / Extra / Critical Config), file hashes and the
7209 * Closed + Removed Plugins block.
7210 *
7211 * Implementation detail to keep persistence intact:
7212 * - We delete the file scan options + hashes outright.
7213 * - For plugin status we ONLY delete the last_check timestamp — the state
7214 * map and the ignore list are preserved in DB. The render gates the
7215 * plugin_status subsections on last_check > 0, so they hide after
7216 * Clear (visual reset) and reappear on the next Run Scan Now with the
7217 * state intact. This avoids degrading a 'removed' slug (404 without
7218 * metadata) back to 'not_in_repo' on the next scan, which would
7219 * silently lose the alert.
7220 *
7221 * The Ignored Files list and the Ignored Closed + Removed Plugins list
7222 * are preserved on purpose; each has its own explicit "Clear All …"
7223 * button.
7224 */
7225 public function ajax_clear_scan() {
7226 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7227
7228 if ( ! current_user_can( 'manage_options' ) ) {
7229 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7230 }
7231
7232 delete_option( 'vigilante_last_integrity_results' );
7233 delete_option( 'vigilante_last_integrity_scan' );
7234
7235 if ( $this->database ) {
7236 $this->database->clear_file_hashes();
7237 }
7238
7239 // Visual reset of plugin_status block without touching the state map
7240 // or the ignored list. See PHPDoc above for the rationale.
7241 delete_option( 'vigilante_plugin_status_last_check' );
7242
7243 wp_send_json_success( __( 'Scan results cleared.', 'vigilante' ) );
7244 }
7245
7246 /**
7247 * AJAX: Ignore a file from scan results
7248 */
7249 public function ajax_ignore_file() {
7250 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7251
7252 if ( ! current_user_can( 'manage_options' ) ) {
7253 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7254 }
7255
7256 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7257
7258 if ( empty( $file ) ) {
7259 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7260 }
7261
7262 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7263 $file_integrity->ignore_file( $file );
7264
7265 // Also remove the file from stored scan results so UI updates
7266 $results = get_option( 'vigilante_last_integrity_results' );
7267 if ( $results ) {
7268 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7269 if ( ! empty( $results[ $category ] ) ) {
7270 $results[ $category ] = array_values(
7271 array_filter(
7272 $results[ $category ],
7273 function ( $item ) use ( $file ) {
7274 return ( is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item ) !== $file;
7275 }
7276 )
7277 );
7278 }
7279 }
7280 update_option( 'vigilante_last_integrity_results', $results );
7281 }
7282
7283 wp_send_json_success( __( 'File added to ignored list.', 'vigilante' ) );
7284 }
7285
7286 /**
7287 * AJAX: Stop ignoring a file
7288 */
7289 public function ajax_unignore_file() {
7290 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7291
7292 if ( ! current_user_can( 'manage_options' ) ) {
7293 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7294 }
7295
7296 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
7297
7298 if ( empty( $file ) ) {
7299 wp_send_json_error( __( 'No file specified.', 'vigilante' ) );
7300 }
7301
7302 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7303 $file_integrity->unignore_file( $file );
7304
7305 wp_send_json_success( __( 'File removed from ignored list.', 'vigilante' ) );
7306 }
7307
7308 /**
7309 * AJAX: Bulk ignore multiple files at once
7310 *
7311 * Processes a single batch into ignored list and prunes them from the
7312 * stored scan results so the UI updates without a re-scan.
7313 */
7314 public function ajax_bulk_ignore_files() {
7315 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7316
7317 if ( ! current_user_can( 'manage_options' ) ) {
7318 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7319 }
7320
7321 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7322 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7323 if ( ! is_array( $raw_files ) ) {
7324 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7325 }
7326
7327 $files = array();
7328 foreach ( $raw_files as $f ) {
7329 $clean = sanitize_text_field( $f );
7330 if ( '' !== $clean ) {
7331 $files[] = $clean;
7332 }
7333 }
7334
7335 if ( empty( $files ) ) {
7336 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7337 }
7338
7339 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7340 $count = 0;
7341 foreach ( $files as $file ) {
7342 $file_integrity->ignore_file( $file );
7343 $count++;
7344 }
7345
7346 // Also prune the stored scan results so the UI matches the new ignore list.
7347 $results = get_option( 'vigilante_last_integrity_results' );
7348 if ( $results ) {
7349 $files_set = array_flip( $files );
7350 foreach ( array( 'modified', 'suspicious', 'extra' ) as $category ) {
7351 if ( ! empty( $results[ $category ] ) ) {
7352 $results[ $category ] = array_values(
7353 array_filter(
7354 $results[ $category ],
7355 function ( $item ) use ( $files_set ) {
7356 $path = is_array( $item ) ? ( $item['file'] ?? '' ) : (string) $item;
7357 return ! isset( $files_set[ $path ] );
7358 }
7359 )
7360 );
7361 }
7362 }
7363 update_option( 'vigilante_last_integrity_results', $results );
7364 }
7365
7366 wp_send_json_success(
7367 array(
7368 'count' => $count,
7369 'message' => sprintf(
7370 /* translators: %d: number of files added to the ignored list */
7371 _n( '%d file added to ignored list.', '%d files added to ignored list.', $count, 'vigilante' ),
7372 $count
7373 ),
7374 )
7375 );
7376 }
7377
7378 /**
7379 * AJAX: Bulk un-ignore multiple files at once
7380 */
7381 public function ajax_bulk_unignore_files() {
7382 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7383
7384 if ( ! current_user_can( 'manage_options' ) ) {
7385 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7386 }
7387
7388 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below per-item.
7389 $raw_files = isset( $_POST['files'] ) ? wp_unslash( $_POST['files'] ) : array();
7390 if ( ! is_array( $raw_files ) ) {
7391 wp_send_json_error( __( 'Invalid request.', 'vigilante' ) );
7392 }
7393
7394 $files = array();
7395 foreach ( $raw_files as $f ) {
7396 $clean = sanitize_text_field( $f );
7397 if ( '' !== $clean ) {
7398 $files[] = $clean;
7399 }
7400 }
7401
7402 if ( empty( $files ) ) {
7403 wp_send_json_error( __( 'No files selected.', 'vigilante' ) );
7404 }
7405
7406 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7407 $count = 0;
7408 foreach ( $files as $file ) {
7409 $file_integrity->unignore_file( $file );
7410 $count++;
7411 }
7412
7413 wp_send_json_success(
7414 array(
7415 'count' => $count,
7416 'message' => sprintf(
7417 /* translators: %d: number of files removed from the ignored list */
7418 _n( '%d file removed from ignored list.', '%d files removed from ignored list.', $count, 'vigilante' ),
7419 $count
7420 ),
7421 )
7422 );
7423 }
7424
7425 /**
7426 * AJAX: Clear all ignored files
7427 */
7428 public function ajax_clear_ignored() {
7429 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7430
7431 if ( ! current_user_can( 'manage_options' ) ) {
7432 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7433 }
7434
7435 $file_integrity = new Vigilante_File_Integrity( $this->settings, $this->database );
7436 $file_integrity->clear_ignored_files();
7437
7438 wp_send_json_success( __( 'Ignored files list cleared.', 'vigilante' ) );
7439 }
7440
7441 /**
7442 * AJAX: Ignore a closed/removed plugin slug so it stops appearing in the
7443 * main list and email digests. The plugin keeps running on the site;
7444 * silencing is purely cosmetic and reversible.
7445 */
7446 public function ajax_ignore_closed_plugin() {
7447 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7448
7449 if ( ! current_user_can( 'manage_options' ) ) {
7450 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7451 }
7452
7453 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7454 if ( '' === $slug ) {
7455 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7456 }
7457
7458 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7459 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7460 }
7461 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7462 $checker->ignore_slug( $slug );
7463
7464 wp_send_json_success( __( 'Plugin added to the ignored list.', 'vigilante' ) );
7465 }
7466
7467 /**
7468 * AJAX: Stop ignoring a previously-ignored closed/removed plugin slug.
7469 */
7470 public function ajax_unignore_closed_plugin() {
7471 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7472
7473 if ( ! current_user_can( 'manage_options' ) ) {
7474 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7475 }
7476
7477 $slug = isset( $_POST['slug'] ) ? sanitize_key( wp_unslash( $_POST['slug'] ) ) : '';
7478 if ( '' === $slug ) {
7479 wp_send_json_error( __( 'No slug specified.', 'vigilante' ) );
7480 }
7481
7482 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7483 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7484 }
7485 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7486 $checker->unignore_slug( $slug );
7487
7488 wp_send_json_success( __( 'Plugin removed from the ignored list.', 'vigilante' ) );
7489 }
7490
7491 /**
7492 * AJAX: Clear the entire ignored-closed-plugins list.
7493 */
7494 public function ajax_clear_ignored_closed_plugins() {
7495 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7496
7497 if ( ! current_user_can( 'manage_options' ) ) {
7498 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7499 }
7500
7501 if ( ! class_exists( 'Vigilante_Plugin_Status' ) ) {
7502 require_once VIGILANTE_INCLUDES_DIR . 'class-plugin-status.php';
7503 }
7504 $checker = new Vigilante_Plugin_Status( $this->settings, $this->activity_log );
7505 $checker->clear_ignored();
7506
7507 wp_send_json_success( __( 'Ignored closed plugins list cleared.', 'vigilante' ) );
7508 }
7509
7510 /**
7511 * AJAX: Test security headers
7512 */
7513 public function ajax_test_headers() {
7514 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
7515
7516 if ( ! current_user_can( 'manage_options' ) ) {
7517 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
7518 }
7519
7520 // Get security grade from settings (not from actual HTTP request)
7521 $security_headers = new Vigilante_Security_Headers( $this->settings );
7522 $results = $security_headers->get_security_grade();
7523
7524 wp_send_json_success( $results );
7525 }
7526
7527 /**
7528 * Sanitize section data (kept for compatibility)
7529 *
7530 * @param string $section Section name.
7531 * @param array $data Section data.
7532 * @return array
7533 */
7534 private function sanitize_section_data( $section, $data ) {
7535 $sanitized = array();
7536
7537 foreach ( $data as $key => $value ) {
7538 $key = sanitize_key( $key );
7539
7540 if ( is_array( $value ) ) {
7541 $sanitized[ $key ] = $this->sanitize_section_data( $key, $value );
7542 } elseif ( is_numeric( $value ) ) {
7543 $sanitized[ $key ] = intval( $value );
7544 } else {
7545 $sanitized[ $key ] = sanitize_text_field( $value );
7546 }
7547 }
7548
7549 return $sanitized;
7550 }
7551
7552 /**
7553 * Apply changes after saving settings
7554 *
7555 * @param string $section Section that was updated.
7556 * @param array $all_options All options.
7557 */
7558 private function apply_section_changes( $section, $all_options ) {
7559 // Create fresh settings instance to ensure we have the latest data
7560 $fresh_settings = new Vigilante_Settings();
7561
7562 // The shared Vigilant .htaccess block carries BOTH the firewall's
7563 // file-protection rules and the server-signature / fingerprinting rules
7564 // that are configured under Security Headers. So it must be regenerated
7565 // whenever either section (or the module toggles) changes, not only on
7566 // the firewall save — otherwise toggling "Hide server signature" or
7567 // "Remove fingerprinting headers" never reaches the .htaccess.
7568 if ( in_array( $section, array( 'firewall', 'security_headers', 'modules' ), true ) ) {
7569 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7570 $sh = $fresh_settings->get_section( 'security_headers' );
7571 $needs_htaccess_block = ! empty( $all_options['modules']['firewall'] )
7572 || ! empty( $sh['hide_server_signature'] )
7573 || ! empty( $sh['remove_fingerprinting_headers'] );
7574
7575 if ( $needs_htaccess_block ) {
7576 $htaccess->apply_rules();
7577 } else {
7578 $htaccess->remove_rules();
7579 }
7580 }
7581
7582 // Regenerate the HTTP security headers (sent by PHP) for the headers section.
7583 if ( 'security_headers' === $section || 'modules' === $section ) {
7584 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7585 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7586
7587 if ( $headers_enabled ) {
7588 $security_headers->apply_rules();
7589 } else {
7590 $security_headers->remove_rules();
7591 }
7592 }
7593
7594 // Regenerate wp-config for wp_hardening section
7595 if ( 'wp_hardening' === $section || 'modules' === $section ) {
7596 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7597 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7598
7599 if ( $hardening_enabled ) {
7600 $wpconfig->apply_security_constants();
7601 } else {
7602 $wpconfig->remove_constants();
7603 }
7604
7605 // Apply WordPress options for comments/pingbacks
7606 $hardening_options = $all_options['wp_hardening'] ?? array();
7607
7608 if ( $hardening_enabled ) {
7609 // Pingbacks
7610 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7611 update_option( 'default_pingback_flag', 0 );
7612 } else {
7613 // Restore default: pingbacks enabled
7614 update_option( 'default_pingback_flag', 1 );
7615 }
7616
7617 // Trackbacks and ping status
7618 // Only close if either pingbacks OR trackbacks are disabled
7619 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7620 update_option( 'default_ping_status', 'closed' );
7621 } else {
7622 // Restore default: pings open
7623 update_option( 'default_ping_status', 'open' );
7624 }
7625
7626 // Comment moderation
7627 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7628 update_option( 'comment_moderation', 1 );
7629 } else {
7630 // Restore default: no moderation required
7631 update_option( 'comment_moderation', 0 );
7632 }
7633 }
7634 }
7635
7636 // Trim activity log entries immediately when limits change
7637 if ( 'activity_log' === $section && $this->activity_log ) {
7638 $this->activity_log->cleanup_old_logs();
7639 }
7640
7641 // Flush rewrite rules if login URL changed
7642 if ( 'login_security' === $section ) {
7643 $login_options = $all_options['login_security'] ?? array();
7644 if ( ! empty( $login_options['custom_login_url'] ) ) {
7645 delete_option( 'vigilante_login_rules_version' );
7646 }
7647 }
7648
7649 // Log the settings change with readable section name
7650 if ( $this->activity_log ) {
7651 $section_names = array(
7652 'firewall' => __( 'Firewall', 'vigilante' ),
7653 'login_security' => __( 'Login Security', 'vigilante' ),
7654 'security_headers' => __( 'Security Headers', 'vigilante' ),
7655 'rest_api_security'=> __( 'REST API Security', 'vigilante' ),
7656 'user_security' => __( 'User Security', 'vigilante' ),
7657 'wp_hardening' => __( 'WP Hardening', 'vigilante' ),
7658 'activity_log' => __( 'Security Audit', 'vigilante' ),
7659 'file_integrity' => __( 'File Integrity', 'vigilante' ),
7660 'email' => __( 'Notification Settings', 'vigilante' ),
7661 'backup' => __( 'Backup', 'vigilante' ),
7662 'advanced' => __( 'Advanced', 'vigilante' ),
7663 'modules' => __( 'Modules', 'vigilante' ),
7664 );
7665 $display_name = isset( $section_names[ $section ] ) ? $section_names[ $section ] : $section;
7666
7667 $this->activity_log->log(
7668 'settings',
7669 'settings_updated',
7670 sprintf(
7671 /* translators: %s: Section name */
7672 __( 'Settings updated: %s', 'vigilante' ),
7673 $display_name
7674 ),
7675 array( 'section' => $section ),
7676 'info'
7677 );
7678 }
7679 }
7680
7681 /**
7682 * Apply all file changes (htaccess, wp-config) based on current options
7683 *
7684 * Used after preset, import, or reset operations
7685 *
7686 * @param array $all_options All plugin options.
7687 */
7688 private function apply_all_file_changes( $all_options ) {
7689 // Refresh settings cache first
7690 $this->settings->clear_cache();
7691
7692 // Create fresh settings instance
7693 $fresh_settings = new Vigilante_Settings();
7694
7695 // Apply firewall htaccess changes
7696 $htaccess = new Vigilante_Htaccess_Protection( $fresh_settings );
7697 $firewall_enabled = ! empty( $all_options['modules']['firewall'] );
7698
7699 if ( $firewall_enabled ) {
7700 $htaccess->apply_rules();
7701 } else {
7702 $htaccess->remove_rules();
7703 }
7704
7705 // Apply security headers htaccess changes
7706 $security_headers = new Vigilante_Security_Headers( $fresh_settings );
7707 $headers_enabled = ! empty( $all_options['modules']['security_headers'] );
7708
7709 if ( $headers_enabled ) {
7710 $security_headers->apply_rules();
7711 } else {
7712 $security_headers->remove_rules();
7713 }
7714
7715 // Apply wp-config changes
7716 $wpconfig = new Vigilante_Wpconfig_Security( $fresh_settings );
7717 $hardening_enabled = ! empty( $all_options['modules']['wp_hardening'] );
7718
7719 if ( $hardening_enabled ) {
7720 $wpconfig->apply_security_constants();
7721 } else {
7722 $wpconfig->remove_constants();
7723 }
7724
7725 // Apply WordPress options for comments/pingbacks
7726 $hardening_options = $all_options['wp_hardening'] ?? array();
7727
7728 if ( $hardening_enabled ) {
7729 // Pingbacks
7730 if ( ! empty( $hardening_options['disable_pingbacks'] ) ) {
7731 update_option( 'default_pingback_flag', 0 );
7732 } else {
7733 // Restore default: pingbacks enabled
7734 update_option( 'default_pingback_flag', 1 );
7735 }
7736
7737 // Trackbacks and ping status
7738 // Only close if either pingbacks OR trackbacks are disabled
7739 if ( ! empty( $hardening_options['disable_pingbacks'] ) || ! empty( $hardening_options['disable_trackbacks'] ) ) {
7740 update_option( 'default_ping_status', 'closed' );
7741 } else {
7742 // Restore default: pings open
7743 update_option( 'default_ping_status', 'open' );
7744 }
7745
7746 // Comment moderation
7747 if ( ! empty( $hardening_options['require_comment_moderation'] ) ) {
7748 update_option( 'comment_moderation', 1 );
7749 } else {
7750 // Restore default: no moderation required
7751 update_option( 'comment_moderation', 0 );
7752 }
7753 }
7754
7755 // Log the change
7756 if ( $this->activity_log ) {
7757 $this->activity_log->log(
7758 'settings',
7759 'bulk_settings_applied',
7760 __( 'Bulk settings applied (preset/import/reset)', 'vigilante' ),
7761 array(),
7762 'info'
7763 );
7764 }
7765 }
7766 }