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

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