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

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